key.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**************************************************************************************************
  2. Phyplus Microelectronics Limited confidential and proprietary.
  3. All rights reserved.
  4. IMPORTANT: All rights of this software belong to Phyplus Microelectronics
  5. Limited ("Phyplus"). Your use of this Software is limited to those
  6. specific rights granted under the terms of the business contract, the
  7. confidential agreement, the non-disclosure agreement and any other forms
  8. of agreements as a customer or a partner of Phyplus. You may not use this
  9. Software unless you agree to abide by the terms of these agreements.
  10. You acknowledge that the Software may not be modified, copied,
  11. distributed or disclosed unless embedded on a Phyplus Bluetooth Low Energy
  12. (BLE) integrated circuit, either as a product or is integrated into your
  13. products. Other than for the aforementioned purposes, you may not use,
  14. reproduce, copy, prepare derivative works of, modify, distribute, perform,
  15. display or sell this Software and/or its documentation for any purposes.
  16. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  17. PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  18. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  19. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  20. PHYPLUS OR ITS SUBSIDIARIES BE LIABLE OR OBLIGATED UNDER CONTRACT,
  21. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  22. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  23. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  24. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  25. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  26. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  27. **************************************************************************************************/
  28. /**************************************************************
  29. *
  30. *
  31. * Module Name: key
  32. * File name: key.h
  33. * Brief description:
  34. * key driver module
  35. * Author: Eagle.Lao
  36. * Data: 2017-07-01
  37. * Revision:V0.01
  38. ****************************************************************/
  39. #ifndef __KEY_H__
  40. #define __KEY_H__
  41. #include "types.h"
  42. #include "gpio.h"
  43. #define HAL_KEY_NUM 2 //config key's number
  44. #define HAL_KEY_EVENT 0x0100 //assign short key event in your app event process
  45. #define HAL_KEY_SUPPORT_LONG_PRESS //if use long key,please enable it
  46. #ifdef HAL_KEY_SUPPORT_LONG_PRESS
  47. #define HAL_KEY_LONG_PRESS_TIME 2000 //2s
  48. #endif
  49. #define HAL_KEY_DEBOUNCD 20 //20ms
  50. typedef enum{
  51. HAL_STATE_KEY_IDLE = 0x00,
  52. HAL_STATE_KEY_PRESS_DEBOUNCE = 0x01,
  53. HAL_STATE_KEY_PRESS = 0x02,
  54. HAL_STATE_KEY_RELEASE_DEBOUNCE = 0x03,
  55. }key_state_e;
  56. typedef enum{
  57. HAL_KEY_EVT_IDLE = 0x0000,
  58. HAL_KEY_EVT_PRESS = 0x0002,
  59. HAL_KEY_EVT_RELEASE = 0x0004,
  60. HAL_KEY_EVT_LONG_PRESS = 0x0010,
  61. HAL_KEY_EVT_LONG_RELEASE = 0x0020,
  62. } key_evt_t;
  63. typedef enum{
  64. HAL_LOW_IDLE = 0x00,
  65. HAL_HIGH_IDLE = 0x01,
  66. }idle_level_e;
  67. typedef void (* key_callbank_hdl_t)(uint8_t,key_evt_t);
  68. typedef struct gpio_key_t{
  69. GPIO_Pin_e pin;
  70. key_state_e state;
  71. idle_level_e idle_level;
  72. }gpio_key;
  73. typedef struct gpio_internal_t{
  74. uint32_t timer_tick;
  75. bool in_enable;
  76. }gpio_internal;
  77. typedef struct key_state{
  78. gpio_key key[HAL_KEY_NUM];
  79. gpio_internal temp[HAL_KEY_NUM];
  80. uint8_t task_id;
  81. key_callbank_hdl_t key_callbank;
  82. }key_contex_t;
  83. void key_init(void);
  84. void gpio_key_timer_handler(uint8 index);
  85. extern key_contex_t key_state;
  86. #endif