Skip to content

Commit

Permalink
rak10701: support touchscreen (#4104)
Browse files Browse the repository at this point in the history
* Add the touch screen driver RAK10701 platform, lib_deps https://github.com/RAKWireless/RAK14014-FT6336U

* Added RAK10701 touch screen virtual keyboard, supporting cannedMessageModule free text
  • Loading branch information
DanielCao0 authored Jun 15, 2024
1 parent 8b8e056 commit e55604b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 20 deletions.
25 changes: 25 additions & 0 deletions src/graphics/TFTDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,15 @@ static LGFX *tft = nullptr;

#elif defined(RAK14014)
#include <TFT_eSPI.h>
#include <RAK14014_FT6336U.h>
TFT_eSPI *tft = nullptr;
FT6336U ft6336u;

static uint8_t _rak14014_touch_int = false; // TP interrupt generation flag.
static void rak14014_tpIntHandle(void)
{
_rak14014_touch_int = true;
}

#elif defined(ST7789_CS)
#include <LovyanGFX.hpp> // Graphics and font library for ST7735 driver chip
Expand Down Expand Up @@ -642,8 +650,12 @@ void TFTDisplay::sendCommand(uint8_t com)

void TFTDisplay::setDisplayBrightness(uint8_t _brightness)
{
#ifdef RAK14014
//todo
#else
tft->setBrightness(_brightness);
LOG_DEBUG("Brightness is set to value: %i \n", _brightness);
#endif
}

void TFTDisplay::flipScreenVertically()
Expand All @@ -657,6 +669,7 @@ void TFTDisplay::flipScreenVertically()
bool TFTDisplay::hasTouch(void)
{
#ifdef RAK14014
return true;
#elif !defined(M5STACK)
return tft->touch() != nullptr;
#else
Expand All @@ -667,6 +680,15 @@ bool TFTDisplay::hasTouch(void)
bool TFTDisplay::getTouch(int16_t *x, int16_t *y)
{
#ifdef RAK14014
if(_rak14014_touch_int) {
_rak14014_touch_int = false;
/* The X and Y axes have to be switched */
*y = ft6336u.read_touch1_x();
*x = TFT_HEIGHT - ft6336u.read_touch1_y();
return true;
} else {
return false;
}
#elif !defined(M5STACK)
return tft->getTouch(x, y);
#else
Expand Down Expand Up @@ -717,6 +739,9 @@ bool TFTDisplay::connect()
tft->setRotation(1);
tft->setSwapBytes(true);
// tft->fillScreen(TFT_BLACK);
ft6336u.begin();
pinMode(SCREEN_TOUCH_INT, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(SCREEN_TOUCH_INT), rak14014_tpIntHandle, FALLING);
#elif defined(T_DECK) || defined(PICOMPUTER_S3) || defined(CHATTER_2)
tft->setRotation(1); // T-Deck has the TFT in landscape
#elif defined(T_WATCH_S3)
Expand Down
28 changes: 14 additions & 14 deletions src/modules/CannedMessageModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ CannedMessageModule::CannedMessageModule()
LOG_INFO("CannedMessageModule is enabled\n");

// T-Watch interface currently has no way to select destination type, so default to 'node'
#ifdef T_WATCH_S3
#if defined(T_WATCH_S3) || defined(RAK14014)
this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NODE;
#endif

Expand All @@ -75,7 +75,7 @@ int CannedMessageModule::splitConfiguredMessages()

String messages = cannedMessageModuleConfig.messages;

#ifdef T_WATCH_S3
#if defined(T_WATCH_S3) || defined(RAK14014)
String separator = messages.length() ? "|" : "";

messages = "[---- Free Text ----]" + separator + messages;
Expand Down Expand Up @@ -144,7 +144,7 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event)
}
if (event->inputEvent == static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_SELECT)) {

#ifdef T_WATCH_S3
#if defined(T_WATCH_S3) || defined(RAK14014)
if (this->currentMessageIndex == 0) {
this->runState = CANNED_MESSAGE_RUN_STATE_FREETEXT;

Expand All @@ -170,7 +170,7 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event)
e.frameChanged = true;
this->currentMessageIndex = -1;

#ifndef T_WATCH_S3
#if !defined(T_WATCH_S3) && !defined(RAK14014)
this->freetext = ""; // clear freetext
this->cursor = 0;
this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE;
Expand All @@ -183,7 +183,7 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event)
(event->inputEvent == static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_LEFT)) ||
(event->inputEvent == static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT))) {

#ifdef T_WATCH_S3
#if defined(T_WATCH_S3) || defined(RAK14014)
if (event->inputEvent == static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_LEFT)) {
this->payload = 0xb4;
} else if (event->inputEvent == static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT)) {
Expand Down Expand Up @@ -283,7 +283,7 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event)
}
}

#ifdef T_WATCH_S3
#if defined(T_WATCH_S3) || defined(RAK14014)
if (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT) {
String keyTapped = keyForCoordinates(event->touchX, event->touchY);

Expand Down Expand Up @@ -404,7 +404,7 @@ int32_t CannedMessageModule::runOnce()
this->freetext = ""; // clear freetext
this->cursor = 0;

#ifndef T_WATCH_S3
#if !defined(T_WATCH_S3) && !defined(RAK14014)
this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE;
#endif

Expand All @@ -417,7 +417,7 @@ int32_t CannedMessageModule::runOnce()
this->freetext = ""; // clear freetext
this->cursor = 0;

#ifndef T_WATCH_S3
#if !defined(T_WATCH_S3) && !defined(RAK14014)
this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE;
#endif

Expand All @@ -437,7 +437,7 @@ int32_t CannedMessageModule::runOnce()
powerFSM.trigger(EVENT_PRESS);
return INT32_MAX;
} else {
#ifdef T_WATCH_S3
#if defined(T_WATCH_S3) || defined(RAK14014)
sendText(this->dest, indexChannels[this->channel], this->messages[this->currentMessageIndex], true);
#else
sendText(NODENUM_BROADCAST, channels.getPrimaryIndex(), this->messages[this->currentMessageIndex], true);
Expand All @@ -454,7 +454,7 @@ int32_t CannedMessageModule::runOnce()
this->freetext = ""; // clear freetext
this->cursor = 0;

#ifndef T_WATCH_S3
#if !defined(T_WATCH_S3) && !defined(RAK14014)
this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE;
#endif

Expand All @@ -471,7 +471,7 @@ int32_t CannedMessageModule::runOnce()
this->freetext = ""; // clear freetext
this->cursor = 0;

#ifndef T_WATCH_S3
#if !defined(T_WATCH_S3) && !defined(RAK14014)
this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE;
#endif

Expand All @@ -484,7 +484,7 @@ int32_t CannedMessageModule::runOnce()
this->freetext = ""; // clear freetext
this->cursor = 0;

#ifndef T_WATCH_S3
#if !defined(T_WATCH_S3) && !defined(RAK14014)
this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE;
#endif

Expand Down Expand Up @@ -714,7 +714,7 @@ void CannedMessageModule::showTemporaryMessage(const String &message)
setIntervalFromNow(2000);
}

#ifdef T_WATCH_S3
#if defined(T_WATCH_S3) || defined(RAK14014)

String CannedMessageModule::keyForCoordinates(uint x, uint y)
{
Expand Down Expand Up @@ -949,7 +949,7 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
display->drawString(10 + x, 0 + y + FONT_HEIGHT_SMALL, "Canned Message\nModule disabled.");
} else if (cannedMessageModule->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT) {

#ifdef T_WATCH_S3
#if defined(T_WATCH_S3) || defined(RAK14014)
drawKeyboard(display, state, 0, 0);
#else

Expand Down
4 changes: 2 additions & 2 deletions src/modules/CannedMessageModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class CannedMessageModule : public SinglePortModule, public Observable<const UIF
int getNextIndex();
int getPrevIndex();

#ifdef T_WATCH_S3
#if defined(T_WATCH_S3) || defined(RAK14014)
void drawKeyboard(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
String keyForCoordinates(uint x, uint y);
bool shift = false;
Expand Down Expand Up @@ -150,7 +150,7 @@ class CannedMessageModule : public SinglePortModule, public Observable<const UIF
unsigned long lastTouchMillis = 0;
String temporaryMessage;

#ifdef T_WATCH_S3
#if defined(T_WATCH_S3) || defined(RAK14014)
Letter keyboard[2][4][10] = {{{{"Q", 20, 0, 0, 0, 0},
{"W", 22, 0, 0, 0, 0},
{"E", 17, 0, 0, 0, 0},
Expand Down
2 changes: 2 additions & 0 deletions variants/rak10701/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ lib_deps =
https://github.com/RAKWireless/RAK13800-W5100S.git#1.0.2
rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2
bodmer/TFT_eSPI
beegee-tokyo/RAKwireless RAK12034@^1.0.0
beegee-tokyo/RAK14014-FT6336U @ 1.0.1
debug_tool = jlink
; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm)
;upload_protocol = jlink
8 changes: 4 additions & 4 deletions variants/rak10701/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,10 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG
#define SCREEN_ROTATE
#define SCREEN_TRANSITION_FRAMERATE 5

#define HAS_TOUCHSCREEN 0
#define SCREEN_TOUCH_INT 10 // From tp.h on the tracker open source code.
#define TOUCH_I2C_PORT 0
#define TOUCH_SLAVE_ADDRESS 0x5D // GT911
#define HAS_TOUCHSCREEN 1
#define SCREEN_TOUCH_INT WB_IO6

#define CANNED_MESSAGE_MODULE_ENABLE 1

/*----------------------------------------------------------------------------
* Arduino objects - C++ only
Expand Down

0 comments on commit e55604b

Please sign in to comment.