; ***************************************************************************
; copyright   : (C) 2023 by Martin Preuss
; email       : martin@libchipcard.de
;
; ***************************************************************************
; * This file is part of the project "AqHome".                              *
; * Please see toplevel file COPYING of that project for license details.   *
; ***************************************************************************


; ***************************************************************************
;
;                                 AtMega8515
;                                 --------
;         DEV0        (T0)   PB0  1     40 VCC
;         DEV1        (T1)   PB1  2     39 PA0 (AD0) SRAM
;         DEV2        (AIN0) PB2  3     38 PA1 (AD1) SRAM
;         D_RES       (AIN1) PB3  4     37 PA2 (AD2) SRAM
;         SPI         (SS)   PB4  5     36 PA3 (AD3) SRAM
;         SPI         (MOSI) PB5  6     35 PA4 (AD4) SRAM
;         SPI         (MISO) PB6  7     34 PA5 (AD5) SRAM
;         SPI         (SCK)  PB7  8     33 PA6 (AD6) SRAM
;                         /RESET  9     32 PA7 (AD7) SRAM
;         UART        (RXD)  PD0 10     31 PE0 (INT2)
;         UART        (TXD)  PD1 11     30 PE1 (ALE) SRAM
;         ATTN        (INT0) PD2 12     29 PE2 (OC1B) LED
;         T-IRQ       (INT1) PD3 13     28 PC7 (A15) SRAM
;         D-DC        (XCK)  PD4 14     27 PC6 (A14) SRAM
;         D_BACKLIGHT (OC1A) PD5 15     26 PC5 (A13) SRAM
;         SRAM        (/WR)  PD6 16     25 PC4 (A12) SRAM
;         SRAM        (/RD)  PD7 17     24 PC3 (A11) SRAM
;                          XTAL2 18     23 PC2 (A10) SRAM
;                          XTAL1 19     22 PC1 (A9)  SRAM
;                            GND 20     21 PC0 (A8)  SRAM
;                                 --------
;
; ***************************************************************************



.equ BOOTLOADER_ADDR = 0xc00

.equ FIRMWARE_VARIANT_BOOT        = 0
.equ FIRMWARE_VARIANT_TEMP_WINDOW = 1

.equ DEVICEINFO_ID       = 'C'
.equ DEVICEINFO_VERSION  = 1
.equ DEVICEINFO_REVISION = 0



; ---------------------------------------------------------------------------
; LED module

.equ LED1_DEFAULT_ONTIME  = 1     ; shorter
.equ LED1_DEFAULT_OFFTIME = 99    ; longer
.equ LED1_DEFAULT_REPEATS = 0     ; continous
.equ LED1_DDR     = DDRE
.equ LED1_PORT    = PORTE
.equ LED1_PORTIN  = PINE
.equ LED1_PINNUM  = PORTE2



; ---------------------------------------------------------------------------
; COM module

.equ COM_BIT_LENGTH      = 52000 ; 104000ns=9600, 52000ns=19200, 26000ns=38400
.equ COM_HALFBIT_LENGTH  = 26000 ; see https://de.wikipedia.org/wiki/Universal_Asynchronous_Receiver_Transmitter

.equ COM_DATA_DDR       = DDRD
.equ COM_DATA_INPUT     = PIND
.equ COM_DATA_OUTPUT    = PORTD
.equ COM_DATA_PIN       = PORTD0

.equ COM_CLK_DDR       = DDRD
.equ COM_CLK_INPUT     = PIND
.equ COM_CLK_OUTPUT    = PORTD
.equ COM_CLK_PIN       = PORTD2

.equ COM_IRQ_ADDR_CLK   = GICR
.equ COM_IRQ_BIT_CLK    = INT0
.equ COM_IRQ_GIFR_CLK   = INTF0
;.equ COM_IRQ_GIMSK_ATTN  = PCIE0



; ---------------------------------------------------------------------------
; SPI hardware module

.equ SPIHW_SS_DDR      = DDRB
.equ SPIHW_SS_INPUT    = PINB
.equ SPIHW_SS_OUTPUT   = PORTB
.equ SPIHW_SS_PIN      = PORTB4

.equ SPIHW_MOSI_DDR    = DDRB
.equ SPIHW_MOSI_INPUT  = PINB
.equ SPIHW_MOSI_OUTPUT = PORTB
.equ SPIHW_MOSI_PIN    = PORTB5

.equ SPIHW_MISO_DDR    = DDRB
.equ SPIHW_MISO_INPUT  = PINB
.equ SPIHW_MISO_OUTPUT = PORTB
.equ SPIHW_MISO_PIN    = PORTB6

.equ SPIHW_SCK_DDR    = DDRB
.equ SPIHW_SCK_INPUT  = PINB
.equ SPIHW_SCK_OUTPUT = PORTB
.equ SPIHW_SCK_PIN    = PORTB7

.equ SPIHW_SS0_DDR    = DDRB
.equ SPIHW_SS0_OUTPUT = PORTB
.equ SPIHW_SS0_INPUT  = PORTB
.equ SPIHW_SS0_PIN    = PORTB0

.equ SPIHW_SS1_DDR    = DDRB
.equ SPIHW_SS1_OUTPUT = PORTB
.equ SPIHW_SS1_INPUT  = PORTB
.equ SPIHW_SS1_PIN    = PORTB1

.equ SPIHW_SS2_DDR    = DDRB
.equ SPIHW_SS2_OUTPUT = PORTB
.equ SPIHW_SS2_INPUT  = PORTB
.equ SPIHW_SS2_PIN    = PORTB2



; ---------------------------------------------------------------------------
; ILI9341 module

.equ ILI9341_DEVICENUM    = 0
.equ ILI9341_DSP_WIDTH    = 320
.equ ILI9341_DSP_HEIGHT   = 240

.equ ILI9341_RESET_DDR    = DDRB
.equ ILI9341_RESET_OUTPUT = PORTB
.equ ILI9341_RESET_INPUT  = PORTB
.equ ILI9341_RESET_PIN    = PORTB3

.equ ILI9341_DC_DDR       = DDRD
.equ ILI9341_DC_OUTPUT    = PORTD
.equ ILI9341_DC_INPUT     = PORTD
.equ ILI9341_DC_PIN       = PORTD4

.equ ILI9341_LED_DDR      = DDRD
.equ ILI9341_LED_OUTPUT   = PORTD
.equ ILI9341_LED_INPUT    = PORTD
.equ ILI9341_LED_PIN      = PORTD5



; ---------------------------------------------------------------------------
; ComOnUart module

.equ USART0_DATAREG = UDR
.equ UCSR0A = UCSRA
.equ UCSR0B = UCSRB
.equ UCSR0C = UCSRC
.equ UBRR0L = UBRRL
.equ UBRR0H = UBRRH

.equ UCSZ00 = UCSZ0
.equ UCSZ01 = UCSZ1
.equ UDRE0  = UDRE
.equ RXC0   = RXC
.equ TXC0   = TXC
.equ FE0    = FE
.equ DOR0   = DOR
.equ UPE0   = UPE
.equ RXEN0  = RXEN
.equ TXEN0  = TXEN
.equ USBS0  = USBS
.equ RXCIE0 = RXCIE
.equ UDRIE0 = UDRIE


