aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main/main.c42
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();
+ }
+ }
}
}