air105_sensor.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. * Copyright (c) 2022 OpenLuat & AirM2M
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. * the Software, and to permit persons to whom the Software is furnished to do so,
  9. * subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  16. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  17. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  18. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. #ifndef __AIR105_SENSOR_H
  22. #define __AIR105_SENSOR_H
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /* Includes ------------------------------------------------------------------*/
  27. #include "air105.h"
  28. typedef struct
  29. {
  30. uint32_t SENSOR_Port_Pull;
  31. uint32_t SENSOR_Port_Static;
  32. uint32_t SENSOR_Port_Dynamic;
  33. FunctionalState SENSOR_Port_Enable;
  34. uint32_t SENSOR_DynamicFrequency;
  35. FunctionalState SENSOR_GlitchEnable;
  36. uint32_t SENSOR_PUPU_Frequency;
  37. uint32_t SENSOR_PUPU_DetectTime;
  38. uint32_t SENSOR_PUPU_HoldTime;
  39. FunctionalState SENSOR_PUPU_Enable;
  40. FunctionalState SENSOR_Trig_Hold_Enable;
  41. uint32_t SENSOR_Dynamic_Sample;
  42. uint32_t SENSOR_Static_Sample;
  43. }SENSOR_EXTInitTypeDef;
  44. #define SENSOR_Port_S0 ((uint32_t)0x0001)
  45. #define SENSOR_Port_S1 ((uint32_t)0x0002)
  46. #define SENSOR_Port_S2 ((uint32_t)0x0004)
  47. #define SENSOR_Port_S3 ((uint32_t)0x0008)
  48. #define SENSOR_Port_S4 ((uint32_t)0x0010)
  49. #define SENSOR_Port_S5 ((uint32_t)0x0020)
  50. #define SENSOR_Port_S6 ((uint32_t)0x0040)
  51. #define SENSOR_Port_S7 ((uint32_t)0x0080)
  52. #define SENSOR_Port_All ((uint32_t)0x00FF)
  53. #define SENSOR_Port_S01 (SENSOR_Port_S0 | SENSOR_Port_S1)
  54. #define SENSOR_Port_S23 (SENSOR_Port_S2 | SENSOR_Port_S3)
  55. #define SENSOR_Port_S45 (SENSOR_Port_S4 | SENSOR_Port_S5)
  56. #define SENSOR_Port_S67 (SENSOR_Port_S6 | SENSOR_Port_S7)
  57. #define IS_SENSOR_PORT(PORT) ((((PORT) & (uint32_t)0xFFFFFF00) == 0x00) && ((PORT) != (uint32_t)0x00))
  58. /* �ⲿ��̬��������������Ƶ�� */
  59. #define SENSOR_PUPU_Frequency_Default ((uint32_t)0x0000)
  60. #define SENSOR_PUPU_Frequency_500ms ((uint32_t)0x0000)
  61. #define SENSOR_PUPU_Frequency_1s ((uint32_t)0x0001)
  62. #define IS_SENSOR_EXT_PUPU_FREQ(FREQ) ((FREQ) == SENSOR_PUPU_Frequency_500ms ||\
  63. (FREQ) == SENSOR_PUPU_Frequency_1s)
  64. /* �ⲿ��̬�������������� */
  65. #define SENSOR_STATIC_SAMPLE_Default ((uint32_t)0x0001)
  66. #define SENSOR_STATIC_SAMPLE_1 ((uint32_t)0x0000)
  67. #define SENSOR_STATIC_SAMPLE_2 ((uint32_t)0x0001)
  68. #define SENSOR_STATIC_SAMPLE_3 ((uint32_t)0x0002)
  69. #define SENSOR_STATIC_SAMPLE_4 ((uint32_t)0x0003)
  70. #define IS_SENSOR_EXT_STATIC_SAMPLE(COUNT) ((COUNT) >= SENSOR_STATIC_SAMPLE_1 &&\
  71. (COUNT) <= SENSOR_STATIC_SAMPLE_4)
  72. /* �ⲿ��̬�������������� */
  73. #define SENSOR_DYNAMIC_SAMPLE_Default ((uint32_t)0x0002)
  74. #define SENSOR_DYNAMIC_SAMPLE_1 ((uint32_t)0x0000)
  75. #define SENSOR_DYNAMIC_SAMPLE_2 ((uint32_t)0x0001)
  76. #define SENSOR_DYNAMIC_SAMPLE_3 ((uint32_t)0x0002)
  77. #define SENSOR_DYNAMIC_SAMPLE_4 ((uint32_t)0x0003)
  78. #define IS_SENSOR_EXT_DYNAMIC_SAMPLE(COUNT) ((COUNT) >= SENSOR_DYNAMIC_SAMPLE_1 &&\
  79. (COUNT) <= SENSOR_DYNAMIC_SAMPLE_4)
  80. /* �ⲿ��̬�����������������裬������Чʱ�� */
  81. #define SENSOR_PUPU_HoldTime_Default ((uint32_t)0x0002)
  82. #define SENSOR_PUPU_HoldTime_1_2 ((uint32_t)0x0000)
  83. #define SENSOR_PUPU_HoldTime_1_4 ((uint32_t)0x0001)
  84. #define SENSOR_PUPU_HoldTime_1_8 ((uint32_t)0x0002)
  85. #define SENSOR_PUPU_HoldTime_1_16 ((uint32_t)0x0003)
  86. #define IS_SENSOR_EXT_PUPU_HOLD_TIME(TIME) ((TIME) == SENSOR_PUPU_HoldTime_1_2 ||\
  87. (TIME) == SENSOR_PUPU_HoldTime_1_4 ||\
  88. (TIME) == SENSOR_PUPU_HoldTime_1_8 ||\
  89. (TIME) == SENSOR_PUPU_HoldTime_1_16)
  90. /* ��̬���������Ƶ�� */
  91. #define SENSOR_DynamicFrequency_Default ((uint32_t)0x0003)
  92. #define SENSOR_DynamicFrequency_31_25ms ((uint32_t)0x0000)
  93. #define SENSOR_DynamicFrequency_125ms ((uint32_t)0x0001)
  94. #define SENSOR_DynamicFrequency_500ms ((uint32_t)0x0002)
  95. #define SENSOR_DynamicFrequency_1s ((uint32_t)0x0003)
  96. #define IS_SENSOR_EXT_DYNAMIC_FREQ(FREQ) ((FREQ) == SENSOR_DynamicFrequency_Default ||\
  97. (FREQ) == SENSOR_DynamicFrequency_31_25ms ||\
  98. (FREQ) == SENSOR_DynamicFrequency_125ms ||\
  99. (FREQ) == SENSOR_DynamicFrequency_500ms ||\
  100. (FREQ) == SENSOR_DynamicFrequency_1s)
  101. #define SENSOR_ANA_VOL_HIGH ((uint32_t)0x00000001)
  102. #define SENSOR_ANA_VOL_LOW ((uint32_t)0x00000002)
  103. #define SENSOR_ANA_TEMPER_HIGH ((uint32_t)0x00000004)
  104. #define SENSOR_ANA_TEMPER_LOW ((uint32_t)0x00000008)
  105. #define SENSOR_ANA_XTAL32K ((uint32_t)0x00000010)
  106. #define SENSOR_ANA_MESH ((uint32_t)0x00000020)
  107. #define SENSOR_ANA_VOLGLITCH ((uint32_t)0x00000040)
  108. #define SENSOR_ANA_ALL ((uint32_t)0x0000007F)
  109. #define IS_SENSOR_ANA(ANA) ((((ANA) & (uint32_t)0xFFFFFF80) == 0x00) && ((ANA) != (uint32_t)0x00))
  110. #define SENSOR_LOCK_EXTS ((uint32_t)0x00000001)
  111. #define SENSOR_LOCK_VOL_HIGH ((uint32_t)0x00000002)
  112. #define SENSOR_LOCK_VOL_LOW ((uint32_t)0x00000004)
  113. #define SENSOR_LOCK_TEMPER_HIGH ((uint32_t)0x00000008)
  114. #define SENSOR_LOCK_TEMPER_LOW ((uint32_t)0x00000010)
  115. #define SENSOR_LOCK_VOLGLITCH ((uint32_t)0x00000020)
  116. #define SENSOR_LOCK_XTAL32K ((uint32_t)0x00000040)
  117. #define SENSOR_LOCK_MESH ((uint32_t)0x00000080)
  118. #define IS_SENSOR_LOCK(LOCK) ((((LOCK) & (uint32_t)0xFFFFFF00) == 0x00) && ((LOCK) != (uint32_t)0x00))
  119. #define SENSOR_IT_EXTS ((uint32_t)0x00000FFF)
  120. #define SENSOR_IT_VOL_HIGH ((uint32_t)0x00001000)
  121. #define SENSOR_IT_VOL_LOW ((uint32_t)0x00002000)
  122. #define SENSOR_IT_TEMPER_HIGH ((uint32_t)0x00004000)
  123. #define SENSOR_IT_TEMPER_LOW ((uint32_t)0x00008000)
  124. #define SENSOR_IT_GLITCH ((uint32_t)0x00010000)
  125. #define SENSOR_IT_XTAL32K ((uint32_t)0x00020000)
  126. #define SENSOR_IT_MESH ((uint32_t)0x00040000)
  127. #define SENSOR_IT_SSC ((uint32_t)0x00100000)
  128. #define IS_SENSOR_IT(IT) ((IT) == SENSOR_IT_EXTS || \
  129. (IT) == SENSOR_IT_VOL_HIGH || \
  130. (IT) == SENSOR_IT_VOL_LOW || \
  131. (IT) == SENSOR_IT_TEMPER_HIGH || \
  132. (IT) == SENSOR_IT_TEMPER_LOW || \
  133. (IT) == SENSOR_IT_GLITCH || \
  134. (IT) == SENSOR_IT_XTAL32K || \
  135. (IT) == SENSOR_IT_MESH || \
  136. (IT) == SENSOR_IT_SSC)
  137. typedef enum
  138. {
  139. SENSOR_CPUReset = 0,
  140. SENSOR_Interrupt = 1
  141. }SENSOR_RespModeTypeDef;
  142. #define IS_SENSOR_RESP_MODE(Mode) ((Mode) == SENSOR_CPUReset ||\
  143. (Mode) == SENSOR_Interrupt)
  144. uint32_t SENSOR_SetRand(uint32_t Rand);
  145. uint32_t SENSOR_EXTInit(SENSOR_EXTInitTypeDef *SENSOR_EXTInitStruct);
  146. uint32_t SENSOR_EXTPortCmd(uint32_t SENSOR_Port, FunctionalState NewState);
  147. uint32_t SENSOR_EXTCmd(FunctionalState NewState);
  148. FlagStatus SENSOR_EXTIsRuning(void);
  149. uint32_t SENSOR_ANACmd(uint32_t SENSOR_ANA, FunctionalState NewState);
  150. void SENSOR_Lock(uint32_t SENSOR_LOCK);
  151. void SENSOR_AttackRespMode(SENSOR_RespModeTypeDef SENSOR_RespMode);
  152. int32_t SENSOR_GetITStatus(uint32_t ITState);
  153. int32_t SENSOR_GetITStatusReg(void);
  154. void SENSOR_ClearITPendingBit(void);
  155. FunctionalState SENSOR_GetEXTTrigPull(void);
  156. FunctionalState SENSOR_SetEXTTrigPull(FunctionalState NewState);
  157. FunctionalState SENSOR_GetEXTFilter(void);
  158. FunctionalState SENSOR_SetEXTFilter(FunctionalState NewState);
  159. #define SENSOR_STATIC_PULSE_PERIOD_500MS (0)
  160. #define SENSOR_STATIC_PULSE_PERIOD_1S (1)
  161. uint32_t SENSOR_GetEXTPulsePeriod(void);
  162. uint32_t SENSOR_SetEXTPulsePeriod(uint32_t u32Period);
  163. #define SENSOR_STATIC_PULSE_HOLD_1_2 (0)
  164. #define SENSOR_STATIC_PULSE_HOLD_1_4 (1)
  165. #define SENSOR_STATIC_PULSE_HOLD_1_8 (2)
  166. #define SENSOR_STATIC_PULSE_HOLD_1_16 (3)
  167. uint32_t SENSOR_GetEXTPulseHold(void);
  168. uint32_t SENSOR_SetEXTPulseHold(uint32_t u32Hold);
  169. FunctionalState SENSOR_GetEXTPulsePull(void);
  170. FunctionalState SENSOR_SetEXTPulsePull(FunctionalState NewState);
  171. #define SENSOR_SAMPLE_COUNT_1 (0)
  172. #define SENSOR_SAMPLE_COUNT_2 (1)
  173. #define SENSOR_SAMPLE_COUNT_3 (2)
  174. #define SENSOR_SAMPLE_COUNT_4 (3)
  175. uint32_t SENSOR_GetEXTStaticSample(void);
  176. uint32_t SENSOR_SetEXTStaticSample(uint32_t u32Count);
  177. uint32_t SENSOR_GetEXTDynamicSample(void);
  178. uint32_t SENSOR_SetEXTDynamicSample(uint32_t u32Count);
  179. uint32_t SENSOR_GetEXTDynamicFreq(void);
  180. uint32_t SENSOR_SetEXTDynamicFreq(uint32_t u32Freq);
  181. #ifdef __cplusplus
  182. }
  183. #endif
  184. #endif
  185. /************************** (C) COPYRIGHT Megahunt *****END OF FILE****/