1+ #include " T096Board.h"
2+
3+ #include < Arduino.h>
4+ #include < Wire.h>
5+
6+ #ifdef NRF52_POWER_MANAGEMENT
7+ // Static configuration for power management
8+ // Values come from variant.h defines
9+ const PowerMgtConfig power_config = {
10+ .lpcomp_ain_channel = PWRMGT_LPCOMP_AIN ,
11+ .lpcomp_refsel = PWRMGT_LPCOMP_REFSEL ,
12+ .voltage_bootlock = PWRMGT_VOLTAGE_BOOTLOCK
13+ };
14+
15+ void T096Board::initiateShutdown (uint8_t reason) {
16+ #if ENV_INCLUDE_GPS == 1
17+ pinMode (PIN_GPS_EN , OUTPUT );
18+ digitalWrite (PIN_GPS_EN , !PIN_GPS_EN_ACTIVE );
19+ #endif
20+ variant_shutdown ();
21+
22+ bool enable_lpcomp = (reason == SHUTDOWN_REASON_LOW_VOLTAGE ||
23+ reason == SHUTDOWN_REASON_BOOT_PROTECT );
24+ pinMode (PIN_BAT_CTL , OUTPUT );
25+ digitalWrite (PIN_BAT_CTL , enable_lpcomp ? HIGH : LOW );
26+
27+ if (enable_lpcomp) {
28+ configureVoltageWake (power_config.lpcomp_ain_channel , power_config.lpcomp_refsel );
29+ }
30+
31+ enterSystemOff (reason);
32+ }
33+ #endif // NRF52_POWER_MANAGEMENT
34+
35+ void T096Board::begin () {
36+ NRF52Board::begin ();
37+
38+ #ifdef NRF52_POWER_MANAGEMENT
39+ // Boot voltage protection check (may not return if voltage too low)
40+ checkBootVoltage (&power_config);
41+ #endif
42+
43+ #if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL)
44+ Wire.setPins (PIN_BOARD_SDA , PIN_BOARD_SCL );
45+ #endif
46+
47+ Wire.begin ();
48+
49+ pinMode (P_LORA_TX_LED , OUTPUT );
50+ digitalWrite (P_LORA_TX_LED , LOW );
51+
52+ periph_power.begin ();
53+ loRaFEMControl.init ();
54+ delay (1 );
55+ }
56+
57+ void T096Board::onBeforeTransmit () {
58+ digitalWrite (P_LORA_TX_LED , HIGH ); // turn TX LED on
59+ loRaFEMControl.setTxModeEnable ();
60+ }
61+
62+ void T096Board::onAfterTransmit () {
63+ digitalWrite (P_LORA_TX_LED , LOW ); // turn TX LED off
64+ loRaFEMControl.setRxModeEnable ();
65+ }
66+
67+ uint16_t T096Board::getBattMilliVolts () {
68+ int adcvalue = 0 ;
69+ analogReadResolution (12 );
70+ analogReference (AR_INTERNAL_3_0 );
71+ pinMode (PIN_VBAT_READ , INPUT );
72+ pinMode (PIN_BAT_CTL , OUTPUT );
73+ digitalWrite (PIN_BAT_CTL , 1 );
74+
75+ delay (10 );
76+ adcvalue = analogRead (PIN_VBAT_READ );
77+ digitalWrite (PIN_BAT_CTL , 0 );
78+
79+ return (uint16_t )((float )adcvalue * MV_LSB * 4.9 );
80+ }
81+ void T096Board::variant_shutdown () {
82+ nrf_gpio_cfg_default (PIN_VEXT_EN );
83+ nrf_gpio_cfg_default (PIN_TFT_CS );
84+ nrf_gpio_cfg_default (PIN_TFT_DC );
85+ nrf_gpio_cfg_default (PIN_TFT_SDA );
86+ nrf_gpio_cfg_default (PIN_TFT_SCL );
87+ nrf_gpio_cfg_default (PIN_TFT_RST );
88+ nrf_gpio_cfg_default (PIN_TFT_LEDA_CTL );
89+
90+ nrf_gpio_cfg_default (PIN_LED );
91+
92+ nrf_gpio_cfg_default (P_LORA_KCT8103L_PA_CSD );
93+ nrf_gpio_cfg_default (P_LORA_KCT8103L_PA_CTX );
94+ pinMode (P_LORA_PA_POWER , OUTPUT );
95+ digitalWrite (P_LORA_PA_POWER , LOW );
96+
97+ digitalWrite (PIN_BAT_CTL , LOW );
98+ nrf_gpio_cfg_default (LORA_CS );
99+ nrf_gpio_cfg_default (SX126X_DIO1 );
100+ nrf_gpio_cfg_default (SX126X_BUSY );
101+ nrf_gpio_cfg_default (SX126X_RESET );
102+
103+ nrf_gpio_cfg_default (PIN_SPI_MISO );
104+ nrf_gpio_cfg_default (PIN_SPI_MOSI );
105+ nrf_gpio_cfg_default (PIN_SPI_SCK );
106+
107+ // nrf_gpio_cfg_default(PIN_GPS_PPS);
108+ nrf_gpio_cfg_default (PIN_GPS_RESET );
109+ nrf_gpio_cfg_default (PIN_GPS_EN );
110+ nrf_gpio_cfg_default (PIN_GPS_RX );
111+ nrf_gpio_cfg_default (PIN_GPS_TX );
112+ }
113+
114+ void T096Board::powerOff () {
115+ #if ENV_INCLUDE_GPS == 1
116+ pinMode (PIN_GPS_EN , OUTPUT );
117+ digitalWrite (PIN_GPS_EN , !PIN_GPS_EN_ACTIVE );
118+ #endif
119+ loRaFEMControl.setSleepModeEnable ();
120+ variant_shutdown ();
121+ sd_power_system_off ();
122+ }
123+
124+ const char * T096Board::getManufacturerName () const {
125+ return " Heltec T096" ;
126+ }
0 commit comments