/* Multitasking Example
 
   This example code is in the Public Domain (or CC0 licensed, at your option.)
 
   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"

#define LED_RED GPIO_NUM_2
#define LED_GREEN GPIO_NUM_4
#define LED_BLUE GPIO_NUM_5

struct led_task_parameters_t
{
    gpio_num_t led_gpio;
    TickType_t blink_time;
};

static led_task_parameters_t red_led_gpio = {LED_RED, 500};
static led_task_parameters_t blue_led_gpio = {LED_BLUE, 1000};
static led_task_parameters_t green_led_gpio = {LED_GREEN, 2000};
 

void led_task(void *pvParameter)
{
    gpio_num_t led_gpio = ((led_task_parameters_t *)pvParameter)->led_gpio;
    TickType_t blink_time = ((led_task_parameters_t *)pvParameter)->blink_time;
    uint8_t led_value = 0;
    gpio_reset_pin(led_gpio);
    gpio_set_direction(led_gpio, GPIO_MODE_OUTPUT);


    while (1) {
        gpio_set_level(led_gpio, led_value);
        led_value = !led_value;
        vTaskDelay(blink_time / portTICK_PERIOD_MS);
    }
    vTaskDelete( NULL );
}


extern "C" void app_main()
{   
    xTaskCreate(
    &led_task, // task function  
    "red_led_task", // task name
    2048, // stack size in words
    &red_led_gpio, // pointer to parameters
    5, // priority
    NULL); // out pointer to task handle

    xTaskCreate(
    &led_task, // task function  
    "blue_led_task", // task name
    2048, // stack size in words
    &blue_led_gpio, // pointer to parameters
    5, // priority
    NULL); // out pointer to task handle

    xTaskCreate(
    &led_task, // task function  
    "green_led_task", // task name
    2048, // stack size in words
    &green_led_gpio, // pointer to parameters
    5, // priority
    NULL); // out pointer to task handle
}
esp:VIN
esp:GND.2
esp:D13
esp:D12
esp:D14
esp:D27
esp:D26
esp:D25
esp:D33
esp:D32
esp:D35
esp:D34
esp:VN
esp:VP
esp:EN
esp:3V3
esp:GND.1
esp:D15
esp:D2
esp:D4
esp:RX2
esp:TX2
esp:D5
esp:D18
esp:D19
esp:D21
esp:RX0
esp:TX0
esp:D22
esp:D23
led-red:A
led-red:C
led-green:A
led-green:C
led-blue:A
led-blue:C