电池服务¶
电池服务 (battery service) 提供了监测和管理电池电压的功能。电池电压和 battery_service_event_t 定义的事件可以通过回调函数与用户进行交互。
应用示例¶
以下示例展示了该 API 的实现方式。
Header File¶
Functions¶
- 
periph_service_handle_t 
battery_service_create(battery_service_config_t *config)¶ Create the battery service instance.
- Return
 NULL: Failed
Others: Success
- Parameters
 config: configuration of the battery service
- 
esp_err_t 
battery_service_vol_report_switch(periph_service_handle_t handle, bool on_off)¶ Start or stop the battery voltage report.
- Return
 ESP_OK: Success
ESP_ERR_INVALID_ARG: handle is NULL
- Parameters
 [in] handle: pointer to ‘periph_service_handle_t’ structure[in] on_off: ‘true’ to start, ‘false’ to stop
- 
esp_err_t 
battery_service_set_vol_report_freq(periph_service_handle_t handle, int freq)¶ Set voltage report freqency.
- Return
 ESP_OK: Success
ESP_ERR_INVALID_ARG: handle is NULL
- Parameters
 [in] handle: pointer to ‘periph_service_handle_t’ structure[in] freq: voltage report freqency
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 
 
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.
- Return
 NULL: Failed
Others: Success
- Parameters
 [in] config: pointer to ‘vol_monitor_param_t’ structure
- 
esp_err_t 
vol_monitor_destroy(vol_monitor_handle_t handle)¶ Destroy the voltage monitor.
- Return
 ESP_OK: Success
Others: Failed
- Parameters
 [in] handle: pointer to ‘vol_monitor_handle_t’ structure
- 
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.
- Return
 ESP_OK: Success
Others: Failed
- Parameters
 [in] handle: pointer to ‘vol_monitor_handle_t’ structure[in] event_cb: callback used to handle the events of voltage monitor[in] user_ctx: user’s data
- 
esp_err_t 
vol_monitor_start_freq_report(vol_monitor_handle_t handle)¶ Start the voltage report with the configured frequency.
- Return
 ESP_OK: Success
Others: Failed
- Parameters
 [in] handle: pointer to ‘vol_monitor_handle_t’ structure
- 
esp_err_t 
vol_monitor_stop_freq_report(vol_monitor_handle_t handle)¶ Stop the voltage frequency report.
- Return
 ESP_OK: Success
Others: Failed
- Parameters
 [in] handle: pointer to ‘vol_monitor_handle_t’ structure
- 
esp_err_t 
vol_monitor_set_report_freq(vol_monitor_handle_t handle, int freq)¶ Set the voltage report frequency.
- Return
 ESP_OK: Success
Others: Failed
- Parameters
 [in] handle: pointer to ‘vol_monitor_handle_t’ structure[in] freq: voltage report freqency
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 (*
 
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