Advertisement
erazor

ATmega ATXmega PORT helpers

Feb 18th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.23 KB | None | 0 0
  1. /**
  2.  * @file                lib/utils.h
  3.  * @author          Alexander Krause <alexander.krause@ed-solutions.de>
  4.  * @date                05.03.2012
  5.  * @version         0.1.0
  6.  *
  7.  *
  8.  */
  9.  
  10.  
  11. #ifndef LIB__UTILS_H
  12. #define LIB__UTILS_H
  13.  
  14. uint8_t mirror_uint8(uint8_t);
  15.  
  16. #if defined (__AVR_ATxmega16A4__)
  17. #define IS_XMEGA
  18. #elif defined (__AVR_ATxmega16A4U__)
  19. #define IS_XMEGA
  20. #elif defined (__AVR_ATxmega16D4__)
  21. #define IS_XMEGA
  22. #elif defined (__AVR_ATxmega32A4__)
  23. #define IS_XMEGA
  24. #elif defined (__AVR_ATxmega32A4U__)
  25. #define IS_XMEGA
  26. #elif defined (__AVR_ATxmega32D4__)
  27. #define IS_XMEGA
  28. #elif defined (__AVR_ATxmega64A1__)
  29. #define IS_XMEGA
  30. #elif defined (__AVR_ATxmega64A1U__)
  31. #define IS_XMEGA
  32. #elif defined (__AVR_ATxmega64A3__)
  33. #define IS_XMEGA
  34. #elif defined (__AVR_ATxmega64D3__)
  35. #define IS_XMEGA
  36. #elif defined (__AVR_ATxmega128A1__)
  37. #define IS_XMEGA
  38. #elif defined (__AVR_ATxmega128A1U__)
  39. #define IS_XMEGA
  40. #elif defined (__AVR_ATxmega128A3__)
  41. #define IS_XMEGA
  42. #elif defined (__AVR_ATxmega128D3__)
  43. #define IS_XMEGA
  44. #elif defined (__AVR_ATxmega192A3__)
  45. #define IS_XMEGA
  46. #elif defined (__AVR_ATxmega192D3__)
  47. #define IS_XMEGA
  48. #elif defined (__AVR_ATxmega256A3__)
  49. #define IS_XMEGA
  50. #elif defined (__AVR_ATxmega256A3B__)
  51. #define IS_XMEGA
  52. #elif defined (__AVR_ATxmega256D3__)
  53. #define IS_XMEGA
  54. #endif
  55.  
  56. #ifdef IS_XMEGA
  57. #define PORT_DIRSET(x)              _port_dirset(x)
  58. #define PORT_DIRCLR(x)              _port_dirclr(x)
  59. #define PORT_OUTSET(x)              _port_outset(x)
  60. #define PORT_OUTCLR(x)              _port_outclr(x)
  61. #define PORT_OUTTGL(x)              _port_outtgl(x)
  62. #else
  63. #define PORT(x)             _port2(x)
  64. #define DDR(x)              _ddr2(x)
  65. #define PIN(x)              _pin2(x)
  66. #define REG(x)              _reg(x)
  67. #define PIN_NUM(x)      _pin_num(x)
  68. #endif
  69.  
  70.  
  71. #define PIN_LOW(x)              PIN_LOW2(x)
  72. #define PIN_HIGH(x)             PIN_HIGH2(x)
  73. #define PIN_TOGGLE(x)           PIN_TOGGLE2(x)
  74. #define PIN_SET_OUTPUT(x)   PIN_SET_OUTPUT2(x)
  75. #define PIN_SET_INPUT(x)    PIN_SET_INPUT2(x)
  76. #define PIN_SET_PULLUP(x)   PIN_SET2(x)
  77. #define PIN_IS_SET(x)           PIN_IS_SET2(x)
  78.  
  79. #define SET_INPUT_WITH_PULLUP(x)    SET_INPUT_WITH_PULLUP2(x)
  80.  
  81. #ifdef IS_XMEGA
  82. #define _DIRSET     ".DIRSET"
  83. #define _DIRCLR     ".DIRCLR"
  84. #define _OUTSET     ".OUTSET"
  85. #define _OUTCLR     ".OUTCLR"
  86.  
  87. #define _port_dirset(x) PORT ## x ## _DIRSET
  88. #define _port_dirclr(x) PORT ## x ## _DIRCLR
  89. #define _port_outset(x) PORT ## x ## _OUTSET
  90. #define _port_outclr(x) PORT ## x ## _OUTCLR
  91.  
  92. #else
  93. #define _port2(x)   PORT ## x
  94. #define _ddr2(x)    DDR ## x
  95. #define _pin2(x)    PIN ## x
  96.  
  97. #define _reg(x,y)       x
  98. #define _pin_num(x,y)   y
  99.  
  100. #endif
  101.  
  102. #ifdef IS_XMEGA
  103. #define PIN_LOW2(x,y)           PORT_OUTCLR(x) = (1<<y)
  104. #define PIN_HIGH2(x,y)      PORT_OUTSET(x) = (1<<y)
  105. #define PIN_TOGGLE2(x,y)    PORT_OUTTGL(x) = (1<<y)
  106.  
  107. #define PIN_SET_OUTPUT2(x,y)    PORT_DIRSET(x) = (1<<y)
  108. #define PIN_SET_INPUT2(x,y)     PORT_DIRCLR(x) = (1<<y)
  109. //#define   PIN_SET_INPUT_WITH_PULLUP2(x,y) PIN_SET_INPUT2(x,y);PIN_SET2(x,y)
  110.  
  111. //#define   PIN_IS_SET2(x,y)    ((PIN(x) & (1<<y)) != 0)
  112.  
  113. #else
  114. #define PIN_LOW2(x,y)           PORT(x) &= ~(1<<y)
  115. #define PIN_HIGH2(x,y)      PORT(x) |=  (1<<y)
  116. #define PIN_TOGGLE2(x,y)    PORT(x) ^=  (1<<y)
  117.  
  118. #define PIN_SET_OUTPUT2(x,y)    DDR(x) |= (1<<y)
  119. #define PIN_SET_INPUT2(x,y)     DDR(x) &= ~(1<<y)
  120. #define PIN_SET_INPUT_WITH_PULLUP2(x,y) PIN_SET_INPUT2(x,y);PIN_SET2(x,y)
  121.  
  122. #define PIN_IS_SET2(x,y)    ((PIN(x) & (1<<y)) != 0)
  123. #endif
  124.  
  125. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement