diff options
| author | gamerdonkey | 2024-08-26 17:52:56 -0500 |
|---|---|---|
| committer | gamerdonkey | 2024-08-26 17:52:56 -0500 |
| commit | 2f8dc507d3874fb930799d1b235eac3f37478a84 (patch) | |
| tree | 694e5fcc8d672d63944445659fdf493af78637fb | |
| parent | cc8633dffbbe0cefd81f34e74804787ad31d848d (diff) | |
| download | esp32-inova-led-controller-2f8dc507d3874fb930799d1b235eac3f37478a84.tar.gz esp32-inova-led-controller-2f8dc507d3874fb930799d1b235eac3f37478a84.tar.bz2 esp32-inova-led-controller-2f8dc507d3874fb930799d1b235eac3f37478a84.zip | |
Using a more accurate delay. Outputting rows with correct endian-ness.
| -rw-r--r-- | main/main.c | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/main/main.c b/main/main.c index 5ffcb6d..b5f7362 100644 --- a/main/main.c +++ b/main/main.c @@ -63,7 +63,7 @@ void app_main(void) .clock_speed_hz=1*1000*1000, //Clock out at 1 MHz .mode=0, //SPI mode 0 .spics_io_num=PIN_NUM_CS, //CS pin - .queue_size=7, //We want to be able to queue 7 transactions at a time + .queue_size=1, //We want to be able to queue 7 transactions at a time .flags=SPI_DEVICE_HALFDUPLEX, //Needed to use both data lines for output }; @@ -98,16 +98,33 @@ void app_main(void) ESP_LOG_BUFFER_HEX(TAG, pattern[7], 16); ESP_LOGI(TAG, "Done drawing pattern."); + ESP_LOGI(TAG, "Ticks per MS: %i", (int) portTICK_PERIOD_MS); + + TickType_t xLastWakeTime; + const TickType_t xFrequency = 1 / portTICK_PERIOD_MS; + xLastWakeTime = xTaskGetTickCount(); + + ESP_LOGI(TAG, "Ticks between updates: %i", (int) xFrequency); uint8_t current_row = 0; + uint16_t refresh_count = 0; + TickType_t startMillis = xTaskGetTickCount(); + TickType_t endMillis; + uint8_t i = 0; + uint16_t data; while(true) { - spi_transaction_t t; - memset(&t, 0, sizeof(t)); - t.length = NUM_COL; - t.tx_buffer = pattern[current_row]; - t.flags = SPI_TRANS_MODE_DIO; // output on two data lines. Even bits go to GREEN, odd to RED - ret = spi_device_polling_transmit(spi, &t); - ESP_ERROR_CHECK(ret); + vTaskDelayUntil(&xLastWakeTime, xFrequency); + + for(i = 0; i < (NUM_COL / 8); i++) { + spi_transaction_t t; + memset(&t, 0, sizeof(t)); + t.length = 16; + data = SPI_SWAP_DATA_TX(pattern[current_row][i], 16); + t.tx_buffer = &data; + t.flags = SPI_TRANS_MODE_DIO; // output on two data lines. Even bits go to GREEN, odd to RED + ret = spi_device_polling_transmit(spi, &t); + ESP_ERROR_CHECK(ret); + } gpio_set_level(PIN_NUM_R_LATCH, 0); gpio_set_level(PIN_NUM_R_CLK, 1); @@ -121,8 +138,13 @@ void app_main(void) if(++current_row == NUM_ROW) { current_row = 0; - } - vTaskDelay((10) / portTICK_PERIOD_MS); + if(++refresh_count == 1000) { + endMillis = xTaskGetTickCount(); + ESP_LOGI(TAG, "Refresh Rate: %f Hz", (float) refresh_count * 1000 / (endMillis - startMillis)); + refresh_count = 0; + startMillis = xTaskGetTickCount(); + } + } } } |
