peripheral_hal.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * Copyright (c) 2021 Huawei Device Co., Ltd.
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #ifndef PERIPHERAL_HAL_H
  16. #define PERIPHERAL_HAL_H
  17. #include "ohos_types.h"
  18. /* gpio start */
  19. typedef enum {
  20. /** GPIO hardware pin 0 */
  21. HAL_WIFI_IOT_IO_NAME_GPIO_0,
  22. /** GPIO hardware pin 1 */
  23. HAL_WIFI_IOT_IO_NAME_GPIO_1,
  24. /** GPIO hardware pin 2 */
  25. HAL_WIFI_IOT_IO_NAME_GPIO_2,
  26. /** GPIO hardware pin 3 */
  27. HAL_WIFI_IOT_IO_NAME_GPIO_3,
  28. /** GPIO hardware pin 4 */
  29. HAL_WIFI_IOT_IO_NAME_GPIO_4,
  30. /** GPIO hardware pin 5 */
  31. HAL_WIFI_IOT_IO_NAME_GPIO_5,
  32. /** GPIO hardware pin 6 */
  33. HAL_WIFI_IOT_IO_NAME_GPIO_6,
  34. /** GPIO hardware pin 7 */
  35. HAL_WIFI_IOT_IO_NAME_GPIO_7,
  36. /** GPIO hardware pin 8 */
  37. HAL_WIFI_IOT_IO_NAME_GPIO_8,
  38. /** GPIO hardware pin 9 */
  39. HAL_WIFI_IOT_IO_NAME_GPIO_9,
  40. /** GPIO hardware pin 10 */
  41. HAL_WIFI_IOT_IO_NAME_GPIO_10,
  42. /** GPIO hardware pin 11 */
  43. HAL_WIFI_IOT_IO_NAME_GPIO_11,
  44. /** GPIO hardware pin 12 */
  45. HAL_WIFI_IOT_IO_NAME_GPIO_12,
  46. /** GPIO hardware pin 13 */
  47. HAL_WIFI_IOT_IO_NAME_GPIO_13,
  48. /** GPIO hardware pin 14 */
  49. HAL_WIFI_IOT_IO_NAME_GPIO_14,
  50. /** Maximum value */
  51. HAL_WIFI_IOT_IO_NAME_MAX,
  52. } HalWifiIotIoName;
  53. /**
  54. * @brief set IO function.
  55. *
  56. * @param id -- IO number, reference {@ HalWifiIotIoName}.
  57. * @param val -- the io function value which defined in {@ hi_io.h}.
  58. *
  59. * @return Returns {@link WIFI_IOT_SUCCESS} if the operation is successful;
  60. * returns an error code defined in {@link wifiiot_errno.h} otherwise.
  61. * @since 1.0
  62. * @version 1.0
  63. */
  64. unsigned int HalIoSetFunc(HalWifiIotIoName id, const char *val);
  65. /* gpio end */
  66. /* adc start */
  67. /**
  68. * @brief Enumerates ADC channel indexes.
  69. *
  70. */
  71. typedef enum {
  72. /** Channel 0 */
  73. HAL_WIFI_IOT_ADC_CHANNEL_0,
  74. /** Channel 1 */
  75. HAL_WIFI_IOT_ADC_CHANNEL_1,
  76. /** Channel 2 */
  77. HAL_WIFI_IOT_ADC_CHANNEL_2,
  78. /** Channel 3 */
  79. HAL_WIFI_IOT_ADC_CHANNEL_3,
  80. /** Channel 4 */
  81. HAL_WIFI_IOT_ADC_CHANNEL_4,
  82. /** Channel 5 */
  83. HAL_WIFI_IOT_ADC_CHANNEL_5,
  84. /** Channel 6 */
  85. HAL_WIFI_IOT_ADC_CHANNEL_6,
  86. /** Channel 7 */
  87. HAL_WIFI_IOT_ADC_CHANNEL_7,
  88. /** Button value */
  89. HAL_WIFI_IOT_ADC_CHANNEL_BUTT,
  90. } HalWifiIotAdcChannelIndex;
  91. /**
  92. * @brief Enumerates analog power control modes.
  93. */
  94. typedef enum {
  95. /** Automatic control */
  96. HAL_WIFI_IOT_ADC_CUR_BAIS_DEFAULT,
  97. /** Automatic control */
  98. HAL_WIFI_IOT_ADC_CUR_BAIS_AUTO,
  99. /** Manual control (AVDD = 1.8 V) */
  100. HAL_WIFI_IOT_ADC_CUR_BAIS_1P8V,
  101. /** Manual control (AVDD = 3.3 V) */
  102. HAL_WIFI_IOT_ADC_CUR_BAIS_3P3V,
  103. /** Button value */
  104. HAL_WIFI_IOT_ADC_CUR_BAIS_BUTT,
  105. } HalWifiIotAdcCurBais;
  106. /**
  107. * @brief Enumerates equation models.
  108. */
  109. typedef enum {
  110. /** One-equation model */
  111. HAL_WIFI_IOT_ADC_EQU_MODEL_1,
  112. /** Two-equation model */
  113. HAL_WIFI_IOT_ADC_EQU_MODEL_2,
  114. /** Four-equation model */
  115. HAL_WIFI_IOT_ADC_EQU_MODEL_4,
  116. /** Eight-equation model */
  117. HAL_WIFI_IOT_ADC_EQU_MODEL_8,
  118. /** Button value */
  119. HAL_WIFI_IOT_ADC_EQU_MODEL_BUTT,
  120. } HalWifiIotAdcEquModelSel;
  121. /**
  122. * @brief Reads a piece of sampled data from a specified ADC channel based on the input parameters.
  123. *
  124. *
  125. *
  126. * @param channel Indicates the ADC channel index.
  127. * @param data Indicates the pointer to the address for storing the read data.
  128. * @param equModel Indicates the equation model.
  129. * @param curBais Indicates the analog power control mode.
  130. * @param rstCnt Indicates the count of the time from reset to conversion start.
  131. * One count is equal to 334 ns. The value must range from 0 to 0xFF0.
  132. * @return Returns {@link WIFI_IOT_SUCCESS} if the operation is successful;
  133. * returns an error code defined in {@link wifiiot_errno.h} otherwise.
  134. * @since 1.0
  135. * @version 1.0
  136. */
  137. unsigned int HalAdcRead(HalWifiIotAdcChannelIndex channel, unsigned short *data, HalWifiIotAdcEquModelSel equModel,
  138. HalWifiIotAdcCurBais curBais, unsigned short rstCnt);
  139. /** adc end ****/
  140. /**
  141. * @brief set WatchDog enable or disable.
  142. *
  143. * @param enable -- 1 enable, 0 disable.
  144. *
  145. * @since 1.0
  146. * @version 1.0
  147. */
  148. void HalSetWatchDogEnable(int enable);
  149. /**
  150. * @brief start the pwm.
  151. *
  152. * @param id Port id of PWM
  153. * @param duty The usefull cycles of PWM
  154. * @param freq The total cycles of PWM
  155. *
  156. * @return Returns {@link WIFI_IOT_SUCCESS} if the operation is successful;
  157. * returns an error code defined in {@link wifiiot_errno.h} otherwise.
  158. * @since 1.0
  159. * @version 1.0
  160. */
  161. unsigned int HalPwmStart(uint32 id, uint16 duty, uint16 freq);
  162. #endif // PERIPHERAL_HAL_H