porttran.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. /*
  2. * Copyright (C) 2008 by egnite GmbH
  3. *
  4. * 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. /*
  36. * $Id: porttran.h 5413 2013-10-18 14:39:32Z u_bonnes $
  37. */
  38. #include <cfg/arch.h>
  39. /*!
  40. * \addtogroup xgPortTranslate
  41. */
  42. /*@{*/
  43. /*!
  44. * \file include/cfg/arch/porttran.h
  45. * \brief Port translations.
  46. *
  47. * This header file determines the target specific GPIO register names
  48. * by a simple configured port identifier. In addition it provides
  49. * several macros to configure, set, clear or query GPIO bits.
  50. *
  51. * Unlike most other header files, this one may be included several
  52. * times within a single source file, typically once for each configured
  53. * identifier.
  54. *
  55. * \code
  56. * #undef GPIO_ID
  57. * #define GPIO_ID MY_PORT1_ID
  58. * #include <cfg/arch/porttran.h>
  59. * static INLINE void MY_PORT1_SET(int bit) { GPIO_SET_HI(bit); }
  60. * static INLINE void MY_PORT1_CLR(int bit) { GPIO_SET_LO(bit); }
  61. *
  62. * #undef GPIO_ID
  63. * #define GPIO_ID MY_PORT2_ID
  64. * #include <cfg/arch/porttran.h>
  65. * static INLINE void MY_PORT2_SET(int bit) { GPIO_SET_HI(bit); }
  66. * static INLINE void MY_PORT2_CLR(int bit) { GPIO_SET_LO(bit); }
  67. *
  68. * void Out1(int bit, int val)
  69. * {
  70. * if (val)
  71. * MY_PORT1_SET(bit);
  72. * else
  73. * MY_PORT1_CLR(bit);
  74. * }
  75. *
  76. * void Toogle2(int bit)
  77. * {
  78. * MY_PORT2_SET(bit);
  79. * MY_PORT2_CLR(bit);
  80. * }
  81. * \endcode
  82. *
  83. * In contrast to the routines in dev/gpio.h, these macros do not
  84. * require any function call and will therefore produce faster and
  85. * smaller code. The following macros are currently available:
  86. *
  87. * - GPIO_SET_LO Sets output low.
  88. * - GPIO_SET_HI Sets output high.
  89. * - GPIO_IS_HI Returns output status.
  90. * - GPIO_GET Returns input status.
  91. * - GPIO_ENABLE Enables GPIO function.
  92. * - GPIO_OUTPUT Configures an output.
  93. * - GPIO_INPUT Configures an input.
  94. * - GPIO_PULLUP_ON Enables input pull-up resistor.
  95. * - GPIO_PULLUP_OFF Disables input pull-up resistor.
  96. * - GPIO_FILTER_ON Enables glitch input filter.
  97. * - GPIO_FILTER_OFF Disables glitch input filter.
  98. * - GPIO_OPENDRAIN Configures open drain output mode.
  99. * - GPIO_PUSHPULL Configures push/pull output mode.
  100. *
  101. * \note All listed macros will be available for any port identifier on
  102. * any target, even if the related function is not available. You
  103. * should check the target's datasheet.
  104. *
  105. * \note We use capital letters for the inline attribute to refer to a
  106. * preprocessor macro. If the compiler doesn't support inlined
  107. * function, then the macro will be empty. In this case a function
  108. * call may be used, depending on the compiler's optimization
  109. * strategy. Even if the compiler supports the inline keyword,
  110. * it may decide to generate a callable function.
  111. */
  112. #if defined(MCU_STM32)
  113. #if defined(MCU_STM32L1)
  114. #define GPIO_SPEED GPIO_CFG_SPEED_MED
  115. #else
  116. #define GPIO_SPEED GPIO_CFG_SPEED_SLOW
  117. #endif
  118. #define GPIO_SET_LO(b) GpioPinSetLow(GPIO_ID, b)
  119. #define GPIO_SET_HI(b) GpioPinSetHigh(GPIO_ID, b)
  120. #define GPIO_IS_HI(b) GpioPinGet(GPIO_ID, b)
  121. #define GPIO_GET(b) GpioPinGet(GPIO_ID, b)
  122. #define GPIO_ENABLE(b) GpioPinConfigSet(GPIO_ID, b, GPIO_CFG_INPUT|GPIO_SPEED)
  123. #define GPIO_OUTPUT(b) GpioPinDrive(GPIO_ID, b)
  124. #define GPIO_INPUT(b) GpioPinRelease(GPIO_ID, b)
  125. #if defined(MCU_STM32F1)
  126. #define GPIO_PULLUP_ON(b)
  127. #define GPIO_PULLUP_OFF(b)
  128. #else
  129. #define GPIO_PULLUP_ON(b) do { \
  130. uint32_t pudr = GPIO_ID->PUPDR; \
  131. pudr &= ~(3<<(b<<1)); \
  132. pudr |= 1<<(b<<1); \
  133. GPIO_ID->PUPDR = pudr; } while(0)
  134. #define GPIO_PULLUP_OFF(b) do { \
  135. uint32_t pudr = GPIO_ID->PUPDR; \
  136. pudr &= 3<<(b<<1); \
  137. GPIO_ID->PUPDR = pudr; } while(0)
  138. #endif
  139. #define GPIO_FILTER_ON(b)
  140. #define GPIO_FILTER_OFF(b)
  141. #define GPIO_OPENDRAIN(b) GpioPinRelease(GPIO_ID, b)
  142. #define GPIO_PUSHPULL(b) GpioPinDrive(GPIO_ID, b)
  143. #else
  144. /*
  145. * Remove any previously defined register names.
  146. */
  147. #undef GPIO_PE_REG
  148. #undef GPIO_PD_REG
  149. #undef GPIO_PS_REG
  150. #undef GPIO_OE_REG
  151. #undef GPIO_OD_REG
  152. #undef GPIO_OS_REG
  153. #undef GPIO_SOD_REG
  154. #undef GPIO_COD_REG
  155. #undef GPIO_ODS_REG
  156. #undef GPIO_PDS_REG
  157. #undef GPIO_PUE_REG
  158. #undef GPIO_PUD_REG
  159. #undef GPIO_PUS_REG
  160. #undef GPIO_MDE_REG
  161. #undef GPIO_MDD_REG
  162. #undef GPIO_MDS_REG
  163. #undef GPIO_IFE_REG
  164. #undef GPIO_IFD_REG
  165. #undef GPIO_IFS_REG
  166. #if defined(__AVR__)
  167. /*
  168. * Determine AVR port names.
  169. */
  170. #include <cfg/arch/avr.h>
  171. #if !defined(GPIO_ID) || GPIO_ID == PIOA_ID
  172. #define GPIO_PDS_REG PINA
  173. #define GPIO_SOD_REG PORTA
  174. #define GPIO_OE_REG DDRA
  175. #define GPIO_PUE_REG PORTA
  176. #elif GPIO_ID == PIOB_ID
  177. #define GPIO_PDS_REG PINB
  178. #define GPIO_SOD_REG PORTB
  179. #define GPIO_OE_REG DDRB
  180. #define GPIO_PUE_REG PORTB
  181. #elif GPIO_ID == PIOC_ID
  182. #define GPIO_PDS_REG PINC
  183. #define GPIO_SOD_REG PORTC
  184. #define GPIO_OE_REG DDRC
  185. #define GPIO_PUE_REG PORTC
  186. #elif GPIO_ID == PIOD_ID
  187. #define GPIO_PDS_REG PIND
  188. #define GPIO_SOD_REG PORTD
  189. #define GPIO_OE_REG DDRD
  190. #define GPIO_PUE_REG PORTD
  191. #elif GPIO_ID == PIOE_ID
  192. #define GPIO_PDS_REG PINE
  193. #define GPIO_SOD_REG PORTE
  194. #define GPIO_OE_REG DDRE
  195. #define GPIO_PUE_REG PORTE
  196. #elif GPIO_ID == PIOF_ID
  197. #define GPIO_PDS_REG PINF
  198. #define GPIO_SOD_REG PORTF
  199. #define GPIO_OE_REG DDRF
  200. #define GPIO_PUE_REG PORTF
  201. #elif GPIO_ID == PIOG_ID
  202. #define GPIO_PDS_REG PING
  203. #define GPIO_SOD_REG PORTG
  204. #define GPIO_OE_REG DDRG
  205. #define GPIO_PUE_REG PORTG
  206. #elif GPIO_ID == PIOH_ID
  207. #define GPIO_PDS_REG PINH
  208. #define GPIO_SOD_REG PORTH
  209. #define GPIO_OE_REG DDRH
  210. #define GPIO_PUE_REG PORTH
  211. #elif GPIO_ID == PIOI_ID
  212. #define GPIO_PDS_REG PINI
  213. #define GPIO_SOD_REG PORTI
  214. #define GPIO_OE_REG DDRI
  215. #define GPIO_PUE_REG PORTI
  216. #elif GPIO_ID == PIOJ_ID
  217. #define GPIO_PDS_REG PINJ
  218. #define GPIO_SOD_REG PORTJ
  219. #define GPIO_OE_REG DDRJ
  220. #define GPIO_PUE_REG PORTJ
  221. #elif GPIO_ID == PIOK_ID
  222. #define GPIO_PDS_REG PINK
  223. #define GPIO_SOD_REG PORTK
  224. #define GPIO_OE_REG DDRK
  225. #define GPIO_PUE_REG PORTK
  226. #elif GPIO_ID == PIOL_ID
  227. #define GPIO_PDS_REG PINL
  228. #define GPIO_SOD_REG PORTL
  229. #define GPIO_OE_REG DDRL
  230. #define GPIO_PUE_REG PORTL
  231. #endif
  232. #elif defined(MCU_AT91)
  233. /*
  234. * Determine AT91 port names.
  235. */
  236. #include <arch/arm/at91.h>
  237. #if !defined(GPIO_ID)
  238. #define GPIO_PE_REG PIO_PER
  239. #define GPIO_PD_REG PIO_PDR
  240. #define GPIO_PS_REG PIO_PSR
  241. #define GPIO_OE_REG PIO_OER
  242. #define GPIO_OD_REG PIO_ODR
  243. #define GPIO_OS_REG PIO_OSR
  244. #define GPIO_SOD_REG PIO_SODR
  245. #define GPIO_COD_REG PIO_CODR
  246. #define GPIO_ODS_REG PIO_ODSR
  247. #define GPIO_PDS_REG PIO_PDSR
  248. #if defined(PIO_PUER)
  249. #define GPIO_PUE_REG PIO_PUER
  250. #if defined(PIO_PUDR)
  251. #define GPIO_PUD_REG PIO_PUDR
  252. #define GPIO_PUS_REG PIO_PUSR
  253. #endif /* PIO_PUDR */
  254. #endif /* PIO_PUER */
  255. #if defined(PIO_MDER)
  256. #define GPIO_MDE_REG PIO_MDER
  257. #if defined(PIO_MDDR)
  258. #define GPIO_MDD_REG PIO_MDDR
  259. #define GPIO_MDS_REG PIO_MDSR
  260. #endif /* PIO_MDDR */
  261. #endif /* PIO_MDER */
  262. #if defined(PIO_IFER)
  263. #define GPIO_IFE_REG PIO_IFER
  264. #if defined(PIO_IFDR)
  265. #define GPIO_IFD_REG PIO_IFDR
  266. #define GPIO_IFS_REG PIO_IFSR
  267. #endif /* PIO_IFDR */
  268. #endif /* PIO_IFER */
  269. #elif GPIO_ID == PIOA_ID
  270. #define GPIO_PE_REG PIOA_PER
  271. #define GPIO_PD_REG PIOA_PDR
  272. #define GPIO_PS_REG PIOA_PSR
  273. #define GPIO_OE_REG PIOA_OER
  274. #define GPIO_OD_REG PIOA_ODR
  275. #define GPIO_OS_REG PIOA_OSR
  276. #define GPIO_SOD_REG PIOA_SODR
  277. #define GPIO_COD_REG PIOA_CODR
  278. #define GPIO_ODS_REG PIOA_ODSR
  279. #define GPIO_PDS_REG PIOA_PDSR
  280. #if defined(PIOA_PUER)
  281. #define GPIO_PUE_REG PIOA_PUER
  282. #if defined(PIOA_PUDR)
  283. #define GPIO_PUD_REG PIOA_PUDR
  284. #define GPIO_PUS_REG PIOA_PUSR
  285. #endif /* PIOA_PUDR */
  286. #endif /* PIOA_PUER */
  287. #if defined(PIOA_MDER)
  288. #define GPIO_MDE_REG PIOA_MDER
  289. #if defined(PIOA_MDDR)
  290. #define GPIO_MDD_REG PIOA_MDDR
  291. #define GPIO_MDS_REG PIOA_MDSR
  292. #endif /* PIOA_MDDR */
  293. #endif /* PIOA_MDER */
  294. #if defined(PIOA_IFER)
  295. #define GPIO_IFE_REG PIOA_IFER
  296. #if defined(PIOA_IFDR)
  297. #define GPIO_IFD_REG PIOA_IFDR
  298. #define GPIO_IFS_REG PIOA_IFSR
  299. #endif /* PIOA_IFDR */
  300. #endif /* PIOA_IFER */
  301. #elif GPIO_ID == PIOB_ID
  302. #define GPIO_PE_REG PIOB_PER
  303. #define GPIO_PD_REG PIOB_PDR
  304. #define GPIO_PS_REG PIOB_PSR
  305. #define GPIO_OE_REG PIOB_OER
  306. #define GPIO_OD_REG PIOB_ODR
  307. #define GPIO_OS_REG PIOB_OSR
  308. #define GPIO_SOD_REG PIOB_SODR
  309. #define GPIO_COD_REG PIOB_CODR
  310. #define GPIO_ODS_REG PIOB_ODSR
  311. #define GPIO_PDS_REG PIOB_PDSR
  312. #if defined(PIOB_PUER)
  313. #define GPIO_PUE_REG PIOB_PUER
  314. #if defined(PIOB_PUDR)
  315. #define GPIO_PUD_REG PIOB_PUDR
  316. #define GPIO_PUS_REG PIOB_PUSR
  317. #endif /* PIOB_PUDR */
  318. #endif /* PIOB_PUER */
  319. #if defined(PIOB_MDER)
  320. #define GPIO_MDE_REG PIOB_MDER
  321. #if defined(PIOB_MDDR)
  322. #define GPIO_MDD_REG PIOB_MDDR
  323. #define GPIO_MDS_REG PIOB_MDSR
  324. #endif /* PIOB_MDDR */
  325. #endif /* PIOB_MDER */
  326. #if defined(PIOB_IFER)
  327. #define GPIO_IFE_REG PIOB_IFER
  328. #if defined(PIOB_IFDR)
  329. #define GPIO_IFD_REG PIOB_IFDR
  330. #define GPIO_IFS_REG PIOB_IFSR
  331. #endif /* PIOB_IFDR */
  332. #endif /* PIOB_IFER */
  333. #elif GPIO_ID == PIOC_ID
  334. #define GPIO_PE_REG PIOC_PER
  335. #define GPIO_PD_REG PIOC_PDR
  336. #define GPIO_PS_REG PIOC_PSR
  337. #define GPIO_OE_REG PIOC_OER
  338. #define GPIO_OD_REG PIOC_ODR
  339. #define GPIO_OS_REG PIOC_OSR
  340. #define GPIO_SOD_REG PIOC_SODR
  341. #define GPIO_COD_REG PIOC_CODR
  342. #define GPIO_ODS_REG PIOC_ODSR
  343. #define GPIO_PDS_REG PIOC_PDSR
  344. #if defined(PIOC_PUER)
  345. #define GPIO_PUE_REG PIOC_PUER
  346. #if defined(PIOC_PUDR)
  347. #define GPIO_PUD_REG PIOC_PUDR
  348. #define GPIO_PUS_REG PIOC_PUSR
  349. #endif /* PIOC_PUDR */
  350. #endif /* PIOC_PUER */
  351. #if defined(PIOC_MDER)
  352. #define GPIO_MDE_REG PIOC_MDER
  353. #if defined(PIOC_MDDR)
  354. #define GPIO_MDD_REG PIOC_MDDR
  355. #define GPIO_MDS_REG PIOC_MDSR
  356. #endif /* PIOC_MDDR */
  357. #endif /* PIOC_MDER */
  358. #if defined(PIOC_IFER)
  359. #define GPIO_IFE_REG PIOC_IFER
  360. #if defined(PIOC_IFDR)
  361. #define GPIO_IFD_REG PIOC_IFDR
  362. #define GPIO_IFS_REG PIOC_IFSR
  363. #endif /* PIOC_IFDR */
  364. #endif /* PIOC_IFER */
  365. #endif /* GPIO_ID */
  366. #elif defined(__AVR32__)
  367. #include <avr32/io.h>
  368. #define GPIO_PE_REG &AVR32_GPIO.port[GPIO_ID].gpers
  369. #define GPIO_PD_REG &AVR32_GPIO.port[GPIO_ID].pderc
  370. #define GPIO_PS_REG &AVR32_GPIO.port[GPIO_ID].pder
  371. #define GPIO_OE_REG &AVR32_GPIO.port[GPIO_ID].oders
  372. #define GPIO_OD_REG &AVR32_GPIO.port[GPIO_ID].oderc
  373. #define GPIO_OS_REG &AVR32_GPIO.port[GPIO_ID].oder
  374. #define GPIO_SOD_REG &AVR32_GPIO.port[GPIO_ID].ovrs
  375. #define GPIO_COD_REG &AVR32_GPIO.port[GPIO_ID].ovrc
  376. #define GPIO_ODS_REG &AVR32_GPIO.port[GPIO_ID].ovr
  377. #define GPIO_PDS_REG &AVR32_GPIO.port[GPIO_ID].pvr
  378. #define GPIO_PUE_REG &AVR32_GPIO.port[GPIO_ID].puers
  379. #define GPIO_PUD_REG &AVR32_GPIO.port[GPIO_ID].puerc
  380. #define GPIO_PUS_REG &AVR32_GPIO.port[GPIO_ID].puer
  381. #define GPIO_MDE_REG &AVR32_GPIO.port[GPIO_ID].odmerc
  382. #define GPIO_MDD_REG &AVR32_GPIO.port[GPIO_ID].odmers
  383. #define GPIO_MDS_REG &AVR32_GPIO.port[GPIO_ID].odmer
  384. #define GPIO_IFE_REG &AVR32_GPIO.port[GPIO_ID].gfers
  385. #define GPIO_IFD_REG &AVR32_GPIO.port[GPIO_ID].gferc
  386. #define GPIO_IFS_REG &AVR32_GPIO.port[GPIO_ID].gfer
  387. /* Additional targets can be added here. */
  388. #endif /* MCU */
  389. /*
  390. * Remove any previously defined port macros.
  391. */
  392. #undef GPIO_SET_LO
  393. #undef GPIO_SET_HI
  394. #undef GPIO_IS_HI
  395. #undef GPIO_GET
  396. #undef GPIO_ENABLE
  397. #undef GPIO_OUTPUT
  398. #undef GPIO_INPUT
  399. #undef GPIO_PULLUP_ON
  400. #undef GPIO_PULLUP_OFF
  401. #undef GPIO_OPENDRAIN
  402. #undef GPIO_PUSHPULL
  403. #if defined(GPIO_COD_REG)
  404. #define GPIO_SET_LO(b) outr(GPIO_COD_REG, _BV(b))
  405. #define GPIO_SET_HI(b) outr(GPIO_SOD_REG, _BV(b))
  406. #elif defined(GPIO_SOD_REG)
  407. #define GPIO_SET_LO(b) cbi(GPIO_SOD_REG, b)
  408. #define GPIO_SET_HI(b) sbi(GPIO_SOD_REG, b)
  409. #else
  410. #define GPIO_SET_LO(b)
  411. #define GPIO_SET_HI(b)
  412. #endif
  413. #if defined(GPIO_ODS_REG)
  414. #define GPIO_IS_HI(b) ((inr(GPIO_ODS_REG) & _BV(b)) == _BV(b))
  415. #elif defined(GPIO_SOD_REG)
  416. #define GPIO_IS_HI(b) ((inr(GPIO_SOD_REG) & _BV(b)) == _BV(b))
  417. #else
  418. #define GPIO_IS_HI(b)
  419. #endif
  420. #if defined(GPIO_PDS_REG)
  421. #define GPIO_GET(b) ((inr(GPIO_PDS_REG) & _BV(b)) == _BV(b))
  422. #else
  423. #define GPIO_GET(b)
  424. #endif
  425. /*
  426. ** PIO enable and disable macros.
  427. */
  428. #if defined(GPIO_PE_REG) && defined(GPIO_PD_REG)
  429. /* Direct write, if PIO enable and disable registers are available. */
  430. #define GPIO_ENABLE(b) outr(GPIO_PE_REG, _BV(b))
  431. #define GPIO_DISABLE(b) outr(GPIO_PD_REG, _BV(b))
  432. #elif defined(GPIO_PE_REG)
  433. /* Modify bit, if PIO enable register only. */
  434. #define GPIO_ENABLE(b) sbi(GPIO_PE_REG, _BV(b))
  435. #define GPIO_DISABLE(b) cbi(GPIO_PE_REG, _BV(b))
  436. #elif defined(GPIO_PD_REG)
  437. /* Modify bit, if PIO disable register only. */
  438. #define GPIO_ENABLE(b) cbi(GPIO_PD_REG, _BV(b))
  439. #define GPIO_DISABLE(b) sbi(GPIO_PD_REG, _BV(b))
  440. #else
  441. /* None, PIO may be always enabled or not available. */
  442. #define GPIO_ENABLE(b)
  443. #endif
  444. #if defined(GPIO_OD_REG)
  445. #define GPIO_OUTPUT(b) outr(GPIO_OE_REG, _BV(b))
  446. #elif defined(GPIO_OE_REG)
  447. #define GPIO_OUTPUT(b) sbi(GPIO_OE_REG, b)
  448. #else
  449. #define GPIO_OUTPUT(b)
  450. #endif
  451. #if defined(GPIO_OD_REG)
  452. #define GPIO_INPUT(b) outr(GPIO_OD_REG, _BV(b))
  453. #elif defined(GPIO_OE_REG)
  454. #define GPIO_INPUT(b) cbi(GPIO_OE_REG, b)
  455. #else
  456. #define GPIO_INPUT(b)
  457. #endif
  458. #if defined(GPIO_PUD_REG)
  459. #define GPIO_PULLUP_ON(b) outr(GPIO_PUE_REG, _BV(b))
  460. #elif defined(GPIO_PUE_REG)
  461. #define GPIO_PULLUP_ON(b) sbi(GPIO_PUE_REG, b)
  462. #else
  463. #define GPIO_PULLUP_ON(b)
  464. #endif
  465. #if defined(GPIO_PUD_REG)
  466. #define GPIO_PULLUP_OFF(b) outr(GPIO_PUD_REG, _BV(b))
  467. #elif defined(GPIO_PUE_REG)
  468. #define GPIO_PULLUP_OFF(b) cbi(GPIO_PUE_REG, b)
  469. #else
  470. #define GPIO_PULLUP_OFF(b)
  471. #endif
  472. #if defined(GPIO_IFD_REG)
  473. #define GPIO_FILTER_ON(b) outr(GPIO_IFE_REG, _BV(b))
  474. #elif defined(GPIO_IFE_REG)
  475. #define GPIO_FILTER_ON(b) sbi(GPIO_IFE_REG, b)
  476. #else
  477. #define GPIO_FILTER_ON(b)
  478. #endif
  479. #if defined(GPIO_IFD_REG)
  480. #define GPIO_FILTER_OFF(b) outr(GPIO_IFD_REG, _BV(b))
  481. #elif defined(GPIO_IFE_REG)
  482. #define GPIO_FILTER_OFF(b) cbi(GPIO_IFE_REG, b)
  483. #else
  484. #define GPIO_FILTER_OFF(b)
  485. #endif
  486. #if defined(GPIO_MDD_REG)
  487. #define GPIO_OPENDRAIN(b) outr(GPIO_MDE_REG, _BV(b))
  488. #elif defined(GPIO_MDE_REG)
  489. #define GPIO_OPENDRAIN(b) sbi(GPIO_MDE_REG, b)
  490. #else
  491. #define GPIO_OPENDRAIN(b)
  492. #endif
  493. #if defined(GPIO_MDD_REG)
  494. #define GPIO_PUSHPULL(b) outr(GPIO_MDD_REG, _BV(b))
  495. #elif defined(GPIO_MDE_REG)
  496. #define GPIO_PUSHPULL(b) cbi(GPIO_MDE_REG, b)
  497. #else
  498. #define GPIO_PUSHPULL(b)
  499. #endif
  500. #endif
  501. /*@}*/