ws2812b: minor, put spaces around operators

This commit is contained in:
King Kévin 2020-02-17 14:01:54 +01:00
parent a880df4c0a
commit 330a08adc0
2 changed files with 19 additions and 19 deletions

View File

@ -12,10 +12,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/** library to drive a WS2812B LED chain (code)
* @file led_ws2812b.c
/** library to drive a WS2812B LED chain
* @file
* @author King Kévin <kingkevin@cuvoodoo.info>
* @date 2016-2017
* @date 2016-2020
* @note peripherals used: SPI @ref led_ws2812b_spi, timer @ref led_ws2812b_timer, DMA (for SPI MISO)
*/
@ -59,13 +59,13 @@
*/
#define LED_WS2812B_SPI_TEMPLATE 0x924924
uint8_t led_ws2812b_data[LED_WS2812B_LEDS*3*3+40*3/8+1] = {0}; /**< data encoded to be shifted out by SPI for the WS2812B, plus the 50us reset (~40 data bits) */
uint8_t led_ws2812b_data[LED_WS2812B_LEDS * 3 * 3 + 40 * 3 / 8 + 1] = {0}; /**< data encoded to be shifted out by SPI for the WS2812B, plus the 50us reset (~40 data bits) */
static volatile bool transmit_flag = false; /**< flag set in software when transmission started, clear by interrupt when transmission completed */
void led_ws2812b_set_rgb(uint16_t led, uint8_t red, uint8_t green, uint8_t blue)
{
// verify the led exists
if (led>=LED_WS2812B_LEDS) {
if (led >= LED_WS2812B_LEDS) {
return;
}
// wait for transmission to complete before changing the color
@ -75,14 +75,14 @@ void led_ws2812b_set_rgb(uint16_t led, uint8_t red, uint8_t green, uint8_t blue)
const uint8_t colors[] = {green, red, blue}; // color order for the WS2812B
const uint8_t pattern_bit[] = {0x02, 0x10, 0x80, 0x04, 0x20, 0x01, 0x08, 0x40}; // which bit to change in the pattern
const uint8_t pattern_byte[] = {2,2,2,1,1,0,0,0}; // in which byte in the pattern to write the pattern bit
for (uint8_t color=0; color<LENGTH(colors); color++) { // colors are encoded similarly
const uint8_t pattern_byte[] = {2, 2, 2, 1, 1, 0, 0, 0}; // in which byte in the pattern to write the pattern bit
for (uint8_t color = 0; color < LENGTH(colors); color++) { // colors are encoded similarly
// fill the middle bit (fixed is faster than calculating it)
for (uint8_t bit=0; bit<8; bit++) { // bit from the color to set/clear
if (colors[color]&(1<<bit)) { // setting bit
led_ws2812b_data[led*3*3+color*3+pattern_byte[bit]] |= pattern_bit[bit]; // setting bit is pattern
for (uint8_t bit = 0; bit < 8; bit++) { // bit from the color to set/clear
if (colors[color] & (1 << bit)) { // setting bit
led_ws2812b_data[led * 3 * 3 + color * 3 + pattern_byte[bit]] |= pattern_bit[bit]; // setting bit is pattern
} else { // clear bit
led_ws2812b_data[led*3*3+color*3+pattern_byte[bit]] &= ~pattern_bit[bit]; // clearing bit is pattern
led_ws2812b_data[led * 3 * 3 + color * 3 + pattern_byte[bit]] &= ~pattern_bit[bit]; // clearing bit is pattern
}
}
}
@ -154,13 +154,13 @@ void led_ws2812b_setup(void)
nvic_enable_irq(DMA_IRQ_SPI_TX(LED_WS2812B_SPI)); // enable interrupts for this DMA channel
// fill buffer with bit pattern
for (uint16_t i=0; i<LED_WS2812B_LEDS*3; i++) {
led_ws2812b_data[i*3+0] = (uint8_t)(LED_WS2812B_SPI_TEMPLATE>>16);
led_ws2812b_data[i*3+1] = (uint8_t)(LED_WS2812B_SPI_TEMPLATE>>8);
led_ws2812b_data[i*3+2] = (uint8_t)(LED_WS2812B_SPI_TEMPLATE>>0);
for (uint16_t i = 0; i < LED_WS2812B_LEDS * 3; i++) {
led_ws2812b_data[i * 3 + 0] = (uint8_t)(LED_WS2812B_SPI_TEMPLATE >> 16);
led_ws2812b_data[i * 3 + 1] = (uint8_t)(LED_WS2812B_SPI_TEMPLATE >> 8);
led_ws2812b_data[i * 3 + 2] = (uint8_t)(LED_WS2812B_SPI_TEMPLATE >> 0);
}
// fill remaining with with 0 to encode the reset code
for (uint16_t i=LED_WS2812B_LEDS*3*3; i<LENGTH(led_ws2812b_data); i++) {
for (uint16_t i = LED_WS2812B_LEDS * 3 * 3; i < LENGTH(led_ws2812b_data); i++) {
led_ws2812b_data[i] = 0;
}
led_ws2812b_transmit(); // set LEDs

View File

@ -12,10 +12,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/** library to drive a WS2812B LED chain (API)
* @file led_ws2812b.h
/** library to drive a WS2812B LED chain
* @file
* @author King Kévin <kingkevin@cuvoodoo.info>
* @date 2016-2017
* @date 2016-2020
* @note peripherals used: SPI @ref led_ws2812b_spi, timer @ref led_ws2812b_timer, DMA (for SPI MISO)
*/
#pragma once