207 lines
7.2 KiB
C
207 lines
7.2 KiB
C
/**************************************************************************************************
|
|
Filename: battservice.h
|
|
Revised: $Date $
|
|
Revision: $Revision $
|
|
|
|
Description: This file contains the Battery service definitions and
|
|
prototypes.
|
|
|
|
Copyright 2011-2013 Texas Instruments Incorporated. All rights reserved.
|
|
|
|
IMPORTANT: Your use of this Software is limited to those specific rights
|
|
granted under the terms of a software license agreement between the user
|
|
who downloaded the software, his/her employer (which must be your employer)
|
|
and Texas Instruments Incorporated (the "License"). You may not use this
|
|
Software unless you agree to abide by the terms of the License. The License
|
|
limits your use, and you acknowledge, that the Software may not be modified,
|
|
copied or distributed unless embedded on a Texas Instruments microcontroller
|
|
or used solely and exclusively in conjunction with a Texas Instruments radio
|
|
frequency transceiver, which is integrated into your product. Other than for
|
|
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
|
|
works of, modify, distribute, perform, display or sell this Software and/or
|
|
its documentation for any purpose.
|
|
|
|
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
|
|
PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
|
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
|
|
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
|
|
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
|
|
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
|
|
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
|
|
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
|
|
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
|
|
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
|
|
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
|
|
|
|
Should you have any questions regarding your right to use this Software,
|
|
contact Texas Instruments Incorporated at www.TI.com.
|
|
**************************************************************************************************/
|
|
|
|
#ifndef BATTSERVICE_H
|
|
#define BATTSERVICE_H
|
|
|
|
#ifdef __cplusplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
|
|
/*********************************************************************
|
|
* INCLUDES
|
|
*/
|
|
|
|
/*********************************************************************
|
|
* CONSTANTS
|
|
*/
|
|
|
|
|
|
// Battery Service UUIDs
|
|
#define BATT_SERVICE_UUID 0x180F // Battery Service
|
|
#define BATT_LEVEL_UUID 0x2A19 // Battery Level
|
|
|
|
// Battery Service Get/Set Parameters
|
|
#define BATT_PARAM_LEVEL 0
|
|
#define BATT_PARAM_CRITICAL_LEVEL 1
|
|
#define BATT_PARAM_SERVICE_HANDLE 2
|
|
#define BATT_PARAM_BATT_LEVEL_IN_REPORT 3
|
|
|
|
// Callback events
|
|
#define BATT_LEVEL_NOTI_ENABLED 1
|
|
#define BATT_LEVEL_NOTI_DISABLED 2
|
|
|
|
// HID Report IDs for the service
|
|
#define HID_RPT_ID_BATT_LEVEL_IN 4 // Battery Level input report ID
|
|
|
|
/*********************************************************************
|
|
* TYPEDEFS
|
|
*/
|
|
|
|
// Battery Service callback function
|
|
typedef void (*battServiceCB_t)(uint8 event);
|
|
|
|
// Battery measure HW setup function
|
|
typedef void (*battServiceSetupCB_t)(void);
|
|
|
|
// Battery measure percentage calculation function
|
|
typedef uint8 (*battServiceCalcCB_t)(uint16 adcVal);
|
|
|
|
// Battery measure HW teardown function
|
|
typedef void (*battServiceTeardownCB_t)(void);
|
|
|
|
/*********************************************************************
|
|
* MACROS
|
|
*/
|
|
|
|
/*********************************************************************
|
|
* Profile Callbacks
|
|
*/
|
|
|
|
|
|
/*********************************************************************
|
|
* API FUNCTIONS
|
|
*/
|
|
|
|
/*********************************************************************
|
|
* @fn Batt_AddService
|
|
*
|
|
* @brief Initializes the Battery service by registering
|
|
* GATT attributes with the GATT server.
|
|
*
|
|
* @return Success or Failure
|
|
*/
|
|
extern bStatus_t Batt_AddService( void );
|
|
|
|
/*********************************************************************
|
|
* @fn Batt_Register
|
|
*
|
|
* @brief Register a callback function with the Battery Service.
|
|
*
|
|
* @param pfnServiceCB - Callback function.
|
|
*
|
|
* @return None.
|
|
*/
|
|
extern void Batt_Register( battServiceCB_t pfnServiceCB );
|
|
|
|
/*********************************************************************
|
|
* @fn Batt_SetParameter
|
|
*
|
|
* @brief Set a Battery Service parameter.
|
|
*
|
|
* @param param - Profile parameter ID
|
|
* @param len - length of data to right
|
|
* @param value - pointer to data to write. This is dependent on
|
|
* the parameter ID and WILL be cast to the appropriate
|
|
* data type (example: data type of uint16 will be cast to
|
|
* uint16 pointer).
|
|
*
|
|
* @return bStatus_t
|
|
*/
|
|
extern bStatus_t Batt_SetParameter( uint8 param, uint8 len, void *value );
|
|
|
|
/*********************************************************************
|
|
* @fn Batt_GetParameter
|
|
*
|
|
* @brief Get a Battery parameter.
|
|
*
|
|
* @param param - Profile parameter ID
|
|
* @param value - pointer to data to get. This is dependent on
|
|
* the parameter ID and WILL be cast to the appropriate
|
|
* data type (example: data type of uint16 will be cast to
|
|
* uint16 pointer).
|
|
*
|
|
* @return bStatus_t
|
|
*/
|
|
extern bStatus_t Batt_GetParameter( uint8 param, void *value );
|
|
|
|
/*********************************************************************
|
|
* @fn Batt_MeasLevel
|
|
*
|
|
* @brief Measure the battery level and update the battery
|
|
* level value in the service characteristics. If
|
|
* the battery level-state characteristic is configured
|
|
* for notification and the battery level has changed
|
|
* since the last measurement, then a notification
|
|
* will be sent.
|
|
*
|
|
* @return Success or Failure
|
|
*/
|
|
extern bStatus_t Batt_MeasLevel( void );
|
|
|
|
/*********************************************************************
|
|
* @fn Batt_Setup
|
|
*
|
|
* @brief Set up which ADC source is to be used. Defaults to VDD/3.
|
|
*
|
|
* @param adc_ch - ADC Channel, e.g. HAL_ADC_CHN_AIN6
|
|
* @param minVal - max battery level
|
|
* @param maxVal - min battery level
|
|
* @param sCB - HW setup callback
|
|
* @param tCB - HW tear down callback
|
|
* @param cCB - percentage calculation callback
|
|
*
|
|
* @return none.
|
|
*/
|
|
extern void Batt_Setup( uint8 adc_ch, uint16 minVal, uint16 maxVal,
|
|
battServiceSetupCB_t sCB, battServiceTeardownCB_t tCB,
|
|
battServiceCalcCB_t cCB );
|
|
|
|
/*********************************************************************
|
|
* @fn Batt_HandleConnStatusCB
|
|
*
|
|
* @brief Battery Service link status change handler function.
|
|
*
|
|
* @param connHandle - connection handle
|
|
* @param changeType - type of change
|
|
*
|
|
* @return none
|
|
*/
|
|
void Batt_HandleConnStatusCB( uint16 connHandle, uint8 changeType );
|
|
|
|
/*********************************************************************
|
|
*********************************************************************/
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* BATTSERVICE_H */
|