Advertisement
Guest User

ws2812B LEDSTRIP test cypress

a guest
Nov 18th, 2020
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.48 KB | None | 0 0
  1.  
  2.  
  3.  
  4. uint8 staticBits ;  // (LED_DR & (uint8)(~LED_MASK));
  5.  
  6. uint8 LED_ON_BITVALUE = ((uint8)(1 << LED_SHIFT) & LED_MASK);
  7. uint8 LED_OFF_BITVALUE = ((uint8)(0 << LED_SHIFT) & LED_MASK);
  8.  
  9. #define LED_ON LED_DR = staticBits | LED_ON_BITVALUE;
  10. #define LED_OFF LED_DR = staticBits | LED_OFF_BITVALUE;
  11. #define QUICK_LED_BIT_1 {LED_ON __asm__( "nop\n nop\n nop\n nop\n nop\n nop\n"); LED_OFF }
  12. #define QUICK_LED_BIT_0 {LED_ON LED_OFF __asm__( "nop\n"); }
  13.  
  14. // Test de 2 fonction pour allumer le ruban led WS2812
  15. // La fonction avec les if est plus rapide qu'avec la version switch
  16. void writeLedStrip()
  17. {
  18.     uint_fast8_t i = 0;
  19.     boardLed_Write(1);
  20.     uint_fast8_t bitIndexL = 0;
  21.     uint_fast8_t byteIndexL = 0;
  22.     while(i < NB_LED)
  23.     {
  24.         while (byteIndexL<3)
  25.         {
  26.             if (ledstrip[i].led.data[byteIndexL] & (1u << (7- bitIndexL)))
  27.                 QUICK_LED_BIT_1
  28.             else
  29.                 QUICK_LED_BIT_0
  30.                
  31.             if (bitIndexL == 7)
  32.             {
  33.                 bitIndexL = 0;
  34.                 byteIndexL++;
  35.             }
  36.             else
  37.             {
  38.                 bitIndexL++;
  39.             }
  40.      
  41.         }
  42.         bitIndexL = 0;
  43.         byteIndexL = 0;
  44.         i++;
  45.     }
  46.     boardLed_Write(0);
  47. }
  48.  
  49.  
  50. version switch:
  51. void writeLedStrip()
  52. {
  53.     uint_fast8_t i = 0;
  54.     boardLed_Write(1);
  55.     uint_fast8_t bitIndexL = 0;
  56.     uint_fast8_t byteIndexL = 0;
  57.     while(i < NB_LED)
  58.     {
  59.         while (byteIndexL<3)
  60.         {
  61.                 switch (bitIndexL)
  62.             {
  63.             case 0:
  64.                 if (ledstrip[i].led.data[byteIndexL] & 128u)
  65.                     QUICK_LED_BIT_1
  66.                 else
  67.                     QUICK_LED_BIT_0
  68.                 bitIndexL++;
  69.             break;
  70.             case 1:
  71.                 if (ledstrip[i].led.data[byteIndexL] & 64u)
  72.                     QUICK_LED_BIT_1
  73.                 else
  74.                     QUICK_LED_BIT_0
  75.                 bitIndexL++;
  76.             break;
  77.             case 2:
  78.                 if (ledstrip[i].led.data[byteIndexL] & 32u)
  79.                     QUICK_LED_BIT_1
  80.                 else
  81.                     QUICK_LED_BIT_0
  82.                 bitIndexL++;
  83.             break;
  84.             case 3:
  85.                 if (ledstrip[i].led.data[byteIndexL] & 16u)
  86.                     QUICK_LED_BIT_1
  87.                 else
  88.                     QUICK_LED_BIT_0
  89.                 bitIndexL++;
  90.             break;
  91.             case 4:
  92.                 if (ledstrip[i].led.data[byteIndexL] & 8u)
  93.                     QUICK_LED_BIT_1
  94.                 else
  95.                     QUICK_LED_BIT_0
  96.                 bitIndexL++;
  97.             break;
  98.             case 5:
  99.                 if (ledstrip[i].led.data[byteIndexL] & 4u)
  100.                     QUICK_LED_BIT_1
  101.                 else
  102.                     QUICK_LED_BIT_0
  103.                 bitIndexL++;
  104.             break;
  105.             case 6:
  106.                 if (ledstrip[i].led.data[byteIndexL] & 2u)
  107.                     QUICK_LED_BIT_1
  108.                 else
  109.                     QUICK_LED_BIT_0
  110.                 bitIndexL++;
  111.             break;
  112.             case 7:
  113.                 if (ledstrip[i].led.data[byteIndexL] & 1u)
  114.                     QUICK_LED_BIT_1
  115.                 else
  116.                     QUICK_LED_BIT_0
  117.                 bitIndexL = 0;
  118.                 byteIndexL++;
  119.             break;
  120.             }
  121.      
  122.         }
  123.         bitIndexL = 0;
  124.         byteIndexL = 0;
  125.         i++;
  126.     }
  127.     boardLed_Write(0);
  128. }
  129.  
  130.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement