Blink rate queue
This commit is contained in:
parent
53540d9fb4
commit
615574685d
3 changed files with 43 additions and 4 deletions
|
@ -1,8 +1,16 @@
|
|||
#include "freertos/idf_additions.h"
|
||||
#include "freertos/projdefs.h"
|
||||
#include "tasks.h"
|
||||
#include <stdio.h>
|
||||
|
||||
extern QueueHandle_t blink_rate_q;
|
||||
|
||||
void app_main(void) {
|
||||
TaskHandle_t task_handle_blink;
|
||||
blink_rate_q = xQueueCreate(10, sizeof(BlinkRate_t));
|
||||
|
||||
xTaskCreate(task_blink, "task_blink", 1024, NULL, 0, &task_handle_blink);
|
||||
|
||||
BlinkRate_t br = {1000};
|
||||
xQueueSend(blink_rate_q, &br, pdMS_TO_TICKS(20));
|
||||
}
|
||||
|
|
|
@ -7,14 +7,23 @@
|
|||
|
||||
#include "tasks.h"
|
||||
|
||||
QueueHandle_t blink_rate_q;
|
||||
|
||||
void task_blink(void *pvParams) {
|
||||
u32 blink_delay = BLINK_DELAY;
|
||||
u32 new_delay = {};
|
||||
u32 level = 1;
|
||||
|
||||
esp_rom_gpio_pad_select_gpio(LED_PIN);
|
||||
gpio_set_direction(LED_PIN, GPIO_MODE_OUTPUT);
|
||||
|
||||
while (1) {
|
||||
gpio_set_level(LED_PIN, 0);
|
||||
vTaskDelay(BLINK_DELAY / portTICK_PERIOD_MS);
|
||||
gpio_set_level(LED_PIN, 1);
|
||||
vTaskDelay(BLINK_DELAY / portTICK_PERIOD_MS);
|
||||
if (xQueueReceive(blink_rate_q, &new_delay, 0) == pdPASS)
|
||||
blink_delay = new_delay;
|
||||
|
||||
level = !level;
|
||||
|
||||
gpio_set_level(LED_PIN, level);
|
||||
vTaskDelay(blink_delay / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
|
22
main/tasks.h
22
main/tasks.h
|
@ -1,6 +1,9 @@
|
|||
#ifndef TASKS_H
|
||||
#define TASKS_H
|
||||
|
||||
#include "freertos/idf_additions.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/*
|
||||
* This file exports all the individual tasks, avoiding tons of semi-empty headers.
|
||||
*/
|
||||
|
@ -9,6 +12,25 @@
|
|||
#define RATE_PER_S 10
|
||||
#define BLINK_DELAY (1000 / 2 / RATE_PER_S)
|
||||
|
||||
typedef uint8_t u8;
|
||||
typedef uint16_t u16;
|
||||
typedef uint32_t u32;
|
||||
typedef uint64_t u64;
|
||||
|
||||
typedef int8_t s8;
|
||||
typedef int16_t s16;
|
||||
typedef int32_t s32;
|
||||
typedef int64_t s64;
|
||||
|
||||
typedef float f32;
|
||||
typedef double f64;
|
||||
|
||||
// typedef enum { false = 0, true = 1 } bool;
|
||||
|
||||
typedef struct {
|
||||
u32 rate;
|
||||
} BlinkRate_t;
|
||||
|
||||
void task_blink(void *pvParams);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue