Files
aqhomecontrol/avr/devices/c02/main/main.asm
2025-09-08 22:04:15 +02:00

452 lines
9.9 KiB
NASM

; ***************************************************************************
; 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. *
; ***************************************************************************
;.equ clock=1000000 ; Define the clock frequency
.equ clock=8000000 ; Define the clock frequency
.nolist
.include "include/m644Pdef.inc" ; Define device ATmega644P
.list
.include "version.asm"
.include "../defs.asm"
.include "./data.asm"
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_wait.asm"
.include "common/utils_io.asm"
; ***************************************************************************
; defines
; ---------------------------------------------------------------------------
; generic
.equ STACK_SIZE = 256
.equ NET_BUFFERS_NUM = 8
.equ NET_MSGNUMINBUF_SIZE = 8 ; max buffer nums in ringbuffer (global incoming)
.equ NET_IFACE_OUTMSGBUF_SIZE = 8 ; max buffer nums in ringbuffer (per interface outbound)
; ---------------------------------------------------------------------------
; firmware settings including list of modules used
; #define MODULES_TIMER
#define MODULES_CLOCK
;#define MODULES_XRAM
#define MODULES_HEAP
#define MODULES_LED_SIMPLE
#define MODULES_NETWORK
;#define MODULES_COMONUART0
;#define MODULES_UART_HW
#define MODULES_UART_BITBANG
#define MODULES_SPI_HW
#define MODULES_ILI9341
#define MODULES_FONT
#define MODULES_WIN
;#define MODULES_TWI_MASTER
;#define MODULES_LCD
;#define LCD_MINIMAL_FONT
;#define MODULES_SI7021
;#define MODULES_SGP30
;#define MODULES_SGP40
;#define MODULES_STATS
;#define MODULES_OWI_MASTER
;#define MODULES_DS18B20
;#define MODULES_MOTION
;#define MODULES_CCS811
#define APPS_NETWORK
;#define APPS_MOTION
;#define APPS_REPORTSENSORS
#define APPS_STATS
; ---------------------------------------------------------------------------
; defines for values
.equ VALUE_ID_SI7021_TEMP = 0x01
.equ VALUE_ID_SI7021_HUM = 0x02
.equ VALUE_ID_ADC = 0x03
;.equ VALUE_ID_DS18B20_TEMP = 0x06
.equ VALUE_ID_MOTION = 0x07
.equ VALUE_ID_SGP40_TVOC = 0x08
.equ VALUE_ID_SGP30_TVOC = 0x09
.equ VALUE_ID_SGP30_CO2 = 0x0a
;.equ VALUE_ID_REED_CONF = 0x81
.equ VALUE_ID_DEBUG = 0x7f
.equ VALUE_ID_LEDSIMPLE_TIMING = 0x88
; ***************************************************************************
; code segment
.cseg
.org 000000
; ---------------------------------------------------------------------------
; Reset and interrupt vectors
jmp BOOTLOADER_ADDR ; 1: Reset vector RESET
jmp UART_BitBang_PcintIsr ; 2: INT0 External Interrupt Request 0
jmp irqNotSet ; 3: INT1 External Interrupt Request 1
jmp irqNotSet ; 4: INT2 External Interrupt Request 2
jmp irqNotSet ; 5: PCINT0 Pin Change Interrupt Request 0
jmp irqNotSet ; 6: PCINT1 Pin Change Interrupt Request 1
jmp irqNotSet ; 7: PCINT2 Pin Change Interrupt Request 2
jmp irqNotSet ; 8: PCINT3 Pin Change Interrupt Request 3
jmp irqNotSet ; 9: WDT Watchdog Time-out Interrupt
jmp irqNotSet ; 10: TIMER2_COMPA Timer/Counter2 Compare Match A
jmp irqNotSet ; 11: TIMER2_COMPB Timer/Counter2 Compare Match B
jmp irqNotSet ; 12: TIMER2_OVF Timer/Counter2 Overflow
jmp irqNotSet ; 13: TIMER1_CAPT Timer/Counter1 Capture Event
jmp irqNotSet ; 14: TIMER1_COMPA Timer/Counter1 Compare Match A
jmp irqNotSet ; 15: TIMER1_COMPB Timer/Counter1 Compare Match B
jmp irqNotSet ; 16: TIMER1_OVF Timer/Counter1 Overflow
jmp baseTimerIrqOC0A ; 17: TIMER0_COMPA Timer/Counter0 Compare Match A
jmp irqNotSet ; 18: TIMER0_COMPB Timer/Counter0 Compare Match B
jmp irqNotSet ; 19: TIMER0_OVF Timer/Counter0 Overflow
jmp irqNotSet ; 20: SPI_STC Serial Transfer Complete
jmp irqNotSet ; 21: USART0_RXC USART0 Rx Complete
jmp irqNotSet ; 22: USART0_UDRE USART0 Data Register Empty
jmp irqNotSet ; 23: USART0_TXC USART0 Tx Complete
jmp irqNotSet ; 24: ANA_COMP Analog Comparator
jmp irqNotSet ; 25: ADC ADC Conversion Complete
jmp irqNotSet ; 26: EE_RDY EEPROM Ready
jmp irqNotSet ; 27: TWI 2-Wire Interface
jmp irqNotSet ; 28: SPM_RDY Store Program Memory Ready
devInfoBlock: ; 12 bytes
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
devInfoId: .db DEVICEINFO_ID, 0
devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; version, revision
firmwareVersion: .db FIRMWARE_VARIANT_TEMP_WINDOW, FIRMWARE_VERSION_MAJOR
.db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL
; ---------------------------------------------------------------------------
; @routine firmwareStart @global
firmwareStart:
rjmp main
; @end
irqNotSet:
reti
; ---------------------------------------------------------------------------
; @routine onSystemStart
onSystemStart:
bigcall test
ret
; @end
; ---------------------------------------------------------------------------
; @routine onMessageReceived
;
; Called on every message received
onMessageReceived:
clc
ret
; @end
; ---------------------------------------------------------------------------
; @routine onEvery100ms
;
; Called every 100ms. Add your routine calls here. No arguments, no results.
onEvery100ms:
onEverySecond:
onEveryMinute:
onEveryHour:
onEveryDay:
ret
; @end
; ---------------------------------------------------------------------------
; @routine onEveryLoop
;
; Called on every loop (i.e. after awakening from sleep).
;
onEveryLoop:
ret
; @end
; ***************************************************************************
; includes
.include "devices/all/hw_m644p.asm"
.include "devices/all/includes.asm"
;.include "common/debug.asm"
;.include "modules/lcd2/font/font2.asm"
;.include "modules/lcd2/font/font3.asm"
;.include "modules/lcd2/font/font16x26.asm"
;.include "modules/lcd2/font/font4.asm"
;.include "modules/lcd2/font/font12x16.asm"
.include "modules/lcd2/font/font5.asm"
.include "modules/lcd2/font/font12x20.asm"
;.include "common/list_t.asm"
.include "common/tree_t.asm"
.include "common/divide.asm"
; ---------------------------------------------------------------------------
; defines for network interface
;.equ netInterfaceData = netUartIface
.equ netInterfaceData = uart_bitbang_iface
; @param %0 X
; @param %1 Y
; @param %2 W
; @param %3 H
.macro M_FILL_RECT
ldi r16, LOW(@0) ; X0
mov r4, r16
ldi r16, HIGH(@0)
mov r5, r16
ldi r16, LOW(@1) ; Y0
mov r6, r16
ldi r16, HIGH(@1)
mov r7, r16
ldi r16, LOW(@2) ; W
mov r8, r16
ldi r16, HIGH(@2)
mov r9, r16
ldi r16, LOW(@3) ; H
mov r10, r16
ldi r16, HIGH(@3)
mov r11, r16
bigcall ILI9341_FillRect
.endmacro
test:
; set foreground (r3:r2)
; 0bRRRRRGGGGGGBBBBB
ldi r16, 0b11111111
mov r3, r16
ldi r16, 0b11111111 ; white
mov r2, r16
M_FILL_RECT 0, 0, 319, 239
; set foreground (r3:r2)
ldi r16, 0b00000000
mov r3, r16
ldi r16, 0b00011111 ; blue
mov r2, r16
M_FILL_RECT 0, 0, 319, 32
; set background (r1:r0)
mov r0, r2
mov r1, r3
; set foreground (r3:r2)
ldi r16, 0b11111111
mov r3, r16
ldi r16, 0b11111111 ; white
mov r2, r16
; set Xpos
ldi r16, LOW(10)
mov r4, r16
ldi r16, HIGH(10)
mov r5, r16
; setYpos
ldi r16, LOW(3)
mov r6, r16
ldi r16, HIGH(3)
mov r7, r16
; set font
; ldi zl, LOW(font3_16x26*2)
; ldi zh, HIGH(font3_16x26*2)
ldi zl, LOW(font5_12x20*2)
ldi zh, HIGH(font5_12x20*2)
; set buffer
ldi xl, LOW(glyphBuffer)
ldi xh, HIGH(glyphBuffer)
; write characters
ldi r16, 'A'
bigcall ili9341_WriteCharacterX1At
ldi r16, 'Q'
bigcall ili9341_WriteCharacterX1At
ldi r16, 'H'
bigcall ili9341_WriteCharacterX1At
ldi r16, 'O'
bigcall ili9341_WriteCharacterX1At
ldi r16, 'M'
bigcall ili9341_WriteCharacterX1At
ldi r16, 'E'
bigcall ili9341_WriteCharacterX1At
#if 0
push xl
push xh
rcall listTest1
pop xh
pop xl
brcc test_error
ldi r16, '!'
bigcall ili9341_WriteCharacterX1At
push xl
push xh
rcall listTest2
pop xh
pop xl
brcc test_error
ldi r16, '!'
bigcall ili9341_WriteCharacterX1At
push xl
push xh
rcall listTest3
pop xh
pop xl
brcc test_error
ldi r16, '!'
bigcall ili9341_WriteCharacterX1At
push xl
push xh
rcall listTest4
pop xh
pop xl
brcc test_error
ldi r16, '!'
bigcall ili9341_WriteCharacterX1At
#endif
#if 1
push xl
push xh
rcall treeTest1
pop xh
pop xl
brcc test_error
ldi r16, '!'
bigcall ili9341_WriteCharacterX1At
push xl
push xh
rcall treeTest2
pop xh
pop xl
brcc test_error
ldi r16, '!'
bigcall ili9341_WriteCharacterX1At
push xl
push xh
rcall treeTest3
pop xh
pop xl
brcc test_error
ldi r16, '!'
bigcall ili9341_WriteCharacterX1At
push xl
push xh
rcall treeTest4
pop xh
pop xl
brcc test_error
ldi r16, '!'
bigcall ili9341_WriteCharacterX1At
#endif
ret
test_error:
ldi r17, '0'
add r16, r17
bigcall ili9341_WriteCharacterX1At
ret
helloWorld: .db "Hello World", 0
.dseg
glyphBuffer: .byte 1024
heapStart:
.equ HEAP_START = heapStart
.equ HEAP_SIZE = (SRAM_SIZE-STACK_SIZE)-HEAP_START