Skip to content

Commit a1c0010

Browse files
authored
Merge pull request #166 from tmobile/tmo-CFSPDK-1262-Implement-Battery-Shut-Down-and-Recovery-for-Tracker
Make tmo_shell ADC activity defer to external.
2 parents 9abcd5e + c5cd2ee commit a1c0010

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

samples/tmo_shell/src/tmo_adc.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ K_SEM_DEFINE(adc_sem, 0, 1);
2525
static ADC_InitSingle_TypeDef initSingle_bv = ADC_INITSINGLE_DEFAULT;
2626
static ADC_InitSingle_TypeDef initSingle_hwid = ADC_INITSINGLE_DEFAULT;
2727

28-
#ifdef HWID_APORT
2928
/**
3029
* @brief Set the VBAT_SNS_EN Pin High to enable ADC readings
3130
*
@@ -40,14 +39,19 @@ static void set_vbat_sens_en(bool enable)
4039
GPIO_PinModeSet(VBAT_EN_PORT, VBAT_EN_PIN, gpioModePushPull, enable);
4140
#endif /* VBAT_EN_PORT */
4241
}
43-
#endif /* HWID_APORT */
4442

4543
/**
4644
* @brief Initialize the Gecko ADC
4745
*
4846
*/
49-
void initADC(void)
47+
static void initADC(void)
5048
{
49+
static bool lazy_init = false; /* perform the init only once */
50+
/* use lazy init, to remove the call from tmo_shell.c */
51+
if (lazy_init) {
52+
return;
53+
}
54+
lazy_init = true;
5155

5256
// Enable ADC0 clock
5357
CMU_ClockEnable(cmuClock_ADC0, true);
@@ -77,18 +81,14 @@ void initADC(void)
7781
init.timebase = ADC_TimebaseCalc(0);
7882

7983
ADC_Init(ADC0, &init);
80-
81-
int hwid = read_hwid();
82-
83-
LOG_INF("HWID = %d\n", hwid);
8484
}
8585

8686
/*
8787
* @brief This function writes the amount of battery charge remaining
8888
* (to the nearest 1%) in bv.
8989
* It returns true if successful, or false if there is an issue
9090
*/
91-
bool millivolts_to_percent(uint32_t millivolts, uint8_t *percent) {
91+
__weak bool millivolts_to_percent(uint32_t millivolts, uint8_t *percent) {
9292
float curBv = get_remaining_capacity((float) millivolts / 1000);
9393
*percent = (uint8_t) (curBv + 0.5);
9494
return true;
@@ -97,9 +97,11 @@ bool millivolts_to_percent(uint32_t millivolts, uint8_t *percent) {
9797
/**
9898
* @brief Main function
9999
*/
100-
int read_battery_voltage(void)
100+
__weak int read_battery_voltage(void)
101101
{
102102
#ifdef VBAT_APORT
103+
initADC();
104+
103105
uint32_t sample;
104106
uint32_t millivolts;
105107
float millivolts_f;
@@ -140,9 +142,11 @@ int read_battery_voltage(void)
140142
*
141143
* @return int Millivolts
142144
*/
143-
int read_hwid(void)
145+
__weak int read_hwid(void)
144146
{
145147
#ifdef HWID_APORT
148+
initADC();
149+
146150
uint32_t sample;
147151
uint32_t millivolts;
148152
float millivolts_f;

samples/tmo_shell/src/tmo_adc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@
1010
int read_battery_voltage(void);
1111
int read_hwid(void);
1212
bool millivolts_to_percent(uint32_t millivolts, uint8_t *bv);
13-
void initADC();
1413

1514
#endif

samples/tmo_shell/src/tmo_shell.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3049,7 +3049,6 @@ void tmo_shell_main(void)
30493049
mountfs();
30503050

30513051
cxd5605_init();
3052-
initADC();
30533052
#ifdef CONFIG_WIFI
30543053
tmo_wifi_connect();
30553054
#endif

0 commit comments

Comments
 (0)