| 109 | } |
| 110 | |
| 111 | template<int BITS> __attribute__ ((always_inline)) inline static void writeBits(FASTLED_REGISTER u32 & next_mark, FASTLED_REGISTER u8 & b) { |
| 112 | // SysTick counts down (not up) and is 24-bit |
| 113 | for(FASTLED_REGISTER u32 i = BITS-1; i > 0; i--) { // We could speed this up by using Bit Banding |
| 114 | while(__am_hal_systick_count() > next_mark) { ; } // Wait for the remainder of this cycle to complete |
| 115 | // Calculate next_mark (the time of the next DATA_PIN transition) by subtracting T1+T2+T3 |
| 116 | // SysTick counts down (not up) and is 24-bit |
| 117 | next_mark = (__am_hal_systick_count() - (T1+T2+T3)) & 0xFFFFFFUL; |
| 118 | FastPin<DATA_PIN>::hi(); |
| 119 | if(b&0x80) { |
| 120 | // "1 code" = longer pulse width |
| 121 | while((__am_hal_systick_count() - next_mark) > (T3+(3*(F_CPU/24000000)))) { ; } |
| 122 | FastPin<DATA_PIN>::lo(); |
| 123 | } else { |
| 124 | // "0 code" = shorter pulse width |
| 125 | while((__am_hal_systick_count() - next_mark) > (T2+T3+(4*(F_CPU/24000000)))) { ; } |
| 126 | FastPin<DATA_PIN>::lo(); |
| 127 | } |
| 128 | b <<= 1; |
| 129 | } |
| 130 | |
| 131 | while(__am_hal_systick_count() > next_mark) { ; }// Wait for the remainder of this cycle to complete |
| 132 | // Calculate next_mark (the time of the next DATA_PIN transition) by subtracting T1+T2+T3 |
| 133 | // SysTick counts down (not up) and is 24-bit |
| 134 | next_mark = (__am_hal_systick_count() - (T1+T2+T3)) & 0xFFFFFFUL; |
| 135 | FastPin<DATA_PIN>::hi(); |
| 136 | if(b&0x80) { |
| 137 | // "1 code" = longer pulse width |
| 138 | while((__am_hal_systick_count() - next_mark) > (T3+(2*(F_CPU/24000000)))) { ; } |
| 139 | FastPin<DATA_PIN>::lo(); |
| 140 | } else { |
| 141 | // "0 code" = shorter pulse width |
| 142 | while((__am_hal_systick_count() - next_mark) > (T2+T3+(4*(F_CPU/24000000)))) { ; } |
| 143 | FastPin<DATA_PIN>::lo(); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | // This method is made static to force making register Y available to use for data on AVR - if the method is non-static, then |
| 148 | // gcc will use register Y for the this pointer. |
nothing calls this directly
no test coverage detected