; ***************************************************************************
; 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  ATTN0
;                ATTN1  PB1    3    12  PA1  TXD0 (UART0)
;               /RESET  PB3    4    11  PA2  RXD0 (UART0)
;                  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       = 'R'
.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     = DDRB
.equ LED1_PORT    = PORTB
.equ LED1_PORTIN  = PINB
.equ LED1_PINNUM  = PORTB2



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

; settings for comOnUart0
.equ COM_DATA0_DDR      = DDRA
.equ COM_DATA0_INPUT    = PINA
.equ COM_DATA0_OUTPUT   = PORTA
.equ COM_DATA0_PUE      = PUEA
.equ COM_DATA0_PIN      = PORTA2

.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


; settings for comOnUart1
.equ COM_ATTN1_DDR       = DDRB
.equ COM_ATTN1_INPUT     = PINB
.equ COM_ATTN1_OUTPUT    = PORTB
.equ COM_ATTN1_PUE       = PUEB
.equ COM_ATTN1_PIN       = PORTB1

.equ COM_IRQ_ADDR_ATTN1  = PCMSK1
.equ COM_IRQ_BIT_ATTN1   = PCINT9        ; bit PCINT9 in PCMSK1
.equ COM_IRQ_GIFR_ATTN1  = PCIF1
.equ COM_IRQ_GIMSK_ATTN1 = PCIE1


; settings for comOnUart1
.equ COM_DATA1_DDR      = DDRA
.equ COM_DATA1_INPUT    = PINA
.equ COM_DATA1_OUTPUT   = PORTA
.equ COM_DATA1_PUE      = PUEA
.equ COM_DATA1_PIN      = PORTA4

.equ COM_CLK1_DDR       = DDRB
.equ COM_CLK1_INPUT     = PINB
.equ COM_CLK1_OUTPUT    = PORTB
.equ COM_CLK1_PUE       = PUEB
.equ COM_CLK1_PIN       = PORTB1

.equ COM_IRQ_ADDR_CLK1  = PCMSK1
.equ COM_IRQ_BIT_CLK1   = PCINT9        ; bit PCINT9 in PCMSK1
.equ COM_IRQ_GIFR_CLK1  = PCIF1
.equ COM_IRQ_GIMSK_CLK1 = PCIE1



; ---------------------------------------------------------------------------
; TWI master module

;.equ TWI_BIT_LENGTH = 10000 ; 100000 and 200000 works for display: 10000, 100000, 200000
.equ TWI_BIT_LENGTH = 1 ; 10, 100, 500, 100000 and 200000 works for display: 10000, 100000, 200000

.equ TWI_DDR_SCL          = DDRA
.equ TWI_PORT_SCL         = PORTA
.equ TWI_PIN_SCL          = PINA
.equ TWI_PINNUM_SCL       = PORTA3

.equ TWI_DDR_SDA          = DDRB
.equ TWI_PORT_SDA         = PORTB
.equ TWI_PIN_SDA          = PINB
.equ TWI_PINNUM_SDA       = PORTB0



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



; ---------------------------------------------------------------------------
; LCD module

.equ LCD_TWI_ADDRESS      = 0x3c




