KEY_ATY.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @file KEY_ATY.h
  3. *
  4. * @param Project DEVICE_GENERAL_ATY_LIB
  5. *
  6. * @author ATY
  7. *
  8. * @copyright
  9. * - Copyright 2017 - 2025 MZ-ATY
  10. * - This code follows:
  11. * - MZ-ATY Various Contents Joint Statement -
  12. * <a href="https://mengze.top/MZ-ATY_VCJS">
  13. * https://mengze.top/MZ-ATY_VCJS</a>
  14. * - CC 4.0 BY-NC-SA -
  15. * <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
  16. * https://creativecommons.org/licenses/by-nc-sa/4.0/</a>
  17. * - Your use will be deemed to have accepted the terms of this statement.
  18. *
  19. * @brief functions of keys for all embedded device
  20. *
  21. * @version
  22. * - 1_01_230514 > ATY
  23. * -# Preliminary version, first Release
  24. ********************************************************************************
  25. */
  26. #ifndef __KEY_ATY_H
  27. #define __KEY_ATY_H
  28. #include "INCLUDE_ATY.h"
  29. #include "HW_GPIO_ATY.h"
  30. /******************************* For user *************************************/
  31. // #define __DEBUG_KEY_ATY
  32. #define MAX_KEY_NUMBER 3
  33. #define KEY_INDEX_PW 0
  34. #define KEY_INDEX_UP 1
  35. #define KEY_INDEX_DOWN 2
  36. #define KEY_PORT P2
  37. #define KEY_AD_Threshold 800
  38. extern uint8_t KEY_PIN_GROUP[MAX_KEY_NUMBER];
  39. extern uint8_t KEY_PIN_GROUP_AD[MAX_KEY_NUMBER];
  40. /******************************************************************************/
  41. #define KEY_TYPE_RELASE 0
  42. #define KEY_TYPE_SINGLE 11
  43. #define KEY_TYPE_LONG 21
  44. #define KEY_TYPE_VLONG 22
  45. #define KEY_TYPE_ACCESS_NEW 0xFF
  46. #define KEY_RELEASE_DEBOUNCE_TIME 20
  47. #define KEY_PRESS_DEBOUNCE_TIME 100
  48. #define KEY_TYPE_LONG_TIME 800
  49. #define KEY_TYPE_VLONG_TIME (KEY_TYPE_LONG_TIME * 3)
  50. extern uint8_t lastKeyType[MAX_KEY_NUMBER];
  51. extern uint8_t keyExportType[MAX_KEY_NUMBER];
  52. extern uint16_t keyScanCount[MAX_KEY_NUMBER];
  53. extern uint16_t keyReleaseCount[MAX_KEY_NUMBER];
  54. #define KEY_ACCESS_NEW(index) \
  55. do{ \
  56. if(lastKeyType[index] != KEY_TYPE_RELASE) \
  57. lastKeyType[index] = KEY_TYPE_ACCESS_NEW; \
  58. } while(0)
  59. void KeyStateMachine(uint8_t keyIndex);
  60. float KeyStateMachine_AD(uint8_t keyIndex);
  61. #endif /* __KEY_ATY_H */
  62. /******************************** End Of File *********************************/