Subversion Repositories HomeAutomation

Rev

Rev 1330 | Rev 1332 | 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_pin() sets GPIOX pin to logical 1 level (when output)
  17. * void gpio_clr_pin() clears GPIOX pin to logical 0 level (when output)
  18. * void gpio_toggle_pin() toggles level of output (when output)
  19. *
  20. * Port input functions
  21. * void gpio_set_pullup() makes GPIOX pulled high (when input)
  22. * void gpio_clr_pullup() removes pullup on GPIOX (when input)
  23. * uint8_t gpio_get_state() returns logical level GPIOX pin
  24. *
  25. * Direction functions
  26. * void gpio_set_in() makes GPIOX pin as input
  27. * void gpio_set_out() makes GPIOX pin as output
  28. * uint8_t gpio_get_direction() returns the choosen direction
  29. *
  30. *******************************************************************************/
  31.   static inline __attribute__ ((always_inline)) void gpio_set_pin(volatile uint8_t* port, volatile uint8_t* pin, volatile uint8_t* ddr,uint8_t nr, uint8_t pcint) {*port |= (1 << nr);}
  32.   static inline __attribute__ ((always_inline)) void gpio_clr_pin(volatile uint8_t* port, volatile uint8_t* pin, volatile uint8_t* ddr,uint8_t nr, uint8_t pcint) {*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, uint8_t pcint) {*port ^= (1 << nr);}
  34.  
  35.   static inline __attribute__ ((always_inline)) void gpio_set_pullup(volatile uint8_t* port, volatile uint8_t* pin, volatile uint8_t* ddr,uint8_t nr, uint8_t pcint) {*port |= (1 << nr);}
  36.   static inline __attribute__ ((always_inline)) void gpio_clr_pullup(volatile uint8_t* port, volatile uint8_t* pin, volatile uint8_t* ddr,uint8_t nr, uint8_t pcint) {*port &= ~(1 << nr);}
  37.   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, uint8_t pcint) {return (*pin & (1 << nr)) != 0;}
  38.  
  39.   static inline __attribute__ ((always_inline)) void gpio_set_out(volatile uint8_t* port, volatile uint8_t* pin, volatile uint8_t* ddr,uint8_t nr, uint8_t pcint) {*ddr |= (1 << nr);}
  40.   static inline __attribute__ ((always_inline)) void gpio_set_in(volatile uint8_t* port, volatile uint8_t* pin, volatile uint8_t* ddr,uint8_t nr, uint8_t pcint) {*ddr &= ~(1 << nr);}
  41.   static inline __attribute__ ((always_inline)) uint8_t gpio_get_direction(volatile uint8_t* port, volatile uint8_t* pin, volatile uint8_t* ddr,uint8_t nr, uint8_t pcint) {return (*port & (1 << nr)) != 0;}
  42.  
  43. #define GPIO_PIN_HIGH       1
  44. #define GPIO_PIN_LOW        0
  45. #define GPIO_PORT_INPUT     0
  46. #define GPIO_PORT_OUTPUT    1
  47.  
  48. // generic ports:
  49. #define GPIO_D0         &PORTD,&PIND,&DDRD,PD0,16
  50. #define GPIO_D0_PCINT_vect  PCINT2_vect
  51. #define PORT_GPIO_D0    PORTD
  52. #define PIN_GPIO_D0     PIND
  53. #define DDR_GPIO_D0     DDRD
  54. #define NR_GPIO_D0      PD0
  55.  
  56. #define GPIO_D1         &PORTD,&PIND,&DDRD,PD1,17
  57. #define GPIO_D1_PCINT_vect  PCINT2_vect
  58. #define PORT_GPIO_D1    PORTD
  59. #define PIN_GPIO_D1     PIND
  60. #define DDR_GPIO_D1     DDRD
  61. #define NR_GPIO_D1      PD1
  62.  
  63. #define GPIO_D2         &PORTD,&PIND,&DDRD,PD2,18
  64. #define GPIO_D2_PCINT_vect  PCINT2_vect
  65. #define PORT_GPIO_D2    PORTD
  66. #define PIN_GPIO_D2     PIND
  67. #define DDR_GPIO_D2     DDRD
  68. #define NR_GPIO_D2      PD2
  69.  
  70. #define GPIO_D4         &PORTD,&PIND,&DDRD,PD4,20
  71. #define GPIO_D4_PCINT_vect  PCINT2_vect
  72. #define PORT_GPIO_D4    PORTD
  73. #define PIN_GPIO_D4     PIND
  74. #define DDR_GPIO_D4     DDRD
  75. #define NR_GPIO_D4      PD4
  76.  
  77. #define GPIO_D5         &PORTD,&PIND,&DDRD,PD5,21
  78. #define GPIO_D5_PCINT_vect  PCINT2_vect
  79. #define PORT_GPIO_D5    PORTD
  80. #define PIN_GPIO_D5     PIND
  81. #define DDR_GPIO_D5     DDRD
  82. #define NR_GPIO_D5      PD5
  83.  
  84. #define GPIO_D6         &PORTD,&PIND,&DDRD,PD6,22
  85. #define GPIO_D6_PCINT_vect  PCINT2_vect
  86. #define PORT_GPIO_D6    PORTD
  87. #define PIN_GPIO_D6     PIND
  88. #define DDR_GPIO_D6     DDRD
  89. #define NR_GPIO_D6      PD6
  90.  
  91. #define GPIO_D7         &PORTD,&PIND,&DDRD,PD7,23
  92. #define GPIO_D7_PCINT_vect  PCINT2_vect
  93. #define PORT_GPIO_D7    PORTD
  94. #define PIN_GPIO_D7     PIND
  95. #define DDR_GPIO_D7     DDRD
  96. #define NR_GPIO_D7      PD7
  97.  
  98.  
  99. #define GPIO_B0         &PORTB,&PINB,&DDRB,PB0,0
  100. #define GPIO_B0_PCINT_vect  PCINT0_vect
  101. #define PORT_GPIO_B0    PORTB
  102. #define PIN_GPIO_B0     PINB
  103. #define DDR_GPIO_B0     DDRB
  104. #define NR_GPIO_B0      PB0
  105.  
  106. #define GPIO_B1         &PORTB,&PINB,&DDRB,PB1,1
  107. #define GPIO_B1_PCINT_vect  PCINT0_vect
  108. #define PORT_GPIO_B1    PORTB
  109. #define PIN_GPIO_B1     PINB
  110. #define DDR_GPIO_B1     DDRB
  111. #define NR_GPIO_B1      PB1
  112.  
  113. #define GPIO_B2         &PORTB,&PINB,&DDRB,PB2,2
  114. #define GPIO_B2_PCINT_vect  PCINT0_vect
  115. #define PORT_GPIO_B2    PORTB
  116. #define PIN_GPIO_B2     PINB
  117. #define DDR_GPIO_B2     DDRB
  118. #define NR_GPIO_B2      PB2
  119.  
  120. #define GPIO_B7         &PORTB,&PINB,&DDRB,PB7,7
  121. #define GPIO_B7_PCINT_vect  PCINT0_vect
  122. #define PORT_GPIO_B7    PORTB
  123. #define PIN_GPIO_B7     PINB
  124. #define DDR_GPIO_B7     DDRB
  125. #define NR_GPIO_B7      PB7
  126.  
  127.  
  128. #define GPIO_C0         &PORTC,&PINC,&DDRC,PC0,8
  129. #define GPIO_C0_PCINT_vect  PCINT1_vect
  130. #define PORT_GPIO_C0    PORTC
  131. #define PIN_GPIO_C0     PINC
  132. #define DDR_GPIO_C0     DDRC
  133. #define NR_GPIO_C0      PC0
  134.  
  135. #define GPIO_C1         &PORTC,&PINC,&DDRC,PC1,9
  136. #define GPIO_C1_PCINT_vect  PCINT1_vect
  137. #define PORT_GPIO_C1    PORTC
  138. #define PIN_GPIO_C1     PINC
  139. #define DDR_GPIO_C1     DDRC
  140. #define NR_GPIO_C1      PC1
  141.  
  142. #define GPIO_C2         &PORTC,&PINC,&DDRC,PC2,10
  143. #define GPIO_C2_PCINT_vect  PCINT1_vect
  144. #define PORT_GPIO_C2    PORTC
  145. #define PIN_GPIO_C2     PINC
  146. #define DDR_GPIO_C2     DDRC
  147. #define NR_GPIO_C2      PC2
  148.  
  149. #define GPIO_C3         &PORTC,&PINC,&DDRC,PC3,11
  150. #define GPIO_C3_PCINT_vect  PCINT1_vect
  151. #define PORT_GPIO_C3    PORTC
  152. #define PIN_GPIO_C3     PINC
  153. #define DDR_GPIO_C3     DDRC
  154. #define NR_GPIO_C3      PC3
  155.  
  156. #define GPIO_C4         &PORTC,&PINC,&DDRC,PC4,12
  157. #define GPIO_C4_PCINT_vect  PCINT1_vect
  158. #define PORT_GPIO_C4    PORTC
  159. #define PIN_GPIO_C4     PINC
  160. #define DDR_GPIO_C4     DDRC
  161. #define NR_GPIO_C4      PC4
  162.  
  163. #define GPIO_C5         &PORTC,&PINC,&DDRC,PC5,13
  164. #define GPIO_C5_PCINT_vect  PCINT1_vect
  165. #define PORT_GPIO_C5    PORTC
  166. #define PIN_GPIO_C5     PINC
  167. #define DDR_GPIO_C5     DDRC
  168. #define NR_GPIO_C5      PC5
  169.  
  170. // for corecard:
  171. #define EXP_A   &PORTB,&PINB,&DDRB,PB7,7
  172. #define EXP_D_PCINT_vect    PCINT0_vect
  173. #define PORT_EXP_A  PORTB
  174. #define PIN_EXP_A   PINB
  175. #define DDR_EXP_A   DDRB
  176. #define NR_EXP_A    PB7
  177.  
  178. #define EXP_B   &PORTB,&PINB,&DDRB,PB2,2
  179. #define EXP_D_PCINT_vect    PCINT0_vect
  180. #define PORT_EXP_B  PORTB
  181. #define PIN_EXP_B   PINB
  182. #define DDR_EXP_B   DDRB
  183. #define NR_EXP_B    PB2
  184.  
  185. #define EXP_C   &PORTB,&PINB,&DDRB,PB1,1
  186. #define EXP_D_PCINT_vect    PCINT0_vect
  187. #define PORT_EXP_C  PORTB
  188. #define PIN_EXP_C   PINB
  189. #define DDR_EXP_C   DDRB
  190. #define NR_EXP_C    PB1
  191.  
  192. #define EXP_D   &PORTB,&PINB,&DDRB,PB0,0
  193. #define EXP_D_PCINT_vect    PCINT0_vect
  194. #define PORT_EXP_D  PORTB
  195. #define PIN_EXP_D   PINB
  196. #define DDR_EXP_D   DDRB
  197. #define NR_EXP_D    PB0
  198.  
  199. #define EXP_E   &PORTD,&PIND,&DDRD,PD7,23
  200. #define EXP_E_PCINT_vect    PCINT2_vect
  201. #define PORT_EXP_E  PORTD
  202. #define PIN_EXP_E   PIND
  203. #define DDR_EXP_E   DDRD
  204. #define NR_EXP_E    PD7
  205.  
  206. #define EXP_F   &PORTD,&PIND,&DDRD,PD6,22
  207. #define EXP_F_PCINT_vect    PCINT2_vect
  208. #define PORT_EXP_F  PORTD
  209. #define PIN_EXP_F   PIND
  210. #define DDR_EXP_F   DDRD
  211. #define NR_EXP_F    PD6
  212.  
  213. #define EXP_G   &PORTD,&PIND,&DDRD,PD5,21
  214. #define EXP_G_PCINT_vect    PCINT2_vect
  215. #define PORT_EXP_G  PORTD
  216. #define PIN_EXP_G   PIND
  217. #define DDR_EXP_G   DDRD
  218. #define NR_EXP_G    PD5
  219.  
  220. #define EXP_H   &PORTD,&PIND,&DDRD,PD4,20
  221. #define EXP_H_PCINT_vect    PCINT2_vect
  222. #define PORT_EXP_H  PORTD
  223. #define PIN_EXP_H   PIND
  224. #define DDR_EXP_H   DDRD
  225. #define NR_EXP_H    PD4
  226.  
  227. #define EXP_I   &PORTD,&PIND,&DDRD,PD2,18
  228. #define EXP_I_PCINT_vect    PCINT2_vect
  229. #define PORT_EXP_I  PORTD
  230. #define PIN_EXP_I   PIND
  231. #define DDR_EXP_I   DDRD
  232. #define NR_EXP_I    PD2
  233.  
  234. #define EXP_J   &PORTD,&PIND,&DDRD,PD1,17
  235. #define EXP_J_PCINT_vect    PCINT2_vect
  236. #define PORT_EXP_J  PORTD
  237. #define PIN_EXP_J   PIND
  238. #define DDR_EXP_J   DDRD
  239. #define NR_EXP_J    PD1
  240.  
  241. #define EXP_K   &PORTD,&PIND,&DDRD,PD0,16
  242. #define EXP_K_PCINT_vect    PCINT2_vect
  243. #define PORT_EXP_K  PORTD
  244. #define PIN_EXP_K   PIND
  245. #define DDR_EXP_K   DDRD
  246. #define NR_EXP_K    PC0
  247.  
  248. #define EXP_L   &PORTC,&PINC,&DDRC,PC5,13
  249. #define EXP_L_PCINT_vect    PCINT1_vect
  250. #define PORT_EXP_L  PORTC
  251. #define PIN_EXP_L   PINC
  252. #define DDR_EXP_L   DDRC
  253. #define NR_EXP_L    PC5
  254.  
  255. #define EXP_M   &PORTC,&PINC,&DDRC,PC4,12
  256. #define EXP_M_PCINT_vect    PCINT1_vect
  257. #define PORT_EXP_M  PORTC
  258. #define PIN_EXP_M   PINC
  259. #define DDR_EXP_M   DDRC
  260. #define NR_EXP_M    PC4
  261.  
  262. #define EXP_N   &PORTC,&PINC,&DDRC,PC2,10
  263. #define EXP_N_PCINT_vect    PCINT1_vect
  264. #define PORT_EXP_N  PORTC
  265. #define PIN_EXP_N   PINC
  266. #define DDR_EXP_N   DDRC
  267. #define NR_EXP_N    PC2
  268.  
  269. #define EXP_O   &PORTC,&PINC,&DDRC,PC1,9
  270. #define EXP_O_PCINT_vect    PCINT1_vect
  271. #define PORT_EXP_O  PORTC
  272. #define PIN_EXP_O   PINC
  273. #define DDR_EXP_O   DDRC
  274. #define NR_EXP_O    PC1
  275.  
  276. #define EXP_P   &PORTC,&PINC,&DDRC,PC0,8
  277. #define EXP_P_PCINT_vect    PCINT1_vect
  278. #define PORT_EXP_P      PORTC
  279. #define PIN_EXP_P       PINC
  280. #define DDR_EXP_P       DDRC
  281. #define NR_EXP_P        PC0
  282.  
  283. // for NodeEssential:
  284. #define Essential_0     &PORTD,&PIND,&DDRD,PD2,18
  285. #define Essential_0_PCINT_vect  PCINT2_vect
  286. #define PORT_Essential_0    PORTD
  287. #define PIN_Essential_0     PIND
  288. #define DDR_Essential_0     DDRD
  289. #define NR_Essential_0      PD2
  290.  
  291. #define Essential_1     &PORTD,&PIND,&DDRD,PD1,17
  292. #define Essential_1_PCINT_vect  PCINT2_vect
  293. #define PORT_Essential_1    PORTD
  294. #define PIN_Essential_1     PIND
  295. #define DDR_Essential_1     DDRD
  296. #define NR_Essential_1      PD1
  297.  
  298. #define Essential_2     &PORTD,&PIND,&DDRD,PD0,16
  299. #define Essential_2_PCINT_vect  PCINT2_vect
  300. #define PORT_Essential_2    PORTD
  301. #define PIN_Essential_2     PIND
  302. #define DDR_Essential_2     DDRD
  303. #define NR_Essential_2      PD0
  304.  
  305. #define Essential_3     &PORTD,&PIND,&DDRD,PD4,20
  306. #define Essential_3_PCINT_vect  PCINT2_vect
  307. #define PORT_Essential_3    PORTD
  308. #define PIN_Essential_3     PIND
  309. #define DDR_Essential_3     DDRD
  310. #define NR_Essential_3      PD4
  311.  
  312. #define Essential_4     &PORTD,&PIND,&DDRD,PD5,21
  313. #define Essential_4_PCINT_vect  PCINT2_vect
  314. #define PORT_Essential_4    PORTD
  315. #define PIN_Essential_4     PIND
  316. #define DDR_Essential_4     DDRD
  317. #define NR_Essential_4      PD5
  318.  
  319. #define Essential_5     &PORTD,&PIND,&DDRD,PD6,22
  320. #define Essential_5_PCINT_vect  PCINT2_vect
  321. #define PORT_Essential_5    PORTD
  322. #define PIN_Essential_5     PIND
  323. #define DDR_Essential_5     DDRD
  324. #define NR_Essential_5      PD6
  325.  
  326. #define Essential_6     &PORTB,&PINB,&DDRB,PB0,0
  327. #define Essential_6_PCINT_vect  PCINT0_vect
  328. #define PORT_Essential_6    PORTB
  329. #define PIN_Essential_6     PINB
  330. #define DDR_Essential_6     DDRB
  331. #define NR_Essential_6      PB0
  332.  
  333. #define Essential_7     &PORTB,&PINB,&DDRB,PB1,1
  334. #define Essential_7_PCINT_vect  PCINT0_vect
  335. #define PORT_Essential_7    PORTB
  336. #define PIN_Essential_7     PINB
  337. #define DDR_Essential_7     DDRB
  338. #define NR_Essential_7      PB1
  339.  
  340. #define Essential_8     &PORTC,&PINC,&DDRC,PC4,12
  341. #define Essential_8_PCINT_vect  PCINT1_vect
  342. #define PORT_Essential_8    PORTC
  343. #define PIN_Essential_8     PINC
  344. #define DDR_Essential_8     DDRC
  345. #define NR_Essential_8      PC4
  346.  
  347. #define Essential_9     &PORTC,&PINC,&DDRC,PC5,13
  348. #define Essential_9_PCINT_vect  PCINT1_vect
  349. #define PORT_Essential_9    PORTC
  350. #define PIN_Essential_9     PINC
  351. #define DDR_Essential_9     DDRC
  352. #define NR_Essential_9      PC5
  353. #endif
  354. //eof gpio.h
  355.