Vladimir N. Shilov 2 жил өмнө
parent
commit
0a3ca619bd
1 өөрчлөгдсөн 12 нэмэгдсэн , 7 устгасан
  1. 12 7
      app/led_spi.cpp

+ 12 - 7
app/led_spi.cpp

@@ -7,8 +7,8 @@
 #define PinSet(pin)   GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, ((uint16_t)1<<(pin)))
 #define PinRes(pin)   GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, ((uint16_t)1<<(pin)))
 
-#define PIN_DOUT      14
-#define PIN_CLK       13
+#define PIN_CLK       14
+#define PIN_DOUT      13
 #define PIN_LOAD      12
 #define PIN_OUTE       0
 
@@ -68,23 +68,28 @@ static uint32 MaxDuty;
 
 /* Private functions */
 void LED_writeData (led_pos_t pos, led_symb_t data) {
-  PinRes(PIN_LOAD); // down latch
+  //PinRes(PIN_LOAD); // down latch
   // software spi
   uint8_t i;
   uint16_t sdata = (pos << 8) | data;
   for (i = 16; i != 0; i--) {
     PinRes(PIN_CLK); // prepare CLK
-    if (sdata >= 0x8000) {
-        // if msb bit 1
+    if (sdata & 0x8000) {
+      // if msb bit 1
       PinSet(PIN_DOUT); // MOSI = 1
     } else {
       // if msb bit 0
       PinRes(PIN_DOUT); // MOSI = 0
     }
+    asm("nop;");
     PinSet(PIN_CLK); // lock CLK
     sdata <<= 1;
   }
+  asm("nop;");
   PinSet(PIN_LOAD); // up latch
+  asm("nop;");
+  PinRes(PIN_CLK);
+  PinRes(PIN_LOAD);
 }
 
 void LED_ShowLed(void) {
@@ -113,8 +118,8 @@ void LED_Init (void) {
   pinMode(PIN_CLK, OUTPUT);
   pinMode(PIN_LOAD, OUTPUT);
 
-  PinSet(PIN_CLK);
-  PinSet(PIN_LOAD);
+  PinRes(PIN_CLK);
+  PinRes(PIN_LOAD);
 
   /* Start timer for refresh leds */
   ledTimer.initializeMs(5, LED_ShowLed).start();