Skip to content

Commit

Permalink
Add gecko_adc driver usage to tmo_shell
Browse files Browse the repository at this point in the history
These changes add the gecko_adc driver usage into tmo_shell.

Signed-off-by: Kim Mansfield <[email protected]>
  • Loading branch information
kimmansfield authored and johnlange2 committed Apr 12, 2023
1 parent c9f15d6 commit 01dc3a1
Show file tree
Hide file tree
Showing 10 changed files with 445 additions and 351 deletions.
1 change: 0 additions & 1 deletion samples/tmo_shell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ target_sources(app PRIVATE src/buzzer_test.c)
target_sources(app PRIVATE src/led_test.c)
target_sources(app PRIVATE src/misc_test.c)
target_sources(app PRIVATE src/tmo_file.c)
target_sources(app PRIVATE src/tmo_adc.c)
target_sources(app PRIVATE src/tmo_bq24250.c)
target_sources(app PRIVATE src/tmo_battery_ctrl.c)
target_sources(app PRIVATE src/tmo_sntp.c)
Expand Down
39 changes: 39 additions & 0 deletions samples/tmo_shell/boards/tmo_dev_edge.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,42 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/dt-bindings/adc/adc.h>
#include <zephyr/dt-bindings/gpio/gpio.h>

/ {
zephyr,user {
/* adjust channel number according to pinmux in board.dts */
io-channels = <&adc 0>, <&adc 1>;
battsense-gpios = <&gpiok 0 GPIO_ACTIVE_HIGH>;
};
};

&gpiok {
hog1 {
gpio-hog;
gpios = <0 GPIO_ACTIVE_HIGH>;
output-high;
};
};

&adc {
#address-cells = <1>;
#size-cells = <0>;

channel@0 {
reg = <0>;
zephyr,gain = "ADC_GAIN_1_3";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 32)>;
zephyr,resolution = <12>;
};

channel@1 {
reg = <1>;
zephyr,gain = "ADC_GAIN_1_3";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 32)>;
zephyr,resolution = <12>;
};
};
1 change: 1 addition & 0 deletions samples/tmo_shell/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,4 @@ CONFIG_LOG_PRINTK=n
CONFIG_TMO_TEST_MFG_CHECK_GOLDEN=y
CONFIG_TMO_TEST_MFG_CHECK_ACCESS_CODE=y
CONFIG_DFU_GECKO_LIB=y
CONFIG_ADC_GECKO=y
200 changes: 0 additions & 200 deletions samples/tmo_shell/src/tmo_adc.c

This file was deleted.

15 changes: 0 additions & 15 deletions samples/tmo_shell/src/tmo_adc.h

This file was deleted.

26 changes: 26 additions & 0 deletions samples/tmo_shell/src/tmo_battery_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,29 @@ int get_battery_charging_status(uint8_t *charging, uint8_t *vbus, uint8_t *attac

return status;
}


void battery_apply_filter(float *bv)
{
static float s_filtered_capacity = -1;
static bool s_battery_is_charging = false;
bool battery_is_charging;

// If there has been a switch between charger and battery, reset the filter
battery_is_charging = is_battery_charging();
if (s_battery_is_charging != battery_is_charging) {
s_battery_is_charging = battery_is_charging;
s_filtered_capacity = -1;
}

if (s_filtered_capacity < 0) {
s_filtered_capacity = *bv;
}
*bv = s_filtered_capacity = s_filtered_capacity * 0.95 + (*bv) * 0.05;
}

uint8_t battery_millivolts_to_percent(uint32_t millivolts) {
float curBv = get_remaining_capacity((float) millivolts / 1000);
battery_apply_filter(&curBv);
return (uint8_t) (curBv + 0.5);
} // Calculate input voltage in mV
2 changes: 2 additions & 0 deletions samples/tmo_shell/src/tmo_battery_ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ float get_remaining_capacity(float battery_voltage);
bool is_battery_charging(void);
int get_battery_charging_status(uint8_t *charging, uint8_t *vbus, uint8_t *attached, uint8_t *fault);

void battery_apply_filter(float *bv);
uint8_t battery_millivolts_to_percent(uint32_t millivolts);
#endif
Loading

0 comments on commit 01dc3a1

Please sign in to comment.