sbbif3.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. #ifndef _DEV_SBBIF3_H_
  2. #define _DEV_SBBIF3_H_
  3. /*
  4. * Copyright (C) 2007 by egnite Software GmbH. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. /*!
  35. * \file dev/sbbif3.h
  36. * \brief Serial bit banged interface 3.
  37. *
  38. * \verbatim
  39. *
  40. * \endverbatim
  41. */
  42. #include <cfg/arch/gpio.h>
  43. #include <stdint.h>
  44. /*!
  45. * \brief Maximum number of devices (chip selects).
  46. */
  47. #ifndef SBBI3_MAX_DEVICES
  48. #define SBBI3_MAX_DEVICES 4
  49. #endif
  50. #ifdef SBBI3_CS0_BIT
  51. #undef GPIO_ID
  52. #if defined(SBBI3_CS0_PORT)
  53. #define GPIO_ID SBBI3_CS0_PORT
  54. #endif
  55. #include <cfg/arch/porttran.h>
  56. #define SBBI3_CS0_ENA() GPIO_ENABLE(SBBI3_CS0_BIT)
  57. #define SBBI3_CS0_OUTPUT() GPIO_OUTPUT(SBBI3_CS0_BIT)
  58. #define SBBI3_CS0_SET() GPIO_SET_HI(SBBI3_CS0_BIT)
  59. #define SBBI3_CS0_CLR() GPIO_SET_LO(SBBI3_CS0_BIT)
  60. #else
  61. #define SBBI3_CS0_ENA()
  62. #define SBBI3_CS0_OUTPUT()
  63. #define SBBI3_CS0_CLR()
  64. #define SBBI3_CS0_SET()
  65. #endif
  66. #ifdef SBBI3_CS1_BIT
  67. #undef GPIO_ID
  68. #if defined(SBBI3_CS1_PORT)
  69. #define GPIO_ID SBBI3_CS1_PORT
  70. #endif
  71. #include <cfg/arch/porttran.h>
  72. #define SBBI3_CS1_ENA() GPIO_ENABLE(SBBI3_CS1_BIT)
  73. #define SBBI3_CS1_OUTPUT() GPIO_SET_HI(SBBI3_CS1_BIT)
  74. #define SBBI3_CS1_SET() GPIO_SET_HI(SBBI3_CS1_BIT)
  75. #define SBBI3_CS1_CLR() GPIO_SET_LO(SBBI3_CS1_BIT)
  76. #else
  77. #define SBBI3_CS1_ENA()
  78. #define SBBI3_CS1_OUTPUT()
  79. #define SBBI3_CS1_CLR()
  80. #define SBBI3_CS1_SET()
  81. #endif
  82. #ifdef SBBI3_CS2_BIT
  83. #undef GPIO_ID
  84. #if defined(SBBI3_CS2_PORT)
  85. #define GPIO_ID SBBI3_CS2_PORT
  86. #endif
  87. #include <cfg/arch/porttran.h>
  88. #define SBBI3_CS2_ENA() GPIO_ENABLE(SBBI3_CS2_BIT)
  89. #define SBBI3_CS2_OUTPUT() GPIO_OUTPUT(SBBI3_CS2_BIT)
  90. #define SBBI3_CS2_SET() GPIO_SET_HI(SBBI3_CS2_BIT)
  91. #define SBBI3_CS2_CLR() GPIO_SET_LO(SBBI3_CS2_BIT)
  92. #else
  93. #define SBBI3_CS2_ENA()
  94. #define SBBI3_CS2_OUTPUT()
  95. #define SBBI3_CS2_CLR()
  96. #define SBBI3_CS2_SET()
  97. #endif
  98. #ifdef SBBI3_CS3_BIT
  99. #undef GPIO_ID
  100. #if defined(SBBI3_CS3_PORT)
  101. #define GPIO_ID SBBI3_CS3_PORT
  102. #endif
  103. #include <cfg/arch/porttran.h>
  104. #define SBBI3_CS3_ENA() GPIO_ENABLE(SBBI3_CS3_BIT)
  105. #define SBBI3_CS3_OUTPUT() GPIO_OUTPUT(SBBI3_CS3_BIT)
  106. #define SBBI3_CS3_SET() GPIO_SET_HI(SBBI3_CS3_BIT)
  107. #define SBBI3_CS3_CLR() GPIO_SET_LO(SBBI3_CS3_BIT)
  108. #else
  109. #define SBBI3_CS3_ENA()
  110. #define SBBI3_CS3_OUTPUT()
  111. #define SBBI3_CS3_CLR()
  112. #define SBBI3_CS3_SET()
  113. #endif
  114. #ifdef SBBI3_RST0_BIT
  115. #undef GPIO_ID
  116. #if defined(SBBI3_RST0_PORT)
  117. #define GPIO_ID SBBI3_RST0_PORT
  118. #endif
  119. #include <cfg/arch/porttran.h>
  120. #define SBBI3_RST0_ENA() GPIO_ENABLE(SBBI3_RST0_BIT)
  121. #define SBBI3_RST0_OUTPUT() GPIO_OUTPUT(SBBI3_RST0_BIT)
  122. #define SBBI3_RST0_SET() GPIO_SET_HI(SBBI3_RST0_BIT)
  123. #define SBBI3_RST0_CLR() GPIO_SET_LO(SBBI3_RST0_BIT)
  124. #else
  125. #define SBBI3_RST0_ENA()
  126. #define SBBI3_RST0_OUTPUT()
  127. #define SBBI3_RST0_CLR()
  128. #define SBBI3_RST0_SET()
  129. #endif
  130. #ifdef SBBI3_RST1_BIT
  131. #undef GPIO_ID
  132. #if defined(SBBI3_RST1_PORT)
  133. #define GPIO_ID SBBI3_RST1_PORT
  134. #endif
  135. #include <cfg/arch/porttran.h>
  136. #define SBBI3_RST1_ENA() GPIO_ENABLE(SBBI3_RST1_BIT)
  137. #define SBBI3_RST1_OUTPUT() GPIO_OUTPUT(SBBI3_RST1_BIT)
  138. #define SBBI3_RST1_SET() GPIO_SET_HI(SBBI3_RST1_BIT)
  139. #define SBBI3_RST1_CLR() GPIO_SET_LO(SBBI3_RST1_BIT)
  140. #else
  141. #define SBBI3_RST1_ENA()
  142. #define SBBI3_RST1_OUTPUT()
  143. #define SBBI3_RST1_CLR()
  144. #define SBBI3_RST1_SET()
  145. #endif
  146. #ifdef SBBI3_RST2_BIT
  147. #undef GPIO_ID
  148. #if defined(SBBI3_RST2_PORT)
  149. #define GPIO_ID SBBI3_RST2_PORT
  150. #endif
  151. #include <cfg/arch/porttran.h>
  152. #define SBBI3_RST2_ENA() GPIO_ENABLE(SBBI3_RST2_BIT)
  153. #define SBBI3_RST2_OUTPUT() GPIO_OUTPUT(SBBI3_RST2_BIT)
  154. #define SBBI3_RST2_SET() GPIO_SET_HI(SBBI3_RST2_BIT)
  155. #define SBBI3_RST2_CLR() GPIO_SET_LO(SBBI3_RST2_BIT)
  156. #else
  157. #define SBBI3_RST2_ENA()
  158. #define SBBI3_RST2_OUTPUT()
  159. #define SBBI3_RST2_CLR()
  160. #define SBBI3_RST2_SET()
  161. #endif
  162. #ifdef SBBI3_RST3_BIT
  163. #undef GPIO_ID
  164. #if defined(SBBI3_RST3_PORT)
  165. #define GPIO_ID SBBI3_RST3_PORT
  166. #endif
  167. #include <cfg/arch/porttran.h>
  168. #define SBBI3_RST3_ENA() GPIO_ENABLE(SBBI3_RST3_BIT)
  169. #define SBBI3_RST3_OUTPUT() GPIO_OUTPUT(SBBI3_RST3_BIT)
  170. #define SBBI3_RST3_SET() GPIO_SET_HI(SBBI3_RST3_BIT)
  171. #define SBBI3_RST3_CLR() GPIO_SET_LO(SBBI3_RST3_BIT)
  172. #else
  173. #define SBBI3_RST3_ENA()
  174. #define SBBI3_RST3_OUTPUT()
  175. #define SBBI3_RST3_CLR()
  176. #define SBBI3_RST3_SET()
  177. #endif
  178. #ifdef SBBI3_SCK_BIT
  179. #undef GPIO_ID
  180. #if defined(SBBI3_SCK_PORT)
  181. #define GPIO_ID SBBI3_SCK_PORT
  182. #endif
  183. #include <cfg/arch/porttran.h>
  184. #define SBBI3_SCK_ENA() GPIO_ENABLE(SBBI3_SCK_BIT)
  185. #define SBBI3_SCK_OUTPUT() GPIO_OUTPUT(SBBI3_SCK_BIT)
  186. #define SBBI3_SCK_SET() GPIO_SET_HI(SBBI3_SCK_BIT)
  187. #define SBBI3_SCK_CLR() GPIO_SET_LO(SBBI3_SCK_BIT)
  188. #else
  189. #define SBBI3_SCK_ENA()
  190. #define SBBI3_SCK_OUTPUT()
  191. #define SBBI3_SCK_CLR()
  192. #define SBBI3_SCK_SET()
  193. #endif
  194. #ifdef SBBI3_MOSI_BIT
  195. #undef GPIO_ID
  196. #if defined(SBBI3_MOSI_PORT)
  197. #define GPIO_ID SBBI3_MOSI_PORT
  198. #endif
  199. #include <cfg/arch/porttran.h>
  200. #define SBBI3_MOSI_ENA() GPIO_ENABLE(SBBI3_MOSI_BIT)
  201. #define SBBI3_MOSI_OUTPUT() GPIO_OUTPUT(SBBI3_MOSI_BIT)
  202. #define SBBI3_MOSI_SET() GPIO_SET_HI(SBBI3_MOSI_BIT)
  203. #define SBBI3_MOSI_CLR() GPIO_SET_LO(SBBI3_MOSI_BIT)
  204. #else
  205. #define SBBI3_MOSI_ENA()
  206. #define SBBI3_MOSI_OUTPUT()
  207. #define SBBI3_MOSI_CLR()
  208. #define SBBI3_MOSI_SET()
  209. #endif
  210. #ifdef SBBI3_MISO_BIT
  211. #undef GPIO_ID
  212. #if defined(SBBI3_MISO_PORT)
  213. #define GPIO_ID SBBI3_MISO_PORT
  214. #endif
  215. #include <cfg/arch/porttran.h>
  216. #define SBBI3_MISO_ENA() GPIO_ENABLE(SBBI3_MISO_BIT)
  217. #define SBBI3_MISO_TST() GPIO_GET(SBBI3_MISO_BIT)
  218. #else
  219. #define SBBI3_MISO_ENA()
  220. #define SBBI3_MISO_TST() 0
  221. #endif
  222. #define SBBI3_INIT() \
  223. { \
  224. SBBI3_SCK_CLR(); \
  225. SBBI3_SCK_ENA(); \
  226. SBBI3_MOSI_CLR(); \
  227. SBBI3_MOSI_ENA(); \
  228. SBBI3_MISO_ENA(); \
  229. }
  230. #endif