Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Portduino work #3049

Merged
merged 21 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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 changes: 6 additions & 2 deletions arch/portduino/portduino.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; The Portduino based sim environment on top of any host OS, all hardware will be simulated
[portduino_base]
platform = https://github.com/meshtastic/platform-native.git#8a66ef82cf38a4135d85cbb5043d0e8ebbb8ba17
platform = https://github.com/meshtastic/platform-native.git#04435d06e39916a6c019d511518d8e95c659dfbd
framework = arduino

build_src_filter =
Expand Down Expand Up @@ -28,4 +28,8 @@ build_flags =
${arduino_base.build_flags}
-fPIC
-Isrc/platform/portduino
-DRADIOLIB_EEPROM_UNSUPPORTED
-DRADIOLIB_EEPROM_UNSUPPORTED
-DPORTDUINO_LINUX_HARDWARE
-lbluetooth
-lgpiod
-lyaml-cpp
27 changes: 27 additions & 0 deletions bin/config-dist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Lora:
# IRQ: 17
# Reset: 22

# Module: sx1262 # pinedio
# CS: 0
# IRQ: 10
# Busy: 11
# spidev: spidev0.1

# Module: RF95 # Adafruit RFM9x
# Reset: 25
# CS: 7
Expand All @@ -31,10 +37,19 @@ Lora:
# Busy: 20
# Reset: 18

# DIO3_TCXO_VOLTAGE: true # the Waveshare Core1262 and others are known to need this setting

# TXen: x # TX and RX enable pins
# RXen: x

### Set gpio chip to use in /dev/. Defaults to 0.
### Notably the Raspberry Pi 5 puts the GPIO header on gpiochip4
# gpiochip: 4

### Specify the SPI device to use in /dev/. Defaults to spidev0.0
### Some devices, like the pinedio, may require spidev0.1 as a workaround.
# spidev: spidev0.0

### Define GPIO buttons here:

GPIO:
Expand All @@ -58,6 +73,18 @@ Display:
# Height: 320
# Reset: 27
# Rotate: true
# Invert: true

### Waveshare 1.44inch LCD HAT
# Panel: ST7735S
# CS: 8 #Chip Select
# DC: 25 # Data/Command pin
# Backlight: 24
# Width: 128
# Height: 128
# Reset: 27
# OffsetX: 0
# OffsetY: 0

Touchscreen:
# Module: XPT2046
Expand Down
12 changes: 6 additions & 6 deletions src/ButtonThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ButtonThread : public concurrency::OSThread
#ifdef BUTTON_PIN_TOUCH
OneButton userButtonTouch;
#endif
#if defined(ARCH_RASPBERRY_PI)
#if defined(ARCH_PORTDUINO)
OneButton userButton;
#endif
static bool shutdown_on_long_stop;
Expand All @@ -49,8 +49,8 @@ class ButtonThread : public concurrency::OSThread
// callback returns the period for the next callback invocation (or 0 if we should no longer be called)
ButtonThread() : OSThread("Button")
{
#if defined(ARCH_RASPBERRY_PI) || defined(BUTTON_PIN)
#if defined(ARCH_RASPBERRY_PI)
#if defined(ARCH_PORTDUINO) || defined(BUTTON_PIN)
#if defined(ARCH_PORTDUINO)
if (settingsMap.count(user) != 0 && settingsMap[user] != RADIOLIB_NC)
userButton = OneButton(settingsMap[user], true, true);
#elif defined(BUTTON_PIN)
Expand All @@ -68,7 +68,7 @@ class ButtonThread : public concurrency::OSThread
userButton.attachMultiClick(userButtonMultiPressed);
userButton.attachLongPressStart(userButtonPressedLongStart);
userButton.attachLongPressStop(userButtonPressedLongStop);
#if defined(ARCH_RASPBERRY_PI)
#if defined(ARCH_PORTDUINO)
if (settingsMap.count(user) != 0 && settingsMap[user] != RADIOLIB_NC)
wakeOnIrq(settingsMap[user], FALLING);
#else
Expand Down Expand Up @@ -105,7 +105,7 @@ class ButtonThread : public concurrency::OSThread
#if defined(BUTTON_PIN)
userButton.tick();
canSleep &= userButton.isIdle();
#elif defined(ARCH_RASPBERRY_PI)
#elif defined(ARCH_PORTDUINO)
if (settingsMap.count(user) != 0 && settingsMap[user] != RADIOLIB_NC) {
userButton.tick();
canSleep &= userButton.isIdle();
Expand Down Expand Up @@ -143,7 +143,7 @@ class ButtonThread : public concurrency::OSThread
powerFSM.trigger(EVENT_PRESS);
}
#endif
#if defined(ARCH_RASPBERRY_PI)
#if defined(ARCH_PORTDUINO)
if ((settingsMap.count(user) != 0 && settingsMap[user] != RADIOLIB_NC) &&
(settingsMap[user] != moduleConfig.canned_message.inputbroker_pin_press) ||
!moduleConfig.canned_message.enabled) {
Expand Down
4 changes: 2 additions & 2 deletions src/RedirectablePrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ size_t RedirectablePrint::log(const char *logLevel, const char *format, ...)
int min = (hms % SEC_PER_HOUR) / SEC_PER_MIN;
int sec = (hms % SEC_PER_HOUR) % SEC_PER_MIN; // or hms % SEC_PER_MIN

r += printf("%s | %02d:%02d:%02d %u ", logLevel, hour, min, sec, millis() / 1000);
r += ::printf("%s | %02d:%02d:%02d %u ", logLevel, hour, min, sec, millis() / 1000);
} else
r += printf("%s | ??:??:?? %u ", logLevel, millis() / 1000);
r += ::printf("%s | ??:??:?? %u ", logLevel, millis() / 1000);

auto thread = concurrency::OSThread::currentThread;
if (thread) {
Expand Down
2 changes: 1 addition & 1 deletion src/detect/ScanI2CTwoWire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "concurrency/LockGuard.h"
#include "configuration.h"
#if defined(ARCH_RASPBERRY_PI)
#if defined(ARCH_PORTDUINO)
#include "linux/LinuxHardwareI2C.h"
#endif
#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL)
Expand Down
6 changes: 3 additions & 3 deletions src/gps/GPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define GPS_RESET_MODE HIGH
#endif

#if defined(NRF52840_XXAA) || defined(NRF52833_XXAA) || defined(ARCH_ESP32) || defined(ARCH_RASPBERRY_PI)
#if defined(NRF52840_XXAA) || defined(NRF52833_XXAA) || defined(ARCH_ESP32) || defined(aLinuxInputImpl)
HardwareSerial *GPS::_serial_gps = &Serial1;
#else
HardwareSerial *GPS::_serial_gps = NULL;
Expand Down Expand Up @@ -924,7 +924,7 @@ GPS *GPS::createGps()
if (!_en_gpio)
_en_gpio = PIN_GPS_EN;
#endif
#ifdef ARCH_RASPBERRY_PI
#ifdef ARCH_PORTDUINO
if (!settingsMap[has_gps])
return nullptr;
#endif
Expand Down Expand Up @@ -1286,4 +1286,4 @@ int32_t GPS::disable()
setAwake(false);

return INT32_MAX;
}
}
20 changes: 10 additions & 10 deletions src/graphics/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "sleep.h"
#include "target_specific.h"

#if HAS_WIFI && !defined(ARCH_RASPBERRY_PI)
#if HAS_WIFI && !defined(ARCH_PORTDUINO)
#include "mesh/wifi/WiFiAPClient.h"
#endif

Expand All @@ -52,7 +52,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "modules/esp32/StoreForwardModule.h"
#endif

#if ARCH_RASPBERRY_PI
#if ARCH_PORTDUINO
#include "platform/portduino/PortduinoGlue.h"
#endif

Expand Down Expand Up @@ -930,8 +930,8 @@ Screen::Screen(ScanI2C::DeviceAddress address, meshtastic_Config_DisplayConfig_O
#elif defined(USE_ST7567)
dispdev = new ST7567Wire(address.address, -1, -1, geometry,
(address.port == ScanI2C::I2CPort::WIRE1) ? HW_I2C::I2C_TWO : HW_I2C::I2C_ONE);
#elif ARCH_RASPBERRY_PI
if (settingsMap[displayPanel] == st7789) {
#elif ARCH_PORTDUINO
if (settingsMap[displayPanel] != no_screen) {
LOG_DEBUG("Making TFTDisplay!\n");
dispdev = new TFTDisplay(address.address, -1, -1, geometry,
(address.port == ScanI2C::I2CPort::WIRE1) ? HW_I2C::I2C_TWO : HW_I2C::I2C_ONE);
Expand Down Expand Up @@ -976,7 +976,7 @@ void Screen::handleSetOn(bool on)
#ifdef T_WATCH_S3
PMU->enablePowerOutput(XPOWERS_ALDO2);
#endif
#if !ARCH_RASPBERRY_PI
#if !ARCH_PORTDUINO
dispdev->displayOn();
#endif
dispdev->displayOn();
Expand Down Expand Up @@ -1060,7 +1060,7 @@ void Screen::setup()
uint8_t dmac[6];
getMacAddr(dmac);
snprintf(ourId, sizeof(ourId), "%02x%02x", dmac[4], dmac[5]);
#if ARCH_RASPBERRY_PI
#if ARCH_PORTDUINO
handleSetOn(false); // force clean init
#endif

Expand All @@ -1075,7 +1075,7 @@ void Screen::setup()
#endif
serialSinceMsec = millis();

#if ARCH_RASPBERRY_PI
#if ARCH_PORTDUINO
if (settingsMap[touchscreenModule]) {
touchScreenImpl1 =
new TouchScreenImpl1(dispdev->getWidth(), dispdev->getHeight(), static_cast<TFTDisplay *>(dispdev)->getTouch);
Expand Down Expand Up @@ -1344,7 +1344,7 @@ void Screen::setFrames()
// call a method on debugInfoScreen object (for more details)
normalFrames[numframes++] = &Screen::drawDebugInfoSettingsTrampoline;

#if HAS_WIFI && !defined(ARCH_RASPBERRY_PI)
#if HAS_WIFI && !defined(ARCH_PORTDUINO)
if (isWifiAvailable()) {
// call a method on debugInfoScreen object (for more details)
normalFrames[numframes++] = &Screen::drawDebugInfoWiFiTrampoline;
Expand Down Expand Up @@ -1588,7 +1588,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
#endif
} else {
// TODO: Raspberry Pi supports more than just the one screen size
#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) || ARCH_RASPBERRY_PI) && \
#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) || ARCH_PORTDUINO) && \
!defined(DISPLAY_FORCE_SMALL_FONTS)
display->drawFastImage(x + SCREEN_WIDTH - 14 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 12, 8,
imgInfoL1);
Expand All @@ -1615,7 +1615,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
// Jm
void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
{
#if HAS_WIFI && !defined(ARCH_RASPBERRY_PI)
#if HAS_WIFI && !defined(ARCH_PORTDUINO)
const char *wifiName = config.network.wifi_ssid;

display->setFont(FONT_SMALL);
Expand Down
35 changes: 17 additions & 18 deletions src/graphics/TFTDisplay.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "configuration.h"
#include "main.h"
#if ARCH_RASPBERRY_PI
#if ARCH_PORTDUINO
#include "platform/portduino/PortduinoGlue.h"
#endif

Expand Down Expand Up @@ -331,7 +331,7 @@ static LGFX *tft = nullptr;
#include <TFT_eSPI.h> // Graphics and font library for ILI9341 driver chip

static TFT_eSPI *tft = nullptr; // Invoke library, pins defined in User_Setup.h
#elif ARCH_RASPBERRY_PI
#elif ARCH_PORTDUINO
#include <LovyanGFX.hpp> // Graphics and font library for ST7735 driver chip

class LGFX : public lgfx::LGFX_Device
Expand All @@ -344,8 +344,12 @@ class LGFX : public lgfx::LGFX_Device
public:
LGFX(void)
{

_panel_instance = new lgfx::Panel_ST7789;
if (settingsMap[displayPanel] == st7789)
_panel_instance = new lgfx::Panel_ST7789;
else if (settingsMap[displayPanel] == st7735)
_panel_instance = new lgfx::Panel_ST7735;
else if (settingsMap[displayPanel] == st7735s)
_panel_instance = new lgfx::Panel_ST7735S;
auto buscfg = _bus_instance.config();
buscfg.spi_mode = 0;

Expand All @@ -356,19 +360,14 @@ class LGFX : public lgfx::LGFX_Device

auto cfg = _panel_instance->config(); // Gets a structure for display panel settings.
LOG_DEBUG("Height: %d, Width: %d \n", settingsMap[displayHeight], settingsMap[displayWidth]);
cfg.pin_cs = settingsMap[displayCS]; // Pin number where CS is connected (-1 = disable)
cfg.pin_cs = settingsMap[displayCS]; // Pin number where CS is connected (-1 = disable)
cfg.pin_rst = settingsMap[displayReset];
cfg.panel_width = settingsMap[displayWidth]; // actual displayable width
cfg.panel_height = settingsMap[displayHeight]; // actual displayable height
cfg.offset_x = 0; // Panel offset amount in X direction
cfg.offset_y = 0; // Panel offset amount in Y direction
cfg.offset_x = settingsMap[displayOffsetX]; // Panel offset amount in X direction
cfg.offset_y = settingsMap[displayOffsetY]; // Panel offset amount in Y direction
cfg.offset_rotation = 0; // Rotation direction value offset 0~7 (4~7 is mirrored)
cfg.dummy_read_pixel = 9; // Number of bits for dummy read before pixel readout
cfg.dummy_read_bits = 1; // Number of bits for dummy read before non-pixel data read
cfg.readable = true; // Set to true if data can be read
cfg.invert = true; // Set to true if the light/darkness of the panel is reversed
cfg.rgb_order = false; // Set to true if the panel's red and blue are swapped
cfg.dlen_16bit = false; // Set to true for panels that transmit data length in 16-bit units with 16-bit parallel or SPI
cfg.bus_shared = true; // If the bus is shared with the SD card, set to true (bus control with drawJpgFile etc.)
cfg.invert = settingsMap[displayInvert]; // Set to true if the light/darkness of the panel is reversed

_panel_instance->config(cfg);

Expand Down Expand Up @@ -399,15 +398,15 @@ class LGFX : public lgfx::LGFX_Device
static LGFX *tft = nullptr;
#endif

#if defined(ST7735_CS) || defined(ST7789_CS) || defined(ILI9341_DRIVER) || defined(RAK14014) || ARCH_RASPBERRY_PI
#if defined(ST7735_CS) || defined(ST7789_CS) || defined(ILI9341_DRIVER) || defined(RAK14014) || ARCH_PORTDUINO
#include "SPILock.h"
#include "TFTDisplay.h"
#include <SPI.h>

TFTDisplay::TFTDisplay(uint8_t address, int sda, int scl, OLEDDISPLAY_GEOMETRY geometry, HW_I2C i2cBus)
{
LOG_DEBUG("TFTDisplay!\n");
#if ARCH_RASPBERRY_PI
#if ARCH_PORTDUINO
if (settingsMap[displayRotate]) {
setGeometry(GEOMETRY_RAWMODE, settingsMap[configNames::displayHeight], settingsMap[configNames::displayWidth]);
} else {
Expand Down Expand Up @@ -460,7 +459,7 @@ void TFTDisplay::sendCommand(uint8_t com)
// handle display on/off directly
switch (com) {
case DISPLAYON: {
#if ARCH_RASPBERRY_PI
#if ARCH_PORTDUINO
display(true);
if (settingsMap[displayBacklight] > 0)
digitalWrite(settingsMap[displayBacklight], TFT_BACKLIGHT_ON);
Expand Down Expand Up @@ -492,7 +491,7 @@ void TFTDisplay::sendCommand(uint8_t com)
break;
}
case DISPLAYOFF: {
#if ARCH_RASPBERRY_PI
#if ARCH_PORTDUINO
tft->clear();
if (settingsMap[displayBacklight] > 0)
digitalWrite(settingsMap[displayBacklight], !TFT_BACKLIGHT_ON);
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/images.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const uint8_t imgUser[] PROGMEM = {0x3C, 0x42, 0x99, 0xA5, 0xA5, 0x99, 0x42, 0x3
const uint8_t imgPositionEmpty[] PROGMEM = {0x20, 0x30, 0x28, 0x24, 0x42, 0xFF};
const uint8_t imgPositionSolid[] PROGMEM = {0x20, 0x30, 0x38, 0x3C, 0x7E, 0xFF};

#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) || ARCH_RASPBERRY_PI) && \
#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) || ARCH_PORTDUINO) && \
!defined(DISPLAY_FORCE_SMALL_FONTS)
const uint8_t imgQuestionL1[] PROGMEM = {0xff, 0x01, 0x01, 0x32, 0x7b, 0x49, 0x49, 0x6f, 0x26, 0x01, 0x01, 0xff};
const uint8_t imgQuestionL2[] PROGMEM = {0x0f, 0x08, 0x08, 0x08, 0x06, 0x0f, 0x0f, 0x06, 0x08, 0x08, 0x08, 0x0f};
Expand Down
5 changes: 2 additions & 3 deletions src/input/LinuxInput.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#if ARCH_RASPBERRY_PI
#include "LinuxInput.h"
#include "configuration.h"

#if ARCH_PORTDUINO
#include "LinuxInput.h"
#include "platform/portduino/PortduinoGlue.h"
#include <assert.h>
#include <ctype.h>
Expand Down
2 changes: 1 addition & 1 deletion src/input/LinuxInput.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#if ARCH_RASPBERRY_PI
#if ARCH_PORTDUINO
#include "InputBroker.h"
#include "concurrency/OSThread.h"
#include <assert.h>
Expand Down
5 changes: 3 additions & 2 deletions src/input/LinuxInputImpl.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#if ARCH_RASPBERRY_PI
#include "LinuxInputImpl.h"
#include "configuration.h"
#if ARCH_PORTDUINO
#include "InputBroker.h"
#include "LinuxInputImpl.h"

LinuxInputImpl *aLinuxInputImpl;

Expand Down
2 changes: 1 addition & 1 deletion src/input/LinuxInputImpl.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifdef ARCH_RASPBERRY_PI
#ifdef ARCH_PORTDUINO
#pragma once
#include "LinuxInput.h"
#include "main.h"
Expand Down
Loading
Loading