mirror of
https://github.com/demik/quack.git
synced 2025-04-06 20:37:28 +00:00
starting to work with LEDs
This commit is contained in:
parent
28f9a929db
commit
54fabf05c3
@ -1,6 +1,7 @@
|
||||
set(srcs "blue.c"
|
||||
"esp_hid_gap.c"
|
||||
"gpio.c"
|
||||
"led.c"
|
||||
"main.c")
|
||||
|
||||
set(include_dirs ".")
|
||||
|
17
main/gpio.c
17
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);
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
45
main/led.c
Normal file
45
main/led.c
Normal file
@ -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 <stdio.h>
|
||||
#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);
|
||||
}
|
||||
}
|
33
main/led.h
Normal file
33
main/led.h
Normal file
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user