trunk fmt
This commit is contained in:
+6
-6
@@ -351,19 +351,19 @@ class AnalogBatteryLevel : public HasBatteryLevel
|
|||||||
virtual bool isVbusIn() override
|
virtual bool isVbusIn() override
|
||||||
{
|
{
|
||||||
#ifdef EXT_PWR_DETECT
|
#ifdef EXT_PWR_DETECT
|
||||||
#ifdef HELTEC_CAPSULE_SENSOR_V3
|
#ifdef HELTEC_CAPSULE_SENSOR_V3
|
||||||
// if external powered that pin will be pulled down
|
// if external powered that pin will be pulled down
|
||||||
if (digitalRead(EXT_PWR_DETECT) == LOW) {
|
if (digitalRead(EXT_PWR_DETECT) == LOW) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// if it's not LOW - check the battery
|
// if it's not LOW - check the battery
|
||||||
#else
|
#else
|
||||||
// if external powered that pin will be pulled up
|
// if external powered that pin will be pulled up
|
||||||
if (digitalRead(EXT_PWR_DETECT) == HIGH) {
|
if (digitalRead(EXT_PWR_DETECT) == HIGH) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// if it's not HIGH - check the battery
|
// if it's not HIGH - check the battery
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
return getBattVoltage() > chargingVolt;
|
return getBattVoltage() > chargingVolt;
|
||||||
}
|
}
|
||||||
@@ -461,11 +461,11 @@ Power::Power() : OSThread("Power")
|
|||||||
bool Power::analogInit()
|
bool Power::analogInit()
|
||||||
{
|
{
|
||||||
#ifdef EXT_PWR_DETECT
|
#ifdef EXT_PWR_DETECT
|
||||||
#ifdef HELTEC_CAPSULE_SENSOR_V3
|
#ifdef HELTEC_CAPSULE_SENSOR_V3
|
||||||
pinMode(EXT_PWR_DETECT, INPUT_PULLUP);
|
pinMode(EXT_PWR_DETECT, INPUT_PULLUP);
|
||||||
#else
|
#else
|
||||||
pinMode(EXT_PWR_DETECT, INPUT);
|
pinMode(EXT_PWR_DETECT, INPUT);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#ifdef EXT_CHRG_DETECT
|
#ifdef EXT_CHRG_DETECT
|
||||||
pinMode(EXT_CHRG_DETECT, ext_chrg_detect_mode);
|
pinMode(EXT_CHRG_DETECT, ext_chrg_detect_mode);
|
||||||
|
|||||||
+4
-4
@@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "../variants/rak2560/RAK9154Sensor.h"
|
||||||
#include "PowerStatus.h"
|
#include "PowerStatus.h"
|
||||||
#include "concurrency/OSThread.h"
|
#include "concurrency/OSThread.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "../variants/rak2560/RAK9154Sensor.h"
|
|
||||||
|
|
||||||
#ifdef ARCH_ESP32
|
#ifdef ARCH_ESP32
|
||||||
#include <esp_adc_cal.h>
|
#include <esp_adc_cal.h>
|
||||||
@@ -56,7 +56,7 @@ extern RAK9154Sensor rak9154Sensor;
|
|||||||
class Power : private concurrency::OSThread
|
class Power : private concurrency::OSThread
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Observable<const meshtastic::PowerStatus *> newStatus;
|
Observable<const meshtastic::PowerStatus *> newStatus;
|
||||||
|
|
||||||
Power();
|
Power();
|
||||||
@@ -68,7 +68,7 @@ public:
|
|||||||
void setStatusHandler(meshtastic::PowerStatus *handler) { statusHandler = handler; }
|
void setStatusHandler(meshtastic::PowerStatus *handler) { statusHandler = handler; }
|
||||||
const uint16_t OCV[11] = {OCV_ARRAY};
|
const uint16_t OCV[11] = {OCV_ARRAY};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
meshtastic::PowerStatus *statusHandler;
|
meshtastic::PowerStatus *statusHandler;
|
||||||
|
|
||||||
/// Setup a xpowers chip axp192/axp2101, return true if found
|
/// Setup a xpowers chip axp192/axp2101, return true if found
|
||||||
@@ -76,7 +76,7 @@ protected:
|
|||||||
/// Setup a simple ADC input based battery sensor
|
/// Setup a simple ADC input based battery sensor
|
||||||
bool analogInit();
|
bool analogInit();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// open circuit voltage lookup table
|
// open circuit voltage lookup table
|
||||||
uint8_t low_voltage_counter;
|
uint8_t low_voltage_counter;
|
||||||
#ifdef DEBUG_HEAP
|
#ifdef DEBUG_HEAP
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
#include "../modules/Telemetry/Sensor/TelemetrySensor.h"
|
#include "../modules/Telemetry/Sensor/TelemetrySensor.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
|
|
||||||
#include <RAK-OneWireSerial.h>
|
|
||||||
#include "concurrency/Periodic.h"
|
#include "concurrency/Periodic.h"
|
||||||
|
#include <RAK-OneWireSerial.h>
|
||||||
|
|
||||||
using namespace concurrency;
|
using namespace concurrency;
|
||||||
|
|
||||||
@@ -27,8 +27,7 @@ static uint8_t provision = 0;
|
|||||||
|
|
||||||
static void onewire_evt(const uint8_t pid, const uint8_t sid, const SNHUBAPI_EVT_E eid, uint8_t *msg, uint16_t len)
|
static void onewire_evt(const uint8_t pid, const uint8_t sid, const SNHUBAPI_EVT_E eid, uint8_t *msg, uint16_t len)
|
||||||
{
|
{
|
||||||
switch (eid)
|
switch (eid) {
|
||||||
{
|
|
||||||
case SNHUBAPI_EVT_RECV_REQ:
|
case SNHUBAPI_EVT_RECV_REQ:
|
||||||
case SNHUBAPI_EVT_RECV_RSP:
|
case SNHUBAPI_EVT_RECV_RSP:
|
||||||
break;
|
break;
|
||||||
@@ -62,12 +61,10 @@ static void onewire_evt(const uint8_t pid, const uint8_t sid, const SNHUBAPI_EVT
|
|||||||
// LOG_INFO("%02x,", msg[i]);
|
// LOG_INFO("%02x,", msg[i]);
|
||||||
// }
|
// }
|
||||||
// LOG_INFO("\r\n");
|
// LOG_INFO("\r\n");
|
||||||
switch (msg[0])
|
switch (msg[0]) {
|
||||||
{
|
|
||||||
case RAK_IPSO_CAPACITY:
|
case RAK_IPSO_CAPACITY:
|
||||||
dc_prec = msg[1];
|
dc_prec = msg[1];
|
||||||
if (dc_prec > 100)
|
if (dc_prec > 100) {
|
||||||
{
|
|
||||||
dc_prec = 100;
|
dc_prec = 100;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -92,12 +89,10 @@ static void onewire_evt(const uint8_t pid, const uint8_t sid, const SNHUBAPI_EVT
|
|||||||
// }
|
// }
|
||||||
// LOG_INFO("\r\n");
|
// LOG_INFO("\r\n");
|
||||||
|
|
||||||
switch (msg[0])
|
switch (msg[0]) {
|
||||||
{
|
|
||||||
case RAK_IPSO_CAPACITY:
|
case RAK_IPSO_CAPACITY:
|
||||||
dc_prec = msg[1];
|
dc_prec = msg[1];
|
||||||
if (dc_prec > 100)
|
if (dc_prec > 100) {
|
||||||
{
|
|
||||||
dc_prec = 100;
|
dc_prec = 100;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -129,21 +124,18 @@ static void onewire_evt(const uint8_t pid, const uint8_t sid, const SNHUBAPI_EVT
|
|||||||
|
|
||||||
static int32_t onewireHandle()
|
static int32_t onewireHandle()
|
||||||
{
|
{
|
||||||
if (provision != 0)
|
if (provision != 0) {
|
||||||
{
|
|
||||||
RakSNHub_Protocl_API.get.data(provision);
|
RakSNHub_Protocl_API.get.data(provision);
|
||||||
provision = 0;
|
provision = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (mySerial.available())
|
while (mySerial.available()) {
|
||||||
{
|
|
||||||
char a = mySerial.read();
|
char a = mySerial.read();
|
||||||
buff[bufflen++] = a;
|
buff[bufflen++] = a;
|
||||||
delay(2); // continue data, timeout=2ms
|
delay(2); // continue data, timeout=2ms
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bufflen != 0)
|
if (bufflen != 0) {
|
||||||
{
|
|
||||||
RakSNHub_Protocl_API.process((uint8_t *)buff, bufflen);
|
RakSNHub_Protocl_API.process((uint8_t *)buff, bufflen);
|
||||||
bufflen = 0;
|
bufflen = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,23 @@
|
|||||||
import sys
|
|
||||||
import struct
|
import struct
|
||||||
|
import sys
|
||||||
|
|
||||||
Import("env")
|
Import("env")
|
||||||
|
|
||||||
|
|
||||||
# Parse input and create UF2 file
|
# Parse input and create UF2 file
|
||||||
def create_uf2(source, target, env):
|
def create_uf2(source, target, env):
|
||||||
# source_hex = target[0].get_abspath()
|
# source_hex = target[0].get_abspath()
|
||||||
source_hex = target[0].get_string(False)
|
source_hex = target[0].get_string(False)
|
||||||
source_hex = '.\\'+source_hex
|
source_hex = ".\\" + source_hex
|
||||||
print("#########################################################")
|
print("#########################################################")
|
||||||
print("Create UF2 from "+source_hex)
|
print("Create UF2 from " + source_hex)
|
||||||
print("#########################################################")
|
print("#########################################################")
|
||||||
# print("Source: " + source_hex)
|
# print("Source: " + source_hex)
|
||||||
target = source_hex.replace(".hex", "")
|
target = source_hex.replace(".hex", "")
|
||||||
target = target + ".uf2"
|
target = target + ".uf2"
|
||||||
# print("Target: " + target)
|
# print("Target: " + target)
|
||||||
|
|
||||||
with open(source_hex, mode='rb') as f:
|
with open(source_hex, mode="rb") as f:
|
||||||
inpbuf = f.read()
|
inpbuf = f.read()
|
||||||
|
|
||||||
outbuf = convert_from_hex_to_uf2(inpbuf.decode("utf-8"))
|
outbuf = convert_from_hex_to_uf2(inpbuf.decode("utf-8"))
|
||||||
@@ -48,9 +49,17 @@ class Block:
|
|||||||
flags = 0x0
|
flags = 0x0
|
||||||
if familyid:
|
if familyid:
|
||||||
flags |= 0x2000
|
flags |= 0x2000
|
||||||
hd = struct.pack("<IIIIIIII",
|
hd = struct.pack(
|
||||||
UF2_MAGIC_START0, UF2_MAGIC_START1,
|
"<IIIIIIII",
|
||||||
flags, self.addr, 256, blockno, numblocks, familyid)
|
UF2_MAGIC_START0,
|
||||||
|
UF2_MAGIC_START1,
|
||||||
|
flags,
|
||||||
|
self.addr,
|
||||||
|
256,
|
||||||
|
blockno,
|
||||||
|
numblocks,
|
||||||
|
familyid,
|
||||||
|
)
|
||||||
hd += self.bytes[0:256]
|
hd += self.bytes[0:256]
|
||||||
while len(hd) < 512 - 4:
|
while len(hd) < 512 - 4:
|
||||||
hd += b"\x00"
|
hd += b"\x00"
|
||||||
@@ -70,20 +79,20 @@ def convert_from_hex_to_uf2(buf):
|
|||||||
upper = 0
|
upper = 0
|
||||||
currblock = None
|
currblock = None
|
||||||
blocks = []
|
blocks = []
|
||||||
for line in buf.split('\n'):
|
for line in buf.split("\n"):
|
||||||
if line[0] != ":":
|
if line[0] != ":":
|
||||||
continue
|
continue
|
||||||
i = 1
|
i = 1
|
||||||
rec = []
|
rec = []
|
||||||
while i < len(line) - 1:
|
while i < len(line) - 1:
|
||||||
rec.append(int(line[i:i+2], 16))
|
rec.append(int(line[i : i + 2], 16))
|
||||||
i += 2
|
i += 2
|
||||||
tp = rec[3]
|
tp = rec[3]
|
||||||
if tp == 4:
|
if tp == 4:
|
||||||
upper = ((rec[4] << 8) | rec[5]) << 16
|
upper = ((rec[4] << 8) | rec[5]) << 16
|
||||||
elif tp == 2:
|
elif tp == 2:
|
||||||
upper = ((rec[4] << 8) | rec[5]) << 4
|
upper = ((rec[4] << 8) | rec[5]) << 4
|
||||||
assert (upper & 0xffff) == 0
|
assert (upper & 0xFFFF) == 0
|
||||||
elif tp == 1:
|
elif tp == 1:
|
||||||
break
|
break
|
||||||
elif tp == 0:
|
elif tp == 0:
|
||||||
@@ -92,10 +101,10 @@ def convert_from_hex_to_uf2(buf):
|
|||||||
appstartaddr = addr
|
appstartaddr = addr
|
||||||
i = 4
|
i = 4
|
||||||
while i < len(rec) - 1:
|
while i < len(rec) - 1:
|
||||||
if not currblock or currblock.addr & ~0xff != addr & ~0xff:
|
if not currblock or currblock.addr & ~0xFF != addr & ~0xFF:
|
||||||
currblock = Block(addr & ~0xff)
|
currblock = Block(addr & ~0xFF)
|
||||||
blocks.append(currblock)
|
blocks.append(currblock)
|
||||||
currblock.bytes[addr & 0xff] = rec[i]
|
currblock.bytes[addr & 0xFF] = rec[i]
|
||||||
addr += 1
|
addr += 1
|
||||||
i += 1
|
i += 1
|
||||||
numblocks = len(blocks)
|
numblocks = len(blocks)
|
||||||
|
|||||||
+34
-35
@@ -34,8 +34,7 @@
|
|||||||
#include "WVariant.h"
|
#include "WVariant.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C" {
|
||||||
{
|
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|
||||||
// Number of pins defined in PinDescription array
|
// Number of pins defined in PinDescription array
|
||||||
@@ -56,7 +55,7 @@ extern "C"
|
|||||||
|
|
||||||
#define LED_STATE_ON 1 // State when LED is litted
|
#define LED_STATE_ON 1 // State when LED is litted
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Buttons
|
* Buttons
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -78,14 +77,14 @@ extern "C"
|
|||||||
#define PIN_A6 (0xff)
|
#define PIN_A6 (0xff)
|
||||||
#define PIN_A7 (0xff)
|
#define PIN_A7 (0xff)
|
||||||
|
|
||||||
static const uint8_t A0 = PIN_A0;
|
static const uint8_t A0 = PIN_A0;
|
||||||
static const uint8_t A1 = PIN_A1;
|
static const uint8_t A1 = PIN_A1;
|
||||||
static const uint8_t A2 = PIN_A2;
|
static const uint8_t A2 = PIN_A2;
|
||||||
static const uint8_t A3 = PIN_A3;
|
static const uint8_t A3 = PIN_A3;
|
||||||
static const uint8_t A4 = PIN_A4;
|
static const uint8_t A4 = PIN_A4;
|
||||||
static const uint8_t A5 = PIN_A5;
|
static const uint8_t A5 = PIN_A5;
|
||||||
static const uint8_t A6 = PIN_A6;
|
static const uint8_t A6 = PIN_A6;
|
||||||
static const uint8_t A7 = PIN_A7;
|
static const uint8_t A7 = PIN_A7;
|
||||||
#define ADC_RESOLUTION 14
|
#define ADC_RESOLUTION 14
|
||||||
|
|
||||||
// Other pins
|
// Other pins
|
||||||
@@ -93,7 +92,7 @@ extern "C"
|
|||||||
#define PIN_NFC1 (9)
|
#define PIN_NFC1 (9)
|
||||||
#define PIN_NFC2 (10)
|
#define PIN_NFC2 (10)
|
||||||
|
|
||||||
static const uint8_t AREF = PIN_AREF;
|
static const uint8_t AREF = PIN_AREF;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Serial interfaces
|
* Serial interfaces
|
||||||
@@ -118,12 +117,12 @@ extern "C"
|
|||||||
#define PIN_SPI1_MOSI (30) // (0 + 30)
|
#define PIN_SPI1_MOSI (30) // (0 + 30)
|
||||||
#define PIN_SPI1_SCK (3) // (0 + 3)
|
#define PIN_SPI1_SCK (3) // (0 + 3)
|
||||||
|
|
||||||
static const uint8_t SS = 42;
|
static const uint8_t SS = 42;
|
||||||
static const uint8_t MOSI = PIN_SPI_MOSI;
|
static const uint8_t MOSI = PIN_SPI_MOSI;
|
||||||
static const uint8_t MISO = PIN_SPI_MISO;
|
static const uint8_t MISO = PIN_SPI_MISO;
|
||||||
static const uint8_t SCK = PIN_SPI_SCK;
|
static const uint8_t SCK = PIN_SPI_SCK;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* eink display pins
|
* eink display pins
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -159,7 +158,7 @@ extern "C"
|
|||||||
#define EXTERNAL_FLASH_DEVICES IS25LP080D
|
#define EXTERNAL_FLASH_DEVICES IS25LP080D
|
||||||
#define EXTERNAL_FLASH_USE_QSPI
|
#define EXTERNAL_FLASH_USE_QSPI
|
||||||
|
|
||||||
/* @note RAK5005-O GPIO mapping to RAK4631 GPIO ports
|
/* @note RAK5005-O GPIO mapping to RAK4631 GPIO ports
|
||||||
RAK5005-O <-> nRF52840
|
RAK5005-O <-> nRF52840
|
||||||
IO1 <-> P0.17 (Arduino GPIO number 17)
|
IO1 <-> P0.17 (Arduino GPIO number 17)
|
||||||
IO2 <-> P1.02 (Arduino GPIO number 34)
|
IO2 <-> P1.02 (Arduino GPIO number 34)
|
||||||
@@ -174,29 +173,29 @@ extern "C"
|
|||||||
SPI_CS <-> P0.26 (Arduino GPIO number 26)
|
SPI_CS <-> P0.26 (Arduino GPIO number 26)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// RAK4630 LoRa module
|
// RAK4630 LoRa module
|
||||||
|
|
||||||
/* Setup of the SX1262 LoRa module ( https://docs.rakwireless.com/Product-Categories/WisBlock/RAK4631/Datasheet/ )
|
/* Setup of the SX1262 LoRa module ( https://docs.rakwireless.com/Product-Categories/WisBlock/RAK4631/Datasheet/ )
|
||||||
|
|
||||||
P1.10 NSS SPI NSS (Arduino GPIO number 42)
|
P1.10 NSS SPI NSS (Arduino GPIO number 42)
|
||||||
P1.11 SCK SPI CLK (Arduino GPIO number 43)
|
P1.11 SCK SPI CLK (Arduino GPIO number 43)
|
||||||
P1.12 MOSI SPI MOSI (Arduino GPIO number 44)
|
P1.12 MOSI SPI MOSI (Arduino GPIO number 44)
|
||||||
P1.13 MISO SPI MISO (Arduino GPIO number 45)
|
P1.13 MISO SPI MISO (Arduino GPIO number 45)
|
||||||
P1.14 BUSY BUSY signal (Arduino GPIO number 46)
|
P1.14 BUSY BUSY signal (Arduino GPIO number 46)
|
||||||
P1.15 DIO1 DIO1 event interrupt (Arduino GPIO number 47)
|
P1.15 DIO1 DIO1 event interrupt (Arduino GPIO number 47)
|
||||||
P1.06 NRESET NRESET manual reset of the SX1262 (Arduino GPIO number 38)
|
P1.06 NRESET NRESET manual reset of the SX1262 (Arduino GPIO number 38)
|
||||||
|
|
||||||
Important for successful SX1262 initialization:
|
Important for successful SX1262 initialization:
|
||||||
|
|
||||||
* Setup DIO2 to control the antenna switch
|
* Setup DIO2 to control the antenna switch
|
||||||
* Setup DIO3 to control the TCXO power supply
|
* Setup DIO3 to control the TCXO power supply
|
||||||
* Setup the SX1262 to use it's DCDC regulator and not the LDO
|
* Setup the SX1262 to use it's DCDC regulator and not the LDO
|
||||||
* RAK4630 schematics show GPIO P1.07 connected to the antenna switch, but it should not be initialized, as DIO2 will do the
|
* RAK4630 schematics show GPIO P1.07 connected to the antenna switch, but it should not be initialized, as DIO2 will do the
|
||||||
control of the antenna switch
|
control of the antenna switch
|
||||||
|
|
||||||
SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG
|
SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define DETECTION_SENSOR_EN 4
|
#define DETECTION_SENSOR_EN 4
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user