diff --git a/boards/tracker-t2000-c.json b/boards/tracker-t2000-c.json new file mode 100644 index 000000000..3c10440c9 --- /dev/null +++ b/boards/tracker-t2000-c.json @@ -0,0 +1,60 @@ +{ + "build": { + "arduino": { + "ldscript": "nrf52840_s140_v7.ld" + }, + "core": "nRF5", + "cpu": "cortex-m4", + "extra_flags": "-DARDUINO_TRACKER_T2000_C -DNRF52840_XXAA", + "f_cpu": "64000000L", + "hwids": [ + ["0x239A", "0x8029"], + ["0x239A", "0x0029"], + ["0x239A", "0x002A"], + ["0x239A", "0x802A"], + ["0x2886", "0x0057"] + ], + "usb_product": "T2000-BOOT", + "mcu": "nrf52840", + "variant": "Seeed_T2000-C", + "bsp": { + "name": "adafruit" + }, + "softdevice": { + "sd_flags": "-DS140", + "sd_name": "s140", + "sd_version": "7.3.0", + "sd_fwid": "0x0123" + }, + "bootloader": { + "settings_addr": "0xFF000" + } + }, + "connectivity": ["bluetooth"], + "debug": { + "jlink_device": "nRF52840_xxAA", + "svd_path": "nrf52840.svd", + "openocd_target": "nrf52840-mdk-rs" + }, + "frameworks": ["arduino"], + "name": "Seeed T2000-C", + "upload": { + "maximum_ram_size": 248832, + "maximum_size": 815104, + "speed": 115200, + "protocol": "nrfutil", + "protocols": [ + "jlink", + "nrfjprog", + "nrfutil", + "stlink", + "cmsis-dap", + "blackmagic" + ], + "use_1200bps_touch": true, + "require_upload_port": true, + "wait_for_upload_port": true + }, + "url": "https://www.seeedstudio.com/", + "vendor": "Seeed Studio" +} diff --git a/src/detect/ScanI2C.cpp b/src/detect/ScanI2C.cpp index 75eabc954..de73d8017 100644 --- a/src/detect/ScanI2C.cpp +++ b/src/detect/ScanI2C.cpp @@ -37,8 +37,9 @@ ScanI2C::FoundDevice ScanI2C::firstKeyboard() const ScanI2C::FoundDevice ScanI2C::firstAccelerometer() const { - ScanI2C::DeviceType types[] = {MPU6050, LIS3DH, BMA423, LSM6DS3, BMX160, STK8BAXX, ICM20948, QMA6100P, BMM150, BMI270}; - return firstOfOrNONE(10, types); + ScanI2C::DeviceType types[] = {MPU6050, LIS3DH, BMA423, LSM6DS3, LSM6DSOX, BMX160, + STK8BAXX, ICM20948, QMA6100P, BMM150, BMI270}; + return firstOfOrNONE(11, types); } ScanI2C::FoundDevice ScanI2C::firstAQI() const diff --git a/src/detect/ScanI2C.h b/src/detect/ScanI2C.h index cc83a8d7b..f549b44ad 100644 --- a/src/detect/ScanI2C.h +++ b/src/detect/ScanI2C.h @@ -47,6 +47,7 @@ class ScanI2C BMA423, BQ24295, LSM6DS3, + LSM6DSOX, TCA9535, TCA9555, VEML7700, diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index 2e00c11ce..71dd10999 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -511,6 +511,9 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) if (registerValue == 0x6A) { type = LSM6DS3; logFoundDevice("LSM6DS3", (uint8_t)addr.address); + } else if (registerValue == 0x6C) { + type = LSM6DSOX; + logFoundDevice("LSM6DSOX", (uint8_t)addr.address); } else { type = QMI8658; logFoundDevice("QMI8658", (uint8_t)addr.address); @@ -548,7 +551,19 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) break; - SCAN_SIMPLE_CASE(LSM6DS3_ADDR, LSM6DS3, "LSM6DS3", (uint8_t)addr.address); + case LSM6DS3_ADDR: + registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x0F), 1); + if (registerValue == 0x6A) { + type = LSM6DS3; + logFoundDevice("LSM6DS3", (uint8_t)addr.address); + } else if (registerValue == 0x6C) { + type = LSM6DSOX; + logFoundDevice("LSM6DSOX", (uint8_t)addr.address); + } else { + type = QMI8658; + logFoundDevice("QMI8658", (uint8_t)addr.address); + } + break; SCAN_SIMPLE_CASE(VEML7700_ADDR, VEML7700, "VEML7700", (uint8_t)addr.address); case TCA9555_ADDR: registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x01), 1); diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 428a64fcf..ab515dffb 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -910,8 +910,17 @@ void NodeDB::installDefaultModuleConfig() moduleConfig.neighbor_info.enabled = false; moduleConfig.has_detection_sensor = true; +#ifdef DETECTION_SENSOR_DEFAULT_PIN + moduleConfig.detection_sensor.enabled = true; + moduleConfig.detection_sensor.monitor_pin = DETECTION_SENSOR_DEFAULT_PIN; + moduleConfig.detection_sensor.detection_trigger_type = + meshtastic_ModuleConfig_DetectionSensorConfig_TriggerType_EITHER_EDGE_ACTIVE_HIGH; + moduleConfig.detection_sensor.use_pullup = true; + strncpy(moduleConfig.detection_sensor.name, "Tamper", sizeof(moduleConfig.detection_sensor.name)); +#else moduleConfig.detection_sensor.enabled = false; moduleConfig.detection_sensor.detection_trigger_type = meshtastic_ModuleConfig_DetectionSensorConfig_TriggerType_LOGIC_HIGH; +#endif moduleConfig.detection_sensor.minimum_broadcast_secs = 45; moduleConfig.has_ambient_lighting = true; diff --git a/src/modules/DetectionSensorModule.cpp b/src/modules/DetectionSensorModule.cpp index ca682b772..ddaef7c89 100644 --- a/src/modules/DetectionSensorModule.cpp +++ b/src/modules/DetectionSensorModule.cpp @@ -64,6 +64,11 @@ int32_t DetectionSensorModule::runOnce() if (moduleConfig.detection_sensor.enabled == false) return disable(); +#ifdef DETECTION_SENSOR_DEFAULT_PIN + if (moduleConfig.detection_sensor.monitor_pin == 0) + moduleConfig.detection_sensor.monitor_pin = DETECTION_SENSOR_DEFAULT_PIN; +#endif + if (firstTime) { #ifdef DETECTION_SENSOR_EN diff --git a/src/motion/AccelerometerThread.h b/src/motion/AccelerometerThread.h index 9724192c2..f2c040d8e 100644 --- a/src/motion/AccelerometerThread.h +++ b/src/motion/AccelerometerThread.h @@ -18,6 +18,7 @@ #include "ICM20948Sensor.h" #include "LIS3DHSensor.h" #include "LSM6DS3Sensor.h" +#include "LSM6DSOSensor.h" #include "MPU6050Sensor.h" #include "MotionSensor.h" #ifdef HAS_QMA6100P @@ -103,6 +104,9 @@ class AccelerometerThread : public concurrency::OSThread case ScanI2C::DeviceType::LSM6DS3: sensor = new LSM6DS3Sensor(device); break; + case ScanI2C::DeviceType::LSM6DSOX: + sensor = new LSM6DSOSensor(device); + break; #ifdef HAS_STK8XXX case ScanI2C::DeviceType::STK8BAXX: sensor = new STK8XXXSensor(device); diff --git a/src/motion/LSM6DSOSensor.cpp b/src/motion/LSM6DSOSensor.cpp new file mode 100644 index 000000000..8b7f02978 --- /dev/null +++ b/src/motion/LSM6DSOSensor.cpp @@ -0,0 +1,31 @@ +#include "LSM6DSOSensor.h" +#include "NodeDB.h" + +#if !defined(ARCH_STM32WL) && !MESHTASTIC_EXCLUDE_I2C && __has_include() + +LSM6DSOSensor::LSM6DSOSensor(ScanI2C::FoundDevice foundDevice) : MotionSensor::MotionSensor(foundDevice) {} + +bool LSM6DSOSensor::init() +{ + if (sensor.begin_I2C(deviceAddress())) { + + sensor.setAccelRange(LSM6DS_ACCEL_RANGE_2_G); + sensor.enableWakeup(config.display.wake_on_tap_or_motion, 1, LSM6DSO_WAKE_THRESH); + + LOG_DEBUG("LSM6DSO init ok"); + return true; + } + LOG_DEBUG("LSM6DSO init failed"); + return false; +} + +int32_t LSM6DSOSensor::runOnce() +{ + if (sensor.shake()) { + wakeScreen(); + return 500; + } + return MOTION_SENSOR_CHECK_INTERVAL_MS; +} + +#endif diff --git a/src/motion/LSM6DSOSensor.h b/src/motion/LSM6DSOSensor.h new file mode 100644 index 000000000..013df53d4 --- /dev/null +++ b/src/motion/LSM6DSOSensor.h @@ -0,0 +1,28 @@ +#pragma once +#ifndef _LSM6DSO_SENSOR_H_ +#define _LSM6DSO_SENSOR_H_ + +#include "MotionSensor.h" + +#if !defined(ARCH_STM32WL) && !MESHTASTIC_EXCLUDE_I2C && __has_include() + +#ifndef LSM6DSO_WAKE_THRESH +#define LSM6DSO_WAKE_THRESH 20 +#endif + +#include + +class LSM6DSOSensor : public MotionSensor +{ + private: + Adafruit_LSM6DSOX sensor; + + public: + explicit LSM6DSOSensor(ScanI2C::FoundDevice foundDevice); + virtual bool init() override; + virtual int32_t runOnce() override; +}; + +#endif + +#endif diff --git a/variants/nrf52840/tracker-t2000-c/platformio.ini b/variants/nrf52840/tracker-t2000-c/platformio.ini new file mode 100644 index 000000000..c2b242bc1 --- /dev/null +++ b/variants/nrf52840/tracker-t2000-c/platformio.ini @@ -0,0 +1,26 @@ +[env:tracker-t2000-c] +custom_meshtastic_support_level = 1 +custom_meshtastic_tags = Seeed + +extends = nrf52840_base +board = tracker-t2000-c +board_level = pr +custom_meshtastic_architecture = nrf52840 +custom_meshtastic_display_name = Seeed SenseCAP T2000-C +custom_meshtastic_actively_supported = true +build_flags = ${nrf52840_base.build_flags} + -Ivariants/nrf52840/tracker-t2000-c + -Isrc/platform/nrf52/softdevice + -Isrc/platform/nrf52/softdevice/nrf52 + -DTRACKER_T2000_C + -DPRIVATE_HW + -DMESHTASTIC_EXCLUDE_CANNEDMESSAGES=1 + -DMESHTASTIC_EXCLUDE_SCREEN=1 + -DMESHTASTIC_EXCLUDE_WIFI=1 +board_build.ldscript = src/platform/nrf52/nrf52840_s140_v7.ld +build_src_filter = ${nrf52_base.build_src_filter} +<../variants/nrf52840/tracker-t2000-c> +lib_deps = + ${nrf52840_base.lib_deps} +debug_tool = jlink +; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) +upload_protocol = nrfutil diff --git a/variants/nrf52840/tracker-t2000-c/variant.cpp b/variants/nrf52840/tracker-t2000-c/variant.cpp new file mode 100644 index 000000000..614c386e6 --- /dev/null +++ b/variants/nrf52840/tracker-t2000-c/variant.cpp @@ -0,0 +1,54 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry All right reserved. + Copyright (c) 2018, Adafruit Industries (adafruit.com) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "variant.h" +#include "nrf.h" +#include "wiring_constants.h" +#include "wiring_digital.h" + +const uint32_t g_ADigitalPinMap[] = { + // P0 + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + + // P1 + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47}; + +void initVariant() +{ + // Main power control + pinMode(PIN_PWR_CTR, OUTPUT); + digitalWrite(PIN_PWR_CTR, HIGH); + + // Accelerometer enable + pinMode(ACC_EN_PIN, OUTPUT); + digitalWrite(ACC_EN_PIN, HIGH); + + // GPS power off at init + pinMode(PIN_GPS_EN, OUTPUT); + digitalWrite(PIN_GPS_EN, LOW); + + // GPS reset low at init + pinMode(PIN_GPS_RESET, OUTPUT); + digitalWrite(PIN_GPS_RESET, LOW); + + // Flash power control + pinMode(nRF_FLASH_POWER_CTR, OUTPUT); + digitalWrite(nRF_FLASH_POWER_CTR, HIGH); +} diff --git a/variants/nrf52840/tracker-t2000-c/variant.h b/variants/nrf52840/tracker-t2000-c/variant.h new file mode 100644 index 000000000..370d180f5 --- /dev/null +++ b/variants/nrf52840/tracker-t2000-c/variant.h @@ -0,0 +1,172 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry All right reserved. + Copyright (c) 2018, Adafruit Industries (adafruit.com) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _VARIANT_TRACKER_T2000_C_ +#define _VARIANT_TRACKER_T2000_C_ + +/** Master clock frequency */ +#define VARIANT_MCK (64000000ul) + +#define USE_LFXO // Board uses 32khz crystal for LF + +/*---------------------------------------------------------------------------- + * Headers + *----------------------------------------------------------------------------*/ + +#include "WVariant.h" + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +#define SERIAL_PRINT_PORT 0 + +// Number of pins defined in PinDescription array +#define PINS_COUNT (48) +#define NUM_DIGITAL_PINS (48) +#define NUM_ANALOG_INPUTS (6) +#define NUM_ANALOG_OUTPUTS (0) + +// Use the native nrf52 usb power detection +#define NRF_APM + +// Power control +#define PIN_PWR_CTR (0 + 12) // P0.12, main power control + +// LEDs (active HIGH) +#define PIN_LED1 (32 + 2) // P1.02, Green +#define PIN_LED2 (32 + 3) // P1.03, Blue +#define PIN_LED3 (0 + 19) // P0.19, Red +#define LED_GREEN PIN_LED1 +#define LED_BLUE PIN_LED2 +#define LED_RED PIN_LED3 +#define LED_POWER PIN_LED1 +#define LED_STATE_ON 1 // State when LED is lit + +// Button +#define BUTTON_PIN (0 + 11) // P0.11, USER_BTN +#define BUTTON_ACTIVE_LOW false +#define BUTTON_ACTIVE_PULLUP false +#define BUTTON_SENSE_TYPE 0x5 // enable input pull-down + +// Theft protection / tamper switch +#define TP_BUTTON_PIN (0 + 8) // P0.08 + +// Default detection sensor pin: tamper switch +#define DETECTION_SENSOR_DEFAULT_PIN TP_BUTTON_PIN + +// I2C +#define HAS_WIRE 1 +#define WIRE_INTERFACES_COUNT 1 +#define PIN_WIRE_SDA (0 + 6) // P0.06 +#define PIN_WIRE_SCL (0 + 5) // P0.05 +#define I2C_NO_RESCAN + +// Accelerometer enable (used in initVariant) +#define ACC_EN_PIN (0 + 15) // P0.15 + +/* + * Serial interfaces + */ +// Serial1: GPS (GNSS) +#define PIN_SERIAL1_RX (0 + 26) // P0.26 +#define PIN_SERIAL1_TX (0 + 27) // P0.27 + +/* + * SPI Interfaces (LoRa SX1262) + */ +#define SPI_INTERFACES_COUNT 1 + +#define PIN_SPI_MISO (0 + 3) // P0.03 +#define PIN_SPI_MOSI (0 + 28) // P0.28 +#define PIN_SPI_SCK (0 + 30) // P0.30 +#define PIN_SPI_NSS (32 + 14) // P1.14 + +// LoRa SX1262 +#define LORA_RESET (32 + 7) // P1.07, RST +#define LORA_DIO1 (0 + 7) // P0.07, IRQ/DIO1 +#define LORA_DIO2 (32 + 10) // P1.10, BUSY +#define LORA_SCK PIN_SPI_SCK +#define LORA_MISO PIN_SPI_MISO +#define LORA_MOSI PIN_SPI_MOSI +#define LORA_CS PIN_SPI_NSS + +// Supported modules list +#define USE_SX1262 + +#define SX126X_CS LORA_CS +#define SX126X_DIO1 LORA_DIO1 +#define SX126X_BUSY LORA_DIO2 +#define SX126X_RESET LORA_RESET +#define SX126X_DIO2_AS_RF_SWITCH +#define SX126X_DIO3_TCXO_VOLTAGE 1.8 + +// GPS L76K +#define HAS_GPS 1 +#define GPS_L76K +#define GPS_RX_PIN PIN_SERIAL1_RX +#define GPS_TX_PIN PIN_SERIAL1_TX + +#define GPS_BAUDRATE 9600 + +#define PIN_GPS_EN (32 + 5) // P1.05, GNSS power control +#define GPS_EN_ACTIVE HIGH + +#define PIN_GPS_RESET (32 + 6) // P1.06, GNSS reset +#define GPS_RESET_MODE HIGH + +#define PIN_GPS_STANDBY (32 + 9) // P1.09, GNSS wakeup/standby + +// Battery +#define BATTERY_PIN (0 + 31) // P0.31/AIN7, BAT_ADC +#define ADC_CTRL (0 + 2) // P0.02, BAT_ADC enable +#define ADC_CTRL_ENABLED HIGH +#define BATTERY_IMMUTABLE +#define ADC_MULTIPLIER (2.0F) + +#define ADC_RESOLUTION 14 +#define BATTERY_SENSE_RESOLUTION_BITS 12 + +#undef AREF_VOLTAGE +#define AREF_VOLTAGE 3.0 +#define VBAT_AR_INTERNAL AR_INTERNAL_3_0 + +#define OCV_ARRAY 4000, 3951, 3910, 3867, 3772, 3687, 3593, 3519, 3463, 3297, 3100 + +#define nRF_FLASH_POWER_CTR (32 + 13) // P1.13 + +#define HAS_SCREEN 0 + +// Enable Traffic Management Module +// NRF52840 has 256KB RAM - 1024 entries uses ~10KB +#ifndef HAS_TRAFFIC_MANAGEMENT +#define HAS_TRAFFIC_MANAGEMENT 1 +#endif +#ifndef TRAFFIC_MANAGEMENT_CACHE_SIZE +#define TRAFFIC_MANAGEMENT_CACHE_SIZE 1024 +#endif + +#ifdef __cplusplus +} +#endif + +/*---------------------------------------------------------------------------- + * Arduino objects - C++ only + *----------------------------------------------------------------------------*/ + +#endif // _VARIANT_TRACKER_T2000_C_