24 changed files with 2703 additions and 792 deletions
@ -1,3 +1,9 @@ |
|||
[submodule "components/esp32-camera"] |
|||
path = components/esp32-camera |
|||
url = https://github.com/espressif/esp32-camera.git |
|||
[submodule "components/esp-dl"] |
|||
path = components/esp-dl |
|||
url = https://github.com/espressif/esp-dl.git |
|||
[submodule "components/esp-sr"] |
|||
path = components/esp-sr |
|||
url = https://github.com/espressif/esp-sr.git |
|||
|
@ -1,4 +1,4 @@ |
|||
file(GLOB_RECURSE SOURCES ./*.c) |
|||
file(GLOB_RECURSE SOURCES ./*.c ./*.cpp ./init/*.c) |
|||
set(COMPONENT_SRCS ${SOURCES}) |
|||
|
|||
register_component() |
|||
|
@ -1,105 +1,111 @@ |
|||
menu "My Configuration" |
|||
menu "camera" |
|||
choice CAMERA_PAD_TYPE |
|||
|
|||
prompt "camera pad type" |
|||
default CAMERA_PAD_ESP32_S2_KALUGA_V1_3 |
|||
config CAMERA_PAD_ESP32_S2_KALUGA_V1_3 |
|||
bool "ESP32-S2-KALUGA_V1.3" |
|||
config CAMERA_PAD_ESP32_S2_KALUGA_V1_2 |
|||
bool "ESP32-S2-KALUGA_V1.2" |
|||
config CAMERA_PAD_ESP32_S2_KALUGA_V1_1 |
|||
bool "ESP32-S2-KALUGA_V1.1" |
|||
endchoice |
|||
|
|||
config CAMERA_JPEG_MODE |
|||
bool "jpeg mode" |
|||
endmenu |
|||
|
|||
choice CAMERA_PAD_TYPE |
|||
|
|||
prompt "camera pad type" |
|||
default CAMERA_PAD_ESP32_S2_KALUGA_V1_3 |
|||
config CAMERA_PAD_ESP32_S2_KALUGA_V1_3 |
|||
bool "ESP32-S2-KALUGA_V1.3" |
|||
config CAMERA_PAD_ESP32_S2_KALUGA_V1_2 |
|||
bool "ESP32-S2-KALUGA_V1.2" |
|||
config CAMERA_PAD_ESP32_S2_KALUGA_V1_1 |
|||
bool "ESP32-S2-KALUGA_V1.1" |
|||
endchoice |
|||
|
|||
config CAMERA_JPEG_MODE |
|||
bool "jpeg mode" |
|||
|
|||
choice LCD_PAD_TYPE |
|||
prompt "LCD pad type" |
|||
default LCD_PAD_ESP32_S2_KALUGA_V1_3 |
|||
config LCD_PAD_ESP32_S2_KALUGA_V1_3 |
|||
bool "ESP32-S2-KALUGA_V1.3" |
|||
config LCD_PAD_ESP32_S2_KALUGA_V1_2 |
|||
bool "ESP32-S2-KALUGA_V1.2" |
|||
config LCD_PAD_ESP32_S2_KALUGA_V1_1 |
|||
bool "ESP32-S2-KALUGA_V1.1" |
|||
endchoice |
|||
|
|||
choice AUDIO_PAD_TYPE |
|||
prompt "audio pad type" |
|||
default AUDIO_PAD_ESP32_S2_KALUGA_V1_2 |
|||
config AUDIO_PAD_ESP32_S2_KALUGA_V1_3 |
|||
bool "ESP32-S2-KALUGA_V1.3" |
|||
config AUDIO_PAD_ESP32_S2_KALUGA_V1_2 |
|||
bool "ESP32-S2-KALUGA_V1.2" |
|||
config AUDIO_PAD_ESP32_S2_KALUGA_V1_1 |
|||
bool "ESP32-S2-KALUGA_V1.1" |
|||
help |
|||
Set the GPIO number used for transmitting the RMT signal. |
|||
endchoice |
|||
|
|||
choice LCD_VERSION |
|||
|
|||
prompt "LCD version" |
|||
default LCD_ST7789 |
|||
config LCD_ST7789 |
|||
bool "ST7789" |
|||
config LCD_ILI9341 |
|||
bool "ILI9341" |
|||
help |
|||
Set LCD version |
|||
endchoice |
|||
|
|||
config EXAMPLE_RMT_TX_GPIO |
|||
int "WS2812 GPIO" |
|||
default 45 |
|||
help |
|||
Set the GPIO number used for transmitting the RMT signal. |
|||
|
|||
config EXAMPLE_STRIP_LED_NUMBER |
|||
int "Number of LEDS in a strip" |
|||
default 1 |
|||
help |
|||
A single RGB strip contains several LEDs. |
|||
|
|||
|
|||
menu "WiFi Settings" |
|||
config ESP_WIFI_SSID |
|||
string "WiFi STA SSID" |
|||
default "" |
|||
help |
|||
WiFi SSID (network name) to connect to or empty for Off. |
|||
|
|||
config ESP_WIFI_PASSWORD |
|||
string "WiFi STA Password" |
|||
default "" |
|||
help |
|||
WiFi Password if WEP/WPA/WPA2 or empty if Open. |
|||
|
|||
config ESP_WIFI_AP_SSID |
|||
string "WiFi AP SSID" |
|||
default "ESP32-Camera" |
|||
help |
|||
AP SSID (network name) to create or empty for Off. |
|||
menu "lcd" |
|||
choice LCD_PAD_TYPE |
|||
prompt "LCD pad type" |
|||
default LCD_PAD_ESP32_S2_KALUGA_V1_3 |
|||
config LCD_PAD_ESP32_S2_KALUGA_V1_3 |
|||
bool "ESP32-S2-KALUGA_V1.3" |
|||
config LCD_PAD_ESP32_S2_KALUGA_V1_2 |
|||
bool "ESP32-S2-KALUGA_V1.2" |
|||
config LCD_PAD_ESP32_S2_KALUGA_V1_1 |
|||
bool "ESP32-S2-KALUGA_V1.1" |
|||
endchoice |
|||
|
|||
choice LCD_VERSION |
|||
|
|||
prompt "LCD version" |
|||
default LCD_ST7789 |
|||
config LCD_ST7789 |
|||
bool "ST7789" |
|||
config LCD_ILI9341 |
|||
bool "ILI9341" |
|||
help |
|||
Set LCD version |
|||
endchoice |
|||
endmenu |
|||
|
|||
config ESP_WIFI_AP_PASSWORD |
|||
string "WiFi AP Password" |
|||
default "" |
|||
help |
|||
AP password for WPA2 or empty for Open. |
|||
menu "audio" |
|||
choice AUDIO_PAD_TYPE |
|||
prompt "audio pad type" |
|||
default AUDIO_PAD_ESP32_S2_KALUGA_V1_2 |
|||
config AUDIO_PAD_ESP32_S2_KALUGA_V1_3 |
|||
bool "ESP32-S2-KALUGA_V1.3" |
|||
config AUDIO_PAD_ESP32_S2_KALUGA_V1_2 |
|||
bool "ESP32-S2-KALUGA_V1.2" |
|||
config AUDIO_PAD_ESP32_S2_KALUGA_V1_1 |
|||
bool "ESP32-S2-KALUGA_V1.1" |
|||
help |
|||
Set the GPIO number used for transmitting the RMT signal. |
|||
endchoice |
|||
endmenu |
|||
|
|||
config SERVER_IP |
|||
string "WiFi AP IP Address" |
|||
default "192.168.4.1" |
|||
help |
|||
IP address that the ESP will assign to it's AP interface. You can use this IP to connect to the camera after flashing. |
|||
menu "led" |
|||
config RMT_TX_GPIO |
|||
int "WS2812 GPIO" |
|||
default 45 |
|||
help |
|||
Set the GPIO number used for transmitting the RMT signal. |
|||
|
|||
config STRIP_LED_NUMBER |
|||
int "Number of LEDS in a strip" |
|||
default 1 |
|||
help |
|||
A single RGB strip contains several LEDs. |
|||
endmenu |
|||
|
|||
config ESP_MAXIMUM_RETRY |
|||
int "Maximum retry" |
|||
default 5 |
|||
help |
|||
Set the Maximum retry to avoid station reconnecting to the AP unlimited when the AP is really inexistent. |
|||
menu "wifi" |
|||
config ESP_WIFI_SSID |
|||
string "WiFi STA SSID" |
|||
default "" |
|||
help |
|||
WiFi SSID (network name) to connect to or empty for Off. |
|||
|
|||
config ESP_WIFI_PASSWORD |
|||
string "WiFi STA Password" |
|||
default "" |
|||
help |
|||
WiFi Password if WEP/WPA/WPA2 or empty if Open. |
|||
|
|||
config ESP_WIFI_AP_SSID |
|||
string "WiFi AP SSID" |
|||
default "ESP32-Camera" |
|||
help |
|||
AP SSID (network name) to create or empty for Off. |
|||
|
|||
config ESP_WIFI_AP_PASSWORD |
|||
string "WiFi AP Password" |
|||
default "" |
|||
help |
|||
AP password for WPA2 or empty for Open. |
|||
|
|||
config SERVER_IP |
|||
string "WiFi AP IP Address" |
|||
default "192.168.4.1" |
|||
help |
|||
IP address that the ESP will assign to it's AP interface. You can use this IP to connect to the camera after flashing. |
|||
|
|||
config ESP_MAXIMUM_RETRY |
|||
int "Maximum retry" |
|||
default 5 |
|||
help |
|||
Set the Maximum retry to avoid station reconnecting to the AP unlimited when the AP is really inexistent. |
|||
endmenu |
|||
|
|||
endmenu |
|||
|
@ -1,146 +0,0 @@ |
|||
#include "app.h" |
|||
|
|||
#define DEFAULT_VREF \ |
|||
1100 /*!< Use adc2_vref_to_gpio() to obtain a better estimate */ |
|||
#define NO_OF_SAMPLES 64 |
|||
#define SAMPLE_TIME 200 /*!< Sampling time(ms) */ |
|||
static const adc_channel_t channel = |
|||
ADC_CHANNEL_5; /*!< PIO7 if ADC1, GPIO17 if ADC2 */ |
|||
static const adc_bits_width_t width = ADC_WIDTH_BIT_13; |
|||
|
|||
static const adc_atten_t atten = ADC_ATTEN_DB_11; |
|||
static const adc_unit_t unit = ADC_UNIT_1; |
|||
static xQueueHandle adc_queue = NULL; |
|||
led_strip_t *strip; |
|||
#define DEVIATION 0.1 |
|||
|
|||
const char *TAG = "main"; |
|||
|
|||
double adc_voltage_conversion(uint32_t adc_reading) { |
|||
double voltage = 0; |
|||
|
|||
voltage = (2.60 * adc_reading) / 8191; |
|||
|
|||
return voltage; |
|||
} |
|||
void button_task(void *arg) { |
|||
/*!<Continuously sample ADC1*/ |
|||
while (1) { |
|||
uint32_t adc_reading = 0; |
|||
double voltage = 0; |
|||
|
|||
/*!< Multisampling */ |
|||
for (int i = 0; i < NO_OF_SAMPLES; i++) { |
|||
if (unit == ADC_UNIT_1) { |
|||
adc_reading += adc1_get_raw((adc1_channel_t)channel); |
|||
} else { |
|||
int raw; |
|||
adc2_get_raw((adc2_channel_t)channel, width, &raw); |
|||
adc_reading += raw; |
|||
} |
|||
} |
|||
|
|||
adc_reading /= NO_OF_SAMPLES; |
|||
|
|||
voltage = adc_voltage_conversion(adc_reading); |
|||
ESP_LOGD(TAG, "ADC%d CH%d Raw: %d ; Voltage: %0.2lfV", unit, channel, |
|||
adc_reading, voltage); |
|||
|
|||
xQueueSend(adc_queue, (double *)&voltage, 0); |
|||
vTaskDelay(pdMS_TO_TICKS(SAMPLE_TIME)); |
|||
} |
|||
|
|||
vTaskDelete(NULL); |
|||
} |
|||
|
|||
void led_task(void *arg) { |
|||
double voltage = 0; |
|||
|
|||
while (1) { |
|||
xQueueReceive(adc_queue, &voltage, portMAX_DELAY); |
|||
|
|||
if (voltage > 2.6) { |
|||
continue; |
|||
} else if (voltage > 2.41 - DEVIATION && voltage <= 2.41 + DEVIATION) { |
|||
ESP_LOGI(TAG, "rec(K1) -> red"); |
|||
ESP_ERROR_CHECK(strip->set_pixel(strip, 0, 255, 0, 0)); |
|||
ESP_ERROR_CHECK(strip->refresh(strip, 0)); |
|||
|
|||
} else if (voltage > 1.98 - DEVIATION && voltage <= 1.98 + DEVIATION) { |
|||
ESP_LOGI(TAG, "mode(K2) -> green"); |
|||
ESP_ERROR_CHECK(strip->set_pixel(strip, 0, 0, 255, 0)); |
|||
ESP_ERROR_CHECK(strip->refresh(strip, 0)); |
|||
} else if (voltage > 1.65 - DEVIATION && voltage <= 1.65 + DEVIATION) { |
|||
ESP_LOGI(TAG, "play(K3) -> blue"); |
|||
ESP_ERROR_CHECK(strip->set_pixel(strip, 0, 0, 0, 255)); |
|||
ESP_ERROR_CHECK(strip->refresh(strip, 0)); |
|||
|
|||
} else if (voltage > 1.11 - DEVIATION && voltage <= 1.11 + DEVIATION) { |
|||
ESP_LOGI(TAG, "set(K4) -> yellow"); |
|||
ESP_ERROR_CHECK(strip->set_pixel(strip, 0, 255, 255, 0)); |
|||
ESP_ERROR_CHECK(strip->refresh(strip, 0)); |
|||
|
|||
} else if (voltage > 0.82 - DEVIATION && voltage <= 0.82 + DEVIATION) { |
|||
ESP_LOGI(TAG, "vol(K5) -> purple"); |
|||
ESP_ERROR_CHECK(strip->set_pixel(strip, 0, 255, 0, 255)); |
|||
ESP_ERROR_CHECK(strip->refresh(strip, 0)); |
|||
|
|||
} else if (voltage > 0.38 - DEVIATION && voltage <= 0.38 + DEVIATION) { |
|||
ESP_LOGI(TAG, "vol+(K6) -> write"); |
|||
ESP_ERROR_CHECK(strip->set_pixel(strip, 0, 255, 255, 255)); |
|||
ESP_ERROR_CHECK(strip->refresh(strip, 0)); |
|||
} |
|||
} |
|||
|
|||
vTaskDelete(NULL); |
|||
} |
|||
|
|||
void adc_init(void) { |
|||
if (unit == ADC_UNIT_1) { |
|||
adc1_config_width(width); |
|||
adc1_config_channel_atten(channel, atten); |
|||
} else { |
|||
adc2_config_channel_atten((adc2_channel_t)channel, atten); |
|||
} |
|||
} |
|||
|
|||
esp_err_t example_rmt_init(uint8_t gpio_num, int led_number, |
|||
uint8_t rmt_channel) { |
|||
ESP_LOGI(TAG, "Initializing WS2812"); |
|||
rmt_config_t config = RMT_DEFAULT_CONFIG_TX(gpio_num, rmt_channel); |
|||
|
|||
/*!< set counter clock to 40MHz */ |
|||
config.clk_div = 2; |
|||
|
|||
ESP_ERROR_CHECK(rmt_config(&config)); |
|||
ESP_ERROR_CHECK(rmt_driver_install(config.channel, 0, 0)); |
|||
|
|||
led_strip_config_t strip_config = |
|||
LED_STRIP_DEFAULT_CONFIG(led_number, (led_strip_dev_t)config.channel); |
|||
strip = led_strip_new_rmt_ws2812(&strip_config); |
|||
|
|||
if (!strip) { |
|||
ESP_LOGE(TAG, "install WS2812 driver failed"); |
|||
return ESP_FAIL; |
|||
} |
|||
|
|||
/*!< Clear LED strip (turn off all LEDs) */ |
|||
ESP_ERROR_CHECK(strip->clear(strip, 100)); |
|||
/*!< Show simple rainbow chasing pattern */ |
|||
|
|||
return ESP_OK; |
|||
} |
|||
|
|||
void btns_init(void) { |
|||
/*!< WS2812 init*/ |
|||
ESP_ERROR_CHECK(example_rmt_init(CONFIG_EXAMPLE_RMT_TX_GPIO, |
|||
CONFIG_EXAMPLE_STRIP_LED_NUMBER, |
|||
RMT_CHANNEL_0)); |
|||
|
|||
adc_queue = xQueueCreate(1, sizeof(double)); |
|||
adc_init(); |
|||
|
|||
xTaskCreatePinnedToCore(&button_task, "button_task", 3 * 1024, NULL, 5, |
|||
NULL, 0); |
|||
xTaskCreatePinnedToCore(&led_task, "led_task", 3 * 1024, NULL, 5, NULL, 0); |
|||
} |
@ -0,0 +1,38 @@ |
|||
/**
|
|||
* @author: Pomin |
|||
* @date: 2022-08-27 22:34:01 |
|||
* @github: https://github.com/POMIN-163
|
|||
* @lastedit: 2022-08-28 22:25:31 |
|||
* @description: |
|||
**/ |
|||
#ifndef _APP_INIT_H |
|||
#define _APP_INIT_H |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C"{ |
|||
#endif |
|||
|
|||
#include <stdio.h> |
|||
#include <stdint.h> |
|||
#include <stddef.h> |
|||
#include <string.h> |
|||
#include "esp_wifi.h" |
|||
#include "esp_system.h" |
|||
#include "esp_event.h" |
|||
#include "freertos/FreeRTOS.h" |
|||
#include "freertos/task.h" |
|||
#include "esp_heap_caps.h" |
|||
#include "esp_log.h" |
|||
#include "driver/gpio.h" |
|||
#include "driver/adc.h" |
|||
|
|||
|
|||
int lvgl_init(void); |
|||
void lv_port_indev_init(void); |
|||
void led_init(void); |
|||
void btns_init(void); |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
|||
#endif // _APP_INIT_H
|
@ -0,0 +1,158 @@ |
|||
/**
|
|||
* @author: Pomin |
|||
* @date: 2022-08-27 22:33:46 |
|||
* @github: https://github.com/POMIN-163
|
|||
* @lastedit: 2022-08-28 22:26:31 |
|||
* @description: ADC ๆ้ฎ้ฉฑๅจ |
|||
**/ |
|||
#include "app_init.h" |
|||
#include "gui_guider.h" |
|||
#include "lvgl_helpers.h" |
|||
|
|||
#define NO_OF_SAMPLES 64 |
|||
#define SAMPLE_TIME 200 |
|||
|
|||
static const adc_channel_t channel = ADC_CHANNEL_5; |
|||
static const adc_bits_width_t width = ADC_WIDTH_BIT_13; |
|||
static const adc_atten_t atten = ADC_ATTEN_DB_11; |
|||
static const adc_unit_t unit = ADC_UNIT_1; |
|||
|
|||
static uint8_t key_status; |
|||
|
|||
/* ้จ้ */ |
|||
#define DEVIATION 0.1 |
|||
|
|||
#define TAG "btns" |
|||
|
|||
/**
|
|||
* @brief ADC ่ฝฌๆข |
|||
* |
|||
* @param adc_reading |
|||
* @return double |
|||
**/ |
|||
double adc_voltage_conversion(uint32_t adc_reading) { |
|||
double voltage = 0; |
|||
|
|||
voltage = (2.60 * adc_reading) / 8191; |
|||
|
|||
return voltage; |
|||
} |
|||
|
|||
void button_task(void *arg) { |
|||
while (1) { |
|||
uint32_t adc_reading = 0; |
|||
double voltage = 0; |
|||
|
|||
for (int i = 0; i < NO_OF_SAMPLES; i++) { |
|||
if (unit == ADC_UNIT_1) { |
|||
adc_reading += adc1_get_raw((adc1_channel_t)channel); |
|||
} else { |
|||
int raw; |
|||
adc2_get_raw((adc2_channel_t)channel, width, &raw); |
|||
adc_reading += raw; |
|||
} |
|||
} |
|||
|
|||
adc_reading /= NO_OF_SAMPLES; |
|||
voltage = adc_voltage_conversion(adc_reading); |
|||
|
|||
key_status = 0; |
|||
if (voltage > 2.6) { |
|||
continue; |
|||
} else if (voltage > 2.41 - DEVIATION && voltage <= 2.41 + DEVIATION) { |
|||
key_status = 1; |
|||
|
|||
} else if (voltage > 1.98 - DEVIATION && voltage <= 1.98 + DEVIATION) { |
|||
key_status = 2; |
|||
|
|||
} else if (voltage > 1.65 - DEVIATION && voltage <= 1.65 + DEVIATION) { |
|||
key_status = 3; |
|||
|
|||
} else if (voltage > 1.11 - DEVIATION && voltage <= 1.11 + DEVIATION) { |
|||
key_status = 4; |
|||
|
|||
} else if (voltage > 0.82 - DEVIATION && voltage <= 0.82 + DEVIATION) { |
|||
key_status = 5; |
|||
|
|||
} else if (voltage > 0.38 - DEVIATION && voltage <= 0.38 + DEVIATION) { |
|||
key_status = 6; |
|||
} |
|||
|
|||
vTaskDelay(pdMS_TO_TICKS(SAMPLE_TIME)); |
|||
} |
|||
vTaskDelete(NULL); |
|||
} |
|||
|
|||
/**
|
|||
* @brief ๅๅงๅ ADC |
|||
* |
|||
**/ |
|||
void adc_init(void) { |
|||
if (unit == ADC_UNIT_1) { |
|||
adc1_config_width(width); |
|||
adc1_config_channel_atten(channel, atten); |
|||
} else { |
|||
adc2_config_channel_atten((adc2_channel_t)channel, atten); |
|||
} |
|||
} |
|||
|
|||
/**
|
|||
* @brief ๆ้ฎๅๅงๅ |
|||
* |
|||
**/ |
|||
void btns_init(void) { |
|||
adc_init(); |
|||
BaseType_t res = xTaskCreatePinnedToCore(&button_task, "button_task", 4 * 1024, NULL, 5, NULL, 0); |
|||
if (res == pdPASS) { |
|||
ESP_LOGI(TAG, "successed init."); |
|||
} else { |
|||
ESP_LOGE(TAG, "failed init."); |
|||
} |
|||
} |
|||
|
|||
/* * * lvgl ้ฉฑๅจๆฏๆ * * */ |
|||
static void button_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data); |
|||
static int8_t button_get_pressed_id(void); |
|||
lv_indev_t *indev_button; |
|||
|
|||
void lv_port_indev_init(void) { |
|||
static lv_indev_drv_t indev_drv; |
|||
|
|||
lv_indev_drv_init(&indev_drv); |
|||
indev_drv.type = LV_INDEV_TYPE_BUTTON; |
|||
indev_drv.read_cb = button_read; |
|||
indev_button = lv_indev_drv_register(&indev_drv); |
|||
|
|||
static const lv_point_t btn_points[6] = { |
|||
{ 300, 20 }, /* Button 0 */ |
|||
{ 300, 60 }, /* Button 1 */ |
|||
{ 300, 100 }, /* Button 2 */ |
|||
{ 300, 140 }, /* Button 3 */ |
|||
{ 300, 180 }, /* Button 4 */ |
|||
{ 300, 220 }, /* Button 5 */ |
|||
}; |
|||
lv_indev_set_button_points(indev_button, btn_points); |
|||
} |
|||
|
|||
static void button_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data) { |
|||
static uint8_t last_btn = 0; |
|||
int8_t btn_act = button_get_pressed_id(); |
|||
|
|||
if (btn_act >= 0) { |
|||
data->state = LV_INDEV_STATE_PR; |
|||
last_btn = btn_act; |
|||
} else { |
|||
data->state = LV_INDEV_STATE_REL; |
|||
} |
|||
data->btn_id = last_btn; |
|||
} |
|||
|
|||
static int8_t button_get_pressed_id(void) { |
|||
for (uint8_t i = 0; i < 6; i++) { |
|||
if (key_status - 1 == i) { |
|||
return i; |
|||
} |
|||
} |
|||
return -1; |
|||
} |
|||
|
@ -0,0 +1,161 @@ |
|||
/**
|
|||
* @author: Pomin |
|||
* @date: 2022-08-27 22:33:39 |
|||
* @github: https://github.com/POMIN-163
|
|||
* @lastedit: 2022-08-28 22:35:55 |
|||
* @description: led |
|||
**/ |
|||
#include "app_init.h" |
|||
#include "driver/rmt.h" |
|||
#include "led_strip.h" |
|||
|
|||
led_strip_t* strip; |
|||
|
|||
#define TAG "led" |
|||
|
|||
/**
|
|||
* @brief ๅๅงๅ WS2812 ็็ฎก่ |
|||
* |
|||
* @param gpio_num |
|||
* @param led_number |
|||
* @param rmt_channel |
|||
* @return esp_err_t |
|||
**/ |
|||
esp_err_t rmt_init(uint8_t gpio_num, int led_number, uint8_t rmt_channel) { |
|||
ESP_LOGI(TAG, "Initializing WS2812"); |
|||
rmt_config_t config = RMT_DEFAULT_CONFIG_TX(gpio_num, rmt_channel); |
|||
|
|||
config.clk_div = 2; |
|||
|
|||
ESP_ERROR_CHECK(rmt_config(&config)); |
|||
ESP_ERROR_CHECK(rmt_driver_install(config.channel, 0, 0)); |
|||
|
|||
led_strip_config_t strip_config = |
|||
LED_STRIP_DEFAULT_CONFIG(led_number, (led_strip_dev_t)config.channel); |
|||
strip = led_strip_new_rmt_ws2812(&strip_config); |
|||
|
|||
if (!strip) { |
|||
ESP_LOGE(TAG, "install WS2812 driver failed"); |
|||
return ESP_FAIL; |
|||
} |
|||
|
|||
ESP_ERROR_CHECK(strip->clear(strip, 100)); |
|||
|
|||
return ESP_OK; |
|||
} |
|||
|
|||
/* hsv ่ฒๅฝฉ็ฉบ้ด */ |
|||
typedef struct chsv { |
|||
uint16_t h; |
|||
uint16_t s; |
|||
uint16_t v; |
|||
} chsv; |
|||
|
|||
/* rgb ่ฒๅฝฉ */ |
|||
typedef struct crgb { |
|||
uint8_t r; |
|||
uint8_t g; |
|||
uint8_t b; |
|||
} crgb; |
|||
|
|||
/**
|
|||
* @brief hsv ่ฝฌ rgb |
|||
* |
|||
* @param rgb |
|||
* @param hsv |
|||
**/ |
|||
void HSVtoRGB(crgb* rgb, chsv* hsv) { |
|||
// R,G,B from 0-255, H from 0-360, S,V from 0-100
|
|||
|
|||
uint16_t rgb_max = (uint16_t)(hsv->v * 2.55f); |
|||
uint16_t rgb_min = (uint16_t)(rgb_max * (100 - hsv->s) / 100.0f); |
|||
|
|||
int i = hsv->h / 60; |
|||
int difs = hsv->h % 60; // factorial part of h
|
|||
|
|||
// rgb adjustment amount by hue
|
|||
uint16_t rgb_Adj = (rgb_max - rgb_min) * difs / 60.0f; |
|||
|
|||
switch (i) { |
|||
case 0: |
|||
rgb->r = (uint8_t)rgb_max; |
|||
rgb->g = (uint8_t)(rgb_min + rgb_Adj); |
|||
rgb->b = (uint8_t)rgb_min; |
|||
break; |
|||
case 1: |
|||
rgb->r = (uint8_t)(rgb_max - rgb_Adj); |
|||
rgb->g = (uint8_t)rgb_max; |
|||
rgb->b = (uint8_t)rgb_min; |
|||
break; |
|||
case 2: |
|||
rgb->r = (uint8_t)rgb_min; |
|||
rgb->g = (uint8_t)rgb_max; |
|||
rgb->b = (uint8_t)(rgb_min + rgb_Adj); |
|||
break; |
|||
case 3: |
|||
rgb->r = (uint8_t)rgb_min; |
|||
rgb->g = (uint8_t)(rgb_max - rgb_Adj); |
|||
rgb->b = (uint8_t)rgb_max; |
|||
break; |
|||
case 4: |
|||
rgb->r = (uint8_t)(rgb_min + rgb_Adj); |
|||
rgb->g = (uint8_t)rgb_min; |
|||
rgb->b = (uint8_t)rgb_max; |
|||
break; |
|||
default: // case 5:
|
|||
rgb->r = (uint8_t)rgb_max; |
|||
rgb->g = (uint8_t)rgb_min; |
|||
rgb->b = (uint8_t)(rgb_max - rgb_Adj); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
/**
|
|||
* @brief ๆตๅ
ๆบขๅฝฉ็นๆ |
|||
* |
|||
**/ |
|||
crgb* rgb_brilliant(void) { |
|||
static crgb rgb = {0}; |
|||
static int step = 1; |
|||
static chsv hsv = { |
|||
.h = 0, // 0 ~ 360
|
|||
.s = 100, // 0 ~ 100
|
|||
.v = 20 // 0 ~ 100
|
|||
}; |
|||
hsv.h += step; |
|||
if (hsv.h == 358) { |
|||
step = -1; |
|||
} else if (hsv.h == 0) { |
|||
step = 1; |
|||
} |
|||
HSVtoRGB(&rgb, &hsv); |
|||
return &rgb; |
|||
} |
|||
|
|||
void led_task(void* arg) { |
|||
crgb * rgb; |
|||
|
|||
while (1) { |
|||
vTaskDelay(10); |
|||
rgb = rgb_brilliant(); |
|||
strip->set_pixel(strip, 0, rgb->r, rgb->g, rgb->b); |
|||
strip->refresh(strip, 0); |
|||
} |
|||
vTaskDelete(NULL); |
|||
} |
|||
|
|||
/**
|
|||
* @brief led ๅๅงๅ |
|||
* |
|||
**/ |
|||
void led_init(void) { |
|||
ESP_ERROR_CHECK( |
|||
rmt_init(CONFIG_RMT_TX_GPIO, CONFIG_STRIP_LED_NUMBER, RMT_CHANNEL_0)); |
|||
BaseType_t res = xTaskCreatePinnedToCore(&led_task, "led_task", 1 * 1024, |
|||
NULL, 5, NULL, 0); |
|||
if (res == pdPASS) { |
|||
ESP_LOGI(TAG, "successed init."); |
|||
} else { |
|||
ESP_LOGE(TAG, "failed init."); |
|||
} |
|||
} |
@ -0,0 +1,76 @@ |
|||
/**
|
|||
* @author: Pomin |
|||
* @date: 2022-08-27 22:33:56 |
|||
* @github: https://github.com/POMIN-163
|
|||
* @lastedit: 2022-08-28 22:15:27 |
|||
* @description: lvgl ๅๅงๅ |
|||
**/ |
|||
#include "app_init.h" |
|||
#include "custom.h" |
|||
#include "esp_freertos_hooks.h" |
|||
#include "events_init.h" |
|||
#include "freertos/FreeRTOS.h" |
|||
#include "freertos/semphr.h" |
|||
#include "freertos/task.h" |
|||
#include "gui_guider.h" |
|||
#include "lvgl_helpers.h" |
|||
|
|||
// #include "lv_examples/src/lv_demo_benchmark/lv_demo_benchmark.h"
|
|||
// #include "lv_examples/src/lv_demo_music/lv_demo_music.h"
|
|||
// #include "lv_examples/src/lv_demo_widgets/lv_demo_widgets.h"
|
|||
|
|||
static void lv_tick_task(void *arg) { |
|||
(void)arg; |
|||
lv_tick_inc(portTICK_PERIOD_MS); |
|||
} |
|||
|
|||
SemaphoreHandle_t xGuiSemaphore; |
|||
lv_ui guider_ui; |
|||
|
|||
void gui_task(void *arg) { |
|||
xGuiSemaphore = xSemaphoreCreateMutex(); |
|||
lv_init(); |
|||
lvgl_driver_init(); |
|||
|
|||
static lv_disp_draw_buf_t draw_buf; |
|||
lv_color_t *buf1 = (lv_color_t *)heap_caps_malloc( |
|||
DLV_HOR_RES_MAX * DLV_VER_RES_MAX * sizeof(lv_color_t), MALLOC_CAP_DMA); |
|||
lv_color_t *buf2 = (lv_color_t *)heap_caps_malloc( |
|||
DLV_HOR_RES_MAX * DLV_VER_RES_MAX * sizeof(lv_color_t), MALLOC_CAP_DMA); |
|||
|
|||
lv_disp_draw_buf_init(&draw_buf, buf1, buf2, |
|||
DLV_HOR_RES_MAX * DLV_VER_RES_MAX); |
|||
|
|||
static lv_disp_drv_t disp_drv; |
|||
lv_disp_drv_init(&disp_drv); |
|||
disp_drv.draw_buf = &draw_buf; |
|||
disp_drv.flush_cb = disp_driver_flush; |
|||
disp_drv.hor_res = 320; |
|||
disp_drv.ver_res = 240; |
|||
lv_disp_drv_register(&disp_drv); |
|||
|
|||
esp_register_freertos_tick_hook((esp_freertos_tick_cb_t)lv_tick_task); |
|||
// lv_demo_widgets();
|
|||
// lv_demo_music();
|
|||
// lv_demo_benchmark();
|
|||
|
|||
setup_ui(&guider_ui); |
|||
events_init(&guider_ui); |
|||
// custom_init(&guider_ui);
|
|||
lv_port_indev_init(); |
|||
|
|||
while (1) { |
|||
vTaskDelay(pdMS_TO_TICKS(10)); |
|||
|
|||
if (pdTRUE == xSemaphoreTake(xGuiSemaphore, portMAX_DELAY)) { |
|||
lv_timer_handler(); |
|||
xSemaphoreGive(xGuiSemaphore); |
|||
} |
|||
} |
|||
} |
|||
|
|||
int lvgl_init(void) { |
|||
xTaskCreatePinnedToCore(gui_task, "gui task", 1024 * 4, NULL, 6, NULL, 0); |
|||
return 0; |
|||
} |
|||
|
@ -1,183 +0,0 @@ |
|||
#include <stdio.h> |
|||
|
|||
#include "esp_freertos_hooks.h" |
|||
#include "freertos/FreeRTOS.h" |
|||
#include "freertos/semphr.h" |
|||
#include "freertos/task.h" |
|||
// #include "lv_examples/src/lv_demo_benchmark/lv_demo_benchmark.h"
|
|||
// #include "lv_examples/src/lv_demo_music/lv_demo_music.h"
|
|||
// #include "lv_examples/src/lv_demo_widgets/lv_demo_widgets.h"
|
|||
#include "app.h" |
|||
|
|||
#include "custom.h" |
|||
#include "events_init.h" |
|||
#include "gui_guider.h" |
|||
#include "lvgl_helpers.h" |
|||
|
|||
static void lv_tick_task(void *arg) { |
|||
(void)arg; |
|||
lv_tick_inc(portTICK_PERIOD_MS); |
|||
} |
|||
|
|||
SemaphoreHandle_t xGuiSemaphore; |
|||
lv_ui guider_ui; |
|||
|
|||
static void gui_task(void *arg) { |
|||
xGuiSemaphore = xSemaphoreCreateMutex(); |
|||
lv_init(); |
|||
lvgl_driver_init(); |
|||
|
|||
/* double buff create */ |
|||
static lv_disp_draw_buf_t draw_buf; |
|||
lv_color_t *buf1 = heap_caps_malloc( |
|||
DLV_HOR_RES_MAX * DLV_VER_RES_MAX * sizeof(lv_color_t), MALLOC_CAP_DMA); |
|||
lv_color_t *buf2 = heap_caps_malloc( |
|||
DLV_HOR_RES_MAX * DLV_VER_RES_MAX * sizeof(lv_color_t), MALLOC_CAP_DMA); |
|||
|
|||
lv_disp_draw_buf_init( |
|||
&draw_buf, buf1, buf2, |
|||
DLV_HOR_RES_MAX * DLV_VER_RES_MAX); /*Initialize the display buffer*/ |
|||
|
|||
static lv_disp_drv_t |
|||
disp_drv; /*A variable to hold the drivers. Must be static or global.*/ |
|||
lv_disp_drv_init(&disp_drv); /*Basic initialization*/ |
|||
disp_drv.draw_buf = &draw_buf; /*Set an initialized buffer*/ |
|||
disp_drv.flush_cb = |
|||
disp_driver_flush; /*Set a flush callback to draw to the display*/ |
|||
disp_drv.hor_res = 320; /*Set the horizontal resolution in pixels*/ |
|||
disp_drv.ver_res = 240; /*Set the vertical resolution in pixels*/ |
|||
lv_disp_drv_register( |
|||
&disp_drv); /*Register the driver and save the created display objects*/ |
|||
|
|||
esp_register_freertos_tick_hook(lv_tick_task); |
|||
// lv_demo_widgets();
|
|||
// lv_demo_music();
|
|||
// lv_demo_benchmark();
|
|||
|
|||
setup_ui(&guider_ui); |
|||
events_init(&guider_ui); |
|||
custom_init(&guider_ui); |
|||
|
|||
while (1) { |
|||
/* Delay 1 tick (assumes FreeRTOS tick is 10ms */ |
|||
vTaskDelay(pdMS_TO_TICKS(10)); |
|||
|
|||
/* Try to take the semaphore, call lvgl related function on success */ |
|||
if (pdTRUE == xSemaphoreTake(xGuiSemaphore, portMAX_DELAY)) { |
|||
lv_timer_handler(); |
|||
xSemaphoreGive(xGuiSemaphore); |
|||
} |
|||
} |
|||
} |
|||
|
|||
#include "freertos/FreeRTOS.h" |
|||
#include "freertos/task.h" |
|||
#include "esp_log.h" |
|||
#include "esp_camera.h" |
|||
#include "lcd.h" |
|||
#include "board.h" |
|||
|
|||
static const char *TAG = "main"; |
|||
|
|||
|
|||
void app_main() |
|||
{ |
|||
// xTaskCreatePinnedToCore(gui_task, "gui task", 1024 * 4, NULL, 1, NULL, 0);
|
|||
btns_init(); |
|||
lcd_config_t lcd_config = { |
|||
.clk_fre = 40 * 1000 * 1000, |
|||
.pin_clk = LCD_CLK, |
|||
.pin_mosi = LCD_MOSI, |
|||
.pin_dc = LCD_DC, |
|||
.pin_cs = LCD_CS, |
|||
.pin_rst = LCD_RST, |
|||
.pin_bk = LCD_BK, |
|||
.max_buffer_size = 2 * 1024, |
|||
.horizontal = 2, /*!< 2: UP, 3: DOWN */ |
|||
#ifdef CONFIG_CAMERA_JPEG_MODE |
|||
.swap_data = 1, |
|||
#else |
|||
.swap_data = 0, |
|||
#endif |
|||
}; |
|||
|
|||
lcd_init(&lcd_config); |
|||
|
|||
camera_config_t camera_config = { |
|||
.pin_pwdn = -1, |
|||
.pin_reset = -1, |
|||
.pin_xclk = CAM_XCLK, |
|||
.pin_sscb_sda = CAM_SDA, |
|||
.pin_sscb_scl = CAM_SCL, |
|||
|
|||
.pin_d7 = CAM_D7, |
|||
.pin_d6 = CAM_D6, |
|||
.pin_d5 = CAM_D5, |
|||
.pin_d4 = CAM_D4, |
|||
.pin_d3 = CAM_D3, |
|||
.pin_d2 = CAM_D2, |
|||
.pin_d1 = CAM_D1, |
|||
.pin_d0 = CAM_D0, |
|||
.pin_vsync = CAM_VSYNC, |
|||
.pin_href = CAM_HSYNC, |
|||
.pin_pclk = CAM_PCLK, |
|||
|
|||
//XCLK 20MHz or 10MHz for OV2640 double FPS (Experimental)
|
|||
.xclk_freq_hz = 20000000, |
|||
.ledc_timer = LEDC_TIMER_0, |
|||
.ledc_channel = LEDC_CHANNEL_0, |
|||
#ifdef CONFIG_CAMERA_JPEG_MODE |
|||
.pixel_format = PIXFORMAT_JPEG, //YUV422,GRAYSCALE,RGB565,JPEG
|
|||
#else |
|||
.pixel_format = PIXFORMAT_RGB565, |
|||
#endif |
|||
.frame_size = FRAMESIZE_QVGA, //QQVGA-UXGA Do not use sizes above QVGA when not JPEG
|
|||
.jpeg_quality = 12, //0-63 lower number means higher quality
|
|||
.fb_count = 2 //if more than one, i2s runs in continuous mode. Use only with JPEG
|
|||
}; |
|||
//initialize the camera
|
|||
esp_err_t err = esp_camera_init(&camera_config); |
|||
if (err != ESP_OK) { |
|||
ESP_LOGE(TAG, "Camera Init Failed"); |
|||
return; |
|||
} |
|||
sensor_t *s = esp_camera_sensor_get(); |
|||
s->set_vflip(s, 1);//flip it back
|
|||
//initial sensors are flipped vertically and colors are a bit saturated
|
|||
if (s->id.PID == OV3660_PID) { |
|||
s->set_brightness(s, 1);//up the blightness just a bit
|
|||
s->set_saturation(s, -2);//lower the saturation
|
|||
} |
|||
//drop down frame size for higher initial frame rate
|
|||
s->set_framesize(s, FRAMESIZE_QVGA); |
|||
ESP_LOGI(TAG, "Camera Init done"); |
|||
|
|||
#ifdef CONFIG_CAMERA_JPEG_MODE |
|||
ESP_LOGI(TAG, "Camera jpeg mode"); |
|||
uint8_t *rgb565 = malloc(240 * 320 * 2); |
|||
if (NULL == rgb565) { |
|||
ESP_LOGE(TAG, "can't alloc memory for rgb565 buffer"); |
|||
return; |
|||
} |
|||
#endif |
|||
while (1) { |
|||
camera_fb_t *pic = esp_camera_fb_get(); |
|||
if (pic) { |
|||
ESP_LOGI(TAG, "picture: %d x %d %dbyte", pic->width, pic->height, pic-> |