menu progress, led pwm, db tweaks

This commit is contained in:
ikari
2009-11-04 19:11:10 +01:00
parent c685f9a09f
commit 3b4b1b8069
11 changed files with 94 additions and 60 deletions

View File

@@ -59,7 +59,7 @@
#include "config.h"
#include "ff.h" /* FatFs declarations */
#include "diskio.h" /* Include file for user provided disk functions */
#include "uart.h"
/*--------------------------------------------------------------------------
@@ -1651,7 +1651,7 @@ FRESULT f_write (
*bw = 0;
res = validate(fs /*, fp->id*/); /* Check validity of the object */
if (res != FR_OK) return res;
if (fp->flag & FA__ERROR) return FR_RW_ERROR; /* Check error flag */
if (fp->flag & FA__ERROR) {dprintf("fp->flag & FA__ERROR \n"); return FR_RW_ERROR;} /* Check error flag */
if (!(fp->flag & FA_WRITE)) return FR_DENIED; /* Check access mode */
if (fp->fsize + btw < fp->fsize) return FR_OK; /* File size cannot reach 4GB */
@@ -1669,18 +1669,18 @@ FRESULT f_write (
clust = create_chain(fs, fp->curr_clust); /* Trace or streach cluster chain */
}
if (clust == 0) break; /* Disk full */
if (clust == 1 || clust >= fs->max_clust) goto fw_error;
if (clust == 1 || clust >= fs->max_clust) { dprintf("cluster alloc error\n"); goto fw_error; }
fp->curr_clust = clust; /* Current cluster */
sect = clust2sect(fs, clust); /* Get current sector */
fp->csect = fs->csize; /* Re-initialize the left sector counter */
}
if(!move_fp_window(fp,0)) goto fw_error;
if(!move_fp_window(fp,0)) {dprintf("move_fp_window error\n"); goto fw_error;}
fp->curr_sect = sect; /* Update current sector */
cc = btw / SS(fs); /* When left bytes >= SS(fs), */
if (cc) { /* Write maximum contiguous sectors directly */
if (cc > fp->csect) cc = fp->csect;
if (disk_write(fs->drive, wbuff, sect, (BYTE)cc) != RES_OK)
goto fw_error;
{ dprintf("disk_write error\n"); goto fw_error;}
fp->csect -= (BYTE)(cc - 1);
fp->curr_sect += cc - 1;
wcnt = cc * SS(fs);
@@ -1695,7 +1695,7 @@ FRESULT f_write (
fp->fptr < fp->fsize && /* Fill sector buffer with file data if needed */
#endif
!move_fp_window(fp,fp->curr_sect))
goto fw_error;
{ dprintf("fract write error\n "); goto fw_error; }
memcpy(&FPBUF.data[fp->fptr & (SS(fs) - 1)], wbuff, wcnt);
FPBUF.dirty=TRUE;
}

View File

@@ -20,7 +20,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
led.c: Overdesigned LED handling
led.c: LED handling
*/
@@ -28,19 +28,11 @@
#include "config.h"
#include "led.h"
volatile uint8_t led_state;
static uint8_t led_bright[16]={255,253,252,251,249,247,244,239,232,223,210,191,165,127,74,0};
static uint8_t curr_bright = 0;
static uint8_t led_bounce_dir = 0;
/**
* update_leds - set LEDs to correspond to the buffer status
*
* This function sets the busy/dirty LEDs to correspond to the current state
* of the buffers, i.e. busy on of at least one non-system buffer is
* allocated and dirty on if at least one buffer is allocated for writing.
* Call if you have manually changed the LEDs and you want to restore the
* "default" state.
*/
void update_leds(void) {
}
volatile uint8_t led_state;
void toggle_busy_led(void) {
PORTB &= ~_BV(PB3);
@@ -64,3 +56,33 @@ void set_pwr_led(uint8_t state) {
DDRB &= ~_BV(PB0);
}
}
void set_busy_pwm(uint8_t brightness) {
OCR0A = led_bright[brightness];
set_busy_led(1);
}
void bounce_busy_led() {
set_busy_pwm(curr_bright);
if(led_bounce_dir) {
curr_bright--;
if(curr_bright==0) {
led_bounce_dir = 0;
}
} else {
curr_bright++;
if(curr_bright==15) {
led_bounce_dir = 1;
}
}
}
void led_pwm() {
set_busy_led(1);
TCCR0A = 0x83;
TCCR0B = 0x01;
}
void led_std() {
TCCR0A = 0;
}

View File

@@ -38,10 +38,11 @@
extern volatile uint8_t led_state;
/* Update the LEDs to match the buffer state */
void update_leds(void);
void toggle_busy_led(void);
void set_busy_led(uint8_t);
void set_pwr_led(uint8_t);
void set_busy_pwm(uint8_t brightness);
void bounce_busy_led(void);
void led_pwm(void);
void led_std(void);
#endif

View File

@@ -159,8 +159,11 @@ int main(void) {
uint16_t curr_dir_id = scan_dir(fs_path, 0); // generate files footprint
dprintf("curr dir id = %x\n", curr_dir_id);
uint16_t saved_dir_id;
led_pwm();
if((get_db_id(&saved_dir_id) != FR_OK) // no database?
|| 1 || saved_dir_id != curr_dir_id) { // files changed? // XXX
|| saved_dir_id != curr_dir_id) { // files changed? // XXX
dprintf("saved dir id = %x\n", saved_dir_id);
_delay_ms(50);
dprintf("rebuilding database...");
@@ -181,12 +184,12 @@ int main(void) {
load_sram((uint8_t*)"/sd2snes/sd2snes.dir", SRAM_DIR_ADDR);
}
uart_putc('[');
load_sram((uint8_t*)"/test.srm", SRAM_SAVE_ADDR);
uart_putc(']');
// uart_putc('[');
// load_sram((uint8_t*)"/test.srm", SRAM_SAVE_ADDR);
// uart_putc(']');
uart_putc('(');
load_rom((uint8_t*)"/test.smc");
load_rom((uint8_t*)"/sd2snes/menu.bin");
uart_putc(')');
sram_writebyte(0, SRAM_CMD_ADDR);
@@ -210,7 +213,7 @@ int main(void) {
_delay_ms(100);
// snes_reset(1);
set_avr_ena(0);
dprintf("%s\n", file_lfn);
dprintf("Selected name: %s\n", file_lfn);
load_rom(file_lfn);
set_avr_ena(1);
snes_reset(1);

View File

@@ -123,8 +123,9 @@ uint32_t load_rom(uint8_t* filename) {
if (file_res || !bytes_read) break;
FPGA_SS_LOW();
spiTransferByte(0x91); // write w/ increment
if(!(count++ % 16)) {
toggle_busy_led();
if(!(count++ % 8)) {
// toggle_busy_led();
bounce_busy_led();
uart_putc('.');
}
for(int j=0; j<bytes_read; j++) {

View File

@@ -181,8 +181,8 @@ static uint8_t sdResponse(uint8_t expected)
static uint8_t sdWaitWriteFinish(void)
{
unsigned short count = 0xFFFF; // wait for quite some time
uint32_t count = 0x1FFFF; // wait for quite some time
while ((spiTransferByte(0xFF) == 0) && count )
count--;
@@ -640,6 +640,7 @@ DRESULT sd_write(BYTE drv, const BYTE *buffer, DWORD sector, BYTE count) {
res = sendCommand(drv, WRITE_BLOCK, (sector+sec)<<9, 0);
if (res != 0) {
uart_putc('C');
SPI_SS_HIGH(drv);
disk_state = DISK_ERROR;
return RES_ERROR;
@@ -678,6 +679,7 @@ DRESULT sd_write(BYTE drv, const BYTE *buffer, DWORD sector, BYTE count) {
// Wait for write finish
if (!sdWaitWriteFinish()) {
uart_putc('W');
SPI_SS_HIGH(drv);
disk_state = DISK_ERROR;
return RES_ERROR;