Battery Service
The battery service can monitor and manage battery voltage. You can access battery voltage and the events defined by battery_service_event_t
through callback functions.
Application Example
Implementation of this API is demonstrated in the following example:
Header File
Functions
-
periph_service_handle_t battery_service_create(battery_service_config_t *config)
Create the battery service instance.
- Parameters
config – configuration of the battery service
- Returns
NULL: Failed
Others: Success
-
esp_err_t battery_service_vol_report_switch(periph_service_handle_t handle, bool on_off)
Start or stop the battery voltage report.
- Parameters
handle – [in] pointer to ‘periph_service_handle_t’ structure
on_off – [in] ‘true’ to start, ‘false’ to stop
- Returns
ESP_OK: Success
ESP_ERR_INVALID_ARG: handle is NULL
-
esp_err_t battery_service_set_vol_report_freq(periph_service_handle_t handle, int freq)
Set voltage report freqency.
- Parameters
handle – [in] pointer to ‘periph_service_handle_t’ structure
freq – [in] voltage report freqency
- Returns
ESP_OK: Success
ESP_ERR_INVALID_ARG: handle is NULL
Structures
-
struct battery_service_config_t
Battery service configure.
Public Members
-
int task_stack
>0 Service task stack; =0 with out task created
-
int task_prio
Service task priority (based on freeRTOS priority)
-
int task_core
Service task running in core (0 or 1)
-
bool extern_stack
Task stack allocate on the extern ram
-
periph_service_cb evt_cb
Service callback function
-
void *cb_ctx
Callback context
-
vol_monitor_handle_t vol_monitor
Battery monitor
-
void *charger_monitor
Charger monitor. Not supported yet
-
int task_stack
Macros
-
BATTERY_SERVICE_DEFAULT_CONFIG()
Enumerations
Header File
Functions
-
vol_monitor_handle_t vol_monitor_create(vol_monitor_param_t *config)
Create the voltage monitor instance.
- Parameters
config – [in] pointer to ‘vol_monitor_param_t’ structure
- Returns
NULL: Failed
Others: Success
-
esp_err_t vol_monitor_destroy(vol_monitor_handle_t handle)
Destroy the voltage monitor.
- Parameters
handle – [in] pointer to ‘vol_monitor_handle_t’ structure
- Returns
ESP_OK: Success
Others: Failed
-
esp_err_t vol_monitor_set_event_cb(vol_monitor_handle_t handle, vol_monitor_event_cb event_cb, void *user_ctx)
Set the event callback.
- Parameters
handle – [in] pointer to ‘vol_monitor_handle_t’ structure
event_cb – [in] callback used to handle the events of voltage monitor
user_ctx – [in] user’s data
- Returns
ESP_OK: Success
Others: Failed
-
esp_err_t vol_monitor_start_freq_report(vol_monitor_handle_t handle)
Start the voltage report with the configured frequency.
- Parameters
handle – [in] pointer to ‘vol_monitor_handle_t’ structure
- Returns
ESP_OK: Success
Others: Failed
-
esp_err_t vol_monitor_stop_freq_report(vol_monitor_handle_t handle)
Stop the voltage frequency report.
- Parameters
handle – [in] pointer to ‘vol_monitor_handle_t’ structure
- Returns
ESP_OK: Success
Others: Failed
-
esp_err_t vol_monitor_set_report_freq(vol_monitor_handle_t handle, int freq)
Set the voltage report frequency.
- Parameters
handle – [in] pointer to ‘vol_monitor_handle_t’ structure
freq – [in] voltage report freqency
- Returns
ESP_OK: Success
Others: Failed
Structures
-
struct vol_monitor_param_t
Battery adc configure.
Public Members
-
bool (*init)(void*)
Voltage read init
-
bool (*deinit)(void*)
Voltage read deinit
-
int (*vol_get)(void*)
Voltage read interface
-
void *user_data
Parameters for callbacks
-
int read_freq
Voltage read frequency, unit: s
-
int report_freq
Voltage report frequency, voltage will be report with a interval calculate by (
read_freq
*report_freq
)
-
int vol_full_threshold
Voltage threshold to report, unit: mV
-
int vol_low_threshold
Voltage threshold to report, unit: mV
-
bool (*init)(void*)
Type Definitions
-
typedef void *vol_monitor_handle_t
voltage monitor handle
-
typedef void (*vol_monitor_event_cb)(int msg_id, void *data, void *user_ctx)
callback define