1 /** 2 **************************************************************************************** 3 * 4 * @file pass.h 5 * 6 * @brief Phone Alert Status Service API. 7 * 8 **************************************************************************************** 9 * @attention 10 #####Copyright (c) 2019 GOODIX 11 All rights reserved. 12 13 Redistribution and use in source and binary forms, with or without 14 modification, are permitted provided that the following conditions are met: 15 * Redistributions of source code must retain the above copyright 16 notice, this list of conditions and the following disclaimer. 17 * Redistributions in binary form must reproduce the above copyright 18 notice, this list of conditions and the following disclaimer in the 19 documentation and/or other materials provided with the distribution. 20 * Neither the name of GOODIX nor the names of its contributors may be used 21 to endorse or promote products derived from this software without 22 specific prior written permission. 23 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE 28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 POSSIBILITY OF SUCH DAMAGE. 35 ***************************************************************************************** 36 */ 37 /** 38 * @addtogroup BLE_SRV BLE Services 39 * @{ 40 * @brief Definitions and prototypes for the BLE Service interface. 41 */ 42 43 /** 44 * @defgroup BLE_SDK_PASS Phone Alert Status Service (PASS) 45 * @{ 46 * @brief Phone Alert Status Service module. 47 * 48 * @details The Phone Alert Status Service shall expose the Alert Status characteristic and the 49 * Ringer Setting characteristic, and may expose the Ringer Control Point characteristic. 50 * 51 * After \ref pass_init_t variable is intialized, the application must call \ref pass_service_init() 52 * to add Phone Alert Status Service and Alert Status, Ringer Setting and Ringer Control Point 53 * characteristics to the BLE Stack database according to \ref pass_init_t.char_mask. 54 */ 55 56 #ifndef __PASS_H__ 57 #define __PASS_H__ 58 59 #include <stdint.h> 60 #include <stdbool.h> 61 #include "gr55xx_sys.h" 62 #include "custom_config.h" 63 64 /** 65 * @defgroup PASS_MACRO Defines 66 * @{ 67 */ 68 #define PASS_CONNECTION_MAX (10 < CFG_MAX_CONNECTIONS ? \ 69 10 : CFG_MAX_CONNECTIONS) /**< Maximum number of Phone Alert Status Service connections. */ 70 #define PASS_ALERT_STATUS_VAL_LEN 1 /**< Length of Alert Status value. */ 71 #define PASS_RINGER_SET_VAL_LEN 1 /**< Length of Ringer Setting value. */ 72 #define PASS_RINGER_CTRL_PT_VAL_LEN 1 /**< Length of Ringer Control Point value. */ 73 74 /** 75 * @defgroup PASS_CHAR_MASK Characteristics Mask 76 * @{ 77 * @brief Bit masks for the initialization of \ref pass_init_t.char_mask. 78 */ 79 #define PASS_CHAR_MANDATORY 0x003f /**< Bit mask for mandatory characteristic in PASS. */ 80 #define PASS_CHAR_RING_CTRL_PT_SUP 0x0180 /**< Bit mask for Ringer Control Point characteristic in PASS. */ 81 #define PASS_CHAR_FULL 0x01ff /**< Bit mask of the full characteristic. */ 82 /** @} */ 83 84 /** 85 * @defgroup PASS_ALERT_STATUES_BIT Alert Status BIT 86 * @{ 87 * @brief PASS Alert Status bits. 88 */ 89 #define PASS_NO_STATE_ACTIVE (0x00) /**< Bit for no state active. */ 90 #define PASS_RINGER_ACTIVE (0x01 << 0) /**< Bit for ringer State active. */ 91 #define PASS_VIBRATE_ACTIVE (0x01 << 1) /**< Bit for vibrate State active. */ 92 #define PASS_DISPLAY_ALERT_ACTIVE (0x01 << 2) /**< Bit for display Alert Status State active. */ 93 #define PASS_ALL_STATE_ACTIVE (0x07) /**< Bit for no state active. */ 94 /** @} */ 95 96 /** 97 * @defgroup PASS_RINGER_SETTING Ringer Setting 98 * @{ 99 * @brief The Ringer Setting characteristic defines the setting of the ringer. 100 */ 101 #define PASS_RINGER_SET_SILENT 0 /**< Ringer Silent. */ 102 #define PASS_RINGER_SET_NORMAL 1 /**< Ringer Normal. */ 103 /** @} */ 104 /** @} */ 105 106 /** 107 * @defgroup PASS_ENUM Enumerations 108 * @{ 109 */ 110 /**@brief Phone Alert Status Service Ringer Control Point. */ 111 typedef enum { 112 PASS_CTRL_PT_SILENT_MODE = 0x01, /**< Silent Mode. */ 113 PASS_CTRL_PT_MUTE_ONCE, /**< Mute Once. */ 114 PASS_CTRL_PT_CANCEL_SLIENT_MODE, /**< Cancel Silent Mode. */ 115 } pass_ringer_ctrl_pt_t; 116 117 /**@brief Phone Alert Status Service event type. */ 118 typedef enum { 119 PASS_EVT_INVALID, /**< Invalid PASS event type. */ 120 PASS_EVT_ALERT_STATUS_NTF_ENABLE, /**< Alert Status notification is enabled. */ 121 PASS_EVT_ALERT_STATUS_NTF_DISABLE, /**< Alert Status notification is disabled. */ 122 PASS_EVT_RINGER_SET_NTF_ENABLE, /**< Ringer Setting notification is enabled. */ 123 PASS_EVT_RINGER_SET_NTF_DISABLE, /**< Ringer Setting notification is disabled. */ 124 PASS_EVT_SILENT_MODE_SET, /**< Set silent mode. */ 125 PASS_EVT_MUTE_ONCE_SET, /**< Set mute once. */ 126 PASS_EVT_SILENT_MODE_CANCEL, /**< Cancel silent mode. */ 127 } pass_evt_type_t; 128 /** @} */ 129 130 /** 131 * @defgroup PASS_STRUCT Structures 132 * @{ 133 */ 134 /**@brief Phone Alert Status Service event. */ 135 typedef struct { 136 uint8_t conn_idx; /**< The index of the connection. */ 137 pass_evt_type_t evt_type; /**< The CTS event type. */ 138 } pass_evt_t; 139 /** @} */ 140 141 /** 142 * @defgroup PASS_TYPEDEF Typedefs 143 * @{ 144 */ 145 /**@brief Phone Alert Status Service event handler type.*/ 146 typedef void (*pass_evt_handler_t)(pass_evt_t *p_evt); 147 /** @} */ 148 149 /** 150 * @defgroup PASS_STRUCT Structures 151 * @{ 152 */ 153 /**@brief Phone Alert Status Service init stucture. 154 * This contains all option and data needed for initialization of the service. */ 155 typedef struct { 156 pass_evt_handler_t evt_handler; /**< Phone Alert Status Service event handler. */ 157 uint16_t 158 char_mask; /**< Initial mask of supported characteristics, and configured with \ref PASS_CHAR_MASK. */ 159 uint8_t alert_status; /**< Initial alert status. */ 160 uint8_t ringer_setting; /**< Initial ringer setting. */ 161 } pass_init_t; 162 /** @} */ 163 164 /** 165 * @defgroup PASS_FUNCTION Functions 166 * @{ 167 */ 168 /** 169 ***************************************************************************************** 170 * @brief Initialize a Phone Alert Status Service instance and add in the DB. 171 * 172 * @param[in] p_pass_init: Pointer to PASS Service initialization variable. 173 * 174 * @return Result of service initialization. 175 ***************************************************************************************** 176 */ 177 sdk_err_t pass_service_init(pass_init_t *p_pass_init); 178 179 /** 180 ***************************************************************************************** 181 * @brief Get Ringer Setting value. 182 * 183 * @return Current Ringer Setting value. 184 ***************************************************************************************** 185 */ 186 uint8_t pass_ringer_setting_get(void); 187 188 /** 189 ***************************************************************************************** 190 * @brief Set Ringer Setting value. 191 * 192 * @param[in] conn_idx: Connnection index. 193 * @param[in] new_setting: New Ringer Setting value. 194 ***************************************************************************************** 195 */ 196 void pass_ringer_setting_set(uint8_t conn_idx, uint8_t new_setting); 197 198 /** 199 ***************************************************************************************** 200 * @brief Set Alert Status value. 201 * 202 * @param[in] conn_idx: Connnection index. 203 * @param[in] new_status: New Alert Status value. 204 ***************************************************************************************** 205 */ 206 void pass_alert_status_set(uint8_t conn_idx, uint8_t new_status); 207 /** @} */ 208 209 #endif 210 /** @} */ 211 /** @} */ 212 213