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


; ***************************************************************************
;
;                                 AtTiny84
;                                 --------
;                            VCC  1     14  GND
;                  RAM_CS    PB0  2     13  PA0
;               EEPROM_CS    PB1  3     12  PA1  COM_DATA
;                  /RESET    PB3  4     11  PA2
;                            PB2  5     10  PA3  LED
;                  COM_CLK   PA7  6      9  PA4  SPI_CLK
;                  SPI_MOSI  PA6  7      8  PA5  SPI_MISO
;                                 --------
;
; ***************************************************************************



.equ BOOTLOADER_ADDR = 0xd00

.equ FIRMWARE_VARIANT_BOOT        = 0
.equ FIRMWARE_VARIANT_TEMP_WINDOW = 1

.equ DEVICEINFO_ID       = 'E'
.equ DEVICEINFO_VERSION  = 5
.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     = DDRA
.equ LED1_PORT    = PORTA
.equ LED1_PORTIN  = PINA
.equ LED1_PINNUM  = PORTA3



; ---------------------------------------------------------------------------
; 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       = DDRA
.equ COM_DATA_INPUT     = PINA
.equ COM_DATA_OUTPUT    = PORTA
.equ COM_DATA_PIN       = PORTA1

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

.equ COM_IRQ_ADDR_CLK   = PCMSK0
.equ COM_IRQ_BIT_CLK    = PCINT7        ; bit 7 in PCMSK0
.equ COM_IRQ_GIFR_CLK   = PCIF0
.equ COM_IRQ_GIMSK_CLK  = PCIE0



; ---------------------------------------------------------------------------
; software SPI module


.equ SPISW_MOSI_DDR    = DDRA
.equ SPISW_MOSI_INPUT  = PINA
.equ SPISW_MOSI_OUTPUT = PORTA
.equ SPISW_MOSI_PIN    = PORTA6

.equ SPISW_MISO_DDR    = DDRA
.equ SPISW_MISO_INPUT  = PINA
.equ SPISW_MISO_OUTPUT = PORTA
.equ SPISW_MISO_PIN    = PORTA5

.equ SPISW_SCK_DDR     = DDRA
.equ SPISW_SCK_INPUT   = PINA
.equ SPISW_SCK_OUTPUT  = PORTA
.equ SPISW_SCK_PIN     = PORTA4



; ---------------------------------------------------------------------------
; SPI RAM

.equ RAMCS_DDR         = DDRB
.equ RAMCS_INPUT       = PINB
.equ RAMCS_OUTPUT      = PORTB
.equ RAMCS_PIN         = PORTB0



; ---------------------------------------------------------------------------
; SPI EEPROM


.equ EEPROMCS_DDR      = DDRB
.equ EEPROMCS_INPUT    = PINB
.equ EEPROMCS_OUTPUT   = PORTB
.equ EEPROMCS_PIN      = PORTB1



