sppif0.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. #ifndef _DEV_SPPIF0_H_
  2. #define _DEV_SPPIF0_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/sppif0.h
  36. * \brief Serial bit banged interface 0.
  37. *
  38. * \verbatim
  39. *
  40. * $Log$
  41. * Revision 1.2 2008/08/11 06:59:59 haraldkipp
  42. * BSD types replaced by stdint types (feature request #1282721).
  43. *
  44. * Revision 1.1 2007/04/12 09:07:54 haraldkipp
  45. * Configurable SPI added.
  46. *
  47. *
  48. * \endverbatim
  49. */
  50. #include <cfg/arch/gpio.h>
  51. #include <stdint.h>
  52. /*!
  53. * \brief Maximum number of devices (chip selects).
  54. */
  55. #ifndef SPPI0_MAX_DEVICES
  56. #define SPPI0_MAX_DEVICES 4
  57. #endif
  58. #if defined(__AVR__) /* MCU */
  59. /*
  60. * AVR implementation.
  61. * ======================================
  62. */
  63. #ifdef SPPI0_CS0_BIT
  64. #if (SPPI0_CS0_AVRPORT == AVRPORTB)
  65. #define SPPI0_CS0_SOD_REG PORTB
  66. #define SPPI0_CS0_OE_REG DDRB
  67. #elif (SPPI0_CS0_AVRPORT == AVRPORTD)
  68. #define SPPI0_CS0_SOD_REG PORTD
  69. #define SPPI0_CS0_OE_REG DDRD
  70. #elif (SPPI0_CS0_AVRPORT == AVRPORTE)
  71. #define SPPI0_CS0_SOD_REG PORTE
  72. #define SPPI0_CS0_OE_REG DDRE
  73. #elif (SPPI0_CS0_AVRPORT == AVRPORTF)
  74. #define SPPI0_CS0_SOD_REG PORTF
  75. #define SPPI0_CS0_OE_REG DDRF
  76. #elif (SPPI0_CS0_AVRPORT == AVRPORTG)
  77. #define SPPI0_CS0_SOD_REG PORTG
  78. #define SPPI0_CS0_OE_REG DDRG
  79. #elif (SPPI0_CS0_AVRPORT == AVRPORTH)
  80. #define SPPI0_CS0_SOD_REG PORTH
  81. #define SPPI0_CS0_OE_REG DDRH
  82. #endif
  83. /*! \brief Enable SPPI0 chip select 0 output. */
  84. #define SPPI0_CS0_ENA() sbi(SPPI0_CS0_OE_REG, SPPI0_CS0_BIT)
  85. /*! \brief Set SPPI0 chip select 0 output low. */
  86. #define SPPI0_CS0_CLR() cbi(SPPI0_CS0_SOD_REG, SPPI0_CS0_BIT)
  87. /*! \brief Set SPPI0 chip select 0 output high. */
  88. #define SPPI0_CS0_SET() sbi(SPPI0_CS0_SOD_REG, SPPI0_CS0_BIT)
  89. #endif /* SPPI0_CS0_BIT */
  90. #ifdef SPPI0_CS1_BIT
  91. #if (SPPI0_CS1_AVRPORT == AVRPORTB)
  92. #define SPPI0_CS1_SOD_REG PORTB
  93. #define SPPI0_CS1_OE_REG DDRB
  94. #elif (SPPI0_CS1_AVRPORT == AVRPORTD)
  95. #define SPPI0_CS1_SOD_REG PORTD
  96. #define SPPI0_CS1_OE_REG DDRD
  97. #elif (SPPI0_CS1_AVRPORT == AVRPORTE)
  98. #define SPPI0_CS1_SOD_REG PORTE
  99. #define SPPI0_CS1_OE_REG DDRE
  100. #elif (SPPI0_CS1_AVRPORT == AVRPORTF)
  101. #define SPPI0_CS1_SOD_REG PORTF
  102. #define SPPI0_CS1_OE_REG DDRF
  103. #elif (SPPI0_CS1_AVRPORT == AVRPORTG)
  104. #define SPPI0_CS1_SOD_REG PORTG
  105. #define SPPI0_CS1_OE_REG DDRG
  106. #elif (SPPI0_CS1_AVRPORT == AVRPORTH)
  107. #define SPPI0_CS1_SOD_REG PORTH
  108. #define SPPI0_CS1_OE_REG DDRH
  109. #endif
  110. /*! \brief Enable SPPI0 chip select 1 output. */
  111. #define SPPI0_CS1_ENA() sbi(SPPI0_CS1_OE_REG, SPPI0_CS1_BIT)
  112. /*! \brief Set SPPI0 chip select 1 output low. */
  113. #define SPPI0_CS1_CLR() cbi(SPPI0_CS1_SOD_REG, SPPI0_CS1_BIT)
  114. /*! \brief Set SPPI0 chip select 1 output high. */
  115. #define SPPI0_CS1_SET() sbi(SPPI0_CS1_SOD_REG, SPPI0_CS1_BIT)
  116. #endif /* SPPI0_CS1_BIT */
  117. #ifdef SPPI0_CS2_BIT
  118. #if (SPPI0_CS2_AVRPORT == AVRPORTB)
  119. #define SPPI0_CS2_SOD_REG PORTB
  120. #define SPPI0_CS2_OE_REG DDRB
  121. #elif (SPPI0_CS2_AVRPORT == AVRPORTD)
  122. #define SPPI0_CS2_SOD_REG PORTD
  123. #define SPPI0_CS2_OE_REG DDRD
  124. #elif (SPPI0_CS2_AVRPORT == AVRPORTE)
  125. #define SPPI0_CS2_SOD_REG PORTE
  126. #define SPPI0_CS2_OE_REG DDRE
  127. #elif (SPPI0_CS2_AVRPORT == AVRPORTF)
  128. #define SPPI0_CS2_SOD_REG PORTF
  129. #define SPPI0_CS2_OE_REG DDRF
  130. #elif (SPPI0_CS2_AVRPORT == AVRPORTG)
  131. #define SPPI0_CS2_SOD_REG PORTG
  132. #define SPPI0_CS2_OE_REG DDRG
  133. #elif (SPPI0_CS2_AVRPORT == AVRPORTH)
  134. #define SPPI0_CS2_SOD_REG PORTH
  135. #define SPPI0_CS2_OE_REG DDRH
  136. #endif
  137. /*! \brief Enable SPPI0 chip select 2 output. */
  138. #define SPPI0_CS2_ENA() sbi(SPPI0_CS2_OE_REG, SPPI0_CS2_BIT)
  139. /*! \brief Set SPPI0 chip select 2 output low. */
  140. #define SPPI0_CS2_CLR() cbi(SPPI0_CS2_SOD_REG, SPPI0_CS2_BIT)
  141. /*! \brief Set SPPI0 chip select 2 output high. */
  142. #define SPPI0_CS2_SET() sbi(SPPI0_CS2_SOD_REG, SPPI0_CS2_BIT)
  143. #endif /* SPPI0_CS2_BIT */
  144. #ifdef SPPI0_CS3_BIT
  145. #if (SPPI0_CS3_AVRPORT == AVRPORTB)
  146. #define SPPI0_CS3_SOD_REG PORTB
  147. #define SPPI0_CS3_OE_REG DDRB
  148. #elif (SPPI0_CS3_AVRPORT == AVRPORTD)
  149. #define SPPI0_CS3_SOD_REG PORTD
  150. #define SPPI0_CS3_OE_REG DDRD
  151. #elif (SPPI0_CS3_AVRPORT == AVRPORTE)
  152. #define SPPI0_CS3_SOD_REG PORTE
  153. #define SPPI0_CS3_OE_REG DDRE
  154. #elif (SPPI0_CS3_AVRPORT == AVRPORTF)
  155. #define SPPI0_CS3_SOD_REG PORTF
  156. #define SPPI0_CS3_OE_REG DDRF
  157. #elif (SPPI0_CS3_AVRPORT == AVRPORTG)
  158. #define SPPI0_CS3_SOD_REG PORTG
  159. #define SPPI0_CS3_OE_REG DDRG
  160. #elif (SPPI0_CS3_AVRPORT == AVRPORTH)
  161. #define SPPI0_CS3_SOD_REG PORTH
  162. #define SPPI0_CS3_OE_REG DDRH
  163. #endif
  164. /*! \brief Enable SPPI0 chip select 3 output. */
  165. #define SPPI0_CS3_ENA() sbi(SPPI0_CS3_OE_REG, SPPI0_CS3_BIT)
  166. /*! \brief Set SPPI0 chip select 3 output low. */
  167. #define SPPI0_CS3_CLR() cbi(SPPI0_CS3_SOD_REG, SPPI0_CS3_BIT)
  168. /*! \brief Set SPPI0 chip select 3 output high. */
  169. #define SPPI0_CS3_SET() sbi(SPPI0_CS3_SOD_REG, SPPI0_CS3_BIT)
  170. #endif /* SPPI0_CS3_BIT */
  171. #ifdef SPPI0_RST0_BIT
  172. #if (SPPI0_RST0_AVRPORT == AVRPORTB)
  173. #define SPPI0_RST0_SOD_REG PORTB
  174. #define SPPI0_RST0_OE_REG DDRB
  175. #elif (SPPI0_RST0_AVRPORT == AVRPORTD)
  176. #define SPPI0_RST0_SOD_REG PORTD
  177. #define SPPI0_RST0_OE_REG DDRD
  178. #elif (SPPI0_RST0_AVRPORT == AVRPORTE)
  179. #define SPPI0_RST0_SOD_REG PORTE
  180. #define SPPI0_RST0_OE_REG DDRE
  181. #elif (SPPI0_RST0_AVRPORT == AVRPORTF)
  182. #define SPPI0_RST0_SOD_REG PORTF
  183. #define SPPI0_RST0_OE_REG DDRF
  184. #elif (SPPI0_RST0_AVRPORT == AVRPORTG)
  185. #define SPPI0_RST0_SOD_REG PORTG
  186. #define SPPI0_RST0_OE_REG DDRG
  187. #elif (SPPI0_RST0_AVRPORT == AVRPORTH)
  188. #define SPPI0_RST0_SOD_REG PORTH
  189. #define SPPI0_RST0_OE_REG DDRH
  190. #endif
  191. /*! \brief Enable SPPI0 reset 0 output. */
  192. #define SPPI0_RST0_ENA() sbi(SPPI0_RST0_OE_REG, SPPI0_RST0_BIT)
  193. /*! \brief Set SPPI0 reset 0 output low. */
  194. #define SPPI0_RST0_CLR() cbi(SPPI0_RST0_SOD_REG, SPPI0_RST0_BIT)
  195. /*! \brief Set SPPI0 reset 0 output high. */
  196. #define SPPI0_RST0_SET() sbi(SPPI0_RST0_SOD_REG, SPPI0_RST0_BIT)
  197. #endif /* SPPI0_RST0_BIT */
  198. #ifdef SPPI0_RST1_BIT
  199. #if (SPPI0_RST1_AVRPORT == AVRPORTB)
  200. #define SPPI0_RST1_SOD_REG PORTB
  201. #define SPPI0_RST1_OE_REG DDRB
  202. #elif (SPPI0_RST1_AVRPORT == AVRPORTD)
  203. #define SPPI0_RST1_SOD_REG PORTD
  204. #define SPPI0_RST1_OE_REG DDRD
  205. #elif (SPPI0_RST1_AVRPORT == AVRPORTE)
  206. #define SPPI0_RST1_SOD_REG PORTE
  207. #define SPPI0_RST1_OE_REG DDRE
  208. #elif (SPPI0_RST1_AVRPORT == AVRPORTF)
  209. #define SPPI0_RST1_SOD_REG PORTF
  210. #define SPPI0_RST1_OE_REG DDRF
  211. #elif (SPPI0_RST1_AVRPORT == AVRPORTG)
  212. #define SPPI0_RST1_SOD_REG PORTG
  213. #define SPPI0_RST1_OE_REG DDRG
  214. #elif (SPPI0_RST1_AVRPORT == AVRPORTH)
  215. #define SPPI0_RST1_SOD_REG PORTH
  216. #define SPPI0_RST1_OE_REG DDRH
  217. #endif
  218. /*! \brief Enable SPPI0 reset 1 output. */
  219. #define SPPI0_RST1_ENA() sbi(SPPI0_RST1_OE_REG, SPPI0_RST1_BIT)
  220. /*! \brief Set SPPI0 reset 1 output low. */
  221. #define SPPI0_RST1_CLR() cbi(SPPI0_RST1_SOD_REG, SPPI0_RST1_BIT)
  222. /*! \brief Set SPPI0 reset 1 output high. */
  223. #define SPPI0_RST1_SET() sbi(SPPI0_RST1_SOD_REG, SPPI0_RST1_BIT)
  224. #endif /* SPPI0_RST1_BIT */
  225. #ifdef SPPI0_RST2_BIT
  226. #if (SPPI0_RST2_AVRPORT == AVRPORTB)
  227. #define SPPI0_RST2_SOD_REG PORTB
  228. #define SPPI0_RST2_OE_REG DDRB
  229. #elif (SPPI0_RST2_AVRPORT == AVRPORTD)
  230. #define SPPI0_RST2_SOD_REG PORTD
  231. #define SPPI0_RST2_OE_REG DDRD
  232. #elif (SPPI0_RST2_AVRPORT == AVRPORTE)
  233. #define SPPI0_RST2_SOD_REG PORTE
  234. #define SPPI0_RST2_OE_REG DDRE
  235. #elif (SPPI0_RST2_AVRPORT == AVRPORTF)
  236. #define SPPI0_RST2_SOD_REG PORTF
  237. #define SPPI0_RST2_OE_REG DDRF
  238. #elif (SPPI0_RST2_AVRPORT == AVRPORTG)
  239. #define SPPI0_RST2_SOD_REG PORTG
  240. #define SPPI0_RST2_OE_REG DDRG
  241. #elif (SPPI0_RST2_AVRPORT == AVRPORTH)
  242. #define SPPI0_RST2_SOD_REG PORTH
  243. #define SPPI0_RST2_OE_REG DDRH
  244. #endif
  245. /*! \brief Enable SPPI0 reset 2 output. */
  246. #define SPPI0_RST2_ENA() sbi(SPPI0_RST2_OE_REG, SPPI0_RST2_BIT)
  247. /*! \brief Set SPPI0 chip reset 2 output low. */
  248. #define SPPI0_RST2_CLR() cbi(SPPI0_RST2_SOD_REG, SPPI0_RST2_BIT)
  249. /*! \brief Set SPPI0 chip reset 2 output high. */
  250. #define SPPI0_RST2_SET() sbi(SPPI0_RST2_SOD_REG, SPPI0_RST2_BIT)
  251. #endif /* SPPI0_RST2_BIT */
  252. #ifdef SPPI0_RST3_BIT
  253. #if (SPPI0_RST3_AVRPORT == AVRPORTB)
  254. #define SPPI0_RST3_SOD_REG PORTB
  255. #define SPPI0_RST3_OE_REG DDRB
  256. #elif (SPPI0_RST3_AVRPORT == AVRPORTD)
  257. #define SPPI0_RST3_SOD_REG PORTD
  258. #define SPPI0_RST3_OE_REG DDRD
  259. #elif (SPPI0_RST3_AVRPORT == AVRPORTE)
  260. #define SPPI0_RST3_SOD_REG PORTE
  261. #define SPPI0_RST3_OE_REG DDRE
  262. #elif (SPPI0_RST3_AVRPORT == AVRPORTF)
  263. #define SPPI0_RST3_SOD_REG PORTF
  264. #define SPPI0_RST3_OE_REG DDRF
  265. #elif (SPPI0_RST3_AVRPORT == AVRPORTG)
  266. #define SPPI0_RST3_SOD_REG PORTG
  267. #define SPPI0_RST3_OE_REG DDRG
  268. #elif (SPPI0_RST3_AVRPORT == AVRPORTH)
  269. #define SPPI0_RST3_SOD_REG PORTH
  270. #define SPPI0_RST3_OE_REG DDRH
  271. #endif
  272. /*! \brief Enable SPPI0 reset 3 output. */
  273. #define SPPI0_RST3_ENA() sbi(SPPI0_RST3_OE_REG, SPPI0_RST3_BIT)
  274. /*! \brief Set SPPI0 reset 3 output low. */
  275. #define SPPI0_RST3_CLR() cbi(SPPI0_RST3_SOD_REG, SPPI0_RST3_BIT)
  276. /*! \brief Set SPPI0 reset 3 output high. */
  277. #define SPPI0_RST3_SET() sbi(SPPI0_RST3_SOD_REG, SPPI0_RST3_BIT)
  278. #endif /* SPPI0_RST3_BIT */
  279. #else /* MCU */
  280. /*
  281. * AT91 implementation.
  282. * ======================================
  283. */
  284. #ifdef SPPI0_CS0_BIT
  285. #if !defined(SPPI0_CS0_PIO_ID)
  286. #define SPPI0_CS0_PE_REG PIO_PER
  287. #define SPPI0_CS0_OE_REG PIO_OER
  288. #define SPPI0_CS0_COD_REG PIO_CODR
  289. #define SPPI0_CS0_SOD_REG PIO_SODR
  290. #elif SPPI0_CS0_PIO_ID == PIO_ID
  291. #define SPPI0_CS0_PE_REG PIO_PER
  292. #define SPPI0_CS0_OE_REG PIO_OER
  293. #define SPPI0_CS0_COD_REG PIO_CODR
  294. #define SPPI0_CS0_SOD_REG PIO_SODR
  295. #elif SPPI0_CS0_PIO_ID == PIOA_ID
  296. #define SPPI0_CS0_PE_REG PIOA_PER
  297. #define SPPI0_CS0_OE_REG PIOA_OER
  298. #define SPPI0_CS0_COD_REG PIOA_CODR
  299. #define SPPI0_CS0_SOD_REG PIOA_SODR
  300. #elif SPPI0_CS0_PIO_ID == PIOB_ID
  301. #define SPPI0_CS0_PE_REG PIOB_PER
  302. #define SPPI0_CS0_OE_REG PIOB_OER
  303. #define SPPI0_CS0_COD_REG PIOB_CODR
  304. #define SPPI0_CS0_SOD_REG PIOB_SODR
  305. #elif SPPI0_CS0_PIO_ID == PIOC_ID
  306. #define SPPI0_CS0_PE_REG PIOC_PER
  307. #define SPPI0_CS0_OE_REG PIOC_OER
  308. #define SPPI0_CS0_COD_REG PIOC_CODR
  309. #define SPPI0_CS0_SOD_REG PIOC_SODR
  310. #endif
  311. /*! \brief Enable SPPI0 chip select 0 output. */
  312. #define SPPI0_CS0_ENA() \
  313. outr(SPPI0_CS0_PE_REG, _BV(SPPI0_CS0_BIT)); \
  314. outr(SPPI0_CS0_OE_REG, _BV(SPPI0_CS0_BIT))
  315. /*! \brief Set SPPI0 chip select 0 output low. */
  316. #define SPPI0_CS0_CLR() outr(SPPI0_CS0_COD_REG, _BV(SPPI0_CS0_BIT))
  317. /*! \brief Set SPPI0 chip select 0 output high. */
  318. #define SPPI0_CS0_SET() outr(SPPI0_CS0_SOD_REG, _BV(SPPI0_CS0_BIT))
  319. #endif /* SPPI0_CS0_BIT */
  320. #ifdef SPPI0_CS1_BIT
  321. #if !defined(SPPI0_CS1_PIO_ID)
  322. #define SPPI0_CS1_PE_REG PIO_PER
  323. #define SPPI0_CS1_OE_REG PIO_OER
  324. #define SPPI0_CS1_COD_REG PIO_CODR
  325. #define SPPI0_CS1_SOD_REG PIO_SODR
  326. #elif SPPI0_CS1_PIO_ID == PIO_ID
  327. #define SPPI0_CS1_PE_REG PIO_PER
  328. #define SPPI0_CS1_OE_REG PIO_OER
  329. #define SPPI0_CS1_COD_REG PIO_CODR
  330. #define SPPI0_CS1_SOD_REG PIO_SODR
  331. #elif SPPI0_CS1_PIO_ID == PIOA_ID
  332. #define SPPI0_CS1_PE_REG PIOA_PER
  333. #define SPPI0_CS1_OE_REG PIOA_OER
  334. #define SPPI0_CS1_COD_REG PIOA_CODR
  335. #define SPPI0_CS1_SOD_REG PIOA_SODR
  336. #elif SPPI0_CS1_PIO_ID == PIOB_ID
  337. #define SPPI0_CS1_PE_REG PIOB_PER
  338. #define SPPI0_CS1_OE_REG PIOB_OER
  339. #define SPPI0_CS1_COD_REG PIOB_CODR
  340. #define SPPI0_CS1_SOD_REG PIOB_SODR
  341. #elif SPPI0_CS1_PIO_ID == PIOC_ID
  342. #define SPPI0_CS1_PE_REG PIOC_PER
  343. #define SPPI0_CS1_OE_REG PIOC_OER
  344. #define SPPI0_CS1_COD_REG PIOC_CODR
  345. #define SPPI0_CS1_SOD_REG PIOC_SODR
  346. #endif
  347. /*! \brief Enable SPPI0 chip select output. */
  348. #define SPPI0_CS1_ENA() \
  349. outr(SPPI0_CS1_PE_REG, _BV(SPPI0_CS1_BIT)); \
  350. outr(SPPI0_CS1_OE_REG, _BV(SPPI0_CS1_BIT))
  351. /*! \brief Set SPPI0 chip select output low. */
  352. #define SPPI0_CS1_CLR() outr(SPPI0_CS1_COD_REG, _BV(SPPI0_CS1_BIT))
  353. /*! \brief Set SPPI0 chip select output high. */
  354. #define SPPI0_CS1_SET() outr(SPPI0_CS1_SOD_REG, _BV(SPPI0_CS1_BIT))
  355. #endif /* SPPI0_CS1_BIT */
  356. #ifdef SPPI0_CS2_BIT
  357. #if !defined(SPPI0_CS2_PIO_ID)
  358. #define SPPI0_CS2_PE_REG PIO_PER
  359. #define SPPI0_CS2_OE_REG PIO_OER
  360. #define SPPI0_CS2_COD_REG PIO_CODR
  361. #define SPPI0_CS2_SOD_REG PIO_SODR
  362. #elif SPPI0_CS2_PIO_ID == PIO_ID
  363. #define SPPI0_CS2_PE_REG PIO_PER
  364. #define SPPI0_CS2_OE_REG PIO_OER
  365. #define SPPI0_CS2_COD_REG PIO_CODR
  366. #define SPPI0_CS2_SOD_REG PIO_SODR
  367. #elif SPPI0_CS2_PIO_ID == PIOA_ID
  368. #define SPPI0_CS2_PE_REG PIOA_PER
  369. #define SPPI0_CS2_OE_REG PIOA_OER
  370. #define SPPI0_CS2_COD_REG PIOA_CODR
  371. #define SPPI0_CS2_SOD_REG PIOA_SODR
  372. #elif SPPI0_CS2_PIO_ID == PIOB_ID
  373. #define SPPI0_CS2_PE_REG PIOB_PER
  374. #define SPPI0_CS2_OE_REG PIOB_OER
  375. #define SPPI0_CS2_COD_REG PIOB_CODR
  376. #define SPPI0_CS2_SOD_REG PIOB_SODR
  377. #elif SPPI0_CS2_PIO_ID == PIOC_ID
  378. #define SPPI0_CS2_PE_REG PIOC_PER
  379. #define SPPI0_CS2_OE_REG PIOC_OER
  380. #define SPPI0_CS2_COD_REG PIOC_CODR
  381. #define SPPI0_CS2_SOD_REG PIOC_SODR
  382. #endif
  383. /*! \brief Enable SPPI0 chip select output. */
  384. #define SPPI0_CS2_ENA() \
  385. outr(SPPI0_CS2_PE_REG, _BV(SPPI0_CS2_BIT)); \
  386. outr(SPPI0_CS2_OE_REG, _BV(SPPI0_CS2_BIT))
  387. /*! \brief Set SPPI0 chip select output low. */
  388. #define SPPI0_CS2_CLR() outr(SPPI0_CS2_COD_REG, _BV(SPPI0_CS2_BIT))
  389. /*! \brief Set SPPI0 chip select output high. */
  390. #define SPPI0_CS2_SET() outr(SPPI0_CS2_SOD_REG, _BV(SPPI0_CS2_BIT))
  391. #endif /* SPPI0_CS2_BIT */
  392. #ifdef SPPI0_CS3_BIT
  393. #if !defined(SPPI0_CS3_PIO_ID)
  394. #define SPPI0_CS3_PE_REG PIO_PER
  395. #define SPPI0_CS3_OE_REG PIO_OER
  396. #define SPPI0_CS3_COD_REG PIO_CODR
  397. #define SPPI0_CS3_SOD_REG PIO_SODR
  398. #elif SPPI0_CS3_PIO_ID == PIO_ID
  399. #define SPPI0_CS3_PE_REG PIO_PER
  400. #define SPPI0_CS3_OE_REG PIO_OER
  401. #define SPPI0_CS3_COD_REG PIO_CODR
  402. #define SPPI0_CS3_SOD_REG PIO_SODR
  403. #elif SPPI0_CS3_PIO_ID == PIOA_ID
  404. #define SPPI0_CS3_PE_REG PIOA_PER
  405. #define SPPI0_CS3_OE_REG PIOA_OER
  406. #define SPPI0_CS3_COD_REG PIOA_CODR
  407. #define SPPI0_CS3_SOD_REG PIOA_SODR
  408. #elif SPPI0_CS3_PIO_ID == PIOB_ID
  409. #define SPPI0_CS3_PE_REG PIOB_PER
  410. #define SPPI0_CS3_OE_REG PIOB_OER
  411. #define SPPI0_CS3_COD_REG PIOB_CODR
  412. #define SPPI0_CS3_SOD_REG PIOB_SODR
  413. #elif SPPI0_CS3_PIO_ID == PIOC_ID
  414. #define SPPI0_CS3_PE_REG PIOC_PER
  415. #define SPPI0_CS3_OE_REG PIOC_OER
  416. #define SPPI0_CS3_COD_REG PIOC_CODR
  417. #define SPPI0_CS3_SOD_REG PIOC_SODR
  418. #endif
  419. /*! \brief Enable SPPI0 chip select output. */
  420. #define SPPI0_CS3_ENA() \
  421. outr(SPPI0_CS3_PE_REG, _BV(SPPI0_CS3_BIT)); \
  422. outr(SPPI0_CS3_OE_REG, _BV(SPPI0_CS3_BIT))
  423. /*! \brief Set SPPI0 chip select output low. */
  424. #define SPPI0_CS3_CLR() outr(SPPI0_CS3_COD_REG, _BV(SPPI0_CS3_BIT))
  425. /*! \brief Set SPPI0 chip select output high. */
  426. #define SPPI0_CS3_SET() outr(SPPI0_CS3_SOD_REG, _BV(SPPI0_CS3_BIT))
  427. #endif /* SPPI0_CS3_BIT */
  428. #ifdef SPPI0_RST0_BIT
  429. #if !defined(SPPI0_RST0_PIO_ID)
  430. #define SPPI0_RST0_PE_REG PIO_PER
  431. #define SPPI0_RST0_OE_REG PIO_OER
  432. #define SPPI0_RST0_COD_REG PIO_CODR
  433. #define SPPI0_RST0_SOD_REG PIO_SODR
  434. #elif SPPI0_RST0_PIO_ID == PIO_ID
  435. #define SPPI0_RST0_PE_REG PIO_PER
  436. #define SPPI0_RST0_OE_REG PIO_OER
  437. #define SPPI0_RST0_COD_REG PIO_CODR
  438. #define SPPI0_RST0_SOD_REG PIO_SODR
  439. #elif SPPI0_RST0_PIO_ID == PIOA_ID
  440. #define SPPI0_RST0_PE_REG PIOA_PER
  441. #define SPPI0_RST0_OE_REG PIOA_OER
  442. #define SPPI0_RST0_COD_REG PIOA_CODR
  443. #define SPPI0_RST0_SOD_REG PIOA_SODR
  444. #elif SPPI0_RST0_PIO_ID == PIOB_ID
  445. #define SPPI0_RST0_PE_REG PIOB_PER
  446. #define SPPI0_RST0_OE_REG PIOB_OER
  447. #define SPPI0_RST0_COD_REG PIOB_CODR
  448. #define SPPI0_RST0_SOD_REG PIOB_SODR
  449. #elif SPPI0_RST0_PIO_ID == PIOC_ID
  450. #define SPPI0_RST0_PE_REG PIOC_PER
  451. #define SPPI0_RST0_OE_REG PIOC_OER
  452. #define SPPI0_RST0_COD_REG PIOC_CODR
  453. #define SPPI0_RST0_SOD_REG PIOC_SODR
  454. #endif
  455. /*! \brief Enable SPPI0 reset output. */
  456. #define SPPI0_RST0_ENA() \
  457. outr(SPPI0_RST0_PE_REG, _BV(SPPI0_RST0_BIT)); \
  458. outr(SPPI0_RST0_OE_REG, _BV(SPPI0_RST0_BIT))
  459. /*! \brief Set SPPI0 reset output low. */
  460. #define SPPI0_RST0_CLR() outr(SPPI0_RST0_COD_REG, _BV(SPPI0_RST0_BIT))
  461. /*! \brief Set SPPI0 reset output high. */
  462. #define SPPI0_RST0_SET() outr(SPPI0_RST0_SOD_REG, _BV(SPPI0_RST0_BIT))
  463. #endif /* SPPI0_RST0_BIT */
  464. #ifdef SPPI0_RST1_BIT
  465. #if !defined(SPPI0_RST1_PIO_ID)
  466. #define SPPI0_RST1_PE_REG PIO_PER
  467. #define SPPI0_RST1_OE_REG PIO_OER
  468. #define SPPI0_RST1_COD_REG PIO_CODR
  469. #define SPPI0_RST1_SOD_REG PIO_SODR
  470. #elif SPPI0_RST1_PIO_ID == PIO_ID
  471. #define SPPI0_RST1_PE_REG PIO_PER
  472. #define SPPI0_RST1_OE_REG PIO_OER
  473. #define SPPI0_RST1_COD_REG PIO_CODR
  474. #define SPPI0_RST1_SOD_REG PIO_SODR
  475. #elif SPPI0_RST1_PIO_ID == PIOA_ID
  476. #define SPPI0_RST1_PE_REG PIOA_PER
  477. #define SPPI0_RST1_OE_REG PIOA_OER
  478. #define SPPI0_RST1_COD_REG PIOA_CODR
  479. #define SPPI0_RST1_SOD_REG PIOA_SODR
  480. #elif SPPI0_RST1_PIO_ID == PIOB_ID
  481. #define SPPI0_RST1_PE_REG PIOB_PER
  482. #define SPPI0_RST1_OE_REG PIOB_OER
  483. #define SPPI0_RST1_COD_REG PIOB_CODR
  484. #define SPPI0_RST1_SOD_REG PIOB_SODR
  485. #elif SPPI0_RST1_PIO_ID == PIOC_ID
  486. #define SPPI0_RST1_PE_REG PIOC_PER
  487. #define SPPI0_RST1_OE_REG PIOC_OER
  488. #define SPPI0_RST1_COD_REG PIOC_CODR
  489. #define SPPI0_RST1_SOD_REG PIOC_SODR
  490. #endif
  491. /*! \brief Enable SPPI0 reset output. */
  492. #define SPPI0_RST1_ENA() \
  493. outr(SPPI0_RST1_PE_REG, _BV(SPPI0_RST1_BIT)); \
  494. outr(SPPI0_RST1_OE_REG, _BV(SPPI0_RST1_BIT))
  495. /*! \brief Set SPPI0 reset output low. */
  496. #define SPPI0_RST1_CLR() outr(SPPI0_RST1_COD_REG, _BV(SPPI0_RST1_BIT))
  497. /*! \brief Set SPPI0 reset output high. */
  498. #define SPPI0_RST1_SET() outr(SPPI0_RST1_SOD_REG, _BV(SPPI0_RST1_BIT))
  499. #endif /* SPPI0_RST1_BIT */
  500. #ifdef SPPI0_RST2_BIT
  501. #if !defined(SPPI0_RST2_PIO_ID)
  502. #define SPPI0_RST2_PE_REG PIO_PER
  503. #define SPPI0_RST2_OE_REG PIO_OER
  504. #define SPPI0_RST2_COD_REG PIO_CODR
  505. #define SPPI0_RST2_SOD_REG PIO_SODR
  506. #elif SPPI0_RST2_PIO_ID == PIO_ID
  507. #define SPPI0_RST2_PE_REG PIO_PER
  508. #define SPPI0_RST2_OE_REG PIO_OER
  509. #define SPPI0_RST2_COD_REG PIO_CODR
  510. #define SPPI0_RST2_SOD_REG PIO_SODR
  511. #elif SPPI0_RST2_PIO_ID == PIOA_ID
  512. #define SPPI0_RST2_PE_REG PIOA_PER
  513. #define SPPI0_RST2_OE_REG PIOA_OER
  514. #define SPPI0_RST2_COD_REG PIOA_CODR
  515. #define SPPI0_RST2_SOD_REG PIOA_SODR
  516. #elif SPPI0_RST2_PIO_ID == PIOB_ID
  517. #define SPPI0_RST2_PE_REG PIOB_PER
  518. #define SPPI0_RST2_OE_REG PIOB_OER
  519. #define SPPI0_RST2_COD_REG PIOB_CODR
  520. #define SPPI0_RST2_SOD_REG PIOB_SODR
  521. #elif SPPI0_RST2_PIO_ID == PIOC_ID
  522. #define SPPI0_RST2_PE_REG PIOC_PER
  523. #define SPPI0_RST2_OE_REG PIOC_OER
  524. #define SPPI0_RST2_COD_REG PIOC_CODR
  525. #define SPPI0_RST2_SOD_REG PIOC_SODR
  526. #endif
  527. /*! \brief Enable SPPI0 reset output. */
  528. #define SPPI0_RST2_ENA() \
  529. outr(SPPI0_RST2_PE_REG, _BV(SPPI0_RST2_BIT)); \
  530. outr(SPPI0_RST2_OE_REG, _BV(SPPI0_RST2_BIT))
  531. /*! \brief Set SPPI0 reset output low. */
  532. #define SPPI0_RST2_CLR() outr(SPPI0_RST2_COD_REG, _BV(SPPI0_RST2_BIT))
  533. /*! \brief Set SPPI0 reset output high. */
  534. #define SPPI0_RST2_SET() outr(SPPI0_RST2_SOD_REG, _BV(SPPI0_RST2_BIT))
  535. #endif /* SPPI0_RST2_BIT */
  536. #ifdef SPPI0_RST3_BIT
  537. #if !defined(SPPI0_RST3_PIO_ID)
  538. #define SPPI0_RST3_PE_REG PIO_PER
  539. #define SPPI0_RST3_OE_REG PIO_OER
  540. #define SPPI0_RST3_COD_REG PIO_CODR
  541. #define SPPI0_RST3_SOD_REG PIO_SODR
  542. #elif SPPI0_RST3_PIO_ID == PIO_ID
  543. #define SPPI0_RST3_PE_REG PIO_PER
  544. #define SPPI0_RST3_OE_REG PIO_OER
  545. #define SPPI0_RST3_COD_REG PIO_CODR
  546. #define SPPI0_RST3_SOD_REG PIO_SODR
  547. #elif SPPI0_RST3_PIO_ID == PIOA_ID
  548. #define SPPI0_RST3_PE_REG PIOA_PER
  549. #define SPPI0_RST3_OE_REG PIOA_OER
  550. #define SPPI0_RST3_COD_REG PIOA_CODR
  551. #define SPPI0_RST3_SOD_REG PIOA_SODR
  552. #elif SPPI0_RST3_PIO_ID == PIOB_ID
  553. #define SPPI0_RST3_PE_REG PIOB_PER
  554. #define SPPI0_RST3_OE_REG PIOB_OER
  555. #define SPPI0_RST3_COD_REG PIOB_CODR
  556. #define SPPI0_RST3_SOD_REG PIOB_SODR
  557. #elif SPPI0_RST3_PIO_ID == PIOC_ID
  558. #define SPPI0_RST3_PE_REG PIOC_PER
  559. #define SPPI0_RST3_OE_REG PIOC_OER
  560. #define SPPI0_RST3_COD_REG PIOC_CODR
  561. #define SPPI0_RST3_SOD_REG PIOC_SODR
  562. #endif
  563. /*! \brief Enable SPPI0 reset output. */
  564. #define SPPI0_RST3_ENA() \
  565. outr(SPPI0_RST3_PE_REG, _BV(SPPI0_RST3_BIT)); \
  566. outr(SPPI0_RST3_OE_REG, _BV(SPPI0_RST3_BIT))
  567. /*! \brief Set SPPI0 reset output low. */
  568. #define SPPI0_RST3_CLR() outr(SPPI0_RST3_COD_REG, _BV(SPPI0_RST3_BIT))
  569. /*! \brief Set SPPI0 reset output high. */
  570. #define SPPI0_RST3_SET() outr(SPPI0_RST3_SOD_REG, _BV(SPPI0_RST3_BIT))
  571. #endif /* SPPI0_RST3_BIT */
  572. #endif /* MCU */
  573. extern int Sppi0SetMode(ureg_t ix, ureg_t mode);
  574. extern void Sppi0SetSpeed(ureg_t ix, uint32_t rate);
  575. extern void Sppi0Enable(ureg_t ix);
  576. extern void Sppi0ChipReset(ureg_t ix, uint8_t hi);
  577. extern void Sppi0ChipSelect(ureg_t ix, uint8_t hi);
  578. extern void Sppi0SelectDevice(ureg_t ix);
  579. extern void Sppi0DeselectDevice(ureg_t ix);
  580. extern void Sppi0NegSelectDevice(ureg_t ix);
  581. extern void Sppi0NegDeselectDevice(ureg_t ix);
  582. extern uint8_t Sppi0Byte(uint8_t data);
  583. extern void Sppi0Transact(const void *wdata, void *rdata, size_t len);
  584. #endif