1 /* 2 * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef __APP_BATTERY_H__ 16 #define __APP_BATTERY_H__ 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif 21 22 #include <stdint.h> 23 24 25 #define APP_BATTERY_LEVEL_MIN (0) 26 27 #ifdef __INTERCONNECTION__ 28 #define APP_BATTERY_LEVEL_MAX (100) 29 #define APP_BATTERY_DEFAULT_INFO 0xE4 30 31 typedef struct 32 { 33 uint8_t chargingStatus : 1; 34 uint8_t batteryLevel : 7; 35 }APP_BATTERY_INFO_T; 36 37 uint8_t* app_battery_get_mobile_support_self_defined_command_p(void); 38 #else // #ifdef __INTERCONNECTION__ 39 #define APP_BATTERY_LEVEL_MAX (9) 40 #endif // #ifdef __INTERCONNECTION__ 41 42 #define APP_BATTERY_LEVEL_NUM (APP_BATTERY_LEVEL_MAX-APP_BATTERY_LEVEL_MIN+1) 43 44 enum APP_BATTERY_STATUS_T { 45 APP_BATTERY_STATUS_NORMAL, 46 APP_BATTERY_STATUS_CHARGING, 47 APP_BATTERY_STATUS_OVERVOLT, 48 APP_BATTERY_STATUS_UNDERVOLT, 49 APP_BATTERY_STATUS_PDVOLT, 50 APP_BATTERY_STATUS_PLUGINOUT, 51 APP_BATTERY_STATUS_INVALID, 52 53 APP_BATTERY_STATUS_QTY 54 }; 55 56 #define APP_BATTERY_OPEN_MODE_INVALID (-1) 57 #define APP_BATTERY_OPEN_MODE_NORMAL (0) 58 #define APP_BATTERY_OPEN_MODE_CHARGING (1) 59 #define APP_BATTERY_OPEN_MODE_CHARGING_PWRON (2) 60 61 typedef uint16_t APP_BATTERY_MV_T; 62 63 enum APP_BATTERY_CHARGER_T 64 { 65 APP_BATTERY_CHARGER_PLUGOUT = 0, 66 APP_BATTERY_CHARGER_PLUGIN, 67 APP_BATTERY_CHARGER_QTY, 68 }; 69 70 union APP_BATTERY_MSG_PRAMS{ 71 APP_BATTERY_MV_T volt; 72 enum APP_BATTERY_CHARGER_T charger; 73 uint32_t prams; 74 }; 75 76 typedef void (*APP_BATTERY_CB_T)(APP_BATTERY_MV_T currvolt, uint8_t currlevel,enum APP_BATTERY_STATUS_T curstatus,uint32_t status, union APP_BATTERY_MSG_PRAMS prams); 77 78 79 int app_battery_get_info(APP_BATTERY_MV_T *currvolt, uint8_t *currlevel, enum APP_BATTERY_STATUS_T *status); 80 81 /** 82 * Battery App owns its own context where it will periodically update the 83 * battery level and state. Makes sense for it to act as a Model and publish 84 * battery change events to any interested users. 85 * 86 * Note: Callback will execute out of BES "App Thread" context. 87 * 88 * TODO: ideally implemented as proper observer pattern with support for multiple 89 * listeners 90 * 91 * Returns 92 * - 0: On success 93 * - 1: If registration failed 94 */ 95 int app_battery_register(APP_BATTERY_CB_T user_cb); 96 97 int app_battery_open(void); 98 99 int app_battery_start(void); 100 101 int app_battery_stop(void); 102 103 int app_battery_close(void); 104 105 int app_battery_charger_indication_open(void); 106 107 int8_t app_battery_current_level(void); 108 109 int8_t app_battery_is_charging(void); 110 111 int ntc_capture_open(void); 112 113 int ntc_capture_start(void); 114 115 #ifdef __cplusplus 116 } 117 #endif 118 119 120 #endif 121