Skip to content
Snippets Groups Projects
Commit 46ef3985 authored by rahix's avatar rahix Committed by schneider
Browse files

feat(pmic): Add API-call to read battery voltage


Signed-off-by: default avatarRahix <rahix@rahix.de>
parent 79e2fb15
No related branches found
No related tags found
1 merge request!132Battery Voltage
......@@ -32,6 +32,7 @@ typedef _Bool bool;
#define API_SYSTEM_EXIT 0x1
#define API_SYSTEM_EXEC 0x2
#define API_SYSTEM_RESET 0x3
#define API_BATTERY_VOLTAGE 0x4
#define API_INTERRUPT_ENABLE 0xA
#define API_INTERRUPT_DISABLE 0xB
......@@ -210,6 +211,16 @@ API(API_SYSTEM_EXEC, int __epic_exec(char *name));
*/
API(API_SYSTEM_RESET, void epic_system_reset(void));
/**
* Battery Voltage
* ===============
*/
/**
* Read the current battery voltage.
*/
API(API_BATTERY_VOLTAGE, int epic_read_battery_voltage(float *result));
/**
* UART/Serial Interface
* =====================
......
......@@ -180,6 +180,14 @@ static void pmic_check_battery()
*/
}
/*
* API-call for battery voltage
*/
int epic_read_battery_voltage(float *result)
{
return pmic_read_amux(PMIC_AMUX_BATT_U, result);
}
static StaticTimer_t pmic_timer_data;
static void vPmicTimerCb(TimerHandle_t xTimer)
{
......
......@@ -123,6 +123,18 @@ static mp_obj_t mp_os_rename(mp_obj_t py_oldp, mp_obj_t py_newp)
}
static MP_DEFINE_CONST_FUN_OBJ_2(rename_obj, mp_os_rename);
static mp_obj_t mp_os_read_battery()
{
float result;
int res = epic_read_battery_voltage(&result);
if (res < 0) {
mp_raise_OSError(-res);
}
return mp_obj_new_float(result);
}
static MP_DEFINE_CONST_FUN_OBJ_0(read_battery_obj, mp_os_read_battery);
static const mp_rom_map_elem_t os_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_os) },
{ MP_ROM_QSTR(MP_QSTR_exit), MP_ROM_PTR(&exit_obj) },
......@@ -132,6 +144,7 @@ static const mp_rom_map_elem_t os_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_unlink), MP_ROM_PTR(&unlink_obj) },
{ MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&mkdir_obj) },
{ MP_ROM_QSTR(MP_QSTR_rename), MP_ROM_PTR(&rename_obj) },
{ MP_ROM_QSTR(MP_QSTR_read_battery), MP_ROM_PTR(&read_battery_obj) },
};
static MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table);
......
......@@ -105,6 +105,7 @@ Q(listdir)
Q(unlink)
Q(mkdir)
Q(rename)
Q(read_battery)
/* gpio */
Q(gpio)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment