document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. void main() {
  2.    [...]
  3.    while (1) {
  4.       if (uart_available()) {
  5.          c = uart_getchar();
  6.          process_opcode(c);
  7.       }
  8.    }
  9. }
  10.  
  11. void process_opcode(uint8_t c){
  12.    uint8_t opcode = c >> 5;
  13.    uint8_t reg = c & 0x1f;
  14.    switch (opcode){
  15.       case SETREG_REQ:
  16.          process_setreg_request(reg);
  17.          break;
  18.       case GETREG_REQ:
  19.          process_getreg_request(reg);
  20.    }
  21. }
  22.  
  23. void process_setreg_request(uint8_t reg){
  24.    uint8_t value;
  25.    value = uart_getchar();
  26.    switch(reg){
  27.       // General USB registers
  28.       case (REG_UHWCON):
  29.          UHWCON = value;
  30.          break;
  31.       case (REG_USBCON):
  32.          USBCON = value;
  33.          break;
  34.       case (REG_USBINT):
  35.          USBINT = value;
  36.          break;
  37.       case (REG_USBSTA):
  38.          USBSTA = value;
  39.          break;
  40.       [...]
  41.    }
  42. }
');