Subversion Repositories HomeAutomation

Rev

Rev 1084 | Rev 1139 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /******************************************************************************
  2.   gpio.h
  3.  
  4.   CoreCard GPIO Hardware Abstraction Layer
  5.  
  6. ******************************************************************************/
  7.  
  8. #ifndef GPIO_H_
  9. #define GPIO_H_
  10.  
  11. #include <inttypes.h>
  12. #include <avr/io.h>
  13.  
  14. /******************************************************************************
  15. * Port output functions
  16. * void gpio_set_out() makes GPIOX pin as output
  17. * void gpio_set_pin() sets GPIOX pin to logical 1 level (when output)
  18. * void gpio_clr_pin() clears GPIOX pin to logical 0 level (when output)
  19. * void gpio_toggle_pin() toggles level of output (when output)
  20. *
  21. * Port input functions
  22. * void gpio_set_in() makes GPIOX pin as input
  23. * void gpio_set_pullup() makes GPIOX pulled high (when input)
  24. * void gpio_clr_pullup() removes pullup on GPIOX (when input)
  25. * uint8_t gpio_get_state() returns logical level GPIOX pin
  26. *******************************************************************************/
  27.   static inline __attribute__ ((always_inline)) void gpio_set_pin(volatile uint8_t* port, volatile uint8_t* pin, volatile uint8_t* ddr,uint8_t nr) {*port |= (1 << nr);}
  28.   static inline __attribute__ ((always_inline)) void gpio_clr_pin(volatile uint8_t* port, volatile uint8_t* pin, volatile uint8_t* ddr,uint8_t nr) {*port &= ~(1 << nr);}
  29.   static inline __attribute__ ((always_inline)) void gpio_set_out(volatile uint8_t* port, volatile uint8_t* pin, volatile uint8_t* ddr,uint8_t nr) {*ddr |= (1 << nr);}
  30.   static inline __attribute__ ((always_inline)) void gpio_set_in(volatile uint8_t* port, volatile uint8_t* pin, volatile uint8_t* ddr,uint8_t nr) {*ddr &= ~(1 << nr);}
  31.   static inline __attribute__ ((always_inline)) void gpio_set_pullup(volatile uint8_t* port, volatile uint8_t* pin, volatile uint8_t* ddr,uint8_t nr) {*port |= (1 << nr);}
  32.   static inline __attribute__ ((always_inline)) void gpio_clr_pullup(volatile uint8_t* port, volatile uint8_t* pin, volatile uint8_t* ddr,uint8_t nr) {*port &= ~(1 << nr);}
  33.   static inline __attribute__ ((always_inline)) void gpio_toggle_pin(volatile uint8_t* port, volatile uint8_t* pin, volatile uint8_t* ddr,uint8_t nr) {*port ^= (1 << nr);}
  34.   static inline __attribute__ ((always_inline)) uint8_t gpio_get_state(volatile uint8_t* port, volatile uint8_t* pin, volatile uint8_t* ddr,uint8_t nr) {return (*pin & (1 << nr)) != 0;}
  35.  
  36. // generic ports:
  37. #define GPIO_D0         &PORTD,&PIND,&DDRD,PD0
  38. #define PORT_GPIO_D0    PORTD
  39. #define PIN_GPIO_D0     PIND
  40. #define DDR_GPIO_D0     DDRD
  41. #define NR_GPIO_D0      PD0
  42.  
  43. #define GPIO_D1         &PORTD,&PIND,&DDRD,PD1
  44. #define PORT_GPIO_D1    PORTD
  45. #define PIN_GPIO_D1     PIND
  46. #define DDR_GPIO_D1     DDRD
  47. #define NR_GPIO_D1      PD1
  48.  
  49. #define GPIO_D2         &PORTD,&PIND,&DDRD,PD2
  50. #define PORT_GPIO_D2    PORTD
  51. #define PIN_GPIO_D2     PIND
  52. #define DDR_GPIO_D2     DDRD
  53. #define NR_GPIO_D2      PD2
  54.  
  55. #define GPIO_D4         &PORTD,&PIND,&DDRD,PD4
  56. #define PORT_GPIO_D4    PORTD
  57. #define PIN_GPIO_D4     PIND
  58. #define DDR_GPIO_D4     DDRD
  59. #define NR_GPIO_D4      PD4
  60.  
  61. #define GPIO_D5         &PORTD,&PIND,&DDRD,PD5
  62. #define PORT_GPIO_D5    PORTD
  63. #define PIN_GPIO_D5     PIND
  64. #define DDR_GPIO_D5     DDRD
  65. #define NR_GPIO_D5      PD5
  66.  
  67. #define GPIO_D6         &PORTD,&PIND,&DDRD,PD6
  68. #define PORT_GPIO_D6    PORTD
  69. #define PIN_GPIO_D6     PIND
  70. #define DDR_GPIO_D6     DDRD
  71. #define NR_GPIO_D6      PD6
  72.  
  73. #define GPIO_D7         &PORTD,&PIND,&DDRD,PD7
  74. #define PORT_GPIO_D7    PORTD
  75. #define PIN_GPIO_D7     PIND
  76. #define DDR_GPIO_D7     DDRD
  77. #define NR_GPIO_D7      PD7
  78.  
  79.  
  80. #define GPIO_B0         &PORTB,&PINB,&DDRB,PB0
  81. #define PORT_GPIO_B0    PORTB
  82. #define PIN_GPIO_B0     PINB
  83. #define DDR_GPIO_B0     DDRB
  84. #define NR_GPIO_B0      PB0
  85.  
  86. #define GPIO_B1         &PORTB,&PINB,&DDRB,PB1
  87. #define PORT_GPIO_B1    PORTB
  88. #define PIN_GPIO_B1     PINB
  89. #define DDR_GPIO_B1     DDRB
  90. #define NR_GPIO_B1      PB1
  91.  
  92. #define GPIO_B2         &PORTB,&PINB,&DDRB,PB2
  93. #define PORT_GPIO_B2    PORTB
  94. #define PIN_GPIO_B2     PINB
  95. #define DDR_GPIO_B2     DDRB
  96. #define NR_GPIO_B2      PB2
  97.  
  98. #define GPIO_B7         &PORTB,&PINB,&DDRB,PB7
  99. #define PORT_GPIO_B7    PORTB
  100. #define PIN_GPIO_B7     PINB
  101. #define DDR_GPIO_B7     DDRB
  102. #define NR_GPIO_B7      PB7
  103.  
  104.  
  105. #define GPIO_C0         &PORTC,&PINC,&DDRC,PC0
  106. #define PORT_GPIO_C0    PORTC
  107. #define PIN_GPIO_C0     PINC
  108. #define DDR_GPIO_C0     DDRC
  109. #define NR_GPIO_C0      PC0
  110.  
  111. #define GPIO_C1         &PORTC,&PINC,&DDRC,PC1
  112. #define PORT_GPIO_C1    PORTC
  113. #define PIN_GPIO_C1     PINC
  114. #define DDR_GPIO_C1     DDRC
  115. #define NR_GPIO_C1      PC1
  116.  
  117. #define GPIO_C2         &PORTC,&PINC,&DDRC,PC2
  118. #define PORT_GPIO_C2    PORTC
  119. #define PIN_GPIO_C2     PINC
  120. #define DDR_GPIO_C2     DDRC
  121. #define NR_GPIO_C2      PC2
  122.  
  123. #define GPIO_C3         &PORTC,&PINC,&DDRC,PC3
  124. #define PORT_GPIO_C3    PORTC
  125. #define PIN_GPIO_C3     PINC
  126. #define DDR_GPIO_C3     DDRC
  127. #define NR_GPIO_C3      PC3
  128.  
  129. #define GPIO_C4         &PORTC,&PINC,&DDRC,PC4
  130. #define PORT_GPIO_C4    PORTC
  131. #define PIN_GPIO_C4     PINC
  132. #define DDR_GPIO_C4     DDRC
  133. #define NR_GPIO_C4      PC4
  134.  
  135. #define GPIO_C5         &PORTC,&PINC,&DDRC,PC5
  136. #define PORT_GPIO_C5    PORTC
  137. #define PIN_GPIO_C5     PINC
  138. #define DDR_GPIO_C5     DDRC
  139. #define NR_GPIO_C5      PC5
  140.  
  141. // for corecard:
  142. #define EXP_A   &PORTB,&PINB,&DDRB,PB7
  143. #define PORT_EXP_A  PORTB
  144. #define PIN_EXP_A   PINB
  145. #define DDR_EXP_A   DDRB
  146. #define NR_EXP_A    PB7
  147.  
  148. #define EXP_B   &PORTB,&PINB,&DDRB,PB2
  149. #define PORT_EXP_B  PORTB
  150. #define PIN_EXP_B   PINB
  151. #define DDR_EXP_B   DDRB
  152. #define NR_EXP_B    PB2
  153.  
  154. #define EXP_C   &PORTB,&PINB,&DDRB,PB1
  155. #define PORT_EXP_C  PORTB
  156. #define PIN_EXP_C   PINB
  157. #define DDR_EXP_C   DDRB
  158. #define NR_EXP_C    PB1
  159.  
  160. #define EXP_D   &PORTB,&PINB,&DDRB,PB0
  161. #define PORT_EXP_D  PORTB
  162. #define PIN_EXP_D   PINB
  163. #define DDR_EXP_D   DDRB
  164. #define NR_EXP_D    PB0
  165.  
  166. #define EXP_E   &PORTD,&PIND,&DDRD,PD7
  167. #define PORT_EXP_E  PORTD
  168. #define PIN_EXP_E   PIND
  169. #define DDR_EXP_E   DDRD
  170. #define NR_EXP_E    PD7
  171.  
  172. #define EXP_F   &PORTD,&PIND,&DDRD,PD6
  173. #define PORT_EXP_F  PORTD
  174. #define PIN_EXP_F   PIND
  175. #define DDR_EXP_F   DDRD
  176. #define NR_EXP_F    PD6
  177.  
  178. #define EXP_G   &PORTD,&PIND,&DDRD,PD5
  179. #define PORT_EXP_G  PORTD
  180. #define PIN_EXP_G   PIND
  181. #define DDR_EXP_G   DDRD
  182. #define NR_EXP_G    PD5
  183.  
  184. #define EXP_H   &PORTD,&PIND,&DDRD,PD4
  185. #define PORT_EXP_H  PORTD
  186. #define PIN_EXP_H   PIND
  187. #define DDR_EXP_H   DDRD
  188. #define NR_EXP_H    PD4
  189.  
  190. #define EXP_I   &PORTD,&PIND,&DDRD,PD2
  191. #define PORT_EXP_I  PORTD
  192. #define PIN_EXP_I   PIND
  193. #define DDR_EXP_I   DDRD
  194. #define NR_EXP_I    PD2
  195.  
  196. #define EXP_J   &PORTD,&PIND,&DDRD,PD1
  197. #define PORT_EXP_J  PORTD
  198. #define PIN_EXP_J   PIND
  199. #define DDR_EXP_J   DDRD
  200. #define NR_EXP_J    PD1
  201.  
  202. #define EXP_K   &PORTD,&PIND,&DDRD,PD0
  203. #define PORT_EXP_K  PORTD
  204. #define PIN_EXP_K   PIND
  205. #define DDR_EXP_K   DDRD
  206. #define NR_EXP_K    PC0
  207.  
  208. #define EXP_L   &PORTC,&PINC,&DDRC,PC5
  209. #define PORT_EXP_L  PORTC
  210. #define PIN_EXP_L   PINC
  211. #define DDR_EXP_L   DDRC
  212. #define NR_EXP_L    PC5
  213.  
  214. #define EXP_M   &PORTC,&PINC,&DDRC,PC4
  215. #define PORT_EXP_M  PORTC
  216. #define PIN_EXP_M   PINC
  217. #define DDR_EXP_M   DDRC
  218. #define NR_EXP_M    PC4
  219.  
  220. #define EXP_N   &PORTC,&PINC,&DDRC,PC2
  221. #define PORT_EXP_N  PORTC
  222. #define PIN_EXP_N   PINC
  223. #define DDR_EXP_N   DDRC
  224. #define NR_EXP_N    PC2
  225.  
  226. #define EXP_O   &PORTC,&PINC,&DDRC,PC1
  227. #define PORT_EXP_O  PORTC
  228. #define PIN_EXP_O   PINC
  229. #define DDR_EXP_O   DDRC
  230. #define NR_EXP_O    PC1
  231.  
  232. #define EXP_P   &PORTC,&PINC,&DDRC,PC0
  233. #define PORT_EXP_P  PORTC
  234. #define PIN_EXP_P   PINC
  235. #define DDR_EXP_P   DDRC
  236. #define NR_EXP_P    PC0
  237.  
  238. #endif
  239. //eof gpio.h
  240.