diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2021-11-21 01:47:35 -0700 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2021-11-21 01:47:35 -0700 |
commit | 41574c410661c7ce9231cf9c29602f307f393276 (patch) | |
tree | eb79c417a11271961143c82b3517efceb6bff2a6 | |
parent | 47f0d11301c71819ced150deb96b7304ee10bab1 (diff) | |
download | esp32-ws2812b-41574c410661c7ce9231cf9c29602f307f393276.tar.gz esp32-ws2812b-41574c410661c7ce9231cf9c29602f307f393276.tar.bz2 esp32-ws2812b-41574c410661c7ce9231cf9c29602f307f393276.zip |
Add .clang-format and run clang-format.
-rw-r--r-- | .clang-format | 11 | ||||
-rw-r--r-- | include/drv/ws2812b.h | 3 | ||||
-rw-r--r-- | main/drv/ws2812b.c | 4 | ||||
-rw-r--r-- | main/main.c | 63 |
4 files changed, 46 insertions, 35 deletions
diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..567ff11 --- /dev/null +++ b/.clang-format @@ -0,0 +1,11 @@ +BasedOnStyle: Google +IndentWidth: 2 +BreakBeforeBraces: Custom +BraceWrapping: + AfterFunction: true +AllowShortFunctionsOnASingleLine: InlineOnly +AlignAfterOpenBracket: AlwaysBreak +BinPackArguments: false +BinPackParameters: false +ExperimentalAutoDetectBinPacking: false +AllowAllParametersOfDeclarationOnNextLine: true diff --git a/include/drv/ws2812b.h b/include/drv/ws2812b.h index 9cf35e4..b14b31a 100644 --- a/include/drv/ws2812b.h +++ b/include/drv/ws2812b.h @@ -3,6 +3,7 @@ #define INCLUDE_DRV_WS2812B_H_ #include <stdint.h> + #include "driver/spi_master.h" typedef struct { @@ -12,7 +13,7 @@ typedef struct { } ws2812b_rgb_t; typedef struct { - uint8_t* buf_; /* Buffer to hold the value to spi. */ + uint8_t* buf_; /* Buffer to hold the value to spi. */ uint32_t n_rgb; /* Number of rgb values which exist. */ ws2812b_rgb_t rgb[]; /* Colors to write. */ diff --git a/main/drv/ws2812b.c b/main/drv/ws2812b.c index aaa3c07..3ab6b41 100644 --- a/main/drv/ws2812b.c +++ b/main/drv/ws2812b.c @@ -27,7 +27,7 @@ static inline void byte_compile(uint8_t byte, uint8_t compl [3]) static inline void compile(ws2812b_buffer_t* buffer) { - for (size_t i = 0; i < buffer->n_rgb; ++ i) { + for (size_t i = 0; i < buffer->n_rgb; ++i) { byte_compile(buffer->rgb[i].g, buffer->buf_ + i * 9 + 0); byte_compile(buffer->rgb[i].r, buffer->buf_ + i * 9 + 3); byte_compile(buffer->rgb[i].b, buffer->buf_ + i * 9 + 6); @@ -48,7 +48,7 @@ esp_err_t ws2812b_write_sync(ws2812b_t* drv, ws2812b_buffer_t* buffer) esp_err_t err; compile(buffer); - spi_transaction_t t = { 0 }; + spi_transaction_t t = {0}; spi_transaction_t* rt; t.tx_buffer = buffer->buf_; diff --git a/main/main.c b/main/main.c index cffa6f5..7fbf47d 100644 --- a/main/main.c +++ b/main/main.c @@ -1,44 +1,43 @@ -#include "sdkconfig.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "esp_system.h" -#include "esp_spi_flash.h" #include "driver/spi_master.h" - #include "drv/ws2812b.h" +#include "esp_spi_flash.h" +#include "esp_system.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "sdkconfig.h" #ifdef CONFIG_IDF_TARGET_ESP32 -#define LCD_HOST HSPI_HOST +#define LCD_HOST HSPI_HOST #define PIN_NUM_MISO 25 #define PIN_NUM_MOSI 23 -#define PIN_NUM_CLK 19 -#define PIN_NUM_CS 22 +#define PIN_NUM_CLK 19 +#define PIN_NUM_CS 22 -#define PIN_NUM_DC 21 -#define PIN_NUM_RST 18 +#define PIN_NUM_DC 21 +#define PIN_NUM_RST 18 #define PIN_NUM_BCKL 5 #elif defined CONFIG_IDF_TARGET_ESP32S2 -#define LCD_HOST SPI2_HOST +#define LCD_HOST SPI2_HOST #define PIN_NUM_MISO 37 #define PIN_NUM_MOSI 35 -#define PIN_NUM_CLK 36 -#define PIN_NUM_CS 34 +#define PIN_NUM_CLK 36 +#define PIN_NUM_CS 34 -#define PIN_NUM_DC 4 -#define PIN_NUM_RST 5 +#define PIN_NUM_DC 4 +#define PIN_NUM_RST 5 #define PIN_NUM_BCKL 6 #elif defined CONFIG_IDF_TARGET_ESP32C3 -#define LCD_HOST SPI2_HOST +#define LCD_HOST SPI2_HOST #define PIN_NUM_MISO 2 #define PIN_NUM_MOSI 7 -#define PIN_NUM_CLK 6 -#define PIN_NUM_CS 10 +#define PIN_NUM_CLK 6 +#define PIN_NUM_CS 10 -#define PIN_NUM_DC 9 -#define PIN_NUM_RST 4 +#define PIN_NUM_DC 9 +#define PIN_NUM_RST 4 #define PIN_NUM_BCKL 5 #endif @@ -53,20 +52,20 @@ void app_main(void) esp_err_t error; spi_device_handle_t spi; spi_bus_config_t cfg = { - .miso_io_num = PIN_NUM_MISO, - .mosi_io_num = PIN_NUM_MOSI, - .sclk_io_num = PIN_NUM_CLK, - .quadwp_io_num = -1, - .quadhd_io_num = -1, - .max_transfer_sz = 320 * 2 + 8, + .miso_io_num = PIN_NUM_MISO, + .mosi_io_num = PIN_NUM_MOSI, + .sclk_io_num = PIN_NUM_CLK, + .quadwp_io_num = -1, + .quadhd_io_num = -1, + .max_transfer_sz = 320 * 2 + 8, }; spi_device_interface_config_t devcfg = { - .clock_speed_hz = 25 * 100 * 1000, /* 2.5 MHz */ - .mode = 0, - .spics_io_num = PIN_NUM_CS, - .queue_size = 7, - .pre_cb = NULL, + .clock_speed_hz = 25 * 100 * 1000, /* 2.5 MHz */ + .mode = 0, + .spics_io_num = PIN_NUM_CS, + .queue_size = 7, + .pre_cb = NULL, }; printf("Hello, World!\n"); |