From c45103c66f97a2c79e5f5e2242305fa32311d2bb Mon Sep 17 00:00:00 2001 From: David Lechner Date: Mon, 27 May 2019 16:49:24 -0500 Subject: [PATCH] drv/battery: drop port parameter It seems reasonable to expect that each hub will only have one built-in battery. So drop the port parameter. movehub fw size -16 --- extmod/modbattery.c | 4 ++-- lib/pbio/drv/battery/battery_adc.c | 15 ++++----------- lib/pbio/drv/battery/battery_ev3_linux.c | 6 +++--- lib/pbio/include/pbdrv/battery.h | 11 ++++------- lib/pbio/platform/hub4/sys.c | 4 ++-- lib/pbio/platform/move_hub/sys.c | 4 ++-- 6 files changed, 17 insertions(+), 27 deletions(-) diff --git a/extmod/modbattery.c b/extmod/modbattery.c index 6b2bd414c..87a22dfc7 100644 --- a/extmod/modbattery.c +++ b/extmod/modbattery.c @@ -11,14 +11,14 @@ STATIC mp_obj_t battery_voltage(void) { uint16_t volt; - pb_assert(pbdrv_battery_get_voltage_now(PBIO_PORT_SELF, &volt)); + pb_assert(pbdrv_battery_get_voltage_now(&volt)); return mp_obj_new_int(volt); } STATIC MP_DEFINE_CONST_FUN_OBJ_0(battery_voltage_obj, battery_voltage); STATIC mp_obj_t battery_current(void) { uint16_t cur; - pb_assert(pbdrv_battery_get_current_now(PBIO_PORT_SELF, &cur)); + pb_assert(pbdrv_battery_get_current_now(&cur)); return mp_obj_new_int(cur); } STATIC MP_DEFINE_CONST_FUN_OBJ_0(battery_current_obj, battery_current); diff --git a/lib/pbio/drv/battery/battery_adc.c b/lib/pbio/drv/battery/battery_adc.c index 1648e736d..370a035f4 100644 --- a/lib/pbio/drv/battery/battery_adc.c +++ b/lib/pbio/drv/battery/battery_adc.c @@ -7,22 +7,19 @@ #if PBDRV_CONFIG_BATTERY +#include + #include #include -#include #include PROCESS(pbdrv_battery_process, "battery"); -pbio_error_t pbdrv_battery_get_voltage_now(pbio_port_t port, uint16_t *value) { +pbio_error_t pbdrv_battery_get_voltage_now(uint16_t *value) { uint16_t raw; pbio_error_t err; - if (port != PBIO_PORT_SELF) { - return PBIO_ERROR_INVALID_PORT; - } - err = pbdrv_adc_get_ch(PBDRV_CONFIG_BATTERY_ADC_VOLTAGE_CH, &raw); if (err != PBIO_SUCCESS) { return err; @@ -35,14 +32,10 @@ pbio_error_t pbdrv_battery_get_voltage_now(pbio_port_t port, uint16_t *value) { return PBIO_SUCCESS; } -pbio_error_t pbdrv_battery_get_current_now(pbio_port_t port, uint16_t *value) { +pbio_error_t pbdrv_battery_get_current_now(uint16_t *value) { uint16_t raw; pbio_error_t err; - if (port != PBIO_PORT_SELF) { - return PBIO_ERROR_INVALID_PORT; - } - // this is measuring the voltage across a 0.05 ohm shunt resistor probably // via an op amp with unknown gain. err = pbdrv_adc_get_ch(PBDRV_CONFIG_BATTERY_ADC_CURRENT_CH, &raw); diff --git a/lib/pbio/drv/battery/battery_ev3_linux.c b/lib/pbio/drv/battery/battery_ev3_linux.c index 9bbf32a95..684052639 100644 --- a/lib/pbio/drv/battery/battery_ev3_linux.c +++ b/lib/pbio/drv/battery/battery_ev3_linux.c @@ -8,10 +8,10 @@ #if PBDRV_CONFIG_BATTERY +#include #include #include -#include #include PROCESS(pbdrv_battery_process, "battery"); @@ -19,7 +19,7 @@ PROCESS(pbdrv_battery_process, "battery"); static FILE *f_voltage; static FILE *f_current; -pbio_error_t pbdrv_battery_get_voltage_now(pbio_port_t port, uint16_t *value) { +pbio_error_t pbdrv_battery_get_voltage_now(uint16_t *value) { int32_t microvolt; if (0 == fseek(f_voltage, 0, SEEK_SET) && 0 <= fscanf(f_voltage, "%d", µvolt) && @@ -30,7 +30,7 @@ pbio_error_t pbdrv_battery_get_voltage_now(pbio_port_t port, uint16_t *value) { return PBIO_ERROR_IO; } -pbio_error_t pbdrv_battery_get_current_now(pbio_port_t port, uint16_t *value) { +pbio_error_t pbdrv_battery_get_current_now(uint16_t *value) { int32_t microamp; if (0 == fseek(f_current, 0, SEEK_SET) && 0 <= fscanf(f_current, "%d", µamp) && diff --git a/lib/pbio/include/pbdrv/battery.h b/lib/pbio/include/pbdrv/battery.h index 12c159111..cf0f23c0b 100644 --- a/lib/pbio/include/pbdrv/battery.h +++ b/lib/pbio/include/pbdrv/battery.h @@ -12,7 +12,6 @@ #include #include -#include #if PBDRV_CONFIG_BATTERY @@ -26,32 +25,30 @@ PROCESS_NAME(pbdrv_battery_process); /** * Gets the battery voltage. - * @param [in] port The I/O port * @param [out] value The voltage in millivolts * @return ::PBIO_SUCCESS on success, ::PBIO_ERROR_INVALID_PORT if * the port is not valid or ::PBIO_ERROR_IO if there was * an I/O error. */ -pbio_error_t pbdrv_battery_get_voltage_now(pbio_port_t port, uint16_t *value); +pbio_error_t pbdrv_battery_get_voltage_now(uint16_t *value); /** * Gets the battery current. - * @param [in] port The I/O port * @param [out] value The current in milliamps * @return ::PBIO_SUCCESS on success, ::PBIO_ERROR_INVALID_PORT if * the port is not valid or ::PBIO_ERROR_IO if there was * an I/O error. */ -pbio_error_t pbdrv_battery_get_current_now(pbio_port_t port, uint16_t *value); +pbio_error_t pbdrv_battery_get_current_now(uint16_t *value); #else static inline void _pbdrv_battery_poll(uint32_t now) { } static inline void _pbdrv_battery_deinit(void) { } -static inline pbio_error_t pbdrv_battery_get_voltage_now(pbio_port_t port, uint16_t *value) { +static inline pbio_error_t pbdrv_battery_get_voltage_now(uint16_t *value) { return PBIO_ERROR_NOT_SUPPORTED; } -static inline pbio_error_t pbdrv_battery_get_current_now(pbio_port_t port, uint16_t *value) { +static inline pbio_error_t pbdrv_battery_get_current_now(uint16_t *value) { return PBIO_ERROR_NOT_SUPPORTED; } diff --git a/lib/pbio/platform/hub4/sys.c b/lib/pbio/platform/hub4/sys.c index c28c581b4..e5a513798 100644 --- a/lib/pbio/platform/hub4/sys.c +++ b/lib/pbio/platform/hub4/sys.c @@ -151,7 +151,7 @@ static void init(void) { IWDG->KR = 0xaaaa; // refresh counter IWDG->KR = 0xcccc; // start watchdog timer - pbdrv_battery_get_voltage_now(PBIO_PORT_SELF, &battery_voltage); + pbdrv_battery_get_voltage_now(&battery_voltage); avg_battery_voltage = battery_voltage; _pbio_light_set_user_mode(false); @@ -200,7 +200,7 @@ static void update_battery(clock_time_t now) { poll_interval = clock_to_msec(now - prev_poll_time); prev_poll_time = now; - pbdrv_battery_get_voltage_now(PBIO_PORT_SELF, &battery_voltage); + pbdrv_battery_get_voltage_now(&battery_voltage); avg_battery_voltage = (avg_battery_voltage * (BATTERY_PERIOD_MS - poll_interval) + battery_voltage * poll_interval) / BATTERY_PERIOD_MS; diff --git a/lib/pbio/platform/move_hub/sys.c b/lib/pbio/platform/move_hub/sys.c index 9f00a7338..42aaf14cb 100644 --- a/lib/pbio/platform/move_hub/sys.c +++ b/lib/pbio/platform/move_hub/sys.c @@ -143,7 +143,7 @@ static void init(void) { uint16_t battery_voltage; uint8_t r, g, b; - pbdrv_battery_get_voltage_now(PBIO_PORT_SELF, &battery_voltage); + pbdrv_battery_get_voltage_now(&battery_voltage); avg_battery_voltage = battery_voltage; _pbio_light_set_user_mode(false); @@ -192,7 +192,7 @@ static void update_battery(clock_time_t now) { poll_interval = clock_to_msec(now - prev_poll_time); prev_poll_time = now; - pbdrv_battery_get_voltage_now(PBIO_PORT_SELF, &battery_voltage); + pbdrv_battery_get_voltage_now(&battery_voltage); avg_battery_voltage = (avg_battery_voltage * (BATTERY_PERIOD_MS - poll_interval) + battery_voltage * poll_interval) / BATTERY_PERIOD_MS;