- Add new Compass Sensor

- speed up I2C Scanning
- make adding sensors less error prone
This commit is contained in:
Thomas Göttgens 2022-11-12 11:03:29 +01:00
parent f25f902c20
commit 65197a8e48
7 changed files with 71 additions and 59 deletions

View File

@ -69,6 +69,7 @@ lib_deps =
${env.lib_deps} ${env.lib_deps}
; Portduino is using meshtastic fork for now ; Portduino is using meshtastic fork for now
jgromes/RadioLib@5.4.1 jgromes/RadioLib@5.4.1
mprograms/QMC5883LCompass@^1.1.1
https://github.com/meshtastic/SparkFun_ATECCX08a_Arduino_Library.git#52b5282639d08a8cbd4b748363089eed6102dc76 https://github.com/meshtastic/SparkFun_ATECCX08a_Arduino_Library.git#52b5282639d08a8cbd4b748363089eed6102dc76
build_flags = ${env.build_flags} -Os build_flags = ${env.build_flags} -Os

@ -1 +1 @@
Subproject commit c82c15aac71b9134d96c03dbe319916739cc8314 Subproject commit f7d11572b436d1078222ba27892ac73b7a9842ba

View File

@ -110,6 +110,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define INA_ADDR_ALTERNATE 0x41 #define INA_ADDR_ALTERNATE 0x41
#define QMC6310_ADDR 0x1C #define QMC6310_ADDR 0x1C
#define QMI8658_ADDR 0x6B #define QMI8658_ADDR 0x6B
#define QMC5883L_ADDR 0x1E
#define SHTC3_ADDR 0x70 #define SHTC3_ADDR 0x70
#define LPS22HB_ADDR 0x5C #define LPS22HB_ADDR 0x5C
#define LPS22HB_ADDR_ALT 0x5D #define LPS22HB_ADDR_ALT 0x5D

View File

@ -90,12 +90,14 @@ uint8_t oled_probe(byte addr)
return o_probe; return o_probe;
} }
void scanI2Cdevice(void) void scanI2Cdevice(bool partial)
{ {
byte err, addr; byte err, addr;
uint16_t registerValue = 0x00; uint16_t registerValue = 0x00;
int nDevices = 0; int nDevices = 0;
for (addr = 1; addr < 127; addr++) { for (addr = 1; addr < 127; addr++) {
if (partial && addr != SSD1306_ADDRESS && addr != ST7567_ADDRESS && addr != XPOWERS_AXP192_AXP2101_ADDRESS)
continue;
Wire.beginTransmission(addr); Wire.beginTransmission(addr);
err = Wire.endTransmission(); err = Wire.endTransmission();
if (err == 0) { if (err == 0) {
@ -106,16 +108,16 @@ void scanI2Cdevice(void)
if (addr == SSD1306_ADDRESS) { if (addr == SSD1306_ADDRESS) {
screen_found = addr; screen_found = addr;
screen_model = oled_probe(addr); screen_model = oled_probe(addr);
if (screen_model == 1){ if (screen_model == 1) {
DEBUG_MSG("ssd1306 display found\n"); DEBUG_MSG("ssd1306 display found\n");
} else if (screen_model == 2){ } else if (screen_model == 2) {
DEBUG_MSG("sh1106 display found\n"); DEBUG_MSG("sh1106 display found\n");
} else { } else {
DEBUG_MSG("unknown display found\n"); DEBUG_MSG("unknown display found\n");
} }
} }
#ifndef ARCH_PORTDUINO #ifndef ARCH_PORTDUINO
if (addr == ATECC608B_ADDR){ if (addr == ATECC608B_ADDR) {
keystore_found = addr; keystore_found = addr;
if (atecc.begin(keystore_found) == true) { if (atecc.begin(keystore_found) == true) {
DEBUG_MSG("ATECC608B initialized\n"); DEBUG_MSG("ATECC608B initialized\n");
@ -189,24 +191,30 @@ void scanI2Cdevice(void)
} }
if (addr == MCP9808_ADDR) { if (addr == MCP9808_ADDR) {
nodeTelemetrySensorsMap[TelemetrySensorType_MCP9808] = addr; nodeTelemetrySensorsMap[TelemetrySensorType_MCP9808] = addr;
DEBUG_MSG("MCP9808 sensor found at address 0x%x\n", (uint8_t)addr); DEBUG_MSG("MCP9808 sensor found\n");
}
if (addr == QMC6310_ADDR) {
DEBUG_MSG("QMC6310 3-Axis magnetic sensor found at address 0x%x\n", (uint8_t)addr);
nodeTelemetrySensorsMap[TelemetrySensorType_QMC6310] = addr;
}
if (addr == QMI8658_ADDR) {
DEBUG_MSG("QMI8658 6-Axis inertial measurement sensor found at address 0x%x\n", (uint8_t)addr);
nodeTelemetrySensorsMap[TelemetrySensorType_QMI8658] = addr;
} }
if (addr == SHTC3_ADDR) { if (addr == SHTC3_ADDR) {
DEBUG_MSG("SHTC3 sensor found at address 0x%x\n", (uint8_t)addr); DEBUG_MSG("SHTC3 sensor found\n");
nodeTelemetrySensorsMap[TelemetrySensorType_SHTC3] = addr; nodeTelemetrySensorsMap[TelemetrySensorType_SHTC3] = addr;
} }
if (addr == LPS22HB_ADDR || addr == LPS22HB_ADDR_ALT) { if (addr == LPS22HB_ADDR || addr == LPS22HB_ADDR_ALT) {
DEBUG_MSG("LPS22HB sensor found at address 0x%x\n", (uint8_t)addr); DEBUG_MSG("LPS22HB sensor found\n");
nodeTelemetrySensorsMap[TelemetrySensorType_LPS22] = addr; nodeTelemetrySensorsMap[TelemetrySensorType_LPS22] = addr;
} }
// High rate sensors, will be processed internally
if (addr == QMC6310_ADDR) {
DEBUG_MSG("QMC6310 Highrate 3-Axis magnetic sensor found\n");
nodeTelemetrySensorsMap[TelemetrySensorType_QMC6310] = addr;
}
if (addr == QMI8658_ADDR) {
DEBUG_MSG("QMI8658 Highrate 6-Axis inertial measurement sensor found\n");
nodeTelemetrySensorsMap[TelemetrySensorType_QMI8658] = addr;
}
if (addr == QMC5883L_ADDR) {
DEBUG_MSG("QMC5883L Highrate 3-Axis magnetic sensor found\n");
nodeTelemetrySensorsMap[TelemetrySensorType_QMC5883L] = addr;
}
} else if (err == 4) { } else if (err == 4) {
DEBUG_MSG("Unknow error at address 0x%x\n", addr); DEBUG_MSG("Unknow error at address 0x%x\n", addr);
} }
@ -218,5 +226,5 @@ void scanI2Cdevice(void)
DEBUG_MSG("%i I2C devices found\n",nDevices); DEBUG_MSG("%i I2C devices found\n",nDevices);
} }
#else #else
void scanI2Cdevice(void) {} void scanI2Cdevice(bool partial) {}
#endif #endif

View File

@ -100,7 +100,7 @@ uint32_t serialSinceMsec;
bool pmu_found; bool pmu_found;
// Array map of sensor types (as array index) and i2c address as value we'll find in the i2c scan // Array map of sensor types (as array index) and i2c address as value we'll find in the i2c scan
uint8_t nodeTelemetrySensorsMap[TelemetrySensorType_QMI8658+1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; uint8_t nodeTelemetrySensorsMap[_TelemetrySensorType_MAX + 1] = { 0 }; // one is enough, missing elements will be initialized to 0 anyway.
Router *router = NULL; // Users of router don't care what sort of subclass implements that API Router *router = NULL; // Users of router don't care what sort of subclass implements that API
@ -245,7 +245,7 @@ void setup()
#endif #endif
// We need to scan here to decide if we have a screen for nodeDB.init() // We need to scan here to decide if we have a screen for nodeDB.init()
scanI2Cdevice(); scanI2Cdevice(true);
#ifdef RAK4630 #ifdef RAK4630
// scanEInkDevice(); // scanEInkDevice();
#endif #endif
@ -290,7 +290,7 @@ void setup()
* Repeat the scanning for I2C devices after power initialization or look for 'latecomers'. * Repeat the scanning for I2C devices after power initialization or look for 'latecomers'.
* Boards with an PMU need to be powered on to correctly scan to the device address, such as t-beam-s3-core * Boards with an PMU need to be powered on to correctly scan to the device address, such as t-beam-s3-core
*/ */
scanI2Cdevice(); scanI2Cdevice(false);
// fixed screen override? // fixed screen override?
if (config.display.oled != Config_DisplayConfig_OledType_OLED_AUTO) if (config.display.oled != Config_DisplayConfig_OledType_OLED_AUTO)

View File

@ -26,7 +26,7 @@ extern bool isUSBPowered;
extern ATECCX08A atecc; extern ATECCX08A atecc;
#endif #endif
extern uint8_t nodeTelemetrySensorsMap[TelemetrySensorType_QMI8658+1]; extern uint8_t nodeTelemetrySensorsMap[_TelemetrySensorType_MAX + 1];
extern int TCPPort; // set by Portduino extern int TCPPort; // set by Portduino

View File

@ -33,7 +33,9 @@ typedef enum _TelemetrySensorType {
/* 3-Axis magnetic sensor */ /* 3-Axis magnetic sensor */
TelemetrySensorType_QMC6310 = 9, TelemetrySensorType_QMC6310 = 9,
/* 6-Axis inertial measurement sensor */ /* 6-Axis inertial measurement sensor */
TelemetrySensorType_QMI8658 = 10 TelemetrySensorType_QMI8658 = 10,
/* 3-Axis magnetic sensor */
TelemetrySensorType_QMC5883L = 11
} TelemetrySensorType; } TelemetrySensorType;
/* Struct definitions */ /* Struct definitions */
@ -85,8 +87,8 @@ typedef struct _Telemetry {
/* Helper constants for enums */ /* Helper constants for enums */
#define _TelemetrySensorType_MIN TelemetrySensorType_SENSOR_UNSET #define _TelemetrySensorType_MIN TelemetrySensorType_SENSOR_UNSET
#define _TelemetrySensorType_MAX TelemetrySensorType_QMI8658 #define _TelemetrySensorType_MAX TelemetrySensorType_QMC5883L
#define _TelemetrySensorType_ARRAYSIZE ((TelemetrySensorType)(TelemetrySensorType_QMI8658+1)) #define _TelemetrySensorType_ARRAYSIZE ((TelemetrySensorType)(TelemetrySensorType_QMC5883L+1))
#ifdef __cplusplus #ifdef __cplusplus