193 lines
5.0 KiB
C
193 lines
5.0 KiB
C
/* 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 "sdkconfig.h"
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "esp_system.h"
|
|
#include "esp_spi_flash.h"
|
|
#include "nvs_flash.h"
|
|
#include "esp_err.h"
|
|
#include "esp_log.h"
|
|
|
|
#include "app_task_hello.h"
|
|
// #include "app_task_wifi.h"
|
|
// #include "app_task_mqtt.h"
|
|
// #include "app_task_sensors.h"
|
|
#include "st7789.h"
|
|
#include "CST816T.h"
|
|
#include "app_main.h"
|
|
#include "shell_port.h"
|
|
// #include "msg_queue.h"
|
|
|
|
static app_main_handle_t sg_app_main_handle = {0};
|
|
|
|
static void _init_esp()
|
|
{
|
|
// Initialize NVS
|
|
esp_err_t ret = nvs_flash_init();
|
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
|
ret = nvs_flash_init();
|
|
}
|
|
ESP_ERROR_CHECK( ret );
|
|
}
|
|
|
|
TickType_t FillTest(TFT_t * dev, int width, int height) {
|
|
TickType_t startTick, endTick, diffTick;
|
|
startTick = xTaskGetTickCount();
|
|
|
|
lcdFillScreen(dev, RED);
|
|
vTaskDelay(50);
|
|
lcdFillScreen(dev, GREEN);
|
|
vTaskDelay(50);
|
|
lcdFillScreen(dev, BLUE);
|
|
vTaskDelay(50);
|
|
|
|
endTick = xTaskGetTickCount();
|
|
diffTick = endTick - startTick;
|
|
ESP_LOGI(__FUNCTION__, "elapsed time[ms]:%d",diffTick*portTICK_PERIOD_MS);
|
|
return diffTick;
|
|
}
|
|
|
|
void cst_scan_gesture()
|
|
{
|
|
while (1)
|
|
{
|
|
vTaskDelay(1);
|
|
if (cst816t_available())
|
|
{
|
|
/*printf("gesture.id %u \n", data.gestureID);
|
|
printf("points %u \n", data.points);
|
|
printf("event %u \n", data.event);*/
|
|
printf("x %i \n", data.x);
|
|
printf("y %i \n", data.y);
|
|
|
|
switch (data.gestureID)
|
|
{
|
|
case NONE:
|
|
// printf("NONE");
|
|
break;
|
|
case SWIPE_DOWN:
|
|
printf("SWIPE DOWN \n");
|
|
break;
|
|
case SWIPE_UP:
|
|
printf("SWIPE UP \n");
|
|
break;
|
|
case SWIPE_LEFT:
|
|
printf("SWIPE LEFT \n");
|
|
break;
|
|
case SWIPE_RIGHT:
|
|
printf("SWIPE RIGHT \n");
|
|
break;
|
|
case SINGLE_CLICK:
|
|
printf("SINGLE CLICK \n");
|
|
break;
|
|
case DOUBLE_CLICK:
|
|
printf("DOUBLE CLICK \n");
|
|
break;
|
|
case LONG_PRESS:
|
|
printf("LONG PRESS \n");
|
|
break;
|
|
default:
|
|
printf("UNKNOWN \n");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void app_main(void)
|
|
{
|
|
// app_task_wifi_t wifi_info = {0};
|
|
// msg_queue_init();
|
|
printf("Hello world!\n");
|
|
|
|
vTaskDelay(10);
|
|
|
|
_init_esp();
|
|
// app_hello_task_start();
|
|
// app_task_wifi_start();
|
|
// app_task_mqtt_start();
|
|
// app_task_sensors_start();
|
|
|
|
userShellInit();
|
|
|
|
cst816t_begin(34, 33, 35, 36);
|
|
|
|
xTaskCreatePinnedToCore(cst_scan_gesture, "sct test", 4096, NULL, 4, NULL, tskNO_AFFINITY);
|
|
|
|
|
|
TFT_t dev;
|
|
spi_master_init(&dev, CONFIG_MOSI_GPIO, CONFIG_SCLK_GPIO, CONFIG_CS_GPIO, CONFIG_DC_GPIO, CONFIG_RESET_GPIO, CONFIG_BL_GPIO);
|
|
// lcdBacklightOn(&dev);
|
|
// vTaskDelay(1000);
|
|
lcdInit(&dev, CONFIG_WIDTH, CONFIG_HEIGHT, CONFIG_OFFSETX, CONFIG_OFFSETY);
|
|
// lcdBacklightOn(&dev);
|
|
|
|
#if CONFIG_INVERSION
|
|
// ESP_LOGI(TAG, "Enable Display Inversion");
|
|
lcdInversionOn(&dev);
|
|
#endif
|
|
|
|
/* Print chip information */
|
|
esp_chip_info_t chip_info;
|
|
esp_chip_info(&chip_info);
|
|
printf("This is %s chip with %d CPU core(s), WiFi%s%s, ",
|
|
CONFIG_IDF_TARGET,
|
|
chip_info.cores,
|
|
(chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
|
|
(chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");
|
|
|
|
printf("silicon revision %d, ", chip_info.revision);
|
|
|
|
printf("%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024),
|
|
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
|
|
|
|
printf("Minimum free heap size: %d bytes\n", esp_get_minimum_free_heap_size());
|
|
|
|
// uint8_t ret = msg_queue_create("mqtt_task");
|
|
// printf("ret = %d\r\n", ret);
|
|
|
|
// msg_data_t msg_data = {0};
|
|
for (int i = 10; ; ) {
|
|
// printf("Restarting in %d seconds...\n", i);
|
|
// app_task_wifi_get_info(&wifi_info);
|
|
// sg_app_main_handle.have_network = wifi_info.is_wifi_conneted;
|
|
FillTest(&dev, CONFIG_WIDTH, CONFIG_HEIGHT);
|
|
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
|
// if (!msg_queue_recive_msg("mqtt_task", &msg_data, 100)) {
|
|
// printf("msg queue get data = %d\r\n", msg_data.msg_type);
|
|
// }
|
|
}
|
|
printf("Restarting now.\n");
|
|
fflush(stdout);
|
|
esp_restart();
|
|
}
|
|
|
|
uint8_t app_main_handle_get_nework_state()
|
|
{
|
|
return sg_app_main_handle.have_network;
|
|
}
|
|
|
|
static void _show_build_time(int argc, char **argv)
|
|
{
|
|
printf("build at %s %s\n", __DATE__, __TIME__);
|
|
}
|
|
|
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), show_build_time, _show_build_time, show the build time);
|
|
|
|
static void _reboot(int argc, char **argv)
|
|
{
|
|
esp_restart();
|
|
}
|
|
|
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), reboot, _reboot, reboot system);
|
|
|