aboutsummaryrefslogtreecommitdiff
path: root/main/main.c
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2021-12-02 17:19:00 -0700
committerJosh Rahm <joshuarahm@gmail.com>2021-12-02 17:19:00 -0700
commit8d379bf60e50960f6c855cd6b9c83956a082f73d (patch)
treeabc799411d565f7e0330ceb6d2db5818ea987d6a /main/main.c
parent62715093e446d952bbc3fa82fdb65deacd576be2 (diff)
downloadesp32-ws2812b-8d379bf60e50960f6c855cd6b9c83956a082f73d.tar.gz
esp32-ws2812b-8d379bf60e50960f6c855cd6b9c83956a082f73d.tar.bz2
esp32-ws2812b-8d379bf60e50960f6c855cd6b9c83956a082f73d.zip
Break out the state parmaters into their own include file.
This helps by creating one location to add state parameters.
Diffstat (limited to 'main/main.c')
-rw-r--r--main/main.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/main/main.c b/main/main.c
index 691043d..9cd4f0f 100644
--- a/main/main.c
+++ b/main/main.c
@@ -46,6 +46,26 @@
static ws_params_t ws_params;
+/* Ticks the clock at a constant rate independent of the time it takes to write
+ * to the led strip. */
+portTASK_FUNCTION(time_keeper, params_)
+{
+ ws_params_t* params = (ws_params_t*) params_;
+
+ TickType_t last_wake;
+ const TickType_t freq = 1;
+
+ // Initialise the xLastWakeTime variable with the current time.
+ last_wake = xTaskGetTickCount();
+
+ for( ;; )
+ {
+ // Wait for the next cycle.
+ vTaskDelayUntil( &last_wake, freq );
+ params->state.time += params->state.timetick;
+ }
+}
+
void app_main(void)
{
esp_err_t error;
@@ -71,6 +91,7 @@ void app_main(void)
printf("miso: %d\n", PIN_NUM_MISO);
printf("mosi: %d\n", PIN_NUM_MOSI);
printf("sclk: %d\n", PIN_NUM_CLK);
+ printf("Tick period ms: %d\n", portTICK_PERIOD_MS);
error = spi_bus_initialize(HSPI_HOST, &cfg, SPI_DMA_CH_AUTO);
printf("Bus Init\n");
@@ -84,6 +105,7 @@ void app_main(void)
printf("Configuration complete!!\n");
+ xTaskCreate(time_keeper, "time_keeper", 1024, &ws_params, 1, NULL);
xTaskCreate(ws2812b_write_task, "ws2812b_writer", 4096, &ws_params, 1, NULL);
xTaskCreate(tcp_server, "tcp_server", 4096, &ws_params, 2, NULL);
}