Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
52 changes: 52 additions & 0 deletions QuickStart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Quick Starts for common platforms

## Linux CLI-Only QuickStart

### Starting from the home dir, Clone this repository and `cd` into it
```
cd ~
git clone git@github.com:ripplebiz/MeshCore.git
cd MeshCore
```

### Install deps:
```
platformio pkg install
```

### If installing from cli, ensure arduino embed package is installed:
```
platformio pkg install -t platformio/framework-arduino-mbed
```

### Need to patch some libs as per https://learn.rakwireless.com/hc/en-us/articles/26687276346775-How-To-Perform-Installation-of-Board-Support-Package-in-PlatformIO
```
cd ../.platformio
wget https://raw.githubusercontent.com/RAKWireless/WisBlock/master/PlatformIO/RAK_PATCH.zip
unar RAK_PATCH.zip
cd RAK_PATCH
python3 ./rak_patch.py
```

We should see something like:
```
~/.platformio/RAK_PATCH via 🐍 v3.12.8
❯ python3 ./rak_patch.py
Patching RAK4631
Patched RAK4631
Patching RAK11200
Patched RAK11200
Patching RAK11310
Patched RAK11310
Patch done, check output if successful
```

### Build the T-Deck_hello_world example
```
platformio run -e T-Deck_hello_world -t mergebin
```

### Flash it to a T-Deck
```
python3 -m esptool --chip esp32s3 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m 0x0 .pio/build/T-Deck_hello_world/firmware-merged.bin
```
38 changes: 38 additions & 0 deletions boards/T-Deck.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"build": {
"arduino": {
"ldscript": "esp32s3_out.ld",
"partitions": "default_16MB.csv",
"memory_type": "qio_opi"
},
"core": "esp32",
"extra_flags": [
"-DARDUINO_USB_MODE=1",
"-DARDUINO_RUNNING_CORE=1",
"-DARDUINO_EVENT_RUNNING_CORE=1"
],
"f_cpu": "240000000L",
"f_flash": "80000000L",
"flash_mode": "qio",
"hwids": [["0x303A", "0x1001"]],
"mcu": "esp32s3",
"variant": "esp32s3"
},
"connectivity": ["wifi"],
"debug": {
"default_tool": "esp-builtin",
"onboard_tools": ["esp-builtin"],
"openocd_target": "esp32s3.cfg"
},
"frameworks": ["arduino", "espidf"],
"name": "LilyGo T-Deck(16M Flash 8M OPI PSRAM )",
"upload": {
"flash_size": "16MB",
"maximum_ram_size": 327680,
"maximum_size": 16777216,
"require_upload_port": true,
"speed": 921600
},
"url": "https://www.lilygo.cc",
"vendor": "LilyGo"
}
133 changes: 133 additions & 0 deletions examples/tdeck_hello_world/display.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#include <Arduino.h>
#include <SPI.h>
#include <TFT_eSPI.h>
#include "utilities.h"

typedef struct {
uint8_t cmd;
uint8_t data[14];
uint8_t len;
} lcd_cmd_t;

lcd_cmd_t lcd_st7789v[] = {
{0x01, {0}, 0 | 0x80},
{0x11, {0}, 0 | 0x80},
{0x3A, {0X05}, 1},
{0x36, {0x55}, 1},
{0xB2, {0x0C, 0x0C, 0X00, 0X33, 0X33}, 5},
{0xB7, {0X75}, 1},
{0xBB, {0X1A}, 1},
{0xC0, {0X2C}, 1},
{0xC2, {0X01}, 1},
{0xC3, {0X13}, 1},
{0xC4, {0X20}, 1},
{0xC6, {0X0F}, 1},
{0xD0, {0XA4, 0XA1}, 2},
{0xD6, {0XA1}, 1},
{0xE0, {0XD0, 0X0D, 0X14, 0X0D, 0X0D, 0X09, 0X38, 0X44, 0X4E, 0X3A, 0X17, 0X18, 0X2F, 0X30}, 14},
{0xE1, {0XD0, 0X09, 0X0F, 0X08, 0X07, 0X14, 0X37, 0X44, 0X4D, 0X38, 0X15, 0X16, 0X2C, 0X3E}, 14},
{0x21, {0}, 0}, //invertDisplay
{0x29, {0}, 0},
{0x2C, {0}, 0},
};

TFT_eSPI tft;

// LilyGo T-Deck control backlight chip has 16 levels of adjustment range
// The adjustable range is 0~15, 0 is the minimum brightness, 16 is the maximum brightness
void setBrightness(uint8_t value)
{
static uint8_t level = 0;
static uint8_t steps = 16;
if (value == 0) {
digitalWrite(BOARD_BL_PIN, 0);
delay(3);
level = 0;
return;
}
if (level == 0) {
digitalWrite(BOARD_BL_PIN, 1);
level = steps;
delayMicroseconds(30);
}
int from = steps - level;
int to = steps - value;
int num = (steps + to - from) % steps;
for (int i = 0; i < num; i++) {
digitalWrite(BOARD_BL_PIN, 0);
digitalWrite(BOARD_BL_PIN, 1);
}
level = value;
}


void display_setup()
{
Serial.begin(115200);

Serial.println("T-DECK factory");

//! The board peripheral power control pin needs to be set to HIGH when using the peripheral
pinMode(BOARD_POWERON, OUTPUT);
digitalWrite(BOARD_POWERON, HIGH);

//! Set CS on all SPI buses to high level during initialization
pinMode(BOARD_SDCARD_CS, OUTPUT);
pinMode(RADIO_CS_PIN, OUTPUT);
pinMode(BOARD_TFT_CS, OUTPUT);

digitalWrite(BOARD_SDCARD_CS, HIGH);
digitalWrite(RADIO_CS_PIN, HIGH);
digitalWrite(BOARD_TFT_CS, HIGH);

pinMode(BOARD_SPI_MISO, INPUT_PULLUP);
SPI.begin(BOARD_SPI_SCK, BOARD_SPI_MISO, BOARD_SPI_MOSI); //SD

Serial.print("Init display id:");
Serial.println(USER_SETUP_ID);

tft.begin();

/**
* * T-Deck-Plus and T-Deck display panels are different.
* * This initialization is used to override the initialization parameters.
* * It is used when the display is abnormal after the TFT_eSPI update. */
#if 0
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);
}
}
#endif

tft.setRotation( 1 );
tft.fillScreen(TFT_BLACK);

tft.setTextDatum(BL_DATUM);
tft.setFreeFont(&FreeMono9pt7b);
tft.drawString("Hello World", TFT_HEIGHT / 2, TFT_WIDTH / 2);


pinMode(BOARD_BL_PIN, OUTPUT);
for (int i = 0; i <= 16; ++i) {
setBrightness(i);
delay(30);
}
}

void display_loop(
char *message_buffer
) {
tft.setTextColor(random(0xFFFF));
tft.fillScreen(TFT_BLACK);
tft.drawString(
message_buffer,
1,
TFT_WIDTH - 1
);
}
3 changes: 3 additions & 0 deletions examples/tdeck_hello_world/display.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

void display_setup();
void display_loop(char *keyValue);
95 changes: 95 additions & 0 deletions examples/tdeck_hello_world/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#include <Arduino.h>
#include <Wire.h>
#include <RadioLib.h>
#include "./display.h"
#include "./mesh.h"

#define LILYGO_KB_ADDR 0x55

#define BOARD_PWR 10
#define BOARD_SDA 18
#define BOARD_SCL 8

char message_buffer[20] = "Hello, World!";
uint8_t message_buffer_cursor = 0;

#if defined(NRF52_PLATFORM)
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
#elif defined(P_LORA_SCLK)
SPIClass spi;
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi);
#else
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY);
#endif
StdRNG fast_rng;
SimpleMeshTables tables;
MyMesh the_mesh(*new WRAPPER_CLASS(radio, board), fast_rng, *new VolatileRTCClock(), tables);

void halt() {
while (1) {
delay(1000);
}
}

void setup() {
Serial.begin(115200);

#ifdef SX126X_DIO3_TCXO_VOLTAGE
float tcxo = SX126X_DIO3_TCXO_VOLTAGE;
#else
float tcxo = 1.6f;
#endif

#if defined(NRF52_PLATFORM)
SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI);
SPI.begin();
#elif defined(P_LORA_SCLK)
spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);
#endif

int status = radio.begin(
LORA_FREQUENCY,
LORA_BANDWIDTH,
LORA_SPREADING_FACTOR,
LORA_TRANSMISSION_POWER,
LORA_SYNC_WORD,
tcxo
);

if (status != RADIOLIB_ERR_NONE) {
Serial.print("ERROR: Radio initialization failed: ");
Serial.println(status);
halt();
}


pinMode(BOARD_PWR, OUTPUT);
digitalWrite(BOARD_PWR, HIGH);

delay(200);
Wire.begin(BOARD_SDA, BOARD_SCL);
Wire.requestFrom(LILYGO_KB_ADDR, 1);
if (Wire.read() == -1) {
Serial.println("Keyboard not found");
while (1) {
delay(1000);
}
}

display_setup();
}

void loop() {
char key_value = 0;

Wire.requestFrom(LILYGO_KB_ADDR, 1);
if (Wire.available()) {
key_value = Wire.read();
if (key_value != 0) {
message_buffer[message_buffer_cursor++ % sizeof(message_buffer)] = key_value;

}
}

display_loop(message_buffer);
}
Loading