; ***************************************************************************
; 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.   *
; ***************************************************************************


; ***************************************************************************
;
;                             AtTiny 841
;                              -------
;                       VCC    1    14  GND
;                       PB0    2    13  PA0  COM-CLK
;                       PB1    3    12  PA1  
;               /RESET  PB3    4    11  PA2  COM-DATA
;                  LED  PB2    5    10  PA3  
;               1-wire  PA7    6     9  PA4  RXD1 (UART1)  [SCK, PRG]
; [MOSI,PRG] SDA (I2C)  PA6    7     8  PA5  TXD1 (UART1)  [MISO, PRG]
;                              -------
;
; when using ATTN1: LED=PA3, ATTN1=PB2 !!
; ***************************************************************************



.equ BOOTLOADER_ADDR = 0xd00

.equ FIRMWARE_VARIANT_BOOT        = 0
.equ FIRMWARE_VARIANT_TEMP_WINDOW = 1

.equ DEVICEINFO_ID       = 'T'
.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  = PORTB2



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

.equ LED_SIGNAL_DDR     = DDRB
.equ LED_SIGNAL_PORT    = PORTB
.equ LED_SIGNAL_PORTIN  = PINB
.equ LED_SIGNAL_PINNUM  = PORTB2



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

.equ COM_BIT_LENGTH     = 52000 ; 104000ns=9600, 52000ns=19200, 26000ns=38400

.equ COM_ATTN0_DDR       = DDRA
.equ COM_ATTN0_INPUT     = PINA
.equ COM_ATTN0_OUTPUT    = PORTA
.equ COM_ATTN0_PUE       = PUEA
.equ COM_ATTN0_PIN       = PORTA0

.equ COM_IRQ_ADDR_ATTN0  = PCMSK0
.equ COM_IRQ_BIT_ATTN0   = PCINT0        ; bit 0 in PCMSK0
.equ COM_IRQ_GIFR_ATTN0  = PCIF0
.equ COM_IRQ_GIMSK_ATTN0 = PCIE0

; compatibility
.equ COM_ATTN_DDR       = COM_ATTN0_DDR
.equ COM_ATTN_INPUT     = COM_ATTN0_INPUT
.equ COM_ATTN_OUTPUT    = COM_ATTN0_OUTPUT
.equ COM_ATTN_PUE       = COM_ATTN0_PUE
.equ COM_ATTN_PIN       = COM_ATTN0_PIN

.equ COM_IRQ_ADDR_ATTN   = COM_IRQ_ADDR_ATTN0
.equ COM_IRQ_BIT_ATTN    = COM_IRQ_BIT_ATTN0
.equ COM_IRQ_GIFR_ATTN   = COM_IRQ_GIFR_ATTN0
.equ COM_IRQ_GIMSK_ATTN  = COM_IRQ_GIMSK_ATTN0



.equ COM_DATA_DDR      = DDRA
.equ COM_DATA_INPUT    = PINA
.equ COM_DATA_OUTPUT   = PORTA
.equ COM_DATA_PUE      = PUEA
.equ COM_DATA_PIN      = PORTA2

.equ COM_CLK_DDR       = DDRA
.equ COM_CLK_INPUT     = PINA
.equ COM_CLK_OUTPUT    = PORTA
.equ COM_CLK_PUE       = PUEA
.equ COM_CLK_PIN       = PORTA0

.equ COM_IRQ_ADDR_CLK  = PCMSK0
.equ COM_IRQ_BIT_CLK   = PCINT0        ; bit 0 in PCMSK0
.equ COM_IRQ_GIFR_CLK  = PCIF0
.equ COM_IRQ_GIMSK_CLK = PCIE0



; ---------------------------------------------------------------------------
; 1-Wire Master
;

.equ OWI_DDR     = DDRA
.equ OWI_PORTOUT = PORTA
.equ OWI_PORTIN  = PINA
.equ OWI_PINNUM  = PORTA7


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

.equ  USART0_DATAREG   = UDR0
.equ  USART1_DATAREG   = UDR1

