src refactor
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -17,3 +17,4 @@ pcb/panel/*
|
|||||||
sdkconfig
|
sdkconfig
|
||||||
sdkconfig.old
|
sdkconfig.old
|
||||||
|
|
||||||
|
.vscode/*
|
||||||
|
|||||||
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"idf.pythonInstallPath": "/usr/bin/python3"
|
|
||||||
}
|
|
||||||
@@ -34,7 +34,7 @@ menu "Example Configuration"
|
|||||||
config BLINK_GPIO
|
config BLINK_GPIO
|
||||||
int "Blink GPIO number"
|
int "Blink GPIO number"
|
||||||
range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX
|
range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX
|
||||||
default 2
|
default 4
|
||||||
help
|
help
|
||||||
GPIO number (IOxx) to blink on and off the LED.
|
GPIO number (IOxx) to blink on and off the LED.
|
||||||
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to blink.
|
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to blink.
|
||||||
@@ -42,7 +42,7 @@ menu "Example Configuration"
|
|||||||
config BLINK_PERIOD
|
config BLINK_PERIOD
|
||||||
int "Blink period in ms"
|
int "Blink period in ms"
|
||||||
range 10 3600000
|
range 10 3600000
|
||||||
default 1000
|
default 500
|
||||||
help
|
help
|
||||||
Define the blinking period in milliseconds.
|
Define the blinking period in milliseconds.
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
CONFIG_BLINK_LED_GPIO=y
|
|
||||||
CONFIG_BLINK_GPIO=2
|
CONFIG_BLINK_PERIOD=100
|
||||||
@@ -5,6 +5,9 @@ set -e
|
|||||||
export IDF_TOOLS_PATH=${PWD}/lib/idf-tools
|
export IDF_TOOLS_PATH=${PWD}/lib/idf-tools
|
||||||
export IDF_PATH=${PWD}/lib/esp-idf
|
export IDF_PATH=${PWD}/lib/esp-idf
|
||||||
|
|
||||||
|
export SDKCONFIG=${PWD}/config/sdkconfig
|
||||||
|
export SDKCONFIG_DEFAULTS=${PWD}/config/sdkconfig.defaults
|
||||||
|
|
||||||
. ${IDF_PATH}/export.sh
|
. ${IDF_PATH}/export.sh
|
||||||
|
|
||||||
idf.py fullclean
|
idf.py fullclean
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
|
|
||||||
idf_component_register(SRCS "main.cpp"
|
file(GLOB SRC_FILES "*.c" "*.cpp")
|
||||||
|
|
||||||
|
idf_component_register(
|
||||||
|
SRCS ${SRC_FILES}
|
||||||
PRIV_REQUIRES spi_flash
|
PRIV_REQUIRES spi_flash
|
||||||
REQUIRES esp_driver_gpio
|
REQUIRES esp_driver_gpio
|
||||||
INCLUDE_DIRS ".")
|
INCLUDE_DIRS "."
|
||||||
|
)
|
||||||
107
src/main.cpp
107
src/main.cpp
@@ -1,112 +1,21 @@
|
|||||||
/* Blink Example
|
|
||||||
|
|
||||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
#include "App.hpp"
|
||||||
|
|
||||||
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"
|
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "sdkconfig.h"
|
|
||||||
|
|
||||||
#ifdef CONFIG_BLINK_LED_STRIP
|
static const char *TAG = "main";
|
||||||
#include "led_strip.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static const char *TAG = "example";
|
|
||||||
|
|
||||||
/* Use project configuration menu (idf.py menuconfig) to choose the GPIO to blink,
|
|
||||||
or you can edit the following line and set a number here.
|
|
||||||
*/
|
|
||||||
#define BLINK_GPIO CONFIG_BLINK_GPIO
|
|
||||||
|
|
||||||
static uint8_t s_led_state = 0;
|
|
||||||
|
|
||||||
#ifdef CONFIG_BLINK_LED_STRIP
|
|
||||||
|
|
||||||
static led_strip_handle_t led_strip;
|
|
||||||
|
|
||||||
static void blink_led(void)
|
|
||||||
{
|
|
||||||
/* If the addressable LED is enabled */
|
|
||||||
if (s_led_state) {
|
|
||||||
/* Set the LED pixel using RGB from 0 (0%) to 255 (100%) for each color */
|
|
||||||
led_strip_set_pixel(led_strip, 0, 16, 16, 16);
|
|
||||||
/* Refresh the strip to send data */
|
|
||||||
led_strip_refresh(led_strip);
|
|
||||||
} else {
|
|
||||||
/* Set all LED off to clear all pixels */
|
|
||||||
led_strip_clear(led_strip);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void configure_led(void)
|
|
||||||
{
|
|
||||||
ESP_LOGI(TAG, "Example configured to blink addressable LED!");
|
|
||||||
/* LED strip initialization with the GPIO and pixels number*/
|
|
||||||
led_strip_config_t strip_config = {
|
|
||||||
.strip_gpio_num = BLINK_GPIO,
|
|
||||||
.max_leds = 1, // at least one LED on board
|
|
||||||
};
|
|
||||||
#if CONFIG_BLINK_LED_STRIP_BACKEND_RMT
|
|
||||||
led_strip_rmt_config_t rmt_config = {
|
|
||||||
.resolution_hz = 10 * 1000 * 1000, // 10MHz
|
|
||||||
.flags.with_dma = false,
|
|
||||||
};
|
|
||||||
ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip));
|
|
||||||
#elif CONFIG_BLINK_LED_STRIP_BACKEND_SPI
|
|
||||||
led_strip_spi_config_t spi_config = {
|
|
||||||
.spi_bus = SPI2_HOST,
|
|
||||||
.flags.with_dma = true,
|
|
||||||
};
|
|
||||||
ESP_ERROR_CHECK(led_strip_new_spi_device(&strip_config, &spi_config, &led_strip));
|
|
||||||
#else
|
|
||||||
#error "unsupported LED strip backend"
|
|
||||||
#endif
|
|
||||||
/* Set all LED off to clear all pixels */
|
|
||||||
led_strip_clear(led_strip);
|
|
||||||
}
|
|
||||||
|
|
||||||
#elif CONFIG_BLINK_LED_GPIO
|
|
||||||
|
|
||||||
static void blink_led(void)
|
|
||||||
{
|
|
||||||
/* Set the GPIO level according to the state (LOW or HIGH)*/
|
|
||||||
gpio_set_level((gpio_num_t)BLINK_GPIO, s_led_state);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void configure_led(void)
|
|
||||||
{
|
|
||||||
ESP_LOGI(TAG, "Example configured to blink GPIO LED!");
|
|
||||||
gpio_reset_pin((gpio_num_t)BLINK_GPIO);
|
|
||||||
/* Set the GPIO as a push/pull output */
|
|
||||||
gpio_set_direction((gpio_num_t)BLINK_GPIO, GPIO_MODE_OUTPUT);
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
#error "unsupported LED type"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void app_main(void)
|
void app_main(void) {
|
||||||
{
|
|
||||||
/* Configure the peripheral according to the LED type */
|
|
||||||
configure_led();
|
|
||||||
|
|
||||||
while (1) {
|
ESP_LOGI(TAG, "Program start");
|
||||||
ESP_LOGI(TAG, "Turning the LED %s!", s_led_state == true ? "ON" : "OFF");
|
|
||||||
blink_led();
|
App app;
|
||||||
/* Toggle the LED state */
|
int8_t status = app.main();
|
||||||
s_led_state = !s_led_state;
|
ESP_LOGI(TAG, "App main returned status %d", status);
|
||||||
vTaskDelay(CONFIG_BLINK_PERIOD / portTICK_PERIOD_MS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
Reference in New Issue
Block a user