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
8,707 changes: 8,611 additions & 96 deletions platformio.ini

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/helpers/esp32/SerialBLEInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "SerialBLEInterface.h"
#include <esp_mac.h>

// See the following for generating UUIDs:
// https://www.uuidgenerator.net/
Expand Down
23 changes: 23 additions & 0 deletions src/helpers/radiolib/CustomLR1121.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <RadioLib.h>

class CustomLR1121 : public LR1121 {
public:
CustomLR1121(Module* mod) : LR1121(mod) { }

size_t getPacketLength(bool update) override {
size_t len = LR1121::getPacketLength(update);
if (len == 0 && (getIrqStatus() & RADIOLIB_LR11X0_IRQ_HEADER_ERR)) {
// Recover from sporadic shifted-packet state seen after header errors.
standby();
}
return len;
}

bool isReceiving() {
uint16_t irq = getIrqStatus();
return (irq & RADIOLIB_LR11X0_IRQ_SYNC_WORD_HEADER_VALID) ||
(irq & RADIOLIB_LR11X0_IRQ_PREAMBLE_DETECTED);
}
};
28 changes: 28 additions & 0 deletions src/helpers/radiolib/CustomLR1121Wrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include "CustomLR1121.h"
#include "RadioLibWrappers.h"

class CustomLR1121Wrapper : public RadioLibWrapper {
public:
CustomLR1121Wrapper(CustomLR1121& radio, mesh::MainBoard& board) : RadioLibWrapper(radio, board) { }

bool isReceivingPacket() override {
return ((CustomLR1121*)_radio)->isReceiving();
}

float getCurrentRSSI() override {
float rssi = -110;
((CustomLR1121*)_radio)->getRssiInst(&rssi);
return rssi;
}

void onSendFinished() override {
RadioLibWrapper::onSendFinished();
((CustomLR1121*)_radio)->setPreambleLength(16);
}

float getLastRSSI() const override { return ((CustomLR1121*)_radio)->getRSSI(); }
float getLastSNR() const override { return ((CustomLR1121*)_radio)->getSNR(); }
int16_t setRxBoostedGainMode(bool en) { return ((CustomLR1121*)_radio)->setRxBoostedGainMode(en); }
};
11 changes: 11 additions & 0 deletions variants/waveshare_esp32_c6/WaveshareESP32C6Board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <Arduino.h>
#include <helpers/ESP32Board.h>

class WaveshareESP32C6Board : public ESP32Board {
public:
const char* getManufacturerName() const override {
return "Waveshare ESP32-C6";
}
};
162 changes: 162 additions & 0 deletions variants/waveshare_esp32_c6/WaveshareESP32C6LCDDisplay.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#include "WaveshareESP32C6LCDDisplay.h"

#include <Arduino.h>
#include <math.h>

static constexpr uint16_t COLOR_BLACK = 0x0000;
static constexpr uint16_t COLOR_WHITE = 0xFFFF;

WaveshareESP32C6LCDDisplay::WaveshareESP32C6LCDDisplay()
: DisplayDriver(128, 64),
_bus(new Arduino_HWSPI(15 /* DC */, 14 /* CS */, 7 /* SCK */, 6 /* MOSI */, 5 /* MISO */)),
_display(new Arduino_ST7789(
_bus,
21 /* RST */,
DISPLAY_ROTATION,
true /* IPS */,
TFT_WIDTH,
TFT_HEIGHT,
34 /* col offset 1 */,
0 /* row offset 1 */,
34 /* col offset 2 */,
0 /* row offset 2 */)),
_is_on(false),
_color(COLOR_WHITE) {
}

int WaveshareESP32C6LCDDisplay::sx(int x) const {
return DISPLAY_OFFSET_X + (int)lroundf(x * DISPLAY_SCALE_X);
}

int WaveshareESP32C6LCDDisplay::sy(int y) const {
return DISPLAY_OFFSET_Y + (int)lroundf(y * DISPLAY_SCALE_Y);
}

int WaveshareESP32C6LCDDisplay::sw(int w) const {
int v = (int)lroundf(w * DISPLAY_SCALE_X);
return (v < 1) ? 1 : v;
}

int WaveshareESP32C6LCDDisplay::sh(int h) const {
int v = (int)lroundf(h * DISPLAY_SCALE_Y);
return (v < 1) ? 1 : v;
}

bool WaveshareESP32C6LCDDisplay::begin() {
if (_is_on) return true;

// Disable the SD chip to avoid SPI bus contention with the LCD.
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);

pinMode(22, OUTPUT);
digitalWrite(22, HIGH); // backlight on

_display->begin(40000000);
_display->fillScreen(COLOR_BLACK);
_display->setTextColor(COLOR_WHITE);
_display->setTextSize(1);
_is_on = true;

return true;
}

void WaveshareESP32C6LCDDisplay::turnOn() {
if (!_is_on) begin();
digitalWrite(22, HIGH);
_is_on = true;
}

void WaveshareESP32C6LCDDisplay::turnOff() {
digitalWrite(22, LOW);
_is_on = false;
}

void WaveshareESP32C6LCDDisplay::clear() {
_display->fillScreen(COLOR_BLACK);
}

void WaveshareESP32C6LCDDisplay::startFrame(Color bkg) {
_display->fillScreen((bkg == DARK) ? COLOR_BLACK : COLOR_WHITE);
_display->setTextColor((bkg == DARK) ? COLOR_WHITE : COLOR_BLACK);
}

void WaveshareESP32C6LCDDisplay::setTextSize(int sz) {
int text_scale = (int)lroundf(sz * DISPLAY_SCALE_X);
if (text_scale < 1) text_scale = 1;
_display->setTextSize(text_scale);
}

void WaveshareESP32C6LCDDisplay::setColor(Color c) {
switch (c) {
case DARK:
_color = COLOR_BLACK;
break;
case LIGHT:
_color = COLOR_WHITE;
break;
case RED:
_color = _display->color565(255, 0, 0);
break;
case GREEN:
_color = _display->color565(0, 255, 0);
break;
case BLUE:
_color = _display->color565(0, 0, 255);
break;
case YELLOW:
_color = _display->color565(255, 255, 0);
break;
case ORANGE:
_color = _display->color565(255, 165, 0);
break;
default:
_color = COLOR_WHITE;
break;
}
_display->setTextColor(_color);
}

void WaveshareESP32C6LCDDisplay::setCursor(int x, int y) {
_display->setCursor(sx(x), sy(y));
}

void WaveshareESP32C6LCDDisplay::print(const char* str) {
_display->print(str);
}

void WaveshareESP32C6LCDDisplay::fillRect(int x, int y, int w, int h) {
_display->fillRect(sx(x), sy(y), sw(w), sh(h), _color);
}

void WaveshareESP32C6LCDDisplay::drawRect(int x, int y, int w, int h) {
_display->drawRect(sx(x), sy(y), sw(w), sh(h), _color);
}

void WaveshareESP32C6LCDDisplay::drawXbm(int x, int y, const uint8_t* bits, int w, int h) {
int pixel_w = sw(1);
int pixel_h = sh(1);
int base_x = sx(x);
int base_y = sy(y);
int byte_width = (w + 7) / 8;

for (int row = 0; row < h; row++) {
for (int col = 0; col < w; col++) {
uint8_t byte = bits[row * byte_width + (col / 8)];
if (byte & (0x80 >> (col & 7))) {
_display->fillRect(base_x + col * pixel_w, base_y + row * pixel_h, pixel_w, pixel_h, _color);
}
}
}
}

uint16_t WaveshareESP32C6LCDDisplay::getTextWidth(const char* str) {
int16_t x1, y1;
uint16_t w, h;
_display->getTextBounds(str, 0, 0, &x1, &y1, &w, &h);
return (uint16_t)lroundf(w / DISPLAY_SCALE_X);
}

void WaveshareESP32C6LCDDisplay::endFrame() {
// Immediate mode display driver. Nothing to flush.
}
59 changes: 59 additions & 0 deletions variants/waveshare_esp32_c6/WaveshareESP32C6LCDDisplay.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#pragma once

#include <helpers/ui/DisplayDriver.h>
#include <Arduino_GFX_Library.h>

#ifndef DISPLAY_ROTATION
#define DISPLAY_ROTATION 0
#endif

#ifndef DISPLAY_SCALE_X
#define DISPLAY_SCALE_X 1.34375f // 172 / 128
#endif

#ifndef DISPLAY_SCALE_Y
#define DISPLAY_SCALE_Y 5.0f // 320 / 64
#endif

#ifndef DISPLAY_OFFSET_X
#define DISPLAY_OFFSET_X 0
#endif

#ifndef DISPLAY_OFFSET_Y
#define DISPLAY_OFFSET_Y 0
#endif

class WaveshareESP32C6LCDDisplay : public DisplayDriver {
Arduino_DataBus* _bus;
Arduino_GFX* _display;
bool _is_on;
uint16_t _color;

static constexpr int TFT_WIDTH = 172;
static constexpr int TFT_HEIGHT = 320;

int sx(int x) const;
int sy(int y) const;
int sw(int w) const;
int sh(int h) const;

public:
WaveshareESP32C6LCDDisplay();

bool begin();

bool isOn() override { return _is_on; }
void turnOn() override;
void turnOff() override;
void clear() override;
void startFrame(Color bkg = DARK) override;
void setTextSize(int sz) override;
void setColor(Color c) override;
void setCursor(int x, int y) override;
void print(const char* str) override;
void fillRect(int x, int y, int w, int h) override;
void drawRect(int x, int y, int w, int h) override;
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override;
uint16_t getTextWidth(const char* str) override;
void endFrame() override;
};
Loading