drv_spi.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2023-05-01 flyingcys first version
  9. */
  10. #include <rtthread.h>
  11. #include <rtdevice.h>
  12. #include <rthw.h>
  13. #include "bflb_spi.h"
  14. #include "bflb_dma.h"
  15. #include "bflb_gpio.h"
  16. #ifndef __DRV_SPI_H_
  17. #define __DRV_SPI_H_
  18. #ifdef SPI_SCK_USING_GPIO1
  19. #define SPI_SCK_PIN GPIO_PIN_1
  20. #elif defined(SPI_SCK_USING_GPIO3)
  21. #define SPI_SCK_PIN GPIO_PIN_3
  22. #elif defined(SPI_SCK_USING_GPIO5)
  23. #define SPI_SCK_PIN GPIO_PIN_5
  24. #elif defined(SPI_SCK_USING_GPIO7)
  25. #define SPI_SCK_PIN GPIO_PIN_7
  26. #elif defined(SPI_SCK_USING_GPIO9)
  27. #define SPI_SCK_PIN GPIO_PIN_9
  28. #elif defined(SPI_SCK_USING_GPIO11)
  29. #define SPI_SCK_PIN GPIO_PIN_11
  30. #elif defined(SPI_SCK_USING_GPIO13)
  31. #define SPI_SCK_PIN GPIO_PIN_13
  32. #elif defined(SPI_SCK_USING_GPIO15)
  33. #define SPI_SCK_PIN GPIO_PIN_15
  34. #elif defined(SPI_SCK_USING_GPIO17)
  35. #define SPI_SCK_PIN GPIO_PIN_17
  36. #elif defined(SPI_SCK_USING_GPIO19)
  37. #define SPI_SCK_PIN GPIO_PIN_19
  38. #elif defined(SPI_SCK_USING_GPIO21)
  39. #define SPI_SCK_PIN GPIO_PIN_21
  40. #elif defined(SPI_SCK_USING_GPIO23)
  41. #define SPI_SCK_PIN GPIO_PIN_23
  42. #elif defined(SPI_SCK_USING_GPIO25)
  43. #define SPI_SCK_PIN GPIO_PIN_25
  44. #elif defined(SPI_SCK_USING_GPIO27)
  45. #define SPI_SCK_PIN GPIO_PIN_27
  46. #elif defined(SPI_SCK_USING_GPIO29)
  47. #define SPI_SCK_PIN GPIO_PIN_29
  48. #elif defined(SPI_SCK_USING_GPIO31)
  49. #define SPI_SCK_PIN GPIO_PIN_31
  50. #elif defined(SPI_SCK_USING_GPIO33)
  51. #define SPI_SCK_PIN GPIO_PIN_33
  52. #elif defined(SPI_SCK_USING_GPIO35)
  53. #define SPI_SCK_PIN GPIO_PIN_35
  54. #elif defined(SPI_SCK_USING_GPIO39)
  55. #define SPI_SCK_PIN GPIO_PIN_39
  56. #elif defined(SPI_SCK_USING_GPIO43)
  57. #define SPI_SCK_PIN GPIO_PIN_43
  58. #endif
  59. #ifdef SPI_MISO_USING_GPIO0
  60. #define SPI_MISO_PIN GPIO_PIN_0
  61. #elif defined(SPI_MISO_USING_GPIO1)
  62. #define SPI_MISO_PIN GPIO_PIN_1
  63. #elif defined(SPI_MISO_USING_GPIO2)
  64. #define SPI_MISO_PIN GPIO_PIN_2
  65. #elif defined(SPI_MISO_USING_GPIO4)
  66. #define SPI_MISO_PIN GPIO_PIN_4
  67. #elif defined(SPI_MISO_USING_GPIO5)
  68. #define SPI_MISO_PIN GPIO_PIN_5
  69. #elif defined(SPI_MISO_USING_GPIO6)
  70. #define SPI_MISO_PIN GPIO_PIN_6
  71. #elif defined(SPI_MISO_USING_GPIO8)
  72. #define SPI_MISO_PIN GPIO_PIN_8
  73. #elif defined(SPI_MISO_USING_GPIO9)
  74. #define SPI_MISO_PIN GPIO_PIN_9
  75. #elif defined(SPI_MISO_USING_GPIO10)
  76. #define SPI_MISO_PIN GPIO_PIN_10
  77. #elif defined(SPI_MISO_USING_GPIO12)
  78. #define SPI_MISO_PIN GPIO_PIN_12
  79. #elif defined(SPI_MISO_USING_GPIO13)
  80. #define SPI_MISO_PIN GPIO_PIN_13
  81. #elif defined(SPI_MISO_USING_GPIO14)
  82. #define SPI_MISO_PIN GPIO_PIN_14
  83. #elif defined(SPI_MISO_USING_GPIO16)
  84. #define SPI_MISO_PIN GPIO_PIN_16
  85. #elif defined(SPI_MISO_USING_GPIO17)
  86. #define SPI_MISO_PIN GPIO_PIN_17
  87. #elif defined(SPI_MISO_USING_GPIO18)
  88. #define SPI_MISO_PIN GPIO_PIN_18
  89. #elif defined(SPI_MISO_USING_GPIO20)
  90. #define SPI_MISO_PIN GPIO_PIN_20
  91. #elif defined(SPI_MISO_USING_GPIO21)
  92. #define SPI_MISO_PIN GPIO_PIN_21
  93. #elif defined(SPI_MISO_USING_GPIO22)
  94. #define SPI_MISO_PIN GPIO_PIN_22
  95. #elif defined(SPI_MISO_USING_GPIO25)
  96. #define SPI_MISO_PIN GPIO_PIN_25
  97. #elif defined(SPI_MISO_USING_GPIO26)
  98. #define SPI_MISO_PIN GPIO_PIN_26
  99. #elif defined(SPI_MISO_USING_GPIO29)
  100. #define SPI_MISO_PIN GPIO_PIN_29
  101. #elif defined(SPI_MISO_USING_GPIO30)
  102. #define SPI_MISO_PIN GPIO_PIN_30
  103. #elif defined(SPI_MISO_USING_GPIO34)
  104. #define SPI_MISO_PIN GPIO_PIN_34
  105. #elif defined(SPI_MISO_USING_GPIO38)
  106. #define SPI_MISO_PIN GPIO_PIN_38
  107. #elif defined(SPI_MISO_USING_GPIO42)
  108. #define SPI_MISO_PIN GPIO_PIN_42
  109. #endif
  110. #ifdef SPI_MOSI_USING_GPIO0
  111. #define SPI_MOSI_PIN GPIO_PIN_0
  112. #elif defined(SPI_MOSI_USING_GPIO1)
  113. #define SPI_MOSI_PIN GPIO_PIN_1
  114. #elif defined(SPI_MOSI_USING_GPIO3)
  115. #define SPI_MOSI_PIN GPIO_PIN_3
  116. #elif defined(SPI_MOSI_USING_GPIO4)
  117. #define SPI_MOSI_PIN GPIO_PIN_4
  118. #elif defined(SPI_MOSI_USING_GPIO5)
  119. #define SPI_MOSI_PIN GPIO_PIN_5
  120. #elif defined(SPI_MOSI_USING_GPIO7)
  121. #define SPI_MOSI_PIN GPIO_PIN_7
  122. #elif defined(SPI_MOSI_USING_GPIO8)
  123. #define SPI_MOSI_PIN GPIO_PIN_8
  124. #elif defined(SPI_MOSI_USING_GPIO9)
  125. #define SPI_MOSI_PIN GPIO_PIN_9
  126. #elif defined(SPI_MOSI_USING_GPIO11)
  127. #define SPI_MOSI_PIN GPIO_PIN_11
  128. #elif defined(SPI_MOSI_USING_GPIO12)
  129. #define SPI_MOSI_PIN GPIO_PIN_12
  130. #elif defined(SPI_MOSI_USING_GPIO13)
  131. #define SPI_MOSI_PIN GPIO_PIN_13
  132. #elif defined(SPI_MOSI_USING_GPIO15)
  133. #define SPI_MOSI_PIN GPIO_PIN_15
  134. #elif defined(SPI_MOSI_USING_GPIO16)
  135. #define SPI_MOSI_PIN GPIO_PIN_16
  136. #elif defined(SPI_MOSI_USING_GPIO17)
  137. #define SPI_MOSI_PIN GPIO_PIN_17
  138. #elif defined(SPI_MOSI_USING_GPIO19)
  139. #define SPI_MOSI_PIN GPIO_PIN_19
  140. #elif defined(SPI_MOSI_USING_GPIO20)
  141. #define SPI_MOSI_PIN GPIO_PIN_20
  142. #elif defined(SPI_MOSI_USING_GPIO21)
  143. #define SPI_MOSI_PIN GPIO_PIN_21
  144. #elif defined(SPI_MOSI_USING_GPIO23)
  145. #define SPI_MOSI_PIN GPIO_PIN_23
  146. #elif defined(SPI_MOSI_USING_GPIO24)
  147. #define SPI_MOSI_PIN GPIO_PIN_24
  148. #elif defined(SPI_MOSI_USING_GPIO25)
  149. #define SPI_MOSI_PIN GPIO_PIN_25
  150. #elif defined(SPI_MOSI_USING_GPIO27)
  151. #define SPI_MOSI_PIN GPIO_PIN_27
  152. #elif defined(SPI_MOSI_USING_GPIO28)
  153. #define SPI_MOSI_PIN GPIO_PIN_28
  154. #elif defined(SPI_MOSI_USING_GPIO29)
  155. #define SPI_MOSI_PIN GPIO_PIN_29
  156. #elif defined(SPI_MOSI_USING_GPIO31)
  157. #define SPI_MOSI_PIN GPIO_PIN_31
  158. #elif defined(SPI_MOSI_USING_GPIO33)
  159. #define SPI_MOSI_PIN GPIO_PIN_33
  160. #elif defined(SPI_MOSI_USING_GPIO37)
  161. #define SPI_MOSI_PIN GPIO_PIN_37
  162. #elif defined(SPI_MOSI_USING_GPIO41)
  163. #define SPI_MOSI_PIN GPIO_PIN_41
  164. #elif defined(SPI_MOSI_USING_GPIO45)
  165. #define SPI_MOSI_PIN GPIO_PIN_45
  166. #endif
  167. rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_uint32_t cs_pin);
  168. int rt_hw_spi_init(void);
  169. #endif /*__DRV_SPI_H_*/