if (bit == 0) {
/* "high" time : 350ns */
- gpio_port->set = gpio_bit;
+ gpio_port->toggle = gpio_bit;
nop();
nop();
nop();
nop();
nop();
/* "low" time : 800ns */
- gpio_port->clear = gpio_bit;
+ gpio_port->toggle = gpio_bit;
nop();
nop();
nop();
nop();
} else {
/* "high" time : 800ns */
- gpio_port->set = gpio_bit;
+ gpio_port->toggle = gpio_bit;
nop();
nop();
nop();
nop();
nop();
/* "low" time : 600ns */
- gpio_port->clear = gpio_bit;
+ gpio_port->toggle = gpio_bit;
nop();
}
lpc_enable_irq();
}
-static void ws2812_inverted_bit_sender(struct ws2812_conf* ws2812)
-{
- struct lpc_gpio* gpio_port = LPC_GPIO_REGS(ws2812->gpio.port);
- uint32_t gpio_bit = (1 << ws2812->gpio.pin);
- uint32_t byte_idx = 0;
- uint8_t bit_idx = 7;
- uint8_t bit = 0;
- uint8_t data = (ws2812->led_data[0] * ws2812->brightness) >> 8;
-
- lpc_disable_irq();
-
- /* Send data */
- while (byte_idx < ws2812->nb_bytes) {
- bit = (data & (0x01 << bit_idx));
-
- if (bit == 0) {
- /* "high" time : 350ns */
- gpio_port->clear = gpio_bit;
- nop();
- nop();
- nop();
- nop();
- nop();
- nop();
- nop();
- nop();
- /* "low" time : 800ns */
- gpio_port->set = gpio_bit;
- nop();
- nop();
- nop();
- nop();
- nop();
- nop();
- nop();
- nop();
- } else {
- /* "high" time : 700ns */
- gpio_port->clear = gpio_bit;
- nop();
- nop();
- nop();
- nop();
- nop();
- nop();
- nop();
- nop();
- nop();
- nop();
- nop();
- nop();
- nop();
- nop();
- nop();
- nop();
- /* "low" time : 600ns */
- gpio_port->set = gpio_bit;
- nop();
- nop();
- }
-
- /* Move to the next bit */
- if (bit_idx == 0) {
- bit_idx = 7;
- byte_idx++;
- data = (ws2812->led_data[byte_idx] * ws2812->brightness) >> 8;
- } else {
- bit_idx--;
- }
- }
-
- lpc_enable_irq();
-}
/* Send led data from internal buffer (set leds to the selected color).
* If nb_leds is 0 then all led data set using ws2812_set_pixel() since the last call
nb_leds = ws2812->max_led + 1;
}
ws2812->nb_bytes = nb_leds * 3;
- if (ws2812->inverted == 0) {
- ws2812_bit_sender(ws2812);
- } else {
- ws2812_inverted_bit_sender(ws2812);
- }
+ ws2812_bit_sender(ws2812);
return 0;
}