board.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. /*
  2. * Copyright (C) 2017-2024 Alibaba Group Holding Limited
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. /*
  19. This is an example board.h for Board Compment, New Board should flow the macro defines.
  20. */
  21. #ifndef __BOARD_H__
  22. #define __BOARD_H__
  23. #include <soc.h>
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. // Common Board Features Define
  28. /*
  29. The Common BOARD_XXX Macro Defines Boards supported features which may reference by Solutions.
  30. Common board macro include:
  31. . BOARD_NAME
  32. · UART
  33. · GPIO
  34. · PWM
  35. · ADC
  36. · BUTTON
  37. · LED
  38. · WIFI
  39. · BT
  40. · AUDIO
  41. BOARD_XXX Macro descripted below should be defined if the board support.
  42. */
  43. /****************************************************************************/
  44. /*
  45. This riscv dummy board include:
  46. · UART x1
  47. · GPIO x2
  48. · PWM x2
  49. · ADC x1
  50. · BUTTON x2
  51. · LED x2
  52. · WIFI x0
  53. · BT x0
  54. · AUDIO x1
  55. */
  56. #ifndef CONFIG_BOARD_UART
  57. #define CONFIG_BOARD_UART 1
  58. #endif
  59. #ifndef CONFIG_BOARD_GPIO
  60. #define CONFIG_BOARD_GPIO 0
  61. #endif
  62. #ifndef CONFIG_BOARD_PWM
  63. #define CONFIG_BOARD_PWM 0
  64. #endif
  65. #ifndef CONFIG_BOARD_ADC
  66. #define CONFIG_BOARD_ADC 0
  67. #endif
  68. #ifndef CONFIG_BOARD_BUTTON
  69. #define CONFIG_BOARD_BUTTON 0
  70. #endif
  71. #ifndef CONFIG_BOARD_LED
  72. #define CONFIG_BOARD_LED 0
  73. #endif
  74. #ifndef CONFIG_BOARD_WIFI
  75. #define CONFIG_BOARD_WIFI 0
  76. #endif
  77. #ifndef CONFIG_BOARD_BT
  78. #define CONFIG_BOARD_BT 0
  79. #endif
  80. #ifndef CONFIG_BOARD_AUDIO
  81. #define CONFIG_BOARD_AUDIO 0
  82. #endif
  83. #define BOARD_NAME "RISCV_DUMMY"
  84. /* the board pins, can be used as uart, gpio, pwd... */
  85. #define BOARD_PIN0 (0)
  86. #define BOARD_PIN1 (1)
  87. #define BOARD_PIN2 (2)
  88. #define BOARD_PIN3 (3)
  89. #define BOARD_PIN4 (4)
  90. #define BOARD_PIN5 (5)
  91. #define BOARD_PIN6 (6)
  92. #define BOARD_PIN7 (7)
  93. #define BOARD_PIN8 (8)
  94. #define BOARD_PIN9 (9)
  95. #define BOARD_PIN10 (10)
  96. #define BOARD_PIN11 (11)
  97. #define BOARD_PIN12 (12)
  98. //...
  99. #if defined(CONFIG_BOARD_UART) && CONFIG_BOARD_UART
  100. // UART
  101. /*
  102. The total supported uart numbers on this board, 0 meas No uart support.
  103. the BOARD_UART<x>_XXX, x in rang of (0, BOARD_UART_NUM - 1)
  104. */
  105. #ifndef BOARD_UART_NUM
  106. #define BOARD_UART_NUM (1)
  107. #endif
  108. #if defined(BOARD_UART_NUM) && BOARD_UART_NUM > 0
  109. /* the board uart0 tx pin */
  110. #define BOARD_UART0_TX_PIN (BOARD_PIN0)
  111. /* the borad uart0 rx pin */
  112. #define BOARD_UART0_RX_PIN (BOARD_PIN1)
  113. /* The real UART port reference to board logic port 0 */
  114. #define BOARD_UART0_IDX (0)
  115. /* The default baudrate for uart0 */
  116. #define BOARD_UART0_BAUD (115200)
  117. //#define BOARD_UART1_IDX (1)
  118. //#define BOARD_UART1_BAUD (115200)
  119. // ...
  120. #endif // defined(BOARD_UART_NUM) && BOARD_UART_NUM > 0
  121. #endif // defined(CONFIG_BOARD_UART) && CONFIG_BOARD_UART
  122. #if defined(CONFIG_BOARD_GPIO) && CONFIG_BOARD_GPIO
  123. // GPIO
  124. /*
  125. The total supported GPIO Pin numbers on this board, 0 meas No uart support.
  126. the BOARD_GPIO_PIN<x>, x in rang of (0, BOARD_GPIO_PIN_NUM - 1)
  127. */
  128. #ifndef BOARD_GPIO_PIN_NUM
  129. #define BOARD_GPIO_PIN_NUM (2)
  130. #endif
  131. #if defined(BOARD_GPIO_PIN_NUM) && BOARD_GPIO_PIN_NUM > 0
  132. /* The real gpio reference to board logic gpio pin */
  133. #define BOARD_GPIO_PIN0 (BOARD_PIN2)
  134. #define BOARD_GPIO_PIN1 (BOARD_PIN3)
  135. //#define BOARD_GPIO_PIN2 (x)
  136. //#define BOARD_GPIO_PIN3 (x)
  137. #endif // defined(BOARD_GPIO_PIN_NUM) && BOARD_GPIO_PIN_NUM > 0
  138. #endif // defined(CONFIG_BOARD_GPIO) && CONFIG_BOARD_GPIO
  139. #if defined(CONFIG_BOARD_PWM) && CONFIG_BOARD_PWM
  140. // PWM
  141. /* the board supported pwm channels */
  142. #ifndef BOARD_PWM_NUM
  143. #define BOARD_PWM_NUM (2)
  144. #endif
  145. #if defined(BOARD_PWM_NUM) && BOARD_PWM_NUM > 0
  146. /* the board pwm pin */
  147. #define BOARD_PWM0_PIN (BOARD_PIN4)
  148. /* The real pwm channel reference to board logic pwm channel */
  149. #define BOARD_PWM0_CH (0)
  150. #define BOARD_PWM1_PIN (BOARD_PIN5)
  151. #define BOARD_PWM1_CH (1)
  152. #endif // defined(BOARD_PWM_NUM) && BOARD_PWM_NUM > 0
  153. #endif // defined(CONFIG_BOARD_PWM) && CONFIG_BOARD_PWM
  154. #if defined(CONFIG_BOARD_ADC) && CONFIG_BOARD_ADC > 0
  155. // ADC
  156. /* the board supported adc channels */
  157. #ifndef BOARD_ADC_NUM
  158. #define BOARD_ADC_NUM (1)
  159. #endif
  160. #if defined(BOARD_ADC_NUM) && BOARD_ADC_NUM > 0
  161. /* the board adc pin */
  162. #define BOARD_ADC0_PIN (BOARD_PIN6)
  163. /* The real adc channel reference to board logic adc channel */
  164. #define BOARD_ADC0_CH (0)
  165. #endif // defined(BOARD_ADC_NUM) && BOARD_ADC_NUM > 0
  166. #endif // defined(CONFIG_BOARD_ADC) && CONFIG_BOARD_ADC > 0
  167. #if defined(CONFIG_BOARD_BUTTON) && CONFIG_BOARD_BUTTON > 0
  168. // BUTTON
  169. #ifndef BOARD_BUTTON_NUM
  170. /*
  171. the board supported buttons, include gpio button and adc button,
  172. BOARD_BUTTON_NUM = BOARD_BUTTON_GPIO_NUM + BOARD_BUTTON_ADC_NUM.
  173. */
  174. #define BOARD_BUTTON_NUM (4)
  175. #endif
  176. #if defined(BOARD_BUTTON_NUM) && BOARD_BUTTON_NUM > 0
  177. #define BOARD_BUTTON0_PIN (BOARD_PIN7)
  178. #define BOARD_BUTTON1_PIN (BOARD_PIN8)
  179. #define BOARD_BUTTON2_PIN (BOARD_PIN9)
  180. #define BOARD_BUTTON3_PIN (BOARD_PIN10)
  181. // GPIO BUTTON
  182. /* the board supported GPIO Buttons */
  183. #ifndef BOARD_BUTTON_GPIO_NUM
  184. #define BOARD_BUTTON_GPIO_NUM (2)
  185. #endif
  186. #if defined(BOARD_BUTTON_GPIO_NUM) && BOARD_BUTTON_GPIO_NUM > 0
  187. /* the board logic button id, in range of (0, BOARD_BUTTON_GPIO_NUM - 1) */
  188. #define BOARD_BUTTON0 (0)
  189. /* for gpio button, define the pin numner. if the gpio pin used as gpio button, it shoudn't reference as BOARD_GPIO_PINx
  190. */
  191. #define BOARD_BUTTON0_GPIO_PIN (BOARD_BUTTON0_PIN)
  192. #define BOARD_BUTTON1 (1)
  193. #define BOARD_BUTTON1_GPIO_PIN (BOARD_BUTTON1_PIN)
  194. #endif // defined(BOARD_BUTTON_GPIO_NUM) && BOARD_BUTTON_GPIO_NUM > 0
  195. // ADC BUTTON
  196. /* the board supported adc Buttons */
  197. #ifndef BOARD_BUTTON_ADC_NUM
  198. #define BOARD_BUTTON_ADC_NUM (2)
  199. #endif
  200. #if defined(BOARD_BUTTON_ADC_NUM) && BOARD_BUTTON_ADC_NUM > 0
  201. /* the board logic adc button id, in range of (BOARD_BUTTON_GPIO_NUM, BOARD_BUTTON_NUM - 1), if not suuport GPIO Button,
  202. * BOARD_BUTTON_GPIO_NUM should be 0 */
  203. #define BOARD_BUTTON2 (BOARD_BUTTON_GPIO_NUM + 0)
  204. #define BOARD_BUTTON2_ADC_PIN (BOARD_BUTTON2_PIN)
  205. /* the adc channel used for button2, if the adc channel used as adc button, it shoudn't reference as BOARD_ADCx_CH*/
  206. #define BOARD_BUTTON2_ADC_CH (1)
  207. /* the adc device name */
  208. #define BOARD_BUTTON2_ADC_NAME "adc1"
  209. /* adc voltage reference */
  210. #define BOARD_BUTTON2_ADC_REF (100)
  211. /* adc voltage range */
  212. #define BOARD_BUTTON2_ADC_RANG (500)
  213. #define BOARD_BUTTON3 (BOARD_BUTTON_GPIO_NUM + 1)
  214. #define BOARD_BUTTON3_ADC_PIN (BOARD_BUTTON3_PIN)
  215. #define BOARD_BUTTON3_ADC_CH (1)
  216. #define BOARD_BUTTON3_ADC_NAME "adc1"
  217. #define BOARD_BUTTON3_ADC_REF (600)
  218. #define BOARD_BUTTON3_ADC_RANG (500)
  219. //#define BOARD_ADC_BUTTON2 (2)
  220. //#define BOARD_ADC_BUTTON2_CH (1)
  221. //#define BOARD_ADC_BUTTON2_NAME "adc1"
  222. //#define BOARD_ADC_BUTTON2_REF xxx
  223. //#define BOARD_ADC_BUTTON2_RANG xxx
  224. #endif // defined(BOARD_BUTTON_ADC_NUM) && BOARD_BUTTON_ADC_NUM > 0
  225. #endif // defined(BOARD_BUTTON_NUM) && BOARD_BUTTON_NUM > 0
  226. #endif // defined(BOARD_BUTTON_NUM) && BOARD_BUTTON_NUM > 0
  227. #if defined(CONFIG_BOARD_LED) && CONFIG_BOARD_LED > 0
  228. // LED
  229. /* the board supported leds */
  230. #ifndef BOARD_LED_NUM
  231. #define BOARD_LED_NUM (2)
  232. #endif
  233. #define BOARD_LED0_PIN BOARD_PIN11
  234. #define BOARD_LED1_PIN BOARD_PIN12
  235. // PWM LED
  236. /* the board supported pwm leds */
  237. #ifndef BOARD_LED_PWM_NUM
  238. #define BOARD_LED_PWM_NUM (1)
  239. #endif
  240. #if defined(BOARD_LED_PWM_NUM) && BOARD_LED_PWM_NUM > 0
  241. #define BOARD_LED0_PWM_PIN (BOARD_LED0_PIN)
  242. /* the pwm channel used for led0, if the pwm channel used as led0, it shoudn't reference as BOARD_PWMx_CH */
  243. #define BOARD_LED0_PWM_CH (0)
  244. #endif // defined(BOARD_LED_PWM_NUM) && BOARD_LED_PWM_NUM > 0
  245. // GPIO LED
  246. #ifndef BOARD_LED_GPIO_NUM
  247. #define BOARD_LED_GPIO_NUM (1)
  248. #endif
  249. #if defined(BOARD_LED_GPIO_NUM) && BOARD_LED_GPIO_NUM > 0
  250. /* the gpio pin used for led0, if the gpio pin used as led, it shoudn't reference as BOARD_GPIO_PINx */
  251. #define BOARD_LED1_GPIO_PIN (BOARD_LED1_PIN)
  252. #endif // defined(BOARD_LED_GPIO_NUM) && BOARD_LED_GPIO_NUM > 0
  253. #endif // defined(CONFIG_BOARD_LED) && CONFIG_BOARD_LED > 0
  254. #if defined(CONFIG_BOARD_BT) && CONFIG_BOARD_BT > 0
  255. // BT
  256. /* the board support bluetooth */
  257. #ifndef BOARD_BT_SUPPORT
  258. #define BOARD_BT_SUPPORT 1
  259. #endif
  260. #endif // defined(CONFIG_BOARD_BT) && CONFIG_BOARD_BT > 0
  261. #if defined(CONFIG_BOARD_WIFI) && CONFIG_BOARD_WIFI > 0
  262. // WIFI
  263. /* the board support wifi */
  264. #ifndef BOARD_WIFI_SUPPORT
  265. #define BOARD_WIFI_SUPPORT 1
  266. #endif
  267. #endif // defined(CONFIG_BOARD_WIFI) && CONFIG_BOARD_WIFI > 0
  268. #if defined(CONFIG_BOARD_AUDIO) && CONFIG_BOARD_AUDIO > 0
  269. // Audio
  270. /* the board support audio */
  271. #ifndef BOARD_AUDIO_SUPPORT
  272. #define BOARD_AUDIO_SUPPORT 1
  273. #endif
  274. #endif // defined(CONFIG_BOARD_AUDIO) && CONFIG_BOARD_AUDIO > 0
  275. /****************************************************************************/
  276. // Common solutions defines
  277. // Console config, Almost all solutions and demos use these.
  278. #ifndef CONSOLE_UART_IDX
  279. #define CONSOLE_UART_IDX (BOARD_UART0_IDX)
  280. #endif
  281. #ifndef CONFIG_CLI_USART_BAUD
  282. #define CONFIG_CLI_USART_BAUD (BOARD_UART0_BAUD)
  283. #endif
  284. #ifndef CONFIG_CONSOLE_UART_BUFSIZE
  285. #define CONFIG_CONSOLE_UART_BUFSIZE (128)
  286. #endif
  287. /****************************************************************************/
  288. // Commom test demos defines
  289. // i2c
  290. #define EXAMPLE_IIC_IDX 0 // 1
  291. #define EXAMPLE_PIN_IIC_SDA 0 // PC1
  292. #define EXAMPLE_PIN_IIC_SCL 0 // PC0
  293. #define EXAMPLE_PIN_IIC_SDA_FUNC 0 // PC1_I2C1_SDA
  294. #define EXAMPLE_PIN_IIC_SCL_FUNC 0 // PC0_I2C1_SCL
  295. // adc
  296. #define EXAMPLE_ADC_CH0 0 // PA8
  297. #define EXAMPLE_ADC_CH0_FUNC 0 // PA8_ADC_A0
  298. #define EXAMPLE_ADC_CH12 0 // PA26
  299. #define EXAMPLE_ADC_CH12_FUNC 0 // PA26_ADC_A12
  300. /****************************************************************************/
  301. // Vendor board defines
  302. /* other board specific defines */
  303. //#define CUSTOM_BOARD_xxx
  304. /****************************************************************************/
  305. /**
  306. * @brief init the board for default: pin mux, etc.
  307. * re-implement if need.
  308. * @return
  309. */
  310. void board_init(void);
  311. /**
  312. * @brief init the board gpio pin for default: pin mux, etc.
  313. * re-implement if need.
  314. * @return
  315. */
  316. void board_gpio_pin_init(void);
  317. /**
  318. * @brief init the board uart for default: pin mux, etc.
  319. * re-implement if need.
  320. * @return
  321. */
  322. void board_uart_init(void);
  323. /**
  324. * @brief init the board pwm for default: pin mux, etc.
  325. * re-implement if need.
  326. * @return
  327. */
  328. void board_pwm_init(void);
  329. /**
  330. * @brief init the board adc for default: pin mux, etc.
  331. * re-implement if need.
  332. * @return
  333. */
  334. void board_adc_init(void);
  335. /**
  336. * @brief init the board button for default: pin mux, etc.
  337. * re-implement if need.
  338. * @return
  339. */
  340. void board_button_init(void);
  341. /**
  342. * @brief init the board led for default: pin mux, etc.
  343. * re-implement if need.
  344. * @return
  345. */
  346. void board_led_init(void);
  347. /**
  348. * @brief init the board wifi for default: pin mux, etc.
  349. * re-implement if need.
  350. * @return
  351. */
  352. void board_wifi_init(void);
  353. /**
  354. * @brief init the board bt for default: pin mux, etc.
  355. * re-implement if need.
  356. * @return
  357. */
  358. void board_bt_init(void);
  359. /**
  360. * @brief init the board audio for default: pin mux, etc.
  361. * re-implement if need.
  362. * @return
  363. */
  364. void board_audio_init(void);
  365. #ifdef __cplusplus
  366. }
  367. #endif
  368. #endif /* __BOARD_H__ */