avrcompat.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /* sd2snes - SD card based universal cartridge for the SNES
  2. Copyright (C) 2009-2010 Maximilian Rehkopf <otakon@gmx.net>
  3. This file was adapted from sd2iec, written by Ingo Korb, original
  4. disclaimer follows:
  5. */
  6. /* sd2iec - SD/MMC to Commodore serial bus interface/controller
  7. Copyright (C) 2007-2009 Ingo Korb <ingo@akana.de>
  8. Inspiration and low-level SD/MMC access based on code from MMC2IEC
  9. by Lars Pontoppidan et al., see sdcard.c|h and config.h.
  10. FAT filesystem access based on code from ChaN and Jim Brain, see ff.c|h.
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; version 2 of the License only.
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with this program; if not, write to the Free Software
  20. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. avrcompat.h: Compatibility defines for multiple target chips
  22. */
  23. #ifndef AVRCOMPAT_H
  24. #define AVRCOMPAT_H
  25. /* USART */
  26. #if defined __AVR_ATmega644__ || defined __AVR_ATmega644P__ || defined __AVR_ATmega1281__ || defined __AVR_ATmega2561__
  27. # ifdef USE_UART1
  28. # define RXC RXC1
  29. # define RXEN RXEN1
  30. # define TXC TXC1
  31. # define TXEN TXEN1
  32. # define UBRRH UBRR1H
  33. # define UBRRL UBRR1L
  34. # define UCSRA UCSR1A
  35. # define UCSRB UCSR1B
  36. # define UCSRC UCSR1C
  37. # define UCSZ0 UCSZ10
  38. # define UCSZ1 UCSZ11
  39. # define UDR UDR1
  40. # define UDRIE UDRIE1
  41. # define RXCIE RXCIE1
  42. # define USART_UDRE_vect USART1_UDRE_vect
  43. # define USART_RX_vect USART1_RX_vect
  44. # else
  45. /* Default is USART0 */
  46. # define RXC RXC0
  47. # define RXEN RXEN0
  48. # define TXC TXC0
  49. # define TXEN TXEN0
  50. # define UBRRH UBRR0H
  51. # define UBRRL UBRR0L
  52. # define UCSRA UCSR0A
  53. # define UCSRB UCSR0B
  54. # define UCSRC UCSR0C
  55. # define UCSZ0 UCSZ00
  56. # define UCSZ1 UCSZ01
  57. # define UDR UDR0
  58. # define UDRIE UDRIE0
  59. # define RXCIE RXCIE0
  60. # define USART_UDRE_vect USART0_UDRE_vect
  61. # define USART_RX_vect USART0_RX_vect
  62. # endif
  63. #elif defined __AVR_ATmega48__ || defined __AVR_ATmega88__ || defined __AVR_ATmega168__
  64. /* These chips include the USART number in their register names, */
  65. /* but not in the ISR name. */
  66. # define RXC RXC0
  67. # define RXEN RXEN0
  68. # define TXC TXC0
  69. # define TXEN TXEN0
  70. # define UBRRH UBRR0H
  71. # define UBRRL UBRR0L
  72. # define UCSRA UCSR0A
  73. # define UCSRB UCSR0B
  74. # define UCSRC UCSR0C
  75. # define UCSZ0 UCSZ00
  76. # define UCSZ1 UCSZ01
  77. # define UDR UDR0
  78. # define UDRIE UDRIE0
  79. #elif defined __AVR_ATmega32__
  80. # define TIMER2_COMPA_vect TIMER2_COMP_vect
  81. # define TCCR0B TCCR0
  82. # define TCCR2A TCCR2
  83. # define TCCR2B TCCR2
  84. # define TIFR0 TIFR
  85. # define TIMSK2 TIMSK
  86. # define OCIE2A OCIE2
  87. # define OCR2A OCR2
  88. #elif defined __AVR_ATmega128__
  89. # define UBRRH UBRR0H
  90. # define UBRRL UBRR0L
  91. # define UCSRA UCSR0A
  92. # define UCSRB UCSR0B
  93. # define UCSRC UCSR0C
  94. # define UDR UDR0
  95. # define USART_UDRE_vect USART0_UDRE_vect
  96. # define TIMER2_COMPA_vect TIMER2_COMP_vect
  97. # define TCCR0B TCCR0
  98. # define TCCR2A TCCR2
  99. # define TCCR2B TCCR2
  100. # define TIFR0 TIFR
  101. # define TIMSK1 TIMSK
  102. # define TIMSK2 TIMSK
  103. # define OCIE2A OCIE2
  104. # define OCR2A OCR2
  105. #else
  106. # error Unknown chip! (USART)
  107. #endif
  108. /* SPI and I2C */
  109. #if defined __AVR_ATmega32__ || defined __AVR_ATmega644__ || defined __AVR_ATmega644P__
  110. # define SPI_PORT PORTB
  111. # define SPI_DDR DDRB
  112. # define SPI_SS _BV(PB4)
  113. # define SPI_MOSI _BV(PB5)
  114. # define SPI_MISO _BV(PB6)
  115. # define SPI_SCK _BV(PB7)
  116. # define HWI2C_PORT PORTC
  117. # define HWI2C_SDA _BV(PC1)
  118. # define HWI2C_SCL _BV(PC0)
  119. #elif defined __AVR_ATmega128__ || defined __AVR_ATmega1281__ || defined __AVR_ATmega2561__
  120. # define SPI_PORT PORTB
  121. # define SPI_DDR DDRB
  122. # define SPI_SS _BV(PB0)
  123. # define SPI_SCK _BV(PB1)
  124. # define SPI_MOSI _BV(PB2)
  125. # define SPI_MISO _BV(PB3)
  126. # define HWI2C_PORT PORTD
  127. # define HWI2C_SDA _BV(PD1)
  128. # define HWI2C_SCL _BV(PD0)
  129. #elif defined __AVR_ATmega48__ || defined __AVR_ATmega88__ || defined __AVR_ATmega168__
  130. # define SPI_PORT PORTB
  131. # define SPI_DDR DDRB
  132. # define SPI_SS _BV(PB2)
  133. # define SPI_SCK _BV(PB5)
  134. # define SPI_MOSI _BV(PB3)
  135. # define SPI_MISO _BV(PB4)
  136. # define HWI2C_PORT PORTC
  137. # define HWI2C_SDA _BV(PC4)
  138. # define HWI2C_SCL _BV(PC5)
  139. #else
  140. # error Unknown chip! (SPI/TWI)
  141. #endif
  142. #define SPI_MASK (SPI_SS|SPI_MOSI|SPI_MISO|SPI_SCK)
  143. #endif /* AVRCOMPAT_H */