diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 6efbde8..179b749 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,6 +1,7 @@ set(srcs "blue.c" "esp_hid_gap.c" "gpio.c" + "led.c" "main.c") set(include_dirs ".") diff --git a/main/gpio.c b/main/gpio.c index 75e977c..1f5461b 100644 --- a/main/gpio.c +++ b/main/gpio.c @@ -17,12 +17,13 @@ #include "gpio.h" void gpio_init(void) { - gpio_reset_pin(GREENLED_GPIO); - gpio_set_direction(GREENLED_GPIO, GPIO_MODE_OUTPUT); - - /* do a half second blink for debug mode */ - gpio_set_level(GREENLED_GPIO, 1); - vTaskDelay(500 / portTICK_PERIOD_MS); - gpio_set_level(GREENLED_GPIO, 0); - vTaskDelay(500 / portTICK_PERIOD_MS); + /* LEDs */ + gpio_reset_pin(GPIO_GREENLED); + gpio_reset_pin(GPIO_BLUELED); + gpio_reset_pin(GPIO_YELLOWLED); + gpio_reset_pin(GPIO_REDLED); + gpio_set_direction(GPIO_GREENLED, GPIO_MODE_OUTPUT); + gpio_set_direction(GPIO_BLUELED, GPIO_MODE_OUTPUT); + gpio_set_direction(GPIO_YELLOWLED, GPIO_MODE_OUTPUT); + gpio_set_direction(GPIO_REDLED, GPIO_MODE_OUTPUT); } diff --git a/main/gpio.h b/main/gpio.h index fc4d945..f0ddaf5 100644 --- a/main/gpio.h +++ b/main/gpio.h @@ -56,9 +56,9 @@ void gpio_init(void); #define QY1_GPIO 14 #define QY2_GPIO 15 -#define GREENLED_GPIO 21 -#define BLUELED_GPIO 25 -#define YELLOWLED_GPIO 26 -#define REDLED_GPIO 27 +#define GPIO_GREENLED 21 +#define GPIO_BLUELED 25 +#define GPIO_YELLOWLED 26 +#define GPIO_REDLED 27 #endif diff --git a/main/led.c b/main/led.c new file mode 100644 index 0000000..61ed8cc --- /dev/null +++ b/main/led.c @@ -0,0 +1,45 @@ +/* Hello World 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 +#include "driver/gpio.h" +#include "sdkconfig.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "esp_system.h" +#include "esp_spi_flash.h" + +#include "led.h" +#include "gpio.h" + +void led_init(void) { + BaseType_t r; + TaskHandle_t green, blue, yellow, red; + + /* blink allds LEDs once */ + gpio_set_level(GPIO_GREENLED, 1); + gpio_set_level(GPIO_BLUELED, 1); + gpio_set_level(GPIO_YELLOWLED, 1); + gpio_set_level(GPIO_REDLED, 1); + vTaskDelay(125 / portTICK_PERIOD_MS); + gpio_set_level(GPIO_GREENLED, 0); + gpio_set_level(GPIO_BLUELED, 0); + gpio_set_level(GPIO_YELLOWLED, 0); + gpio_set_level(GPIO_REDLED, 0); + + r = xTaskCreate(led_task, "GREEN", 1024, (void *) GPIO_GREENLED, tskIDLE_PRIORITY, &green); +} + +void led_task(void *pvParameters) { + while (1) { + gpio_set_level(GPIO_GREENLED, 1); + vTaskDelay(75 / portTICK_PERIOD_MS); + gpio_set_level(GPIO_GREENLED, 0); + vTaskDelay(75 / portTICK_PERIOD_MS); + } +} diff --git a/main/led.h b/main/led.h new file mode 100644 index 0000000..5c508f6 --- /dev/null +++ b/main/led.h @@ -0,0 +1,33 @@ +/* + * led.h + * quack + * + * Created by Michel DEPEIGE on 15/12/2020. + * Copyright (c) 2020 Michel DEPEIGE. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (see the file COPYING); if not, write to the + * Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + */ + +#ifndef LED_H +#define LED_H + +/* prototypes */ +void led_init(void); +void led_task(void *pvParameters); + +#endif + diff --git a/main/main.c b/main/main.c index 9ff00f0..a23c817 100644 --- a/main/main.c +++ b/main/main.c @@ -16,6 +16,7 @@ #include "esp_spi_flash.h" #include "blue.h" +#include "led.h" #include "gpio.h" static const char* TAG = "quack"; @@ -38,5 +39,6 @@ void app_main(void) ESP_LOGI(TAG, "Minimum free heap size: %d bytes", esp_get_minimum_free_heap_size()); gpio_init(); + led_init(); blue_init(); } diff --git a/sdkconfig b/sdkconfig index 8c756c7..7d9a7b2 100644 --- a/sdkconfig +++ b/sdkconfig @@ -91,9 +91,9 @@ CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y # CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set CONFIG_ESPTOOLPY_FLASHSIZE="4MB" CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y -CONFIG_ESPTOOLPY_BEFORE_RESET=y -# CONFIG_ESPTOOLPY_BEFORE_NORESET is not set -CONFIG_ESPTOOLPY_BEFORE="default_reset" +# CONFIG_ESPTOOLPY_BEFORE_RESET is not set +CONFIG_ESPTOOLPY_BEFORE_NORESET=y +CONFIG_ESPTOOLPY_BEFORE="no_reset" CONFIG_ESPTOOLPY_AFTER_RESET=y # CONFIG_ESPTOOLPY_AFTER_NORESET is not set CONFIG_ESPTOOLPY_AFTER="hard_reset"