Skip to content
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions boards/heltec_v4_r8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"build": {
"arduino": {
"ldscript": "esp32s3_out.ld",
"partitions": "default_16MB.csv",
"memory_type": "qio_opi"
},
"core": "esp32",
"extra_flags": [
"-DBOARD_HAS_PSRAM",
"-DARDUINO_USB_CDC_ON_BOOT=1",
"-DARDUINO_USB_MODE=1",
"-DARDUINO_RUNNING_CORE=1",
"-DARDUINO_EVENT_RUNNING_CORE=1"
],
"f_cpu": "240000000L",
"f_flash": "80000000L",
"flash_mode": "qio",
"psram_type": "opi",
"hwids": [["0x303A", "0x1001"]],
"mcu": "esp32s3",
"variant": "heltec_v4_r8"
},
"connectivity": ["wifi", "bluetooth", "lora"],
"debug": {
"default_tool": "esp-builtin",
"onboard_tools": ["esp-builtin"],
"openocd_target": "esp32s3.cfg"
},
"frameworks": ["arduino", "espidf"],
"name": "heltec_wifi_lora_32 v4 r8 (16 MB FLASH, 8 MB PSRAM)",
"upload": {
"flash_size": "16MB",
"maximum_ram_size": 327680,
"maximum_size": 16777216,
"use_1200bps_touch": true,
"wait_for_upload_port": true,
"require_upload_port": true,
"speed": 921600
},
"url": "https://heltec.org/",
"vendor": "heltec"
}
8 changes: 6 additions & 2 deletions src/helpers/ui/ST7789LCDDisplay.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "ST7789LCDDisplay.h"

#ifndef PIN_TFT_MISO
#define PIN_TFT_MISO -1
#endif

#ifndef DISPLAY_ROTATION
#define DISPLAY_ROTATION 3
#endif
Expand Down Expand Up @@ -29,8 +33,8 @@ bool ST7789LCDDisplay::begin() {
}

// Im not sure if this is just a t-deck problem or not, if your display is slow try this.
#if defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT)
displaySPI.begin(PIN_TFT_SCL, -1, PIN_TFT_SDA, PIN_TFT_CS);
#if defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT) || defined(HELTEC_V4_R8_TFT)
displaySPI.begin(PIN_TFT_SCL, PIN_TFT_MISO, PIN_TFT_SDA, PIN_TFT_CS);
#endif

display.init(DISPLAY_WIDTH, DISPLAY_HEIGHT);
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/ui/ST7789LCDDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <helpers/RefCountedDigitalPin.h>

class ST7789LCDDisplay : public DisplayDriver {
#if defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT)
#if defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT) || defined(HELTEC_V4_R8_TFT)
SPIClass displaySPI;
#endif
Adafruit_ST7789 display;
Expand All @@ -25,7 +25,7 @@ class ST7789LCDDisplay : public DisplayDriver {
{
_isOn = false;
}
#elif defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT)
#elif defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT) || defined(HELTEC_V4_R8_TFT)
ST7789LCDDisplay(RefCountedDigitalPin* peripher_power=NULL) : DisplayDriver(128, 64),
displaySPI(HSPI),
display(&displaySPI, PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_RST),
Expand Down
86 changes: 86 additions & 0 deletions variants/heltec_v4_r8/HeltecV4R8Board.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include "HeltecV4R8Board.h"

void HeltecV4R8Board::begin() {
ESP32Board::begin();

periph_power.begin();
periph_power.claim(); // R8 VEXT also feeds the LoRa antenna boost rail.

loRaFEMControl.init();

#ifdef PIN_TOUCH_RST
pinMode(PIN_TOUCH_RST, OUTPUT);
digitalWrite(PIN_TOUCH_RST, HIGH);
delay(10);
digitalWrite(PIN_TOUCH_RST, LOW);
delay(100);
digitalWrite(PIN_TOUCH_RST, HIGH);
#endif

esp_reset_reason_t reason = esp_reset_reason();
if (reason == ESP_RST_DEEPSLEEP) {
long wakeup_source = esp_sleep_get_ext1_wakeup_status();
if (wakeup_source & (1 << P_LORA_DIO_1)) {
startup_reason = BD_STARTUP_RX_PACKET;
}

rtc_gpio_hold_dis((gpio_num_t)P_LORA_NSS);
rtc_gpio_deinit((gpio_num_t)P_LORA_DIO_1);
}
}

void HeltecV4R8Board::onBeforeTransmit(void) {
digitalWrite(P_LORA_TX_LED, HIGH);
loRaFEMControl.setTxModeEnable();
}

void HeltecV4R8Board::onAfterTransmit(void) {
digitalWrite(P_LORA_TX_LED, LOW);
loRaFEMControl.setRxModeEnable();
}

void HeltecV4R8Board::enterDeepSleep(uint32_t secs, int pin_wake_btn) {
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);

rtc_gpio_set_direction((gpio_num_t)P_LORA_DIO_1, RTC_GPIO_MODE_INPUT_ONLY);
rtc_gpio_pulldown_en((gpio_num_t)P_LORA_DIO_1);

rtc_gpio_hold_en((gpio_num_t)P_LORA_NSS);
loRaFEMControl.setRxModeEnableWhenMCUSleep();

if (pin_wake_btn < 0) {
esp_sleep_enable_ext1_wakeup((1L << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH);
} else {
esp_sleep_enable_ext1_wakeup((1L << P_LORA_DIO_1) | (1L << pin_wake_btn), ESP_EXT1_WAKEUP_ANY_HIGH);
}

if (secs > 0) {
esp_sleep_enable_timer_wakeup(secs * 1000000);
}

esp_deep_sleep_start();
}

void HeltecV4R8Board::powerOff() {
enterDeepSleep(0);
}

uint16_t HeltecV4R8Board::getBattMilliVolts() {
analogReadResolution(12);

uint32_t raw = 0;
for (int i = 0; i < 8; i++) {
raw += analogRead(PIN_VBAT_READ);
}
raw = raw / 8;

return (adc_mult * (3.3f / 4096.0f) * raw) * 1000;
}

const char* HeltecV4R8Board::getManufacturerName() const {
#ifdef HELTEC_V4_R8_TFT
return "Heltec V4 R8 TFT";
#else
return "Heltec V4 R8 OLED";
#endif
}
39 changes: 39 additions & 0 deletions variants/heltec_v4_r8/HeltecV4R8Board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

#include <Arduino.h>
#include <driver/rtc_io.h>
#include <helpers/ESP32Board.h>
#include <helpers/RefCountedDigitalPin.h>
#include "LoRaFEMControl.h"

#ifndef ADC_MULTIPLIER
#define ADC_MULTIPLIER (4.9f * 1.035f)
#endif

class HeltecV4R8Board : public ESP32Board {
protected:
float adc_mult = ADC_MULTIPLIER;

public:
RefCountedDigitalPin periph_power;
LoRaFEMControl loRaFEMControl;

HeltecV4R8Board() : periph_power(PIN_VEXT_EN, PIN_VEXT_EN_ACTIVE) { }

void begin();
void onBeforeTransmit(void) override;
void onAfterTransmit(void) override;
void enterDeepSleep(uint32_t secs, int pin_wake_btn = -1);
void powerOff() override;
uint16_t getBattMilliVolts() override;
bool setAdcMultiplier(float multiplier) override {
if (multiplier == 0.0f) {
adc_mult = ADC_MULTIPLIER;
} else {
adc_mult = multiplier;
}
return true;
}
float getAdcMultiplier() const override { return adc_mult; }
const char* getManufacturerName() const override;
};
52 changes: 52 additions & 0 deletions variants/heltec_v4_r8/LoRaFEMControl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "LoRaFEMControl.h"

#include <Arduino.h>
#include <driver/rtc_io.h>
#include <esp_sleep.h>

void LoRaFEMControl::init(void) {
pinMode(P_LORA_PA_POWER, OUTPUT);
digitalWrite(P_LORA_PA_POWER, HIGH);
rtc_gpio_hold_dis((gpio_num_t)P_LORA_PA_POWER);

esp_reset_reason_t reason = esp_reset_reason();
if (reason != ESP_RST_DEEPSLEEP) {
delay(1);
}

rtc_gpio_hold_dis((gpio_num_t)P_LORA_KCT8103L_PA_CSD);
rtc_gpio_hold_dis((gpio_num_t)P_LORA_KCT8103L_PA_CTX);

pinMode(P_LORA_KCT8103L_PA_CSD, OUTPUT);
digitalWrite(P_LORA_KCT8103L_PA_CSD, HIGH);
pinMode(P_LORA_KCT8103L_PA_CTX, OUTPUT);
digitalWrite(P_LORA_KCT8103L_PA_CTX, lna_enabled ? LOW : HIGH);
}

void LoRaFEMControl::setSleepModeEnable(void) {
digitalWrite(P_LORA_KCT8103L_PA_CSD, LOW);
}

void LoRaFEMControl::setTxModeEnable(void) {
digitalWrite(P_LORA_KCT8103L_PA_CSD, HIGH);
digitalWrite(P_LORA_KCT8103L_PA_CTX, HIGH);
}

void LoRaFEMControl::setRxModeEnable(void) {
digitalWrite(P_LORA_KCT8103L_PA_CSD, HIGH);
digitalWrite(P_LORA_KCT8103L_PA_CTX, lna_enabled ? LOW : HIGH);
}

void LoRaFEMControl::setRxModeEnableWhenMCUSleep(void) {
digitalWrite(P_LORA_PA_POWER, HIGH);
rtc_gpio_hold_en((gpio_num_t)P_LORA_PA_POWER);

digitalWrite(P_LORA_KCT8103L_PA_CSD, HIGH);
rtc_gpio_hold_en((gpio_num_t)P_LORA_KCT8103L_PA_CSD);
digitalWrite(P_LORA_KCT8103L_PA_CTX, lna_enabled ? LOW : HIGH);
rtc_gpio_hold_en((gpio_num_t)P_LORA_KCT8103L_PA_CTX);
}

void LoRaFEMControl::setLNAEnable(bool enabled) {
lna_enabled = enabled;
}
24 changes: 24 additions & 0 deletions variants/heltec_v4_r8/LoRaFEMControl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

typedef enum {
KCT8103L_PA,
OTHER_FEM_TYPES
} LoRaFEMType;

class LoRaFEMControl {
public:
LoRaFEMControl() { }
virtual ~LoRaFEMControl() { }
void init(void);
void setSleepModeEnable(void);
void setTxModeEnable(void);
void setRxModeEnable(void);
void setRxModeEnableWhenMCUSleep(void);
void setLNAEnable(bool enabled);
bool isLnaCanControl(void) { return true; }
void setLnaCanControl(bool can_control) { }
LoRaFEMType getFEMType(void) const { return KCT8103L_PA; }

private:
bool lna_enabled = false;
};
56 changes: 56 additions & 0 deletions variants/heltec_v4_r8/pins_arduino.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#ifndef Pins_Arduino_h
#define Pins_Arduino_h

#include <stdint.h>

#define USB_VID 0x303a
#define USB_PID 0x1001

static const uint8_t TX = 43;
static const uint8_t RX = 44;

static const uint8_t SDA = 17;
static const uint8_t SCL = 18;

static const uint8_t SS = 8;
static const uint8_t MOSI = 10;
static const uint8_t MISO = 11;
static const uint8_t SCK = 9;

static const uint8_t A0 = 1;
static const uint8_t A1 = 2;
static const uint8_t A2 = 3;
static const uint8_t A3 = 4;
static const uint8_t A4 = 5;
static const uint8_t A5 = 6;
static const uint8_t A6 = 7;
static const uint8_t A7 = 8;
static const uint8_t A8 = 9;
static const uint8_t A9 = 10;
static const uint8_t A10 = 11;
static const uint8_t A11 = 12;
static const uint8_t A12 = 13;
static const uint8_t A13 = 14;
static const uint8_t A14 = 15;
static const uint8_t A15 = 16;
static const uint8_t A16 = 17;
static const uint8_t A17 = 18;
static const uint8_t A18 = 19;
static const uint8_t A19 = 20;

static const uint8_t T1 = 1;
static const uint8_t T2 = 2;
static const uint8_t T3 = 3;
static const uint8_t T4 = 4;
static const uint8_t T5 = 5;
static const uint8_t T6 = 6;
static const uint8_t T7 = 7;
static const uint8_t T8 = 8;
static const uint8_t T9 = 9;
static const uint8_t T10 = 10;
static const uint8_t T11 = 11;
static const uint8_t T12 = 12;
static const uint8_t T13 = 13;
static const uint8_t T14 = 14;

#endif
Loading