; ***************************************************************************
; copyright   : (C) 2025 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.   *
; ***************************************************************************


; ***************************************************************************
;
;                                 AtMega644
;                                 --------
;                       LED  PB0  1     40 PA0 COM0-CLK
;                            PB1  2     39 PA1 COM1-CLK
;                            PB2  3     38 PA2 COM2-CLK
;                            PB3  4     37 PA3 COM3-CLK
;                            PB4  5     36 PA4 COM4-CLK
;                      MOSI  PB5  6     35 PA5 COM5-CLK
;                      MISO  PB6  7     34 PA6 COM6-CLK
;                       SCK  PB7  8     33 PA7 COM7-CLK
;                         /RESET  9     32 AREF
;                            VCC 10     31 GND
;                            GND 11     30 AVCC
;                          XTAL2 12     29 PC7 COM7-DATA
;                          XTAL1 13     28 PC6 COM6-DATA
;                  COM0-LED  PD0 14     27 PC5 COM5-DATA
;                  COM1-LED  PD1 15     26 PC4 COM4-DATA
;                  COM2-LED  PD2 16     25 PC3 COM3-DATA
;                  COM3-LED  PD3 17     24 PC2 COM2-DATA
;                  COM4-LED  PD4 18     23 PC1 COM1-DATA
;                  COM5-LED  PD5 19     22 PC0 COM0-DATA
;                  COM6-LED  PD6 20     21 COM7-LED
;                                 --------
;
; ***************************************************************************



.equ BOOTLOADER_ADDR = 0x7c00

.equ FIRMWARE_VARIANT_BOOT        = 0
.equ FIRMWARE_VARIANT_TEMP_WINDOW = 1

.equ DEVICEINFO_ID       = 'S'
.equ DEVICEINFO_VERSION  = 3
.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     = DDRB
.equ LED1_PORT    = PORTB
.equ LED1_PORTIN  = PINB
.equ LED1_PINNUM  = PORTB0



; ---------------------------------------------------------------------------
; 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       = DDRC
.equ COM_DATA_INPUT     = PINC
.equ COM_DATA_OUTPUT    = PORTC
.equ COM_DATA_PIN       = PORTC6

.equ COM_CLK_DDR        = DDRA
.equ COM_CLK_INPUT      = PINA
.equ COM_CLK_OUTPUT     = PORTA
.equ COM_CLK_PIN        = PORTA6

.equ COM_IRQ_ADDR_M_CLK = PCICR
.equ COM_IRQ_BIT_M_CLK  = PCIE0

.equ COM_IRQ_ADDR_F_CLK = PCIFR
.equ COM_IRQ_BIT_F_CLK  = PCIF0

.equ COM_IRQ_ADDR_CLK   = PCMSK0



#if 0
.equ COM_PORTS         = 8

.equ COM_MASK_CLK0     = (1<<PINA0)
.equ COM_MASK_DATA0    = (1<<PINC0)

.equ COM_MASK_CLK1     = (1<<PINA1)
.equ COM_MASK_DATA1    = (1<<PINC1)

.equ COM_MASK_CLK2     = (1<<PINA2)
.equ COM_MASK_DATA2    = (1<<PINC2)

.equ COM_MASK_CLK3     = (1<<PINA3)
.equ COM_MASK_DATA3    = (1<<PINC3)

.equ COM_MASK_CLK4     = (1<<PINA4)
.equ COM_MASK_DATA4    = (1<<PINC4)

.equ COM_MASK_CLK5     = (1<<PINA5)
.equ COM_MASK_DATA5    = (1<<PINC5)

.equ COM_MASK_CLK6     = (1<<PINA6)
.equ COM_MASK_DATA6    = (1<<PINC6)

.equ COM_MASK_CLK7     = (1<<PINA7)
.equ COM_MASK_DATA7    = (1<<PINC7)

#else
.equ COM_PORTS         = 2

.equ COM_MASK_CLK0     = (1<<PINA6)
.equ COM_MASK_DATA0    = (1<<PINC6)

.equ COM_MASK_CLK1     = (1<<PINA5)
.equ COM_MASK_DATA1    = (1<<PINC5)

#endif




