diff --git a/epicardium/modules/ws2812.c b/epicardium/modules/ws2812.c index 2ee08387b833e7bef70769f0801327e9db50cbd8..fc41d2a9876172f3cf9d1dbf5f9689a0288f8e84 100644 --- a/epicardium/modules/ws2812.c +++ b/epicardium/modules/ws2812.c @@ -13,39 +13,37 @@ #define OVERHEAD 33 #define EPIC_WS2812_ZERO_HIGH_TICKS 34 - OVERHEAD -#define EPIC_WS2812_ZERO_LOW_TICKS 86 - OVERHEAD -#define EPIC_WS2812_ONE_HIGH_TICKS 86 - OVERHEAD -#define EPIC_WS2812_ONE_LOW_TICKS 34 - OVERHEAD -#define EPIC_WS2812_RESET_TCKS 4800 - OVERHEAD +#define EPIC_WS2812_ZERO_LOW_TICKS 86 - OVERHEAD +#define EPIC_WS2812_ONE_HIGH_TICKS 86 - OVERHEAD +#define EPIC_WS2812_ONE_LOW_TICKS 34 - OVERHEAD +#define EPIC_WS2812_RESET_TCKS 4800 - OVERHEAD -#define EPIC_WS2812_DELAY_TICKS(ticks) \ - counter = ticks; \ - while (--counter); +#define EPIC_WS2812_DELAY_TICKS(ticks) \ + counter = ticks; \ + while (--counter) \ + ; -#define EPIC_WS2812_TRANSMIT_BIT(pin, bit) \ - if ((bit) != 0) \ - { \ - GPIO_OutSet(pin); \ - EPIC_WS2812_DELAY_TICKS(EPIC_WS2812_ONE_HIGH_TICKS); \ - GPIO_OutClr(pin); \ - EPIC_WS2812_DELAY_TICKS(EPIC_WS2812_ONE_LOW_TICKS); \ - } \ - else \ - { \ - GPIO_OutSet(pin); \ - EPIC_WS2812_DELAY_TICKS(EPIC_WS2812_ZERO_HIGH_TICKS); \ - GPIO_OutClr(pin); \ - EPIC_WS2812_DELAY_TICKS(EPIC_WS2812_ZERO_LOW_TICKS); \ +#define EPIC_WS2812_TRANSMIT_BIT(pin, bit) \ + if ((bit) != 0) { \ + GPIO_OutSet(pin); \ + EPIC_WS2812_DELAY_TICKS(EPIC_WS2812_ONE_HIGH_TICKS); \ + GPIO_OutClr(pin); \ + EPIC_WS2812_DELAY_TICKS(EPIC_WS2812_ONE_LOW_TICKS); \ + } else { \ + GPIO_OutSet(pin); \ + EPIC_WS2812_DELAY_TICKS(EPIC_WS2812_ZERO_HIGH_TICKS); \ + GPIO_OutClr(pin); \ + EPIC_WS2812_DELAY_TICKS(EPIC_WS2812_ZERO_LOW_TICKS); \ } -#define EPIC_WS2812_TRANSMIT_BYTE(pin, byte) \ - EPIC_WS2812_TRANSMIT_BIT(pin, byte & 0b10000000); \ - EPIC_WS2812_TRANSMIT_BIT(pin, byte & 0b01000000); \ - EPIC_WS2812_TRANSMIT_BIT(pin, byte & 0b00100000); \ - EPIC_WS2812_TRANSMIT_BIT(pin, byte & 0b00010000); \ - EPIC_WS2812_TRANSMIT_BIT(pin, byte & 0b00001000); \ - EPIC_WS2812_TRANSMIT_BIT(pin, byte & 0b00000100); \ - EPIC_WS2812_TRANSMIT_BIT(pin, byte & 0b00000010); \ +#define EPIC_WS2812_TRANSMIT_BYTE(pin, byte) \ + EPIC_WS2812_TRANSMIT_BIT(pin, byte & 0b10000000); \ + EPIC_WS2812_TRANSMIT_BIT(pin, byte & 0b01000000); \ + EPIC_WS2812_TRANSMIT_BIT(pin, byte & 0b00100000); \ + EPIC_WS2812_TRANSMIT_BIT(pin, byte & 0b00010000); \ + EPIC_WS2812_TRANSMIT_BIT(pin, byte & 0b00001000); \ + EPIC_WS2812_TRANSMIT_BIT(pin, byte & 0b00000100); \ + EPIC_WS2812_TRANSMIT_BIT(pin, byte & 0b00000010); \ EPIC_WS2812_TRANSMIT_BIT(pin, byte & 0b00000001); void epic_ws2812_write(uint8_t pin, uint8_t *pixels, uint32_t n_bytes) @@ -58,8 +56,7 @@ void epic_ws2812_write(uint8_t pin, uint8_t *pixels, uint32_t n_bytes) epic_gpio_set_pin_mode(pin, EPIC_GPIO_MODE_OUT); - do - { + do { EPIC_WS2812_TRANSMIT_BYTE(pin_cfg, *pixels); } while (++pixels != pixels_end); diff --git a/pycardium/modules/ws2812.c b/pycardium/modules/ws2812.c index 928ab2d91a172fb5e253b8c8ad90fce2527168b0..ce8ad6014ca00b9c05a3292a9a0fef5b4331eee9 100644 --- a/pycardium/modules/ws2812.c +++ b/pycardium/modules/ws2812.c @@ -8,16 +8,13 @@ /* Define the pixel write function in this module */ static mp_obj_t mp_ws2812_write(mp_obj_t pin, mp_obj_t pixels) { - mp_int_t pin_int = mp_obj_get_int(pin); + mp_int_t pin_int = mp_obj_get_int(pin); mp_int_t pixels_len = mp_obj_get_int(mp_obj_len(pixels)); uint8_t *pixels_arr = alloca(pixels_len * sizeof(uint8_t)); - for (int i = 0; i < pixels_len; i++) - { + for (int i = 0; i < pixels_len; i++) { mp_obj_t elem = mp_obj_subscr( - pixels, - MP_OBJ_NEW_SMALL_INT(i), - MP_OBJ_SENTINEL + pixels, MP_OBJ_NEW_SMALL_INT(i), MP_OBJ_SENTINEL ); pixels_arr[i] = mp_obj_get_int(elem); @@ -32,14 +29,14 @@ static MP_DEFINE_CONST_FUN_OBJ_2(ws2812_write_obj, mp_ws2812_write); /* The globals table for this module */ static const mp_rom_map_elem_t ws2812_module_globals_table[] = { - {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ws2812)}, - {MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&ws2812_write_obj)}, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ws2812) }, + { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&ws2812_write_obj) }, }; static MP_DEFINE_CONST_DICT(ws2812_module_globals, ws2812_module_globals_table); const mp_obj_module_t ws2812_module = { - .base = {&mp_type_module}, - .globals = (mp_obj_dict_t*) &ws2812_module_globals, + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&ws2812_module_globals, }; /* This is a special macro that will make MicroPython aware of this module */