2020-09-06 09:24:08 -07:00
|
|
|
#include "CryptoEngine.h"
|
2021-01-02 11:06:38 +08:00
|
|
|
#include "PortduinoGPIO.h"
|
2021-01-02 14:14:59 +08:00
|
|
|
#include "mesh/RF95Interface.h"
|
2020-10-31 15:50:39 +08:00
|
|
|
#include "sleep.h"
|
2021-04-02 09:14:12 +08:00
|
|
|
#include "target_specific.h"
|
2020-09-06 09:24:08 -07:00
|
|
|
|
2021-01-02 14:14:59 +08:00
|
|
|
#include <Utility.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
2021-04-02 09:14:12 +08:00
|
|
|
// FIXME - move setBluetoothEnable into a HALPlatform class
|
2020-09-06 09:24:08 -07:00
|
|
|
|
|
|
|
|
void setBluetoothEnable(bool on)
|
|
|
|
|
{
|
2021-03-17 20:29:27 +08:00
|
|
|
// not needed
|
2020-09-06 09:24:08 -07:00
|
|
|
}
|
|
|
|
|
|
2021-04-02 09:14:12 +08:00
|
|
|
void cpuDeepSleep(uint64_t msecs)
|
|
|
|
|
{
|
2020-10-31 15:50:39 +08:00
|
|
|
notImplemented("cpuDeepSleep");
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-02 11:06:38 +08:00
|
|
|
void updateBatteryLevel(uint8_t level) NOT_IMPLEMENTED("updateBatteryLevel");
|
|
|
|
|
|
2021-01-02 12:38:18 +08:00
|
|
|
/** Dear pinetab hardware geeks!
|
2021-04-02 09:14:12 +08:00
|
|
|
*
|
2021-01-02 12:38:18 +08:00
|
|
|
* The current pinetab lora module has a slight bug. The ch341 part only provides ISR assertions on edges.
|
|
|
|
|
* This makes sense because USB interrupts happen through fast/repeated special irq urbs that are constantly
|
|
|
|
|
* chattering on the USB bus.
|
2021-04-02 09:14:12 +08:00
|
|
|
*
|
2021-01-02 12:38:18 +08:00
|
|
|
* But this isn't sufficient for level triggered ISR sources like the sx127x radios. The common way that seems to
|
|
|
|
|
* be addressed by cs341 users is to **always** connect the INT# (pin 26 on the ch341f) signal to one of the GPIO signals
|
|
|
|
|
* on the part. I'd recommend connecting that LORA_DIO0/INT# line to pin 19 (data 4) on the pinetab board. This would
|
|
|
|
|
* provide an efficent mechanism so that the (kernel) code in the cs341 driver that I've slightly hacked up to see the
|
|
|
|
|
* current state of LORA_DIO0. Without that access, I can't know if the interrupt is still pending - which would create
|
2021-04-02 09:14:12 +08:00
|
|
|
* race conditions in packet handling.
|
|
|
|
|
*
|
2021-01-02 12:38:18 +08:00
|
|
|
* My workaround is to poll the status register internally to the sx127x. Which is expensive because it involves a number of
|
|
|
|
|
* i2c transactions and many trips back and forth between kernel and my userspace app. I think shipping the current version
|
|
|
|
|
* of the pinetab lora device would be fine because I can poll slowly (because lora is slow). But if you ever have cause to
|
|
|
|
|
* rev this board. I highly encourage this small change.
|
2021-04-02 09:14:12 +08:00
|
|
|
*
|
2021-01-02 12:38:18 +08:00
|
|
|
* Btw - your little "USB lora dongle" is really neat. I encourage you to sell it, because even non pinetab customers could
|
|
|
|
|
* use it to easily add lora to rasberry pi, desktop pcs etc...
|
2021-04-02 09:14:12 +08:00
|
|
|
*
|
2021-01-02 12:38:18 +08:00
|
|
|
* Porduino helper class to do this i2c based polling:
|
|
|
|
|
*/
|
2021-04-22 08:49:05 +08:00
|
|
|
class PolledIrqPin : public GPIOPin
|
2021-04-02 09:14:12 +08:00
|
|
|
{
|
|
|
|
|
public:
|
2021-04-22 08:49:05 +08:00
|
|
|
PolledIrqPin() : GPIOPin(LORA_DIO0, "LORA_DIO0") {}
|
2021-01-02 12:38:18 +08:00
|
|
|
|
|
|
|
|
/// Read the low level hardware for this pin
|
|
|
|
|
virtual PinStatus readPinHardware()
|
|
|
|
|
{
|
2021-04-02 09:14:12 +08:00
|
|
|
if (isrPinStatus < 0)
|
2021-01-02 12:38:18 +08:00
|
|
|
return LOW; // No interrupt handler attached, don't bother polling i2c right now
|
|
|
|
|
else {
|
2021-04-02 09:14:12 +08:00
|
|
|
extern RadioInterface *rIf; // FIXME, temporary hack until we know if we need to keep this
|
2021-01-02 12:38:18 +08:00
|
|
|
|
|
|
|
|
assert(rIf);
|
2021-04-22 08:49:05 +08:00
|
|
|
bool p = rIf->isIRQPending();
|
|
|
|
|
if(p)
|
|
|
|
|
log(SysGPIO, LogDebug, "R595PolledIrqPin::readPinHardware(%s, %d, %d)", getName(), getPinNum(), p);
|
2021-01-02 12:38:18 +08:00
|
|
|
return p ? HIGH : LOW;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2021-01-02 11:06:38 +08:00
|
|
|
|
2021-04-02 09:14:12 +08:00
|
|
|
/** apps run under portduino can optionally define a portduinoSetup() to
|
2021-01-02 11:06:38 +08:00
|
|
|
* use portduino specific init code (such as gpioBind) to setup portduino on their host machine,
|
|
|
|
|
* before running 'arduino' code.
|
|
|
|
|
*/
|
2021-04-02 09:14:12 +08:00
|
|
|
void portduinoSetup()
|
|
|
|
|
{
|
|
|
|
|
printf("Setting up Meshtastic on Porduino...\n");
|
2021-03-15 19:59:09 +08:00
|
|
|
|
2021-04-22 08:49:05 +08:00
|
|
|
// FIXME: remove this hack once interrupts are confirmed to work on new pine64 board
|
|
|
|
|
gpioBind(new PolledIrqPin());
|
2021-03-15 19:59:09 +08:00
|
|
|
|
2021-04-02 09:14:12 +08:00
|
|
|
// gpioBind((new SimGPIOPin(LORA_RESET, "LORA_RESET")));
|
|
|
|
|
// gpioBind((new SimGPIOPin(RF95_NSS, "RF95_NSS"))->setSilent());
|
2021-01-02 11:06:38 +08:00
|
|
|
}
|