30 #ifdef WS2812_TARGET_PLATFORM_STM8S
40 #if F_CPU != 16000000UL
41 #error "F_CPU must be 16MHz!"
45 #define TICKS_PER_LOOP 2
46 #define LOOPS_PER_US (F_CPU / TICKS_PER_LOOP / 1000000UL)
47 #define LDW_OVERHEAD 2
50 volatile static uint16_t _port_odr_addr;
51 volatile static uint8_t _mask_hi;
52 volatile static uint8_t _mask_lo;
54 static bool _prep =
false;
57 volatile static uint16_t _us_loops_remaining;
74 ldw x, __us_loops_remaining
92 for (uint8_t i = 0; i < cfg->
n_dev; i++) {
93 pin_msk |= cfg->
pins[i];
94 GPIO_Init(port, cfg->
pins[i], GPIO_MODE_OUT_PP_LOW_FAST);
151 static void ws2812_tx_bit_1()
154 ldw x, __port_odr_addr
204 static void ws2812_tx_bit_0()
207 ldw x, __port_odr_addr
239 for (uint8_t i = 0; i < 8; i++)
242 if (
byte & 0b10000000)
254 for (
size_t i = 0; i < n_leds; i++) {
255 for (uint8_t j = 0; j <
sizeof(dev->
rgbmap); j++) {
256 uint8_t *pxl = (uint8_t *) &(
leds[i]);
ws2812_rgb leds[N_LEDS]
RGB array which represents the LEDs.
ALL PLATFORMS: Data structure to configure a WS2812 device struct.
uint8_t n_dev
Number of WS2812 device to drive.
uint8_t rst_time_us
Time required for the WS2812 device(s) to reset in us.
uint16_t port_baseaddr
Base address of the port used to drive WS2812 devices (ex. GPIOA_BASE, GPIOB_BASE,...
ws2812_order order
CoColor order of the WS2812 device(s) (ex. rgb, grb, bgr...)
uint8_t * pins
Array of pins used to program WS2812 devices (Must share the same PORT! (ex. PB0, PB1,...
Data structure to hold RGB color values.
ALL PLATFORMS: WS2812 device struct to drive one or more WS2812 devices.
uint16_t port_baseaddr
Base address of the port used to drive WS2812 devices (ex. GPIOA_BASE, GPIOB_BASE,...
uint8_t rgbmap[3]
RGB map to map/convert RGB values to another color order.
uint8_t rst_time_us
Time required for WS2812 to reset in us.
uint8_t masklo
PORT masks to toggle the data pins low.
uint8_t maskhi
PORT masks to toggle the data pins high.
void delay_us(uint8_t us)
Halts the program for a given ammount of microseconds.
void ws2812_tx_byte(ws2812 *dev, uint8_t byte)
Transmits a byte of data to the WS2812 device.
void _ws2812_get_rgbmap(uint8_t(*rgbmap)[3], ws2812_order order)
Initializes a rgb map for a given color order.
Definitions required by all platform specific headers.
void ws2812_close_tx(ws2812 *dev)
Closes a WS2812 transmission.
void ws2812_wait_rst(ws2812 *dev)
Waits for the WS2812 device to reset.
uint8_t ws2812_config(ws2812 *dev, ws2812_cfg *cfg)
Configures a WS2812 device struct.
void ws2812_prep_tx(ws2812 *dev)
Prepares the host device for data transmission.
void ws2812_tx(ws2812 *dev, ws2812_rgb *leds, size_t n_leds)
Transmits RGB values to the provided WS2812 device.
#define LOOPS_PER_US
Number for loops required for 1 us to pass.
#define LDW_OVERHEAD
Number of CPU ticks for the LDW instruction.
Provides STM8S platform specific definitions.