From 897878307d09f234ff75bead19314329c24a21c3 Mon Sep 17 00:00:00 2001 From: liquidraver <504870+liquidraver@users.noreply.github.com> Date: Thu, 16 Apr 2026 09:35:09 +0200 Subject: [PATCH] Revert "rak ADC tuning" This reverts commit 5369e5d3d8a516c84be4bb0ff677db2db19329a6. --- .../nrf52840/rak3401_1watt/rak3401_1watt.dts | 437 +++++++------- .../boards/nrf52840/rak4631/board.overlay | 3 +- .../rak_wismesh_tag/rak_wismesh_tag.dts | 561 +++++++++--------- 3 files changed, 501 insertions(+), 500 deletions(-) diff --git a/zephcore/boards/nrf52840/rak3401_1watt/rak3401_1watt.dts b/zephcore/boards/nrf52840/rak3401_1watt/rak3401_1watt.dts index 701d15a..6074818 100644 --- a/zephcore/boards/nrf52840/rak3401_1watt/rak3401_1watt.dts +++ b/zephcore/boards/nrf52840/rak3401_1watt/rak3401_1watt.dts @@ -1,218 +1,219 @@ -/* - * RAK3401 1W — nRF52840 + SX1262 + SKY66122 1W PA (WisMesh Booster) - * Copyright (c) 2025 ZephCore - * - * SPDX-License-Identifier: Apache-2.0 - * - * Hardware: - * - nRF52840 SoC with BLE 5 - * - SX1262 LoRa radio on RAK13302 IO-slot module (30 dBm, SKY66122 FEM) - * DIO2 as RF switch, TCXO 1.8V via DIO3 - * - RAK1910 GPS module (optional) on UART0 at 9600 baud - * - Battery ADC on AIN3 (P0.05) - * - I2C0 for WisBlock sensors (auto-detected) - * - LEDs: GREEN=P1.03 (TX, active HIGH), BLUE=P1.04 (status, active HIGH) - * - QSPI flash disabled (pins conflict with LoRa SPI bus) - * - SoftDevice s140 v6.1.1, UF2 bootloader - * - * Pin mappings (from Meshtastic/MeshCore variant.h): - * - LoRa SPI: SCK=P0.03, MOSI=P0.30, MISO=P0.29, CS=P0.26 - * - LoRa ctl: DIO1=P0.10 (NFC2), BUSY=P0.09 (NFC1), RESET=P0.04 - * - FEM: SX126X_POWER_EN=P0.21 (SKY66122 CSD+CPS) - * - 3V3_S: WB_IO2=P1.02 (3V3_S rail, powers GPS + PA boost) - * - I2C: SDA=P0.13, SCL=P0.14 - * - GPS: TX=P0.16, RX=P0.15 - * - Battery: AIN3=P0.05 - */ - -/dts-v1/; -#include -#include "rak3401_1watt-pinctrl.dtsi" -#include -#include - -/ { - model = "RAK3401 1W"; - compatible = "rak,rak3401-1watt"; - - chosen { - zephyr,sram = &sram0; - zephyr,flash = &flash0; - zephyr,code-partition = &code_partition; - zephyr,console = &cdc_acm_uart; - zephyr,shell-uart = &cdc_acm_uart; - }; - - aliases { - lora0 = &lora; - led0 = &led_green; - led1 = &led_blue; - lora-tx-led = &led_green; - watchdog0 = &wdt0; - }; - - /* ---- LEDs (active HIGH per variant.h LED_STATE_ON=HIGH) ---- */ - leds { - compatible = "gpio-leds"; - - led_green: led_0 { - gpios = <&gpio1 3 GPIO_ACTIVE_HIGH>; - label = "Green LED"; - }; - - led_blue: led_1 { - gpios = <&gpio1 4 GPIO_ACTIVE_HIGH>; - label = "Blue LED"; - }; - }; - - /* ---- Power control ---- */ - - /* 3V3_S rail — must be HIGH for GPS and IO-slot peripherals. - * WB_IO2 (P1.02) doubles as GPS_RESET on the RAK1910 slot, - * so it must remain HIGH when GPS is active. */ - v3v3s_enable: v3v3s-enable { - compatible = "regulator-fixed"; - regulator-name = "v3v3s-enable"; - enable-gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>; - regulator-boot-on; - }; - - /* SKY66122 FEM enable — must be HIGH before SX1262 can transmit. - * SX126X_POWER_EN = P0.21 (IO3 on WisBlock base). */ - lora_pwr_enable: lora-pwr-enable { - compatible = "regulator-fixed"; - regulator-name = "lora-pwr-enable"; - enable-gpios = <&gpio0 21 GPIO_ACTIVE_HIGH>; - regulator-boot-on; - startup-delay-us = <10000>; - }; - - /* ---- Battery ADC ---- */ - /* P0.05 (AIN3), 150K+150K divider — same circuit as RAK4631. - * mV = raw * mult / 4096; 7200 = 3.6 V FS at pin × 2 (see thinknode_m3.dts). */ - zephyr,user { - io-channels = <&adc 3>; - vbat-mv-multiplier = <7200>; - }; -}; - -/* ---- SoC configuration ---- */ - -®0 { - status = "okay"; -}; - -®1 { - regulator-initial-mode = ; -}; - -&adc { - status = "okay"; - #address-cells = <1>; - #size-cells = <0>; - - /* Battery voltage on P0.05 (AIN3) */ - channel@3 { - reg = <3>; - zephyr,gain = "ADC_GAIN_1_6"; - zephyr,reference = "ADC_REF_INTERNAL"; - zephyr,acquisition-time = ; - zephyr,input-positive = ; - zephyr,resolution = <12>; - }; -}; - -/* Enable NFC1 (P0.09) and NFC2 (P0.10) as plain GPIOs. - * P0.09 → SX1262 BUSY, P0.10 → SX1262 DIO1. */ -&uicr { - nfct-pins-as-gpios; -}; - -&gpiote { - status = "okay"; -}; - -&gpio0 { - status = "okay"; -}; - -&gpio1 { - status = "okay"; -}; - -/* ---- GPS on UART0 (RAK1910 u-blox MAX-7Q, 9600 baud) ---- */ -&uart0 { - compatible = "nordic,nrf-uarte"; - status = "okay"; - current-speed = <9600>; - pinctrl-0 = <&uart0_default>; - pinctrl-1 = <&uart0_sleep>; - pinctrl-names = "default", "sleep"; - - gnss: gnss-nmea-generic { - compatible = "gnss-nmea-generic"; - }; -}; - -/* ---- I2C0 for WisBlock sensors ---- */ -&i2c0 { - compatible = "nordic,nrf-twim"; - status = "okay"; - clock-frequency = ; - pinctrl-0 = <&i2c0_default>; - pinctrl-1 = <&i2c0_sleep>; - pinctrl-names = "default", "sleep"; - - /* All supported environment & power sensors — auto-detected at runtime */ - #include "../../common/sensors-i2c.dtsi" -}; - -/* ---- SPI1 for LoRa SX1262 (RAK13302 IO-slot module) ---- */ -&spi1 { - compatible = "nordic,nrf-spim"; - status = "okay"; - pinctrl-0 = <&spi1_default>; - pinctrl-1 = <&spi1_sleep>; - pinctrl-names = "default", "sleep"; - cs-gpios = <&gpio0 26 GPIO_ACTIVE_LOW>; /* P0.26 LORA_CS */ - - lora: lora@0 { - compatible = "semtech,sx1262"; - reg = <0>; - spi-max-frequency = <8000000>; - - /* LoRa control pins */ - reset-gpios = <&gpio0 4 GPIO_ACTIVE_LOW>; /* P0.04 WB_IO4 */ - busy-gpios = <&gpio0 9 GPIO_ACTIVE_HIGH>; /* P0.09 NFC1 */ - dio1-gpios = <&gpio0 10 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>; /* P0.10 NFC2 */ - - /* DIO2 drives SKY66122 CTX (TX/RX switch) */ - dio2-tx-enable; - - /* TCXO 1.8V reference via DIO3 */ - dio3-tcxo-voltage = ; - tcxo-power-startup-delay-ms = <5>; - - /* RX boosted LNA for improved sensitivity */ - rx-boosted; - }; -}; - -/* ---- QSPI flash — disabled (pins shared with LoRa SPI) ---- */ -&qspi { - status = "disabled"; -}; - -/* ---- USB CDC for console/CLI ---- */ -zephyr_udc0: &usbd { - compatible = "nordic,nrf-usbd"; - status = "okay"; - - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; -}; - -/* ---- Flash partitions (SoftDevice v6, app@0x26000) ---- */ -#include "../../common/nrf52_partitions_sdv6.dtsi" +/* + * RAK3401 1W — nRF52840 + SX1262 + SKY66122 1W PA (WisMesh Booster) + * Copyright (c) 2025 ZephCore + * + * SPDX-License-Identifier: Apache-2.0 + * + * Hardware: + * - nRF52840 SoC with BLE 5 + * - SX1262 LoRa radio on RAK13302 IO-slot module (30 dBm, SKY66122 FEM) + * DIO2 as RF switch, TCXO 1.8V via DIO3 + * - RAK1910 GPS module (optional) on UART0 at 9600 baud + * - Battery ADC on AIN3 (P0.05) + * - I2C0 for WisBlock sensors (auto-detected) + * - LEDs: GREEN=P1.03 (TX, active HIGH), BLUE=P1.04 (status, active HIGH) + * - QSPI flash disabled (pins conflict with LoRa SPI bus) + * - SoftDevice s140 v6.1.1, UF2 bootloader + * + * Pin mappings (from Meshtastic/MeshCore variant.h): + * - LoRa SPI: SCK=P0.03, MOSI=P0.30, MISO=P0.29, CS=P0.26 + * - LoRa ctl: DIO1=P0.10 (NFC2), BUSY=P0.09 (NFC1), RESET=P0.04 + * - FEM: SX126X_POWER_EN=P0.21 (SKY66122 CSD+CPS) + * - 3V3_S: WB_IO2=P1.02 (3V3_S rail, powers GPS + PA boost) + * - I2C: SDA=P0.13, SCL=P0.14 + * - GPS: TX=P0.16, RX=P0.15 + * - Battery: AIN3=P0.05 + */ + +/dts-v1/; +#include +#include "rak3401_1watt-pinctrl.dtsi" +#include +#include + +/ { + model = "RAK3401 1W"; + compatible = "rak,rak3401-1watt"; + + chosen { + zephyr,sram = &sram0; + zephyr,flash = &flash0; + zephyr,code-partition = &code_partition; + zephyr,console = &cdc_acm_uart; + zephyr,shell-uart = &cdc_acm_uart; + }; + + aliases { + lora0 = &lora; + led0 = &led_green; + led1 = &led_blue; + lora-tx-led = &led_green; + watchdog0 = &wdt0; + }; + + /* ---- LEDs (active HIGH per variant.h LED_STATE_ON=HIGH) ---- */ + leds { + compatible = "gpio-leds"; + + led_green: led_0 { + gpios = <&gpio1 3 GPIO_ACTIVE_HIGH>; + label = "Green LED"; + }; + + led_blue: led_1 { + gpios = <&gpio1 4 GPIO_ACTIVE_HIGH>; + label = "Blue LED"; + }; + }; + + /* ---- Power control ---- */ + + /* 3V3_S rail — must be HIGH for GPS and IO-slot peripherals. + * WB_IO2 (P1.02) doubles as GPS_RESET on the RAK1910 slot, + * so it must remain HIGH when GPS is active. */ + v3v3s_enable: v3v3s-enable { + compatible = "regulator-fixed"; + regulator-name = "v3v3s-enable"; + enable-gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>; + regulator-boot-on; + }; + + /* SKY66122 FEM enable — must be HIGH before SX1262 can transmit. + * SX126X_POWER_EN = P0.21 (IO3 on WisBlock base). */ + lora_pwr_enable: lora-pwr-enable { + compatible = "regulator-fixed"; + regulator-name = "lora-pwr-enable"; + enable-gpios = <&gpio0 21 GPIO_ACTIVE_HIGH>; + regulator-boot-on; + startup-delay-us = <10000>; + }; + + /* ---- Battery ADC ---- */ + /* P0.05 (AIN3), 150K+150K divider — same circuit as RAK4631. + * Arduino ADC_MULTIPLIER=1.73, AREF=3.0V: + * vbat-mv-multiplier = round(3 * 1.73 * 1.187 * 1000) = 6161 */ + zephyr,user { + io-channels = <&adc 3>; + vbat-mv-multiplier = <6161>; + }; +}; + +/* ---- SoC configuration ---- */ + +®0 { + status = "okay"; +}; + +®1 { + regulator-initial-mode = ; +}; + +&adc { + status = "okay"; + #address-cells = <1>; + #size-cells = <0>; + + /* Battery voltage on P0.05 (AIN3) */ + channel@3 { + reg = <3>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; + zephyr,resolution = <12>; + }; +}; + +/* Enable NFC1 (P0.09) and NFC2 (P0.10) as plain GPIOs. + * P0.09 → SX1262 BUSY, P0.10 → SX1262 DIO1. */ +&uicr { + nfct-pins-as-gpios; +}; + +&gpiote { + status = "okay"; +}; + +&gpio0 { + status = "okay"; +}; + +&gpio1 { + status = "okay"; +}; + +/* ---- GPS on UART0 (RAK1910 u-blox MAX-7Q, 9600 baud) ---- */ +&uart0 { + compatible = "nordic,nrf-uarte"; + status = "okay"; + current-speed = <9600>; + pinctrl-0 = <&uart0_default>; + pinctrl-1 = <&uart0_sleep>; + pinctrl-names = "default", "sleep"; + + gnss: gnss-nmea-generic { + compatible = "gnss-nmea-generic"; + }; +}; + +/* ---- I2C0 for WisBlock sensors ---- */ +&i2c0 { + compatible = "nordic,nrf-twim"; + status = "okay"; + clock-frequency = ; + pinctrl-0 = <&i2c0_default>; + pinctrl-1 = <&i2c0_sleep>; + pinctrl-names = "default", "sleep"; + + /* All supported environment & power sensors — auto-detected at runtime */ + #include "../../common/sensors-i2c.dtsi" +}; + +/* ---- SPI1 for LoRa SX1262 (RAK13302 IO-slot module) ---- */ +&spi1 { + compatible = "nordic,nrf-spim"; + status = "okay"; + pinctrl-0 = <&spi1_default>; + pinctrl-1 = <&spi1_sleep>; + pinctrl-names = "default", "sleep"; + cs-gpios = <&gpio0 26 GPIO_ACTIVE_LOW>; /* P0.26 LORA_CS */ + + lora: lora@0 { + compatible = "semtech,sx1262"; + reg = <0>; + spi-max-frequency = <8000000>; + + /* LoRa control pins */ + reset-gpios = <&gpio0 4 GPIO_ACTIVE_LOW>; /* P0.04 WB_IO4 */ + busy-gpios = <&gpio0 9 GPIO_ACTIVE_HIGH>; /* P0.09 NFC1 */ + dio1-gpios = <&gpio0 10 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>; /* P0.10 NFC2 */ + + /* DIO2 drives SKY66122 CTX (TX/RX switch) */ + dio2-tx-enable; + + /* TCXO 1.8V reference via DIO3 */ + dio3-tcxo-voltage = ; + tcxo-power-startup-delay-ms = <5>; + + /* RX boosted LNA for improved sensitivity */ + rx-boosted; + }; +}; + +/* ---- QSPI flash — disabled (pins shared with LoRa SPI) ---- */ +&qspi { + status = "disabled"; +}; + +/* ---- USB CDC for console/CLI ---- */ +zephyr_udc0: &usbd { + compatible = "nordic,nrf-usbd"; + status = "okay"; + + cdc_acm_uart: cdc_acm_uart { + compatible = "zephyr,cdc-acm-uart"; + }; +}; + +/* ---- Flash partitions (SoftDevice v6, app@0x26000) ---- */ +#include "../../common/nrf52_partitions_sdv6.dtsi" diff --git a/zephcore/boards/nrf52840/rak4631/board.overlay b/zephcore/boards/nrf52840/rak4631/board.overlay index b222848..5925715 100644 --- a/zephcore/boards/nrf52840/rak4631/board.overlay +++ b/zephcore/boards/nrf52840/rak4631/board.overlay @@ -76,8 +76,7 @@ / { zephyr,user { io-channels = <&adc 3>; - /* mV = raw * mult / 4096; 7200 = 3.6 V FS at pin × 2 (2:1 divider), same as thinknode_m3 */ - vbat-mv-multiplier = <7200>; + vbat-mv-multiplier = <6161>; /* matches RAK4631 divider + SAADC ref */ }; }; diff --git a/zephcore/boards/nrf52840/rak_wismesh_tag/rak_wismesh_tag.dts b/zephcore/boards/nrf52840/rak_wismesh_tag/rak_wismesh_tag.dts index 3223517..b031944 100644 --- a/zephcore/boards/nrf52840/rak_wismesh_tag/rak_wismesh_tag.dts +++ b/zephcore/boards/nrf52840/rak_wismesh_tag/rak_wismesh_tag.dts @@ -1,280 +1,281 @@ -/* - * RAK WisMesh Tag — nRF52840 + SX1262 (card-sized GPS tracker) - * Copyright (c) 2025 ZephCore - * - * SPDX-License-Identifier: Apache-2.0 - * - * Hardware: - * - nRF52840 SoC with BLE 5 - * - SX1262 LoRa radio (DIO2 as RF switch, TCXO 1.8V via DIO3) - * - AT6558R GNSS on UART0 at 9600 baud - * - LIS2DH 3-axis accelerometer on I2C0 - * - 1000 mAh battery with ADC on AIN3 (P0.05) - * - Buzzer on PWM0 (P0.21) - * - LEDs: GREEN=P1.03 (TX, active HIGH), BLUE=P1.04 (status, active HIGH) - * - User button on P0.09 (NFC1, active LOW) - * - Board power enable on P0.12 - * - No display, no QSPI flash - * - IP66 sealed, pogo-pin USB interface - * - * Pin mappings (from Arduino MeshCore variant.h): - * - LoRa SPI: SCK=P1.11, MOSI=P1.12, MISO=P1.13, CS=P1.10 - * - LoRa ctl: DIO1=P1.15, BUSY=P1.14, RESET=P1.06, PWR_EN=P1.05 - * - I2C: SDA=P0.25, SCL=P0.24 - * - GPS: TX=P0.16, RX=P0.15, EN=P1.02, PPS=P0.17 - */ - -/dts-v1/; -#include -#include "rak_wismesh_tag-pinctrl.dtsi" -#include -#include -#include -#include - -/ { - model = "RAK WisMesh Tag"; - compatible = "rak,wismesh-tag"; - - chosen { - zephyr,sram = &sram0; - zephyr,flash = &flash0; - zephyr,code-partition = &code_partition; - zephyr,console = &cdc_acm_uart; - zephyr,shell-uart = &cdc_acm_uart; - }; - - aliases { - lora0 = &lora; - led0 = &led_green; - led1 = &led_blue; - lora-tx-led = &led_green; - sw0 = &user_button; - watchdog0 = &wdt0; - buzzer = &buzzer; - gps-enable = &gps_enable_pin; - }; - - /* ---- LEDs (active HIGH per Arduino LED_STATE_ON=HIGH) ---- */ - leds { - compatible = "gpio-leds"; - - led_green: led_0 { - gpios = <&gpio1 3 GPIO_ACTIVE_HIGH>; - label = "Green LED"; - }; - - led_blue: led_1 { - gpios = <&gpio1 4 GPIO_ACTIVE_HIGH>; - label = "Blue LED"; - }; - }; - - /* ---- Button (P0.09/NFC1, active LOW with pull-up) ---- */ - buttons: buttons { - compatible = "gpio-keys"; - - user_button: button_0 { - gpios = <&gpio0 9 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; - zephyr,code = ; - label = "User Button"; - }; - }; - - /* Input filter: long-press (1000ms) */ - user_btn_longpress { - compatible = "zephyr,input-longpress"; - input = <&buttons>; - input-codes = ; - short-codes = ; - long-codes = ; - long-delay-ms = <1000>; - }; - - /* Input filter: multi-tap - * 1 tap → KEY_1 = (reserved / next page if display added) - * 2 taps → KEY_B = flood advert - * 3 taps → KEY_D = buzzer mute toggle - * 4 taps → KEY_C = GPS on/off - * 5 taps → KEY_E = LED heartbeat toggle */ - user_btn_multitap { - compatible = "zephcore,input-multi-tap"; - input-codes = ; - tap-codes = ; - tap-delay-ms = <400>; - }; - - /* ---- Power control ---- */ - - /* Board power enable — must be HIGH for peripherals */ - pwr_enable: pwr-enable { - compatible = "regulator-fixed"; - regulator-name = "pwr-enable"; - enable-gpios = <&gpio0 12 GPIO_ACTIVE_HIGH>; - regulator-boot-on; - }; - - /* LoRa radio power enable — must be HIGH before SX1262 can communicate */ - lora_pwr_enable: lora-pwr-enable { - compatible = "regulator-fixed"; - regulator-name = "lora-pwr-enable"; - enable-gpios = <&gpio1 5 GPIO_ACTIVE_HIGH>; - regulator-boot-on; - startup-delay-us = <10000>; - }; - - /* GPS power control */ - gps_en: gps-enable { - compatible = "gpio-leds"; - gps_enable_pin: gps_enable { - gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>; - label = "GPS Enable"; - }; - }; - - /* ---- Battery ADC ---- */ - /* P0.05 (AIN3), 150k+150k divider (same net as RAK4631). GAIN_1_6 + internal ref. - * mV = raw * mult / 4096; mult 7200 = 3.6 V full-scale at pin × 2 (see thinknode_m3.dts). */ - zephyr,user { - io-channels = <&adc 3>; - vbat-mv-multiplier = <7200>; - }; - - /* ---- Buzzer on PWM0 ---- */ - pwmbuzzer { - compatible = "pwm-leds"; - buzzer: buzzer { - pwms = <&pwm0 0 PWM_MSEC(20) PWM_POLARITY_NORMAL>; - }; - }; -}; - -/* ---- SoC configuration ---- */ - -®0 { - status = "okay"; -}; - -®1 { - regulator-initial-mode = ; -}; - -&adc { - status = "okay"; - #address-cells = <1>; - #size-cells = <0>; - - /* Battery voltage on P0.05 (AIN3) */ - channel@3 { - reg = <3>; - zephyr,gain = "ADC_GAIN_1_6"; - zephyr,reference = "ADC_REF_INTERNAL"; - zephyr,acquisition-time = ; - zephyr,input-positive = ; - zephyr,resolution = <12>; - }; -}; - -&uicr { - nfct-pins-as-gpios; -}; - -&gpiote { - status = "okay"; -}; - -&gpio0 { - status = "okay"; -}; - -&gpio1 { - status = "okay"; -}; - -/* ---- PWM0 for buzzer ---- */ -&pwm0 { - status = "okay"; - pinctrl-0 = <&pwm0_default>; - pinctrl-1 = <&pwm0_sleep>; - pinctrl-names = "default", "sleep"; -}; - -/* ---- GPS on UART0 (AT6558R, 9600 baud) ---- - * Uses luatos,air530z driver for NMEA with power control. - * GPS power controlled via on-off-gpios (P1.02 = GPS_EN). */ -&uart0 { - compatible = "nordic,nrf-uarte"; - status = "okay"; - current-speed = <9600>; - pinctrl-0 = <&uart0_default>; - pinctrl-1 = <&uart0_sleep>; - pinctrl-names = "default", "sleep"; - - gnss: gnss { - compatible = "luatos,air530z"; - on-off-gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>; - }; -}; - -/* ---- I2C0 for sensors ---- */ -&i2c0 { - compatible = "nordic,nrf-twim"; - status = "okay"; - clock-frequency = ; - pinctrl-0 = <&i2c0_default>; - pinctrl-1 = <&i2c0_sleep>; - pinctrl-names = "default", "sleep"; - - /* All supported environment & power sensors — auto-detected at runtime */ - #include "../../common/sensors-i2c.dtsi" -}; - -/* ---- SPI2 for LoRa SX1262 ---- */ -&spi2 { - compatible = "nordic,nrf-spim"; - status = "okay"; - pinctrl-0 = <&spi2_default>; - pinctrl-1 = <&spi2_sleep>; - pinctrl-names = "default", "sleep"; - cs-gpios = <&gpio1 10 GPIO_ACTIVE_LOW>; /* P1.10 (Arduino 42) LORA_CS */ - - lora: lora@0 { - compatible = "semtech,sx1262"; - reg = <0>; - spi-max-frequency = <8000000>; - - /* LoRa control pins */ - reset-gpios = <&gpio1 6 GPIO_ACTIVE_LOW>; /* P1.06 (Arduino 38) */ - busy-gpios = <&gpio1 14 GPIO_ACTIVE_HIGH>; /* P1.14 (Arduino 46) */ - dio1-gpios = <&gpio1 15 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>; /* P1.15 (Arduino 47) */ - - /* DIO2 drives RF switch for TX */ - dio2-tx-enable; - - /* TCXO voltage 1.8V via DIO3 */ - dio3-tcxo-voltage = ; - tcxo-power-startup-delay-ms = <5>; - - /* RX boosted mode for better sensitivity */ - rx-boosted; - }; -}; - -/* ---- QSPI Flash — not present on WisMesh Tag ---- */ -&qspi { - status = "disabled"; -}; - -/* ---- USB CDC for console/CLI ---- */ -zephyr_udc0: &usbd { - compatible = "nordic,nrf-usbd"; - status = "okay"; - - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; -}; - -/* ---- Flash partitions (SoftDevice v6, app@0x26000) ---- */ -#include "../../common/nrf52_partitions_sdv6.dtsi" -#include "../../common/nrf52_wakeup.dtsi" +/* + * RAK WisMesh Tag — nRF52840 + SX1262 (card-sized GPS tracker) + * Copyright (c) 2025 ZephCore + * + * SPDX-License-Identifier: Apache-2.0 + * + * Hardware: + * - nRF52840 SoC with BLE 5 + * - SX1262 LoRa radio (DIO2 as RF switch, TCXO 1.8V via DIO3) + * - AT6558R GNSS on UART0 at 9600 baud + * - LIS2DH 3-axis accelerometer on I2C0 + * - 1000 mAh battery with ADC on AIN3 (P0.05) + * - Buzzer on PWM0 (P0.21) + * - LEDs: GREEN=P1.03 (TX, active HIGH), BLUE=P1.04 (status, active HIGH) + * - User button on P0.09 (NFC1, active LOW) + * - Board power enable on P0.12 + * - No display, no QSPI flash + * - IP66 sealed, pogo-pin USB interface + * + * Pin mappings (from Arduino MeshCore variant.h): + * - LoRa SPI: SCK=P1.11, MOSI=P1.12, MISO=P1.13, CS=P1.10 + * - LoRa ctl: DIO1=P1.15, BUSY=P1.14, RESET=P1.06, PWR_EN=P1.05 + * - I2C: SDA=P0.25, SCL=P0.24 + * - GPS: TX=P0.16, RX=P0.15, EN=P1.02, PPS=P0.17 + */ + +/dts-v1/; +#include +#include "rak_wismesh_tag-pinctrl.dtsi" +#include +#include +#include +#include + +/ { + model = "RAK WisMesh Tag"; + compatible = "rak,wismesh-tag"; + + chosen { + zephyr,sram = &sram0; + zephyr,flash = &flash0; + zephyr,code-partition = &code_partition; + zephyr,console = &cdc_acm_uart; + zephyr,shell-uart = &cdc_acm_uart; + }; + + aliases { + lora0 = &lora; + led0 = &led_green; + led1 = &led_blue; + lora-tx-led = &led_green; + sw0 = &user_button; + watchdog0 = &wdt0; + buzzer = &buzzer; + gps-enable = &gps_enable_pin; + }; + + /* ---- LEDs (active HIGH per Arduino LED_STATE_ON=HIGH) ---- */ + leds { + compatible = "gpio-leds"; + + led_green: led_0 { + gpios = <&gpio1 3 GPIO_ACTIVE_HIGH>; + label = "Green LED"; + }; + + led_blue: led_1 { + gpios = <&gpio1 4 GPIO_ACTIVE_HIGH>; + label = "Blue LED"; + }; + }; + + /* ---- Button (P0.09/NFC1, active LOW with pull-up) ---- */ + buttons: buttons { + compatible = "gpio-keys"; + + user_button: button_0 { + gpios = <&gpio0 9 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + zephyr,code = ; + label = "User Button"; + }; + }; + + /* Input filter: long-press (1000ms) */ + user_btn_longpress { + compatible = "zephyr,input-longpress"; + input = <&buttons>; + input-codes = ; + short-codes = ; + long-codes = ; + long-delay-ms = <1000>; + }; + + /* Input filter: multi-tap + * 1 tap → KEY_1 = (reserved / next page if display added) + * 2 taps → KEY_B = flood advert + * 3 taps → KEY_D = buzzer mute toggle + * 4 taps → KEY_C = GPS on/off + * 5 taps → KEY_E = LED heartbeat toggle */ + user_btn_multitap { + compatible = "zephcore,input-multi-tap"; + input-codes = ; + tap-codes = ; + tap-delay-ms = <400>; + }; + + /* ---- Power control ---- */ + + /* Board power enable — must be HIGH for peripherals */ + pwr_enable: pwr-enable { + compatible = "regulator-fixed"; + regulator-name = "pwr-enable"; + enable-gpios = <&gpio0 12 GPIO_ACTIVE_HIGH>; + regulator-boot-on; + }; + + /* LoRa radio power enable — must be HIGH before SX1262 can communicate */ + lora_pwr_enable: lora-pwr-enable { + compatible = "regulator-fixed"; + regulator-name = "lora-pwr-enable"; + enable-gpios = <&gpio1 5 GPIO_ACTIVE_HIGH>; + regulator-boot-on; + startup-delay-us = <10000>; + }; + + /* GPS power control */ + gps_en: gps-enable { + compatible = "gpio-leds"; + gps_enable_pin: gps_enable { + gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>; + label = "GPS Enable"; + }; + }; + + /* ---- Battery ADC ---- */ + /* P0.05 (AIN3), same divider circuit as RAK4631 + * Arduino ADC_MULTIPLIER = (3 * 1.73 * 1.187 * 1000) ≈ 6161, + * applied to 12-bit average with default ref (GAIN_1_6 + 0.6V internal = 3.6V FS). */ + zephyr,user { + io-channels = <&adc 3>; + vbat-mv-multiplier = <6161>; + }; + + /* ---- Buzzer on PWM0 ---- */ + pwmbuzzer { + compatible = "pwm-leds"; + buzzer: buzzer { + pwms = <&pwm0 0 PWM_MSEC(20) PWM_POLARITY_NORMAL>; + }; + }; +}; + +/* ---- SoC configuration ---- */ + +®0 { + status = "okay"; +}; + +®1 { + regulator-initial-mode = ; +}; + +&adc { + status = "okay"; + #address-cells = <1>; + #size-cells = <0>; + + /* Battery voltage on P0.05 (AIN3) */ + channel@3 { + reg = <3>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; + zephyr,resolution = <12>; + }; +}; + +&uicr { + nfct-pins-as-gpios; +}; + +&gpiote { + status = "okay"; +}; + +&gpio0 { + status = "okay"; +}; + +&gpio1 { + status = "okay"; +}; + +/* ---- PWM0 for buzzer ---- */ +&pwm0 { + status = "okay"; + pinctrl-0 = <&pwm0_default>; + pinctrl-1 = <&pwm0_sleep>; + pinctrl-names = "default", "sleep"; +}; + +/* ---- GPS on UART0 (AT6558R, 9600 baud) ---- + * Uses luatos,air530z driver for NMEA with power control. + * GPS power controlled via on-off-gpios (P1.02 = GPS_EN). */ +&uart0 { + compatible = "nordic,nrf-uarte"; + status = "okay"; + current-speed = <9600>; + pinctrl-0 = <&uart0_default>; + pinctrl-1 = <&uart0_sleep>; + pinctrl-names = "default", "sleep"; + + gnss: gnss { + compatible = "luatos,air530z"; + on-off-gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>; + }; +}; + +/* ---- I2C0 for sensors ---- */ +&i2c0 { + compatible = "nordic,nrf-twim"; + status = "okay"; + clock-frequency = ; + pinctrl-0 = <&i2c0_default>; + pinctrl-1 = <&i2c0_sleep>; + pinctrl-names = "default", "sleep"; + + /* All supported environment & power sensors — auto-detected at runtime */ + #include "../../common/sensors-i2c.dtsi" +}; + +/* ---- SPI2 for LoRa SX1262 ---- */ +&spi2 { + compatible = "nordic,nrf-spim"; + status = "okay"; + pinctrl-0 = <&spi2_default>; + pinctrl-1 = <&spi2_sleep>; + pinctrl-names = "default", "sleep"; + cs-gpios = <&gpio1 10 GPIO_ACTIVE_LOW>; /* P1.10 (Arduino 42) LORA_CS */ + + lora: lora@0 { + compatible = "semtech,sx1262"; + reg = <0>; + spi-max-frequency = <8000000>; + + /* LoRa control pins */ + reset-gpios = <&gpio1 6 GPIO_ACTIVE_LOW>; /* P1.06 (Arduino 38) */ + busy-gpios = <&gpio1 14 GPIO_ACTIVE_HIGH>; /* P1.14 (Arduino 46) */ + dio1-gpios = <&gpio1 15 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>; /* P1.15 (Arduino 47) */ + + /* DIO2 drives RF switch for TX */ + dio2-tx-enable; + + /* TCXO voltage 1.8V via DIO3 */ + dio3-tcxo-voltage = ; + tcxo-power-startup-delay-ms = <5>; + + /* RX boosted mode for better sensitivity */ + rx-boosted; + }; +}; + +/* ---- QSPI Flash — not present on WisMesh Tag ---- */ +&qspi { + status = "disabled"; +}; + +/* ---- USB CDC for console/CLI ---- */ +zephyr_udc0: &usbd { + compatible = "nordic,nrf-usbd"; + status = "okay"; + + cdc_acm_uart: cdc_acm_uart { + compatible = "zephyr,cdc-acm-uart"; + }; +}; + +/* ---- Flash partitions (SoftDevice v6, app@0x26000) ---- */ +#include "../../common/nrf52_partitions_sdv6.dtsi" +#include "../../common/nrf52_wakeup.dtsi"