diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2021-11-21 01:43:23 -0700 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2021-11-21 01:43:23 -0700 |
commit | 47f0d11301c71819ced150deb96b7304ee10bab1 (patch) | |
tree | 8f7dd394bb859d04c3cdb21d9ad4e8143f2ae1c3 /main/main.c | |
parent | 85d993bcc6363eb20019cd5519784733b1f929c1 (diff) | |
download | esp32-ws2812b-47f0d11301c71819ced150deb96b7304ee10bab1.tar.gz esp32-ws2812b-47f0d11301c71819ced150deb96b7304ee10bab1.tar.bz2 esp32-ws2812b-47f0d11301c71819ced150deb96b7304ee10bab1.zip |
Add crude ws2812b driver.
This driver can run lights! However it is very crude and does not
provide a great API. It does work though! Currently lights up 5 leds of
different colors.
Right now this does synchronous writes, which is not the best. It would
be better to be async, but I think that sholud not be a problem and will
shortly be done.
Diffstat (limited to 'main/main.c')
-rw-r--r-- | main/main.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/main/main.c b/main/main.c index b4c744f..cffa6f5 100644 --- a/main/main.c +++ b/main/main.c @@ -5,6 +5,8 @@ #include "esp_spi_flash.h" #include "driver/spi_master.h" +#include "drv/ws2812b.h" + #ifdef CONFIG_IDF_TARGET_ESP32 #define LCD_HOST HSPI_HOST @@ -82,23 +84,19 @@ void app_main(void) printf("Configuration complete!!\n"); - for (int i = 0; i < sizeof(buffer); ++ i) { - buffer[i] = 0xfa; - } - - spi_transaction_t t = {0}; - t.tx_buffer = buffer; - t.length = sizeof(buffer) * 8; + ws2812b_t* drv = ws2812b_init(spi); + ws2812b_buffer_t* buffer = ws2812b_new_buffer(5); - spi_transaction_t* rt; + ws2812b_buffer_set_rgb(buffer, 0, 255, 0, 0); + ws2812b_buffer_set_rgb(buffer, 1, 0, 255, 0); + ws2812b_buffer_set_rgb(buffer, 2, 0, 0, 255); + ws2812b_buffer_set_rgb(buffer, 3, 255, 255, 0); + ws2812b_buffer_set_rgb(buffer, 4, 255, 0, 255); while (1) { - error = spi_device_queue_trans(spi, &t, portMAX_DELAY); - assert(error == ESP_OK); - printf("SPI Transaction Equeued!!\n"); - - error = spi_device_get_trans_result(spi, &rt, portMAX_DELAY); - assert(error == ESP_OK); - printf("SPI Transaction Sent!!\n"); + ws2812b_write_sync(drv, buffer); + // TODO(rahm) push this into the sync write, or otherwise make this better + // to deal with. + vTaskDelay(10 / portTICK_PERIOD_MS); } } |