diff --git a/boards/CYD-2432S028/interface.cpp b/boards/CYD-2432S028/interface.cpp index d795ca54..f8739e4f 100644 --- a/boards/CYD-2432S028/interface.cpp +++ b/boards/CYD-2432S028/interface.cpp @@ -40,6 +40,8 @@ void _setup_gpio() { log_i("Touch IC not Started"); } else log_i("Touch IC Started"); #endif + + bruceConfig.colorInverted = 0; } /*************************************************************************************** @@ -80,7 +82,7 @@ void _post_setup_gpio() { // Brightness control must be initialized after tft in this case @Pirata pinMode(TFT_BL, OUTPUT); ledcAttach(TFT_BL, TFT_BRIGHT_FREQ, TFT_BRIGHT_Bits); - ledcWrite(TFT_BRIGHT_CHANNEL, 255); + ledcWrite(TFT_BL, 255); } /********************************************************************* diff --git a/boards/ESP32-C5-tft/connections.md b/boards/ESP32-C5-tft/connections.md index 4aba5072..52ac5702 100644 --- a/boards/ESP32-C5-tft/connections.md +++ b/boards/ESP32-C5-tft/connections.md @@ -9,12 +9,19 @@ | NRF24 | 6 | 2 | 7 | 9* | 8* | (*) CC1101, NRF24, W5500 use the same pinouts, need to add a switch on CS and CE/GDO0 to choose which to use. +If using Buttons, use thesee pinouts | Buttons | GPIO | | --- | :---: | | Prev | 0 | | Sel | 28 | | Next | 1 | +If using ILI9341 with XPT2046 fo touchscreen, in this case you have 2 GPIO available (0 and 28) to use on CC1101/NRF24 +| Device | SCK | MISO | MOSI | CS | IRQ | +| --- | :---: | :---: | :---: | :---: | :---: | +| Display | 6 | 2 | 7 | 23 | --- | +| XPT2046 | 6 | 2 | 7 | 1 | --- | + | Device | RX | TX | GPIO | | --- | :---: | :---: | :---: | diff --git a/boards/ESP32-C5-tft/interface.cpp b/boards/ESP32-C5-tft/interface.cpp index 9ecd062b..ace9ad72 100644 --- a/boards/ESP32-C5-tft/interface.cpp +++ b/boards/ESP32-C5-tft/interface.cpp @@ -1,4 +1,5 @@ #include "core/powerSave.h" +#include "core/utils.h" #include /*************************************************************************************** @@ -20,10 +21,11 @@ void _setup_gpio() { pinMode(TFT_DC, OUTPUT); digitalWrite(TFT_DC, HIGH); +#ifdef HAS_3_BUTTONS pinMode(UP_BTN, INPUT_PULLUP); // Sets the power btn as an INPUT pinMode(SEL_BTN, INPUT_PULLUP); pinMode(DW_BTN, INPUT_PULLUP); - +#endif pinMode(NRF24_SS_PIN, OUTPUT); pinMode(CC1101_SS_PIN, OUTPUT); pinMode(SDCARD_CS, OUTPUT); @@ -35,6 +37,44 @@ void _setup_gpio() { digitalWrite(SDCARD_CS, HIGH); digitalWrite(W5500_SS_PIN, HIGH); digitalWrite(TFT_CS, HIGH); +#ifdef ILI9341_DRIVER + bruceConfig.colorInverted = 0; +#endif +} +/*************************************************************************************** +** Function name: _post_setup_gpio() +** Location: main.cpp +** Description: second stage gpio setup to make a few functions work +***************************************************************************************/ +void _post_setup_gpio() { +#ifdef HAS_TOUCH + pinMode(TOUCH_CS, OUTPUT); + uint16_t calData[5]; + File caldata = LittleFS.open("/calData", "r"); + + if (!caldata) { + tft.setRotation(ROTATION); + tft.calibrateTouch(calData, TFT_WHITE, TFT_BLACK, 10); + + caldata = LittleFS.open("/calData", "w"); + if (caldata) { + caldata.printf( + "%d\n%d\n%d\n%d\n%d\n", calData[0], calData[1], calData[2], calData[3], calData[4] + ); + caldata.close(); + } + } else { + Serial.print("\ntft Calibration data: "); + for (int i = 0; i < 5; i++) { + String line = caldata.readStringUntil('\n'); + calData[i] = line.toInt(); + Serial.printf("%d, ", calData[i]); + } + Serial.println(); + caldata.close(); + } + tft.setTouch(calData); +#endif } /*************************************************************************************** @@ -71,7 +111,53 @@ void _setBrightness(uint8_t brightval) { void InputHandler(void) { static unsigned long tm = 0; if (millis() - tm < 200 && !LongPress) return; +#ifdef HAS_TOUCH + TouchPoint t; + checkPowerSaveTime(); + bool _IH_touched = tft.getTouch(&t.x, &t.y); + if (_IH_touched) { + NextPress = false; + PrevPress = false; + UpPress = false; + DownPress = false; + SelPress = false; + EscPress = false; + AnyKeyPress = false; + NextPagePress = false; + PrevPagePress = false; + touchPoint.pressed = false; + _IH_touched = false; + Serial.printf("\nRAW: Touch Pressed on x=%d, y=%d", t.x, t.y); + if (bruceConfig.rotation == 3) { + t.y = (tftHeight + 20) - t.y; + t.x = tftWidth - t.x; + } + if (bruceConfig.rotation == 0) { + uint16_t tmp = t.x; + t.x = map((tftHeight + 20) - t.y, 0, 320, 0, 240); + t.y = map(tmp, 0, 240, 0, 320); + } + if (bruceConfig.rotation == 2) { + uint16_t tmp = t.x; + t.x = map(t.y, 0, 320, 0, 240); + t.y = map(tftWidth - tmp, 0, 240, 0, 320); + } + Serial.printf("\nROT: Touch Pressed on x=%d, y=%d, rot=%d\n", t.x, t.y, bruceConfig.rotation); + + if (!wakeUpScreen()) AnyKeyPress = true; + else return; + + // Touch point global variable + touchPoint.x = t.x; + touchPoint.y = t.y; + touchPoint.pressed = true; + touchHeatMap(touchPoint); + tm = millis(); + } + +#endif +#ifdef HAS_3_BUTTONS bool upPressed = (digitalRead(UP_BTN) == LOW); bool selPressed = (digitalRead(SEL_BTN) == LOW); bool dwPressed = (digitalRead(DW_BTN) == LOW); @@ -85,6 +171,7 @@ void InputHandler(void) { EscPress = upPressed && dwPressed; NextPress = dwPressed; SelPress = selPressed; +#endif } /********************************************************************* diff --git a/boards/ESP32-C5-tft/pins_arduino.h b/boards/ESP32-C5-tft/pins_arduino.h index 2907a090..21126e8e 100644 --- a/boards/ESP32-C5-tft/pins_arduino.h +++ b/boards/ESP32-C5-tft/pins_arduino.h @@ -71,24 +71,30 @@ static const uint8_t LP_TX = 11; #define ROTATION 1 #define MINBRIGHT (uint8_t)1 #define USER_SETUP_LOADED 1 - -// Setup for ST7789 170x320 -#define ST7789_DRIVER 1 -#define TFT_RGB_ORDER 0 -#define TFT_WIDTH 170 -#define TFT_HEIGHT 320 /* --------------------- */ // Setup for ST7789 170x320 + +// #define ST7789_DRIVER 1 +// #define TFT_RGB_ORDER 0 +// #define TFT_WIDTH 170 +// #define TFT_HEIGHT 320 + +/* --------------------- */ +// Setup for ST7789 240x320 + // #define ST7789_DRIVER=1 // #define TFT_WIDTH=240 // #define TFT_HEIGHT=320 // // #define TFT_INVERSION_ON // #define TFT_RGB_ORDER=TFT_BGR + /* --------------------- */ // Setup for ILI9341 320x240 (no touch) -// #define ILI9341_DRIVER 1 -// #define TFT_HEIGHT 320 -// #define TFT_WIDTH 240 + +#define ILI9341_DRIVER 1 +#define TFT_HEIGHT 320 +#define TFT_WIDTH 240 + /* --------------------- */ // Common TFT definitions #define TFT_BACKLIGHT_ON 1 @@ -99,7 +105,7 @@ static const uint8_t LP_TX = 11; #define TFT_MOSI 7 #define TFT_SCLK 6 #define TFT_CS 23 -#define TOUCH_CS -1 +#define TOUCH_CS 1 #define SMOOTH_FONT 1 #define SPI_FREQUENCY 20000000 #define SPI_READ_FREQUENCY 20000000 @@ -112,6 +118,17 @@ static const uint8_t LP_TX = 11; // GPS Bus #define GPS_SERIAL_TX 5 #define GPS_SERIAL_RX 4 + +#ifdef ILI9341_DRIVER +// Touch Screen +#define USE_TFT_eSPI_TOUCH 1 // touchscreen uses same tft spi bus +#define HAS_TOUCH 1 +#define TOUCH_INT -1 +#define TOUCH_CS 1 +#define BTN_ACT LOW +#define DEEPSLEEP_WAKEUP_PIN 0 + +#else // Buttons #define HAS_3_BUTTONS #define SEL_BTN 28 @@ -119,6 +136,8 @@ static const uint8_t LP_TX = 11; #define UP_BTN 0 #define BTN_ACT LOW #define DEEPSLEEP_WAKEUP_PIN SEL_BTN +#endif + // InfraRed #define RXLED 26 #define LED 3 diff --git a/boards/lilygo-t-deck/interface.cpp b/boards/lilygo-t-deck/interface.cpp index 6a255a12..8560116e 100644 --- a/boards/lilygo-t-deck/interface.cpp +++ b/boards/lilygo-t-deck/interface.cpp @@ -125,7 +125,7 @@ void _post_setup_gpio() { // Brightness control must be initialized after tft in this case @Pirata pinMode(TFT_BL, OUTPUT); ledcAttach(TFT_BL, TFT_BRIGHT_FREQ, TFT_BRIGHT_Bits); - ledcWrite(TFT_BRIGHT_CHANNEL, 255); + ledcWrite(TFT_BL, 255); } /********************************************************************* ** Function: setBrightness diff --git a/boards/lilygo-t-deck/lilygo-t-deck.ini b/boards/lilygo-t-deck/lilygo-t-deck.ini index 7b942c63..7d6c1dcc 100644 --- a/boards/lilygo-t-deck/lilygo-t-deck.ini +++ b/boards/lilygo-t-deck/lilygo-t-deck.ini @@ -156,7 +156,7 @@ build_flags = -DSPI_MISO_PIN=38 -DSPI_SS_PIN=-1 -DT_DECK_PLUS - -DDEVICE_NAME='"Lilygo T-Deck Pro"' + -DDEVICE_NAME='"Lilygo T-Deck Plus"' lib_deps = ${env.lib_deps} @@ -177,4 +177,9 @@ build_flags = -DDEVICE_NAME='"Lilygo T-Deck"' build_unflags = + -DIR_TX_PINS='{{"Unavailable", -1}}' + -DIR_RX_PINS='{{"Unavailable", -1}}' + -DRF_TX_PINS='{{"Unavailable", -1}}' + -DRF_RX_PINS='{{"Unavailable", -1}}' + -DDEVICE_NAME='"Lilygo T-Deck Plus"' -DT_DECK_PLUS diff --git a/boards/lilygo-t-display-s3-pro/interface.cpp b/boards/lilygo-t-display-s3-pro/interface.cpp index 307350a0..cb5fc651 100644 --- a/boards/lilygo-t-display-s3-pro/interface.cpp +++ b/boards/lilygo-t-display-s3-pro/interface.cpp @@ -78,7 +78,7 @@ void _setup_gpio() { void _post_setup_gpio() { // PWM backlight setup ledcAttach(TFT_BL, TFT_BRIGHT_FREQ, TFT_BRIGHT_Bits); - ledcWrite(TFT_BRIGHT_CHANNEL, 255); + ledcWrite(TFT_BL, 255); } /*************************************************************************************** diff --git a/boards/lilygo-t-hmi/interface.cpp b/boards/lilygo-t-hmi/interface.cpp index fa14c39b..50ce5c23 100644 --- a/boards/lilygo-t-hmi/interface.cpp +++ b/boards/lilygo-t-hmi/interface.cpp @@ -37,7 +37,7 @@ void _post_setup_gpio() { // Brightness control must be initialized after tft in this case @Pirata pinMode(TFT_BL, OUTPUT); ledcAttach(TFT_BL, TFT_BRIGHT_FREQ, TFT_BRIGHT_Bits); - ledcWrite(TFT_BRIGHT_CHANNEL, 255); + ledcWrite(TFT_BL, 255); } /********************************************************************* diff --git a/boards/lilygo-t-watch-s3/interface.cpp b/boards/lilygo-t-watch-s3/interface.cpp index 0d5fae5d..a845bc86 100644 --- a/boards/lilygo-t-watch-s3/interface.cpp +++ b/boards/lilygo-t-watch-s3/interface.cpp @@ -95,7 +95,7 @@ void _post_setup_gpio() { pinMode(TFT_BL, OUTPUT); digitalWrite(TFT_BL, HIGH); ledcAttach(TFT_BL, TFT_BRIGHT_FREQ, TFT_BRIGHT_Bits); - ledcWrite(TFT_BRIGHT_CHANNEL, 255); + ledcWrite(TFT_BL, 255); } /*************************************************************************************** diff --git a/boards/phantom/interface.cpp b/boards/phantom/interface.cpp index dca54412..b3650cfd 100644 --- a/boards/phantom/interface.cpp +++ b/boards/phantom/interface.cpp @@ -36,7 +36,7 @@ void _post_setup_gpio() { // Brightness control must be initialized after tft in this case @Pirata pinMode(TFT_BL, OUTPUT); ledcAttach(TFT_BL, TFT_BRIGHT_FREQ, TFT_BRIGHT_Bits); - ledcWrite(TFT_BRIGHT_CHANNEL, 255); + ledcWrite(TFT_BL, 255); } /********************************************************************* diff --git a/sd_files/xFlipper.js b/sd_files/xFlipper.js new file mode 100644 index 00000000..b7873c17 --- /dev/null +++ b/sd_files/xFlipper.js @@ -0,0 +1,121 @@ + +let eventLoop = require("event_loop"); +let gui = require("gui"); + +let loadingView = require("gui/loading"); +let submenuView = require("gui/submenu"); +let emptyView = require("gui/empty_screen"); +let textInputView = require("gui/text_input"); +let byteInputView = require("gui/byte_input"); +let textBoxView = require("gui/text_box"); +let dialogView = require("gui/dialog"); +let filePicker = require("gui/file_picker"); +let icon = require("gui/icon"); +let flipper = require("flipper"); + +let press =0; +let serial = require("serial"); + +serial.setup("usart", 115200); + + +function SerialCMD(cmd) { + serial.write(cmd); +} + + + +// declare view instances +let views = { + loading: loadingView.make(), + empty: emptyView.make(), + keyboard: textInputView.makeWith({ + header: "", + minLength: 0, + maxLength: 32, + defaultText: flipper.getName(), + defaultTextClear: true, + }), + helloDialog: dialogView.make(), + bytekb: byteInputView.makeWith({ + }), + longText: textBoxView.makeWith({ + text: "", + }), + xmenu: submenuView.makeWith({ + header: "xFlipper", + items: [ + "Controller", + "Terminal", + "Send Command", + "Exit app", + ], + }), +}; + +// Enable illegal filename symbols since we're not choosing filenames, gives more flexibility +// Not available in all firmwares, good idea to check if it is supported +if (doesSdkSupport(["gui-textinput-illegalsymbols"])) { + views.keyboard.set("illegalSymbols", true); +} + +views.helloDialog.set("text", "hshax "); + + views.helloDialog.set("left", "<<"); + views.helloDialog.set("center", "SELECT"); + views.helloDialog.set("right", ">>"); + +// selector +eventLoop.subscribe(views.xmenu.chosen, function (_sub, index, gui, eventLoop, views) { + if (index === 0) { + gui.viewDispatcher.switchTo(views.helloDialog); + } else if (index === 1) { + gui.viewDispatcher.switchTo(views.empty); + } else if (index === 2) { + gui.viewDispatcher.switchTo(views.empty); + } else if (index === 3) { + eventLoop.stop(); + } +}, gui, eventLoop, views); + + + +// go back after the greeting dialog +eventLoop.subscribe(views.helloDialog.input, function (_sub, button, gui, views) { + + if (button === "left" && press === 0) { + press =2; + serial.write("nav prev\n"); + delay(100); + } else if (button === "center" && press === 0) { + press =2; + serial.write("nav sel\n"); + delay(100); + + } else if (button === "right" && press === 0) { + press =2; + serial.write("nav next\n"); + delay(100); + } else { + serial.write(button); + serial.write("\n"); + delay(100); + } + + if (press === 2) { press=0; } + +}, gui, views); + +// when the back key is pressed +eventLoop.subscribe(gui.viewDispatcher.navigation, function (_sub, _, gui, views, eventLoop) { + if (gui.viewDispatcher.currentView === views.xmenu) { + serial.end(); + eventLoop.stop(); + return; + } + gui.viewDispatcher.switchTo(views.xmenu); +}, gui, views, eventLoop); + +// run UI +gui.viewDispatcher.switchTo(views.xmenu); +eventLoop.run();