diff options
| author | cpldcpu <cpldcpu@gmail.com> | 2013-12-31 12:55:24 +0100 | 
|---|---|---|
| committer | cpldcpu <cpldcpu@gmail.com> | 2013-12-31 12:55:24 +0100 | 
| commit | 5b94559c7226774bda746f640b351bec07fe842f (patch) | |
| tree | 1ce2769dd3fe22293ad80cf11d003cb30637d0da | |
| parent | 918cf149e6c55ae45b9b37bf62780c6ff3e156a5 (diff) | |
| download | micronucleus-5b94559c7226774bda746f640b351bec07fe842f.tar.gz micronucleus-5b94559c7226774bda746f640b351bec07fe842f.tar.bz2 micronucleus-5b94559c7226774bda746f640b351bec07fe842f.zip | |
firemware: Clean up command handling
| -rw-r--r-- | firmware/main.c | 25 | 
1 files changed, 13 insertions, 12 deletions
| diff --git a/firmware/main.c b/firmware/main.c index d0a3edd..ad0b7a2 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -36,7 +36,8 @@  register uint8_t  command asm( "r3" ); // register saves many bytes   enum { -  cmd_nop=0, // also: get device info +  cmd_local_nop=0, // also: get device info +  cmd_device_info=0,    cmd_transfer_page=1,    cmd_erase_application=2,    cmd_exit=4, @@ -151,7 +152,6 @@ static void writeWordToPageBuffer(uint16_t data) {  /* ------------------------------------------------------------------------ */  static uint8_t usbFunctionSetup(uint8_t data[8]) {    usbRequest_t *rq = (void *)data; -  ((uint8_t*)&idlePolls)[1] = 0;              // reset idle polls when we get usb traffic    static uint8_t replyBuffer[4] = {      (((uint16_t)PROGMEM_SIZE) >> 8) & 0xff, @@ -159,21 +159,22 @@ static uint8_t usbFunctionSetup(uint8_t data[8]) {      SPM_PAGESIZE,      MICRONUCLEUS_WRITE_SLEEP    }; -     -  if (rq->bRequest == 0) { // get device info + +  ((uint8_t*)&idlePolls)[1] = 0;              // reset idle polls when we get usb traffic +   +  if (rq->bRequest == cmd_device_info) { // get device info      usbMsgPtr = replyBuffer;      return 4;       -  } else if (rq->bRequest == cmd_transfer_page) { // transfer page -   +  } else if (rq->bRequest == cmd_transfer_page) { // transfer page        // clear page buffer as a precaution before filling the buffer in case       // a previous write operation failed and there is still something in the buffer.      __boot_page_fill_clear();      currentAddress = rq->wIndex.word;              return USB_NO_MSG; // hands off work to usbFunctionWrite    } else { -  // Handle cmd_erase_application and cmd_exit -  command=rq->bRequest; -  return 0; +    // Handle cmd_erase_application and cmd_exit +    command=rq->bRequest; +    return 0;    }  } @@ -263,7 +264,7 @@ static inline void leaveBootloader(void) {    // jump to application reset vector at end of flash    asm volatile ("rjmp __vectors - 4"); -} +  }  int main(void) { @@ -282,7 +283,7 @@ int main(void) {        _delay_us(100);        wdt_reset();   // Only necessary if WDT is fused on -      command=cmd_nop; +      command=cmd_local_nop;        usbPoll();        idlePolls++; @@ -294,7 +295,7 @@ int main(void) {        // Wait for USB traffic to finish before a blocking event is executed        // All events will render the MCU unresponsive to USB traffic for a while. -      if (command!=cmd_nop) _delay_ms(2); +      if (command!=cmd_local_nop) _delay_ms(2);        if (command==cmd_erase_application)           eraseApplication(); | 
