KEY.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /********************************** (C) COPYRIGHT *******************************
  2. * File Name : KEY.h
  3. * Author : WCH
  4. * Version : V1.0
  5. * Date : 2016/04/12
  6. * Description :
  7. * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
  8. * SPDX-License-Identifier: Apache-2.0
  9. *******************************************************************************/
  10. /******************************************************************************/
  11. #ifndef __KEY_H
  12. #define __KEY_H
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. /**************************************************************************************************
  17. * MACROS
  18. **************************************************************************************************/
  19. #define HAL_KEY_POLLING_VALUE 100
  20. /* Switches (keys) */
  21. #define HAL_KEY_SW_1 0x01 // key1
  22. #define HAL_KEY_SW_2 0x02 // key2
  23. #define HAL_KEY_SW_3 0x04 // key3
  24. #define HAL_KEY_SW_4 0x08 // key4
  25. /* °´¼ü¶¨Òå */
  26. /* 1 - KEY */
  27. #define KEY1_BV BV(22)
  28. #define KEY2_BV BV(4)
  29. #define KEY3_BV ()
  30. #define KEY4_BV ()
  31. #define KEY1_PU (R32_PB_PU |= KEY1_BV)
  32. #define KEY2_PU (R32_PB_PU |= KEY2_BV)
  33. #define KEY3_PU ()
  34. #define KEY4_PU ()
  35. #define KEY1_DIR (R32_PB_DIR &= ~KEY1_BV)
  36. #define KEY2_DIR (R32_PB_DIR &= ~KEY2_BV)
  37. #define KEY3_DIR ()
  38. #define KEY4_DIR ()
  39. #define KEY1_IN (ACTIVE_LOW(R32_PB_PIN & KEY1_BV))
  40. #define KEY2_IN (ACTIVE_LOW(R32_PB_PIN & KEY2_BV))
  41. #define KEY3_IN ()
  42. #define KEY4_IN ()
  43. #define HAL_PUSH_BUTTON1() (KEY1_IN) //Ìí¼Ó×Ô¶¨Òå°´¼ü
  44. #define HAL_PUSH_BUTTON2() (KEY2_IN)
  45. #define HAL_PUSH_BUTTON3() (0)
  46. #define HAL_PUSH_BUTTON4() (0)
  47. /**************************************************************************************************
  48. * TYPEDEFS
  49. **************************************************************************************************/
  50. typedef void (*halKeyCBack_t)(uint8_t keys);
  51. typedef struct
  52. {
  53. uint8_t keys; // keys
  54. } keyChange_t;
  55. /**************************************************************************************************
  56. * GLOBAL VARIABLES
  57. **************************************************************************************************/
  58. /*********************************************************************
  59. * FUNCTIONS
  60. */
  61. /**
  62. * @brief Initialize the Key Service
  63. */
  64. void HAL_KeyInit(void);
  65. /**
  66. * @brief This is for internal used by hal_driver
  67. */
  68. void HAL_KeyPoll(void);
  69. /**
  70. * @brief Configure the Key serivce
  71. *
  72. * @param cback - pointer to the CallBack function
  73. */
  74. void HalKeyConfig(const halKeyCBack_t cback);
  75. /**
  76. * @brief Read the Key callback
  77. */
  78. void HalKeyCallback(uint8_t keys);
  79. /**
  80. * @brief Read the Key status
  81. */
  82. uint8_t HalKeyRead(void);
  83. /**************************************************************************************************
  84. **************************************************************************************************/
  85. #ifdef __cplusplus
  86. }
  87. #endif
  88. #endif