Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uint8 staticBits ; // (LED_DR & (uint8)(~LED_MASK));
- uint8 LED_ON_BITVALUE = ((uint8)(1 << LED_SHIFT) & LED_MASK);
- uint8 LED_OFF_BITVALUE = ((uint8)(0 << LED_SHIFT) & LED_MASK);
- #define LED_ON LED_DR = staticBits | LED_ON_BITVALUE;
- #define LED_OFF LED_DR = staticBits | LED_OFF_BITVALUE;
- #define QUICK_LED_BIT_1 {LED_ON __asm__( "nop\n nop\n nop\n nop\n nop\n nop\n"); LED_OFF }
- #define QUICK_LED_BIT_0 {LED_ON LED_OFF __asm__( "nop\n"); }
- // Test de 2 fonction pour allumer le ruban led WS2812
- // La fonction avec les if est plus rapide qu'avec la version switch
- void writeLedStrip()
- {
- uint_fast8_t i = 0;
- boardLed_Write(1);
- uint_fast8_t bitIndexL = 0;
- uint_fast8_t byteIndexL = 0;
- while(i < NB_LED)
- {
- while (byteIndexL<3)
- {
- if (ledstrip[i].led.data[byteIndexL] & (1u << (7- bitIndexL)))
- QUICK_LED_BIT_1
- else
- QUICK_LED_BIT_0
- if (bitIndexL == 7)
- {
- bitIndexL = 0;
- byteIndexL++;
- }
- else
- {
- bitIndexL++;
- }
- }
- bitIndexL = 0;
- byteIndexL = 0;
- i++;
- }
- boardLed_Write(0);
- }
- version switch:
- void writeLedStrip()
- {
- uint_fast8_t i = 0;
- boardLed_Write(1);
- uint_fast8_t bitIndexL = 0;
- uint_fast8_t byteIndexL = 0;
- while(i < NB_LED)
- {
- while (byteIndexL<3)
- {
- switch (bitIndexL)
- {
- case 0:
- if (ledstrip[i].led.data[byteIndexL] & 128u)
- QUICK_LED_BIT_1
- else
- QUICK_LED_BIT_0
- bitIndexL++;
- break;
- case 1:
- if (ledstrip[i].led.data[byteIndexL] & 64u)
- QUICK_LED_BIT_1
- else
- QUICK_LED_BIT_0
- bitIndexL++;
- break;
- case 2:
- if (ledstrip[i].led.data[byteIndexL] & 32u)
- QUICK_LED_BIT_1
- else
- QUICK_LED_BIT_0
- bitIndexL++;
- break;
- case 3:
- if (ledstrip[i].led.data[byteIndexL] & 16u)
- QUICK_LED_BIT_1
- else
- QUICK_LED_BIT_0
- bitIndexL++;
- break;
- case 4:
- if (ledstrip[i].led.data[byteIndexL] & 8u)
- QUICK_LED_BIT_1
- else
- QUICK_LED_BIT_0
- bitIndexL++;
- break;
- case 5:
- if (ledstrip[i].led.data[byteIndexL] & 4u)
- QUICK_LED_BIT_1
- else
- QUICK_LED_BIT_0
- bitIndexL++;
- break;
- case 6:
- if (ledstrip[i].led.data[byteIndexL] & 2u)
- QUICK_LED_BIT_1
- else
- QUICK_LED_BIT_0
- bitIndexL++;
- break;
- case 7:
- if (ledstrip[i].led.data[byteIndexL] & 1u)
- QUICK_LED_BIT_1
- else
- QUICK_LED_BIT_0
- bitIndexL = 0;
- byteIndexL++;
- break;
- }
- }
- bitIndexL = 0;
- byteIndexL = 0;
- i++;
- }
- boardLed_Write(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement