From 31139c0fe03b3f3ebd6f781ab5886e2237a9c9e0 Mon Sep 17 00:00:00 2001 From: tobozo Date: Wed, 24 Apr 2024 08:45:50 +0200 Subject: [PATCH] added portduino to CI tests --- .github/workflows/PlatformioBuild.yml | 3 + examples/Test/build_test/platformio.ini | 1 + .../Test/build_test/platformio_native.ini | 44 +++++++++++++ examples/Test/build_test/portduino/main.cpp | 53 ++++++++++++++++ examples/Test/build_test/portduino/main.h | 62 +++++++++++++++++++ 5 files changed, 163 insertions(+) create mode 100644 examples/Test/build_test/platformio_native.ini create mode 100644 examples/Test/build_test/portduino/main.cpp create mode 100644 examples/Test/build_test/portduino/main.h diff --git a/.github/workflows/PlatformioBuild.yml b/.github/workflows/PlatformioBuild.yml index aa591db5..2e4f37dd 100644 --- a/.github/workflows/PlatformioBuild.yml +++ b/.github/workflows/PlatformioBuild.yml @@ -63,6 +63,7 @@ jobs: - { board: seeed_wio_terminal, platform-version: default, ... } - { board: adafruit_pybadge_m4, platform-version: default, ... } - { board: pico, platform-version: default, ... } + - { board: native, platform-version: portduino, ... } fail-fast: false @@ -101,4 +102,6 @@ jobs: export pio_ver=${{ matrix.platform-version }} export pio_env="${pio_ver//./_}" pio pkg install -e ${{ matrix.board }}-$pio_env --no-save --library file://$(realpath ../../../) + [[ "$pio_env" == "native" ]] && { sudo apt update; sudo apt-get install libgpiod-dev; } + [[ "$pio_env" == "native" ]] && export PLATFORMIO_SRC_DIR=portduino pio run -e ${{ matrix.board }}-$pio_env diff --git a/examples/Test/build_test/platformio.ini b/examples/Test/build_test/platformio.ini index 6dec1889..4476d8a5 100644 --- a/examples/Test/build_test/platformio.ini +++ b/examples/Test/build_test/platformio.ini @@ -9,6 +9,7 @@ extra_configs = platformio_esp8266.ini platformio_esp32.ini platformio_atmelsam.ini platformio_rpipico.ini + platformio_native.ini [env] framework = arduino diff --git a/examples/Test/build_test/platformio_native.ini b/examples/Test/build_test/platformio_native.ini new file mode 100644 index 00000000..bfe2e39d --- /dev/null +++ b/examples/Test/build_test/platformio_native.ini @@ -0,0 +1,44 @@ + +[env:native-default] +platform = https://github.com/geeksville/platform-native.git +;build_flags = ${env.build_flags} -O0 -lgpiod +; framework = arduino +board = linux_hardware + +; build_src_filter = +; - +; - +; - +; - +; - +; - +; - +; - +; - +; +<../variants/portduino> + +; lib_deps = LovyanGFX + +;build_flags = -fPIC -Isrc/platform/portduino -O0 -lgpiod +build_flags = -O0 -xc++ -std=c++14 + + +[env:native-portduino] +platform = https://github.com/meshtastic/platform-native.git#659e49346aa33008b150dfb206b1817ddabc7132 +framework = arduino +board = cross_platform +;build_src_filter = +<**/*.cpp> -
+ + + +build_flags = + ${env.build_flags} + -lgpiod + -DPORTDUINO_LINUX_HARDWARE + -DARCH_PORTDUINO + -O0 + +lib_deps = + SPI + Wire + LovyanGFX diff --git a/examples/Test/build_test/portduino/main.cpp b/examples/Test/build_test/portduino/main.cpp new file mode 100644 index 00000000..8442ff45 --- /dev/null +++ b/examples/Test/build_test/portduino/main.cpp @@ -0,0 +1,53 @@ + +#include "main.h" + + +void setup() +{ + gpioInit(); + initGPIOPin(25, "gpiochip4"); + initGPIOPin(24, "gpiochip4"); + + DisplaySPI = new HardwareSPI; + DisplaySPI->begin("/dev/spidev0.0"); + Wire.begin(1); + display = new LGFX(); + display->init(); + + canvas.setColorDepth(8); + canvas.setFont(&fonts::lgfxJapanMinchoP_32); + canvas.setTextWrap(false); // 右端到達時のカーソル折り返しを禁止 + canvas.createSprite(display->width(), 36); +} + + +void loop() +{ + if (display->touch()) { + canvas.clear(); + canvas.setCursor(0, 0); + lgfx::touch_point_t tp; + auto blah = display->getTouchRaw(&tp, 1); + if (blah > 0) { + canvas.printf("Touch %i, %i\n", tp.x, tp.y); + canvas.pushSprite(display, 0, 0); + } + } +} + + +int initGPIOPin(int pinNum, std::string gpioChipName) +{ + std::string gpio_name = "GPIO" + std::to_string(pinNum); + try { + GPIOPin *csPin; + csPin = new LinuxGPIOPin(pinNum, gpioChipName.c_str(), pinNum, gpio_name.c_str()); + csPin->setSilent(); + gpioBind(csPin); + return 1; + } catch (...) { + std::exception_ptr p = std::current_exception(); + std::cout << "Warning, cannot claim pin " << gpio_name << (p ? p.__cxa_exception_type()->name() : "null") << std::endl; + return 0; + } +} diff --git a/examples/Test/build_test/portduino/main.h b/examples/Test/build_test/portduino/main.h new file mode 100644 index 00000000..558c8302 --- /dev/null +++ b/examples/Test/build_test/portduino/main.h @@ -0,0 +1,62 @@ +#include "LovyanGFX.h" +#include "Arduino.h" +#include +#include +#include "linux/gpio/LinuxGPIOPin.h" +#include "PortduinoGPIO.h" +#include + +HardwareSPI *DisplaySPI; +int initGPIOPin(int pinNum, std::string gpioChipName); + +class LGFX : public lgfx::LGFX_Device +{ + lgfx::Panel_ILI9341 _panel_instance; + lgfx::Bus_SPI _bus_instance; + lgfx::Touch_FT5x06 _touch_instance; + +public: + LGFX(void) + { + { + // Create I2C + + //Init the TFT and touch + auto buscfg = _bus_instance.config(); + buscfg.spi_mode = 0; + buscfg.pin_dc = 25; + _bus_instance.spi_device(DisplaySPI); + _bus_instance.config(buscfg); // applies the set value to the bus. + _panel_instance.setBus(&_bus_instance); // set the bus on the panel. + } + { + auto cfg = _panel_instance.config(); // Gets a structure for display panel settings. + + cfg.panel_width = 240; + cfg.panel_height = 320; + cfg.offset_x = 0; + cfg.offset_y = 0; + cfg.offset_rotation = 0; // Rotation direction value offset 0~7 (4~7 is mirrored) + cfg.invert = 0; + + _panel_instance.config(cfg); + } + { + auto touch_cfg = _touch_instance.config(); + touch_cfg.x_min = 0; + touch_cfg.x_max = 319; + touch_cfg.y_min = 0; + touch_cfg.y_max = 239; + touch_cfg.pin_int = 24; + touch_cfg.bus_shared = true; + touch_cfg.offset_rotation = 1; + touch_cfg.i2c_addr = 0x38; + _touch_instance.config(touch_cfg); + _panel_instance.setTouch(&_touch_instance); + } + setPanel(&_panel_instance); // Sets the panel to use. + } +}; + +LGFX *display; +LGFX_Sprite canvas;