diff --git a/README.md b/README.md index 534f9b1c..15720abe 100644 --- a/README.md +++ b/README.md @@ -37,3 +37,7 @@ Specifications: * MPU6050 Accelerometer and Gyroscope IMU * HT1818Z3G5L GPS Module * LVGL UI + LovyanGFX + +Added support to Makerfabs ESP32-S3 Parallel TFT with Touch 3.5" ILI9488 (thanks to @hpsaturn) + + diff --git a/lib/lv_CUSTOMBOARD_conf.h b/lib/lv_CUSTOMBOARD_conf.h index c81d2482..c79a94b7 100644 --- a/lib/lv_CUSTOMBOARD_conf.h +++ b/lib/lv_CUSTOMBOARD_conf.h @@ -90,8 +90,10 @@ *It removes the need to manually update the tick with `lv_tick_inc()`)*/ #define LV_TICK_CUSTOM 1 #if LV_TICK_CUSTOM - #define LV_TICK_CUSTOM_INCLUDE "Arduino.h" /*Header for the system time function*/ - #define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current system time in ms*/ + //#define LV_TICK_CUSTOM_INCLUDE "Arduino.h" /*Header for the system time function*/ + //#define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current system time in ms*/ + #define LV_TICK_CUSTOM_INCLUDE "esp_timer.h" + #define LV_TICK_CUSTOM_SYS_TIME_EXPR ((esp_timer_get_time() / 1000LL)) #endif /*LV_TICK_CUSTOM*/ /*Default Dot Per Inch. Used to initialize default sizes such as widgets sized, style paddings. diff --git a/lib/lv_MAKERF_ESP32S3_conf.h b/lib/lv_MAKERF_ESP32S3_conf.h index c81d2482..134ac498 100644 --- a/lib/lv_MAKERF_ESP32S3_conf.h +++ b/lib/lv_MAKERF_ESP32S3_conf.h @@ -88,10 +88,12 @@ /*Use a custom tick source that tells the elapsed time in milliseconds. *It removes the need to manually update the tick with `lv_tick_inc()`)*/ -#define LV_TICK_CUSTOM 1 +#define LV_TICK_CUSTOM 0 #if LV_TICK_CUSTOM - #define LV_TICK_CUSTOM_INCLUDE "Arduino.h" /*Header for the system time function*/ - #define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current system time in ms*/ + //#define LV_TICK_CUSTOM_INCLUDE "Arduino.h" /*Header for the system time function*/ + //#define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current system time in ms*/ + #define LV_TICK_CUSTOM_INCLUDE "esp_timer.h" + #define LV_TICK_CUSTOM_SYS_TIME_EXPR ((esp_timer_get_time() / 1000LL)) #endif /*LV_TICK_CUSTOM*/ /*Default Dot Per Inch. Used to initialize default sizes such as widgets sized, style paddings. diff --git a/lib/makefabs-esp32s3parallel/FT6236.cpp b/lib/makefabs-esp32s3parallel/FT6236.cpp deleted file mode 100644 index 0a3d2e55..00000000 --- a/lib/makefabs-esp32s3parallel/FT6236.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include "FT6236.h" - -int readTouchReg(int reg) -{ - int data = 0; - Wire.beginTransmission(TOUCH_I2C_ADD); - Wire.write(reg); - Wire.endTransmission(); - Wire.requestFrom(TOUCH_I2C_ADD, 1); - if (Wire.available()) - { - data = Wire.read(); - } - return data; -} - -/* -int getTouchPointX() -{ - int XL = 0; - int XH = 0; - - XH = readTouchReg(TOUCH_REG_XH); - XL = readTouchReg(TOUCH_REG_XL); - - return ((XH & 0x0F) << 8) | XL; -} -*/ - -int getTouchPointX() -{ - int XL = 0; - int XH = 0; - - XH = readTouchReg(TOUCH_REG_XH); - //Serial.println(XH >> 6,HEX); - if(XH >> 6 == 1) - return -1; - XL = readTouchReg(TOUCH_REG_XL); - - return ((XH & 0x0F) << 8) | XL; -} - -int getTouchPointY() -{ - int YL = 0; - int YH = 0; - - YH = readTouchReg(TOUCH_REG_YH); - YL = readTouchReg(TOUCH_REG_YL); - - return ((YH & 0x0F) << 8) | YL; -} - -int ft6236_pos(int pos[2]) -{ - int XL = 0; - int XH = 0; - int YL = 0; - int YH = 0; - - XH = readTouchReg(TOUCH_REG_XH); - if(XH >> 6 == 1) - { - pos[0] = -1; - pos[1] = -1; - return 0; - } - XL = readTouchReg(TOUCH_REG_XL); - YH = readTouchReg(TOUCH_REG_YH); - YL = readTouchReg(TOUCH_REG_YL); - - pos[0] = ((XH & 0x0F) << 8) | XL; - pos[1] = ((YH & 0x0F) << 8) | YL; - return 1; -} \ No newline at end of file diff --git a/lib/makefabs-esp32s3parallel/FT6236.h b/lib/makefabs-esp32s3parallel/FT6236.h deleted file mode 100644 index eb7a494d..00000000 --- a/lib/makefabs-esp32s3parallel/FT6236.h +++ /dev/null @@ -1,16 +0,0 @@ -#include - -#define TOUCH_I2C_ADD 0x38 - -#define TOUCH_REG_XL 0x04 -#define TOUCH_REG_XH 0x03 -#define TOUCH_REG_YL 0x06 -#define TOUCH_REG_YH 0x05 - -int readTouchReg(int reg); - -int getTouchPointX(); - -int getTouchPointY(); - -int ft6236_pos(int pos[2]); \ No newline at end of file diff --git a/lib/makefabs-esp32s3parallel/LGFX_MakerFabs_Parallel_S3.hpp b/lib/makefabs-esp32s3parallel/LGFX_MakerFabs_Parallel_S3.hpp index 9e1ffd5e..4988434d 100644 --- a/lib/makefabs-esp32s3parallel/LGFX_MakerFabs_Parallel_S3.hpp +++ b/lib/makefabs-esp32s3parallel/LGFX_MakerFabs_Parallel_S3.hpp @@ -5,29 +5,17 @@ #include "SPI.h" #include -#define I2C_SCL 39 -#define I2C_SDA 38 - -//#define NS2009_TOUCH //Resistive screen driver -#define FT6236_TOUCH //Capacitive screen driver - -#ifdef NS2009_TOUCH -#include "NS2009.h" -const int i2c_touch_addr = NS2009_ADDR; -#define get_pos ns2009_pos -#endif - -#ifdef FT6236_TOUCH -#include "FT6236.h" -const int i2c_touch_addr = TOUCH_I2C_ADD; -#define get_pos ft6236_pos -#endif - class LGFX : public lgfx::LGFX_Device { + static constexpr int I2C_PORT_NUM = 0; + static constexpr int I2C_PIN_SDA = 38; + static constexpr int I2C_PIN_SCL = 39; + static constexpr int I2C_PIN_INT = 40; + // lgfx::Panel_ILI9341 _panel_instance; lgfx::Panel_ILI9488 _panel_instance; lgfx::Bus_Parallel16 _bus_instance; // 8ビットパラレルバスのインスタンス (ESP32のみ) + lgfx::Touch_FT5x06 _touch_instance; public: // コンストラクタを作成し、ここで各種設定を行います。 @@ -93,5 +81,27 @@ class LGFX : public lgfx::LGFX_Device } setPanel(&_panel_instance); // 使用するパネルをセットします。 + + { + auto cfg = _touch_instance.config(); + + cfg.x_min = 0; + cfg.x_max = 320; + cfg.y_min = 0; + cfg.y_max = 480; + cfg.pin_int = I2C_PIN_INT; + cfg.bus_shared = true; + cfg.offset_rotation = 0; + + cfg.i2c_port = I2C_PORT_NUM; + cfg.i2c_addr = 0x38; + cfg.pin_sda = I2C_PIN_SDA; + cfg.pin_scl = I2C_PIN_SCL; + cfg.freq = 400000; + + _touch_instance.config(cfg); + _panel_instance.setTouch(&_touch_instance); + } + setPanel(&_panel_instance); } }; diff --git a/lib/makefabs-esp32s3parallel/NS2009.cpp b/lib/makefabs-esp32s3parallel/NS2009.cpp deleted file mode 100644 index c43c0d23..00000000 --- a/lib/makefabs-esp32s3parallel/NS2009.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "NS2009.h" - -//I2C receive -void ns2009_recv(const uint8_t *send_buf, size_t send_buf_len, uint8_t *receive_buf, - size_t receive_buf_len) -{ - Wire.beginTransmission(NS2009_ADDR); - Wire.write(send_buf, send_buf_len); - Wire.endTransmission(); - Wire.requestFrom(NS2009_ADDR, receive_buf_len); - while (Wire.available()) - { - *receive_buf++ = Wire.read(); - } -} - -//read 12bit data -unsigned int ns2009_read(uint8_t cmd) -{ - uint8_t buf[2]; - ns2009_recv(&cmd, 1, buf, 2); - return (buf[0] << 4) | (buf[1] >> 4); -} - -int ns2009_get_press() -{ - return ns2009_read(NS2009_LOW_POWER_READ_Z1); -} - -int ns2009_pos(int pos[2]) -{ - int press = ns2009_read(NS2009_LOW_POWER_READ_Z1); - if (press > 30) - { - int x, y, z = 0; - - x = ns2009_read(NS2009_LOW_POWER_READ_X); - y = ns2009_read(NS2009_LOW_POWER_READ_Y); - - pos[0] = x * SCREEN_X_PIXEL / 4096; //4096 = 2 ^ 12 - pos[1] = y * SCREEN_Y_PIXEL / 4096; - return 1; - } - else - { - pos[0] = -1; - pos[1] = -1; - return 0; - } -} \ No newline at end of file diff --git a/lib/makefabs-esp32s3parallel/NS2009.h b/lib/makefabs-esp32s3parallel/NS2009.h deleted file mode 100644 index 57171e9a..00000000 --- a/lib/makefabs-esp32s3parallel/NS2009.h +++ /dev/null @@ -1,20 +0,0 @@ -#include - -//NS2009 -#define NS2009_ADDR 0x48 //10010000 - -#define NS2009_LOW_POWER_READ_X 0xc0 -#define NS2009_LOW_POWER_READ_Y 0xd0 -#define NS2009_LOW_POWER_READ_Z1 0xe0 - -#define SCREEN_X_PIXEL 320 -#define SCREEN_Y_PIXEL 480 - -void ns2009_recv(const uint8_t *send_buf, size_t send_buf_len, uint8_t *receive_buf, - size_t receive_buf_len); - -unsigned ns2009_read(uint8_t cmd, int *val); - -int ns2009_pos(int pos[2]); - -int ns2009_get_press(); \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index f33bb4f7..dd17985f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -15,8 +15,8 @@ default_envs = CUSTOMBOARD [common] platform = espressif32 framework = arduino -version = 0.1.1 -revision = 7 +version = 0.1.2 +revision = 10 monitor_speed = 115200 monitor_rts = 0 monitor_dtr = 0 @@ -40,7 +40,7 @@ lib_deps = adafruit/Adafruit BME280 Library@^2.2.2 paulstoffregen/Time@^1.6.1 me-no-dev/ESP Async WebServer@^1.2.3 - lvgl/lvgl@^8.3.2 + lvgl/lvgl@^8.3.4 lovyan03/LovyanGFX@^1.1.5 jchristensen/Timezone@^1.2.4 @@ -66,6 +66,7 @@ build_flags = -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue -D ENABLE_COMPASS=1 + -D ENABLE_BME=1 -D TFT_WIDTH=320 -D TFT_HEIGHT=480 -D TFT_BL=33 diff --git a/src/gui/events/main_screen.h b/src/gui/events/main_screen.h index cde598a1..32ae603b 100644 --- a/src/gui/events/main_screen.h +++ b/src/gui/events/main_screen.h @@ -53,8 +53,10 @@ void update_main_screen(lv_timer_t *t) switch (act_tile) { case COMPASS: +#ifdef ENABLE_COMPASS heading = read_compass(); lv_event_send(compass_heading, LV_EVENT_VALUE_CHANGED, NULL); +#endif if (GPS.location.isUpdated()) { diff --git a/src/gui/events/notify_bar.h b/src/gui/events/notify_bar.h index 3acedbfa..095a1c29 100644 --- a/src/gui/events/notify_bar.h +++ b/src/gui/events/notify_bar.h @@ -106,9 +106,11 @@ void update_notify_bar(lv_timer_t *t) sat_count_old = GPS.satellites.value(); } +#ifdef ENABLE_BME if (int(bme.readTemperature()) != temp_old) { lv_label_set_text_fmt(temp, "%02d\xC2\xB0", int(bme.readTemperature())); temp_old = int(bme.readTemperature()); } +#endif } \ No newline at end of file diff --git a/src/gui/lvgl.h b/src/gui/lvgl.h index d55d198c..a5163e14 100644 --- a/src/gui/lvgl.h +++ b/src/gui/lvgl.h @@ -72,20 +72,7 @@ void disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) void touchpad_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) { uint16_t touchX, touchY; - -#ifndef MAKERF_ESP32S3 bool touched = tft.getTouch(&touchX, &touchY); -#else - int pos[2] = {0, 0}; - bool touched = false; - get_pos(pos); - if (pos[0]!=0 && pos[1]!=0) - { - touched = true; - touchX = pos[0]; - touchY = pos[1]; - } -#endif if (!touched) data->state = LV_INDEV_STATE_RELEASED; else diff --git a/src/gui/screens-lvgl/main_scr.h b/src/gui/screens-lvgl/main_scr.h index ecc4ed5f..6c42a6c5 100644 --- a/src/gui/screens-lvgl/main_scr.h +++ b/src/gui/screens-lvgl/main_scr.h @@ -75,6 +75,7 @@ void create_main_scr() lv_obj_set_align(compass_heading, LV_ALIGN_CENTER); lv_obj_set_y(compass_heading, 35); lv_obj_set_style_text_font(compass_heading, &lv_font_montserrat_48, 0); + lv_label_set_text(compass_heading, "-----\xC2\xB0"); lv_obj_t *arrow_img = lv_img_create(compass_tile); lv_img_set_src(arrow_img, "F:/arrow.bin"); diff --git a/src/gui/screens-lvgl/notify_bar.h b/src/gui/screens-lvgl/notify_bar.h index 9b457483..9825557d 100644 --- a/src/gui/screens-lvgl/notify_bar.h +++ b/src/gui/screens-lvgl/notify_bar.h @@ -70,6 +70,7 @@ void create_notify_bar() temp = lv_label_create(lv_scr_act()); lv_obj_set_size(temp, 50, 20); lv_obj_set_pos(temp, TFT_WIDTH - 145, 2); + lv_label_set_text(temp, "--\xC2\xB0"); gps_time = lv_label_create(lv_scr_act()); lv_obj_set_size(gps_time, 100, 20); diff --git a/src/hardware/tft.h b/src/hardware/tft.h index 50547f47..c5f65041 100644 --- a/src/hardware/tft.h +++ b/src/hardware/tft.h @@ -16,7 +16,7 @@ #include -int brightness_level = 255; +uint8_t brightness_level = 255; static TFT_eSPI tft; #define LVGL_BKG 0x10A2 @@ -27,7 +27,7 @@ static TFT_eSPI tft; * * @param brightness -> 0..255 */ -void set_brightness(int brightness) +void set_brightness(uint8_t brightness) { if (brightness <= 255) { @@ -41,7 +41,7 @@ void set_brightness(int brightness) * * @return int -> brightness value 0..255 */ -int get_brightness() +uint8_t get_brightness() { return brightness_level; } diff --git a/src/main.cpp b/src/main.cpp index 360ba967..15299e78 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include #include @@ -25,8 +24,12 @@ unsigned long millis_actual = 0; #include "hardware/serial.h" #include "hardware/sdcard.h" #include "hardware/tft.h" +#ifdef ENABLE_COMPASS #include "hardware/compass.h" +#endif +#ifdef ENABLE_BME #include "hardware/bme.h" +#endif #include "hardware/battery.h" #include "hardware/gps.h" #include "hardware/power.h" @@ -45,8 +48,13 @@ unsigned long millis_actual = 0; */ void setup() { + +#ifdef ENABLE_BME bme.begin(BME_ADDRESS); +#endif +#ifdef ENABLE_COMPASS compass.begin(); +#endif #ifdef DEBUG init_serial(); @@ -54,6 +62,10 @@ void setup() powerOn(); init_sd(); init_SPIFFS(); +#ifdef MAKERF_ESP32S3 + Wire.end(); +// Wire.begin(38,39); +#endif init_LVGL(); init_tft(); init_gps(); @@ -74,6 +86,9 @@ void setup() */ void loop() { +#ifdef MAKERF_ESP32S3 + lv_tick_inc(5); +#endif lv_timer_handler(); - delay(5); + delayMicroseconds(5); }