Subversion Repositories HomeAutomation

Rev

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