]> the.earth.li Git - riso-kagaku-clone.git/blobdiff - main.c
Fix serial number retrieval from EEPROM
[riso-kagaku-clone.git] / main.c
diff --git a/main.c b/main.c
index 2308d558b52999815a8eb7a42c8318331a3068db..f00ecfe0936d7434058ad2bec8a706416c56655e 100644 (file)
--- a/main.c
+++ b/main.c
 #include "usbdrv.h"
 #include "libs-device/osccal.h"
 
-#define RED_BIT    8 /* Bit 3 on port B */
-#define GREEN_BIT 16 /* Bit 4 on port B */
-#define BLUE_BIT  32 /* Bit 5 on port B */
+#define GREEN_BIT  1 /* Bit 0 on port B */
+#define RED_BIT    2 /* Bit 1 on port B */
+#define BLUE_BIT   4 /* Bit 2 on port B */
 #define ALL_BITS (RED_BIT | GREEN_BIT | BLUE_BIT)
 #define CMD_SET_SERIAL 0xfa
 
-uchar serno_read = 0;
 int serno_str[] = {
        USB_STRING_DESCRIPTOR_HEADER(8),
        'U', 'N', 'S', 'E', 'T', 'X', 'X', 'X',
@@ -89,7 +88,7 @@ PROGMEM const char usbHidReportDescriptor[22] = {
        0x15, 0x00,                     /*   LOGICAL_MINIMUM (0) */
        0x26, 0xff, 0x00,               /*   LOGICAL_MAXIMUM (255) */
        0x75, 0x08,                     /*   REPORT_SIZE (8 bits) */
-       0x95, 0x06,                     /*   REPORT_COUNT (6 elements) */
+       0x95, 0x08,                     /*   REPORT_COUNT (8 elements) */
        0x09, 0x00,                     /*   USAGE (Undefined) */
        0xb2, 0x02, 0x01,               /*   FEATURE (Data, Var, Abs, Buf) */
        0xc0                            /* END_COLLECTION */
@@ -104,28 +103,25 @@ void fetch_serno(void)
 {
        uint32_t serno;
 
-       if (!serno_read) {
-               eeprom_read_block(&serno, 0, 4);
-               if (serno == 0xffffffff) {
-                       serno_str[1] = 'U';
-                       serno_str[2] = 'N';
-                       serno_str[3] = 'S';
-                       serno_str[4] = 'E';
-                       serno_str[5] = 'T';
-                       serno_str[6] = 'X';
-                       serno_str[7] = 'X';
-                       serno_str[8] = 'X';
-               } else {
-                       serno_str[1] = hexdigit((serno >> 28));
-                       serno_str[2] = hexdigit((serno >> 24) & 0xF);
-                       serno_str[3] = hexdigit((serno >> 20) & 0xF);
-                       serno_str[4] = hexdigit((serno >> 16) & 0xF);
-                       serno_str[5] = hexdigit((serno >> 12) & 0xF);
-                       serno_str[6] = hexdigit((serno >>  8) & 0xF);
-                       serno_str[7] = hexdigit((serno >>  4) & 0xF);
-                       serno_str[8] = hexdigit( serno        & 0xF);
-               }
-               serno_read = 1;
+       eeprom_read_block(&serno, 0, 4);
+       if (serno == 0xffffffff) {
+               serno_str[1] = 'U';
+               serno_str[2] = 'N';
+               serno_str[3] = 'S';
+               serno_str[4] = 'E';
+               serno_str[5] = 'T';
+               serno_str[6] = 'X';
+               serno_str[7] = 'X';
+               serno_str[8] = 'X';
+       } else {
+               serno_str[1] = hexdigit((serno >> 28));
+               serno_str[2] = hexdigit((serno >> 24) & 0xF);
+               serno_str[3] = hexdigit((serno >> 20) & 0xF);
+               serno_str[4] = hexdigit((serno >> 16) & 0xF);
+               serno_str[5] = hexdigit((serno >> 12) & 0xF);
+               serno_str[6] = hexdigit((serno >>  8) & 0xF);
+               serno_str[7] = hexdigit((serno >>  4) & 0xF);
+               serno_str[8] = hexdigit( serno        & 0xF);
        }
 }
 
@@ -254,6 +250,8 @@ int __attribute__((noreturn)) main(void)
 
        wdt_enable(WDTO_1S);
 
+       fetch_serno();
+
        usbInit();
        usbDeviceDisconnect();