Subversion Repositories HomeAutomation

Rev

Rev 1070 | Rev 1082 | 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. * void GPIOX_set() sets GPIOX pin to logical 1 level.
  16. * void GPIOX_clr() clears GPIOX pin to logical 0 level.
  17. * void GPIOX_make_in makes GPIOX pin as input.
  18. * void GPIOX_make_out makes GPIOX pin as output.
  19. * uint8_t GPIOX_read() returns logical level GPIOX pin.
  20. * uint8_t GPIOX_state() returns configuration of GPIOX port.
  21. *******************************************************************************/
  22. #define INLINE static inline __attribute__ ((always_inline))
  23.  
  24. #define HAL_ASSIGN_PIN(name, port, bit) \
  25. INLINE void  GPIO_##name##_set(void)         {PORT##port |= (1 << bit);} \
  26. INLINE void  GPIO_##name##_clr(void)         {PORT##port &= ~(1 << bit);} \
  27. INLINE uint8_t  GPIO_##name##_read(void)     {return (PIN##port & (1 << bit)) != 0;} \
  28. INLINE uint8_t  GPIO_##name##_state(void)    {return (DDR##port & (1 << bit)) != 0;} \
  29. INLINE void  GPIO_##name##_make_out(void)    {DDR##port |= (1 << bit);} \
  30. INLINE void  GPIO_##name##_make_in(void)     {DDR##port &= ~(1 << bit); PORT##port &= ~(1 << bit);} \
  31. INLINE void  GPIO_##name##_make_pullup(void) {PORT##port |= (1 << bit);}\
  32. INLINE void  GPIO_##name##_toggle(void)      {PORT##port ^= (1 << bit);}
  33.  
  34. // the macros for the manipulation by EXP_A
  35. HAL_ASSIGN_PIN(EXP_A, B, 7);
  36. // the macros for the manipulation by EXP_B
  37. HAL_ASSIGN_PIN(EXP_B, B, 2);
  38. // the macros for the manipulation by EXP_C
  39. HAL_ASSIGN_PIN(EXP_C, B, 1);
  40. // the macros for the manipulation by EXP_D
  41. HAL_ASSIGN_PIN(EXP_D, B, 0);
  42. // the macros for the manipulation by EXP_E
  43. HAL_ASSIGN_PIN(EXP_E, D, 7);
  44. // the macros for the manipulation by EXP_F
  45. HAL_ASSIGN_PIN(EXP_F, D, 6);
  46. // the macros for the manipulation by EXP_G
  47. HAL_ASSIGN_PIN(EXP_G, D, 5);
  48. // the macros for the manipulation by EXP_H
  49. HAL_ASSIGN_PIN(EXP_H, D, 4);
  50. // the macros for the manipulation by EXP_I
  51. HAL_ASSIGN_PIN(EXP_I, D, 2);
  52. // the macros for the manipulation by EXP_J
  53. HAL_ASSIGN_PIN(EXP_J,  D, 1);
  54. // the macros for the manipulation by EXP_K
  55. HAL_ASSIGN_PIN(EXP_K, D, 0);
  56. // the macros for the manipulation by EXP_L
  57. HAL_ASSIGN_PIN(EXP_L, C, 5);
  58. // the macros for the manipulation by EXP_M
  59. HAL_ASSIGN_PIN(EXP_M, C, 4);
  60. // the macros for the manipulation by EXP_N
  61. HAL_ASSIGN_PIN(EXP_N, C, 2);
  62. // the macros for the manipulation by EXP_O
  63. HAL_ASSIGN_PIN(EXP_O, C, 5);
  64. // the macros for the manipulation by EXP_P
  65. HAL_ASSIGN_PIN(EXP_P, C, 1);
  66. // the macros for the manipulation by EXP_Q
  67. HAL_ASSIGN_PIN(EXP_Q, C, 7);
  68. // the macros for the manipulation by EXP_R
  69. HAL_ASSIGN_PIN(EXP_R, C, 7);
  70.  
  71. // the macros for the manipulation by PORTB BIT0
  72. HAL_ASSIGN_PIN(GPIO_B0, B, 0);
  73. // the macros for the manipulation by PORTB BIT1
  74. HAL_ASSIGN_PIN(GPIO_B1, B, 1);
  75. // the macros for the manipulation by PORTB BIT2
  76. HAL_ASSIGN_PIN(GPIO_B2, B, 2);
  77. // the macros for the manipulation by PORTB BIT3    bit 3-5 are spi communication with mcp2515
  78. //HAL_ASSIGN_PIN(GPIO_B3, B, 3);
  79. // the macros for the manipulation by PORTB BIT4
  80. //HAL_ASSIGN_PIN(GPIO_B4, B, 4);
  81. // the macros for the manipulation by PORTB BIT5
  82. //HAL_ASSIGN_PIN(GPIO_B5, B, 5);
  83. // the macros for the manipulation by PORTB BIT6    bit 6 is external clock from mcp2515
  84. //HAL_ASSIGN_PIN(GPIO_B6, B, 6);
  85. // the macros for the manipulation by PORTB BIT7
  86. HAL_ASSIGN_PIN(GPIO_B7, B, 7);
  87.  
  88. // the macros for the manipulation by PORTD BIT0
  89. HAL_ASSIGN_PIN(GPIO_D0, D, 0);
  90. // the macros for the manipulation by PORTD BIT1
  91. HAL_ASSIGN_PIN(GPIO_D1, D, 1);
  92. // the macros for the manipulation by PORTD BIT2
  93. HAL_ASSIGN_PIN(GPIO_D2, D, 2);
  94. // the macros for the manipulation by PORTD BIT3    bit 3 is interrup from mcp2515
  95. //HAL_ASSIGN_PIN(GPIO_D3, D, 3);
  96. // the macros for the manipulation by PORTD BIT4
  97. HAL_ASSIGN_PIN(GPIO_D4, D, 4);
  98. // the macros for the manipulation by PORTD BIT5
  99. HAL_ASSIGN_PIN(GPIO_D5, D, 5);
  100. // the macros for the manipulation by PORTD BIT6
  101. HAL_ASSIGN_PIN(GPIO_D6, D, 6);
  102. // the macros for the manipulation by PORTD BIT7
  103. HAL_ASSIGN_PIN(GPIO_D7, D, 7);
  104.  
  105. // the macros for the manipulation by PORTC BIT0
  106. HAL_ASSIGN_PIN(GPIO_C0, C, 0);
  107. // the macros for the manipulation by PORTC BIT1
  108. HAL_ASSIGN_PIN(GPIO_C1, C, 1);
  109. // the macros for the manipulation by PORTC BIT2
  110. HAL_ASSIGN_PIN(GPIO_C2, C, 2);
  111. // the macros for the manipulation by PORTC BIT3    bit 3 is cs on corecard but could be used on nodes
  112. HAL_ASSIGN_PIN(GPIO_C3, C, 3);
  113. // the macros for the manipulation by PORTC BIT4
  114. HAL_ASSIGN_PIN(GPIO_C4, C, 4);
  115. // the macros for the manipulation by PORTC BIT5
  116. HAL_ASSIGN_PIN(GPIO_C5, C, 5);
  117. // the macros for the manipulation by PORTC BIT6    bit 6 is reset
  118. //HAL_ASSIGN_PIN(GPIO_C6, C, 6);
  119.  
  120.  
  121.  
  122. #endif
  123. //eof gpio.h
  124.