From ce8342d3e528692849854e0eca4f55ff93c7f761 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 26 Nov 2023 21:30:08 -0600 Subject: [PATCH] Drop Pi HAL --- src/main.cpp | 5 +- src/platform/portduino/PiHal.h | 140 --------------------------------- 2 files changed, 2 insertions(+), 143 deletions(-) delete mode 100644 src/platform/portduino/PiHal.h diff --git a/src/main.cpp b/src/main.cpp index b8432c5ad..83f3b721e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -68,7 +68,6 @@ NRF52Bluetooth *nrf52Bluetooth; #endif #ifdef ARCH_RASPBERRY_PI -#include "platform/portduino/PiHal.h" #include "platform/portduino/PortduinoGlue.h" #include #include @@ -693,7 +692,7 @@ void setup() #ifdef ARCH_RASPBERRY_PI if (settingsMap[use_sx1262]) { if (!rIf) { - PiHal *RadioLibHAL = new PiHal(1); + LockingArduinoHal *RadioLibHAL = new LockingArduinoHal(SPI, spiSettings); rIf = new SX1262Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset], settingsMap[busy]); if (!rIf->init()) { @@ -706,7 +705,7 @@ void setup() } } else if (settingsMap[use_rf95]) { if (!rIf) { - PiHal *RadioLibHAL = new PiHal(1); + LockingArduinoHal *RadioLibHAL = new LockingArduinoHal(SPI, spiSettings); rIf = new RF95Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset], settingsMap[busy]); if (!rIf->init()) { diff --git a/src/platform/portduino/PiHal.h b/src/platform/portduino/PiHal.h deleted file mode 100644 index d80009450..000000000 --- a/src/platform/portduino/PiHal.h +++ /dev/null @@ -1,140 +0,0 @@ -#ifndef PI_HAL_H -#define PI_HAL_H - -// include RadioLib -#include - -// include the library for Raspberry GPIO pins -#include "pigpio.h" - -#include "linux/gpio/LinuxGPIOPin.h" - -// create a new Raspberry Pi hardware abstraction layer -// using the pigpio library -// the HAL must inherit from the base RadioLibHal class -// and implement all of its virtual methods -class PiHal : public RadioLibHal -{ - public: - // default constructor - initializes the base HAL and any needed private members - PiHal(uint8_t spiChannel, uint32_t spiSpeed = 2000000) - : RadioLibHal(PI_INPUT, PI_OUTPUT, PI_LOW, PI_HIGH, RISING_EDGE, FALLING_EDGE), _spiChannel(spiChannel), - _spiSpeed(spiSpeed) - { - } - - void init() override - { - // first initialise pigpio library - gpioInitialise(); - - // now the SPI - spiBegin(); - - // Waveshare LoRaWAN Hat also needs pin 18 to be pulled high to enable the radio - // gpioSetMode(18, PI_OUTPUT); - // gpioWrite(18, PI_HIGH); - } - - void term() override - { - // stop the SPI - spiEnd(); - - // pull the enable pin low - // gpioSetMode(18, PI_OUTPUT); - // gpioWrite(18, PI_LOW); - - // finally, stop the pigpio library - gpioTerminate(); - } - - // GPIO-related methods (pinMode, digitalWrite etc.) should check - // RADIOLIB_NC as an alias for non-connected pins - void pinMode(uint32_t pin, uint32_t mode) override - { - if (pin == RADIOLIB_NC) { - return; - } - ::pinMode(pin, RADIOLIB_ARDUINOHAL_PIN_MODE_CAST mode); - } - - void digitalWrite(uint32_t pin, uint32_t value) override - { - if (pin == RADIOLIB_NC) { - return; - } - ::digitalWrite(pin, RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST value); - } - - uint32_t digitalRead(uint32_t pin) override - { - if (pin == RADIOLIB_NC) { - return (0); - } - - return (::digitalRead(pin)); - } - - void attachInterrupt(uint32_t interruptNum, void (*interruptCb)(void), uint32_t mode) override - { - if (interruptNum == RADIOLIB_NC) { - return; - } - ::attachInterrupt(interruptNum, interruptCb, RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST mode); - } - - void detachInterrupt(uint32_t interruptNum) override - { - if (interruptNum == RADIOLIB_NC) { - return; - } - - ::detachInterrupt(interruptNum); - } - - void delay(unsigned long ms) override { gpioDelay(ms * 1000); } - - void delayMicroseconds(unsigned long us) override { gpioDelay(us); } - - unsigned long millis() override { return (gpioTick() / 1000); } - - unsigned long micros() override { return (gpioTick()); } - - long pulseIn(uint32_t pin, uint32_t state, unsigned long timeout) override - { - if (pin == RADIOLIB_NC) { - return (0); - } - - return (::pulseIn(pin, state, timeout)); - } - void spiBegin() - { - if (_spiHandle < 0) { - _spiHandle = spiOpen(_spiChannel, _spiSpeed, 0); - } - } - - void spiBeginTransaction() {} - - void spiTransfer(uint8_t *out, size_t len, uint8_t *in) { spiXfer(_spiHandle, (char *)out, (char *)in, len); } - - void spiEndTransaction() {} - - void spiEnd() - { - if (_spiHandle >= 0) { - spiClose(_spiHandle); - _spiHandle = -1; - } - } - - private: - // the HAL can contain any additional private members - const unsigned int _spiSpeed; - const uint8_t _spiChannel; - int _spiHandle = -1; -}; - -#endif \ No newline at end of file