Subversion Repositories HomeAutomation

Rev

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