|
|
@ -4,39 +4,26 @@ |
|
|
|
static //inline __attribute__((always_inline))
|
|
|
|
static //inline __attribute__((always_inline))
|
|
|
|
void ws2812_byte(GPIO_TypeDef *port, uint32_t ll_pin, uint8_t b) |
|
|
|
void ws2812_byte(GPIO_TypeDef *port, uint32_t ll_pin, uint8_t b) |
|
|
|
{ |
|
|
|
{ |
|
|
|
__disable_irq(); |
|
|
|
|
|
|
|
for (register volatile uint8_t i = 0; i < 8; i++) { |
|
|
|
for (register volatile uint8_t i = 0; i < 8; i++) { |
|
|
|
LL_GPIO_SetOutputPin(port, ll_pin); |
|
|
|
LL_GPIO_SetOutputPin(port, ll_pin); |
|
|
|
|
|
|
|
|
|
|
|
// duty cycle determines bit value
|
|
|
|
// duty cycle determines bit value
|
|
|
|
if (b & 0x80) { |
|
|
|
if (b & 0x80) { |
|
|
|
for(uint32_t _i = 0; _i < 10; _i++) asm volatile("nop"); |
|
|
|
__delay_cycles(20); |
|
|
|
|
|
|
|
//for(uint32_t _i = 0; _i < 10; _i++) asm volatile("nop");
|
|
|
|
LL_GPIO_ResetOutputPin(port, ll_pin); |
|
|
|
LL_GPIO_ResetOutputPin(port, ll_pin); |
|
|
|
for(uint32_t _i = 0; _i < 10; _i++) asm volatile("nop"); |
|
|
|
//for(uint32_t _i = 0; _i < 10; _i++) asm volatile("nop");
|
|
|
|
|
|
|
|
__delay_cycles(10); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
for(uint32_t _i = 0; _i < 5; _i++) asm volatile("nop"); |
|
|
|
__delay_cycles(10); |
|
|
|
|
|
|
|
//for(uint32_t _i = 0; _i < 5; _i++) asm volatile("nop");
|
|
|
|
LL_GPIO_ResetOutputPin(port, ll_pin); |
|
|
|
LL_GPIO_ResetOutputPin(port, ll_pin); |
|
|
|
for(uint32_t _i = 0; _i < 10; _i++) asm volatile("nop"); |
|
|
|
__delay_cycles(20); |
|
|
|
|
|
|
|
//for(uint32_t _i = 0; _i < 10; _i++) asm volatile("nop");
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
b <<= 1; // shift to next bit
|
|
|
|
b <<= 1; // shift to next bit
|
|
|
|
} |
|
|
|
} |
|
|
|
__enable_irq(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Set many RGBs */ |
|
|
|
|
|
|
|
void ws2812_load(GPIO_TypeDef *port, uint32_t ll_pin, uint32_t *rgbs, uint32_t count) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
vPortEnterCritical(); |
|
|
|
|
|
|
|
for (uint32_t i = 0; i < count; i++) { |
|
|
|
|
|
|
|
uint32_t rgb = *rgbs++; |
|
|
|
|
|
|
|
ws2812_byte(port, ll_pin, rgb_g(rgb)); |
|
|
|
|
|
|
|
ws2812_byte(port, ll_pin, rgb_r(rgb)); |
|
|
|
|
|
|
|
ws2812_byte(port, ll_pin, rgb_b(rgb)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
vPortExitCritical(); |
|
|
|
|
|
|
|
// TODO: Delay 50 us
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** Set many RGBs from packed stream */ |
|
|
|
/** Set many RGBs from packed stream */ |
|
|
@ -82,7 +69,6 @@ void ws2812_load_sparse(GPIO_TypeDef *port, uint32_t ll_pin, uint8_t *rgbs, uint |
|
|
|
// TODO: Delay 50 us
|
|
|
|
// TODO: Delay 50 us
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Set many RGBs */ |
|
|
|
/** Set many RGBs */ |
|
|
|
void ws2812_clear(GPIO_TypeDef *port, uint32_t ll_pin, uint32_t count) |
|
|
|
void ws2812_clear(GPIO_TypeDef *port, uint32_t ll_pin, uint32_t count) |
|
|
|
{ |
|
|
|
{ |
|
|
|