Skip to content

Commit d5fc2db

Browse files
kimmansfieldjohnlange2
authored andcommitted
tmo_shell: driver: Added in gecko_adc driver
These changes add the gecko_adc driver usage into tmo_shell. Signed-off-by: Kim Mansfield <[email protected]>
1 parent 2b88be9 commit d5fc2db

File tree

9 files changed

+272
-272
lines changed

9 files changed

+272
-272
lines changed

samples/tmo_shell/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ target_sources(app PRIVATE src/buzzer_test.c)
2727
target_sources(app PRIVATE src/led_test.c)
2828
target_sources(app PRIVATE src/misc_test.c)
2929
target_sources(app PRIVATE src/tmo_file.c)
30-
target_sources(app PRIVATE src/tmo_adc.c)
3130
target_sources(app PRIVATE src/tmo_bq24250.c)
3231
target_sources(app PRIVATE src/tmo_battery_ctrl.c)
3332
target_sources(app PRIVATE src/tmo_sntp.c)

samples/tmo_shell/prj.conf

+1
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,4 @@ CONFIG_LOG_PRINTK=n
160160
CONFIG_TMO_TEST_MFG_CHECK_GOLDEN=y
161161
CONFIG_TMO_TEST_MFG_CHECK_ACCESS_CODE=y
162162
CONFIG_DFU_GECKO_LIB=y
163+
CONFIG_ADC_GECKO=y

samples/tmo_shell/src/tmo_adc.c

-198
This file was deleted.

samples/tmo_shell/src/tmo_adc.h

-15
This file was deleted.

samples/tmo_shell/src/tmo_battery_ctrl.c

+26
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,29 @@ int get_battery_charging_status(uint8_t *charging, uint8_t *vbus, uint8_t *attac
9292

9393
return status;
9494
}
95+
96+
97+
void battery_apply_filter(float *bv)
98+
{
99+
static float s_filtered_capacity = -1;
100+
static bool s_battery_is_charging = false;
101+
bool battery_is_charging;
102+
103+
// If there has been a switch between charger and battery, reset the filter
104+
battery_is_charging = is_battery_charging();
105+
if (s_battery_is_charging != battery_is_charging) {
106+
s_battery_is_charging = battery_is_charging;
107+
s_filtered_capacity = -1;
108+
}
109+
110+
if (s_filtered_capacity < 0) {
111+
s_filtered_capacity = *bv;
112+
}
113+
*bv = s_filtered_capacity = s_filtered_capacity * 0.95 + (*bv) * 0.05;
114+
}
115+
116+
uint8_t battery_millivolts_to_percent(uint32_t millivolts) {
117+
float curBv = get_remaining_capacity((float) millivolts / 1000);
118+
battery_apply_filter(&curBv);
119+
return (uint8_t) (curBv + 0.5);
120+
} // Calculate input voltage in mV

samples/tmo_shell/src/tmo_battery_ctrl.h

+2
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@ float get_remaining_capacity(float battery_voltage);
3636
bool is_battery_charging(void);
3737
int get_battery_charging_status(uint8_t *charging, uint8_t *vbus, uint8_t *attached, uint8_t *fault);
3838

39+
void battery_apply_filter(float *bv);
40+
uint8_t battery_millivolts_to_percent(uint32_t millivolts);
3941
#endif

0 commit comments

Comments
 (0)