| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: bkpd.h $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/8 $ |
|---|
| 12 | * $brcm_Date: 9/15/04 12:06p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: /magnum/portinginterface/kpd/7038/bkpd.h $ |
|---|
| 19 | * |
|---|
| 20 | * Hydra_Software_Devel/8 9/15/04 12:06p brianlee |
|---|
| 21 | * PR12504: Added function to allow user to install interrupt callback. |
|---|
| 22 | * |
|---|
| 23 | * Hydra_Software_Devel/8 9/15/04 11:51a brianlee |
|---|
| 24 | * PR12504: Added function to allow user to install interrupt callback. |
|---|
| 25 | * |
|---|
| 26 | * Hydra_Software_Devel/8 9/15/04 11:51a brianlee |
|---|
| 27 | * PR12504: Added function to allow user to install interrupt callback. |
|---|
| 28 | * |
|---|
| 29 | * Hydra_Software_Devel/8 9/15/04 11:50a brianlee |
|---|
| 30 | * PR12504: Added function to allow user to install interrupt callback. |
|---|
| 31 | * |
|---|
| 32 | * Hydra_Software_Devel/7 11/6/03 4:09p lseverin |
|---|
| 33 | * updated module overview for DocJet format |
|---|
| 34 | * |
|---|
| 35 | * Hydra_Software_Devel/6 10/1/03 11:41a brianlee |
|---|
| 36 | * Fixed sample code. |
|---|
| 37 | * |
|---|
| 38 | * Hydra_Software_Devel/5 9/25/03 12:05p brianlee |
|---|
| 39 | * Fixed tags for Midas service generator. |
|---|
| 40 | * |
|---|
| 41 | * Hydra_Software_Devel/4 9/23/03 11:40a brianlee |
|---|
| 42 | * Added polling option. |
|---|
| 43 | * |
|---|
| 44 | * Hydra_Software_Devel/3 8/20/03 5:13p brianlee |
|---|
| 45 | * Added error code for BKPD_Read if there's no key press. |
|---|
| 46 | * |
|---|
| 47 | * Hydra_Software_Devel/2 7/31/03 6:02p brianlee |
|---|
| 48 | * Added GetEventHandle() function. |
|---|
| 49 | * |
|---|
| 50 | * Hydra_Software_Devel/1 7/25/03 11:27a brianlee |
|---|
| 51 | * Initial version. |
|---|
| 52 | * |
|---|
| 53 | ***************************************************************************/ |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | /*= Module Overview ********************************************************* |
|---|
| 57 | <verbatim> |
|---|
| 58 | |
|---|
| 59 | Overview |
|---|
| 60 | The KPD PI module controls the keypad controller within the BCM7038-B0. The |
|---|
| 61 | keypad controller (along with the LED controller) is not available in the |
|---|
| 62 | BCM7038-A0 version. |
|---|
| 63 | |
|---|
| 64 | Design |
|---|
| 65 | The design for BKPD PI API is broken into three parts. |
|---|
| 66 | |
|---|
| 67 | o Part 1 (open/close/configuration): |
|---|
| 68 | |
|---|
| 69 | These APIs are used for opening and closing BKPD device. |
|---|
| 70 | |
|---|
| 71 | o Part 2 (wait for key press): |
|---|
| 72 | |
|---|
| 73 | These APIs are used to scan for key presses. |
|---|
| 74 | |
|---|
| 75 | o Part 3 (get the data): |
|---|
| 76 | |
|---|
| 77 | These APIs are used to read the data from the keypad. |
|---|
| 78 | |
|---|
| 79 | Usage |
|---|
| 80 | The usage of BKPD involves the following: |
|---|
| 81 | |
|---|
| 82 | * Configure/Open of BKPD |
|---|
| 83 | |
|---|
| 84 | * Configure BKPD device for the target system |
|---|
| 85 | * Open BKPD device |
|---|
| 86 | |
|---|
| 87 | * Wait for key press |
|---|
| 88 | |
|---|
| 89 | * Read the data |
|---|
| 90 | |
|---|
| 91 | Sample Code |
|---|
| 92 | void main( void ) |
|---|
| 93 | { |
|---|
| 94 | BKPD_Handle hKPD; |
|---|
| 95 | BKPD_Settings defSettings; |
|---|
| 96 | BREG_Handle hReg; |
|---|
| 97 | BCHP_Handle hChip; |
|---|
| 98 | BINT_Handle hInt; |
|---|
| 99 | bool keyReady = FALSE; |
|---|
| 100 | uint16_t key; |
|---|
| 101 | |
|---|
| 102 | // Do other initialization, i.e. for BREG, BCHP, etc. |
|---|
| 103 | |
|---|
| 104 | // Now, ready to setup the BKPD |
|---|
| 105 | BKPD_GetDefaultSettings( &defSettings, hChip ); |
|---|
| 106 | |
|---|
| 107 | // Make any changes required from the default values |
|---|
| 108 | defSettings.prescale = 0x60; |
|---|
| 109 | defSettings.debounce = 0x40; |
|---|
| 110 | |
|---|
| 111 | BKPD_Open (&hKPD, hChip, hReg, hInt, &defSettings); |
|---|
| 112 | |
|---|
| 113 | // Wait for a key to be hit |
|---|
| 114 | do |
|---|
| 115 | { |
|---|
| 116 | BKPD_IsDataReady (hKPD, &keyReady); |
|---|
| 117 | } |
|---|
| 118 | while (keyReady == FALSE); |
|---|
| 119 | |
|---|
| 120 | // key is now ready, go read it |
|---|
| 121 | BKPD_Read (hKPD, &key); |
|---|
| 122 | |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | </verbatim> |
|---|
| 126 | ***************************************************************************/ |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | #ifndef BKPD_H__ |
|---|
| 130 | #define BKPD_H__ |
|---|
| 131 | |
|---|
| 132 | #include "bchp.h" |
|---|
| 133 | #include "breg_mem.h" |
|---|
| 134 | #include "bint.h" |
|---|
| 135 | #include "bkni.h" |
|---|
| 136 | #include "berr_ids.h" |
|---|
| 137 | |
|---|
| 138 | #ifdef __cplusplus |
|---|
| 139 | extern "C" { |
|---|
| 140 | #endif |
|---|
| 141 | |
|---|
| 142 | /*************************************************************************** |
|---|
| 143 | Summary: |
|---|
| 144 | Error Codes specific to BKPD |
|---|
| 145 | |
|---|
| 146 | Description: |
|---|
| 147 | |
|---|
| 148 | See Also: |
|---|
| 149 | |
|---|
| 150 | ****************************************************************************/ |
|---|
| 151 | #define BKPD_ERR_NO_KEY BERR_MAKE_CODE(BERR_KPD_ID, 0) /* no key press */ |
|---|
| 152 | |
|---|
| 153 | /*************************************************************************** |
|---|
| 154 | Summary: |
|---|
| 155 | The handle for kpd module. |
|---|
| 156 | |
|---|
| 157 | Description: |
|---|
| 158 | |
|---|
| 159 | See Also: |
|---|
| 160 | BKPD_Open() |
|---|
| 161 | |
|---|
| 162 | ****************************************************************************/ |
|---|
| 163 | typedef struct BKPD_P_Handle *BKPD_Handle; |
|---|
| 164 | |
|---|
| 165 | /*************************************************************************** |
|---|
| 166 | Summary: |
|---|
| 167 | Required default settings structure for KPD module. |
|---|
| 168 | |
|---|
| 169 | Description: |
|---|
| 170 | The default setting structure defines the default configure of |
|---|
| 171 | KPD when the device is opened. |
|---|
| 172 | |
|---|
| 173 | See Also: |
|---|
| 174 | BKPD_Open() |
|---|
| 175 | |
|---|
| 176 | ****************************************************************************/ |
|---|
| 177 | typedef struct BKPD_Settings |
|---|
| 178 | { |
|---|
| 179 | uint32_t prescale; /* 27mhz clock prescale value */ |
|---|
| 180 | uint8_t debounce; /* debounce count */ |
|---|
| 181 | bool intMode; /* interrupt enable */ |
|---|
| 182 | } BKPD_Settings; |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | /*************************************************************************** |
|---|
| 186 | Summary: |
|---|
| 187 | Callback function for BKPD |
|---|
| 188 | |
|---|
| 189 | Description: |
|---|
| 190 | The callback function is registered by the caller. It gets called |
|---|
| 191 | when KPD interrupt happens. |
|---|
| 192 | |
|---|
| 193 | See Also: |
|---|
| 194 | BKPD_InstallInterruptCallback() |
|---|
| 195 | |
|---|
| 196 | ****************************************************************************/ |
|---|
| 197 | typedef void (*BKPD_CallbackFunc)( void *pParm1, int parm2, void *pKPD_data); |
|---|
| 198 | |
|---|
| 199 | /*************************************************************************** |
|---|
| 200 | Summary: |
|---|
| 201 | Callback info structure |
|---|
| 202 | |
|---|
| 203 | Description: |
|---|
| 204 | This is the callback information structure. Caller registers this |
|---|
| 205 | information with module to be called at interrupt time. |
|---|
| 206 | |
|---|
| 207 | See Also: |
|---|
| 208 | BKPD_InstallInterruptCallback() |
|---|
| 209 | |
|---|
| 210 | ****************************************************************************/ |
|---|
| 211 | typedef struct BKPD_CallbackInfo |
|---|
| 212 | { |
|---|
| 213 | BKPD_CallbackFunc cbFunc ; |
|---|
| 214 | void *pParm1 ; |
|---|
| 215 | int parm2 ; |
|---|
| 216 | } BKPD_CallbackInfo; |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | /*************************************************************************** |
|---|
| 220 | Summary: |
|---|
| 221 | This function opens KPD module. |
|---|
| 222 | |
|---|
| 223 | Description: |
|---|
| 224 | This function is responsible for opening BKPD module. When BKPD is |
|---|
| 225 | opened, it will create a module handle and configure the module based |
|---|
| 226 | on the default settings. Once the device is opened, it must be closed |
|---|
| 227 | before it can be opened again. |
|---|
| 228 | |
|---|
| 229 | Returns: |
|---|
| 230 | TODO: |
|---|
| 231 | |
|---|
| 232 | See Also: |
|---|
| 233 | BKPD_Close() |
|---|
| 234 | BKPD_GetDefaultSettings() |
|---|
| 235 | |
|---|
| 236 | ****************************************************************************/ |
|---|
| 237 | BERR_Code BKPD_Open( |
|---|
| 238 | BKPD_Handle *pKPD, /* [out] Returns handle */ |
|---|
| 239 | BCHP_Handle hChip, /* [in] Chip handle */ |
|---|
| 240 | BREG_Handle hRegister, /* [in] Register handle */ |
|---|
| 241 | BINT_Handle hInterrupt, /* [in] Interrupt handle */ |
|---|
| 242 | const BKPD_Settings *pDefSettings /* [in] Default settings */ |
|---|
| 243 | ); |
|---|
| 244 | |
|---|
| 245 | /*************************************************************************** |
|---|
| 246 | Summary: |
|---|
| 247 | This function closes KPD module. |
|---|
| 248 | |
|---|
| 249 | Description: |
|---|
| 250 | This function is responsible for closing BKPD module. Closing BKPD |
|---|
| 251 | will free main BKPD handle. |
|---|
| 252 | |
|---|
| 253 | Returns: |
|---|
| 254 | TODO: |
|---|
| 255 | |
|---|
| 256 | See Also: |
|---|
| 257 | BKPD_Open() |
|---|
| 258 | |
|---|
| 259 | ****************************************************************************/ |
|---|
| 260 | BERR_Code BKPD_Close( |
|---|
| 261 | BKPD_Handle hDev /* [in] Device handle */ |
|---|
| 262 | ); |
|---|
| 263 | |
|---|
| 264 | /*************************************************************************** |
|---|
| 265 | Summary: |
|---|
| 266 | This function returns the default settings for KPD module. |
|---|
| 267 | |
|---|
| 268 | Description: |
|---|
| 269 | This function is responsible for returns the default setting for |
|---|
| 270 | BKPD module. The returning default setting should be when |
|---|
| 271 | opening the device. |
|---|
| 272 | |
|---|
| 273 | Returns: |
|---|
| 274 | TODO: |
|---|
| 275 | |
|---|
| 276 | See Also: |
|---|
| 277 | BKPD_Open() |
|---|
| 278 | |
|---|
| 279 | ****************************************************************************/ |
|---|
| 280 | BERR_Code BKPD_GetDefaultSettings( |
|---|
| 281 | BKPD_Settings *pDefSettings, /* [out] Returns default setting */ |
|---|
| 282 | BCHP_Handle hChip /* [in] Chip handle */ |
|---|
| 283 | ); |
|---|
| 284 | |
|---|
| 285 | /*************************************************************************** |
|---|
| 286 | Summary: |
|---|
| 287 | This function checks for a key press |
|---|
| 288 | |
|---|
| 289 | Description: |
|---|
| 290 | This function is used to check for a key press. |
|---|
| 291 | |
|---|
| 292 | Returns: |
|---|
| 293 | TODO: |
|---|
| 294 | |
|---|
| 295 | See Also: |
|---|
| 296 | |
|---|
| 297 | |
|---|
| 298 | ****************************************************************************/ |
|---|
| 299 | BERR_Code BKPD_IsDataReady ( |
|---|
| 300 | BKPD_Handle hKpd, /* [in] Device handle */ |
|---|
| 301 | bool *ready /* [out] flag indicating key is pressed */ |
|---|
| 302 | ); |
|---|
| 303 | |
|---|
| 304 | /*************************************************************************** |
|---|
| 305 | Summary: |
|---|
| 306 | This function reads the data from the keypad. |
|---|
| 307 | |
|---|
| 308 | Description: |
|---|
| 309 | This function is used to get the key that was pressed. |
|---|
| 310 | |
|---|
| 311 | Returns: |
|---|
| 312 | BKPD_ERR_NO_KEY if there is no key press. |
|---|
| 313 | |
|---|
| 314 | See Also: |
|---|
| 315 | |
|---|
| 316 | |
|---|
| 317 | ****************************************************************************/ |
|---|
| 318 | BERR_Code BKPD_Read ( |
|---|
| 319 | BKPD_Handle hKpd, /* [in] Device handle */ |
|---|
| 320 | uint16_t *pData /* [out] pointer to data read from keypad */ |
|---|
| 321 | ); |
|---|
| 322 | |
|---|
| 323 | /*************************************************************************** |
|---|
| 324 | Summary: |
|---|
| 325 | This function installs user-specified interrupt callback function |
|---|
| 326 | |
|---|
| 327 | Description: |
|---|
| 328 | This function is used to install an interrupt callback function. |
|---|
| 329 | |
|---|
| 330 | Returns: |
|---|
| 331 | BERR_SUCCESS |
|---|
| 332 | |
|---|
| 333 | See Also: |
|---|
| 334 | |
|---|
| 335 | |
|---|
| 336 | ****************************************************************************/ |
|---|
| 337 | BERR_Code BKPD_InstallInterruptCallback ( |
|---|
| 338 | BKPD_Handle hKpd, /* [in] Device handle */ |
|---|
| 339 | BKPD_CallbackFunc callback, /* [in] callback function */ |
|---|
| 340 | void *pParm1, /* [in] application specified parameter */ |
|---|
| 341 | int parm2 /* [in] application specified parameter */ |
|---|
| 342 | ); |
|---|
| 343 | |
|---|
| 344 | /*************************************************************************** |
|---|
| 345 | Summary: |
|---|
| 346 | This function uninstalls user-specified interrupt callback function |
|---|
| 347 | |
|---|
| 348 | Description: |
|---|
| 349 | This function is used to uninstall an interrupt callback function. |
|---|
| 350 | |
|---|
| 351 | Returns: |
|---|
| 352 | BERR_SUCCESS |
|---|
| 353 | |
|---|
| 354 | See Also: |
|---|
| 355 | |
|---|
| 356 | |
|---|
| 357 | ****************************************************************************/ |
|---|
| 358 | BERR_Code BKPD_UnInstallInterruptCallback ( |
|---|
| 359 | BKPD_Handle hKpd /* [in] Device handle */ |
|---|
| 360 | ); |
|---|
| 361 | |
|---|
| 362 | /*************************************************************************** |
|---|
| 363 | Summary: |
|---|
| 364 | This function gets the event handle for BKPD module. |
|---|
| 365 | |
|---|
| 366 | Description: |
|---|
| 367 | This function is responsible for getting the event handle. The |
|---|
| 368 | application code should use this function get BKPD's event handle, |
|---|
| 369 | which the application should use to pend on. The KPD ISR will |
|---|
| 370 | set the event. |
|---|
| 371 | |
|---|
| 372 | Returns: |
|---|
| 373 | TODO: |
|---|
| 374 | |
|---|
| 375 | See Also: |
|---|
| 376 | |
|---|
| 377 | ****************************************************************************/ |
|---|
| 378 | BERR_Code BKPD_GetEventHandle( |
|---|
| 379 | BKPD_Handle hKpd, /* [in] Device handle */ |
|---|
| 380 | BKNI_EventHandle *phEvent /* [out] Returns event handle */ |
|---|
| 381 | ); |
|---|
| 382 | |
|---|
| 383 | #ifdef __cplusplus |
|---|
| 384 | } |
|---|
| 385 | #endif |
|---|
| 386 | |
|---|
| 387 | #endif |
|---|
| 388 | |
|---|
| 389 | |
|---|
| 390 | |
|---|