Modify the example to the default display version and clear the pio version limit

This commit is contained in:
lewishe 2023-03-21 10:09:43 +08:00
parent 2d230438af
commit 84e8604072
10 changed files with 727 additions and 722 deletions

View File

@ -18,9 +18,6 @@ platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
platform_packages =
framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#2.0.5
build_flags =
-DLV_LVGL_H_INCLUDE_SIMPLE
-DBOARD_HAS_PSRAM

View File

@ -6,7 +6,7 @@
/* The product now has two screens, and the initialization code needs a small change in the new version. The LCD_MODULE_CMD_1 is used to define the
* switch macro. */
#define LCD_MODULE_CMD_1
// #define LCD_MODULE_CMD_1
#include "OneButton.h" /* https://github.com/mathertel/OneButton.git */
#include "lvgl.h" /* https://github.com/lvgl/lvgl.git */
@ -36,9 +36,9 @@ OneButton button1(PIN_BUTTON_1, true);
OneButton button2(PIN_BUTTON_2, true);
#if defined(LCD_MODULE_CMD_1)
typedef struct {
uint8_t cmd;
uint8_t data[14];
uint8_t len;
uint8_t cmd;
uint8_t data[14];
uint8_t len;
} lcd_cmd_t;
lcd_cmd_t lcd_st7789v[] = {
@ -78,375 +78,386 @@ void printLocalTime();
void SmartConfig();
void setTimezone();
static bool example_notify_lvgl_flush_ready(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx) {
if (is_initialized_lvgl) {
lv_disp_drv_t *disp_driver = (lv_disp_drv_t *)user_ctx;
lv_disp_flush_ready(disp_driver);
}
return false;
static bool example_notify_lvgl_flush_ready(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx)
{
if (is_initialized_lvgl) {
lv_disp_drv_t *disp_driver = (lv_disp_drv_t *)user_ctx;
lv_disp_flush_ready(disp_driver);
}
return false;
}
static void example_lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map) {
esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t)drv->user_data;
int offsetx1 = area->x1;
int offsetx2 = area->x2;
int offsety1 = area->y1;
int offsety2 = area->y2;
// copy a buffer's content to a specific area of the display
esp_lcd_panel_draw_bitmap(panel_handle, offsetx1, offsety1, offsetx2 + 1, offsety2 + 1, color_map);
static void example_lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map)
{
esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t)drv->user_data;
int offsetx1 = area->x1;
int offsetx2 = area->x2;
int offsety1 = area->y1;
int offsety2 = area->y2;
// copy a buffer's content to a specific area of the display
esp_lcd_panel_draw_bitmap(panel_handle, offsetx1, offsety1, offsetx2 + 1, offsety2 + 1, color_map);
}
static void lv_touchpad_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) {
static void lv_touchpad_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
{
#if defined(TOUCH_READ_FROM_INTERRNUPT)
if (get_int_signal) {
get_int_signal = false;
touch.read();
if (get_int_signal) {
get_int_signal = false;
touch.read();
#else
if (touch.read()) {
if (touch.read()) {
#endif
String str_buf;
uint8_t fn = touch.getPointNum();
str_buf += " Finger num : " + String(fn) + " \n";
for (uint8_t i = 0; i < fn; i++) {
TP_Point t = touch.getPoint(i);
str_buf += "x: " + String(t.x) + " y: " + String(t.y) + " p: " + String(t.pressure) + " \n";
}
TP_Point t = touch.getPoint(0);
data->point.x = t.x;
data->point.y = t.y;
data->state = LV_INDEV_STATE_PR;
lv_msg_send(MSG_NEW_TOUCH_POINT, str_buf.c_str());
} else
data->state = LV_INDEV_STATE_REL;
String str_buf;
uint8_t fn = touch.getPointNum();
str_buf += " Finger num : " + String(fn) + " \n";
for (uint8_t i = 0; i < fn; i++) {
TP_Point t = touch.getPoint(i);
str_buf += "x: " + String(t.x) + " y: " + String(t.y) + " p: " + String(t.pressure) + " \n";
}
TP_Point t = touch.getPoint(0);
data->point.x = t.x;
data->point.y = t.y;
data->state = LV_INDEV_STATE_PR;
lv_msg_send(MSG_NEW_TOUCH_POINT, str_buf.c_str());
} else
data->state = LV_INDEV_STATE_REL;
}
void setup() {
pinMode(PIN_POWER_ON, OUTPUT);
digitalWrite(PIN_POWER_ON, HIGH);
Serial.begin(115200);
sntp_servermode_dhcp(1); // (optional)
configTime(GMT_OFFSET_SEC, DAY_LIGHT_OFFSET_SEC, NTP_SERVER1, NTP_SERVER2);
pinMode(PIN_LCD_RD, OUTPUT);
digitalWrite(PIN_LCD_RD, HIGH);
esp_lcd_i80_bus_handle_t i80_bus = NULL;
esp_lcd_i80_bus_config_t bus_config = {
.dc_gpio_num = PIN_LCD_DC,
.wr_gpio_num = PIN_LCD_WR,
.clk_src = LCD_CLK_SRC_PLL160M,
.data_gpio_nums =
{
PIN_LCD_D0,
PIN_LCD_D1,
PIN_LCD_D2,
PIN_LCD_D3,
PIN_LCD_D4,
PIN_LCD_D5,
PIN_LCD_D6,
PIN_LCD_D7,
},
.bus_width = 8,
.max_transfer_bytes = LVGL_LCD_BUF_SIZE * sizeof(uint16_t),
};
esp_lcd_new_i80_bus(&bus_config, &i80_bus);
esp_lcd_panel_io_i80_config_t io_config = {
.cs_gpio_num = PIN_LCD_CS,
.pclk_hz = EXAMPLE_LCD_PIXEL_CLOCK_HZ,
.trans_queue_depth = 20,
.on_color_trans_done = example_notify_lvgl_flush_ready,
.user_ctx = &disp_drv,
.lcd_cmd_bits = 8,
.lcd_param_bits = 8,
.dc_levels =
{
.dc_idle_level = 0,
.dc_cmd_level = 0,
.dc_dummy_level = 0,
.dc_data_level = 1,
},
};
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handle));
esp_lcd_panel_handle_t panel_handle = NULL;
esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = PIN_LCD_RES,
.color_space = ESP_LCD_COLOR_SPACE_RGB,
.bits_per_pixel = 16,
};
esp_lcd_new_panel_st7789(io_handle, &panel_config, &panel_handle);
esp_lcd_panel_reset(panel_handle);
esp_lcd_panel_init(panel_handle);
esp_lcd_panel_invert_color(panel_handle, true);
esp_lcd_panel_swap_xy(panel_handle, true);
esp_lcd_panel_mirror(panel_handle, false, true);
// the gap is LCD panel specific, even panels with the same driver IC, can
// have different gap value
esp_lcd_panel_set_gap(panel_handle, 0, 35);
#if defined(LCD_MODULE_CMD_1)
for (uint8_t i = 0; i < (sizeof(lcd_st7789v) / sizeof(lcd_cmd_t)); i++) {
esp_lcd_panel_io_tx_param(io_handle, lcd_st7789v[i].cmd, lcd_st7789v[i].data, lcd_st7789v[i].len & 0x7f);
if (lcd_st7789v[i].len & 0x80)
delay(120);
}
#endif
/* Lighten the screen with gradient */
ledcSetup(0, 10000, 8);
ledcAttachPin(PIN_LCD_BL, 0);
for (uint8_t i = 0; i < 0xFF; i++) {
ledcWrite(0, i);
delay(2);
}
lv_init();
lv_disp_buf = (lv_color_t *)heap_caps_malloc(LVGL_LCD_BUF_SIZE * sizeof(lv_color_t), MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
lv_disp_draw_buf_init(&disp_buf, lv_disp_buf, NULL, LVGL_LCD_BUF_SIZE);
/*Initialize the display*/
lv_disp_drv_init(&disp_drv);
/*Change the following line to your display resolution*/
disp_drv.hor_res = EXAMPLE_LCD_H_RES;
disp_drv.ver_res = EXAMPLE_LCD_V_RES;
disp_drv.flush_cb = example_lvgl_flush_cb;
disp_drv.draw_buf = &disp_buf;
disp_drv.user_data = panel_handle;
lv_disp_drv_register(&disp_drv);
/* Register touch brush with LVGL */
// Wire.begin(PIN_IIC_SDA, PIN_IIC_SCL, 800000);
inited_touch = touch.init();
if (inited_touch) {
touch.setRotation(1);
static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = lv_touchpad_read;
lv_indev_drv_register(&indev_drv);
}
is_initialized_lvgl = true;
#if defined(TOUCH_READ_FROM_INTERRNUPT)
attachInterrupt(
PIN_TOUCH_INT, [] { get_int_signal = true; }, FALLING);
#endif
SD_MMC.setPins(PIN_SD_CLK, PIN_SD_CMD, PIN_SD_D0);
inited_sd = SD_MMC.begin("/sdcard", true, true);
wifi_test();
button1.attachClick([]() {
void setup()
{
pinMode(PIN_POWER_ON, OUTPUT);
pinMode(PIN_LCD_BL, OUTPUT);
digitalWrite(PIN_POWER_ON, LOW);
digitalWrite(PIN_LCD_BL, LOW);
esp_sleep_enable_ext0_wakeup((gpio_num_t)PIN_BUTTON_2, 0); // 1 = High, 0 = Low
esp_deep_sleep_start();
});
digitalWrite(PIN_POWER_ON, HIGH);
Serial.begin(115200);
button2.attachClick([]() { ui_switch_page(); });
sntp_servermode_dhcp(1); // (optional)
configTime(GMT_OFFSET_SEC, DAY_LIGHT_OFFSET_SEC, NTP_SERVER1, NTP_SERVER2);
pinMode(PIN_LCD_RD, OUTPUT);
digitalWrite(PIN_LCD_RD, HIGH);
esp_lcd_i80_bus_handle_t i80_bus = NULL;
esp_lcd_i80_bus_config_t bus_config = {
.dc_gpio_num = PIN_LCD_DC,
.wr_gpio_num = PIN_LCD_WR,
.clk_src = LCD_CLK_SRC_PLL160M,
.data_gpio_nums =
{
PIN_LCD_D0,
PIN_LCD_D1,
PIN_LCD_D2,
PIN_LCD_D3,
PIN_LCD_D4,
PIN_LCD_D5,
PIN_LCD_D6,
PIN_LCD_D7,
},
.bus_width = 8,
.max_transfer_bytes = LVGL_LCD_BUF_SIZE * sizeof(uint16_t),
};
esp_lcd_new_i80_bus(&bus_config, &i80_bus);
esp_lcd_panel_io_i80_config_t io_config = {
.cs_gpio_num = PIN_LCD_CS,
.pclk_hz = EXAMPLE_LCD_PIXEL_CLOCK_HZ,
.trans_queue_depth = 20,
.on_color_trans_done = example_notify_lvgl_flush_ready,
.user_ctx = &disp_drv,
.lcd_cmd_bits = 8,
.lcd_param_bits = 8,
.dc_levels =
{
.dc_idle_level = 0,
.dc_cmd_level = 0,
.dc_dummy_level = 0,
.dc_data_level = 1,
},
};
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handle));
esp_lcd_panel_handle_t panel_handle = NULL;
esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = PIN_LCD_RES,
.color_space = ESP_LCD_COLOR_SPACE_RGB,
.bits_per_pixel = 16,
};
esp_lcd_new_panel_st7789(io_handle, &panel_config, &panel_handle);
esp_lcd_panel_reset(panel_handle);
esp_lcd_panel_init(panel_handle);
esp_lcd_panel_invert_color(panel_handle, true);
esp_lcd_panel_swap_xy(panel_handle, true);
esp_lcd_panel_mirror(panel_handle, false, true);
// the gap is LCD panel specific, even panels with the same driver IC, can
// have different gap value
esp_lcd_panel_set_gap(panel_handle, 0, 35);
#if defined(LCD_MODULE_CMD_1)
for (uint8_t i = 0; i < (sizeof(lcd_st7789v) / sizeof(lcd_cmd_t)); i++) {
esp_lcd_panel_io_tx_param(io_handle, lcd_st7789v[i].cmd, lcd_st7789v[i].data, lcd_st7789v[i].len & 0x7f);
if (lcd_st7789v[i].len & 0x80)
delay(120);
}
#endif
/* Lighten the screen with gradient */
ledcSetup(0, 10000, 8);
ledcAttachPin(PIN_LCD_BL, 0);
for (uint8_t i = 0; i < 0xFF; i++) {
ledcWrite(0, i);
delay(2);
}
lv_init();
lv_disp_buf = (lv_color_t *)heap_caps_malloc(LVGL_LCD_BUF_SIZE * sizeof(lv_color_t), MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
lv_disp_draw_buf_init(&disp_buf, lv_disp_buf, NULL, LVGL_LCD_BUF_SIZE);
/*Initialize the display*/
lv_disp_drv_init(&disp_drv);
/*Change the following line to your display resolution*/
disp_drv.hor_res = EXAMPLE_LCD_H_RES;
disp_drv.ver_res = EXAMPLE_LCD_V_RES;
disp_drv.flush_cb = example_lvgl_flush_cb;
disp_drv.draw_buf = &disp_buf;
disp_drv.user_data = panel_handle;
lv_disp_drv_register(&disp_drv);
/* Register touch brush with LVGL */
// Wire.begin(PIN_IIC_SDA, PIN_IIC_SCL, 800000);
inited_touch = touch.init();
if (inited_touch) {
touch.setRotation(1);
static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = lv_touchpad_read;
lv_indev_drv_register(&indev_drv);
}
is_initialized_lvgl = true;
#if defined(TOUCH_READ_FROM_INTERRNUPT)
attachInterrupt(
PIN_TOUCH_INT, [] { get_int_signal = true; }, FALLING);
#endif
SD_MMC.setPins(PIN_SD_CLK, PIN_SD_CMD, PIN_SD_D0);
inited_sd = SD_MMC.begin("/sdcard", true, true);
wifi_test();
button1.attachClick([]() {
pinMode(PIN_POWER_ON, OUTPUT);
pinMode(PIN_LCD_BL, OUTPUT);
digitalWrite(PIN_POWER_ON, LOW);
digitalWrite(PIN_LCD_BL, LOW);
esp_sleep_enable_ext0_wakeup((gpio_num_t)PIN_BUTTON_2, 0); // 1 = High, 0 = Low
esp_deep_sleep_start();
});
button2.attachClick([]() {
ui_switch_page();
});
}
void loop() {
lv_timer_handler();
button1.tick();
button2.tick();
delay(3);
static uint32_t last_tick;
if (millis() - last_tick > 100) {
struct tm timeinfo;
if (getLocalTime(&timeinfo)) {
lv_msg_send(MSG_NEW_HOUR, &timeinfo.tm_hour);
lv_msg_send(MSG_NEW_MIN, &timeinfo.tm_min);
}
uint32_t volt = (analogRead(PIN_BAT_VOLT) * 2 * 3.3 * 1000) / 4096;
lv_msg_send(MSG_NEW_VOLT, &volt);
void loop()
{
lv_timer_handler();
button1.tick();
button2.tick();
delay(3);
static uint32_t last_tick;
if (millis() - last_tick > 100) {
struct tm timeinfo;
if (getLocalTime(&timeinfo)) {
lv_msg_send(MSG_NEW_HOUR, &timeinfo.tm_hour);
lv_msg_send(MSG_NEW_MIN, &timeinfo.tm_min);
}
uint32_t volt = (analogRead(PIN_BAT_VOLT) * 2 * 3.3 * 1000) / 4096;
lv_msg_send(MSG_NEW_VOLT, &volt);
last_tick = millis();
}
last_tick = millis();
}
}
LV_IMG_DECLARE(lilygo2_gif);
void wifi_test(void) {
String text;
lv_obj_t *logo_img = lv_gif_create(lv_scr_act());
lv_obj_center(logo_img);
lv_gif_set_src(logo_img, &lilygo2_gif);
LV_DELAY(1200);
lv_obj_del(logo_img);
void wifi_test(void)
{
String text;
lv_obj_t *logo_img = lv_gif_create(lv_scr_act());
lv_obj_center(logo_img);
lv_gif_set_src(logo_img, &lilygo2_gif);
LV_DELAY(1200);
lv_obj_del(logo_img);
lv_obj_t *log_label = lv_label_create(lv_scr_act());
lv_obj_align(log_label, LV_ALIGN_TOP_LEFT, 0, 0);
lv_obj_set_width(log_label, LV_PCT(100));
lv_label_set_long_mode(log_label, LV_LABEL_LONG_SCROLL);
lv_label_set_recolor(log_label, true);
lv_obj_t *log_label = lv_label_create(lv_scr_act());
lv_obj_align(log_label, LV_ALIGN_TOP_LEFT, 0, 0);
lv_obj_set_width(log_label, LV_PCT(100));
lv_label_set_long_mode(log_label, LV_LABEL_LONG_SCROLL);
lv_label_set_recolor(log_label, true);
lv_label_set_text(log_label, "Scan WiFi");
LV_DELAY(1);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
int n = WiFi.scanNetworks();
Serial.println("scan done");
if (n == 0) {
text = "no networks found";
} else {
text = n;
text += " networks found\n";
for (int i = 0; i < n; ++i) {
text += (i + 1);
text += ": ";
text += WiFi.SSID(i);
text += " (";
text += WiFi.RSSI(i);
text += ")";
text += (WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " \n" : "*\n";
delay(10);
}
}
lv_label_set_text(log_label, text.c_str());
Serial.println(text);
LV_DELAY(2000);
text = "Connecting to ";
Serial.print("Connecting to ");
text += WIFI_SSID;
text += "\n";
Serial.print(WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
uint32_t last_tick = millis();
uint32_t i = 0;
bool is_smartconfig_connect = false;
lv_label_set_long_mode(log_label, LV_LABEL_LONG_WRAP);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
text += ".";
lv_label_set_text(log_label, text.c_str());
LV_DELAY(100);
if (millis() - last_tick > WIFI_CONNECT_WAIT_MAX) { /* Automatically start smartconfig when connection times out */
text += "\nConnection timed out, start smartconfig";
lv_label_set_text(log_label, text.c_str());
LV_DELAY(100);
is_smartconfig_connect = true;
WiFi.mode(WIFI_AP_STA);
Serial.println("\r\n wait for smartconfig....");
text += "\r\n wait for smartconfig....";
text += "\nPlease use #ff0000 EspTouch# Apps to connect to the distribution network";
lv_label_set_text(log_label, text.c_str());
WiFi.beginSmartConfig();
while (1) {
LV_DELAY(100);
if (WiFi.smartConfigDone()) {
Serial.println("\r\nSmartConfig Success\r\n");
Serial.printf("SSID:%s\r\n", WiFi.SSID().c_str());
Serial.printf("PSW:%s\r\n", WiFi.psk().c_str());
text += "\nSmartConfig Success";
text += "\nSSID:";
text += WiFi.SSID().c_str();
text += "\nPSW:";
text += WiFi.psk().c_str();
lv_label_set_text(log_label, text.c_str());
LV_DELAY(1000);
last_tick = millis();
break;
lv_label_set_text(log_label, "Scan WiFi");
LV_DELAY(1);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
int n = WiFi.scanNetworks();
Serial.println("scan done");
if (n == 0) {
text = "no networks found";
} else {
text = n;
text += " networks found\n";
for (int i = 0; i < n; ++i) {
text += (i + 1);
text += ": ";
text += WiFi.SSID(i);
text += " (";
text += WiFi.RSSI(i);
text += ")";
text += (WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " \n" : "*\n";
delay(10);
}
}
}
}
if (!is_smartconfig_connect) {
text += "\nCONNECTED \nTakes ";
Serial.print("\n CONNECTED \nTakes ");
text += millis() - last_tick;
Serial.print(millis() - last_tick);
text += " ms\n";
Serial.println(" millseconds");
lv_label_set_text(log_label, text.c_str());
}
LV_DELAY(2000);
setTimezone();
ui_begin();
Serial.println(text);
LV_DELAY(2000);
text = "Connecting to ";
Serial.print("Connecting to ");
text += WIFI_SSID;
text += "\n";
Serial.print(WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
uint32_t last_tick = millis();
uint32_t i = 0;
bool is_smartconfig_connect = false;
lv_label_set_long_mode(log_label, LV_LABEL_LONG_WRAP);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
text += ".";
lv_label_set_text(log_label, text.c_str());
LV_DELAY(100);
if (millis() - last_tick > WIFI_CONNECT_WAIT_MAX) { /* Automatically start smartconfig when connection times out */
text += "\nConnection timed out, start smartconfig";
lv_label_set_text(log_label, text.c_str());
LV_DELAY(100);
is_smartconfig_connect = true;
WiFi.mode(WIFI_AP_STA);
Serial.println("\r\n wait for smartconfig....");
text += "\r\n wait for smartconfig....";
text += "\nPlease use #ff0000 EspTouch# Apps to connect to the distribution network";
lv_label_set_text(log_label, text.c_str());
WiFi.beginSmartConfig();
while (1) {
LV_DELAY(100);
if (WiFi.smartConfigDone()) {
Serial.println("\r\nSmartConfig Success\r\n");
Serial.printf("SSID:%s\r\n", WiFi.SSID().c_str());
Serial.printf("PSW:%s\r\n", WiFi.psk().c_str());
text += "\nSmartConfig Success";
text += "\nSSID:";
text += WiFi.SSID().c_str();
text += "\nPSW:";
text += WiFi.psk().c_str();
lv_label_set_text(log_label, text.c_str());
LV_DELAY(1000);
last_tick = millis();
break;
}
}
}
}
if (!is_smartconfig_connect) {
text += "\nCONNECTED \nTakes ";
Serial.print("\n CONNECTED \nTakes ");
text += millis() - last_tick;
Serial.print(millis() - last_tick);
text += " ms\n";
Serial.println(" millseconds");
lv_label_set_text(log_label, text.c_str());
}
LV_DELAY(2000);
setTimezone();
ui_begin();
}
void printLocalTime() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
Serial.println("No time available (yet)");
return;
}
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
void printLocalTime()
{
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
Serial.println("No time available (yet)");
return;
}
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
}
// Callback function (get's called when time adjusts via NTP)
void timeavailable(struct timeval *t) {
Serial.println("Got time adjustment from NTP!");
printLocalTime();
WiFi.disconnect();
void timeavailable(struct timeval *t)
{
Serial.println("Got time adjustment from NTP!");
printLocalTime();
WiFi.disconnect();
}
void setTimezone() {
#ifdef CUSTOM_TIMEZONE
String timezone = CUSTOM_TIMEZONE;
#else
const char *rootCACertificate = "-----BEGIN CERTIFICATE-----\n"
"MIIDzTCCArWgAwIBAgIQCjeHZF5ftIwiTv0b7RQMPDANBgkqhkiG9w0BAQsFADBa\n"
"MQswCQYDVQQGEwJJRTESMBAGA1UEChMJQmFsdGltb3JlMRMwEQYDVQQLEwpDeWJl\n"
"clRydXN0MSIwIAYDVQQDExlCYWx0aW1vcmUgQ3liZXJUcnVzdCBSb290MB4XDTIw\n"
"MDEyNzEyNDgwOFoXDTI0MTIzMTIzNTk1OVowSjELMAkGA1UEBhMCVVMxGTAXBgNV\n"
"BAoTEENsb3VkZmxhcmUsIEluYy4xIDAeBgNVBAMTF0Nsb3VkZmxhcmUgSW5jIEVD\n"
"QyBDQS0zMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEua1NZpkUC0bsH4HRKlAe\n"
"nQMVLzQSfS2WuIg4m4Vfj7+7Te9hRsTJc9QkT+DuHM5ss1FxL2ruTAUJd9NyYqSb\n"
"16OCAWgwggFkMB0GA1UdDgQWBBSlzjfq67B1DpRniLRF+tkkEIeWHzAfBgNVHSME\n"
"GDAWgBTlnVkwgkdYzKz6CFQ2hns6tQRN8DAOBgNVHQ8BAf8EBAMCAYYwHQYDVR0l\n"
"BBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMBIGA1UdEwEB/wQIMAYBAf8CAQAwNAYI\n"
"KwYBBQUHAQEEKDAmMCQGCCsGAQUFBzABhhhodHRwOi8vb2NzcC5kaWdpY2VydC5j\n"
"b20wOgYDVR0fBDMwMTAvoC2gK4YpaHR0cDovL2NybDMuZGlnaWNlcnQuY29tL09t\n"
"bmlyb290MjAyNS5jcmwwbQYDVR0gBGYwZDA3BglghkgBhv1sAQEwKjAoBggrBgEF\n"
"BQcCARYcaHR0cHM6Ly93d3cuZGlnaWNlcnQuY29tL0NQUzALBglghkgBhv1sAQIw\n"
"CAYGZ4EMAQIBMAgGBmeBDAECAjAIBgZngQwBAgMwDQYJKoZIhvcNAQELBQADggEB\n"
"AAUkHd0bsCrrmNaF4zlNXmtXnYJX/OvoMaJXkGUFvhZEOFp3ArnPEELG4ZKk40Un\n"
"+ABHLGioVplTVI+tnkDB0A+21w0LOEhsUCxJkAZbZB2LzEgwLt4I4ptJIsCSDBFe\n"
"lpKU1fwg3FZs5ZKTv3ocwDfjhUkV+ivhdDkYD7fa86JXWGBPzI6UAPxGezQxPk1H\n"
"goE6y/SJXQ7vTQ1unBuCJN0yJV0ReFEQPaA1IwQvZW+cwdFD19Ae8zFnWSfda9J1\n"
"CZMRJCQUzym+5iPDuI9yP+kHyCREU3qzuWFloUwOxkgAyXVjBYdwRVKD05WdRerw\n"
"6DEdfgkfCv4+3ao8XnTSrLE=\n"
"-----END CERTIFICATE-----\n";
WiFiClientSecure *client = new WiFiClientSecure;
String timezone;
if (client) {
client->setCACert(rootCACertificate);
HTTPClient https;
if (https.begin(*client, GET_TIMEZONE_API)) {
int httpCode = https.GET();
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTPS] GET... code: %d\n", httpCode);
void setTimezone()
{
#ifdef CUSTOM_TIMEZONE
String timezone = CUSTOM_TIMEZONE;
#else
const char *rootCACertificate = "-----BEGIN CERTIFICATE-----\n"
"MIIDzTCCArWgAwIBAgIQCjeHZF5ftIwiTv0b7RQMPDANBgkqhkiG9w0BAQsFADBa\n"
"MQswCQYDVQQGEwJJRTESMBAGA1UEChMJQmFsdGltb3JlMRMwEQYDVQQLEwpDeWJl\n"
"clRydXN0MSIwIAYDVQQDExlCYWx0aW1vcmUgQ3liZXJUcnVzdCBSb290MB4XDTIw\n"
"MDEyNzEyNDgwOFoXDTI0MTIzMTIzNTk1OVowSjELMAkGA1UEBhMCVVMxGTAXBgNV\n"
"BAoTEENsb3VkZmxhcmUsIEluYy4xIDAeBgNVBAMTF0Nsb3VkZmxhcmUgSW5jIEVD\n"
"QyBDQS0zMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEua1NZpkUC0bsH4HRKlAe\n"
"nQMVLzQSfS2WuIg4m4Vfj7+7Te9hRsTJc9QkT+DuHM5ss1FxL2ruTAUJd9NyYqSb\n"
"16OCAWgwggFkMB0GA1UdDgQWBBSlzjfq67B1DpRniLRF+tkkEIeWHzAfBgNVHSME\n"
"GDAWgBTlnVkwgkdYzKz6CFQ2hns6tQRN8DAOBgNVHQ8BAf8EBAMCAYYwHQYDVR0l\n"
"BBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMBIGA1UdEwEB/wQIMAYBAf8CAQAwNAYI\n"
"KwYBBQUHAQEEKDAmMCQGCCsGAQUFBzABhhhodHRwOi8vb2NzcC5kaWdpY2VydC5j\n"
"b20wOgYDVR0fBDMwMTAvoC2gK4YpaHR0cDovL2NybDMuZGlnaWNlcnQuY29tL09t\n"
"bmlyb290MjAyNS5jcmwwbQYDVR0gBGYwZDA3BglghkgBhv1sAQEwKjAoBggrBgEF\n"
"BQcCARYcaHR0cHM6Ly93d3cuZGlnaWNlcnQuY29tL0NQUzALBglghkgBhv1sAQIw\n"
"CAYGZ4EMAQIBMAgGBmeBDAECAjAIBgZngQwBAgMwDQYJKoZIhvcNAQELBQADggEB\n"
"AAUkHd0bsCrrmNaF4zlNXmtXnYJX/OvoMaJXkGUFvhZEOFp3ArnPEELG4ZKk40Un\n"
"+ABHLGioVplTVI+tnkDB0A+21w0LOEhsUCxJkAZbZB2LzEgwLt4I4ptJIsCSDBFe\n"
"lpKU1fwg3FZs5ZKTv3ocwDfjhUkV+ivhdDkYD7fa86JXWGBPzI6UAPxGezQxPk1H\n"
"goE6y/SJXQ7vTQ1unBuCJN0yJV0ReFEQPaA1IwQvZW+cwdFD19Ae8zFnWSfda9J1\n"
"CZMRJCQUzym+5iPDuI9yP+kHyCREU3qzuWFloUwOxkgAyXVjBYdwRVKD05WdRerw\n"
"6DEdfgkfCv4+3ao8XnTSrLE=\n"
"-----END CERTIFICATE-----\n";
WiFiClientSecure *client = new WiFiClientSecure;
String timezone;
if (client) {
client->setCACert(rootCACertificate);
HTTPClient https;
if (https.begin(*client, GET_TIMEZONE_API)) {
int httpCode = https.GET();
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTPS] GET... code: %d\n", httpCode);
// file found at server
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = https.getString();
Serial.println(payload);
timezone = payload;
// file found at server
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = https.getString();
Serial.println(payload);
timezone = payload;
}
} else {
Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str());
}
https.end();
}
} else {
Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str());
}
https.end();
delete client;
}
delete client;
}
#endif
for (uint32_t i = 0; i < sizeof(zones); i++) {
if (timezone == "none") {
timezone = "CST-8";
break;
for (uint32_t i = 0; i < sizeof(zones); i++) {
if (timezone == "none") {
timezone = "CST-8";
break;
}
if (timezone == zones[i].name) {
timezone = zones[i].zones;
break;
}
}
if (timezone == zones[i].name) {
timezone = zones[i].zones;
break;
}
}
Serial.println("timezone : " + timezone);
setenv("TZ", timezone.c_str(), 1); // set time zone
tzset();
Serial.println("timezone : " + timezone);
setenv("TZ", timezone.c_str(), 1); // set time zone
tzset();
}

View File

@ -18,9 +18,6 @@ platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
platform_packages =
framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#2.0.5
build_flags =
-DLV_LVGL_H_INCLUDE_SIMPLE
-DBOARD_HAS_PSRAM

View File

@ -8,7 +8,7 @@
/* The product now has two screens, and the initialization code needs a small change in the new version. The LCD_MODULE_CMD_1 is used to define the
* switch macro. */
#define LCD_MODULE_CMD_1
// #define LCD_MODULE_CMD_1
/*
This example can only be run on platformIO.
@ -32,9 +32,9 @@ static lv_color_t *lv_disp_buf;
static bool is_initialized_lvgl = false;
#if defined(LCD_MODULE_CMD_1)
typedef struct {
uint8_t cmd;
uint8_t data[14];
uint8_t len;
uint8_t cmd;
uint8_t data[14];
uint8_t len;
} lcd_cmd_t;
lcd_cmd_t lcd_st7789v[] = {
@ -63,161 +63,166 @@ bool inited_touch = false;
bool get_int_signal = false;
#endif
static bool example_notify_lvgl_flush_ready(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx) {
if (is_initialized_lvgl) {
lv_disp_drv_t *disp_driver = (lv_disp_drv_t *)user_ctx;
lv_disp_flush_ready(disp_driver);
}
return false;
static bool example_notify_lvgl_flush_ready(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx)
{
if (is_initialized_lvgl) {
lv_disp_drv_t *disp_driver = (lv_disp_drv_t *)user_ctx;
lv_disp_flush_ready(disp_driver);
}
return false;
}
static void example_lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map) {
esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t)drv->user_data;
int offsetx1 = area->x1;
int offsetx2 = area->x2;
int offsety1 = area->y1;
int offsety2 = area->y2;
// copy a buffer's content to a specific area of the display
esp_lcd_panel_draw_bitmap(panel_handle, offsetx1, offsety1, offsetx2 + 1, offsety2 + 1, color_map);
static void example_lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map)
{
esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t)drv->user_data;
int offsetx1 = area->x1;
int offsetx2 = area->x2;
int offsety1 = area->y1;
int offsety2 = area->y2;
// copy a buffer's content to a specific area of the display
esp_lcd_panel_draw_bitmap(panel_handle, offsetx1, offsety1, offsetx2 + 1, offsety2 + 1, color_map);
}
static void lv_touchpad_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) {
static void lv_touchpad_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
{
#if defined(TOUCH_READ_FROM_INTERRNUPT)
if (get_int_signal) {
get_int_signal = false;
touch.read();
if (get_int_signal) {
get_int_signal = false;
touch.read();
#else
if (touch.read()) {
if (touch.read()) {
#endif
TP_Point t = touch.getPoint(0);
data->point.x = t.x;
data->point.y = t.y;
data->state = LV_INDEV_STATE_PR;
} else
data->state = LV_INDEV_STATE_REL;
TP_Point t = touch.getPoint(0);
data->point.x = t.x;
data->point.y = t.y;
data->state = LV_INDEV_STATE_PR;
} else
data->state = LV_INDEV_STATE_REL;
}
void setup() {
pinMode(PIN_POWER_ON, OUTPUT);
digitalWrite(PIN_POWER_ON, HIGH);
Serial.begin(115200);
void setup()
{
pinMode(PIN_POWER_ON, OUTPUT);
digitalWrite(PIN_POWER_ON, HIGH);
Serial.begin(115200);
pinMode(PIN_LCD_RD, OUTPUT);
digitalWrite(PIN_LCD_RD, HIGH);
esp_lcd_i80_bus_handle_t i80_bus = NULL;
esp_lcd_i80_bus_config_t bus_config = {
.dc_gpio_num = PIN_LCD_DC,
.wr_gpio_num = PIN_LCD_WR,
.clk_src = LCD_CLK_SRC_PLL160M,
.data_gpio_nums =
{
PIN_LCD_D0,
PIN_LCD_D1,
PIN_LCD_D2,
PIN_LCD_D3,
PIN_LCD_D4,
PIN_LCD_D5,
PIN_LCD_D6,
PIN_LCD_D7,
},
.bus_width = 8,
.max_transfer_bytes = LVGL_LCD_BUF_SIZE * sizeof(uint16_t),
};
esp_lcd_new_i80_bus(&bus_config, &i80_bus);
pinMode(PIN_LCD_RD, OUTPUT);
digitalWrite(PIN_LCD_RD, HIGH);
esp_lcd_i80_bus_handle_t i80_bus = NULL;
esp_lcd_i80_bus_config_t bus_config = {
.dc_gpio_num = PIN_LCD_DC,
.wr_gpio_num = PIN_LCD_WR,
.clk_src = LCD_CLK_SRC_PLL160M,
.data_gpio_nums =
{
PIN_LCD_D0,
PIN_LCD_D1,
PIN_LCD_D2,
PIN_LCD_D3,
PIN_LCD_D4,
PIN_LCD_D5,
PIN_LCD_D6,
PIN_LCD_D7,
},
.bus_width = 8,
.max_transfer_bytes = LVGL_LCD_BUF_SIZE * sizeof(uint16_t),
};
esp_lcd_new_i80_bus(&bus_config, &i80_bus);
esp_lcd_panel_io_i80_config_t io_config = {
.cs_gpio_num = PIN_LCD_CS,
.pclk_hz = EXAMPLE_LCD_PIXEL_CLOCK_HZ,
.trans_queue_depth = 20,
.on_color_trans_done = example_notify_lvgl_flush_ready,
.user_ctx = &disp_drv,
.lcd_cmd_bits = 8,
.lcd_param_bits = 8,
.dc_levels =
{
.dc_idle_level = 0,
.dc_cmd_level = 0,
.dc_dummy_level = 0,
.dc_data_level = 1,
},
};
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handle));
esp_lcd_panel_handle_t panel_handle = NULL;
esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = PIN_LCD_RES,
.color_space = ESP_LCD_COLOR_SPACE_RGB,
.bits_per_pixel = 16,
};
esp_lcd_new_panel_st7789(io_handle, &panel_config, &panel_handle);
esp_lcd_panel_reset(panel_handle);
esp_lcd_panel_init(panel_handle);
esp_lcd_panel_invert_color(panel_handle, true);
esp_lcd_panel_io_i80_config_t io_config = {
.cs_gpio_num = PIN_LCD_CS,
.pclk_hz = EXAMPLE_LCD_PIXEL_CLOCK_HZ,
.trans_queue_depth = 20,
.on_color_trans_done = example_notify_lvgl_flush_ready,
.user_ctx = &disp_drv,
.lcd_cmd_bits = 8,
.lcd_param_bits = 8,
.dc_levels =
{
.dc_idle_level = 0,
.dc_cmd_level = 0,
.dc_dummy_level = 0,
.dc_data_level = 1,
},
};
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handle));
esp_lcd_panel_handle_t panel_handle = NULL;
esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = PIN_LCD_RES,
.color_space = ESP_LCD_COLOR_SPACE_RGB,
.bits_per_pixel = 16,
};
esp_lcd_new_panel_st7789(io_handle, &panel_config, &panel_handle);
esp_lcd_panel_reset(panel_handle);
esp_lcd_panel_init(panel_handle);
esp_lcd_panel_invert_color(panel_handle, true);
esp_lcd_panel_swap_xy(panel_handle, true);
esp_lcd_panel_mirror(panel_handle, false, true);
// the gap is LCD panel specific, even panels with the same driver IC, can
// have different gap value
esp_lcd_panel_set_gap(panel_handle, 0, 35);
esp_lcd_panel_swap_xy(panel_handle, true);
esp_lcd_panel_mirror(panel_handle, false, true);
// the gap is LCD panel specific, even panels with the same driver IC, can
// have different gap value
esp_lcd_panel_set_gap(panel_handle, 0, 35);
#if defined(LCD_MODULE_CMD_1)
for (uint8_t i = 0; i < (sizeof(lcd_st7789v) / sizeof(lcd_cmd_t)); i++) {
esp_lcd_panel_io_tx_param(io_handle, lcd_st7789v[i].cmd, lcd_st7789v[i].data, lcd_st7789v[i].len & 0x7f);
if (lcd_st7789v[i].len & 0x80)
delay(120);
}
for (uint8_t i = 0; i < (sizeof(lcd_st7789v) / sizeof(lcd_cmd_t)); i++) {
esp_lcd_panel_io_tx_param(io_handle, lcd_st7789v[i].cmd, lcd_st7789v[i].data, lcd_st7789v[i].len & 0x7f);
if (lcd_st7789v[i].len & 0x80)
delay(120);
}
#endif
/* Lighten the screen with gradient */
ledcSetup(0, 10000, 8);
ledcAttachPin(PIN_LCD_BL, 0);
for (uint8_t i = 0; i < 0xFF; i++) {
ledcWrite(0, i);
delay(2);
}
/* Lighten the screen with gradient */
ledcSetup(0, 10000, 8);
ledcAttachPin(PIN_LCD_BL, 0);
for (uint8_t i = 0; i < 0xFF; i++) {
ledcWrite(0, i);
delay(2);
}
lv_init();
lv_disp_buf = (lv_color_t *)heap_caps_malloc(LVGL_LCD_BUF_SIZE * sizeof(lv_color_t), MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
lv_init();
lv_disp_buf = (lv_color_t *)heap_caps_malloc(LVGL_LCD_BUF_SIZE * sizeof(lv_color_t), MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
lv_disp_draw_buf_init(&disp_buf, lv_disp_buf, NULL, LVGL_LCD_BUF_SIZE);
/*Initialize the display*/
lv_disp_drv_init(&disp_drv);
/*Change the following line to your display resolution*/
disp_drv.hor_res = EXAMPLE_LCD_H_RES;
disp_drv.ver_res = EXAMPLE_LCD_V_RES;
disp_drv.flush_cb = example_lvgl_flush_cb;
disp_drv.draw_buf = &disp_buf;
disp_drv.user_data = panel_handle;
lv_disp_drv_register(&disp_drv);
lv_disp_draw_buf_init(&disp_buf, lv_disp_buf, NULL, LVGL_LCD_BUF_SIZE);
/*Initialize the display*/
lv_disp_drv_init(&disp_drv);
/*Change the following line to your display resolution*/
disp_drv.hor_res = EXAMPLE_LCD_H_RES;
disp_drv.ver_res = EXAMPLE_LCD_V_RES;
disp_drv.flush_cb = example_lvgl_flush_cb;
disp_drv.draw_buf = &disp_buf;
disp_drv.user_data = panel_handle;
lv_disp_drv_register(&disp_drv);
/* Register touch brush with LVGL */
Wire.begin(PIN_IIC_SDA, PIN_IIC_SCL, 800000);
inited_touch = touch.init();
if (inited_touch) {
touch.setRotation(1);
static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = lv_touchpad_read;
lv_indev_drv_register(&indev_drv);
}
is_initialized_lvgl = true;
/* Register touch brush with LVGL */
Wire.begin(PIN_IIC_SDA, PIN_IIC_SCL, 800000);
inited_touch = touch.init();
if (inited_touch) {
touch.setRotation(1);
static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = lv_touchpad_read;
lv_indev_drv_register(&indev_drv);
}
is_initialized_lvgl = true;
#if defined(TOUCH_READ_FROM_INTERRNUPT)
attachInterrupt(
PIN_TOUCH_INT, [] { get_int_signal = true; }, FALLING);
attachInterrupt(
PIN_TOUCH_INT, [] { get_int_signal = true; }, FALLING);
#endif
#if LV_USE_DEMO_WIDGETS
lv_demo_widgets();
lv_demo_widgets();
#elif LV_USE_DEMO_BENCHMARK
lv_demo_benchmark();
lv_demo_benchmark();
#elif LV_USE_DEMO_STRESS
lv_demo_stress();
lv_demo_stress();
#elif LV_USE_DEMO_KEYPAD_AND_ENCODER
lv_demo_keypad_encoder();
lv_demo_keypad_encoder();
#else LV_USE_DEMO_MUSIC
lv_demo_music();
lv_demo_music();
#endif
}
void loop() {
lv_timer_handler();
delay(2);
void loop()
{
lv_timer_handler();
delay(2);
}

View File

@ -18,9 +18,6 @@ platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
platform_packages =
framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#2.0.5
build_flags =
-DLV_LVGL_H_INCLUDE_SIMPLE
-DBOARD_HAS_PSRAM

View File

@ -1,6 +1,6 @@
/* The product now has two screens, and the initialization code needs a small change in the new version. The LCD_MODULE_CMD_1 is used to define the
* switch macro. */
#define LCD_MODULE_CMD_1
// #define LCD_MODULE_CMD_1
#include <esp_task_wdt.h>
#include <esp_wifi.h>
@ -22,7 +22,7 @@ extern "C" {
#define FSROOT "/fs"
Arduino_DataBus *bus = new Arduino_ESP32LCD8(7 /* DC */, 6 /* CS */, 8 /* WR */, 9 /* RD */, 39 /* D0 */, 40 /* D1 */, 41 /* D2 */, 42 /* D3 */,
45 /* D4 */, 46 /* D5 */, 47 /* D6 */, 48 /* D7 */);
45 /* D4 */, 46 /* D5 */, 47 /* D6 */, 48 /* D7 */);
Arduino_GFX *gfx = new Arduino_ST7789(bus, 5 /* RST */, 0 /* rotation */, true /* IPS */, 170 /* width */, 320 /* height */, 35 /* col offset 1 */,
0 /* row offset 1 */, 35 /* col offset 2 */, 0 /* row offset 2 */);
@ -31,9 +31,9 @@ extern uint16_t myPalette[];
int16_t bg_color;
#if defined(LCD_MODULE_CMD_1)
typedef struct {
uint8_t cmd;
uint8_t data[14];
uint8_t len;
uint8_t cmd;
uint8_t data[14];
uint8_t len;
} lcd_cmd_t;
lcd_cmd_t lcd_st7789v[] = {
@ -55,102 +55,111 @@ lcd_cmd_t lcd_st7789v[] = {
};
#endif
void setup() {
pinMode(PIN_POWER_ON, OUTPUT);
digitalWrite(PIN_POWER_ON, HIGH);
ledcSetup(0, 2000, 8);
ledcAttachPin(PIN_LCD_BL, 0);
ledcWrite(0, 255); /* Screen brightness can be modified by adjusting this parameter. (0-255) */
void setup()
{
pinMode(PIN_POWER_ON, OUTPUT);
digitalWrite(PIN_POWER_ON, HIGH);
ledcSetup(0, 2000, 8);
ledcAttachPin(PIN_LCD_BL, 0);
ledcWrite(0, 255); /* Screen brightness can be modified by adjusting this parameter. (0-255) */
Serial.begin(115200);
Serial.println("Hello T-Display-S3 NES DEMO");
Serial.begin(115200);
Serial.println("Hello T-Display-S3 NES DEMO");
// turn off WiFi
esp_wifi_deinit();
// turn off WiFi
esp_wifi_deinit();
// disable Core 0 WDT
TaskHandle_t idle_0 = xTaskGetIdleTaskHandleForCPU(0);
esp_task_wdt_delete(idle_0);
// disable Core 0 WDT
TaskHandle_t idle_0 = xTaskGetIdleTaskHandleForCPU(0);
esp_task_wdt_delete(idle_0);
gfx->begin();
gfx->setRotation(1);
bg_color = gfx->color565(24, 28, 24); // DARK DARK GREY
gfx->begin();
gfx->setRotation(1);
bg_color = gfx->color565(24, 28, 24); // DARK DARK GREY
#if defined(LCD_MODULE_CMD_1)
for (uint8_t i = 0; i < (sizeof(lcd_st7789v) / sizeof(lcd_cmd_t)); i++) {
bus->sendCommand(lcd_st7789v[i].cmd);
for (int j = 0; j < lcd_st7789v[i].len & 0x7f; j++) {
bus->sendData(lcd_st7789v[i].data[j]);
}
for (uint8_t i = 0; i < (sizeof(lcd_st7789v) / sizeof(lcd_cmd_t)); i++) {
bus->sendCommand(lcd_st7789v[i].cmd);
for (int j = 0; j < lcd_st7789v[i].len & 0x7f; j++) {
bus->sendData(lcd_st7789v[i].data[j]);
}
if (lcd_st7789v[i].len & 0x80) {
delay(120);
if (lcd_st7789v[i].len & 0x80) {
delay(120);
}
}
}
#endif
gfx->draw16bitRGBBitmap(0, 0, (uint16_t *)img_logo, 320, 172);
delay(2000);
gfx->draw16bitRGBBitmap(0, 0, (uint16_t *)img_logo, 320, 172);
delay(2000);
SPIFFS.begin(true, FSROOT);
SPIFFS.begin(true, FSROOT);
FS filesystem = SPIFFS;
FS filesystem = SPIFFS;
// find first rom file (*.nes)
File root = filesystem.open("/");
char *argv[1];
if (!root) {
Serial.println("Filesystem mount failed!");
} else {
bool foundRom = false;
// find first rom file (*.nes)
File root = filesystem.open("/");
char *argv[1];
if (!root) {
Serial.println("Filesystem mount failed!");
} else {
bool foundRom = false;
File file = root.openNextFile();
while (file) {
if (file.isDirectory()) {
// skip
} else {
char *filename = (char *)file.name();
int8_t len = strlen(filename);
if (strstr(strlwr(filename + (len - 4)), ".nes")) {
foundRom = true;
char fullFilename[256];
sprintf(fullFilename, "%s/%s", FSROOT, filename);
Serial.println(fullFilename);
argv[0] = fullFilename;
break;
File file = root.openNextFile();
while (file) {
if (file.isDirectory()) {
// skip
} else {
char *filename = (char *)file.name();
int8_t len = strlen(filename);
if (strstr(strlwr(filename + (len - 4)), ".nes")) {
foundRom = true;
char fullFilename[256];
sprintf(fullFilename, "%s/%s", FSROOT, filename);
Serial.println(fullFilename);
argv[0] = fullFilename;
break;
}
}
file = root.openNextFile();
}
}
file = root.openNextFile();
if (!foundRom) {
Serial.println("Failed to find rom file, please copy rom file to data folder and upload with \"ESP32 Sketch Data Upload\"");
argv[0] = "/";
}
Serial.println("NoFrendo start!\n");
nofrendo_main(1, argv);
Serial.println("NoFrendo end!\n");
}
}
void loop(void)
{
delay(1);
}
if (!foundRom) {
Serial.println("Failed to find rom file, please copy rom file to data folder and upload with \"ESP32 Sketch Data Upload\"");
argv[0] = "/";
extern "C" void display_init()
{
frame_x = (gfx->width() - NES_SCREEN_WIDTH) / 2;
frame_y = 35;
}
extern "C" void display_write_frame(const uint8_t *data[])
{
gfx->startWrite();
bus->writeC8D16D16(0x2A, frame_x, frame_x + NES_SCREEN_WIDTH - 1);
bus->writeC8D16D16(0x2B, frame_y, frame_y + NES_SCREEN_HEIGHT - 1);
bus->writeCommand(0x2c);
for (int32_t i = 0; i < NES_SCREEN_HEIGHT; i++) {
if ((i % 7) < 5)
bus->writeIndexedPixels((uint8_t *)(data[i]), myPalette, NES_SCREEN_WIDTH);
}
Serial.println("NoFrendo start!\n");
nofrendo_main(1, argv);
Serial.println("NoFrendo end!\n");
}
}
void loop(void) { delay(1); }
extern "C" void display_init() {
frame_x = (gfx->width() - NES_SCREEN_WIDTH) / 2;
frame_y = 35;
gfx->endWrite();
}
extern "C" void display_write_frame(const uint8_t *data[]) {
gfx->startWrite();
bus->writeC8D16D16(0x2A, frame_x, frame_x + NES_SCREEN_WIDTH - 1);
bus->writeC8D16D16(0x2B, frame_y, frame_y + NES_SCREEN_HEIGHT - 1);
bus->writeCommand(0x2c);
for (int32_t i = 0; i < NES_SCREEN_HEIGHT; i++) {
if ((i % 7) < 5)
bus->writeIndexedPixels((uint8_t *)(data[i]), myPalette, NES_SCREEN_WIDTH);
}
gfx->endWrite();
}
extern "C" void display_clear() { gfx->fillScreen(bg_color); }
extern "C" void display_clear()
{
gfx->fillScreen(bg_color);
}

View File

@ -18,9 +18,6 @@ platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
platform_packages =
framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#2.0.5
build_flags =
-DLV_LVGL_H_INCLUDE_SIMPLE
-DBOARD_HAS_PSRAM

View File

@ -18,8 +18,6 @@ platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
platform_packages =
framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#2.0.5
build_flags =
-DLV_LVGL_H_INCLUDE_SIMPLE

View File

@ -5,7 +5,7 @@
/* The product now has two screens, and the initialization code needs a small change in the new version. The LCD_MODULE_CMD_1 is used to define the
* switch macro. */
#define LCD_MODULE_CMD_1
// #define LCD_MODULE_CMD_1
TFT_eSPI tft = TFT_eSPI();
#define WAIT 1000
@ -13,9 +13,9 @@ unsigned long targetTime = 0; // Used for testing draw times
#if defined(LCD_MODULE_CMD_1)
typedef struct {
uint8_t cmd;
uint8_t data[14];
uint8_t len;
uint8_t cmd;
uint8_t data[14];
uint8_t len;
} lcd_cmd_t;
lcd_cmd_t lcd_st7789v[] = {
@ -36,190 +36,192 @@ lcd_cmd_t lcd_st7789v[] = {
};
#endif
void setup() {
pinMode(PIN_POWER_ON, OUTPUT);
digitalWrite(PIN_POWER_ON, HIGH);
void setup()
{
pinMode(PIN_POWER_ON, OUTPUT);
digitalWrite(PIN_POWER_ON, HIGH);
Serial.begin(115200);
Serial.println("Hello T-Display-S3");
Serial.begin(115200);
Serial.println("Hello T-Display-S3");
tft.begin();
tft.begin();
#if defined(LCD_MODULE_CMD_1)
for (uint8_t i = 0; i < (sizeof(lcd_st7789v) / sizeof(lcd_cmd_t)); i++) {
tft.writecommand(lcd_st7789v[i].cmd);
for (int j = 0; j < lcd_st7789v[i].len & 0x7f; j++) {
tft.writedata(lcd_st7789v[i].data[j]);
}
for (uint8_t i = 0; i < (sizeof(lcd_st7789v) / sizeof(lcd_cmd_t)); i++) {
tft.writecommand(lcd_st7789v[i].cmd);
for (int j = 0; j < lcd_st7789v[i].len & 0x7f; j++) {
tft.writedata(lcd_st7789v[i].data[j]);
}
if (lcd_st7789v[i].len & 0x80) {
delay(120);
if (lcd_st7789v[i].len & 0x80) {
delay(120);
}
}
}
#endif
tft.setRotation(3);
tft.setSwapBytes(true);
tft.pushImage(0, 0, 320, 170, (uint16_t *)img_logo);
delay(2000);
tft.setRotation(3);
tft.setSwapBytes(true);
tft.pushImage(0, 0, 320, 170, (uint16_t *)img_logo);
delay(2000);
ledcSetup(0, 2000, 8);
ledcAttachPin(PIN_LCD_BL, 0);
ledcWrite(0, 255);
ledcSetup(0, 2000, 8);
ledcAttachPin(PIN_LCD_BL, 0);
ledcWrite(0, 255);
}
void loop() {
targetTime = millis();
void loop()
{
targetTime = millis();
// First we test them with a background colour set
tft.setTextSize(1);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_GREEN, TFT_BLACK);
// First we test them with a background colour set
tft.setTextSize(1);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.drawString(" !\"#$%&'()*+,-./0123456", 0, 0, 2);
tft.drawString("789:;<=>?@ABCDEFGHIJKL", 0, 16, 2);
tft.drawString("MNOPQRSTUVWXYZ[\\]^_`", 0, 32, 2);
tft.drawString("abcdefghijklmnopqrstuvw", 0, 48, 2);
int xpos = 0;
xpos += tft.drawString("xyz{|}~", 0, 64, 2);
tft.drawChar(127, xpos, 64, 2);
delay(WAIT);
tft.drawString(" !\"#$%&'()*+,-./0123456", 0, 0, 2);
tft.drawString("789:;<=>?@ABCDEFGHIJKL", 0, 16, 2);
tft.drawString("MNOPQRSTUVWXYZ[\\]^_`", 0, 32, 2);
tft.drawString("abcdefghijklmnopqrstuvw", 0, 48, 2);
int xpos = 0;
xpos += tft.drawString("xyz{|}~", 0, 64, 2);
tft.drawChar(127, xpos, 64, 2);
delay(WAIT);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.drawString(" !\"#$%&'()*+,-.", 0, 0, 4);
tft.drawString("/0123456789:;", 0, 26, 4);
tft.drawString("<=>?@ABCDE", 0, 52, 4);
tft.drawString("FGHIJKLMNO", 0, 78, 4);
tft.drawString("PQRSTUVWX", 0, 104, 4);
delay(WAIT);
tft.drawString(" !\"#$%&'()*+,-.", 0, 0, 4);
tft.drawString("/0123456789:;", 0, 26, 4);
tft.drawString("<=>?@ABCDE", 0, 52, 4);
tft.drawString("FGHIJKLMNO", 0, 78, 4);
tft.drawString("PQRSTUVWX", 0, 104, 4);
delay(WAIT);
tft.fillScreen(TFT_BLACK);
tft.drawString("YZ[\\]^_`abc", 0, 0, 4);
tft.drawString("defghijklmno", 0, 26, 4);
tft.drawString("pqrstuvwxyz", 0, 52, 4);
xpos = 0;
xpos += tft.drawString("{|}~", 0, 78, 4);
tft.drawChar(127, xpos, 78, 4);
delay(WAIT);
tft.fillScreen(TFT_BLACK);
tft.drawString("YZ[\\]^_`abc", 0, 0, 4);
tft.drawString("defghijklmno", 0, 26, 4);
tft.drawString("pqrstuvwxyz", 0, 52, 4);
xpos = 0;
xpos += tft.drawString("{|}~", 0, 78, 4);
tft.drawChar(127, xpos, 78, 4);
delay(WAIT);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_BLUE, TFT_BLACK);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_BLUE, TFT_BLACK);
tft.drawString("012345", 0, 0, 6);
tft.drawString("6789", 0, 40, 6);
tft.drawString("apm-:.", 0, 80, 6);
delay(WAIT);
tft.drawString("012345", 0, 0, 6);
tft.drawString("6789", 0, 40, 6);
tft.drawString("apm-:.", 0, 80, 6);
delay(WAIT);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.drawString("0123", 0, 0, 7);
tft.drawString("4567", 0, 60, 7);
delay(WAIT);
tft.drawString("0123", 0, 0, 7);
tft.drawString("4567", 0, 60, 7);
delay(WAIT);
tft.fillScreen(TFT_BLACK);
tft.drawString("890:.", 0, 0, 7);
tft.drawString("", 0, 60, 7);
delay(WAIT);
tft.fillScreen(TFT_BLACK);
tft.drawString("890:.", 0, 0, 7);
tft.drawString("", 0, 60, 7);
delay(WAIT);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
tft.drawString("01", 0, 0, 8);
delay(WAIT);
tft.drawString("01", 0, 0, 8);
delay(WAIT);
tft.drawString("23", 0, 0, 8);
delay(WAIT);
tft.drawString("23", 0, 0, 8);
delay(WAIT);
tft.drawString("45", 0, 0, 8);
delay(WAIT);
tft.drawString("45", 0, 0, 8);
delay(WAIT);
tft.drawString("67", 0, 0, 8);
delay(WAIT);
tft.drawString("67", 0, 0, 8);
delay(WAIT);
tft.drawString("89", 0, 0, 8);
delay(WAIT);
tft.drawString("89", 0, 0, 8);
delay(WAIT);
tft.drawString("0:.", 0, 0, 8);
delay(WAIT);
tft.drawString("0:.", 0, 0, 8);
delay(WAIT);
tft.setTextColor(TFT_MAGENTA);
tft.drawNumber(millis() - targetTime, 0, 100, 4);
delay(4000);
tft.setTextColor(TFT_MAGENTA);
tft.drawNumber(millis() - targetTime, 0, 100, 4);
delay(4000);
// Now test them with transparent background
targetTime = millis();
// Now test them with transparent background
targetTime = millis();
tft.setTextSize(1);
tft.fillScreen(TFT_BROWN);
tft.setTextColor(TFT_GREEN);
tft.setTextSize(1);
tft.fillScreen(TFT_BROWN);
tft.setTextColor(TFT_GREEN);
tft.drawString(" !\"#$%&'()*+,-./0123456", 0, 0, 2);
tft.drawString("789:;<=>?@ABCDEFGHIJKL", 0, 16, 2);
tft.drawString("MNOPQRSTUVWXYZ[\\]^_`", 0, 32, 2);
tft.drawString("abcdefghijklmnopqrstuvw", 0, 48, 2);
xpos = 0;
xpos += tft.drawString("xyz{|}~", 0, 64, 2);
tft.drawChar(127, xpos, 64, 2);
delay(WAIT);
tft.drawString(" !\"#$%&'()*+,-./0123456", 0, 0, 2);
tft.drawString("789:;<=>?@ABCDEFGHIJKL", 0, 16, 2);
tft.drawString("MNOPQRSTUVWXYZ[\\]^_`", 0, 32, 2);
tft.drawString("abcdefghijklmnopqrstuvw", 0, 48, 2);
xpos = 0;
xpos += tft.drawString("xyz{|}~", 0, 64, 2);
tft.drawChar(127, xpos, 64, 2);
delay(WAIT);
tft.fillScreen(TFT_BROWN);
tft.setTextColor(TFT_GREEN);
tft.fillScreen(TFT_BROWN);
tft.setTextColor(TFT_GREEN);
tft.drawString(" !\"#$%&'()*+,-.", 0, 0, 4);
tft.drawString("/0123456789:;", 0, 26, 4);
tft.drawString("<=>?@ABCDE", 0, 52, 4);
tft.drawString("FGHIJKLMNO", 0, 78, 4);
tft.drawString("PQRSTUVWX", 0, 104, 4);
tft.drawString(" !\"#$%&'()*+,-.", 0, 0, 4);
tft.drawString("/0123456789:;", 0, 26, 4);
tft.drawString("<=>?@ABCDE", 0, 52, 4);
tft.drawString("FGHIJKLMNO", 0, 78, 4);
tft.drawString("PQRSTUVWX", 0, 104, 4);
delay(WAIT);
tft.fillScreen(TFT_BROWN);
tft.drawString("YZ[\\]^_`abc", 0, 0, 4);
tft.drawString("defghijklmno", 0, 26, 4);
tft.drawString("pqrstuvwxyz", 0, 52, 4);
xpos = 0;
xpos += tft.drawString("{|}~", 0, 78, 4);
tft.drawChar(127, xpos, 78, 4);
delay(WAIT);
delay(WAIT);
tft.fillScreen(TFT_BROWN);
tft.drawString("YZ[\\]^_`abc", 0, 0, 4);
tft.drawString("defghijklmno", 0, 26, 4);
tft.drawString("pqrstuvwxyz", 0, 52, 4);
xpos = 0;
xpos += tft.drawString("{|}~", 0, 78, 4);
tft.drawChar(127, xpos, 78, 4);
delay(WAIT);
tft.fillScreen(TFT_BROWN);
tft.setTextColor(TFT_BLUE);
tft.fillScreen(TFT_BROWN);
tft.setTextColor(TFT_BLUE);
tft.drawString("012345", 0, 0, 6);
tft.drawString("6789", 0, 40, 6);
tft.drawString("apm-:.", 0, 80, 6);
delay(WAIT);
tft.drawString("012345", 0, 0, 6);
tft.drawString("6789", 0, 40, 6);
tft.drawString("apm-:.", 0, 80, 6);
delay(WAIT);
tft.fillScreen(TFT_BROWN);
tft.setTextColor(TFT_RED);
tft.fillScreen(TFT_BROWN);
tft.setTextColor(TFT_RED);
tft.drawString("0123", 0, 0, 7);
tft.drawString("4567", 0, 60, 7);
delay(WAIT);
tft.drawString("0123", 0, 0, 7);
tft.drawString("4567", 0, 60, 7);
delay(WAIT);
tft.fillScreen(TFT_BROWN);
tft.drawString("890:.", 0, 0, 7);
tft.drawString("", 0, 60, 7);
delay(WAIT);
tft.fillScreen(TFT_BROWN);
tft.drawString("890:.", 0, 0, 7);
tft.drawString("", 0, 60, 7);
delay(WAIT);
tft.fillScreen(TFT_BROWN);
tft.setTextColor(TFT_YELLOW);
tft.fillScreen(TFT_BROWN);
tft.setTextColor(TFT_YELLOW);
tft.drawString("0123", 0, 0, 8);
delay(WAIT);
tft.drawString("0123", 0, 0, 8);
delay(WAIT);
tft.fillScreen(TFT_BROWN);
tft.drawString("4567", 0, 0, 8);
delay(WAIT);
tft.fillScreen(TFT_BROWN);
tft.drawString("4567", 0, 0, 8);
delay(WAIT);
tft.fillScreen(TFT_BROWN);
tft.drawString("890:.", 0, 0, 8);
delay(WAIT);
tft.fillScreen(TFT_BROWN);
tft.drawString("890:.", 0, 0, 8);
delay(WAIT);
tft.setTextColor(TFT_MAGENTA);
tft.setTextColor(TFT_MAGENTA);
tft.drawNumber(millis() - targetTime, 0, 100, 4);
delay(4000);
tft.drawNumber(millis() - targetTime, 0, 100, 4);
delay(4000);
}

View File

@ -17,11 +17,6 @@ src_dir = .
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
platform_packages =
framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#2.0.5
build_flags =
-DLV_LVGL_H_INCLUDE_SIMPLE
-DBOARD_HAS_PSRAM
@ -30,6 +25,3 @@ build_flags =
; -DTOUCH_MODULES_CST_MUTUAL
; -DTOUCH_MODULES_CST_SELF
board_build.arduino.memory_type = qio_opi
lib_deps =
mathertel/OneButton @ ^2.0.3