You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.9 KiB

  1. /* Copyright 2021 QMK
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #pragma once
  17. #include <avr/io.h>
  18. #define PORT_SHIFTER 4 // this may be 4 for all AVR chips
  19. // If you want to add more to this list, reference the PINx definitions in these header
  20. // files: https://github.com/vancegroup-mirrors/avr-libc/tree/master/avr-libc/include/avr
  21. #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega16U4__)
  22. # define ADDRESS_BASE 0x00
  23. # define PINB_ADDRESS 0x3
  24. # define PINC_ADDRESS 0x6
  25. # define PIND_ADDRESS 0x9
  26. # define PINE_ADDRESS 0xC
  27. # define PINF_ADDRESS 0xF
  28. #elif defined(__AVR_AT90USB162__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
  29. # define ADDRESS_BASE 0x00
  30. # define PINB_ADDRESS 0x3
  31. # define PINC_ADDRESS 0x6
  32. # define PIND_ADDRESS 0x9
  33. #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
  34. # define ADDRESS_BASE 0x00
  35. # define PINA_ADDRESS 0x0
  36. # define PINB_ADDRESS 0x3
  37. # define PINC_ADDRESS 0x6
  38. # define PIND_ADDRESS 0x9
  39. # define PINE_ADDRESS 0xC
  40. # define PINF_ADDRESS 0xF
  41. #elif defined(__AVR_ATmega32A__)
  42. # define ADDRESS_BASE 0x10
  43. # define PIND_ADDRESS 0x0
  44. # define PINC_ADDRESS 0x3
  45. # define PINB_ADDRESS 0x6
  46. # define PINA_ADDRESS 0x9
  47. #elif defined(__AVR_ATtiny85__)
  48. # define ADDRESS_BASE 0x10
  49. # define PINB_ADDRESS 0x6
  50. #else
  51. # error "Pins are not defined"
  52. #endif
  53. #define PINDEF(port, pin) ((PIN##port##_ADDRESS << PORT_SHIFTER) | pin)
  54. #define _PIN_ADDRESS(p, offset) _SFR_IO8(ADDRESS_BASE + ((p) >> PORT_SHIFTER) + (offset))
  55. // Port X Input Pins Address
  56. #define PINx_ADDRESS(p) _PIN_ADDRESS(p, 0)
  57. // Port X Data Direction Register, 0:input 1:output
  58. #define DDRx_ADDRESS(p) _PIN_ADDRESS(p, 1)
  59. // Port X Data Register
  60. #define PORTx_ADDRESS(p) _PIN_ADDRESS(p, 2)
  61. /* I/O pins */
  62. #ifdef PORTA
  63. # define A0 PINDEF(A, 0)
  64. # define A1 PINDEF(A, 1)
  65. # define A2 PINDEF(A, 2)
  66. # define A3 PINDEF(A, 3)
  67. # define A4 PINDEF(A, 4)
  68. # define A5 PINDEF(A, 5)
  69. # define A6 PINDEF(A, 6)
  70. # define A7 PINDEF(A, 7)
  71. #endif
  72. #ifdef PORTB
  73. # define B0 PINDEF(B, 0)
  74. # define B1 PINDEF(B, 1)
  75. # define B2 PINDEF(B, 2)
  76. # define B3 PINDEF(B, 3)
  77. # define B4 PINDEF(B, 4)
  78. # define B5 PINDEF(B, 5)
  79. # define B6 PINDEF(B, 6)
  80. # define B7 PINDEF(B, 7)
  81. #endif
  82. #ifdef PORTC
  83. # define C0 PINDEF(C, 0)
  84. # define C1 PINDEF(C, 1)
  85. # define C2 PINDEF(C, 2)
  86. # define C3 PINDEF(C, 3)
  87. # define C4 PINDEF(C, 4)
  88. # define C5 PINDEF(C, 5)
  89. # define C6 PINDEF(C, 6)
  90. # define C7 PINDEF(C, 7)
  91. #endif
  92. #ifdef PORTD
  93. # define D0 PINDEF(D, 0)
  94. # define D1 PINDEF(D, 1)
  95. # define D2 PINDEF(D, 2)
  96. # define D3 PINDEF(D, 3)
  97. # define D4 PINDEF(D, 4)
  98. # define D5 PINDEF(D, 5)
  99. # define D6 PINDEF(D, 6)
  100. # define D7 PINDEF(D, 7)
  101. #endif
  102. #ifdef PORTE
  103. # define E0 PINDEF(E, 0)
  104. # define E1 PINDEF(E, 1)
  105. # define E2 PINDEF(E, 2)
  106. # define E3 PINDEF(E, 3)
  107. # define E4 PINDEF(E, 4)
  108. # define E5 PINDEF(E, 5)
  109. # define E6 PINDEF(E, 6)
  110. # define E7 PINDEF(E, 7)
  111. #endif
  112. #ifdef PORTF
  113. # define F0 PINDEF(F, 0)
  114. # define F1 PINDEF(F, 1)
  115. # define F2 PINDEF(F, 2)
  116. # define F3 PINDEF(F, 3)
  117. # define F4 PINDEF(F, 4)
  118. # define F5 PINDEF(F, 5)
  119. # define F6 PINDEF(F, 6)
  120. # define F7 PINDEF(F, 7)
  121. #endif