Subversion Repositories HomeAutomation

Rev

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