nu_adc.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /**************************************************************************//**
  2. * @file adc.h
  3. * @brief N9H30 ADC driver header file
  4. *
  5. * @note
  6. * SPDX-License-Identifier: Apache-2.0
  7. * Copyright (C) 2018 Nuvoton Technology Corp. All rights reserved.
  8. *****************************************************************************/
  9. #ifndef __NU_ADC_H__
  10. #define __NU_ADC_H__
  11. #ifdef __cplusplus
  12. extern "C"
  13. {
  14. #endif
  15. /** @addtogroup N9H30_Device_Driver N9H30 Device Driver
  16. @{
  17. */
  18. /** @addtogroup N9H30_ADC_Driver ADC Driver
  19. @{
  20. */
  21. /** @addtogroup N9H30_ADC_EXPORTED_CONSTANTS ADC Exported Constants
  22. @{
  23. */
  24. #define ADC_ERR_ARGS 1 /*!< The arguments is wrong */
  25. #define ADC_ERR_CMD 2 /*!< The command is wrong */
  26. /// @cond HIDDEN_SYMBOLS
  27. typedef int32_t(*ADC_CALLBACK)(uint32_t status, uint32_t userData);
  28. /// @endcond HIDDEN_SYMBOLS
  29. /*---------------------------------------------------------------------------------------------------------*/
  30. /* ADC_CTL constant definitions */
  31. /*---------------------------------------------------------------------------------------------------------*/
  32. #define ADC_CTL_ADEN 0x00000001 /*!< ADC Power Control */
  33. #define ADC_CTL_VBGEN 0x00000002 /*!< ADC Internal Bandgap Power Control */
  34. #define ADC_CTL_PWKPEN 0x00000004 /*!< ADC Keypad Power Enable Control */
  35. #define ADC_CTL_MST 0x00000100 /*!< Menu Start Conversion */
  36. #define ADC_CTL_PEDEEN 0x00000200 /*!< Pen Down Event Enable */
  37. #define ADC_CTL_WKPEN 0x00000400 /*!< Keypad Press Wake Up Enable */
  38. #define ADC_CTL_WKTEN 0x00000800 /*!< Touch Wake Up Enable */
  39. #define ADC_CTL_WMSWCH 0x00010000 /*!< Wire Mode Switch For 5-Wire/4-Wire Configuration */
  40. /*---------------------------------------------------------------------------------------------------------*/
  41. /* ADC_CONF constant definitions */
  42. /*---------------------------------------------------------------------------------------------------------*/
  43. #define ADC_CONF_TEN 0x00000001 /*!< Touch Enable */
  44. #define ADC_CONF_ZEN 0x00000002 /*!< Press Enable */
  45. #define ADC_CONF_NACEN 0x00000004 /*!< Normal AD Conversion Enable */
  46. #define ADC_CONF_VBATEN 0x00000100 /*!< Voltage Battery Enable */
  47. #define ADC_CONF_KPCEN 0x00000200 /*!< Keypad Press Conversion Enable */
  48. #define ADC_CONF_SELFTEN 0x00000400 /*!< Selft Test Enable */
  49. #define ADC_CONF_DISTMAVEN (1<<20) /*!< Display T Mean Average Enable */
  50. #define ADC_CONF_DISZMAVEN (1<<21) /*!< Display Z Mean Average Enable */
  51. #define ADC_CONF_HSPEED (1<<22) /*!< High Speed Enable */
  52. #define ADC_CONF_CHSEL_Pos 3 /*!< Channel Selection Position */
  53. #define ADC_CONF_CHSEL_Msk (7<<3) /*!< Channel Selection Mask */
  54. #define ADC_CONF_CHSEL_VBT (0<<3) /*!< ADC input channel select VBT */
  55. #define ADC_CONF_CHSEL_VHS (1<<3) /*!< ADC input channel select VHS */
  56. #define ADC_CONF_CHSEL_A2 (2<<3) /*!< ADC input channel select A2 */
  57. #define ADC_CONF_CHSEL_A3 (3<<3) /*!< ADC input channel select A3 */
  58. #define ADC_CONF_CHSEL_YM (4<<3) /*!< ADC input channel select YM */
  59. #define ADC_CONF_CHSEL_YP (5<<3) /*!< ADC input channel select YP */
  60. #define ADC_CONF_CHSEL_XM (6<<3) /*!< ADC input channel select XM */
  61. #define ADC_CONF_CHSEL_XP (7<<3) /*!< ADC input channel select XP */
  62. #define ADC_CONF_REFSEL_Pos 6 /*!< Reference Selection Position */
  63. #define ADC_CONF_REFSEL_Msk (3<<6) /*!< Reference Selection Mask */
  64. #define ADC_CONF_REFSEL_VREF (0<<6) /*!< ADC reference select VREF input or 2.5v buffer output */
  65. #define ADC_CONF_REFSEL_YMYP (1<<6) /*!< ADC reference select YM vs YP */
  66. #define ADC_CONF_REFSEL_XMXP (2<<6) /*!< ADC reference select XM vs XP */
  67. #define ADC_CONF_REFSEL_AVDD33 (3<<6) /*!< ADC reference select AGND33 vs AVDD33 */
  68. /*---------------------------------------------------------------------------------------------------------*/
  69. /* ADC_IER constant definitions */
  70. /*---------------------------------------------------------------------------------------------------------*/
  71. #define ADC_IER_MIEN 0x00000001 /*!< Menu Interrupt Enable */
  72. #define ADC_IER_KPEIEN 0x00000002 /*!< Keypad Press Event Interrupt Enable */
  73. #define ADC_IER_PEDEIEN 0x00000004 /*!< Pen Down Even Interrupt Enable */
  74. #define ADC_IER_WKTIEN 0x00000008 /*!< Wake Up Touch Interrupt Enable */
  75. #define ADC_IER_WKPIEN 0x00000010 /*!< Wake Up Keypad Press Interrupt Enable */
  76. #define ADC_IER_KPUEIEN 0x00000020 /*!< Keypad Press Up Event Interrupt Enable */
  77. #define ADC_IER_PEUEIEN 0x00000040 /*!< Pen Up Event Interrupt Enable */
  78. /*---------------------------------------------------------------------------------------------------------*/
  79. /* ADC_ISR constant definitions */
  80. /*---------------------------------------------------------------------------------------------------------*/
  81. #define ADC_ISR_MF 0x00000001 /*!< Menu Complete Flag */
  82. #define ADC_ISR_KPEF 0x00000002 /*!< Keypad Press Event Flag */
  83. #define ADC_ISR_PEDEF 0x00000004 /*!< Pen Down Event Flag */
  84. #define ADC_ISR_KPUEF 0x00000008 /*!< Keypad Press Up Event Flag */
  85. #define ADC_ISR_PEUEF 0x00000010 /*!< Pen Up Event Flag */
  86. #define ADC_ISR_TF 0x00000100 /*!< Touch Conversion Finish */
  87. #define ADC_ISR_ZF 0x00000200 /*!< Press Conversion Finish */
  88. #define ADC_ISR_NACF 0x00000400 /*!< Normal AD Conversion Finish */
  89. #define ADC_ISR_VBF 0x00000800 /*!< Voltage Battery Conversion Finish */
  90. #define ADC_ISR_KPCF 0x00001000 /*!< Keypad Press Conversion Finish */
  91. #define ADC_ISR_SELFTF 0x00002000 /*!< Self-Test Conversion Finish */
  92. #define ADC_ISR_INTKP 0x00010000 /*!< Interrupt Signal For Keypad Detection */
  93. #define ADC_ISR_INTTC 0x00020000 /*!< Interrupt Signal For Touch Screen Touching Detection */
  94. /*---------------------------------------------------------------------------------------------------------*/
  95. /* ADC_WKISR constant definitions */
  96. /*---------------------------------------------------------------------------------------------------------*/
  97. #define ADC_WKISR_WKPEF 0x00000001 /*!< Wake Up Pen Down Event Flag */
  98. #define ADC_WKISR_WPEDEF 0x00000002 /*!< Wake Up Keypad Press Event Flage */
  99. /** \brief Structure type of ADC_CHAN
  100. */
  101. typedef enum
  102. {
  103. AIN0 = ADC_CONF_CHSEL_VBT, /*!< ADC input channel select \ref ADC_CONF_CHSEL_VBT */
  104. AIN1 = ADC_CONF_CHSEL_VHS, /*!< ADC input channel select \ref ADC_CONF_CHSEL_VHS */
  105. AIN2 = ADC_CONF_CHSEL_A2, /*!< ADC input channel select \ref ADC_CONF_CHSEL_A2 */
  106. AIN3 = ADC_CONF_CHSEL_A3, /*!< ADC input channel select \ref ADC_CONF_CHSEL_A3 */
  107. AIN4 = ADC_CONF_CHSEL_YM, /*!< ADC input channel select \ref ADC_CONF_CHSEL_YM */
  108. AIN5 = ADC_CONF_CHSEL_XP, /*!< ADC input channel select \ref ADC_CONF_CHSEL_XP */
  109. AIN6 = ADC_CONF_CHSEL_XM, /*!< ADC input channel select \ref ADC_CONF_CHSEL_XM */
  110. AIN7 = ADC_CONF_CHSEL_XP /*!< ADC input channel select \ref ADC_CONF_CHSEL_XP */
  111. } ADC_CHAN;
  112. /** \brief Structure type of ADC_CMD
  113. */
  114. typedef enum
  115. {
  116. START_MST, /*!<Menu Start Conversion with interrupt */
  117. START_MST_POLLING, /*!<Menu Start Conversion with polling */
  118. VBPOWER_ON, /*!<Enable ADC Internal Bandgap Power */
  119. VBPOWER_OFF, /*!<Disable ADC Internal Bandgap Power */
  120. VBAT_ON, /*!<Enable Voltage Battery conversion function */
  121. VBAT_OFF, /*!<Disable Voltage Battery conversion function */
  122. KPPOWER_ON, /*!<Enable ADC Keypad power */
  123. KPPOWER_OFF, /*!<Disable ADC Keypad power */
  124. KPCONV_ON, /*!<Enable Keypad conversion function */
  125. KPCONV_OFF, /*!<Disable Keypad conversion function */
  126. KPPRESS_ON, /*!<Enable Keypad press event */
  127. KPPRESS_OFF, /*!<Disable Keypad press event */
  128. KPUP_ON, /*!<Enable Keypad up event */
  129. KPUP_OFF, /*!<Disable Keypad up event */
  130. PEPOWER_ON, /*!<Enable Pen Down Power ,It can control pen down event */
  131. PEPOWER_OFF, /*!<Disable Pen Power */
  132. PEDEF_ON, /*!<Enable Pen Down Event Flag */
  133. PEDEF_OFF, /*!<Disable Pen Down Event Flag */
  134. WKP_ON, /*!<Enable Keypad Press Wake Up */
  135. WKP_OFF, /*!<Disable Keypad Press Wake Up */
  136. WKT_ON, /*!<Enable Pen Down Wake Up */
  137. WKT_OFF, /*!<Disable Pen Down Wake Up */
  138. SWITCH_5WIRE_ON, /*!<Wire Mode Switch to 5-Wire Configuration */
  139. SWITCH_5WIRE_OFF, /*!<Wire Mode Switch to 4-Wire Configuration */
  140. T_ON, /*!<Enable Touch detection function */
  141. T_OFF, /*!<Disable Touch detection function */
  142. TAVG_ON, /*!<Enable Touch Mean average for X and Y function */
  143. TAVG_OFF, /*!<Disable Touch Mean average for X and Y function */
  144. Z_ON, /*!<Enable Press measure function */
  145. Z_OFF, /*!<Disable Press measure function */
  146. TZAVG_ON, /*!<Enable Pressure Mean average for Z1 and Z2 function */
  147. TZAVG_OFF, /*!<Disable Pressure Mean average for Z1 and Z2 function */
  148. NAC_ON, /*!<Enable Normal AD Conversion */
  149. NAC_OFF, /*!<Disable Normal AD Conversion */
  150. SWITCH_CH, /*!<Switch Channel */
  151. } ADC_CMD;
  152. /*@}*/ /* end of group N9H30_ADC_EXPORTED_CONSTANTS */
  153. /** @addtogroup N9H30_ADC_EXPORTED_FUNCTIONS ADC Exported Functions
  154. @{
  155. */
  156. int adcOpen(void);
  157. int adcOpen2(uint32_t freq);
  158. int adcClose(void);
  159. int adcReadXY(short *bufX, short *bufY, int dataCnt);
  160. int adcReadZ(short *bufZ1, short *bufZ2, int dataCnt);
  161. int adcIoctl(ADC_CMD cmd, int arg1, int arg2);
  162. int adcChangeChannel(int channel);
  163. /*@}*/ /* end of group N9H30_ADC_EXPORTED_FUNCTIONS */
  164. /*@}*/ /* end of group N9H30_ADC_Driver */
  165. /*@}*/ /* end of group N9H30_Device_Driver */
  166. #ifdef __cplusplus
  167. }
  168. #endif
  169. #endif //__NU_ADC_H__