|
|
@ -1,10 +1,12 @@ |
|
|
|
#include "platform.h" |
|
|
|
#include "platform.h" |
|
|
|
#include "ws2812.h" |
|
|
|
#include "ws2812.h" |
|
|
|
|
|
|
|
|
|
|
|
#define PLAT_NEOPIXEL_SHORT (uint32_t)(800e-9*PLAT_AHB_CLOCK) |
|
|
|
#define FREQ_STEP (PLAT_AHB_MHZ/20.0f) |
|
|
|
#define PLAT_NEOPIXEL_LONG (uint32_t)(400e-9*PLAT_AHB_CLOCK) |
|
|
|
#define NPX_DELAY_SHORT (uint32_t)(FREQ_STEP*1.5f) |
|
|
|
|
|
|
|
#define NPX_DELAY_LONG (uint32_t)(FREQ_STEP*3.5f) |
|
|
|
|
|
|
|
#define NPX_DELAY_SHOW (uint32_t)(FREQ_STEP*60) |
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (register volatile uint8_t i = 0; i < 8; i++) { |
|
|
|
for (register volatile uint8_t i = 0; i < 8; i++) { |
|
|
@ -12,17 +14,13 @@ void ws2812_byte(GPIO_TypeDef *port, uint32_t ll_pin, uint8_t b) |
|
|
|
|
|
|
|
|
|
|
|
// duty cycle determines bit value
|
|
|
|
// duty cycle determines bit value
|
|
|
|
if (b & 0x80) { |
|
|
|
if (b & 0x80) { |
|
|
|
__delay_cycles(PLAT_NEOPIXEL_LONG); |
|
|
|
__asm_loop(NPX_DELAY_LONG); |
|
|
|
//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");
|
|
|
|
__asm_loop(NPX_DELAY_SHORT); |
|
|
|
__delay_cycles(PLAT_NEOPIXEL_SHORT); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
__delay_cycles(PLAT_NEOPIXEL_SHORT); |
|
|
|
__asm_loop(NPX_DELAY_SHORT); |
|
|
|
//for(uint32_t _i = 0; _i < 5; _i++) asm volatile("nop");
|
|
|
|
|
|
|
|
LL_GPIO_ResetOutputPin(port, ll_pin); |
|
|
|
LL_GPIO_ResetOutputPin(port, ll_pin); |
|
|
|
__delay_cycles(PLAT_NEOPIXEL_LONG); |
|
|
|
__asm_loop(NPX_DELAY_LONG); |
|
|
|
//for(uint32_t _i = 0; _i < 10; _i++) asm volatile("nop");
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
b <<= 1; // shift to next bit
|
|
|
|
b <<= 1; // shift to next bit
|
|
|
@ -43,7 +41,11 @@ void ws2812_load_raw(GPIO_TypeDef *port, uint32_t ll_pin, uint8_t *rgbs, uint32_ |
|
|
|
ws2812_byte(port, ll_pin, b); |
|
|
|
ws2812_byte(port, ll_pin, b); |
|
|
|
} |
|
|
|
} |
|
|
|
vPortExitCritical(); |
|
|
|
vPortExitCritical(); |
|
|
|
// TODO: Delay 50 us
|
|
|
|
__asm_loop(NPX_DELAY_SHOW); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LL_GPIO_SetOutputPin(port, ll_pin); |
|
|
|
|
|
|
|
__asm_loop(NPX_DELAY_SHORT); |
|
|
|
|
|
|
|
LL_GPIO_ResetOutputPin(port, ll_pin); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** Set many RGBs from uint32 stream */ |
|
|
|
/** Set many RGBs from uint32 stream */ |
|
|
@ -69,7 +71,11 @@ void ws2812_load_sparse(GPIO_TypeDef *port, uint32_t ll_pin, uint8_t *rgbs, uint |
|
|
|
ws2812_byte(port, ll_pin, b); |
|
|
|
ws2812_byte(port, ll_pin, b); |
|
|
|
} |
|
|
|
} |
|
|
|
vPortExitCritical(); |
|
|
|
vPortExitCritical(); |
|
|
|
// TODO: Delay 50 us
|
|
|
|
__asm_loop(NPX_DELAY_SHOW); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LL_GPIO_SetOutputPin(port, ll_pin); |
|
|
|
|
|
|
|
__asm_loop(NPX_DELAY_SHORT); |
|
|
|
|
|
|
|
LL_GPIO_ResetOutputPin(port, ll_pin); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** Set many RGBs */ |
|
|
|
/** Set many RGBs */ |
|
|
@ -80,5 +86,9 @@ void ws2812_clear(GPIO_TypeDef *port, uint32_t ll_pin, uint32_t count) |
|
|
|
ws2812_byte(port, ll_pin, 0); |
|
|
|
ws2812_byte(port, ll_pin, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
vPortExitCritical(); |
|
|
|
vPortExitCritical(); |
|
|
|
// TODO: Delay 50 us
|
|
|
|
__asm_loop(NPX_DELAY_SHOW); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LL_GPIO_SetOutputPin(port, ll_pin); |
|
|
|
|
|
|
|
__asm_loop(NPX_DELAY_SHORT); |
|
|
|
|
|
|
|
LL_GPIO_ResetOutputPin(port, ll_pin); |
|
|
|
} |
|
|
|
} |
|
|
|