diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2021-11-20 15:21:32 -0700 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2021-11-20 15:21:32 -0700 |
commit | 85d993bcc6363eb20019cd5519784733b1f929c1 (patch) | |
tree | 7bb0a38313920af7f9f82ea6222dea334e63b67c | |
parent | ea2ac3d6d651ab58aec2fb320f0d015bdd4826d9 (diff) | |
download | esp32-ws2812b-85d993bcc6363eb20019cd5519784733b1f929c1.tar.gz esp32-ws2812b-85d993bcc6363eb20019cd5519784733b1f929c1.tar.bz2 esp32-ws2812b-85d993bcc6363eb20019cd5519784733b1f929c1.zip |
Got initial SPI set up.
Got the SPI to work at 2.5 MHz. Just writes a bunch of 0xaf
to make the pattern easy to see on the oscilloscope.
-rw-r--r-- | main/main.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/main/main.c b/main/main.c index 9c53c3f..b4c744f 100644 --- a/main/main.c +++ b/main/main.c @@ -3,8 +3,102 @@ #include "freertos/task.h" #include "esp_system.h" #include "esp_spi_flash.h" +#include "driver/spi_master.h" + +#ifdef CONFIG_IDF_TARGET_ESP32 +#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_DC 21 +#define PIN_NUM_RST 18 +#define PIN_NUM_BCKL 5 +#elif defined CONFIG_IDF_TARGET_ESP32S2 +#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_DC 4 +#define PIN_NUM_RST 5 +#define PIN_NUM_BCKL 6 +#elif defined CONFIG_IDF_TARGET_ESP32C3 +#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_DC 9 +#define PIN_NUM_RST 4 +#define PIN_NUM_BCKL 5 +#endif + +void ws_init() +{ +} + +uint8_t buffer[256]; 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, + }; + + 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, + }; + printf("Hello, World!\n"); + printf("miso: %d\n", PIN_NUM_MISO); + printf("mosi: %d\n", PIN_NUM_MOSI); + printf("sclk: %d\n", PIN_NUM_CLK); + + error = spi_bus_initialize(HSPI_HOST, &cfg, SPI_DMA_CH_AUTO); + printf("Bus Init\n"); + ESP_ERROR_CHECK(error); + + error = spi_bus_add_device(HSPI_HOST, &devcfg, &spi); + printf("Add Device\n"); + ESP_ERROR_CHECK(error); + + 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; + + spi_transaction_t* rt; + + 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"); + } } |