From f834a4ecc5566a0c90d682222407e03ddfa397c5 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 17 May 2025 10:44:37 +0200 Subject: [PATCH 01/58] fixed apidoc. --- avr/apps/door/main.asm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avr/apps/door/main.asm b/avr/apps/door/main.asm index ef0bb46..da436e9 100644 --- a/avr/apps/door/main.asm +++ b/avr/apps/door/main.asm @@ -49,7 +49,7 @@ AppDoor_Init: ldi yl, LOW(appDoorValSchedData) ldi yh, HIGH(appDoorValSchedData) rcall ValueScheduler_Init - ldi r16, (1< Date: Sat, 17 May 2025 10:44:48 +0200 Subject: [PATCH 02/58] fixed a bug. --- avr/apps/reportsensors/main.asm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/avr/apps/reportsensors/main.asm b/avr/apps/reportsensors/main.asm index 94a7dd8..6f4751e 100644 --- a/avr/apps/reportsensors/main.asm +++ b/avr/apps/reportsensors/main.asm @@ -53,11 +53,12 @@ AppReportSensors_Fini: ; AppReportSensors_OnEverySecond: - in r15, SREG push r15 + in r15, SREG cli rcall AppReportSensors_OnEverySecond_noIrqs - out SREG, r15 + out SREG, r15 + pop r15 ret AppReportSensors_OnEverySecond_noIrqs: lds r16, reportSensorTimer From f5606554c9e2e3dc947f91f09602e7fb0d608cf3 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 17 May 2025 10:45:37 +0200 Subject: [PATCH 03/58] added tool flashnode.sh --- flashnode.sh | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 flashnode.sh diff --git a/flashnode.sh b/flashnode.sh new file mode 100755 index 0000000..bc3358b --- /dev/null +++ b/flashnode.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +NODE="$1" + +if test -z "$NODE"; then + echo "Missing node" + exit 1 +fi + + + +case $NODE in + c01) + DEVICE_ARG="-p m8515" + HFUSE_ARG="-U hfuse:w:0xD1:m" + LFUSE_ARG="-U lfuse:w:0xE4:m" + FILE_ARG="-U flash:w:./0-build/avr/devices/c01/boot/c01_boot.hex" + ;; + n21) + DEVICE_ARG="-p t84" + HFUSE_ARG="-U hfuse:w:0xD7:m" + LFUSE_ARG="" + EFUSE_ARG="-U efuse:w:0xFE:m" + FILE="-U flash:w:./0-build/avr/devices/n21/boot/n21_boot.hex" + ;; + n22) + DEVICE_ARG="-p t85" + HFUSE_ARG="-U hfuse:w:0xD7:m" + LFUSE_ARG="" + EFUSE_ARG="-U efuse:w:0xFE:m" + FILE_ARG="-U flash:w:./0-build/avr/devices/n22/boot/n22_boot.hex" + ;; + n23) + DEVICE_ARG="-p t84" + HFUSE_ARG="-U hfuse:w:0xD7:m" + LFUSE_ARG="" + EFUSE_ARG="-U efuse:w:0xFE:m" + FILE_ARG="-U flash:w:./0-build/avr/devices/n21/boot/n21_boot.hex" + ;; + n24) + DEVICE_ARG="-p t84" + HFUSE_ARG="-U hfuse:w:0xD7:m" + LFUSE_ARG="" + EFUSE_ARG="-U efuse:w:0xFE:m" + FILE_ARG="-U flash:w:./0-build/avr/devices/n23/boot/n23_boot.hex" + ;; + t03) + DEVICE_ARG="-p t841" + HFUSE_ARG="-U hfuse:w:0xD7:m" + LFUSE_ARG="" + EFUSE_ARG="-U efuse:w:0xFE:m" + FILE_ARG="-U flash:w:./0-build/avr/devices/t03/boot/t03_boot.hex" + ;; + *) + echo "Unknown node $NODE". + exit 1 + ;; +esac + + +echo "avrdude -c stk500 -P /dev/ttyACM0 -B16 $DEVICE_ARG $HFUSE_ARG $LFUSE_ARG $EFUSE_ARG $FILE_ARG" +avrdude -c stk500 -P /dev/ttyACM0 -B16 $DEVICE_ARG $HFUSE_ARG $LFUSE_ARG $EFUSE_ARG $FILE_ARG + + From bb4e16cae7d0e66d12a902574b63a6958c7bf970 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 17 May 2025 10:46:03 +0200 Subject: [PATCH 04/58] add line with ATTN. --- aqhome-nodes.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/aqhome-nodes.sh b/aqhome-nodes.sh index 7152686..78b9ca0 100755 --- a/aqhome-nodes.sh +++ b/aqhome-nodes.sh @@ -11,3 +11,4 @@ export LD_LIBRARY_PATH="0-build/aqhome/:$LD_LIBRARY_PATH" # 0-build/apps/aqhomed/aqhomed -l aqhome.log -db aqhome.db -p aqhomed.pid -W /tmp/aqhome/aqhomed -ma 192.168.117.192 -mp 1883 -t 127.0.0.1 --mqttclientid=AQHOMEMQTTLOGTEST1 0-build/apps/aqhome-nodes/aqhome-nodes -N -l aqhome-nodes.log -db aqhome-nodes.db -p aqhome-nodes.pid -t 127.0.0.1 -ba 127.0.0.1 "$@" +#0-build/apps/aqhome-nodes/aqhome-nodes -l aqhome-nodes.log -db aqhome-nodes.db -p aqhome-nodes.pid -t 127.0.0.1 -ba 127.0.0.1 "$@" From 930229b96994a539b35838cf05188a20a587bfd3 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 17 May 2025 10:46:46 +0200 Subject: [PATCH 05/58] add macros for reading/writing IO regs regardless of their position (i.e. < or >=0x40). --- avr/common/0BUILD | 1 + avr/common/utils_io.asm | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 avr/common/utils_io.asm diff --git a/avr/common/0BUILD b/avr/common/0BUILD index 4d18df1..26bb9eb 100644 --- a/avr/common/0BUILD +++ b/avr/common/0BUILD @@ -17,6 +17,7 @@ utils_copy_from_flash.asm utils_copy_sdram.asm utils_initial_wait.asm + utils_io.asm utils_wait.asm utils_wait_fixed.asm utils_wait_pin.asm diff --git a/avr/common/utils_io.asm b/avr/common/utils_io.asm new file mode 100644 index 0000000..8309a1e --- /dev/null +++ b/avr/common/utils_io.asm @@ -0,0 +1,29 @@ +; *************************************************************************** +; copyright : (C) 2023 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. * +; *************************************************************************** + + +; M_IO_READ DEST, SRC +.macro M_IO_READ +.if @1 < 64 + in @0, @1 +.else + lds @0, @1 +.endif +.endmacro + + + +; M_IO_WRITE DEST, SRC +.macro M_IO_WRITE +.if @0 < 64 + out @0, @1 +.else + sts @0, @1 +.endif +.endmacro From 732dcd74f70890a87a865492b6de63594a91b79a Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 17 May 2025 10:47:29 +0200 Subject: [PATCH 06/58] only include "sendvalue.asm" if networking code enabled. --- avr/devices/all/includes.asm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/avr/devices/all/includes.asm b/avr/devices/all/includes.asm index a526ebc..55160d6 100644 --- a/avr/devices/all/includes.asm +++ b/avr/devices/all/includes.asm @@ -11,7 +11,9 @@ .include "devices/all/main.asm" .include "devices/all/apps.asm" .include "devices/all/modules.asm" -.include "devices/all/sendvalue.asm" +#ifdef MODULES_NETWORK + .include "devices/all/sendvalue.asm" +#endif .include "devices/all/data.asm" .include "common/utils.asm" From dba503df5bcd7583379772ee3436a697ff097301 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 17 May 2025 10:47:44 +0200 Subject: [PATCH 07/58] only call LedSimple_OnPacketReceived is networking code enabled. --- avr/devices/all/modules.asm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/avr/devices/all/modules.asm b/avr/devices/all/modules.asm index 04592d4..90a41f6 100644 --- a/avr/devices/all/modules.asm +++ b/avr/devices/all/modules.asm @@ -203,7 +203,9 @@ mainModulesOnPacketReceived: #endif #ifdef MODULES_LED_SIMPLE + #ifdef MODULES_NETWORK rcall LedSimple_OnPacketReceived + #endif #endif From d51ca9b1d1cba054374bd2241ef31f493123e225 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 17 May 2025 10:47:59 +0200 Subject: [PATCH 08/58] n21: added VALUE_ID_LEDSIMPLE_TIMING --- avr/devices/n21/main/main.asm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/avr/devices/n21/main/main.asm b/avr/devices/n21/main/main.asm index c9c0c62..a2e0325 100644 --- a/avr/devices/n21/main/main.asm +++ b/avr/devices/n21/main/main.asm @@ -97,6 +97,8 @@ ;.equ VALUE_ID_REED_CONF = 0x81 +.equ VALUE_ID_LEDSIMPLE_TIMING = 0x88 + ; *************************************************************************** From e545251b27003176f5f8560542fb0dcdb8074405 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 17 May 2025 10:48:39 +0200 Subject: [PATCH 09/58] moved timer setup code into hardware include file. --- avr/devices/all/hw_tn84.asm | 58 ++++++++++++++++++++++++++++++++++ avr/devices/all/hw_tn841.asm | 58 ++++++++++++++++++++++++++++++++++ avr/devices/all/hw_tn85.asm | 58 ++++++++++++++++++++++++++++++++++ avr/modules/basetimer/main.asm | 50 +---------------------------- 4 files changed, 175 insertions(+), 49 deletions(-) diff --git a/avr/devices/all/hw_tn84.asm b/avr/devices/all/hw_tn84.asm index 3218867..b093245 100644 --- a/avr/devices/all/hw_tn84.asm +++ b/avr/devices/all/hw_tn84.asm @@ -85,3 +85,61 @@ systemSleep: +; --------------------------------------------------------------------------- +; @routine systemSetupTimer0 +; + +systemSetupTimer0: ; setup timer for IRQ every 100ms + ldi r16, (1< Date: Sat, 17 May 2025 10:49:03 +0200 Subject: [PATCH 10/58] bootloader: decreased waiting time. --- avr/modules/bootloader/main.asm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/avr/modules/bootloader/main.asm b/avr/modules/bootloader/main.asm index e295abf..6f8dfb0 100644 --- a/avr/modules/bootloader/main.asm +++ b/avr/modules/bootloader/main.asm @@ -66,13 +66,13 @@ bootLoader: brcc bootLoader_waitAndRestartBootLoader ; try to start firmware bootLoader_startFirmware: - ldi r19, 20 ; loop count + ldi r19, 10 ; loop count ldi r20, 4 ; on time ldi r21, 1 ; off time rcall bootLoaderBlinkLed rjmp firmwareStart bootLoader_waitAndRestartBootLoader: - ldi r19, 15 ; loop count + ldi r19, 5 ; loop count ldi r20, 1 ; on time ldi r21, 8 ; off time rcall bootLoaderBlinkLed From 21c2c60f4fb86f1efb01989ea605b038753698a1 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 17 May 2025 10:50:09 +0200 Subject: [PATCH 11/58] started working on AtMega8515 module C1. --- avr/common/utils.asm | 18 + avr/devices/0BUILD | 1 + avr/devices/all/0BUILD | 1 + avr/devices/all/defs.asm | 3 +- avr/devices/all/hw_m8515.asm | 151 ++++++++ avr/devices/c01/.gitignore | 2 + avr/devices/c01/0BUILD | 22 ++ avr/devices/c01/README | 10 + avr/devices/c01/aqua_c01.xml | 11 + avr/devices/c01/boot/0BUILD | 32 ++ avr/devices/c01/boot/boot.asm | 163 ++++++++ avr/devices/c01/defs.asm | 108 ++++++ avr/devices/c01/main/0BUILD | 34 ++ avr/devices/c01/main/data.asm | 14 + avr/devices/c01/main/main.asm | 231 +++++++++++ avr/modules/flash/0BUILD | 2 + avr/modules/flash/eeprom.asm | 4 + avr/modules/flash/flash1p.asm | 11 + avr/modules/flash/flash1pmega.asm | 81 ++++ avr/modules/flash/flashprocess.asm | 1 + avr/modules/flash/flashxp.asm | 8 + avr/modules/flash/io_attn.asm | 41 ++ avr/modules/flash/io_bitbang.asm | 43 +- avr/modules/flash/io_uart.asm | 32 ++ avr/modules/flash/io_uart1.asm | 386 +----------------- avr/modules/flash/io_uart_all.asm | 387 ++++++++++++++++++ avr/modules/flash/io_uart_all_attn.asm | 495 ++++++++++++++++++++++++ avr/modules/uart_hw/comonuart0.asm | 15 +- avr/modules/uart_hw/m_lowlevel_uart.asm | 8 +- 29 files changed, 1893 insertions(+), 422 deletions(-) create mode 100644 avr/devices/all/hw_m8515.asm create mode 100644 avr/devices/c01/.gitignore create mode 100644 avr/devices/c01/0BUILD create mode 100644 avr/devices/c01/README create mode 100644 avr/devices/c01/aqua_c01.xml create mode 100644 avr/devices/c01/boot/0BUILD create mode 100644 avr/devices/c01/boot/boot.asm create mode 100644 avr/devices/c01/defs.asm create mode 100644 avr/devices/c01/main/0BUILD create mode 100644 avr/devices/c01/main/data.asm create mode 100644 avr/devices/c01/main/main.asm create mode 100644 avr/modules/flash/flash1pmega.asm create mode 100644 avr/modules/flash/io_uart.asm create mode 100644 avr/modules/flash/io_uart_all.asm create mode 100644 avr/modules/flash/io_uart_all_attn.asm diff --git a/avr/common/utils.asm b/avr/common/utils.asm index e297b9b..d8db6a8 100644 --- a/avr/common/utils.asm +++ b/avr/common/utils.asm @@ -269,7 +269,11 @@ Utils_IncrementCounter16: ; MODIFIED REGISTERS: R16 Utils_ReadEepromIncr: +.ifdef EEPE sbic EECR, EEPE ; wait for previous write to complete (if any) +.else + sbic EECR, EEWE ; wait for previous write to complete (if any) +.endif rjmp Utils_ReadEepromIncr out EEARH, xh ; set EEPROM address out EEARL, xl @@ -293,15 +297,29 @@ Utils_ReadEepromIncr: ; MODIFIED REGISTERS: R17 Utils_WriteEepromIncr: +.ifdef EEPE sbic EECR, EEPE ; wait for previous write to complete (if any) +.else + sbic EECR, EEWE ; wait for previous write to complete (if any) +.endif rjmp Utils_WriteEepromIncr +.ifdef EEPM1 ldi r17, (0< all + c01 n16 n21 n22 diff --git a/avr/devices/all/0BUILD b/avr/devices/all/0BUILD index b63c66d..72eda57 100644 --- a/avr/devices/all/0BUILD +++ b/avr/devices/all/0BUILD @@ -9,6 +9,7 @@ hw_tn84.asm hw_tn85.asm hw_tn841.asm + hw_m8515.asm includes.asm main.asm modules.asm diff --git a/avr/devices/all/defs.asm b/avr/devices/all/defs.asm index ae0861a..c3b0a1d 100644 --- a/avr/devices/all/defs.asm +++ b/avr/devices/all/defs.asm @@ -40,7 +40,8 @@ .equ EEPROM_OFFS_SEED = 10 ; 2 bytes -.equ EEPROM_OFFS_REED_CONF = 12 ; 1 byte (plus one byte reserved) +.equ EEPROM_OFFS_OSCCAL_SLOW = 12 ; 1 byte +.equ EEPROM_OFFS_OSCCAL_FAST = 13 ; 1 byte .equ EEPROM_OFFS_MAL_CONF_ONTIME = 14 ; 2 bytes .equ EEPROM_OFFS_MAL_CONF_SRC1_ADDR = 16 ; 1 byte diff --git a/avr/devices/all/hw_m8515.asm b/avr/devices/all/hw_m8515.asm new file mode 100644 index 0000000..8df7e0e --- /dev/null +++ b/avr/devices/all/hw_m8515.asm @@ -0,0 +1,151 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + +; Hardware routine for AtTiny 84 devices + + +.cseg + + +; --------------------------------------------------------------------------- +; @routine systemInitHardware +; + +systemInitHardware: + ; set all ports as inputs and enable internal pull-up resistors + ldi r16, 0xff + clr r17 +.ifdef PORTA + out DDRA, r17 ; all input + out PORTA, r16 ; enable pull-up on all +.endif + +.ifdef PORTB + out DDRB, r17 ; all input + out PORTB, r16 ; enable pull-up on all +.endif + +.ifdef PORTC + out DDRC, r17 ; all input + out PORTC, r16 ; enable pull-up on all +.endif + +.ifdef PORTD + out DDRD, r17 ; all input + out PORTD, r16 ; enable pull-up on all +.endif + +.ifdef PORTE + out DDRE, r17 ; all input + out PORTE, r16 ; enable pull-up on all +.endif + + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine systemSetSpeed +; + +systemSetSpeed: + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine systemSleep +; + +systemSleep: + ; only modify SE, SM2, SM1 and SM0 + cli + M_IO_READ r16, MCUCR + cbr r16, (1< + + + + + boot + main + + + + aqua_c01.xml + + + + defs.asm + README + + + + + + diff --git a/avr/devices/c01/README b/avr/devices/c01/README new file mode 100644 index 0000000..0513f8f --- /dev/null +++ b/avr/devices/c01/README @@ -0,0 +1,10 @@ + +C01 +=== + +- Role: Controller with Display +- MCU: AtMega 8515 +- Connection: RJ45 +- Periphery: + - Display with SPI + diff --git a/avr/devices/c01/aqua_c01.xml b/avr/devices/c01/aqua_c01.xml new file mode 100644 index 0000000..4ea15e0 --- /dev/null +++ b/avr/devices/c01/aqua_c01.xml @@ -0,0 +1,11 @@ + + + AQUA + N + 1 + + + + + + diff --git a/avr/devices/c01/boot/0BUILD b/avr/devices/c01/boot/0BUILD new file mode 100644 index 0000000..bfe939f --- /dev/null +++ b/avr/devices/c01/boot/0BUILD @@ -0,0 +1,32 @@ + + + + + + + + -I $(builddir) + -I $(srcdir) + -I $(topsrcdir)/avr + -I $(topbuilddir)/avr + + + + + boot.asm + + + + + + + + + + + + + + + + diff --git a/avr/devices/c01/boot/boot.asm b/avr/devices/c01/boot/boot.asm new file mode 100644 index 0000000..c681ea6 --- /dev/null +++ b/avr/devices/c01/boot/boot.asm @@ -0,0 +1,163 @@ +; *************************************************************************** +; Source file for base system node on AtMega 8515 +; +; This is for the maintenance system (i.e. the flash loader). +; +; All definitions and changes should go into this file. +; *************************************************************************** + +.equ clock=8000000 ; Define the clock frequency + +.nolist +.include "include/m8515def.inc" ; Define device ATmega8515 +.list + +.include "../defs.asm" +.include "defs_all.asm" + +.include "common/utils_wait.asm" +.include "common/utils_io.asm" +.include "modules/com2/defs.asm" +.include "modules/comproto/defs.asm" + + + +; *************************************************************************** +; defines + +; --------------------------------------------------------------------------- +; generic + + +.equ NET_BUFFERS_NUM = 6 +.equ NET_BUFFERS_SIZE = 32 + + + +; --------------------------------------------------------------------------- +; firmware settings + +.equ FIRMWARE_VERSION_MAJOR = 0 +.equ FIRMWARE_VERSION_MINOR = 0 +.equ FIRMWARE_VERSION_PATCHLEVEL = 1 + + + +; --------------------------------------------------------------------------- +; LED + +.equ LED_DDR = DDRE +.equ LED_PORT = PORTE +.equ LED_PIN = PINE +.equ LED_PINNUM = PORTE2 + + + + + +; *************************************************************************** +; code segment + +.cseg +.org 0x0000 + + + +; --------------------------------------------------------------------------- +; Reset and interrupt vectors + rjmp main ; 1: Reset vector RESET + reti ; 2: INT0 External Interrupt Request 0 + reti ; 3: INT1 External Interrupt Request 1 + reti ; 4: TIMER1_CAPT Timer/Counter1 Capture Event + reti ; 5: TIMER1_COMPA Timer/Counter1 Compare Match A + reti ; 6: TIMER1_COMPB Timer/Counter1 Compare Match B + reti ; 7: TIMER1_OVF Timer/Counter1 Overflow + reti ; 8: TIMER0_OVF Timer/Counter0 Overflow + reti ; 9: SPI_STC Serial Transfer Complete + reti ; 10: USART_RXC USART Rx Complete + reti ; 11: USART_UDRE USART Data Register Empty + reti ; 12: USART_TXC USART Tx Complete + reti ; 13: ANA_COMP Analog Comparator + reti ; 14: INT2 External Interrupt Request 2 + reti ; 15: TIMER0_COMP Timer/Counter0 Compare Match + reti ; 16: EE_RDY EEPROM Ready + reti ; 17: SPM_RDY Store Program Memory Ready + + + +; --------------------------------------------------------------------------- +; Device Info Block + +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_BOOT, FIRMWARE_VERSION_MAJOR + .db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL + +firmwareStart: + rjmp main ; will be overwritten when flashing + + + +; *************************************************************************** +; main code + + +.org BOOTLOADER_ADDR + + +main: + ldi r16, 0xb0 ; orig: a0 + out OSCCAL, r16 + rjmp bootLoader ; this routine is in modules/bootloader/main.asm + + + +; *************************************************************************** +; includes + +.include "common/utils_wait_fixed.asm" +.include "common/utils_copy_from_flash.asm" +.include "common/utils_copy_sdram.asm" + +.include "modules/flash/defs.asm" +.include "modules/flash/eeprom.asm" +.include "modules/flash/io.asm" +.include "modules/flash/io_attn.asm" +.include "modules/flash/io_uart.asm" +.include "modules/flash/io_uart_all_attn.asm" +.include "modules/flash/flash1pmega.asm" +.include "modules/flash/flashxp.asm" +.include "modules/flash/flashprocess.asm" +.include "modules/flash/wait.asm" +.include "modules/bootloader/main.asm" +.include "modules/network/msg/defs.asm" +.include "modules/network/msg/crc.asm" + +;.include "common/debug.asm" + + + +systemSetSpeed: +#if 0 ; disabled (can't really change clock at runtime) +.if clock == 8000000 + ldi r16, (1< + + + + + + + -I $(builddir) + -I $(srcdir) + -I $(topsrcdir)/avr + -I $(topbuilddir)/avr + + + + + main.asm + + + + + + + + + + + + data.asm + + + + + + diff --git a/avr/devices/c01/main/data.asm b/avr/devices/c01/main/data.asm new file mode 100644 index 0000000..31ccc2f --- /dev/null +++ b/avr/devices/c01/main/data.asm @@ -0,0 +1,14 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + + +.dseg + + diff --git a/avr/devices/c01/main/main.asm b/avr/devices/c01/main/main.asm new file mode 100644 index 0000000..15e8748 --- /dev/null +++ b/avr/devices/c01/main/main.asm @@ -0,0 +1,231 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + + + +; *************************************************************************** +; Source file for temperature sensor node on AtTiny 84 +; +; This is for the full system (i.e. not the boot loader). +; +; All definitions and changes should go into this file. +; +; +; *************************************************************************** + + +;.equ clock=1000000 ; Define the clock frequency +.equ clock=8000000 ; Define the clock frequency + + + +.nolist +.include "include/m8515def.inc" ; Define device ATmega8515 +.list + +.include "../defs.asm" +.include "./data.asm" + +.include "devices/all/defs.asm" +.include "common/utils_wait.asm" +.include "common/utils_io.asm" + + + +; *************************************************************************** +; defines + +; --------------------------------------------------------------------------- +; generic + +.equ NET_BUFFERS_NUM = 6 +.equ NET_BUFFERS_SIZE = 32 + +.equ PROGRAM_SENSOR_INTERVAL_SECS = 60 +.equ PROGRAM_STATS_INTERVAL_MINS = 10 + + + +; --------------------------------------------------------------------------- +; firmware settings including list of modules used + +.equ FIRMWARE_VERSION_MAJOR = 0 +.equ FIRMWARE_VERSION_MINOR = 0 +.equ FIRMWARE_VERSION_PATCHLEVEL = 1 + + +; #define MODULES_TIMER +;#define MODULES_CLOCK +#define MODULES_LED_SIMPLE +;#define MODULES_NETWORK +;#define MODULES_COMONUART0 +;#define MODULES_UART_BITBANG +;#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 + rjmp BOOTLOADER_ADDR ; 1: Reset vector RESET +; rjmp ComOnUart0_AttnChangeIsr ; 2: INT0 External Interrupt Request 0 + reti + reti ; 3: INT1 External Interrupt Request 1 + reti ; 4: TIMER1_CAPT Timer/Counter1 Capture Event + reti ; 5: TIMER1_COMPA Timer/Counter1 Compare Match A + reti ; 6: TIMER1_COMPB Timer/Counter1 Compare Match B + reti ; 7: TIMER1_OVF Timer/Counter1 Overflow + reti ; 8: TIMER0_OVF Timer/Counter0 Overflow + reti ; 9: SPI_STC Serial Transfer Complete +; rjmp ComOnUart0_RxCharIsr ; 10: USART_RXC USART Rx Complete + reti +; rjmp ComOnUart0_TxUdreIsr ; 11: USART_UDRE USART Data Register Empty + reti +; rjmp ComOnUart0_TxCharIsr ; 12: USART_TXC USART Tx Complete + reti + reti ; 13: ANA_COMP Analog Comparator + reti ; 14: INT2 External Interrupt Request 2 + rjmp baseTimerIrqOC0A ; 15: TIMER0_COMP Timer/Counter0 Compare Match + reti ; 16: EE_RDY EEPROM Ready + reti ; 17: 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 + + + +; --------------------------------------------------------------------------- +; @routine onSystemStart + +onSystemStart: + 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_m8515.asm" +.include "devices/all/includes.asm" + +.include "common/debug.asm" + + + +; --------------------------------------------------------------------------- +; defines for network interface + +;.equ netInterfaceData = comonuart0_iface + + + diff --git a/avr/modules/flash/0BUILD b/avr/modules/flash/0BUILD index 64d9cef..53f3762 100644 --- a/avr/modules/flash/0BUILD +++ b/avr/modules/flash/0BUILD @@ -12,7 +12,9 @@ io.asm io_attn.asm io_bitbang.asm + io_uart.asm io_uart1.asm + io_uart_all.asm wait.asm diff --git a/avr/modules/flash/eeprom.asm b/avr/modules/flash/eeprom.asm index 5c6f909..a215953 100644 --- a/avr/modules/flash/eeprom.asm +++ b/avr/modules/flash/eeprom.asm @@ -21,7 +21,11 @@ ; REGS: R16 flashReadEepromIncr: +.ifdef EEPE sbic EECR, EEPE ; wait for previous write to complete (if any) +.else + sbic EECR, EEWE ; wait for previous write to complete (if any) +.endif rjmp flashReadEepromIncr out EEARH, xh ; set EEPROM address out EEARL, xl diff --git a/avr/modules/flash/flash1p.asm b/avr/modules/flash/flash1p.asm index 9e64ffc..ba5c6c0 100644 --- a/avr/modules/flash/flash1p.asm +++ b/avr/modules/flash/flash1p.asm @@ -56,6 +56,17 @@ flash1pWritePages_loop: ; transfer data from temporary page buffer into FLASH memory ldi r20, (1< 7 per loop, max about 1000 - clc ; 1 - ret ; 4 -ioRawWaitForData_gotit: - sec ; 1 - ret ; 4 -; @end +.equ UART_REG_UDR = UDR1 +.equ UART_REG_UCSRA = UCSR1A +.equ UART_REG_UCSRB = UCSR1B +.equ UART_REG_UCSRC = UCSR1C +.equ UART_REG_UBRRL = UBRR1L +.equ UART_REG_UBRRH = UBRR1H + +.equ UART_BIT_UCSZ0 = UCSZ10 +.equ UART_BIT_UDRE = UDRE1 +.equ UART_BIT_RXC = RXC1 +.equ UART_BIT_TXC = TXC1 +.equ UART_BIT_FE = FE1 +.equ UART_BIT_DOR = DOR1 +.equ UART_BIT_UPE = UPE1 +.equ UART_BIT_RXEN = RXEN1 +.equ UART_BIT_TXEN = TXEN1 diff --git a/avr/modules/flash/io_uart_all.asm b/avr/modules/flash/io_uart_all.asm new file mode 100644 index 0000000..118d900 --- /dev/null +++ b/avr/modules/flash/io_uart_all.asm @@ -0,0 +1,387 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + +; *************************************************************************** +; code + + +.cseg + + +; --------------------------------------------------------------------------- +; @routine ioRawInit +; Send a message +; +; @clobbers r16, r17 + +ioRawInit: + ; set baudrate +.if clock == 8000000 + ldi r16, 25 ; (19.2Kb/s at 8MHz) + ldi r17, 0 +.endif + +.if clock == 1000000 + ldi r16, 3 ; (19.2Kb/s at 1MHz) + ldi r17, 0 +.endif + + sts UART_REG_UBRRH, r17 + sts UART_REG_UBRRL, r16 + + ; set character format (asynchronous USART, 8-bit, one stop bit, no parity) + ldi r16, (3< 7 per loop, max about 1000 + clc ; 1 + ret ; 4 +ioRawWaitForData_gotit: + sec ; 1 + ret ; 4 +; @end + + + + diff --git a/avr/modules/flash/io_uart_all_attn.asm b/avr/modules/flash/io_uart_all_attn.asm new file mode 100644 index 0000000..c503229 --- /dev/null +++ b/avr/modules/flash/io_uart_all_attn.asm @@ -0,0 +1,495 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + +; *************************************************************************** +; code + + +.cseg + + +; --------------------------------------------------------------------------- +; @routine ioRawInit +; Send a message +; +; @clobbers r16, r17 + +ioRawInit: + ; set baudrate +.if clock == 8000000 + ldi r16, 25 ; (19.2Kb/s at 8MHz) + ldi r17, 0 +.endif + +.if clock == 1000000 + ldi r16, 3 ; (19.2Kb/s at 1MHz) + ldi r17, 0 +.endif + + M_IO_WRITE UART_REG_UBRRH, r17 + M_IO_WRITE UART_REG_UBRRL, r16 + + ; set character format (asynchronous USART, 8-bit, one stop bit, no parity) + ldi r16, (1< 7 per loop, max about 1000 + clc ; 1 + ret ; 4 +ioRawWaitForData_gotit: + sec ; 1 + ret ; 4 +; @end + + + + diff --git a/avr/modules/uart_hw/comonuart0.asm b/avr/modules/uart_hw/comonuart0.asm index 60ebe7b..cc1e4ba 100644 --- a/avr/modules/uart_hw/comonuart0.asm +++ b/avr/modules/uart_hw/comonuart0.asm @@ -33,14 +33,19 @@ ComOnUart0_Init: rcall comOnUart0SetAttnInput ; (none) rcall UART_HW_Interface_Init ; (R16, R17, X) - rcall comOnUart0Init ; (R16, R17, X) + rcall comOnUart0Init ; (R16, R17, X) ldi r16, COMONUART0_IFACENUM std Y+NET_IFACE_OFFS_IFACENUM, r16 - sbi COM_IRQ_ADDR_ATTN, COM_IRQ_BIT_ATTN ; enable pin change irq for ATTN line - in r16, GIMSK ; enable pin change irq PCIE0 or PCIE1 - ori r16, (1< Date: Sat, 17 May 2025 10:51:04 +0200 Subject: [PATCH 12/58] t03: use new uart file. --- avr/devices/t03/boot/boot.asm | 1 + avr/devices/t03/defs.asm | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/avr/devices/t03/boot/boot.asm b/avr/devices/t03/boot/boot.asm index 1a83579..37a7147 100644 --- a/avr/devices/t03/boot/boot.asm +++ b/avr/devices/t03/boot/boot.asm @@ -131,6 +131,7 @@ main: .include "modules/flash/eeprom.asm" .include "modules/flash/io.asm" .include "modules/flash/io_uart1.asm" +.include "modules/flash/io_uart_all.asm" .include "modules/flash/flashxp.asm" .include "modules/flash/flash4p.asm" .include "modules/flash/flashprocess.asm" diff --git a/avr/devices/t03/defs.asm b/avr/devices/t03/defs.asm index 2b6374a..75a19f4 100644 --- a/avr/devices/t03/defs.asm +++ b/avr/devices/t03/defs.asm @@ -77,4 +77,9 @@ .equ OWI_PINNUM = PORTA7 +; --------------------------------------------------------------------------- +; ComOnUart module + +.equ USART0_DATAREG = UDR0 +.equ USART1_DATAREG = UDR1 From f8d3d097169ee1afe94253601805e3ebe32b2940 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 17 May 2025 10:51:21 +0200 Subject: [PATCH 13/58] n21: fixed README. --- avr/devices/n21/README | 1 + 1 file changed, 1 insertion(+) diff --git a/avr/devices/n21/README b/avr/devices/n21/README index 98c2591..55a3d2c 100644 --- a/avr/devices/n21/README +++ b/avr/devices/n21/README @@ -5,6 +5,7 @@ N21 - Role: Door sensor with temp and motion detection - MCU: AtTiny84 - Connection: RJ45 +- Predecessor: N16 - Periphery: - PIR sensor (AMN31112) - door sensor (TCRT1000) From 27a0214b5dc4925314e9f07379ff6d084624aab2 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 17 May 2025 13:16:46 +0200 Subject: [PATCH 14/58] removed old COM2 parts from code. --- avr/modules/flash/flashprocess.asm | 2 +- avr/modules/flash/io.asm | 6 +++--- avr/modules/network/msg/defs.asm | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/avr/modules/flash/flashprocess.asm b/avr/modules/flash/flashprocess.asm index dfc11a5..f6ca81e 100644 --- a/avr/modules/flash/flashprocess.asm +++ b/avr/modules/flash/flashprocess.asm @@ -277,7 +277,7 @@ flashProcessWriteFlashReady: st X+, r16 ; msg len ldi r16, NETMSG_CMD_FLASH_READY st X+, r16 ; msg code - ldi r16, COM2_MAINTENANCE_ADDR + ldi r16, NET_MAINTENANCE_ADDR st X+, r16 ; src address ; payload diff --git a/avr/modules/flash/io.asm b/avr/modules/flash/io.asm index 47b0428..54d59f3 100644 --- a/avr/modules/flash/io.asm +++ b/avr/modules/flash/io.asm @@ -35,12 +35,12 @@ ioWaitForGivenMsg_loop: brcc ioWaitForGivenMsg_loopEnd ldi xl, LOW(flashRecvBuffer) ldi xh, HIGH(flashRecvBuffer) - adiw xh:xl, COM2_MSG_OFFS_CMD + adiw xh:xl, NETMSG_OFFS_CMD ld r16, X - sbiw xh:xl, COM2_MSG_OFFS_CMD + sbiw xh:xl, NETMSG_OFFS_CMD cp r16, r17 breq ioWaitForGivenMsg_gotIt - cpi r16, CPRO_CMD_FLASH_END + cpi r16, NETMSG_CMD_FLASH_END breq ioWaitForGivenMsg_gotIt ioWaitForGivenMsg_loopEnd: mov r16, r17 ; move expected code back to r16 diff --git a/avr/modules/network/msg/defs.asm b/avr/modules/network/msg/defs.asm index 89d978e..e5b8c3d 100644 --- a/avr/modules/network/msg/defs.asm +++ b/avr/modules/network/msg/defs.asm @@ -63,6 +63,10 @@ +; --------------------------------------------------------------------------- +; special addresses + +.equ NET_MAINTENANCE_ADDR = 0xc1 From ea0d42643059fd5fd2cab85ffe413912c93c548d Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 17 May 2025 13:17:16 +0200 Subject: [PATCH 15/58] added definition for bit USBS --- avr/modules/flash/io_uart.asm | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/avr/modules/flash/io_uart.asm b/avr/modules/flash/io_uart.asm index 40abbac..d499109 100644 --- a/avr/modules/flash/io_uart.asm +++ b/avr/modules/flash/io_uart.asm @@ -8,23 +8,24 @@ ; *************************************************************************** -.equ UART_REG_UDR = UDR -.equ UART_REG_UCSRA = UCSRA -.equ UART_REG_UCSRB = UCSRB -.equ UART_REG_UCSRC = UCSRC -.equ UART_REG_UBRRL = UBRRL -.equ UART_REG_UBRRH = UBRRH +.equ UART_REG_UDR = UDR +.equ UART_REG_UCSRA = UCSRA +.equ UART_REG_UCSRB = UCSRB +.equ UART_REG_UCSRC = UCSRC +.equ UART_REG_UBRRL = UBRRL +.equ UART_REG_UBRRH = UBRRH -.equ UART_BIT_UCSZ0 = UCSZ0 -.equ UART_BIT_UCSZ1 = UCSZ1 -.equ UART_BIT_UDRE = UDRE -.equ UART_BIT_RXC = RXC -.equ UART_BIT_TXC = TXC -.equ UART_BIT_FE = FE -.equ UART_BIT_DOR = DOR -.equ UART_BIT_UPE = UPE -.equ UART_BIT_RXEN = RXEN -.equ UART_BIT_TXEN = TXEN +.equ UART_BIT_USBS = USBS +.equ UART_BIT_UCSZ0 = UCSZ0 +.equ UART_BIT_UCSZ1 = UCSZ1 +.equ UART_BIT_UDRE = UDRE +.equ UART_BIT_RXC = RXC +.equ UART_BIT_TXC = TXC +.equ UART_BIT_FE = FE +.equ UART_BIT_DOR = DOR +.equ UART_BIT_UPE = UPE +.equ UART_BIT_RXEN = RXEN +.equ UART_BIT_TXEN = TXEN From 10e4aa8f85f32e4c2e34e58159fd17a7014885a1 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 17 May 2025 13:18:50 +0200 Subject: [PATCH 16/58] fixed a problem with m8515 UART. UBRRH and UCSRC share the same io register location, bit URSEL needs to be set in order to access UCSRC!! --- avr/modules/flash/io_uart_all_attn.asm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/avr/modules/flash/io_uart_all_attn.asm b/avr/modules/flash/io_uart_all_attn.asm index c503229..740f3bc 100644 --- a/avr/modules/flash/io_uart_all_attn.asm +++ b/avr/modules/flash/io_uart_all_attn.asm @@ -37,8 +37,13 @@ ioRawInit: M_IO_WRITE UART_REG_UBRRL, r16 ; set character format (asynchronous USART, 8-bit, one stop bit, no parity) - ldi r16, (1< Date: Sat, 17 May 2025 13:19:54 +0200 Subject: [PATCH 17/58] consequently use M_IO_READ and M_IO_WRITE. on tn841 those are in the extended io space, on most others in normal io space. --- avr/modules/uart_hw/m_lowlevel_uart.asm | 58 +++++++++++++------------ 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/avr/modules/uart_hw/m_lowlevel_uart.asm b/avr/modules/uart_hw/m_lowlevel_uart.asm index 1985b1f..6e028c4 100644 --- a/avr/modules/uart_hw/m_lowlevel_uart.asm +++ b/avr/modules/uart_hw/m_lowlevel_uart.asm @@ -30,12 +30,16 @@ ldi r17, 0 .endif - sts UBRR@0H, r17 - sts UBRR@0L, r16 + M_IO_WRITE UBRR@0H, r17 + M_IO_WRITE UBRR@0L, r16 ; set character format +.ifdef URSEL + ldi r16, (1< Date: Sat, 17 May 2025 13:20:51 +0200 Subject: [PATCH 18/58] c01: enable more modules and apps. --- avr/devices/c01/main/main.asm | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/avr/devices/c01/main/main.asm b/avr/devices/c01/main/main.asm index 15e8748..494296f 100644 --- a/avr/devices/c01/main/main.asm +++ b/avr/devices/c01/main/main.asm @@ -64,8 +64,8 @@ ; #define MODULES_TIMER ;#define MODULES_CLOCK #define MODULES_LED_SIMPLE -;#define MODULES_NETWORK -;#define MODULES_COMONUART0 +#define MODULES_NETWORK +#define MODULES_COMONUART0 ;#define MODULES_UART_BITBANG ;#define MODULES_TWI_MASTER ;#define MODULES_LCD @@ -79,10 +79,10 @@ ;#define MODULES_MOTION ;#define MODULES_CCS811 -;#define APPS_NETWORK +#define APPS_NETWORK ;#define APPS_MOTION ;#define APPS_REPORTSENSORS -;#define APPS_STATS +#define APPS_STATS @@ -122,8 +122,7 @@ ; --------------------------------------------------------------------------- ; Reset and interrupt vectors rjmp BOOTLOADER_ADDR ; 1: Reset vector RESET -; rjmp ComOnUart0_AttnChangeIsr ; 2: INT0 External Interrupt Request 0 - reti + rjmp ComOnUart0_AttnChangeIsr ; 2: INT0 External Interrupt Request 0 reti ; 3: INT1 External Interrupt Request 1 reti ; 4: TIMER1_CAPT Timer/Counter1 Capture Event reti ; 5: TIMER1_COMPA Timer/Counter1 Compare Match A @@ -131,12 +130,9 @@ reti ; 7: TIMER1_OVF Timer/Counter1 Overflow reti ; 8: TIMER0_OVF Timer/Counter0 Overflow reti ; 9: SPI_STC Serial Transfer Complete -; rjmp ComOnUart0_RxCharIsr ; 10: USART_RXC USART Rx Complete - reti -; rjmp ComOnUart0_TxUdreIsr ; 11: USART_UDRE USART Data Register Empty - reti -; rjmp ComOnUart0_TxCharIsr ; 12: USART_TXC USART Tx Complete - reti + rjmp ComOnUart0_RxCharIsr ; 10: USART_RXC USART Rx Complete + rjmp ComOnUart0_TxUdreIsr ; 11: USART_UDRE USART Data Register Empty + rjmp ComOnUart0_TxCharIsr ; 12: USART_TXC USART Tx Complete reti ; 13: ANA_COMP Analog Comparator reti ; 14: INT2 External Interrupt Request 2 rjmp baseTimerIrqOC0A ; 15: TIMER0_COMP Timer/Counter0 Compare Match @@ -225,7 +221,7 @@ onEveryLoop: ; --------------------------------------------------------------------------- ; defines for network interface -;.equ netInterfaceData = comonuart0_iface +.equ netInterfaceData = comonuart0_iface From 2cc260790c7eee0577d87fa6f2db4e738d5aae73 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 17 May 2025 13:21:07 +0200 Subject: [PATCH 19/58] c01: removed unneeded code. --- avr/devices/c01/boot/boot.asm | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/avr/devices/c01/boot/boot.asm b/avr/devices/c01/boot/boot.asm index c681ea6..5b123b0 100644 --- a/avr/devices/c01/boot/boot.asm +++ b/avr/devices/c01/boot/boot.asm @@ -17,8 +17,6 @@ .include "common/utils_wait.asm" .include "common/utils_io.asm" -.include "modules/com2/defs.asm" -.include "modules/comproto/defs.asm" @@ -140,22 +138,7 @@ main: systemSetSpeed: -#if 0 ; disabled (can't really change clock at runtime) -.if clock == 8000000 - ldi r16, (1< Date: Sat, 17 May 2025 14:22:05 +0200 Subject: [PATCH 20/58] added memory stats. --- avr/apps/network/stats.asm | 21 +++++++++++++++++++++ avr/apps/stats/main.asm | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/avr/apps/network/stats.asm b/avr/apps/network/stats.asm index 3bb33bb..2b2d6bb 100644 --- a/avr/apps/network/stats.asm +++ b/avr/apps/network/stats.asm @@ -53,6 +53,27 @@ AppNetwork_SendRxdStats_end: +; --------------------------------------------------------------------------- +; @routine AppNetwork_SendRxdStats + +; @param Y network interface to work with +; @clobbers R16, X (R17, R18, R19, R20, R21, Z) + +AppNetwork_SendMemStats: + rcall NET_Buffer_Alloc ; (R16, R17, X) + brcc AppNetwork_SendMemStats_end + push r16 + adiw xh:xl, 1 + rcall NETMSG_MemStats_Write ; (R16, R17, R18, R19, R20, R21) + sbiw xh:xl, 1 + pop r16 + rcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X) +AppNetwork_SendMemStats_end: + ret +; @end + + + ; --------------------------------------------------------------------------- ; @routine AppNetwork_SendDevice diff --git a/avr/apps/stats/main.asm b/avr/apps/stats/main.asm index fb9bb75..a0d6c25 100644 --- a/avr/apps/stats/main.asm +++ b/avr/apps/stats/main.asm @@ -68,11 +68,15 @@ AppStats_OnEveryMinute_store: breq AppStats_OnEveryMinute_sendTxdStats cpi r16, 3 breq AppStats_OnEveryMinute_sendRxdStats + cpi r16, 4 + breq AppStats_OnEveryMinute_sendMemStats ret AppStats_OnEveryMinute_sendTxdStats: rjmp AppNetwork_SendTxdStats AppStats_OnEveryMinute_sendRxdStats: rjmp AppNetwork_SendRxdStats +AppStats_OnEveryMinute_sendMemStats: + rjmp AppNetwork_SendMemStats AppStats_OnEveryMinute_sendDevice: rjmp AppNetwork_SendDevice ; @end From 75b602811cc46c409dd17904484d80382805cfb1 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 17 May 2025 14:22:49 +0200 Subject: [PATCH 21/58] added XRAM module. Module for external SRAM with AtMega8515. --- avr/devices/all/includes.asm | 5 ++ avr/devices/all/modules.asm | 4 ++ avr/modules/0BUILD | 1 + avr/modules/xram/0BUILD | 11 ++++ avr/modules/xram/main.asm | 106 +++++++++++++++++++++++++++++++++++ 5 files changed, 127 insertions(+) create mode 100644 avr/modules/xram/0BUILD create mode 100644 avr/modules/xram/main.asm diff --git a/avr/devices/all/includes.asm b/avr/devices/all/includes.asm index 55160d6..b0cfb68 100644 --- a/avr/devices/all/includes.asm +++ b/avr/devices/all/includes.asm @@ -24,6 +24,10 @@ .include "modules/basetimer/main.asm" +#ifdef MODULES_XRAM +.include "modules/xram/main.asm" +#endif + #ifdef MODULES_NETWORK .include "common/crc8.asm" .include "common/m_fixedbuffers.asm" @@ -169,6 +173,7 @@ .include "apps/network/stats.asm" .include "modules/network/msg/sendstats-w.asm" .include "modules/network/msg/recvstats-w.asm" +.include "modules/network/msg/memstats-w.asm" .include "modules/network/msg/device-w.asm" #endif diff --git a/avr/devices/all/modules.asm b/avr/devices/all/modules.asm index 90a41f6..571a5f5 100644 --- a/avr/devices/all/modules.asm +++ b/avr/devices/all/modules.asm @@ -32,6 +32,10 @@ initModules: rcall Timer_Init #endif +#ifdef MODULES_XRAM + rcall XRAM_Init +#endif + #ifdef MODULES_LED ldi zl, LOW(ledA3Flash) ldi zh, HIGH(ledA3Flash) diff --git a/avr/modules/0BUILD b/avr/modules/0BUILD index 16da38b..dc51511 100644 --- a/avr/modules/0BUILD +++ b/avr/modules/0BUILD @@ -35,6 +35,7 @@ bootloader f_keepup valsched + xram diff --git a/avr/modules/xram/0BUILD b/avr/modules/xram/0BUILD new file mode 100644 index 0000000..febd367 --- /dev/null +++ b/avr/modules/xram/0BUILD @@ -0,0 +1,11 @@ + + + + + + main.asm + + + + + diff --git a/avr/modules/xram/main.asm b/avr/modules/xram/main.asm new file mode 100644 index 0000000..44cd65e --- /dev/null +++ b/avr/modules/xram/main.asm @@ -0,0 +1,106 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + +; *************************************************************************** +; defines + + + +; *************************************************************************** +; data + +.dseg + +xramLastAddress: .byte 2 + + + + + +; *************************************************************************** +; code + +.cseg + + + +; --------------------------------------------------------------------------- +; @routine XRAM_Init @global +; + +XRAM_Init: + clr r16 + sts xramLastAddress, r16 + sts xramLastAddress+1, r16 + + M_IO_READ r16, MCUCR + sbr r16, (1< Date: Sat, 17 May 2025 14:23:10 +0200 Subject: [PATCH 22/58] c01: use modules CLOCK and XRAM. --- avr/devices/c01/main/main.asm | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/avr/devices/c01/main/main.asm b/avr/devices/c01/main/main.asm index 494296f..7f11e37 100644 --- a/avr/devices/c01/main/main.asm +++ b/avr/devices/c01/main/main.asm @@ -7,20 +7,6 @@ ; * Please see toplevel file COPYING of that project for license details. * ; *************************************************************************** - - - -; *************************************************************************** -; Source file for temperature sensor node on AtTiny 84 -; -; This is for the full system (i.e. not the boot loader). -; -; All definitions and changes should go into this file. -; -; -; *************************************************************************** - - ;.equ clock=1000000 ; Define the clock frequency .equ clock=8000000 ; Define the clock frequency @@ -45,11 +31,9 @@ ; --------------------------------------------------------------------------- ; generic -.equ NET_BUFFERS_NUM = 6 -.equ NET_BUFFERS_SIZE = 32 +.equ NET_BUFFERS_NUM = 6 +.equ NET_BUFFERS_SIZE = 32 -.equ PROGRAM_SENSOR_INTERVAL_SECS = 60 -.equ PROGRAM_STATS_INTERVAL_MINS = 10 @@ -62,7 +46,8 @@ ; #define MODULES_TIMER -;#define MODULES_CLOCK +#define MODULES_CLOCK +#define MODULES_XRAM #define MODULES_LED_SIMPLE #define MODULES_NETWORK #define MODULES_COMONUART0 From 613a7e629d2c21610d44880cab710e1e1e5a583d Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 17 May 2025 14:23:24 +0200 Subject: [PATCH 23/58] remove unneeded includes. --- avr/devices/t03/boot/boot.asm | 2 -- 1 file changed, 2 deletions(-) diff --git a/avr/devices/t03/boot/boot.asm b/avr/devices/t03/boot/boot.asm index 37a7147..2e59e88 100644 --- a/avr/devices/t03/boot/boot.asm +++ b/avr/devices/t03/boot/boot.asm @@ -25,8 +25,6 @@ ; generic .include "common/utils_wait.asm" -.include "modules/com2/defs.asm" -.include "modules/comproto/defs.asm" From e713711a6107d27b3d957791156a8511edf8e4fc Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 17 May 2025 14:23:34 +0200 Subject: [PATCH 24/58] added missing includes. --- avr/devices/t03/main/main.asm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/avr/devices/t03/main/main.asm b/avr/devices/t03/main/main.asm index 6fdd478..a37e92f 100644 --- a/avr/devices/t03/main/main.asm +++ b/avr/devices/t03/main/main.asm @@ -32,6 +32,9 @@ .include "../defs.asm" .include "defs_all.asm" +.include "common/utils_wait.asm" +.include "common/utils_io.asm" + ; *************************************************************************** @@ -41,9 +44,6 @@ ; generic -.include "common/utils_wait.asm" - - ; --------------------------------------------------------------------------- ; firmware settings including list of modules used From 550967c176e606fc0345d18d36224fcc763b3da1 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 17 May 2025 14:24:04 +0200 Subject: [PATCH 25/58] memstats: send XRAM size instead of stack size. --- avr/modules/network/msg/memstats-w.asm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/avr/modules/network/msg/memstats-w.asm b/avr/modules/network/msg/memstats-w.asm index 00ac3a0..7317936 100644 --- a/avr/modules/network/msg/memstats-w.asm +++ b/avr/modules/network/msg/memstats-w.asm @@ -35,6 +35,12 @@ NETMSG_MemStats_Write: st X+, r16 st X+, r16 ; stack used +.ifdef MODULES_XRAM + lds r20, xramLastAddress + lds r21, xramLastAddress+1 + st X+, r20 + st X+, r21 +.else ldi r20, LOW(RAMEND) ldi r21, HIGH(RAMEND) in r17, SPL @@ -43,6 +49,7 @@ NETMSG_MemStats_Write: in r17, SPH sbc r21, r17 st X+, r21 +.endif ; current buffers used push xl push xh From 44b8848996b6c2590a7bcce94f7d529f95111da9 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 17 May 2025 14:24:23 +0200 Subject: [PATCH 26/58] minor beautifications. --- avr/devices/all/hw_m8515.asm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/avr/devices/all/hw_m8515.asm b/avr/devices/all/hw_m8515.asm index 8df7e0e..040bc8e 100644 --- a/avr/devices/all/hw_m8515.asm +++ b/avr/devices/all/hw_m8515.asm @@ -68,20 +68,27 @@ systemSetSpeed: systemSleep: ; only modify SE, SM2, SM1 and SM0 cli + M_IO_READ r16, MCUCR cbr r16, (1< Date: Sun, 18 May 2025 00:56:43 +0200 Subject: [PATCH 27/58] fixed apidoc. --- avr/common/ringbuffer_y.asm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avr/common/ringbuffer_y.asm b/avr/common/ringbuffer_y.asm index 7eba828..e4e2ec9 100644 --- a/avr/common/ringbuffer_y.asm +++ b/avr/common/ringbuffer_y.asm @@ -119,7 +119,7 @@ RingBufferY_Reset: ; @routine RingBufferY_ReadByteGuarded ; ; @return CFLAG on success, cleared on error -; @param r16 byte to write +; @return r16 byte read ; @param Y pointer to start of interface data ; @clobbers R17, R18, X From 4b4753415a482f86e1a913cb45f8c100b02eceaa Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sun, 18 May 2025 00:57:03 +0200 Subject: [PATCH 28/58] sort order of stats messages. --- avr/apps/stats/main.asm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/avr/apps/stats/main.asm b/avr/apps/stats/main.asm index a0d6c25..f3f8f5f 100644 --- a/avr/apps/stats/main.asm +++ b/avr/apps/stats/main.asm @@ -63,11 +63,11 @@ AppStats_OnEveryMinute_store: ldi yl, LOW(netInterfaceData) ldi yh, HIGH(netInterfaceData) cpi r16, 1 - breq AppStats_OnEveryMinute_sendDevice + breq AppStats_OnEveryMinute_sendRxdStats cpi r16, 2 breq AppStats_OnEveryMinute_sendTxdStats cpi r16, 3 - breq AppStats_OnEveryMinute_sendRxdStats + breq AppStats_OnEveryMinute_sendDevice cpi r16, 4 breq AppStats_OnEveryMinute_sendMemStats ret From b8fbbb71252b3ec229ae3ddf1227b7b2f9ff1d38 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sun, 18 May 2025 00:57:39 +0200 Subject: [PATCH 29/58] remove COM_* code. --- avr/devices/n23/boot/boot.asm | 2 -- avr/modules/flash/io_bitbang.asm | 47 ++++++++++++-------------------- 2 files changed, 17 insertions(+), 32 deletions(-) diff --git a/avr/devices/n23/boot/boot.asm b/avr/devices/n23/boot/boot.asm index 7d74df3..807f5c3 100644 --- a/avr/devices/n23/boot/boot.asm +++ b/avr/devices/n23/boot/boot.asm @@ -27,8 +27,6 @@ ; generic .include "common/utils_wait.asm" -.include "modules/com2/defs.asm" -.include "modules/comproto/defs.asm" diff --git a/avr/modules/flash/io_bitbang.asm b/avr/modules/flash/io_bitbang.asm index a70d919..1dd5039 100644 --- a/avr/modules/flash/io_bitbang.asm +++ b/avr/modules/flash/io_bitbang.asm @@ -140,7 +140,7 @@ ioRawWaitForValidMsg: ioRawWaitForValidMsg_attnLow: ldi xl, LOW(flashRecvBuffer) ldi xh, HIGH(flashRecvBuffer) - ldi r16, COM2_MAINTENANCE_ADDR + ldi r16, NET_MAINTENANCE_ADDR ldi r17, FLASH_RECVBUFFER_MAXLEN-3 rcall ioRawReceivePacketIntoBuffer brcs ioRawWaitForValidMsg_packetReceived @@ -174,7 +174,6 @@ ioRawWaitForValidMsg_end: ; @param R17 maximum value for accepted msg data (i.e. buffersize minus 3) ; @param X buffer to receive to ; @return CFLAG set if okay (packet received), cleared on error -; @return R16 error code if CFLAG is cleared (COM2_ERROR_NOTFORME, COM2_ERROR_IOERROR, COM2_ERROR_DATAERROR) ; @clobbers: r16, r17, r18, X (r19, r20, r21, r22) ioRawReceivePacketIntoBuffer: @@ -183,7 +182,7 @@ ioRawReceivePacketIntoBuffer: ; read destination address rcall ioRawReceiveByte ; read byte (R16, R17, R20, R21, R22) pop r17 ; pop from R16 to R17 - brcc ioRawReceivePacketIntoBuffer_ioError + brcc ioRawReceivePacketIntoBuffer_error #ifndef COM_ACCEPT_ALL_DEST ; accept every destination address ; compare destination address (accept "FF" and own address) cp r16, r17 @@ -197,27 +196,22 @@ ioRawReceivePacketIntoBuffer_acceptAddr: st X+, r16 ; store dest address, lock buffer ; read msg length rcall ioRawReceiveByte ; read packet length (R16, R17, R20, R21, R22) - brcc ioRawReceivePacketIntoBuffer_ioError + brcc ioRawReceivePacketIntoBuffer_error st X+, r16 cp r16, r18 ; (COM2_BUFFER_SIZE-3) - brcc ioRawReceivePacketIntoBuffer_contentError ; packet too long + brcc ioRawReceivePacketIntoBuffer_error ; packet too long inc r16 ; account for checksum byte mov r17, r16 ioRawReceivePacketIntoBuffer_loop: push r17 rcall ioRawReceiveByte ; read byte (R16, R17, R20, R21, R22) pop r17 - brcc ioRawReceivePacketIntoBuffer_ioError + brcc ioRawReceivePacketIntoBuffer_error st X+, r16 dec r17 brne ioRawReceivePacketIntoBuffer_loop sec ret -ioRawReceivePacketIntoBuffer_ioError: - ldi r16, COM2_ERROR_IOERROR - rjmp ioRawReceivePacketIntoBuffer_error -ioRawReceivePacketIntoBuffer_contentError: - ldi r16, COM2_ERROR_DATAERROR ioRawReceivePacketIntoBuffer_error: clc ret @@ -281,36 +275,29 @@ ioRawReceiveByte_error: ; @clobbers R16, R22 (R17, R21, X) ioRawSendPacket: - rcall ioRawAcquireBus ; (none) - brcc ioRawSendPacket_lineBusyError + rcall ioRawAcquireBus ; (none) + brcc ioRawSendPacket_ret - rcall ioRawWaitForOneBitLength ; wait for one bit duration (R22) - rcall ioRawWaitForOneBitLength ; wait for one bit duration (R22) + rcall ioRawWaitForOneBitLength ; wait for one bit duration (R22) + rcall ioRawWaitForOneBitLength ; wait for one bit duration (R22) - adiw xh:xl, COM2_MSG_OFFS_MSGLEN + adiw xh:xl, NETMSG_OFFS_MSGLEN ld r17, X - sbiw xh:xl, COM2_MSG_OFFS_MSGLEN - inc r17 ; account for dest addr - inc r17 ; account for msglen byte - inc r17 ; account for crc byte + sbiw xh:xl, NETMSG_OFFS_MSGLEN + inc r17 ; account for dest addr + inc r17 ; account for msglen byte + inc r17 ; account for crc byte ioRawSendPacket_loop: ld r16, X+ - rcall ioRawSendByte ; send byte (R16, R21, R22) + rcall ioRawSendByte ; send byte (R16, R21, R22) brcc ioRawSendPacket_releaseBusRet dec r17 brne ioRawSendPacket_loop sec ioRawSendPacket_releaseBusRet: - cbi COM_ATTN_DDR, COM_ATTN_PIN ; release ATTN line (by setting direction to IN) - brcc ioRawSendPacket_ioError - ; packet successfully sent - ret -ioRawSendPacket_ioError: - ldi r16,COM2_ERROR_COLLISION - ret -ioRawSendPacket_lineBusyError: - ldi r16,COM2_ERROR_BUSY + cbi COM_ATTN_DDR, COM_ATTN_PIN ; release ATTN line (by setting direction to IN) +ioRawSendPacket_ret: ret ; @end From b6800e538d1c560eb2e3665c78bd30002dd87ec0 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sun, 18 May 2025 00:58:46 +0200 Subject: [PATCH 30/58] tried some fixes... --- avr/modules/uart_hw/comonuart0.asm | 72 +++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 5 deletions(-) diff --git a/avr/modules/uart_hw/comonuart0.asm b/avr/modules/uart_hw/comonuart0.asm index cc1e4ba..5133005 100644 --- a/avr/modules/uart_hw/comonuart0.asm +++ b/avr/modules/uart_hw/comonuart0.asm @@ -30,22 +30,32 @@ comOnUart0_iface: .byte UART_HW_IFACE_SIZE ComOnUart0_Init: ldi yl, LOW(comOnUart0_iface) ldi yh, HIGH(comOnUart0_iface) - rcall comOnUart0SetAttnInput ; (none) + rcall comOnUart0SetAttnInput ; (none) rcall UART_HW_Interface_Init ; (R16, R17, X) rcall comOnUart0Init ; (R16, R17, X) ldi r16, COMONUART0_IFACENUM std Y+NET_IFACE_OFFS_IFACENUM, r16 +.if COM_IRQ_BIT_ATTN == INT0 + M_IO_READ r16, MCUCR + cbr r16, (1< Date: Sun, 18 May 2025 00:59:19 +0200 Subject: [PATCH 31/58] try new implementation of UART code for m8515. --- avr/devices/all/includes.asm | 9 + avr/devices/all/main.asm | 4 + avr/devices/all/modules.asm | 8 + avr/devices/c01/defs.asm | 2 +- avr/devices/c01/main/main.asm | 17 +- avr/modules/uart_hw/attn.asm | 102 ++++++ avr/modules/uart_hw/lowlevel.asm | 1 + avr/modules/uart_hw/m_lowlevel_uart.asm | 88 ++++++ avr/modules/uart_hw/net_uart.asm | 240 ++++++++++++++ avr/modules/uart_hw/uart.asm | 398 ++++++++++++++++++++++++ 10 files changed, 861 insertions(+), 8 deletions(-) create mode 100644 avr/modules/uart_hw/attn.asm create mode 100644 avr/modules/uart_hw/net_uart.asm create mode 100644 avr/modules/uart_hw/uart.asm diff --git a/avr/devices/all/includes.asm b/avr/devices/all/includes.asm index b0cfb68..c76ac9a 100644 --- a/avr/devices/all/includes.asm +++ b/avr/devices/all/includes.asm @@ -53,6 +53,15 @@ .include "modules/uart_bitbang2/lowlevel.asm" #endif +#ifdef MODULES_UART_HW +.include "modules/uart_hw/defs.asm" +.include "modules/uart_hw/lowlevel.asm" +.include "modules/uart_hw/uart.asm" +.include "modules/uart_hw/attn.asm" +.include "modules/uart_hw/net_uart.asm" +#endif + + #ifdef MODULES_COMONUART0 .include "modules/uart_hw/defs.asm" .include "modules/uart_hw/lowlevel.asm" diff --git a/avr/devices/all/main.asm b/avr/devices/all/main.asm index c86ffe4..adad9ec 100644 --- a/avr/devices/all/main.asm +++ b/avr/devices/all/main.asm @@ -94,6 +94,10 @@ onSystemTimerTick: rcall UART_BitBang_Every100ms #endif +#ifdef MODULES_UART_HW + rcall NET_Uart_Periodically +#endif + #ifdef MODULES_TTYONUART1 rcall TtyOnUart1_Periodically #endif diff --git a/avr/devices/all/modules.asm b/avr/devices/all/modules.asm index 571a5f5..0e5249b 100644 --- a/avr/devices/all/modules.asm +++ b/avr/devices/all/modules.asm @@ -61,6 +61,10 @@ initModules: rcall UART_BitBang_Init #endif +#ifdef MODULES_UART_HW + rcall NET_Uart_Init +#endif + #ifdef MODULES_TTYONUART1 rcall TtyOnUart1_Init #endif @@ -165,6 +169,10 @@ runModules_Com: runModules_ComEnd: #endif +#ifdef MODULES_UART_HW + rcall NET_Uart_Run +#endif + #ifdef MODULES_TTYONUART1 rcall TtyOnUart1_Run #endif diff --git a/avr/devices/c01/defs.asm b/avr/devices/c01/defs.asm index 6df1f40..46aee57 100644 --- a/avr/devices/c01/defs.asm +++ b/avr/devices/c01/defs.asm @@ -84,7 +84,7 @@ ; --------------------------------------------------------------------------- ; ComOnUart module -.equ USART0_DATAREG = UDR +.equ USART0_DATAREG = UDR .equ UCSR0A = UCSRA .equ UCSR0B = UCSRB .equ UCSR0C = UCSRC diff --git a/avr/devices/c01/main/main.asm b/avr/devices/c01/main/main.asm index 7f11e37..9b66edf 100644 --- a/avr/devices/c01/main/main.asm +++ b/avr/devices/c01/main/main.asm @@ -31,7 +31,7 @@ ; --------------------------------------------------------------------------- ; generic -.equ NET_BUFFERS_NUM = 6 +.equ NET_BUFFERS_NUM = 8 .equ NET_BUFFERS_SIZE = 32 @@ -50,7 +50,9 @@ #define MODULES_XRAM #define MODULES_LED_SIMPLE #define MODULES_NETWORK -#define MODULES_COMONUART0 +;#define MODULES_COMONUART0 +#define MODULES_UART_HW + ;#define MODULES_UART_BITBANG ;#define MODULES_TWI_MASTER ;#define MODULES_LCD @@ -107,7 +109,8 @@ ; --------------------------------------------------------------------------- ; Reset and interrupt vectors rjmp BOOTLOADER_ADDR ; 1: Reset vector RESET - rjmp ComOnUart0_AttnChangeIsr ; 2: INT0 External Interrupt Request 0 +; rjmp ComOnUart0_AttnChangeIsr ; 2: INT0 External Interrupt Request 0 + reti reti ; 3: INT1 External Interrupt Request 1 reti ; 4: TIMER1_CAPT Timer/Counter1 Capture Event reti ; 5: TIMER1_COMPA Timer/Counter1 Compare Match A @@ -115,9 +118,9 @@ reti ; 7: TIMER1_OVF Timer/Counter1 Overflow reti ; 8: TIMER0_OVF Timer/Counter0 Overflow reti ; 9: SPI_STC Serial Transfer Complete - rjmp ComOnUart0_RxCharIsr ; 10: USART_RXC USART Rx Complete - rjmp ComOnUart0_TxUdreIsr ; 11: USART_UDRE USART Data Register Empty - rjmp ComOnUart0_TxCharIsr ; 12: USART_TXC USART Tx Complete + rjmp Uart_RxCharIsr ; 10: USART_RXC USART Rx Complete + rjmp Uart_UdreIsr ; 11: USART_UDRE USART Data Register Empty + rjmp Uart_TxCharIsr ; 12: USART_TXC USART Tx Complete reti ; 13: ANA_COMP Analog Comparator reti ; 14: INT2 External Interrupt Request 2 rjmp baseTimerIrqOC0A ; 15: TIMER0_COMP Timer/Counter0 Compare Match @@ -206,7 +209,7 @@ onEveryLoop: ; --------------------------------------------------------------------------- ; defines for network interface -.equ netInterfaceData = comonuart0_iface +.equ netInterfaceData = netUartIface diff --git a/avr/modules/uart_hw/attn.asm b/avr/modules/uart_hw/attn.asm new file mode 100644 index 0000000..6217f57 --- /dev/null +++ b/avr/modules/uart_hw/attn.asm @@ -0,0 +1,102 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + + +; *************************************************************************** +; code + +.cseg + + +; --------------------------------------------------------------------------- +; @routine ATTN_Init @global +; +; @clobbers R16 + +ATTN_Init: +.ifdef INT0 + .if COM_IRQ_BIT_ATTN == INT0 + M_IO_READ r16, MCUCR + cbr r16, (1< Date: Sun, 18 May 2025 01:04:15 +0200 Subject: [PATCH 32/58] increased buffer size. --- avr/modules/uart_hw/uart.asm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avr/modules/uart_hw/uart.asm b/avr/modules/uart_hw/uart.asm index 9141093..b170dfe 100644 --- a/avr/modules/uart_hw/uart.asm +++ b/avr/modules/uart_hw/uart.asm @@ -13,7 +13,7 @@ .equ UART_RINGBUFFER_IN_SIZE = 24 -.equ UART_RINGBUFFER_OUT_SIZE = 24 +.equ UART_RINGBUFFER_OUT_SIZE = 32 .equ UART_FLAGS_TXEN_BIT = 7 From 8ece026f2dafe6eaefae39dece781a1a858b5df6 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Tue, 20 May 2025 00:29:45 +0200 Subject: [PATCH 33/58] Add wait routines for milliseconds. --- avr/common/utils_wait_fixed.asm | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/avr/common/utils_wait_fixed.asm b/avr/common/utils_wait_fixed.asm index 9be3aba..f94569c 100644 --- a/avr/common/utils_wait_fixed.asm +++ b/avr/common/utils_wait_fixed.asm @@ -53,4 +53,41 @@ Utils_WaitFor100MicroSecs: +; --------------------------------------------------------------------------- +; @routine Utils_WaitFor1MilliSec @global +; +; wait for about 1ms. +; +; @clobbers r22 + +Utils_WaitFor1MilliSec: + push r21 + ldi r21, 10 +Utils_WaitFor1MilliSec_loop: + rcall Utils_WaitFor100MicroSecs ; (R22) + dec r21 + brne Utils_WaitFor1MilliSec_loop + pop r21 + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine Utils_WaitForMilliSecs @global +; +; wait for given amount of milliseconds +; @param r16 number of millisecs to wait +; @clobbers r22 + +Utils_WaitForMilliSecs: + rcall Utils_WaitFor100MicroSecs ; (R22) + dec r16 + brne Utils_WaitForMilliSecs + ret +; @end + + + + From aceffdfad21e3b2dd43b611c12cf4d0aeb1f7213 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Tue, 20 May 2025 00:30:39 +0200 Subject: [PATCH 34/58] uart_hw: removed unneeded code. --- avr/devices/all/main.asm | 2 +- avr/devices/c01/main/main.asm | 14 +- avr/modules/uart_hw/net_uart.asm | 337 ++++++++++++---------- avr/modules/uart_hw/uart.asm | 465 ++++++++++++------------------- 4 files changed, 377 insertions(+), 441 deletions(-) diff --git a/avr/devices/all/main.asm b/avr/devices/all/main.asm index adad9ec..31ed484 100644 --- a/avr/devices/all/main.asm +++ b/avr/devices/all/main.asm @@ -95,7 +95,7 @@ onSystemTimerTick: #endif #ifdef MODULES_UART_HW - rcall NET_Uart_Periodically + rcall NET_Uart_Every100ms #endif #ifdef MODULES_TTYONUART1 diff --git a/avr/devices/c01/main/main.asm b/avr/devices/c01/main/main.asm index 9b66edf..0ee6818 100644 --- a/avr/devices/c01/main/main.asm +++ b/avr/devices/c01/main/main.asm @@ -52,7 +52,8 @@ #define MODULES_NETWORK ;#define MODULES_COMONUART0 #define MODULES_UART_HW - +#define MODULES_SPI_HW +#define MODULES_ILI9341 ;#define MODULES_UART_BITBANG ;#define MODULES_TWI_MASTER ;#define MODULES_LCD @@ -109,8 +110,7 @@ ; --------------------------------------------------------------------------- ; Reset and interrupt vectors rjmp BOOTLOADER_ADDR ; 1: Reset vector RESET -; rjmp ComOnUart0_AttnChangeIsr ; 2: INT0 External Interrupt Request 0 - reti + rjmp NetUart_AttnChangeIsr ; 2: INT0 External Interrupt Request 0 reti ; 3: INT1 External Interrupt Request 1 reti ; 4: TIMER1_CAPT Timer/Counter1 Capture Event reti ; 5: TIMER1_COMPA Timer/Counter1 Compare Match A @@ -118,9 +118,9 @@ reti ; 7: TIMER1_OVF Timer/Counter1 Overflow reti ; 8: TIMER0_OVF Timer/Counter0 Overflow reti ; 9: SPI_STC Serial Transfer Complete - rjmp Uart_RxCharIsr ; 10: USART_RXC USART Rx Complete - rjmp Uart_UdreIsr ; 11: USART_UDRE USART Data Register Empty - rjmp Uart_TxCharIsr ; 12: USART_TXC USART Tx Complete + reti ; 10: USART_RXC USART Rx Complete + reti ; 11: USART_UDRE USART Data Register Empty + reti ; 12: USART_TXC USART Tx Complete reti ; 13: ANA_COMP Analog Comparator reti ; 14: INT2 External Interrupt Request 2 rjmp baseTimerIrqOC0A ; 15: TIMER0_COMP Timer/Counter0 Compare Match @@ -202,7 +202,7 @@ onEveryLoop: .include "devices/all/hw_m8515.asm" .include "devices/all/includes.asm" -.include "common/debug.asm" +;.include "common/debug.asm" diff --git a/avr/modules/uart_hw/net_uart.asm b/avr/modules/uart_hw/net_uart.asm index 022906b..6f9b872 100644 --- a/avr/modules/uart_hw/net_uart.asm +++ b/avr/modules/uart_hw/net_uart.asm @@ -11,7 +11,6 @@ ; *************************************************************************** ; defines -.equ NET_UART_MSG_INTERVAL = 1 @@ -46,195 +45,229 @@ NET_Uart_Init: -; --------------------------------------------------------------------------- -; @routine NET_Uart_Run @global -; -; @clobbers all - -NET_Uart_Run: - push r15 - in r15, SREG - cli - ldi yl, LOW(netUartIface) - ldi yh, HIGH(netUartIface) - rcall netUartRunReadModes - ldd r16, Y+UART_HW_IFACE_OFFS_READMODE ; test for active read mode - cpi r16, UART_HW_READMODE_IDLE - brne NET_Uart_Run_end - rcall netUartRunWriteModes ; only call write routine if read idle -NET_Uart_Run_end: - pop r15 - out SREG, r15 - ret -; @end - - - ; --------------------------------------------------------------------------- ; @routine NET_Uart_Periodically ; ; @clobbers all, !Y -NET_Uart_Periodically: +NET_Uart_Every100ms: ldi yl, LOW(netUartIface) ldi yh, HIGH(netUartIface) + push r15 + in r15, SREG + cli + rcall NET_Interface_Periodically ; (R16) + rcall netUartSendNextPkg + out SREG, r15 + pop r15 + ret rjmp NET_Interface_Periodically ; @end +; --------------------------------------------------------------------------- +; @routine netUartSendNextPkg +; +; Check whether there is an outgoing message in interface data +; and send it if possible. +; +; @return CFLAG set if okay, clear on error +; @param Y pointer to start of interface data +; @clobbers R16, R17, R18, R21, R21, R24, R25, X + +netUartSendNextPkg: + rcall NET_Interface_PeekNextOutgoingMsgNum ; (R17, R18, X) + brcc netUartSendNextPkg_end + rcall NET_Buffer_Locate ; get pointer to buffer (R17) + brcc netUartSendNextPkg_end + adiw xh:xl, 1 ; skip buffer header + rcall netUartSendPacketWithAttn ; (R16, R17, R21, R22, X) + brcc netUartSendNextPkg_error + rcall NET_Interface_GetNextOutgoingMsgNum ; remove from stack (R17, R18, X) + rcall NET_Buffer_ReleaseByNum ; release buffer (R16, X) + ldi r16, NET_IFACE_OFFS_PACKETSOUT_LOW + rcall NET_Interface_IncCounter16 ; (R24, R25) + sec + rjmp netUartSendNextPkg_end +netUartSendNextPkg_error: + rcall NET_Interface_IncCounter16 ; (R24, R25) + clc +netUartSendNextPkg_end: + ret +; @end + + ; --------------------------------------------------------------------------- -; @routine netUartRunWriteModes +; @routine netUartSendPacket ; -; @clobbers all, !Y +; @param X buffer to send +; @return CFLAG set if okay, cleared on error +; @return R16 error code (if CFLAG cleared) +; @clobbers R16, R17, R22, X -netUartRunWriteModes: - ldd r16, Y+UART_HW_IFACE_OFFS_WRITEMODE ; handle write functions - cpi r16, UART_HW_WRITEMODE_IDLE - breq netUartRunWriteIdle - cpi r16, UART_HW_WRITEMODE_WRITING - breq netUartRunWriting - cpi r16, UART_HW_WRITEMODE_WAITBUFFEREMPTY - breq netUartRunWaitBufferEmpty - cpi r16, UART_HW_WRITEMODE_WRITEBUFFEREMPTY - breq netUartRunWriteBufferEmpty - ret -; @end - - - -netUartRunWaitBufferEmpty: - rcall UART_GetFlags ; (none) - ldi r17, (1< 7 per loop, max about 1000 + clc ; 1 + ret ; 4 +uartWaitForData_gotit: + sec ; 1 + ret ; 4 +; @end + + + + + ; --------------------------------------------------------------------------- ; @routine UART_StartRx @global ; ; @clobbers R16 UART_StartRx: - ; clear read error flags - lds r16, uartFlags - cbr r16, (1< Date: Tue, 20 May 2025 00:31:56 +0200 Subject: [PATCH 35/58] avr: started working on new LCD module and SPI module. --- avr/devices/all/includes.asm | 12 + avr/devices/all/modules.asm | 13 +- avr/devices/c01/defs.asm | 62 +++ avr/modules/lcd2/ili9341/0BUILD | 11 + avr/modules/lcd2/ili9341/defs.asm | 38 ++ avr/modules/lcd2/ili9341/main.asm | 629 ++++++++++++++++++++++++++++++ avr/modules/lcd2/xpt2046/0BUILD | 11 + avr/modules/lcd2/xpt2046/main.asm | 11 + avr/modules/spi_hw/0BUILD | 11 + avr/modules/spi_hw/main.asm | 202 ++++++++++ 10 files changed, 996 insertions(+), 4 deletions(-) create mode 100644 avr/modules/lcd2/ili9341/0BUILD create mode 100644 avr/modules/lcd2/ili9341/defs.asm create mode 100644 avr/modules/lcd2/ili9341/main.asm create mode 100644 avr/modules/lcd2/xpt2046/0BUILD create mode 100644 avr/modules/lcd2/xpt2046/main.asm create mode 100644 avr/modules/spi_hw/0BUILD create mode 100644 avr/modules/spi_hw/main.asm diff --git a/avr/devices/all/includes.asm b/avr/devices/all/includes.asm index c76ac9a..59569b8 100644 --- a/avr/devices/all/includes.asm +++ b/avr/devices/all/includes.asm @@ -121,6 +121,11 @@ .include "modules/owimaster/main.asm" #endif + +#ifdef MODULES_SPI_HW +.include "modules/spi_hw/main.asm" +#endif + #ifdef MODULES_DS18B20 .include "modules/ds18b20/main2.asm" #ifdef MODULES_NETWORK @@ -147,6 +152,13 @@ #endif #endif +#ifdef MODULES_ILI9341 +.include "modules/lcd2/ili9341/defs.asm" +.include "modules/lcd2/ili9341/main.asm" +#endif + + + #ifdef APPS_MOTION .include "modules/f_keepup/main.asm" .include "modules/valsched/main.asm" diff --git a/avr/devices/all/modules.asm b/avr/devices/all/modules.asm index 0e5249b..75ce833 100644 --- a/avr/devices/all/modules.asm +++ b/avr/devices/all/modules.asm @@ -84,6 +84,11 @@ initModules: #ifdef MODULES_OWI_MASTER rcall OwiMaster_Init #endif + +#ifdef MODULES_SPI_HW + rcall SPIHW_Init +#endif + #ifdef MODULES_LCD rcall LCD_Init #endif @@ -135,6 +140,10 @@ initModules: rcall CCS811_Init #endif +#ifdef MODULES_ILI9341 + rcall ILI9341_Init +#endif + ; done ret @@ -169,10 +178,6 @@ runModules_Com: runModules_ComEnd: #endif -#ifdef MODULES_UART_HW - rcall NET_Uart_Run -#endif - #ifdef MODULES_TTYONUART1 rcall TtyOnUart1_Run #endif diff --git a/avr/devices/c01/defs.asm b/avr/devices/c01/defs.asm index 46aee57..21fed9d 100644 --- a/avr/devices/c01/defs.asm +++ b/avr/devices/c01/defs.asm @@ -79,6 +79,68 @@ +; --------------------------------------------------------------------------- +; SPI hardware module + +.equ SPIHW_SS_DDR = DDRB +.equ SPIHW_SS_INPUT = PINB +.equ SPIHW_SS_OUTPUT = PORTB +.equ SPIHW_SS_PIN = PORTB4 + +.equ SPIHW_MOSI_DDR = DDRB +.equ SPIHW_MOSI_INPUT = PINB +.equ SPIHW_MOSI_OUTPUT = PORTB +.equ SPIHW_MOSI_PIN = PORTB5 + +.equ SPIHW_MISO_DDR = DDRB +.equ SPIHW_MISO_INPUT = PINB +.equ SPIHW_MISO_OUTPUT = PORTB +.equ SPIHW_MISO_PIN = PORTB6 + +.equ SPIHW_SCK_DDR = DDRB +.equ SPIHW_SCK_INPUT = PINB +.equ SPIHW_SCK_OUTPUT = PORTB +.equ SPIHW_SCK_PIN = PORTB7 + +.equ SPIHW_SS0_DDR = DDRB +.equ SPIHW_SS0_OUTPUT = PORTB +.equ SPIHW_SS0_INPUT = PORTB +.equ SPIHW_SS0_PIN = PORTB0 + +.equ SPIHW_SS1_DDR = DDRB +.equ SPIHW_SS1_OUTPUT = PORTB +.equ SPIHW_SS1_INPUT = PORTB +.equ SPIHW_SS1_PIN = PORTB1 + +.equ SPIHW_SS2_DDR = DDRB +.equ SPIHW_SS2_OUTPUT = PORTB +.equ SPIHW_SS2_INPUT = PORTB +.equ SPIHW_SS2_PIN = PORTB2 + + + +; --------------------------------------------------------------------------- +; ILI9341 module + +.equ ILI9341_DEVICENUM = 0 +.equ ILI9341_DSP_WIDTH = 320 +.equ ILI9341_DSP_HEIGHT = 240 + +.equ ILI9341_RESET_DDR = DDRB +.equ ILI9341_RESET_OUTPUT = PORTB +.equ ILI9341_RESET_INPUT = PORTB +.equ ILI9341_RESET_PIN = PORTB3 + +.equ ILI9341_DC_DDR = DDRD +.equ ILI9341_DC_OUTPUT = PORTD +.equ ILI9341_DC_INPUT = PORTD +.equ ILI9341_DC_PIN = PORTD4 + +.equ ILI9341_LED_DDR = DDRD +.equ ILI9341_LED_OUTPUT = PORTD +.equ ILI9341_LED_INPUT = PORTD +.equ ILI9341_LED_PIN = PORTD5 + ; --------------------------------------------------------------------------- diff --git a/avr/modules/lcd2/ili9341/0BUILD b/avr/modules/lcd2/ili9341/0BUILD new file mode 100644 index 0000000..febd367 --- /dev/null +++ b/avr/modules/lcd2/ili9341/0BUILD @@ -0,0 +1,11 @@ + + + + + + main.asm + + + + + diff --git a/avr/modules/lcd2/ili9341/defs.asm b/avr/modules/lcd2/ili9341/defs.asm new file mode 100644 index 0000000..63c4903 --- /dev/null +++ b/avr/modules/lcd2/ili9341/defs.asm @@ -0,0 +1,38 @@ + + + +#define ILI9341_FRAMERATE_61_HZ 0x1F +#define ILI9341_FRAMERATE_63_HZ 0x1E +#define ILI9341_FRAMERATE_65_HZ 0x1D +#define ILI9341_FRAMERATE_68_HZ 0x1C +#define ILI9341_FRAMERATE_70_HZ 0x1B +#define ILI9341_FRAMERATE_73_HZ 0x1A +#define ILI9341_FRAMERATE_76_HZ 0x19 +#define ILI9341_FRAMERATE_79_HZ 0x18 +#define ILI9341_FRAMERATE_83_HZ 0x17 +#define ILI9341_FRAMERATE_86_HZ 0x16 +#define ILI9341_FRAMERATE_90_HZ 0x15 +#define ILI9341_FRAMERATE_95_HZ 0x14 +#define ILI9341_FRAMERATE_100_HZ 0x13 +#define ILI9341_FRAMERATE_106_HZ 0x12 +#define ILI9341_FRAMERATE_112_HZ 0x11 +#define ILI9341_FRAMERATE_119_HZ 0x10 + +#define ILI9341_MADCTL_MY 0x80 ; row address order +#define ILI9341_MADCTL_MX 0x40 ; column address order +#define ILI9341_MADCTL_MV 0x20 ; row/column exchange +#define ILI9341_MADCTL_ML 0x10 ; vertical refresh order +#define ILI9341_MADCTL_RGB 0x00 ; RGB color order +#define ILI9341_MADCTL_BGR 0x08 ; BGR color order +#define ILI9341_MADCTL_MH 0x04 ; horizontal refresh order + + +#define ILI9341_CMD_CASET 0x2A +#define ILI9341_CMD_PASET 0x2B +#define ILI9341_CMD_RAMWR 0x2C +#define ILI9341_CMD_RAMRD 0x2E + +#define ILI9341_CMD_COLORSET 0x2d +#define ILI9341_CMD_SETDSPBRIGHTNESS 0x51 +#define ILI9341_CMD_WRITECTLDISPLAY 0x53 + diff --git a/avr/modules/lcd2/ili9341/main.asm b/avr/modules/lcd2/ili9341/main.asm new file mode 100644 index 0000000..d086b2c --- /dev/null +++ b/avr/modules/lcd2/ili9341/main.asm @@ -0,0 +1,629 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + +; *************************************************************************** +; defines + +#if 0 +.equ ILI9341_SPIMODE = (0< + + + + + main.asm + + + + + diff --git a/avr/modules/lcd2/xpt2046/main.asm b/avr/modules/lcd2/xpt2046/main.asm new file mode 100644 index 0000000..4e899e5 --- /dev/null +++ b/avr/modules/lcd2/xpt2046/main.asm @@ -0,0 +1,11 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + + diff --git a/avr/modules/spi_hw/0BUILD b/avr/modules/spi_hw/0BUILD new file mode 100644 index 0000000..febd367 --- /dev/null +++ b/avr/modules/spi_hw/0BUILD @@ -0,0 +1,11 @@ + + + + + + main.asm + + + + + diff --git a/avr/modules/spi_hw/main.asm b/avr/modules/spi_hw/main.asm new file mode 100644 index 0000000..ea6fd7b --- /dev/null +++ b/avr/modules/spi_hw/main.asm @@ -0,0 +1,202 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + +; *************************************************************************** +; defines + +.equ SPIHW_MODE_SPEED0_BIT = 0 ; 00=CLK/4, 01=CLK/16 +.equ SPIHW_MODE_SPEED1_BIT = 1 ; 10=CLK/64, 11=CLK/128 +.equ SPIHW_MODE_DOUBLESPEED_BIT = 2 ; 1=double speed from SPIHW_MODE_SPEED0/1_BIT +.equ SPIHW_MODE_DATAORDER_BIT = 3 ; 1=LSB first, 0=MSB first +.equ SPIHW_MODE_CPOL_BIT = 4 ; 0=leading edge rising/trailing edge falling +.equ SPIHW_MODE_CPHA_BIT = 5 ; 0=sample on leading edge, setup on trailing edge + + + +; *************************************************************************** +; data + +.dseg + + + +; *************************************************************************** +; code + +.cseg + + + +; --------------------------------------------------------------------------- +; @routine SPIHW_Init @global +; + +SPIHW_Init: + sbi SPIHW_SS0_DDR, SPIHW_SS0_PIN ; SS0= output + sbi SPIHW_SS1_DDR, SPIHW_SS1_PIN ; SS1= output + sbi SPIHW_SS2_DDR, SPIHW_SS2_PIN ; SS2= output + sec + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine SPIHW_Fini @global +; + +SPIHW_Fini: + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine SPIHW_MasterStart @global +; +; Start SPI hardware master with the given mode (see @ref SPIHW_MODE_SPEED0_BIT +; and others). + +; @param r16 mode +; @param r17 device num (0-7) +; @clobbers r17 + +SPIHW_MasterStart: + ; setup pins + sbi SPIHW_SS_DDR, SPIHW_SS_PIN ; SS : output + sbi SPIHW_MOSI_DDR, SPIHW_MOSI_PIN ; MOSI: output + cbi SPIHW_MISO_DDR, SPIHW_MISO_PIN ; MISO: input + sbi SPIHW_SCK_DDR, SPIHW_SCK_PIN ; SCK: output + + ; select device + sbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS high + rcall spiHwSelectDevice ; (none) +; cbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS low + + ; setup SPCR + clr r17 + sbrc r16, SPIHW_MODE_DATAORDER_BIT + sbr r17, (1< Date: Tue, 20 May 2025 21:32:04 +0200 Subject: [PATCH 36/58] ili9341: finalized SPI params. --- avr/modules/lcd2/ili9341/main.asm | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/avr/modules/lcd2/ili9341/main.asm b/avr/modules/lcd2/ili9341/main.asm index d086b2c..950ec9a 100644 --- a/avr/modules/lcd2/ili9341/main.asm +++ b/avr/modules/lcd2/ili9341/main.asm @@ -11,32 +11,12 @@ ; *************************************************************************** ; defines -#if 0 .equ ILI9341_SPIMODE = (0< Date: Tue, 20 May 2025 21:32:18 +0200 Subject: [PATCH 37/58] started working with fonts. --- avr/modules/lcd2/ili9341/font1.asm | 71 ++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 avr/modules/lcd2/ili9341/font1.asm diff --git a/avr/modules/lcd2/ili9341/font1.asm b/avr/modules/lcd2/ili9341/font1.asm new file mode 100644 index 0000000..17d3985 --- /dev/null +++ b/avr/modules/lcd2/ili9341/font1.asm @@ -0,0 +1,71 @@ + + + +font8x8: +.db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, ; 0x20 +.db 0x0C,0x1E,0x1E,0x0C,0x0C,0x00,0x0C,0x00, ; 0x21 +.db 0x36,0x36,0x36,0x00,0x00,0x00,0x00,0x00, ; 0x22 +.db 0x36,0x36,0x7F,0x36,0x7F,0x36,0x36,0x00, ; 0x23 +.db 0x0C,0x3E,0x03,0x1E,0x30,0x1F,0x0C,0x00, ; 0x24 +.db 0x00,0x63,0x33,0x18,0x0C,0x66,0x63,0x00, ; 0x25 +.db 0x1C,0x36,0x1C,0x6E,0x3B,0x33,0x6E,0x00, ; 0x26 +.db 0x06,0x06,0x03,0x00,0x00,0x00,0x00,0x00, ; 0x27 +.db 0x18,0x0C,0x06,0x06,0x06,0x0C,0x18,0x00, ; 0x28 +.db 0x06,0x0C,0x18,0x18,0x18,0x0C,0x06,0x00, ; 0x29 +.db 0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00, ; 0x2A +.db 0x00,0x0C,0x0C,0x3F,0x0C,0x0C,0x00,0x00, ; 0x2B +.db 0x00,0x00,0x00,0x00,0x00,0x0E,0x0C,0x06, ; 0x2C +.db 0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00, ; 0x2D +.db 0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x00, ; 0x2E +.db 0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00, ; 0x2F +.db 0x1E,0x33,0x3B,0x3F,0x37,0x33,0x1E,0x00, ; 0x30 +.db 0x0C,0x0F,0x0C,0x0C,0x0C,0x0C,0x3F,0x00, ; 0x31 +.db 0x1E,0x33,0x30,0x1C,0x06,0x33,0x3F,0x00, ; 0x32 +.db 0x1E,0x33,0x30,0x1C,0x30,0x33,0x1E,0x00, ; 0x33 +.db 0x38,0x3C,0x36,0x33,0x7F,0x30,0x30,0x00, ; 0x34 +.db 0x3F,0x03,0x1F,0x30,0x30,0x33,0x1E,0x00, ; 0x35 +.db 0x1C,0x06,0x03,0x1F,0x33,0x33,0x1E,0x00, ; 0x36 +.db 0x3F,0x33,0x30,0x18,0x0C,0x06,0x06,0x00, ; 0x37 +.db 0x1E,0x33,0x33,0x1E,0x33,0x33,0x1E,0x00, ; 0x38 +.db 0x1E,0x33,0x33,0x3E,0x30,0x18,0x0E,0x00, ; 0x39 +.db 0x00,0x00,0x0C,0x0C,0x00,0x0C,0x0C,0x00, ; 0x3A +.db 0x00,0x00,0x0C,0x0C,0x00,0x0E,0x0C,0x06, ; 0x3B +.db 0x18,0x0C,0x06,0x03,0x06,0x0C,0x18,0x00, ; 0x3C +.db 0x00,0x00,0x3F,0x00,0x3F,0x00,0x00,0x00, ; 0x3D +.db 0x06,0x0C,0x18,0x30,0x18,0x0C,0x06,0x00, ; 0x3E +.db 0x1E,0x33,0x30,0x18,0x0C,0x00,0x0C,0x00, ; 0x3F +.db 0x3E,0x63,0x7B,0x7B,0x7B,0x03,0x1E,0x00, ; 0x40 +.db 0x0C,0x1E,0x33,0x33,0x3F,0x33,0x33,0x00, ; 0x41 +.db 0x3F,0x66,0x66,0x3E,0x66,0x66,0x3F,0x00, ; 0x42 +.db 0x3C,0x66,0x03,0x03,0x03,0x66,0x3C,0x00, ; 0x43 +.db 0x3F,0x36,0x66,0x66,0x66,0x36,0x3F,0x00, ; 0x44 +.db 0x7F,0x46,0x16,0x1E,0x16,0x46,0x7F,0x00, ; 0x45 +.db 0x7F,0x46,0x16,0x1E,0x16,0x06,0x0F,0x00, ; 0x46 +.db 0x3C,0x66,0x03,0x03,0x73,0x66,0x7C,0x00, ; 0x47 +.db 0x33,0x33,0x33,0x3F,0x33,0x33,0x33,0x00, ; 0x48 +.db 0x1E,0x0C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00, ; 0x49 +.db 0x78,0x30,0x30,0x30,0x33,0x33,0x1E,0x00, ; 0x4A +.db 0x67,0x66,0x36,0x1E,0x36,0x66,0x67,0x00, ; 0x4B +.db 0x0F,0x06,0x06,0x06,0x46,0x66,0x7F,0x00, ; 0x4C +.db 0x63,0x77,0x7F,0x6B,0x63,0x63,0x63,0x00, ; 0x4D +.db 0x63,0x67,0x6F,0x7B,0x73,0x63,0x63,0x00, ; 0x4E +.db 0x1C,0x36,0x63,0x63,0x63,0x36,0x1C,0x00, ; 0x4F +.db 0x3F,0x66,0x66,0x3E,0x06,0x06,0x0F,0x00, ; 0x50 +.db 0x1E,0x33,0x33,0x33,0x3B,0x1E,0x38,0x00, ; 0x51 +.db 0x3F,0x66,0x66,0x3E,0x1E,0x36,0x67,0x00, ; 0x52 +.db 0x1E,0x33,0x07,0x1C,0x38,0x33,0x1E,0x00, ; 0x53 +.db 0x3F,0x2D,0x0C,0x0C,0x0C,0x0C,0x1E,0x00, ; 0x54 +.db 0x33,0x33,0x33,0x33,0x33,0x33,0x3F,0x00, ; 0x55 +.db 0x33,0x33,0x33,0x33,0x33,0x1E,0x0C,0x00, ; 0x56 +.db 0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00, ; 0x57 +.db 0x63,0x63,0x36,0x1C,0x36,0x63,0x63,0x00, ; 0x58 +.db 0x33,0x33,0x33,0x1E,0x0C,0x0C,0x1E,0x00, ; 0x59 +.db 0x7F,0x33,0x19,0x0C,0x46,0x63,0x7F,0x00, ; 0x5A +.db 0x1E,0x06,0x06,0x06,0x06,0x06,0x1E,0x00, ; 0x5B +.db 0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00, ; 0x5C +.db 0x1E,0x18,0x18,0x18,0x18,0x18,0x1E,0x00, ; 0x5D +.db 0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, ; 0x5E +.db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF ; 0x5F + + + From 2ca246deca4da2777d4068f6008119dcfadea212 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Tue, 20 May 2025 21:32:53 +0200 Subject: [PATCH 38/58] removed ili9341WriteColorTable --- avr/modules/lcd2/ili9341/main.asm | 35 ------------------------------- 1 file changed, 35 deletions(-) diff --git a/avr/modules/lcd2/ili9341/main.asm b/avr/modules/lcd2/ili9341/main.asm index 950ec9a..8f04ab3 100644 --- a/avr/modules/lcd2/ili9341/main.asm +++ b/avr/modules/lcd2/ili9341/main.asm @@ -518,41 +518,6 @@ ili9341Test5: -ili9341WriteColorTable: - rcall ili9341BeginSpi ; (R16, R17) - ldi r16, ILI9341_CMD_COLORSET - rcall ili9341SendCommand - - ldi r17, 32 ; send R00-R31 - clr r18 - ldi r19, 2 - rcall ili9341WriteColorTable_loop - - ldi r17, 64 ; send G00-G63 - clr r18 - ldi r19, 1 - rcall ili9341WriteColorTable_loop - - ldi r17, 32 ; send B00-B31 - clr r18 - ldi r19, 2 - rcall ili9341WriteColorTable_loop - - rcall ili9341EndSpi - ret - -ili9341WriteColorTable_loop: - mov r16, r18 - rcall ili9341SendData - add r18, r19 - dec r17 - brne ili9341WriteColorTable_loop - ret -; @end - - - - ili9341InitCommands: ; display off .db 0x28, 0 From a0898b8327e8a3d637e0b4c70245ad39d9358257 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Tue, 20 May 2025 23:36:00 +0200 Subject: [PATCH 39/58] insert 2 bytes at beginning of a font (first char, num chars) --- avr/modules/lcd2/ili9341/font1.asm | 1 + 1 file changed, 1 insertion(+) diff --git a/avr/modules/lcd2/ili9341/font1.asm b/avr/modules/lcd2/ili9341/font1.asm index 17d3985..a1c3b69 100644 --- a/avr/modules/lcd2/ili9341/font1.asm +++ b/avr/modules/lcd2/ili9341/font1.asm @@ -2,6 +2,7 @@ font8x8: +.db 32, 64 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, ; 0x20 .db 0x0C,0x1E,0x1E,0x0C,0x0C,0x00,0x0C,0x00, ; 0x21 .db 0x36,0x36,0x36,0x00,0x00,0x00,0x00,0x00, ; 0x22 From d29147fe574e6c3b4a708e7df9be2558b6e5377c Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Tue, 20 May 2025 23:36:31 +0200 Subject: [PATCH 40/58] added ili9341_WriteCharacterAt. --- avr/modules/lcd2/ili9341/main.asm | 152 +++++++++++++++++++++++++++++- 1 file changed, 150 insertions(+), 2 deletions(-) diff --git a/avr/modules/lcd2/ili9341/main.asm b/avr/modules/lcd2/ili9341/main.asm index 8f04ab3..364d826 100644 --- a/avr/modules/lcd2/ili9341/main.asm +++ b/avr/modules/lcd2/ili9341/main.asm @@ -24,6 +24,9 @@ .dseg +ILI9341_foregroundColor: .byte 2 +ILI9341_backgroundColor: .byte 2 +ILI9341_buffer: .byte 128 ; *************************************************************************** @@ -71,6 +74,39 @@ ILI9341_Init: ldi r16, 0b11100000 ; green rcall ili9341Test4 +; set foreground color + ldi r16, 0b11100000 ; green + mov r2, r16 + ldi r16, 0b00000111 ; green + mov r3, r16 + +; set background color + ldi r16, 0b11111111 ; white + mov r0, r16 + mov r1, r16 + +; set Xpos + ldi r18, LOW(100) + ldi r19, LOW(100) + +; setYpos + ldi r20, LOW(150) + ldi r21, HIGH(150) + +; set font pos + ldi zl, LOW(font8x8*2) + ldi zh, HIGH(font8x8*2) + +; set buffer pos +; ldi xl, LOW(ILI9341_buffer) +; ldi xh, HIGH(ILI9341_buffer) + ldi xl, LOW(0x260) + ldi xh, HIGH(0x260) + +; set character + ldi r16, 65 + + rcall ili9341_WriteCharacterAt sec ret @@ -325,6 +361,109 @@ ili9341SetAddressWindow: +; --------------------------------------------------------------------------- +; @routine ili9341_WriteCharacterAt + +; @param R16 character to write +; @param r19:r18 X pos +; @param r21:r20 Y pos +; @param R01:R00 background color +; @param R03:R02 foreground color +; @param X pointer to font +; @param Y pointer to RAM to store data to +; @clobbers + +ili9341_WriteCharacterAt: + push xl + push xh + rcall ili9341WriteCharacterFromFont8x8 ; (r17, r24, r25, x, z) + pop xh + pop xl + ldi r17, 7 + ; calc X1 + mov r22, r18 + mov r23, r19 + add r22, r17 + adc r23, r17 + sub r23, r17 + ; calc Y1 + mov r24, r20 + mov r25, r21 + add r24, r17 + adc r25, r17 + sub r25, r17 + + rcall ili9341BeginSpi ; (r16, r17) + rcall ili9341SetAddressWindow ; (R16) + ldi r16, ILI9341_CMD_RAMWR ; start writing ro RAM + rcall ili9341SendCommand + ldi r17, 64 ; 8x8 +ili9341_WriteCharacterAt_loop: + ld r18, X+ + ld r19, X+ + rcall ili9341Send16BitData + dec r17 + brne ili9341_WriteCharacterAt_loop + rcall ili9341EndSpi + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine ili9341WriteCharacterFromFont8x8 + +; @param R16 character to write +; @param R01:R00 background color +; @param R03:R02 foreground color +; @param Z pointer to font +; @param X pointer to RAM to store data to +; @clobbers r17, r24, r25, x, z + +ili9341WriteCharacterFromFont8x8: + mov r24, r16 + lpm r17, Z+ ; first char num + sub r24, r17 + brcc ili9341WriteCharacterFromFont8x8_firstValueOkay + clr r24 ; use first char + adiw zh:zl, 1 + rjmp ili9341WriteCharacterFromFont8x8_transform ; skip next test +ili9341WriteCharacterFromFont8x8_firstValueOkay: + lpm r17, Z+ + cp r24, r17 + brcc ili9341WriteCharacterFromFont8x8_transform ; use first char +ili9341WriteCharacterFromFont8x8_gotPos: + clr r25 + lsl r24 ; R16x8 + rol r25 + lsl r24 + rol r25 + lsl r24 + rol r25 + add zl, r24 + adc zh, r25 +ili9341WriteCharacterFromFont8x8_transform: + ldi r25, 8 ; 8 bytes +ili9341WriteCharacterFromFont8x8_loop1: + ldi r24, 8 ; 8 bits + lpm r17, Z+ +ili9341WriteCharacterFromFont8x8_loop2: + lsr r17 + brcs ili9341WriteCharacterFromFont8x8_writeForeground + st X+, r0 + st X+, r1 + rjmp ili9341WriteCharacterFromFont8x8_loop2end +ili9341WriteCharacterFromFont8x8_writeForeground: + st X+, r2 + st X+, r3 +ili9341WriteCharacterFromFont8x8_loop2end: + dec r24 + brne ili9341WriteCharacterFromFont8x8_loop2 + dec r25 + brne ili9341WriteCharacterFromFont8x8_loop1 + ret +; @end + ili9341SendCommand: @@ -353,9 +492,9 @@ ili9341Send16BitData: cbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS low sbi ILI9341_DC_OUTPUT, ILI9341_DC_PIN ; D high mov r16, r19 - rcall SPIHW_MasterTransfer + rcall SPIHW_MasterTransfer ; (R16) mov r16, r18 - rcall SPIHW_MasterTransfer + rcall SPIHW_MasterTransfer ; (R16) sbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS low ret ; @end @@ -495,6 +634,15 @@ l_loopW_%: ili9341Test2: M_ILI9341_FILL_RECT 10, 20, 70, 100 + ldi r18, LOW(10) ; X + ldi r19, HIGH(10) + ldi r20, LOW(20) ; Y + ldi r21, HIGH(20) + ldi r22, LOW(70) ; W + ldi r23, HIGH(70) + ldi r24, LOW(100) ; H + ldi r25, HIGH(100) + rjmp ILI9341_FillRect ret From b3d7d492d7d89762258ae112148fd967023db3a4 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Wed, 21 May 2025 00:12:38 +0200 Subject: [PATCH 41/58] ili9341: added routine to write a char in double height/width. --- avr/modules/lcd2/ili9341/main.asm | 199 +++++++++++++++++++++++++----- 1 file changed, 165 insertions(+), 34 deletions(-) diff --git a/avr/modules/lcd2/ili9341/main.asm b/avr/modules/lcd2/ili9341/main.asm index 364d826..a8657a4 100644 --- a/avr/modules/lcd2/ili9341/main.asm +++ b/avr/modules/lcd2/ili9341/main.asm @@ -105,8 +105,7 @@ ILI9341_Init: ; set character ldi r16, 65 - - rcall ili9341_WriteCharacterAt + rcall ili9341_WriteCharacterX2At sec ret @@ -360,9 +359,27 @@ ili9341SetAddressWindow: +; --------------------------------------------------------------------------- +; @routine ili9341_WriteStringX1At + +; @param R16 character to write +; @param r19:r18 X pos +; @param r21:r20 Y pos +; @param R01:R00 background color +; @param R03:R02 foreground color +; @param Z pointer to font +; @param Y pointer to RAM to store data to +; @clobbers + +ili9341_WriteStringX1At: + + ret +; @end + + ; --------------------------------------------------------------------------- -; @routine ili9341_WriteCharacterAt +; @routine ili9341_WriteCharacterX1At ; @param R16 character to write ; @param r19:r18 X pos @@ -373,13 +390,14 @@ ili9341SetAddressWindow: ; @param Y pointer to RAM to store data to ; @clobbers -ili9341_WriteCharacterAt: +ili9341_WriteCharacterX1At: push xl push xh - rcall ili9341WriteCharacterFromFont8x8 ; (r17, r24, r25, x, z) + rcall ili9341WriteCharacterFromFont8x8x1 ; (r17, r24, r25, x, z) pop xh pop xl ldi r17, 7 + ; calc X1 mov r22, r18 mov r23, r19 @@ -398,12 +416,12 @@ ili9341_WriteCharacterAt: ldi r16, ILI9341_CMD_RAMWR ; start writing ro RAM rcall ili9341SendCommand ldi r17, 64 ; 8x8 -ili9341_WriteCharacterAt_loop: +ili9341_WriteCharacterX1At_loop: ld r18, X+ ld r19, X+ rcall ili9341Send16BitData dec r17 - brne ili9341_WriteCharacterAt_loop + brne ili9341_WriteCharacterX1At_loop rcall ili9341EndSpi ret ; @end @@ -411,7 +429,57 @@ ili9341_WriteCharacterAt_loop: ; --------------------------------------------------------------------------- -; @routine ili9341WriteCharacterFromFont8x8 +; @routine ili9341_WriteCharacterX2At + +; @param R16 character to write +; @param r19:r18 X pos +; @param r21:r20 Y pos +; @param R01:R00 background color +; @param R03:R02 foreground color +; @param X pointer to font +; @param Y pointer to RAM to store data to +; @clobbers + +ili9341_WriteCharacterX2At: + push xl + push xh + rcall ili9341WriteCharacterFromFont8x8x2 ; (r17, r24, r25, x, z) + pop xh + pop xl + ldi r17, 15 + + ; calc X1 + mov r22, r18 + mov r23, r19 + add r22, r17 + adc r23, r17 + sub r23, r17 + ; calc Y1 + mov r24, r20 + mov r25, r21 + add r24, r17 + adc r25, r17 + sub r25, r17 + + rcall ili9341BeginSpi ; (r16, r17) + rcall ili9341SetAddressWindow ; (R16) + ldi r16, ILI9341_CMD_RAMWR ; start writing ro RAM + rcall ili9341SendCommand + ldi r17, 0 ; 256 bytes +ili9341_WriteCharacterX2At_loop: + ld r18, X+ + ld r19, X+ + rcall ili9341Send16BitData + dec r17 + brne ili9341_WriteCharacterX2At_loop + rcall ili9341EndSpi + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine ili9341WriteCharacterFromFont8x8x1 ; @param R16 character to write ; @param R01:R00 background color @@ -420,18 +488,97 @@ ili9341_WriteCharacterAt_loop: ; @param X pointer to RAM to store data to ; @clobbers r17, r24, r25, x, z -ili9341WriteCharacterFromFont8x8: +ili9341WriteCharacterFromFont8x8x1: + rcall ili9341GetCharPosInFont8x8 ; (r17, r24, r25, z) + ldi r25, 8 ; 8 bytes +ili9341WriteCharacterFromFont8x8x1_loop1: + ldi r24, 8 ; 8 bits + lpm r17, Z+ +ili9341WriteCharacterFromFont8x8x1_loop2: + lsr r17 + brcs ili9341WriteCharacterFromFont8x8x1_writeForeground + st X+, r0 + st X+, r1 + rjmp ili9341WriteCharacterFromFont8x8x1_loop2end +ili9341WriteCharacterFromFont8x8x1_writeForeground: + st X+, r2 + st X+, r3 +ili9341WriteCharacterFromFont8x8x1_loop2end: + dec r24 + brne ili9341WriteCharacterFromFont8x8x1_loop2 + dec r25 + brne ili9341WriteCharacterFromFont8x8x1_loop1 + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine ili9341WriteCharacterFromFont8x8x2 + +; @param R16 character to write +; @param R01:R00 background color +; @param R03:R02 foreground color +; @param Z pointer to font +; @param X pointer to RAM to store data to +; @clobbers r17, r22, r23, r24, r25, x, z + +ili9341WriteCharacterFromFont8x8x2: + rcall ili9341GetCharPosInFont8x8 ; (r17, r24, r25, z) + ldi r25, 8 ; 8 bytes +ili9341WriteCharacterFromFont8x8x2_loop1: + ldi r24, 8 ; 8 bits + lpm r17, Z+ +ili9341WriteCharacterFromFont8x8x2_loop2: + lsr r17 + brcs ili9341WriteCharacterFromFont8x8x2_writeForeground + mov r22, r0 + mov r23, r1 + rjmp ili9341WriteCharacterFromFont8x8x2_loop2end +ili9341WriteCharacterFromFont8x8x2_writeForeground: + mov r22, r2 + mov r23, r3 +ili9341WriteCharacterFromFont8x8x2_loop2end: + st X+, r22 + st X+, r23 + st X+, r22 + st X+, r23 + adiw xh:xl, 28 ; move to next row (8*4)-4 + st X+, r22 + st X+, r23 + st X+, r22 + st X+, r23 + sbiw xh:xl, 32 ; move back to previous row + dec r24 + brne ili9341WriteCharacterFromFont8x8x2_loop2 + adiw xh:xl, 32 ; skip next line (we already wrote it) + dec r25 + brne ili9341WriteCharacterFromFont8x8x2_loop1 + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine ili9341GetCharPosInFont8x8 + +; @param R16 character to write +; @param Z pointer to font +; @return Z pointer to begin of char data +; @clobbers r17, r24, r25, z + +ili9341GetCharPosInFont8x8: mov r24, r16 lpm r17, Z+ ; first char num sub r24, r17 - brcc ili9341WriteCharacterFromFont8x8_firstValueOkay - clr r24 ; use first char - adiw zh:zl, 1 - rjmp ili9341WriteCharacterFromFont8x8_transform ; skip next test -ili9341WriteCharacterFromFont8x8_firstValueOkay: + brcc ili9341GetCharPosInFont8x8_firstValueOkay + adiw zh:zl, 1 ; use first char + ret +ili9341GetCharPosInFont8x8_firstValueOkay: lpm r17, Z+ cp r24, r17 - brcc ili9341WriteCharacterFromFont8x8_transform ; use first char + brcs ili9341WriteCharacterFromFont8x8_gotPos + ret ili9341WriteCharacterFromFont8x8_gotPos: clr r25 lsl r24 ; R16x8 @@ -442,25 +589,6 @@ ili9341WriteCharacterFromFont8x8_gotPos: rol r25 add zl, r24 adc zh, r25 -ili9341WriteCharacterFromFont8x8_transform: - ldi r25, 8 ; 8 bytes -ili9341WriteCharacterFromFont8x8_loop1: - ldi r24, 8 ; 8 bits - lpm r17, Z+ -ili9341WriteCharacterFromFont8x8_loop2: - lsr r17 - brcs ili9341WriteCharacterFromFont8x8_writeForeground - st X+, r0 - st X+, r1 - rjmp ili9341WriteCharacterFromFont8x8_loop2end -ili9341WriteCharacterFromFont8x8_writeForeground: - st X+, r2 - st X+, r3 -ili9341WriteCharacterFromFont8x8_loop2end: - dec r24 - brne ili9341WriteCharacterFromFont8x8_loop2 - dec r25 - brne ili9341WriteCharacterFromFont8x8_loop1 ret ; @end @@ -716,6 +844,9 @@ ili9341InitCommands: .db 0xff, 0xff +helloWorld: .db "Hello World", 0 + + .include "modules/lcd2/ili9341/font1.asm" From de94590fa0c4d9c8778f5fcdc65dcec7f6c391be Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Wed, 21 May 2025 01:44:38 +0200 Subject: [PATCH 42/58] ili9341: moved io code into own file. changed args to r0-r11. --- avr/devices/all/includes.asm | 1 + avr/modules/lcd2/ili9341/io_spi.asm | 112 ++++++ avr/modules/lcd2/ili9341/main.asm | 527 +++++++++++----------------- 3 files changed, 310 insertions(+), 330 deletions(-) create mode 100644 avr/modules/lcd2/ili9341/io_spi.asm diff --git a/avr/devices/all/includes.asm b/avr/devices/all/includes.asm index 59569b8..77a1647 100644 --- a/avr/devices/all/includes.asm +++ b/avr/devices/all/includes.asm @@ -155,6 +155,7 @@ #ifdef MODULES_ILI9341 .include "modules/lcd2/ili9341/defs.asm" .include "modules/lcd2/ili9341/main.asm" +.include "modules/lcd2/ili9341/io_spi.asm" #endif diff --git a/avr/modules/lcd2/ili9341/io_spi.asm b/avr/modules/lcd2/ili9341/io_spi.asm new file mode 100644 index 0000000..a91629a --- /dev/null +++ b/avr/modules/lcd2/ili9341/io_spi.asm @@ -0,0 +1,112 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + +; generally we use the following parameters here: +; @param r1:r0 background color +; @param r3:r2 foreground color +; @param r5:r4 X0 +; @param r7:r6 Y0 +; @param r9:r8 X1/W +; @param r11:r10 Y1/H + + +; *************************************************************************** +; defines + +.equ ILI9341_SPIMODE = (0< Date: Wed, 21 May 2025 01:45:02 +0200 Subject: [PATCH 43/58] ili9341: first ideas for window/screen management. --- avr/modules/lcd2/ili9341/defs.asm | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/avr/modules/lcd2/ili9341/defs.asm b/avr/modules/lcd2/ili9341/defs.asm index 63c4903..aa3aa70 100644 --- a/avr/modules/lcd2/ili9341/defs.asm +++ b/avr/modules/lcd2/ili9341/defs.asm @@ -36,3 +36,24 @@ #define ILI9341_CMD_SETDSPBRIGHTNESS 0x51 #define ILI9341_CMD_WRITECTLDISPLAY 0x53 + + +.equ WIN_OFFS_BGCOLOR_LOW = 0 +.equ WIN_OFFS_BGCOLOR_HIGH = 1 + +.equ WIN_OFFS_FGCOLOR_LOW = 2 +.equ WIN_OFFS_FGCOLOR_HIGH = 3 + +.equ WIN_OFFS_WIDTH_LOW = 4 +.equ WIN_OFFS_WIDTH_HIGH = 5 + +.equ WIN_OFFS_HEIGHT_LOW = 6 +.equ WIN_OFFS_HEIGHT_HIGH = 7 + +.equ WIN_OFFS_ABS_X_LOW = 8 +.equ WIN_OFFS_ABS_X_HIGH = 9 + +.equ WIN_OFFS_REL_X_LOW = 10 +.equ WIN_OFFS_REL_X_HIGH = 11 + + From c0654157139ba731209bce5a707cb36ca8f37b47 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Thu, 22 May 2025 00:42:09 +0200 Subject: [PATCH 44/58] ili9341: created dedicated sourcefile for font handling. --- avr/devices/all/includes.asm | 1 + avr/modules/lcd2/ili9341/font8x8.asm | 88 ++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 avr/modules/lcd2/ili9341/font8x8.asm diff --git a/avr/devices/all/includes.asm b/avr/devices/all/includes.asm index 77a1647..1dc5887 100644 --- a/avr/devices/all/includes.asm +++ b/avr/devices/all/includes.asm @@ -156,6 +156,7 @@ .include "modules/lcd2/ili9341/defs.asm" .include "modules/lcd2/ili9341/main.asm" .include "modules/lcd2/ili9341/io_spi.asm" +.include "modules/lcd2/ili9341/font8x8.asm" #endif diff --git a/avr/modules/lcd2/ili9341/font8x8.asm b/avr/modules/lcd2/ili9341/font8x8.asm new file mode 100644 index 0000000..04395f4 --- /dev/null +++ b/avr/modules/lcd2/ili9341/font8x8.asm @@ -0,0 +1,88 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + +; *************************************************************************** +; code + +.cseg + + + + +; --------------------------------------------------------------------------- +; @routine ili9341WriteCharacterFromFont8x8 + +; @param R16 character to write +; @param R1:R0 background color +; @param R3:R2 foreground color +; @param Z pointer to font +; @param X pointer to RAM to store data to +; @clobbers r17, r24, r25, x, z + +ili9341WriteCharacterFromFont8x8: + rcall ili9341GetCharPosInFont8x8 ; (r17, r24, r25, z) + ldi r25, 8 ; 8 bytes +ili9341WriteCharacterFromFont8x8_loop1: + ldi r24, 8 ; 8 bits + lpm r17, Z+ +ili9341WriteCharacterFromFont8x8_loop2: + lsr r17 + brcs ili9341WriteCharacterFromFont8x8_writeForeground + st X+, r0 + st X+, r1 + rjmp ili9341WriteCharacterFromFont8x8_loop2end +ili9341WriteCharacterFromFont8x8_writeForeground: + st X+, r2 + st X+, r3 +ili9341WriteCharacterFromFont8x8_loop2end: + dec r24 + brne ili9341WriteCharacterFromFont8x8_loop2 + dec r25 + brne ili9341WriteCharacterFromFont8x8_loop1 + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine ili9341GetCharPosInFont8x8 + +; @param R16 character to write +; @param Z pointer to font +; @return Z pointer to begin of char data +; @clobbers r17, r24, r25, z + +ili9341GetCharPosInFont8x8: + mov r24, r16 + lpm r17, Z+ ; first char num + sub r24, r17 + brcc ili9341GetCharPosInFont8x8_firstValueOkay + adiw zh:zl, 1 ; use first char + ret +ili9341GetCharPosInFont8x8_firstValueOkay: + lpm r17, Z+ + cp r24, r17 + brcs ili9341WriteCharacterFromFont8x8_gotPos + ret +ili9341WriteCharacterFromFont8x8_gotPos: + clr r25 + lsl r24 ; R16x8 + rol r25 + lsl r24 + rol r25 + lsl r24 + rol r25 + add zl, r24 + adc zh, r25 + ret +; @end + + + From 143180d68baad16c9cfdf3ffd18807969645f1a9 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Thu, 22 May 2025 00:42:55 +0200 Subject: [PATCH 45/58] ili9341: added bitblit routines. --- avr/modules/lcd2/ili9341/main.asm | 588 ++++++++++++++++++------------ 1 file changed, 349 insertions(+), 239 deletions(-) diff --git a/avr/modules/lcd2/ili9341/main.asm b/avr/modules/lcd2/ili9341/main.asm index 8da3db6..4c91dbf 100644 --- a/avr/modules/lcd2/ili9341/main.asm +++ b/avr/modules/lcd2/ili9341/main.asm @@ -106,9 +106,14 @@ ILI9341_Init: ldi xl, LOW(0x260) ldi xh, HIGH(0x260) +; set foreground color + ldi r16, 0b00000000 ; black + mov r2, r16 + mov r3, r16 + ; set character ldi r16, 65 - rcall ili9341_WriteCharacterX2At + rcall ili9341_WriteCharacterX4At sec ret @@ -259,74 +264,24 @@ ILI9341_FillScreen: -; --------------------------------------------------------------------------- -; @routine ILI9341_FillRect -; @param r3:r2 color -; @param r5:r4 X0 -; @param r7:r6 Y0 -; @param r9:r8 X1/W -; @param r11:r10 Y1/H - -ILI9341_FillRect: - rcall ili9341BeginSpi ; (R16, R17) - push r8 ; W - push r9 - push r10 - push r11 - ldi r16, 1 - - sub r8, r16 ; X1=X+W-1 - sbc r9, r16 - add r9, r16 - add r8, r4 - adc r9, r5 - - sub r10, r16 ; Y1=Y+H-1 - sbc r11, r16 - add r11, r16 - add r10, r6 - adc r11, r7 - rcall ili9341SetAddressWindow ; (R16) - pop r11 - pop r10 - pop r9 - pop r8 - - mov r18, r2 ; color - mov r19, r3 - mov r22, r10 ; H low - mov r23, r11 ; H high - ldi r16, ILI9341_CMD_RAMWR ; start writing ro RAM - rcall ili9341SendCommand -ILI9341_FillRect_loopH: - mov r24, r8 ; W low - mov r25, r9 ; W high -ILI9341_FillRect_loopW: - rcall ili9341Send16BitData ; send r19:r18 - sbiw r25:r24, 1 - brne ILI9341_FillRect_loopW - mov r24, r22 ; H low - mov r25, r23 ; H high - sbiw r25:r24, 1 ; dec - mov r22, r24 ; save in r23:r22 - mov r23, r25 - brne ILI9341_FillRect_loopH - rcall ili9341EndSpi - ret -; @end - - - ; --------------------------------------------------------------------------- ; @routine ili9341SetAddressWindow ; ; @param r5:r4 X0 ; @param r7:r6 Y0 -; @param r9:r8 X1 -; @param r11:r10 Y1 -; @clobbers R16 +; @param r9:r8 W +; @param r11:r10 H +; @clobbers R16, r20, r21 ili9341SetAddressWindow: + ; calc XEnd (=X+W-1) + mov r20, r8 + mov r21, r9 + add r20, r4 + adc r21, r5 + subi r20, 1 + sbci r21, 0 + ; send column address ldi r16, ILI9341_CMD_CASET rcall ili9341SendCommand @@ -336,11 +291,19 @@ ili9341SetAddressWindow: mov r16, r4 rcall ili9341SendData ; X1 - mov r16, r9 + mov r16, r21 rcall ili9341SendData - mov r16, r8 + mov r16, r20 rcall ili9341SendData + ; calc YEnd (=Y+H-1) + mov r20, r10 + mov r21, r11 + add r20, r6 + adc r21, r7 + subi r20, 1 + sbci r21, 0 + ; send row address ldi r16, ILI9341_CMD_PASET rcall ili9341SendCommand @@ -350,9 +313,9 @@ ili9341SetAddressWindow: mov r16, r6 rcall ili9341SendData ; Y1 - mov r16, r11 + mov r16, r21 rcall ili9341SendData - mov r16, r10 + mov r16, r20 rcall ili9341SendData ret @@ -360,6 +323,272 @@ ili9341SetAddressWindow: +; --------------------------------------------------------------------------- +; @routine ILI9341_FillRect +; @param r3:r2 color +; @param r5:r4 X0 +; @param r7:r6 Y0 +; @param r9:r8 X1/W +; @param r11:r10 Y1/H + +ILI9341_FillRect: + push r15 + in r15, SREG + cli + + rcall ili9341BeginSpi ; (R16, R17) + rcall ili9341SetAddressWindow ; (R16, r20, r21) + + mov r18, r2 ; color + mov r19, r3 + mov r22, r10 ; H low + mov r23, r11 ; H high + ldi r16, ILI9341_CMD_RAMWR ; start writing ro RAM + rcall ili9341SendCommand + + cbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS low + sbi ILI9341_DC_OUTPUT, ILI9341_DC_PIN ; D high (DATA) +ILI9341_FillRect_loopH: + mov r24, r8 ; W low + mov r25, r9 ; W high +ILI9341_FillRect_loopW: + mov r16, r19 + rcall SPIHW_MasterTransfer + mov r16, r18 + rcall SPIHW_MasterTransfer + sbiw r25:r24, 1 + brne ILI9341_FillRect_loopW + mov r24, r22 ; H low + mov r25, r23 ; H high + sbiw r25:r24, 1 ; dec + mov r22, r24 ; save in r23:r22 + mov r23, r25 + brne ILI9341_FillRect_loopH + sbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS high + rcall ili9341EndSpi + out SREG, r15 + pop r15 + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine ili9341BitBlit + +; @param r5:r4 X (dest) +; @param r7:r6 Y (dest) +; @param r9:r8 W +; @param r11:r10 H +; @param X source data pointer (RAM) +; @clobbers r16, r22, r23, r24, r25, X (r17, r20, r21) + +ili9341BitBlit: + push r15 + in r15, SREG + cli + + rcall ili9341BeginSpi ; (r16, r17) + rcall ili9341SetAddressWindow ; (R16, R20, R21) + + ldi r16, ILI9341_CMD_RAMWR ; start writing ro RAM + rcall ili9341SendCommand + + mov r22, r10 + mov r23, r11 + cbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS low + sbi ILI9341_DC_OUTPUT, ILI9341_DC_PIN ; D high (DATA) +ili9341BitBlit_loopH: + mov r24, r8 + mov r25, r9 +ili9341BitBlit_loopW: + ld r18, X+ + ld r19, X+ + mov r16, r19 + rcall SPIHW_MasterTransfer ; (R16) + mov r16, r18 + rcall SPIHW_MasterTransfer ; (R16) + sbiw r25:r24, 1 + brne ili9341BitBlit_loopW + mov r24, r22 + mov r25, r23 + sbiw r25:r24, 1 + mov r22, r24 + mov r23, r25 + brne ili9341BitBlit_loopH + sbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS high + rcall ili9341EndSpi ; (R16) + out SREG, r15 + pop r15 + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine ili9341BitBlitStretch2 + +; @param r5:r4 X (dest) +; @param r7:r6 Y (dest) +; @param r9:r8 W +; @param r11:r10 H +; @param X source data pointer (RAM) +; @clobbers r16, r22, r23, r24, r25, X (r17, r20, r21) + +ili9341BitBlitStretch2: + push r15 + in r15, SREG + cli + + push r8 + push r9 + push r10 + push r11 + ; width + lsl r8 ; x2 + rol r9 + ; height + lsl r10 ; x2 + rol r11 + + rcall ili9341BeginSpi ; (r16, r17) + rcall ili9341SetAddressWindow ; (R16, R20, R21) + pop r11 + pop r10 + pop r9 + pop r8 + ldi r16, ILI9341_CMD_RAMWR ; start writing ro RAM + rcall ili9341SendCommand + + mov r22, r10 + mov r23, r11 + cbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS low + sbi ILI9341_DC_OUTPUT, ILI9341_DC_PIN ; D high (DATA) + ldi r17, 2 +ili9341BitBlitStretch2_loopH: + mov r20, xl ; preserve for next run + mov r21, xh + rcall ili9341BitBlitStretchNWriteLine ; (r16, r17, r18, r19, r24, r25, X) + mov xl, r20 + mov xh, r21 + rcall ili9341BitBlitStretchNWriteLine ; (r16, r17, r18, r19, r24, r25, X) + mov r24, r22 + mov r25, r23 + sbiw r25:r24, 1 + mov r22, r24 + mov r23, r25 + brne ili9341BitBlitStretch2_loopH + sbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS high + rcall ili9341EndSpi ; (R16) + out SREG, r15 + pop r15 + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine ili9341BitBlitStretch4 + +; @param r5:r4 X (dest) +; @param r7:r6 Y (dest) +; @param r9:r8 W +; @param r11:r10 H +; @param X source data pointer (RAM) +; @clobbers r16, r22, r23, r24, r25, X (r17, r20, r21) + +ili9341BitBlitStretch4: + push r15 + in r15, SREG + cli + + push r8 + push r9 + push r10 + push r11 + ; width + lsl r8 ; x2 + rol r9 + lsl r8 ; x4 + rol r9 + ; height + lsl r10 ; x2 + rol r11 + lsl r10 ; x4 + rol r11 + + rcall ili9341BeginSpi ; (r16, r17) + rcall ili9341SetAddressWindow ; (R16, R20, R21) + pop r11 + pop r10 + pop r9 + pop r8 + ldi r16, ILI9341_CMD_RAMWR ; start writing ro RAM + rcall ili9341SendCommand + + mov r22, r10 + mov r23, r11 + ldi r17, 4 + cbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS low + sbi ILI9341_DC_OUTPUT, ILI9341_DC_PIN ; D high (DATA) +ili9341BitBlitStretch4_loopH: + mov r20, xl ; preserve for next run + mov r21, xh + rcall ili9341BitBlitStretchNWriteLine ; (r16, r17, r18, r19, r24, r25, X) + mov xl, r20 + mov xh, r21 + rcall ili9341BitBlitStretchNWriteLine ; (r16, r17, r18, r19, r24, r25, X) + mov xl, r20 + mov xh, r21 + rcall ili9341BitBlitStretchNWriteLine ; (r16, r17, r18, r19, r24, r25, X) + mov xl, r20 + mov xh, r21 + rcall ili9341BitBlitStretchNWriteLine ; (r16, r17, r18, r19, r24, r25, X) + mov r24, r22 + mov r25, r23 + sbiw r25:r24, 1 + mov r22, r24 + mov r23, r25 + brne ili9341BitBlitStretch4_loopH + sbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS high + rcall ili9341EndSpi ; (R16) + out SREG, r15 + pop r15 + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine ili9341BitBlitStretchNWriteLine + +; @param r9:r8 width +; @param r17 repeat factor +; @param X source position of line +; @clobbers r16, r17, r18, r19, r24, r25, X + +ili9341BitBlitStretchNWriteLine: + mov r24, r8 + mov r25, r9 +ili9341BitBlitStretchNWriteLine_loop1: + ld r18, X+ + ld r19, X+ + push r17 +ili9341BitBlitStretchNWriteLine_loop2: + mov r16, r19 + rcall SPIHW_MasterTransfer ; (R16) + mov r16, r18 + rcall SPIHW_MasterTransfer ; (R16) + dec r17 + brne ili9341BitBlitStretchNWriteLine_loop2 + pop r17 + sbiw r25:r24, 1 + brne ili9341BitBlitStretchNWriteLine_loop1 + ret +; @end + + + ; --------------------------------------------------------------------------- ; @routine ili9341_WriteCharacterX1At @@ -374,215 +603,96 @@ ili9341SetAddressWindow: ; @clobbers r16, r17, r18, r19, r24, r25, x, z ili9341_WriteCharacterX1At: + ; render character push xl push xh - rcall ili9341WriteCharacterFromFont8x8x1 ; (r17, r24, r25, x, z) + rcall ili9341WriteCharacterFromFont8x8 ; (r17, r24, r25, x, z) pop xh pop xl - ldi r17, 7 - ; calc X1 - mov r8, r4 - mov r9, r5 - add r8, r17 - adc r9, r17 - sub r9, r17 - ; calc Y1 - mov r10, r6 - mov r11, r7 - add r10, r17 - adc r11, r17 - sub r11, r17 - - rcall ili9341BeginSpi ; (r16, r17) - rcall ili9341SetAddressWindow ; (R16) - ldi r16, 8 ; increment X pos for next char - add r4, r16 - adc r5, r16 - sub r5, r16 + ; set width and height + ldi r16, 8 + mov r8, r16 + clr r9 + mov r10, r16 + clr r11 - ldi r16, ILI9341_CMD_RAMWR ; start writing ro RAM - rcall ili9341SendCommand - ldi r17, 64 ; 8x8 -ili9341_WriteCharacterX1At_loop: - ld r18, X+ - ld r19, X+ - rcall ili9341Send16BitData - dec r17 - brne ili9341_WriteCharacterX1At_loop - rcall ili9341EndSpi - ret + rjmp ili9341BitBlit ; @end + ; --------------------------------------------------------------------------- ; @routine ili9341_WriteCharacterX2At -; @param R16 character to write -; @param r5:r4 X -; @param r7:r6 Y -; @param r1:r0 background color -; @param r3:r2 foreground color -; @param Z pointer to font -; @param X pointer to RAM to store data to +; @param R16 character to write +; @param r5:r4 X +; @param r7:r6 Y +; @param r1:r0 background color +; @param r3:r2 foreground color +; @param Z pointer to font +; @param X pointer to RAM to store data to +; @return r5:r4 new X (advanced by character width) ; @clobbers r16, r17, r18, r19, r24, r25, x, z ili9341_WriteCharacterX2At: + ; render character push xl push xh - rcall ili9341WriteCharacterFromFont8x8x2 ; (r17, r24, r25, x, z) + rcall ili9341WriteCharacterFromFont8x8 ; (r17, r24, r25, x, z) pop xh pop xl - ldi r17, 15 - ; calc X1 - mov r8, r4 - mov r9, r5 - add r8, r17 - adc r9, r17 - sub r9, r17 - ; calc Y1 - mov r10, r6 - mov r11, r7 - add r10, r17 - adc r11, r17 - sub r11, r17 - - rcall ili9341BeginSpi ; (r16, r17) - rcall ili9341SetAddressWindow ; (R16) - ldi r16, 16 ; increment X pos for next char - add r4, r16 - adc r5, r16 - sub r5, r16 - ldi r16, ILI9341_CMD_RAMWR ; start writing ro RAM - rcall ili9341SendCommand - ldi r17, 0 ; 256 bytes -ili9341_WriteCharacterX2At_loop: - ld r18, X+ - ld r19, X+ - rcall ili9341Send16BitData - dec r17 - brne ili9341_WriteCharacterX2At_loop - rcall ili9341EndSpi - ret + ; set width and height + ldi r16, 8 + mov r8, r16 + clr r9 + mov r10, r8 + clr r11 + + rjmp ili9341BitBlitStretch2 ; @end ; --------------------------------------------------------------------------- -; @routine ili9341WriteCharacterFromFont8x8x1 +; @routine ili9341_WriteCharacterX4At -; @param R16 character to write -; @param R1:R0 background color -; @param R3:R2 foreground color -; @param Z pointer to font -; @param X pointer to RAM to store data to -; @clobbers r17, r24, r25, x, z +; @param R16 character to write +; @param r5:r4 X +; @param r7:r6 Y +; @param r1:r0 background color +; @param r3:r2 foreground color +; @param Z pointer to font +; @param X pointer to RAM to store data to +; @return r5:r4 new X (advanced by character width) +; @clobbers r16, r17, r18, r19, r24, r25, x, z -ili9341WriteCharacterFromFont8x8x1: - rcall ili9341GetCharPosInFont8x8 ; (r17, r24, r25, z) - ldi r25, 8 ; 8 bytes -ili9341WriteCharacterFromFont8x8x1_loop1: - ldi r24, 8 ; 8 bits - lpm r17, Z+ -ili9341WriteCharacterFromFont8x8x1_loop2: - lsr r17 - brcs ili9341WriteCharacterFromFont8x8x1_writeForeground - st X+, r0 - st X+, r1 - rjmp ili9341WriteCharacterFromFont8x8x1_loop2end -ili9341WriteCharacterFromFont8x8x1_writeForeground: - st X+, r2 - st X+, r3 -ili9341WriteCharacterFromFont8x8x1_loop2end: - dec r24 - brne ili9341WriteCharacterFromFont8x8x1_loop2 - dec r25 - brne ili9341WriteCharacterFromFont8x8x1_loop1 - ret +ili9341_WriteCharacterX4At: + ; render character + push xl + push xh + rcall ili9341WriteCharacterFromFont8x8 ; (r17, r24, r25, x, z) + pop xh + pop xl + + ; set width and height + ldi r16, 8 + mov r8, r16 + clr r9 + mov r10, r8 + clr r11 + + rjmp ili9341BitBlitStretch4 ; @end -; --------------------------------------------------------------------------- -; @routine ili9341WriteCharacterFromFont8x8x2 - -; @param R16 character to write -; @param R1:R0 background color -; @param R3:R2 foreground color -; @param Z pointer to font -; @param X pointer to RAM to store data to -; @clobbers r17, r22, r23, r24, r25, x, z - -ili9341WriteCharacterFromFont8x8x2: - rcall ili9341GetCharPosInFont8x8 ; (r17, r24, r25, z) - ldi r25, 8 ; 8 bytes -ili9341WriteCharacterFromFont8x8x2_loop1: - ldi r24, 8 ; 8 bits - lpm r17, Z+ -ili9341WriteCharacterFromFont8x8x2_loop2: - lsr r17 - brcs ili9341WriteCharacterFromFont8x8x2_writeForeground - mov r22, r0 - mov r23, r1 - rjmp ili9341WriteCharacterFromFont8x8x2_loop2end -ili9341WriteCharacterFromFont8x8x2_writeForeground: - mov r22, r2 - mov r23, r3 -ili9341WriteCharacterFromFont8x8x2_loop2end: - st X+, r22 - st X+, r23 - st X+, r22 - st X+, r23 - adiw xh:xl, 28 ; move to next row (8*4)-4 - st X+, r22 - st X+, r23 - st X+, r22 - st X+, r23 - sbiw xh:xl, 32 ; move back to previous row - dec r24 - brne ili9341WriteCharacterFromFont8x8x2_loop2 - adiw xh:xl, 32 ; skip next line (we already wrote it) - dec r25 - brne ili9341WriteCharacterFromFont8x8x2_loop1 - ret -; @end -; --------------------------------------------------------------------------- -; @routine ili9341GetCharPosInFont8x8 -; @param R16 character to write -; @param Z pointer to font -; @return Z pointer to begin of char data -; @clobbers r17, r24, r25, z - -ili9341GetCharPosInFont8x8: - mov r24, r16 - lpm r17, Z+ ; first char num - sub r24, r17 - brcc ili9341GetCharPosInFont8x8_firstValueOkay - adiw zh:zl, 1 ; use first char - ret -ili9341GetCharPosInFont8x8_firstValueOkay: - lpm r17, Z+ - cp r24, r17 - brcs ili9341WriteCharacterFromFont8x8_gotPos - ret -ili9341WriteCharacterFromFont8x8_gotPos: - clr r25 - lsl r24 ; R16x8 - rol r25 - lsl r24 - rol r25 - lsl r24 - rol r25 - add zl, r24 - adc zh, r25 - ret -; @end From 229e68077c69b299180f5c032800b210ce61a24e Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Thu, 22 May 2025 01:18:49 +0200 Subject: [PATCH 46/58] ili9341: moved text functions to dedicated source file. --- avr/devices/all/includes.asm | 1 + avr/modules/lcd2/ili9341/main.asm | 132 +++++++----------------------- avr/modules/lcd2/ili9341/text.asm | 125 ++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+), 104 deletions(-) create mode 100644 avr/modules/lcd2/ili9341/text.asm diff --git a/avr/devices/all/includes.asm b/avr/devices/all/includes.asm index 1dc5887..2a765e7 100644 --- a/avr/devices/all/includes.asm +++ b/avr/devices/all/includes.asm @@ -157,6 +157,7 @@ .include "modules/lcd2/ili9341/main.asm" .include "modules/lcd2/ili9341/io_spi.asm" .include "modules/lcd2/ili9341/font8x8.asm" +.include "modules/lcd2/ili9341/text.asm" #endif diff --git a/avr/modules/lcd2/ili9341/main.asm b/avr/modules/lcd2/ili9341/main.asm index 4c91dbf..453e788 100644 --- a/avr/modules/lcd2/ili9341/main.asm +++ b/avr/modules/lcd2/ili9341/main.asm @@ -112,8 +112,23 @@ ILI9341_Init: mov r3, r16 ; set character - ldi r16, 65 - rcall ili9341_WriteCharacterX4At + ldi r16, 'A' + rcall ili9341PrintChar + + ldi r16, 'Q' + rcall ili9341PrintChar + + ldi r16, 'H' + rcall ili9341PrintChar + + ldi r16, 'O' + rcall ili9341PrintChar + + ldi r16, 'M' + rcall ili9341PrintChar + + ldi r16, 'E' + rcall ili9341PrintChar sec ret @@ -121,6 +136,16 @@ ILI9341_Init: +ili9341PrintChar: + push zl + push zh + rcall ili9341_WriteCharacterX4At + pop zh + pop zl + ret + + + ; --------------------------------------------------------------------------- ; @routine ILI9341_Fini @global @@ -433,7 +458,7 @@ ili9341BitBlit_loopW: ; @param r9:r8 W ; @param r11:r10 H ; @param X source data pointer (RAM) -; @clobbers r16, r22, r23, r24, r25, X (r17, r20, r21) +; @clobbers r16, r22, r23, r24, r25, X (r17, r18, r19, r20, r21) ili9341BitBlitStretch2: push r15 @@ -589,107 +614,6 @@ ili9341BitBlitStretchNWriteLine_loop2: -; --------------------------------------------------------------------------- -; @routine ili9341_WriteCharacterX1At - -; @param R16 character to write -; @param r5:r4 X -; @param r7:r6 Y -; @param r1:r0 background color -; @param r3:r2 foreground color -; @param Z pointer to font -; @param X pointer to RAM to store data to -; @return r5:r4 new X (advanced by character width) -; @clobbers r16, r17, r18, r19, r24, r25, x, z - -ili9341_WriteCharacterX1At: - ; render character - push xl - push xh - rcall ili9341WriteCharacterFromFont8x8 ; (r17, r24, r25, x, z) - pop xh - pop xl - - ; set width and height - ldi r16, 8 - mov r8, r16 - clr r9 - mov r10, r16 - clr r11 - - rjmp ili9341BitBlit -; @end - - - - -; --------------------------------------------------------------------------- -; @routine ili9341_WriteCharacterX2At - -; @param R16 character to write -; @param r5:r4 X -; @param r7:r6 Y -; @param r1:r0 background color -; @param r3:r2 foreground color -; @param Z pointer to font -; @param X pointer to RAM to store data to -; @return r5:r4 new X (advanced by character width) -; @clobbers r16, r17, r18, r19, r24, r25, x, z - -ili9341_WriteCharacterX2At: - ; render character - push xl - push xh - rcall ili9341WriteCharacterFromFont8x8 ; (r17, r24, r25, x, z) - pop xh - pop xl - - ; set width and height - ldi r16, 8 - mov r8, r16 - clr r9 - mov r10, r8 - clr r11 - - rjmp ili9341BitBlitStretch2 -; @end - - - -; --------------------------------------------------------------------------- -; @routine ili9341_WriteCharacterX4At - -; @param R16 character to write -; @param r5:r4 X -; @param r7:r6 Y -; @param r1:r0 background color -; @param r3:r2 foreground color -; @param Z pointer to font -; @param X pointer to RAM to store data to -; @return r5:r4 new X (advanced by character width) -; @clobbers r16, r17, r18, r19, r24, r25, x, z - -ili9341_WriteCharacterX4At: - ; render character - push xl - push xh - rcall ili9341WriteCharacterFromFont8x8 ; (r17, r24, r25, x, z) - pop xh - pop xl - - ; set width and height - ldi r16, 8 - mov r8, r16 - clr r9 - mov r10, r8 - clr r11 - - rjmp ili9341BitBlitStretch4 -; @end - - - - diff --git a/avr/modules/lcd2/ili9341/text.asm b/avr/modules/lcd2/ili9341/text.asm new file mode 100644 index 0000000..08f264d --- /dev/null +++ b/avr/modules/lcd2/ili9341/text.asm @@ -0,0 +1,125 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + +; *************************************************************************** +; code + +.cseg + + + +; --------------------------------------------------------------------------- +; @routine ili9341_WriteCharacterX1At + +; @param R16 character to write +; @param r5:r4 X +; @param r7:r6 Y +; @param r1:r0 background color +; @param r3:r2 foreground color +; @param Z pointer to font +; @param X pointer to RAM to store data to +; @return r5:r4 new X (advanced by character width) +; @clobbers r16 (r17, r20, r21, r22, r23, r24, r25, X) + +ili9341_WriteCharacterX1At: + rcall ili9341PrepareCharFromFont ; (r16, r17, r24, r25, z) + rcall ili9341BitBlit ; (r16, r17, r20, r21, r22, r23, r24, r25, X) + ldi r16, 8 + add r4, r16 + adc r5, r16 + sub r5, r16 + ret +; @end + + + + +; --------------------------------------------------------------------------- +; @routine ili9341_WriteCharacterX2At + +; @param R16 character to write +; @param r5:r4 X +; @param r7:r6 Y +; @param r1:r0 background color +; @param r3:r2 foreground color +; @param Z pointer to font +; @param X pointer to RAM to store data to +; @return r5:r4 new X (advanced by character width) +; @clobbers r16 (r17, r18, r19, r20, r21, r22, r23, r24, r25, X) + +ili9341_WriteCharacterX2At: + rcall ili9341PrepareCharFromFont ; (r16, r17, r24, r25, z) + rcall ili9341BitBlitStretch2 ; (r16, r17, r18, r19, r20, r21, r22, r23, r24, r25, X) + ldi r16, 16 + add r4, r16 + adc r5, r16 + sub r5, r16 + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine ili9341_WriteCharacterX4At + +; @param R16 character to write +; @param r5:r4 X +; @param r7:r6 Y +; @param r1:r0 background color +; @param r3:r2 foreground color +; @param Z pointer to font +; @param X pointer to RAM to store data to +; @return r5:r4 new X (advanced by character width) +; @clobbers r16, r17, r18, r19, r24, r25, x, z + +ili9341_WriteCharacterX4At: + rcall ili9341PrepareCharFromFont ; (r16, r17, r24, r25, z) + rcall ili9341BitBlitStretch4 + ldi r16, 32 + add r4, r16 + adc r5, r16 + sub r5, r16 + ret +; @end + + + + + +; --------------------------------------------------------------------------- +; @routine ili9341PrepareCharFromFont + +; @param R16 character to write +; @param Z pointer to font +; @param X pointer to RAM to store data to +; @param r9:r8 character width in points +; @param r11:r10 character height in points +; @clobbers r16 (r17, r24, r25, z) + +ili9341PrepareCharFromFont: + ; render character + push xl + push xh + rcall ili9341WriteCharacterFromFont8x8 ; (r17, r24, r25, x, z) + pop xh + pop xl + + ; set width and height + ldi r16, 8 + mov r8, r16 + clr r9 + mov r10, r16 + clr r11 + + ret +; @end + + + From a4975038b4a5e72995320a362d907984a9fefef2 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Thu, 22 May 2025 15:57:03 +0200 Subject: [PATCH 47/58] more generalisation of font code. --- avr/devices/all/includes.asm | 5 +- avr/devices/c01/main/main.asm | 3 +- avr/modules/lcd2/font/0BUILD | 13 ++++ avr/modules/lcd2/font/defs.asm | 20 ++++++ avr/modules/lcd2/font/font1.asm | 100 +++++++++++++++++++++++++++ avr/modules/lcd2/font/font8x8.asm | 97 ++++++++++++++++++++++++++ avr/modules/lcd2/ili9341/font1.asm | 72 ------------------- avr/modules/lcd2/ili9341/font8x8.asm | 88 ----------------------- avr/modules/lcd2/ili9341/main.asm | 28 +++----- avr/modules/lcd2/ili9341/text.asm | 61 +++++++++------- 10 files changed, 282 insertions(+), 205 deletions(-) create mode 100644 avr/modules/lcd2/font/0BUILD create mode 100644 avr/modules/lcd2/font/defs.asm create mode 100644 avr/modules/lcd2/font/font1.asm create mode 100644 avr/modules/lcd2/font/font8x8.asm delete mode 100644 avr/modules/lcd2/ili9341/font1.asm delete mode 100644 avr/modules/lcd2/ili9341/font8x8.asm diff --git a/avr/devices/all/includes.asm b/avr/devices/all/includes.asm index 2a765e7..05c8aa6 100644 --- a/avr/devices/all/includes.asm +++ b/avr/devices/all/includes.asm @@ -156,10 +156,13 @@ .include "modules/lcd2/ili9341/defs.asm" .include "modules/lcd2/ili9341/main.asm" .include "modules/lcd2/ili9341/io_spi.asm" -.include "modules/lcd2/ili9341/font8x8.asm" .include "modules/lcd2/ili9341/text.asm" #endif +#ifdef MODULES_FONT_8X8 +.include "modules/lcd2/font/defs.asm" +.include "modules/lcd2/font/font8x8.asm" +#endif #ifdef APPS_MOTION diff --git a/avr/devices/c01/main/main.asm b/avr/devices/c01/main/main.asm index 0ee6818..c04c61e 100644 --- a/avr/devices/c01/main/main.asm +++ b/avr/devices/c01/main/main.asm @@ -54,6 +54,7 @@ #define MODULES_UART_HW #define MODULES_SPI_HW #define MODULES_ILI9341 +#define MODULES_FONT_8X8 ;#define MODULES_UART_BITBANG ;#define MODULES_TWI_MASTER ;#define MODULES_LCD @@ -202,7 +203,7 @@ onEveryLoop: .include "devices/all/hw_m8515.asm" .include "devices/all/includes.asm" -;.include "common/debug.asm" +.include "common/debug.asm" diff --git a/avr/modules/lcd2/font/0BUILD b/avr/modules/lcd2/font/0BUILD new file mode 100644 index 0000000..5a13d9c --- /dev/null +++ b/avr/modules/lcd2/font/0BUILD @@ -0,0 +1,13 @@ + + + + + + defs.asm + font8x8.asm + font1.asm + + + + + diff --git a/avr/modules/lcd2/font/defs.asm b/avr/modules/lcd2/font/defs.asm new file mode 100644 index 0000000..4f86f91 --- /dev/null +++ b/avr/modules/lcd2/font/defs.asm @@ -0,0 +1,20 @@ +; *************************************************************************** +; 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 FONT_OFFS_RENDERFN_LOW = 0 +.equ FONT_OFFS_RENDERFN_HI = 1 +.equ FONT_OFFS_DATASIZE = 2 ; one byte used, one byte reserved +.equ FONT_OFFS_WIDTH = 4 +.equ FONT_OFFS_HEIGHT = 5 +.equ FONT_OFFS_FIRSTCHAR = 6 +.equ FONT_OFFS_NUMCHARS = 7 + + diff --git a/avr/modules/lcd2/font/font1.asm b/avr/modules/lcd2/font/font1.asm new file mode 100644 index 0000000..4fdac2c --- /dev/null +++ b/avr/modules/lcd2/font/font1.asm @@ -0,0 +1,100 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + +; *************************************************************************** +; This is a font from the project LCD_fonts at +; https://github.com/basti79/LCD-fonts.git +; which in turn is based on a post by Benedikt K. in a forum post on +; https://www.mikrocontroller.net/topic/54860 +; *************************************************************************** + + + +; *************************************************************************** +; code + +.cseg + + + +font1_8x8: +; header + rjmp font8x8MonoRenderCharacter ; renderFn + .db 128, 0 ; needed buffer size + .db 8, 8 ; width, height of chars + .db 32, 64 ; first char, num of chars in font +; data + .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, ; 0x20 + .db 0x0C,0x1E,0x1E,0x0C,0x0C,0x00,0x0C,0x00, ; 0x21 + .db 0x36,0x36,0x36,0x00,0x00,0x00,0x00,0x00, ; 0x22 + .db 0x36,0x36,0x7F,0x36,0x7F,0x36,0x36,0x00, ; 0x23 + .db 0x0C,0x3E,0x03,0x1E,0x30,0x1F,0x0C,0x00, ; 0x24 + .db 0x00,0x63,0x33,0x18,0x0C,0x66,0x63,0x00, ; 0x25 + .db 0x1C,0x36,0x1C,0x6E,0x3B,0x33,0x6E,0x00, ; 0x26 + .db 0x06,0x06,0x03,0x00,0x00,0x00,0x00,0x00, ; 0x27 + .db 0x18,0x0C,0x06,0x06,0x06,0x0C,0x18,0x00, ; 0x28 + .db 0x06,0x0C,0x18,0x18,0x18,0x0C,0x06,0x00, ; 0x29 + .db 0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00, ; 0x2A + .db 0x00,0x0C,0x0C,0x3F,0x0C,0x0C,0x00,0x00, ; 0x2B + .db 0x00,0x00,0x00,0x00,0x00,0x0E,0x0C,0x06, ; 0x2C + .db 0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00, ; 0x2D + .db 0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x00, ; 0x2E + .db 0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00, ; 0x2F + .db 0x1E,0x33,0x3B,0x3F,0x37,0x33,0x1E,0x00, ; 0x30 + .db 0x0C,0x0F,0x0C,0x0C,0x0C,0x0C,0x3F,0x00, ; 0x31 + .db 0x1E,0x33,0x30,0x1C,0x06,0x33,0x3F,0x00, ; 0x32 + .db 0x1E,0x33,0x30,0x1C,0x30,0x33,0x1E,0x00, ; 0x33 + .db 0x38,0x3C,0x36,0x33,0x7F,0x30,0x30,0x00, ; 0x34 + .db 0x3F,0x03,0x1F,0x30,0x30,0x33,0x1E,0x00, ; 0x35 + .db 0x1C,0x06,0x03,0x1F,0x33,0x33,0x1E,0x00, ; 0x36 + .db 0x3F,0x33,0x30,0x18,0x0C,0x06,0x06,0x00, ; 0x37 + .db 0x1E,0x33,0x33,0x1E,0x33,0x33,0x1E,0x00, ; 0x38 + .db 0x1E,0x33,0x33,0x3E,0x30,0x18,0x0E,0x00, ; 0x39 + .db 0x00,0x00,0x0C,0x0C,0x00,0x0C,0x0C,0x00, ; 0x3A + .db 0x00,0x00,0x0C,0x0C,0x00,0x0E,0x0C,0x06, ; 0x3B + .db 0x18,0x0C,0x06,0x03,0x06,0x0C,0x18,0x00, ; 0x3C + .db 0x00,0x00,0x3F,0x00,0x3F,0x00,0x00,0x00, ; 0x3D + .db 0x06,0x0C,0x18,0x30,0x18,0x0C,0x06,0x00, ; 0x3E + .db 0x1E,0x33,0x30,0x18,0x0C,0x00,0x0C,0x00, ; 0x3F + .db 0x3E,0x63,0x7B,0x7B,0x7B,0x03,0x1E,0x00, ; 0x40 + .db 0x0C,0x1E,0x33,0x33,0x3F,0x33,0x33,0x00, ; 0x41 + .db 0x3F,0x66,0x66,0x3E,0x66,0x66,0x3F,0x00, ; 0x42 + .db 0x3C,0x66,0x03,0x03,0x03,0x66,0x3C,0x00, ; 0x43 + .db 0x3F,0x36,0x66,0x66,0x66,0x36,0x3F,0x00, ; 0x44 + .db 0x7F,0x46,0x16,0x1E,0x16,0x46,0x7F,0x00, ; 0x45 + .db 0x7F,0x46,0x16,0x1E,0x16,0x06,0x0F,0x00, ; 0x46 + .db 0x3C,0x66,0x03,0x03,0x73,0x66,0x7C,0x00, ; 0x47 + .db 0x33,0x33,0x33,0x3F,0x33,0x33,0x33,0x00, ; 0x48 + .db 0x1E,0x0C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00, ; 0x49 + .db 0x78,0x30,0x30,0x30,0x33,0x33,0x1E,0x00, ; 0x4A + .db 0x67,0x66,0x36,0x1E,0x36,0x66,0x67,0x00, ; 0x4B + .db 0x0F,0x06,0x06,0x06,0x46,0x66,0x7F,0x00, ; 0x4C + .db 0x63,0x77,0x7F,0x6B,0x63,0x63,0x63,0x00, ; 0x4D + .db 0x63,0x67,0x6F,0x7B,0x73,0x63,0x63,0x00, ; 0x4E + .db 0x1C,0x36,0x63,0x63,0x63,0x36,0x1C,0x00, ; 0x4F + .db 0x3F,0x66,0x66,0x3E,0x06,0x06,0x0F,0x00, ; 0x50 + .db 0x1E,0x33,0x33,0x33,0x3B,0x1E,0x38,0x00, ; 0x51 + .db 0x3F,0x66,0x66,0x3E,0x1E,0x36,0x67,0x00, ; 0x52 + .db 0x1E,0x33,0x07,0x1C,0x38,0x33,0x1E,0x00, ; 0x53 + .db 0x3F,0x2D,0x0C,0x0C,0x0C,0x0C,0x1E,0x00, ; 0x54 + .db 0x33,0x33,0x33,0x33,0x33,0x33,0x3F,0x00, ; 0x55 + .db 0x33,0x33,0x33,0x33,0x33,0x1E,0x0C,0x00, ; 0x56 + .db 0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00, ; 0x57 + .db 0x63,0x63,0x36,0x1C,0x36,0x63,0x63,0x00, ; 0x58 + .db 0x33,0x33,0x33,0x1E,0x0C,0x0C,0x1E,0x00, ; 0x59 + .db 0x7F,0x33,0x19,0x0C,0x46,0x63,0x7F,0x00, ; 0x5A + .db 0x1E,0x06,0x06,0x06,0x06,0x06,0x1E,0x00, ; 0x5B + .db 0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00, ; 0x5C + .db 0x1E,0x18,0x18,0x18,0x18,0x18,0x1E,0x00, ; 0x5D + .db 0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, ; 0x5E + .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF ; 0x5F + + + diff --git a/avr/modules/lcd2/font/font8x8.asm b/avr/modules/lcd2/font/font8x8.asm new file mode 100644 index 0000000..8f1bae2 --- /dev/null +++ b/avr/modules/lcd2/font/font8x8.asm @@ -0,0 +1,97 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + +; *************************************************************************** +; code + +.cseg + + + + +; --------------------------------------------------------------------------- +; @routine font8x8RenderCharacter + +; @param R16 character to write +; @param R1:R0 background color +; @param R3:R2 foreground color +; @param Z pointer to font +; @param X pointer to RAM to store data to +; @param r18 char width in pixel +; @param r19 char height in pixel +; @clobbers r17, r24, r25, x + +font8x8MonoRenderCharacter: + push zl + push zh + lsl zl + rol zh + + rcall font8x8GetCharPosInFont8x8 ; (r17, r24, r25, z) + ldi r25, 8 ; 8 bytes +font8x8MonoRenderCharacter_loop1: + ldi r24, 8 ; 8 bits + lpm r17, Z+ +font8x8MonoRenderCharacter_loop2: + lsr r17 + brcs font8x8MonoRenderCharacter_writeForeground + st X+, r0 + st X+, r1 + rjmp font8x8MonoRenderCharacter_loop2end +font8x8MonoRenderCharacter_writeForeground: + st X+, r2 + st X+, r3 +font8x8MonoRenderCharacter_loop2end: + dec r24 + brne font8x8MonoRenderCharacter_loop2 + dec r25 + brne font8x8MonoRenderCharacter_loop1 + ldi r18, 8 + ldi r19, 8 + pop zh + pop zl + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine font8x8GetCharPosInFont8x8 + +; @param R16 character to write +; @param Z pointer to font +; @return Z pointer to begin of char data +; @clobbers r17, r24, r25, z + +font8x8GetCharPosInFont8x8: + mov r24, r16 + adiw zh:zl, FONT_OFFS_FIRSTCHAR + lpm r24, Z+ ; first char num + lpm r25, Z+ ; num of chars + sub r16, r24 + brcs font8x8GetCharPosInFont8x8_ret + cp r16, r25 + brcc font8x8GetCharPosInFont8x8_ret + mov r24, r16 + clr r25 + lsl r24 ; x2 + rol r25 + lsl r24 ; x4 + rol r25 + lsl r24 ; x8 + rol r25 + add zl, r24 + adc zh, r25 +font8x8GetCharPosInFont8x8_ret: + ret +; @end + + + diff --git a/avr/modules/lcd2/ili9341/font1.asm b/avr/modules/lcd2/ili9341/font1.asm deleted file mode 100644 index a1c3b69..0000000 --- a/avr/modules/lcd2/ili9341/font1.asm +++ /dev/null @@ -1,72 +0,0 @@ - - - -font8x8: -.db 32, 64 -.db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, ; 0x20 -.db 0x0C,0x1E,0x1E,0x0C,0x0C,0x00,0x0C,0x00, ; 0x21 -.db 0x36,0x36,0x36,0x00,0x00,0x00,0x00,0x00, ; 0x22 -.db 0x36,0x36,0x7F,0x36,0x7F,0x36,0x36,0x00, ; 0x23 -.db 0x0C,0x3E,0x03,0x1E,0x30,0x1F,0x0C,0x00, ; 0x24 -.db 0x00,0x63,0x33,0x18,0x0C,0x66,0x63,0x00, ; 0x25 -.db 0x1C,0x36,0x1C,0x6E,0x3B,0x33,0x6E,0x00, ; 0x26 -.db 0x06,0x06,0x03,0x00,0x00,0x00,0x00,0x00, ; 0x27 -.db 0x18,0x0C,0x06,0x06,0x06,0x0C,0x18,0x00, ; 0x28 -.db 0x06,0x0C,0x18,0x18,0x18,0x0C,0x06,0x00, ; 0x29 -.db 0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00, ; 0x2A -.db 0x00,0x0C,0x0C,0x3F,0x0C,0x0C,0x00,0x00, ; 0x2B -.db 0x00,0x00,0x00,0x00,0x00,0x0E,0x0C,0x06, ; 0x2C -.db 0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00, ; 0x2D -.db 0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x00, ; 0x2E -.db 0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00, ; 0x2F -.db 0x1E,0x33,0x3B,0x3F,0x37,0x33,0x1E,0x00, ; 0x30 -.db 0x0C,0x0F,0x0C,0x0C,0x0C,0x0C,0x3F,0x00, ; 0x31 -.db 0x1E,0x33,0x30,0x1C,0x06,0x33,0x3F,0x00, ; 0x32 -.db 0x1E,0x33,0x30,0x1C,0x30,0x33,0x1E,0x00, ; 0x33 -.db 0x38,0x3C,0x36,0x33,0x7F,0x30,0x30,0x00, ; 0x34 -.db 0x3F,0x03,0x1F,0x30,0x30,0x33,0x1E,0x00, ; 0x35 -.db 0x1C,0x06,0x03,0x1F,0x33,0x33,0x1E,0x00, ; 0x36 -.db 0x3F,0x33,0x30,0x18,0x0C,0x06,0x06,0x00, ; 0x37 -.db 0x1E,0x33,0x33,0x1E,0x33,0x33,0x1E,0x00, ; 0x38 -.db 0x1E,0x33,0x33,0x3E,0x30,0x18,0x0E,0x00, ; 0x39 -.db 0x00,0x00,0x0C,0x0C,0x00,0x0C,0x0C,0x00, ; 0x3A -.db 0x00,0x00,0x0C,0x0C,0x00,0x0E,0x0C,0x06, ; 0x3B -.db 0x18,0x0C,0x06,0x03,0x06,0x0C,0x18,0x00, ; 0x3C -.db 0x00,0x00,0x3F,0x00,0x3F,0x00,0x00,0x00, ; 0x3D -.db 0x06,0x0C,0x18,0x30,0x18,0x0C,0x06,0x00, ; 0x3E -.db 0x1E,0x33,0x30,0x18,0x0C,0x00,0x0C,0x00, ; 0x3F -.db 0x3E,0x63,0x7B,0x7B,0x7B,0x03,0x1E,0x00, ; 0x40 -.db 0x0C,0x1E,0x33,0x33,0x3F,0x33,0x33,0x00, ; 0x41 -.db 0x3F,0x66,0x66,0x3E,0x66,0x66,0x3F,0x00, ; 0x42 -.db 0x3C,0x66,0x03,0x03,0x03,0x66,0x3C,0x00, ; 0x43 -.db 0x3F,0x36,0x66,0x66,0x66,0x36,0x3F,0x00, ; 0x44 -.db 0x7F,0x46,0x16,0x1E,0x16,0x46,0x7F,0x00, ; 0x45 -.db 0x7F,0x46,0x16,0x1E,0x16,0x06,0x0F,0x00, ; 0x46 -.db 0x3C,0x66,0x03,0x03,0x73,0x66,0x7C,0x00, ; 0x47 -.db 0x33,0x33,0x33,0x3F,0x33,0x33,0x33,0x00, ; 0x48 -.db 0x1E,0x0C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00, ; 0x49 -.db 0x78,0x30,0x30,0x30,0x33,0x33,0x1E,0x00, ; 0x4A -.db 0x67,0x66,0x36,0x1E,0x36,0x66,0x67,0x00, ; 0x4B -.db 0x0F,0x06,0x06,0x06,0x46,0x66,0x7F,0x00, ; 0x4C -.db 0x63,0x77,0x7F,0x6B,0x63,0x63,0x63,0x00, ; 0x4D -.db 0x63,0x67,0x6F,0x7B,0x73,0x63,0x63,0x00, ; 0x4E -.db 0x1C,0x36,0x63,0x63,0x63,0x36,0x1C,0x00, ; 0x4F -.db 0x3F,0x66,0x66,0x3E,0x06,0x06,0x0F,0x00, ; 0x50 -.db 0x1E,0x33,0x33,0x33,0x3B,0x1E,0x38,0x00, ; 0x51 -.db 0x3F,0x66,0x66,0x3E,0x1E,0x36,0x67,0x00, ; 0x52 -.db 0x1E,0x33,0x07,0x1C,0x38,0x33,0x1E,0x00, ; 0x53 -.db 0x3F,0x2D,0x0C,0x0C,0x0C,0x0C,0x1E,0x00, ; 0x54 -.db 0x33,0x33,0x33,0x33,0x33,0x33,0x3F,0x00, ; 0x55 -.db 0x33,0x33,0x33,0x33,0x33,0x1E,0x0C,0x00, ; 0x56 -.db 0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00, ; 0x57 -.db 0x63,0x63,0x36,0x1C,0x36,0x63,0x63,0x00, ; 0x58 -.db 0x33,0x33,0x33,0x1E,0x0C,0x0C,0x1E,0x00, ; 0x59 -.db 0x7F,0x33,0x19,0x0C,0x46,0x63,0x7F,0x00, ; 0x5A -.db 0x1E,0x06,0x06,0x06,0x06,0x06,0x1E,0x00, ; 0x5B -.db 0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00, ; 0x5C -.db 0x1E,0x18,0x18,0x18,0x18,0x18,0x1E,0x00, ; 0x5D -.db 0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, ; 0x5E -.db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF ; 0x5F - - - diff --git a/avr/modules/lcd2/ili9341/font8x8.asm b/avr/modules/lcd2/ili9341/font8x8.asm deleted file mode 100644 index 04395f4..0000000 --- a/avr/modules/lcd2/ili9341/font8x8.asm +++ /dev/null @@ -1,88 +0,0 @@ -; *************************************************************************** -; 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. * -; *************************************************************************** - - -; *************************************************************************** -; code - -.cseg - - - - -; --------------------------------------------------------------------------- -; @routine ili9341WriteCharacterFromFont8x8 - -; @param R16 character to write -; @param R1:R0 background color -; @param R3:R2 foreground color -; @param Z pointer to font -; @param X pointer to RAM to store data to -; @clobbers r17, r24, r25, x, z - -ili9341WriteCharacterFromFont8x8: - rcall ili9341GetCharPosInFont8x8 ; (r17, r24, r25, z) - ldi r25, 8 ; 8 bytes -ili9341WriteCharacterFromFont8x8_loop1: - ldi r24, 8 ; 8 bits - lpm r17, Z+ -ili9341WriteCharacterFromFont8x8_loop2: - lsr r17 - brcs ili9341WriteCharacterFromFont8x8_writeForeground - st X+, r0 - st X+, r1 - rjmp ili9341WriteCharacterFromFont8x8_loop2end -ili9341WriteCharacterFromFont8x8_writeForeground: - st X+, r2 - st X+, r3 -ili9341WriteCharacterFromFont8x8_loop2end: - dec r24 - brne ili9341WriteCharacterFromFont8x8_loop2 - dec r25 - brne ili9341WriteCharacterFromFont8x8_loop1 - ret -; @end - - - -; --------------------------------------------------------------------------- -; @routine ili9341GetCharPosInFont8x8 - -; @param R16 character to write -; @param Z pointer to font -; @return Z pointer to begin of char data -; @clobbers r17, r24, r25, z - -ili9341GetCharPosInFont8x8: - mov r24, r16 - lpm r17, Z+ ; first char num - sub r24, r17 - brcc ili9341GetCharPosInFont8x8_firstValueOkay - adiw zh:zl, 1 ; use first char - ret -ili9341GetCharPosInFont8x8_firstValueOkay: - lpm r17, Z+ - cp r24, r17 - brcs ili9341WriteCharacterFromFont8x8_gotPos - ret -ili9341WriteCharacterFromFont8x8_gotPos: - clr r25 - lsl r24 ; R16x8 - rol r25 - lsl r24 - rol r25 - lsl r24 - rol r25 - add zl, r24 - adc zh, r25 - ret -; @end - - - diff --git a/avr/modules/lcd2/ili9341/main.asm b/avr/modules/lcd2/ili9341/main.asm index 453e788..04a746f 100644 --- a/avr/modules/lcd2/ili9341/main.asm +++ b/avr/modules/lcd2/ili9341/main.asm @@ -97,8 +97,8 @@ ILI9341_Init: mov r7, r16 ; set font pos - ldi zl, LOW(font8x8*2) - ldi zh, HIGH(font8x8*2) + ldi zl, LOW(font1_8x8) + ldi zh, HIGH(font1_8x8) ; set buffer pos ; ldi xl, LOW(ILI9341_buffer) @@ -113,22 +113,22 @@ ILI9341_Init: ; set character ldi r16, 'A' - rcall ili9341PrintChar + rcall ili9341_WriteCharacterX4At ldi r16, 'Q' - rcall ili9341PrintChar + rcall ili9341_WriteCharacterX4At ldi r16, 'H' - rcall ili9341PrintChar + rcall ili9341_WriteCharacterX4At ldi r16, 'O' - rcall ili9341PrintChar + rcall ili9341_WriteCharacterX4At ldi r16, 'M' - rcall ili9341PrintChar + rcall ili9341_WriteCharacterX4At ldi r16, 'E' - rcall ili9341PrintChar + rcall ili9341_WriteCharacterX4At sec ret @@ -136,16 +136,6 @@ ILI9341_Init: -ili9341PrintChar: - push zl - push zh - rcall ili9341_WriteCharacterX4At - pop zh - pop zl - ret - - - ; --------------------------------------------------------------------------- ; @routine ILI9341_Fini @global @@ -749,6 +739,6 @@ helloWorld: .db "Hello World", 0 -.include "modules/lcd2/ili9341/font1.asm" +.include "modules/lcd2/font/font1.asm" diff --git a/avr/modules/lcd2/ili9341/text.asm b/avr/modules/lcd2/ili9341/text.asm index 08f264d..4d5ef7e 100644 --- a/avr/modules/lcd2/ili9341/text.asm +++ b/avr/modules/lcd2/ili9341/text.asm @@ -23,7 +23,7 @@ ; @param r7:r6 Y ; @param r1:r0 background color ; @param r3:r2 foreground color -; @param Z pointer to font +; @param Z pointer to font (word address!) ; @param X pointer to RAM to store data to ; @return r5:r4 new X (advanced by character width) ; @clobbers r16 (r17, r20, r21, r22, r23, r24, r25, X) @@ -31,10 +31,9 @@ ili9341_WriteCharacterX1At: rcall ili9341PrepareCharFromFont ; (r16, r17, r24, r25, z) rcall ili9341BitBlit ; (r16, r17, r20, r21, r22, r23, r24, r25, X) - ldi r16, 8 - add r4, r16 - adc r5, r16 - sub r5, r16 + ; advance X (add char width to X) + add r4, r8 + adc r5, r9 ret ; @end @@ -49,7 +48,7 @@ ili9341_WriteCharacterX1At: ; @param r7:r6 Y ; @param r1:r0 background color ; @param r3:r2 foreground color -; @param Z pointer to font +; @param Z pointer to font (word address!) ; @param X pointer to RAM to store data to ; @return r5:r4 new X (advanced by character width) ; @clobbers r16 (r17, r18, r19, r20, r21, r22, r23, r24, r25, X) @@ -57,10 +56,11 @@ ili9341_WriteCharacterX1At: ili9341_WriteCharacterX2At: rcall ili9341PrepareCharFromFont ; (r16, r17, r24, r25, z) rcall ili9341BitBlitStretch2 ; (r16, r17, r18, r19, r20, r21, r22, r23, r24, r25, X) - ldi r16, 16 - add r4, r16 - adc r5, r16 - sub r5, r16 + ; advance X (add double char width to X) + lsl r8 ; Wx2 + rol r9 + add r4, r8 ; add to X + adc r5, r9 ret ; @end @@ -74,18 +74,21 @@ ili9341_WriteCharacterX2At: ; @param r7:r6 Y ; @param r1:r0 background color ; @param r3:r2 foreground color -; @param Z pointer to font +; @param Z pointer to font (word address!) ; @param X pointer to RAM to store data to ; @return r5:r4 new X (advanced by character width) ; @clobbers r16, r17, r18, r19, r24, r25, x, z ili9341_WriteCharacterX4At: rcall ili9341PrepareCharFromFont ; (r16, r17, r24, r25, z) - rcall ili9341BitBlitStretch4 - ldi r16, 32 - add r4, r16 - adc r5, r16 - sub r5, r16 + rcall ili9341BitBlitStretch4 ; (r16, r17, r20, r21, r22, r23, r24, r25, X) + ; advance X (add quad char width to X) + lsl r8 ; Wx2 + rol r9 + lsl r8 ; Wx4 + rol r9 + add r4, r8 ; add to X + adc r5, r9 ret ; @end @@ -99,27 +102,37 @@ ili9341_WriteCharacterX4At: ; @param R16 character to write ; @param Z pointer to font ; @param X pointer to RAM to store data to -; @param r9:r8 character width in points -; @param r11:r10 character height in points +; @return r9:r8 character width in points +; @return r11:r10 character height in points ; @clobbers r16 (r17, r24, r25, z) ili9341PrepareCharFromFont: ; render character push xl push xh - rcall ili9341WriteCharacterFromFont8x8 ; (r17, r24, r25, x, z) + ; call render function of the selected font (first word of font is jmp to render function) + rcall ili9341JumpToFontRenderFn ; (r17, r24, r25, x, z) pop xh pop xl - ; set width and height - ldi r16, 8 - mov r8, r16 + ; set src width and height + mov r8, r18 clr r9 - mov r10, r16 + mov r10, r19 clr r11 - ret ; @end +; --------------------------------------------------------------------------- +; @routine ili9341JumpToFontRenderFn +; +; helper function to call function at the beginning of the given font + +ili9341JumpToFontRenderFn: + ijmp +; @end + + + From 7d233136ebcbea2d6701464d80f78c54d89194e3 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Thu, 22 May 2025 16:29:55 +0200 Subject: [PATCH 48/58] moved graphops into a dedicated sourcefile. --- avr/devices/all/includes.asm | 1 + avr/modules/lcd2/font/font1.asm | 2 +- avr/modules/lcd2/font/font8x8.asm | 3 - avr/modules/lcd2/ili9341/graphops.asm | 337 ++++++++++++++++++++++++++ avr/modules/lcd2/ili9341/main.asm | 320 +----------------------- avr/modules/lcd2/ili9341/text.asm | 24 +- 6 files changed, 356 insertions(+), 331 deletions(-) create mode 100644 avr/modules/lcd2/ili9341/graphops.asm diff --git a/avr/devices/all/includes.asm b/avr/devices/all/includes.asm index 05c8aa6..48c95e0 100644 --- a/avr/devices/all/includes.asm +++ b/avr/devices/all/includes.asm @@ -156,6 +156,7 @@ .include "modules/lcd2/ili9341/defs.asm" .include "modules/lcd2/ili9341/main.asm" .include "modules/lcd2/ili9341/io_spi.asm" +.include "modules/lcd2/ili9341/graphops.asm" .include "modules/lcd2/ili9341/text.asm" #endif diff --git a/avr/modules/lcd2/font/font1.asm b/avr/modules/lcd2/font/font1.asm index 4fdac2c..25a04de 100644 --- a/avr/modules/lcd2/font/font1.asm +++ b/avr/modules/lcd2/font/font1.asm @@ -26,7 +26,7 @@ font1_8x8: ; header - rjmp font8x8MonoRenderCharacter ; renderFn + .dw font8x8MonoRenderCharacter ; renderFn .db 128, 0 ; needed buffer size .db 8, 8 ; width, height of chars .db 32, 64 ; first char, num of chars in font diff --git a/avr/modules/lcd2/font/font8x8.asm b/avr/modules/lcd2/font/font8x8.asm index 8f1bae2..f33a2dc 100644 --- a/avr/modules/lcd2/font/font8x8.asm +++ b/avr/modules/lcd2/font/font8x8.asm @@ -31,9 +31,6 @@ font8x8MonoRenderCharacter: push zl push zh - lsl zl - rol zh - rcall font8x8GetCharPosInFont8x8 ; (r17, r24, r25, z) ldi r25, 8 ; 8 bytes font8x8MonoRenderCharacter_loop1: diff --git a/avr/modules/lcd2/ili9341/graphops.asm b/avr/modules/lcd2/ili9341/graphops.asm new file mode 100644 index 0000000..f280508 --- /dev/null +++ b/avr/modules/lcd2/ili9341/graphops.asm @@ -0,0 +1,337 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + +; --------------------------------------------------------------------------- +; @routine ili9341SetAddressWindow +; +; @param r5:r4 X0 +; @param r7:r6 Y0 +; @param r9:r8 W +; @param r11:r10 H +; @clobbers R16, r20, r21 + +ili9341SetAddressWindow: + ; calc XEnd (=X+W-1) + mov r20, r8 + mov r21, r9 + add r20, r4 + adc r21, r5 + subi r20, 1 + sbci r21, 0 + + ; send column address + ldi r16, ILI9341_CMD_CASET + rcall ili9341SendCommand + ; X0 + mov r16, r5 + rcall ili9341SendData + mov r16, r4 + rcall ili9341SendData + ; X1 + mov r16, r21 + rcall ili9341SendData + mov r16, r20 + rcall ili9341SendData + + ; calc YEnd (=Y+H-1) + mov r20, r10 + mov r21, r11 + add r20, r6 + adc r21, r7 + subi r20, 1 + sbci r21, 0 + + ; send row address + ldi r16, ILI9341_CMD_PASET + rcall ili9341SendCommand + ; Y0 + mov r16, r7 + rcall ili9341SendData + mov r16, r6 + rcall ili9341SendData + ; Y1 + mov r16, r21 + rcall ili9341SendData + mov r16, r20 + rcall ili9341SendData + + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine ILI9341_FillRect +; @param r3:r2 color +; @param r5:r4 X0 +; @param r7:r6 Y0 +; @param r9:r8 X1/W +; @param r11:r10 Y1/H + +ILI9341_FillRect: + push r15 + in r15, SREG + cli + + rcall ili9341BeginSpi ; (R16, R17) + rcall ili9341SetAddressWindow ; (R16, r20, r21) + + mov r18, r2 ; color + mov r19, r3 + mov r22, r10 ; H low + mov r23, r11 ; H high + ldi r16, ILI9341_CMD_RAMWR ; start writing ro RAM + rcall ili9341SendCommand + + cbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS low + sbi ILI9341_DC_OUTPUT, ILI9341_DC_PIN ; D high (DATA) +ILI9341_FillRect_loopH: + mov r24, r8 ; W low + mov r25, r9 ; W high +ILI9341_FillRect_loopW: + mov r16, r19 + rcall SPIHW_MasterTransfer + mov r16, r18 + rcall SPIHW_MasterTransfer + sbiw r25:r24, 1 + brne ILI9341_FillRect_loopW + mov r24, r22 ; H low + mov r25, r23 ; H high + sbiw r25:r24, 1 ; dec + mov r22, r24 ; save in r23:r22 + mov r23, r25 + brne ILI9341_FillRect_loopH + sbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS high + rcall ili9341EndSpi + out SREG, r15 + pop r15 + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine ili9341BitBlit + +; @param r5:r4 X (dest) +; @param r7:r6 Y (dest) +; @param r9:r8 W +; @param r11:r10 H +; @param X source data pointer (RAM) +; @clobbers r16, r22, r23, r24, r25, X (r17, r20, r21) + +ili9341BitBlit: + push r15 + in r15, SREG + cli + + rcall ili9341BeginSpi ; (r16, r17) + rcall ili9341SetAddressWindow ; (R16, R20, R21) + + ldi r16, ILI9341_CMD_RAMWR ; start writing ro RAM + rcall ili9341SendCommand + + mov r22, r10 + mov r23, r11 + cbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS low + sbi ILI9341_DC_OUTPUT, ILI9341_DC_PIN ; D high (DATA) +ili9341BitBlit_loopH: + mov r24, r8 + mov r25, r9 +ili9341BitBlit_loopW: + ld r18, X+ + ld r19, X+ + mov r16, r19 + rcall SPIHW_MasterTransfer ; (R16) + mov r16, r18 + rcall SPIHW_MasterTransfer ; (R16) + sbiw r25:r24, 1 + brne ili9341BitBlit_loopW + mov r24, r22 + mov r25, r23 + sbiw r25:r24, 1 + mov r22, r24 + mov r23, r25 + brne ili9341BitBlit_loopH + sbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS high + rcall ili9341EndSpi ; (R16) + out SREG, r15 + pop r15 + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine ili9341BitBlitStretch2 + +; @param r5:r4 X (dest) +; @param r7:r6 Y (dest) +; @param r9:r8 W +; @param r11:r10 H +; @param X source data pointer (RAM) +; @clobbers r16, r22, r23, r24, r25, X (r17, r18, r19, r20, r21) + +ili9341BitBlitStretch2: + push r15 + in r15, SREG + cli + + push r8 + push r9 + push r10 + push r11 + ; width + lsl r8 ; x2 + rol r9 + ; height + lsl r10 ; x2 + rol r11 + + rcall ili9341BeginSpi ; (r16, r17) + rcall ili9341SetAddressWindow ; (R16, R20, R21) + pop r11 + pop r10 + pop r9 + pop r8 + ldi r16, ILI9341_CMD_RAMWR ; start writing ro RAM + rcall ili9341SendCommand + + mov r22, r10 + mov r23, r11 + cbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS low + sbi ILI9341_DC_OUTPUT, ILI9341_DC_PIN ; D high (DATA) + ldi r17, 2 +ili9341BitBlitStretch2_loopH: + mov r20, xl ; preserve for next run + mov r21, xh + rcall ili9341BitBlitStretchNWriteLine ; (r16, r17, r18, r19, r24, r25, X) + mov xl, r20 + mov xh, r21 + rcall ili9341BitBlitStretchNWriteLine ; (r16, r17, r18, r19, r24, r25, X) + mov r24, r22 + mov r25, r23 + sbiw r25:r24, 1 + mov r22, r24 + mov r23, r25 + brne ili9341BitBlitStretch2_loopH + sbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS high + rcall ili9341EndSpi ; (R16) + out SREG, r15 + pop r15 + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine ili9341BitBlitStretch4 + +; @param r5:r4 X (dest) +; @param r7:r6 Y (dest) +; @param r9:r8 W +; @param r11:r10 H +; @param X source data pointer (RAM) +; @clobbers r16, r22, r23, r24, r25, X (r17, r20, r21) + +ili9341BitBlitStretch4: + push r15 + in r15, SREG + cli + + push r8 + push r9 + push r10 + push r11 + ; width + lsl r8 ; x2 + rol r9 + lsl r8 ; x4 + rol r9 + ; height + lsl r10 ; x2 + rol r11 + lsl r10 ; x4 + rol r11 + + rcall ili9341BeginSpi ; (r16, r17) + rcall ili9341SetAddressWindow ; (R16, R20, R21) + pop r11 + pop r10 + pop r9 + pop r8 + ldi r16, ILI9341_CMD_RAMWR ; start writing ro RAM + rcall ili9341SendCommand + + mov r22, r10 + mov r23, r11 + ldi r17, 4 + cbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS low + sbi ILI9341_DC_OUTPUT, ILI9341_DC_PIN ; D high (DATA) +ili9341BitBlitStretch4_loopH: + mov r20, xl ; preserve for next run + mov r21, xh + rcall ili9341BitBlitStretchNWriteLine ; (r16, r17, r18, r19, r24, r25, X) + mov xl, r20 + mov xh, r21 + rcall ili9341BitBlitStretchNWriteLine ; (r16, r17, r18, r19, r24, r25, X) + mov xl, r20 + mov xh, r21 + rcall ili9341BitBlitStretchNWriteLine ; (r16, r17, r18, r19, r24, r25, X) + mov xl, r20 + mov xh, r21 + rcall ili9341BitBlitStretchNWriteLine ; (r16, r17, r18, r19, r24, r25, X) + mov r24, r22 + mov r25, r23 + sbiw r25:r24, 1 + mov r22, r24 + mov r23, r25 + brne ili9341BitBlitStretch4_loopH + sbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS high + rcall ili9341EndSpi ; (R16) + out SREG, r15 + pop r15 + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine ili9341BitBlitStretchNWriteLine + +; @param r9:r8 width +; @param r17 repeat factor +; @param X source position of line +; @clobbers r16, r17, r18, r19, r24, r25, X + +ili9341BitBlitStretchNWriteLine: + mov r24, r8 + mov r25, r9 +ili9341BitBlitStretchNWriteLine_loop1: + ld r18, X+ + ld r19, X+ + push r17 +ili9341BitBlitStretchNWriteLine_loop2: + mov r16, r19 + rcall SPIHW_MasterTransfer ; (R16) + mov r16, r18 + rcall SPIHW_MasterTransfer ; (R16) + dec r17 + brne ili9341BitBlitStretchNWriteLine_loop2 + pop r17 + sbiw r25:r24, 1 + brne ili9341BitBlitStretchNWriteLine_loop1 + ret +; @end + + + + + diff --git a/avr/modules/lcd2/ili9341/main.asm b/avr/modules/lcd2/ili9341/main.asm index 04a746f..933e1ba 100644 --- a/avr/modules/lcd2/ili9341/main.asm +++ b/avr/modules/lcd2/ili9341/main.asm @@ -97,8 +97,8 @@ ILI9341_Init: mov r7, r16 ; set font pos - ldi zl, LOW(font1_8x8) - ldi zh, HIGH(font1_8x8) + ldi zl, LOW(font1_8x8*2) + ldi zh, HIGH(font1_8x8*2) ; set buffer pos ; ldi xl, LOW(ILI9341_buffer) @@ -279,328 +279,12 @@ ILI9341_FillScreen: -; --------------------------------------------------------------------------- -; @routine ili9341SetAddressWindow -; -; @param r5:r4 X0 -; @param r7:r6 Y0 -; @param r9:r8 W -; @param r11:r10 H -; @clobbers R16, r20, r21 - -ili9341SetAddressWindow: - ; calc XEnd (=X+W-1) - mov r20, r8 - mov r21, r9 - add r20, r4 - adc r21, r5 - subi r20, 1 - sbci r21, 0 - - ; send column address - ldi r16, ILI9341_CMD_CASET - rcall ili9341SendCommand - ; X0 - mov r16, r5 - rcall ili9341SendData - mov r16, r4 - rcall ili9341SendData - ; X1 - mov r16, r21 - rcall ili9341SendData - mov r16, r20 - rcall ili9341SendData - - ; calc YEnd (=Y+H-1) - mov r20, r10 - mov r21, r11 - add r20, r6 - adc r21, r7 - subi r20, 1 - sbci r21, 0 - - ; send row address - ldi r16, ILI9341_CMD_PASET - rcall ili9341SendCommand - ; Y0 - mov r16, r7 - rcall ili9341SendData - mov r16, r6 - rcall ili9341SendData - ; Y1 - mov r16, r21 - rcall ili9341SendData - mov r16, r20 - rcall ili9341SendData - - ret -; @end -; --------------------------------------------------------------------------- -; @routine ILI9341_FillRect -; @param r3:r2 color -; @param r5:r4 X0 -; @param r7:r6 Y0 -; @param r9:r8 X1/W -; @param r11:r10 Y1/H - -ILI9341_FillRect: - push r15 - in r15, SREG - cli - - rcall ili9341BeginSpi ; (R16, R17) - rcall ili9341SetAddressWindow ; (R16, r20, r21) - - mov r18, r2 ; color - mov r19, r3 - mov r22, r10 ; H low - mov r23, r11 ; H high - ldi r16, ILI9341_CMD_RAMWR ; start writing ro RAM - rcall ili9341SendCommand - - cbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS low - sbi ILI9341_DC_OUTPUT, ILI9341_DC_PIN ; D high (DATA) -ILI9341_FillRect_loopH: - mov r24, r8 ; W low - mov r25, r9 ; W high -ILI9341_FillRect_loopW: - mov r16, r19 - rcall SPIHW_MasterTransfer - mov r16, r18 - rcall SPIHW_MasterTransfer - sbiw r25:r24, 1 - brne ILI9341_FillRect_loopW - mov r24, r22 ; H low - mov r25, r23 ; H high - sbiw r25:r24, 1 ; dec - mov r22, r24 ; save in r23:r22 - mov r23, r25 - brne ILI9341_FillRect_loopH - sbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS high - rcall ili9341EndSpi - out SREG, r15 - pop r15 - ret -; @end -; --------------------------------------------------------------------------- -; @routine ili9341BitBlit - -; @param r5:r4 X (dest) -; @param r7:r6 Y (dest) -; @param r9:r8 W -; @param r11:r10 H -; @param X source data pointer (RAM) -; @clobbers r16, r22, r23, r24, r25, X (r17, r20, r21) - -ili9341BitBlit: - push r15 - in r15, SREG - cli - - rcall ili9341BeginSpi ; (r16, r17) - rcall ili9341SetAddressWindow ; (R16, R20, R21) - - ldi r16, ILI9341_CMD_RAMWR ; start writing ro RAM - rcall ili9341SendCommand - - mov r22, r10 - mov r23, r11 - cbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS low - sbi ILI9341_DC_OUTPUT, ILI9341_DC_PIN ; D high (DATA) -ili9341BitBlit_loopH: - mov r24, r8 - mov r25, r9 -ili9341BitBlit_loopW: - ld r18, X+ - ld r19, X+ - mov r16, r19 - rcall SPIHW_MasterTransfer ; (R16) - mov r16, r18 - rcall SPIHW_MasterTransfer ; (R16) - sbiw r25:r24, 1 - brne ili9341BitBlit_loopW - mov r24, r22 - mov r25, r23 - sbiw r25:r24, 1 - mov r22, r24 - mov r23, r25 - brne ili9341BitBlit_loopH - sbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS high - rcall ili9341EndSpi ; (R16) - out SREG, r15 - pop r15 - ret -; @end - - - -; --------------------------------------------------------------------------- -; @routine ili9341BitBlitStretch2 - -; @param r5:r4 X (dest) -; @param r7:r6 Y (dest) -; @param r9:r8 W -; @param r11:r10 H -; @param X source data pointer (RAM) -; @clobbers r16, r22, r23, r24, r25, X (r17, r18, r19, r20, r21) - -ili9341BitBlitStretch2: - push r15 - in r15, SREG - cli - - push r8 - push r9 - push r10 - push r11 - ; width - lsl r8 ; x2 - rol r9 - ; height - lsl r10 ; x2 - rol r11 - - rcall ili9341BeginSpi ; (r16, r17) - rcall ili9341SetAddressWindow ; (R16, R20, R21) - pop r11 - pop r10 - pop r9 - pop r8 - ldi r16, ILI9341_CMD_RAMWR ; start writing ro RAM - rcall ili9341SendCommand - - mov r22, r10 - mov r23, r11 - cbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS low - sbi ILI9341_DC_OUTPUT, ILI9341_DC_PIN ; D high (DATA) - ldi r17, 2 -ili9341BitBlitStretch2_loopH: - mov r20, xl ; preserve for next run - mov r21, xh - rcall ili9341BitBlitStretchNWriteLine ; (r16, r17, r18, r19, r24, r25, X) - mov xl, r20 - mov xh, r21 - rcall ili9341BitBlitStretchNWriteLine ; (r16, r17, r18, r19, r24, r25, X) - mov r24, r22 - mov r25, r23 - sbiw r25:r24, 1 - mov r22, r24 - mov r23, r25 - brne ili9341BitBlitStretch2_loopH - sbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS high - rcall ili9341EndSpi ; (R16) - out SREG, r15 - pop r15 - ret -; @end - - - -; --------------------------------------------------------------------------- -; @routine ili9341BitBlitStretch4 - -; @param r5:r4 X (dest) -; @param r7:r6 Y (dest) -; @param r9:r8 W -; @param r11:r10 H -; @param X source data pointer (RAM) -; @clobbers r16, r22, r23, r24, r25, X (r17, r20, r21) - -ili9341BitBlitStretch4: - push r15 - in r15, SREG - cli - - push r8 - push r9 - push r10 - push r11 - ; width - lsl r8 ; x2 - rol r9 - lsl r8 ; x4 - rol r9 - ; height - lsl r10 ; x2 - rol r11 - lsl r10 ; x4 - rol r11 - - rcall ili9341BeginSpi ; (r16, r17) - rcall ili9341SetAddressWindow ; (R16, R20, R21) - pop r11 - pop r10 - pop r9 - pop r8 - ldi r16, ILI9341_CMD_RAMWR ; start writing ro RAM - rcall ili9341SendCommand - - mov r22, r10 - mov r23, r11 - ldi r17, 4 - cbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS low - sbi ILI9341_DC_OUTPUT, ILI9341_DC_PIN ; D high (DATA) -ili9341BitBlitStretch4_loopH: - mov r20, xl ; preserve for next run - mov r21, xh - rcall ili9341BitBlitStretchNWriteLine ; (r16, r17, r18, r19, r24, r25, X) - mov xl, r20 - mov xh, r21 - rcall ili9341BitBlitStretchNWriteLine ; (r16, r17, r18, r19, r24, r25, X) - mov xl, r20 - mov xh, r21 - rcall ili9341BitBlitStretchNWriteLine ; (r16, r17, r18, r19, r24, r25, X) - mov xl, r20 - mov xh, r21 - rcall ili9341BitBlitStretchNWriteLine ; (r16, r17, r18, r19, r24, r25, X) - mov r24, r22 - mov r25, r23 - sbiw r25:r24, 1 - mov r22, r24 - mov r23, r25 - brne ili9341BitBlitStretch4_loopH - sbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS high - rcall ili9341EndSpi ; (R16) - out SREG, r15 - pop r15 - ret -; @end - - - -; --------------------------------------------------------------------------- -; @routine ili9341BitBlitStretchNWriteLine - -; @param r9:r8 width -; @param r17 repeat factor -; @param X source position of line -; @clobbers r16, r17, r18, r19, r24, r25, X - -ili9341BitBlitStretchNWriteLine: - mov r24, r8 - mov r25, r9 -ili9341BitBlitStretchNWriteLine_loop1: - ld r18, X+ - ld r19, X+ - push r17 -ili9341BitBlitStretchNWriteLine_loop2: - mov r16, r19 - rcall SPIHW_MasterTransfer ; (R16) - mov r16, r18 - rcall SPIHW_MasterTransfer ; (R16) - dec r17 - brne ili9341BitBlitStretchNWriteLine_loop2 - pop r17 - sbiw r25:r24, 1 - brne ili9341BitBlitStretchNWriteLine_loop1 - ret -; @end diff --git a/avr/modules/lcd2/ili9341/text.asm b/avr/modules/lcd2/ili9341/text.asm index 4d5ef7e..bc8b8ee 100644 --- a/avr/modules/lcd2/ili9341/text.asm +++ b/avr/modules/lcd2/ili9341/text.asm @@ -23,13 +23,13 @@ ; @param r7:r6 Y ; @param r1:r0 background color ; @param r3:r2 foreground color -; @param Z pointer to font (word address!) +; @param Z pointer to font (byte address for LPM!) ; @param X pointer to RAM to store data to ; @return r5:r4 new X (advanced by character width) ; @clobbers r16 (r17, r20, r21, r22, r23, r24, r25, X) ili9341_WriteCharacterX1At: - rcall ili9341PrepareCharFromFont ; (r16, r17, r24, r25, z) + rcall ili9341FontRenderChar ; (r16, r17, r24, r25, z) rcall ili9341BitBlit ; (r16, r17, r20, r21, r22, r23, r24, r25, X) ; advance X (add char width to X) add r4, r8 @@ -48,13 +48,13 @@ ili9341_WriteCharacterX1At: ; @param r7:r6 Y ; @param r1:r0 background color ; @param r3:r2 foreground color -; @param Z pointer to font (word address!) +; @param Z pointer to font (byte address for LPM!) ; @param X pointer to RAM to store data to ; @return r5:r4 new X (advanced by character width) ; @clobbers r16 (r17, r18, r19, r20, r21, r22, r23, r24, r25, X) ili9341_WriteCharacterX2At: - rcall ili9341PrepareCharFromFont ; (r16, r17, r24, r25, z) + rcall ili9341FontRenderChar ; (r16, r17, r24, r25, z) rcall ili9341BitBlitStretch2 ; (r16, r17, r18, r19, r20, r21, r22, r23, r24, r25, X) ; advance X (add double char width to X) lsl r8 ; Wx2 @@ -74,13 +74,13 @@ ili9341_WriteCharacterX2At: ; @param r7:r6 Y ; @param r1:r0 background color ; @param r3:r2 foreground color -; @param Z pointer to font (word address!) +; @param Z pointer to font (byte address for LPM!) ; @param X pointer to RAM to store data to ; @return r5:r4 new X (advanced by character width) ; @clobbers r16, r17, r18, r19, r24, r25, x, z ili9341_WriteCharacterX4At: - rcall ili9341PrepareCharFromFont ; (r16, r17, r24, r25, z) + rcall ili9341FontRenderChar ; (r16, r17, r24, r25, z) rcall ili9341BitBlitStretch4 ; (r16, r17, r20, r21, r22, r23, r24, r25, X) ; advance X (add quad char width to X) lsl r8 ; Wx2 @@ -97,7 +97,7 @@ ili9341_WriteCharacterX4At: ; --------------------------------------------------------------------------- -; @routine ili9341PrepareCharFromFont +; @routine ili9341FontRenderChar ; @param R16 character to write ; @param Z pointer to font @@ -106,7 +106,7 @@ ili9341_WriteCharacterX4At: ; @return r11:r10 character height in points ; @clobbers r16 (r17, r24, r25, z) -ili9341PrepareCharFromFont: +ili9341FontRenderChar: ; render character push xl push xh @@ -129,9 +129,15 @@ ili9341PrepareCharFromFont: ; @routine ili9341JumpToFontRenderFn ; ; helper function to call function at the beginning of the given font +; @clobbers r17 ili9341JumpToFontRenderFn: - ijmp + lpm r17, Z+ + push r17 + lpm r17, Z + push r17 + sbiw zh:zl, 1 + ret ; @end From fa5acddcbe0c39e10889593c55ec609535643170 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Thu, 22 May 2025 23:19:33 +0200 Subject: [PATCH 49/58] avr: started working on prerequisites for a window gui system. --- avr/common/0BUILD | 2 + avr/common/list.asm | 166 ++++++++++++++++++++++ avr/common/tree.asm | 192 ++++++++++++++++++++++++++ avr/modules/lcd2/ili9341/graphops.asm | 1 - avr/modules/lcd2/win/defs.asm | 62 +++++++++ 5 files changed, 422 insertions(+), 1 deletion(-) create mode 100644 avr/common/list.asm create mode 100644 avr/common/tree.asm create mode 100644 avr/modules/lcd2/win/defs.asm diff --git a/avr/common/0BUILD b/avr/common/0BUILD index 26bb9eb..6c79831 100644 --- a/avr/common/0BUILD +++ b/avr/common/0BUILD @@ -22,6 +22,8 @@ utils_wait_fixed.asm utils_wait_pin.asm watchdog.asm + list.asm + tree.asm diff --git a/avr/common/list.asm b/avr/common/list.asm new file mode 100644 index 0000000..93240ed --- /dev/null +++ b/avr/common/list.asm @@ -0,0 +1,166 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + +#ifndef AQH_AVR_COMMON_LIST_H +#define AQH_AVR_COMMON_LIST_H + + +; --------------------------------------------------------------------------- +; This code implements a simple single-linked list. +; It assumes that the first 2 bytes of an object managed by this code contain +; a 2 byte pointer to the next object. +; --------------------------------------------------------------------------- + + + + +; *************************************************************************** +; defs + +.equ LIST_OFFS_NEXT_LO = 0 +.equ LIST_OFFS_NEXT_HI = 1 +.equ LIST_SIZE = 2 + + + + + +; *************************************************************************** +; code + +.cseg + + + +; --------------------------------------------------------------------------- +; @routine List_InitObject @global +; +; Reset list object fields. +; @param Y pointer to object +; @clobbers r16 + +List_InitObject: + clr r16 ; set this->NEXT to NULL + std Y+LIST_OFFS_NEXT_LO, r16 + std Y+LIST_OFFS_NEXT_HI, r16 + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine List_GetNextObject @global + +; @param Y pointer to object +; @return X pointer to parent object +; @clobbers none + +List_GetNextObject: + ldd xl, Y+LIST_OFFS_NEXT_LO + ldd xh, Y+LIST_OFFS_NEXT_HI + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine List_GetLastObject + +; @param X pointer to one object in a list +; @return X pointer to last object which has an empty NEXT pointer +; @clobbers r16, r17, X, Y + +List_GetLastObject: + clr yl + clr yh + rjmp List_GetPredecessorFor +; @end + + + +; --------------------------------------------------------------------------- +; @routine List_GetPredecessorFor + +; @param Y pointer to this object +; @param X pointer to first object in a list +; @return X pointer to object whose NEXT pointer points to the given object (or NULL) +; @clobbers r16, r17, X + +List_GetPredecessorFor: + mov r16, xl + or r16, xh + breq List_GetPredecessorFor_ret + ld r16, X+ + ld r17, X+ + cp r16, yl + brne List_GetPredecessorFor_next + cp r17, yh + breq List_GetLastObject_haveIt +List_GetPredecessorFor_next: + mov xl, r16 + mov xh, r17 + rjmp List_GetPredecessorFor +List_GetPredecessorFor_haveIt: + sbiw xh:xl, 1 +List_GetPredecessorFor_ret: + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine List_AddObject + +; @param X pointer to first object in a list +; @param Y pointer to object to add +; @clobbers r16, r17, x + +List_AddObject: + push yl + push yh + rcall List_GetLastObject ; (r16, r17, X, Y) + pop yh + pop yl + st X+, yl ; WID_OFFS_WNEXT_LO + st X+, yh ; WID_OFFS_WNEXT_HI + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine List_UnlinkObject + +; @param X pointer to first object in a list +; @param Y pointer to object to remove +; @clobbers r16, r17, x + +List_UnlinkObject: + push yl + push yh + rcall List_GetPredecessorFor ; (r16, r17, X) + pop yh + pop yl + mov r16, xl + or r16, xh + breq List_UnlinkObject_ret + ldd r16, Y+LIST_OFFS_NEXT_LO ; get this->NEXT + ldd r17, Y+LIST_OFFS_NEXT_HI + st X+, r16 ; store as NEXT in predecessor + st X, r17 + clr r16 ; set this->NEXT to NULL + std Y+LIST_OFFS_NEXT_LO, r16 + std Y+LIST_OFFS_NEXT_HI, r16 +List_UnlinkObject_ret: + ret +; @end + + + +#endif ; AQH_AVR_COMMON_LIST_H diff --git a/avr/common/tree.asm b/avr/common/tree.asm new file mode 100644 index 0000000..38e197a --- /dev/null +++ b/avr/common/tree.asm @@ -0,0 +1,192 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + +#ifndef AQH_AVR_COMMON_TREE_H +#define AQH_AVR_COMMON_TREE_H + + + + +; *************************************************************************** +; defs + +.equ TREE_OFFS_LIST = 0 +.equ TREE_OFFS_WPARENT_LO = TREE_OFFS_LIST+LIST_SIZE +.equ TREE_OFFS_WPARENT_HI = TREE_OFFS_LIST+LIST_SIZE+1 +.equ TREE_OFFS_WCHILD_LO = TREE_OFFS_LIST+LIST_SIZE+2 +.equ TREE_OFFS_WCHILD_HI = TREE_OFFS_LIST+LIST_SIZE+3 +.equ TREE_SIZE = TREE_OFFS_LIST+LIST_SIZE+4 + + + + +; *************************************************************************** +; code + +.cseg + + + +; --------------------------------------------------------------------------- +; @routine Tree_InitObject @global + +; @param Y pointer to object to add +; @clobbers r16 + +Tree_InitObject: + rcall List_InitObject ; (R16) + clr r16 ; clear this->TREE data + std Y+TREE_OFFS_LIST+TREE_OFFS_WPARENT_LO, r16 + std Y+TREE_OFFS_LIST+TREE_OFFS_WPARENT_HI, r16 + std Y+TREE_OFFS_LIST+TREE_OFFS_WCHILD_LO, r16 + std Y+TREE_OFFS_LIST+TREE_OFFS_WCHILD_HI, r16 + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine Tree_GetParentObject @global + +; @param Y pointer to object +; @return X pointer to parent object +; @clobbers none + +Tree_GetParentObject: + ldd xl, Y+TREE_OFFS_WPARENT_LO + ldd xh, Y+TREE_OFFS_WPARENT_HI + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine Tree_GetFirstChildObject @global + +; @param Y pointer to object +; @return X pointer to first child object +; @clobbers none + +Tree_GetFirstChildObject: + ldd xl, Y+TREE_OFFS_WCHILD_LO + ldd xh, Y+TREE_OFFS_WCHILD_HI + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine Tree_GetObjectBelow @global + +; @param Y pointer to object +; @return X pointer to object below (or NULL) +; @clobbers r16 + +Tree_GetObjectBelow: + push yl + push yh + rcall treeGetObjectBelow + pop yh + pop yl + ret + +treeGetObjectBelow: + rcall Tree_GetFirstChildObject + mov r16, xl + or r16, xh + brne treeGetObjectBelow_ret ; got one + rcall List_GetNextObject + mov r16, xl + or r16, xh + brne treeGetObjectBelow_ret ; got one + rcall Tree_GetParentObject + mov r16, xl + or r16, xh + breq treeGetObjectBelow_ret ; no parent + mov yl, xl + mov yh, xh + rjmp treeGetObjectBelow ; try with parent +treeGetObjectBelow_ret: + ret +; @end + + + + +; --------------------------------------------------------------------------- +; @routine Tree_AddChildObject @global + +; @param X pointer to parent to add to +; @param Y pointer to object to add +; @clobbers r16, r17, r18, x + +Tree_AddChildObject: + std Y+TREE_OFFS_WPARENT_LO, xl ; immediately store parent pointer + std Y+TREE_OFFS_WPARENT_HI, xh + adiw xh:xl, TREE_OFFS_WCHILD_LO + ld r16, X+ + ld r17, X + mov r18, r16 + or r18, r17 + brne Tree_AddChildObject_addToChildList + st X, yh ; no child, set THIS as first + st -X, yl + sbiw xh:xl, WID_OFFS_TREE+TREE_OFFS_WCHILD_LO + ret +Tree_AddChildObject_addToChildList: + mov xl, r16 + mov xh, r17 + rjmp List_AddObject +; @end + + + +; --------------------------------------------------------------------------- +; @routine Tree_UnlinkObject @global + +; @param Y pointer to object to remove +; @clobbers r16, r17, x + +Tree_UnlinkObject: + ldd xl, Y+TREE_OFFS_WPARENT_LO + ldd xh, Y+TREE_OFFS_WPARENT_HI + mov r16, xl + or r16, xh + breq Tree_UnlinkObject_ret ; not part of a tree + adiw xh:xl, TREE_OFFS_WCHILD_LO ; get parent's first child to R17:R16 + ld r16, X+ + ld r17, X + cp r16, yl ; same as THIS? + brne Tree_UnlinkObject_inList ; nope, need to check childList + cp r17, yh + brne Tree_UnlinkObject_inList ; nope, need to check childList + ldd r16, Y+TREE_OFFS_LIST+LIST_OFFS_NEXT_HI ; is first child, set this->NEXT as new first child + st X, r16 + ldd r16, Y+TREE_OFFS_LIST+LIST_OFFS_NEXT_LO + st -X, r16 + rjmp Tree_UnlinkObject_clrParentAndSibling +Tree_UnlinkObject_inList: + mov xl, r16 + mov xh, r17 + rcall List_UnlinkObject ; (R16, R17, X) +Tree_UnlinkObject_clrParentAndSibling: + clr r16 ; clear this->PARENT + std Y+TREE_OFFS_LIST+TREE_OFFS_WPARENT_LO, r16 + std Y+TREE_OFFS_LIST+TREE_OFFS_WPARENT_HI, r16 + std Y+LIST_OFFS_NEXT_LO, r16 + std Y+LIST_OFFS_NEXT_HI, r16 ; clear this->NEXT +Tree_UnlinkObject_ret: + ret +; @end + + + + +#endif ; AQH_AVR_COMMON_TREE_H + diff --git a/avr/modules/lcd2/ili9341/graphops.asm b/avr/modules/lcd2/ili9341/graphops.asm index f280508..22aa62a 100644 --- a/avr/modules/lcd2/ili9341/graphops.asm +++ b/avr/modules/lcd2/ili9341/graphops.asm @@ -334,4 +334,3 @@ ili9341BitBlitStretchNWriteLine_loop2: - diff --git a/avr/modules/lcd2/win/defs.asm b/avr/modules/lcd2/win/defs.asm new file mode 100644 index 0000000..47092ed --- /dev/null +++ b/avr/modules/lcd2/win/defs.asm @@ -0,0 +1,62 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + +#ifndef AQH_AVR_WIN_H +#define AQH_AVR_WIN_H + + +; tree/list info +.equ WID_OFFS_TREE = 0 + +; signal handler +.equ WID_OFFS_HANDLERFN_LO = WID_OFFS_TREE+TREE_SIZE +.equ WID_OFFS_HANDLERFN_HI = WID_OFFS_HANDLERFN_LO+1 + +; widget description +.equ WID_OFFS_WIDGET_INFO = WID_OFFS_HANDLERFN_HI+1 +.equ WID_OFFS_OPTIONS1 = WID_OFFS_WIDGET_INFO+0 +.equ WID_OFFS_OPTIONS2 = WID_OFFS_WIDGET_INFO+1 +.equ WID_OFFS_ABS_X_LO = WID_OFFS_WIDGET_INFO+2 +.equ WID_OFFS_ABS_X_HI = WID_OFFS_WIDGET_INFO+3 +.equ WID_OFFS_ABS_Y_LO = WID_OFFS_WIDGET_INFO+4 +.equ WID_OFFS_ABS_Y_HI = WID_OFFS_WIDGET_INFO+5 +.equ WID_OFFS_REL_X_LO = WID_OFFS_WIDGET_INFO+6 +.equ WID_OFFS_REL_X_HI = WID_OFFS_WIDGET_INFO+7 +.equ WID_OFFS_REL_Y_LO = WID_OFFS_WIDGET_INFO+8 +.equ WID_OFFS_REL_Y_HI = WID_OFFS_WIDGET_INFO+9 +.equ WID_OFFS_WIDTH_LO = WID_OFFS_WIDGET_INFO+10 +.equ WID_OFFS_WIDTH_HI = WID_OFFS_WIDGET_INFO+11 +.equ WID_OFFS_HEIGHT_LO = WID_OFFS_WIDGET_INFO+12 +.equ WID_OFFS_HEIGHT_HI = WID_OFFS_WIDGET_INFO+13 +.equ WID_OFFS_BG_COL_LO = WID_OFFS_WIDGET_INFO+14 +.equ WID_OFFS_BG_COL_HI = WID_OFFS_WIDGET_INFO+15 +.equ WID_OFFS_FG_COL_LO = WID_OFFS_WIDGET_INFO+16 +.equ WID_OFFS_FG_COL_HI = WID_OFFS_WIDGET_INFO+17 +.equ WID_OFFS_FONT_LO = WID_OFFS_WIDGET_INFO+18 +.equ WID_OFFS_FONT_HI = WID_OFFS_WIDGET_INFO+19 + +.equ WID_SIZE = WID_OFFS_WIDGET_INFO+20 + + + +.equ WID_OPTIONS1_BIT_DIRTY = 0 +.equ WID_OPTIONS1_BIT_LAYOUT = 1 + +.equ WID_OPTIONS1_BIT_STRETCH_X = 2 +.equ WID_OPTIONS1_BIT_STRETCH_Y = 3 + +.equ WID_OPTIONS1_BIT_ALIGN_LEFT = 4 +.equ WID_OPTIONS1_BIT_ALIGN_RIGHT = 5 + +.equ WID_OPTIONS1_BIT_ALIGN_TOP = 6 +.equ WID_OPTIONS1_BIT_ALIGN_BOTTOM = 7 + + +#endif ; AQH_AVR_WIN_H + From 391c06e7e51dcb30c55f59f270ae982c03223c56 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 24 May 2025 15:32:45 +0200 Subject: [PATCH 50/58] avr: more work on fonts, added heap functions. --- avr/devices/all/includes.asm | 10 + avr/devices/all/modules.asm | 4 + avr/devices/c01/main/main.asm | 12 +- avr/modules/0BUILD | 1 + avr/modules/heap/0BUILD | 11 ++ avr/modules/heap/main.asm | 317 ++++++++++++++++++++++++++++++ avr/modules/lcd2/font/0BUILD | 2 + avr/modules/lcd2/font/defs.asm | 6 + avr/modules/lcd2/font/font1.asm | 2 +- avr/modules/lcd2/font/font2.asm | 179 +++++++++++++++++ avr/modules/lcd2/font/font6x8.asm | 96 +++++++++ avr/modules/lcd2/ili9341/defs.asm | 2 + avr/modules/lcd2/ili9341/main.asm | 6 +- avr/modules/lcd2/win/widget.asm | 18 ++ 14 files changed, 661 insertions(+), 5 deletions(-) create mode 100644 avr/modules/heap/0BUILD create mode 100644 avr/modules/heap/main.asm create mode 100644 avr/modules/lcd2/font/font2.asm create mode 100644 avr/modules/lcd2/font/font6x8.asm create mode 100644 avr/modules/lcd2/win/widget.asm diff --git a/avr/devices/all/includes.asm b/avr/devices/all/includes.asm index 48c95e0..eea0d35 100644 --- a/avr/devices/all/includes.asm +++ b/avr/devices/all/includes.asm @@ -28,6 +28,10 @@ .include "modules/xram/main.asm" #endif +#ifdef MODULES_HEAP + .include "modules/heap/main.asm" +#endif + #ifdef MODULES_NETWORK .include "common/crc8.asm" .include "common/m_fixedbuffers.asm" @@ -166,6 +170,12 @@ #endif +#ifdef MODULES_FONT_6X8 +.include "modules/lcd2/font/defs.asm" +.include "modules/lcd2/font/font6x8.asm" +#endif + + #ifdef APPS_MOTION .include "modules/f_keepup/main.asm" .include "modules/valsched/main.asm" diff --git a/avr/devices/all/modules.asm b/avr/devices/all/modules.asm index 75ce833..c45ba91 100644 --- a/avr/devices/all/modules.asm +++ b/avr/devices/all/modules.asm @@ -24,6 +24,10 @@ initModules: rcall BaseTimer_Init ; unconditionally call this +#ifdef MODULES_HEAP + rcall Heap_Init +#endif + #ifdef MODULES_CLOCK rcall Clock_Init #endif diff --git a/avr/devices/c01/main/main.asm b/avr/devices/c01/main/main.asm index c04c61e..ba8eb22 100644 --- a/avr/devices/c01/main/main.asm +++ b/avr/devices/c01/main/main.asm @@ -36,6 +36,14 @@ +; --------------------------------------------------------------------------- +; heap + +.equ HEAP_START = 0x260 +.equ HEAP_SIZE = 32768-0x260 + + + ; --------------------------------------------------------------------------- ; firmware settings including list of modules used @@ -48,13 +56,15 @@ ; #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_SPI_HW #define MODULES_ILI9341 -#define MODULES_FONT_8X8 +;#define MODULES_FONT_8X8 +#define MODULES_FONT_6X8 ;#define MODULES_UART_BITBANG ;#define MODULES_TWI_MASTER ;#define MODULES_LCD diff --git a/avr/modules/0BUILD b/avr/modules/0BUILD index dc51511..d2ca36a 100644 --- a/avr/modules/0BUILD +++ b/avr/modules/0BUILD @@ -36,6 +36,7 @@ f_keepup valsched xram + heap diff --git a/avr/modules/heap/0BUILD b/avr/modules/heap/0BUILD new file mode 100644 index 0000000..febd367 --- /dev/null +++ b/avr/modules/heap/0BUILD @@ -0,0 +1,11 @@ + + + + + + main.asm + + + + + diff --git a/avr/modules/heap/main.asm b/avr/modules/heap/main.asm new file mode 100644 index 0000000..177ddbb --- /dev/null +++ b/avr/modules/heap/main.asm @@ -0,0 +1,317 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + +; Needed vars: +; - HEAP_START +; - HEAP_SIZE + + +.equ HEAP_HEADER_BIT_USED = 1 + + +.dseg + +heapPtr: .byte 2 +heapUsed: .byte 2 +heapFree: .byte 2 +heapDblFree: .byte 1 + + + + +.cseg + + + +; --------------------------------------------------------------------------- +; @routine Heap_Init + +Heap_Init: + ldi xl, LOW(HEAP_START) + ldi xh, HIGH(HEAP_START) + ldi r24, LOW((HEAP_SIZE-6) & 0xfffc) ; size minus chunk header, chunk footer, start, end + ldi r25, HIGH((HEAP_SIZE-6) & 0xfffc) ; we allocate multiples of 4 bytes + clr r16 + sts heapUsed, r16 + sts heapUsed+1, r16 + st X+, r16 ; write start header + st X+, r16 + sts heapPtr, xl ; store global vars + sts heapPtr+1, xl + sts heapFree, r24 + sts heapFree+1, r25 + st X+, r24 ; store header of first chunk + st X+, r25 + add xl, r24 + adc xh, r25 + st X+, r24 ; store footer of first chunk + st X+, r25 + st X+, r16 ; write end footer + sec + ret +; @end + + + + +; --------------------------------------------------------------------------- +; @routine heapAllocFirstFit +; +; @param r25:r24 number of bytes to alloc +; @return CFLAG set of okay, cleared otherwise +; @return X start of allocated memory + +heapAllocFirstFit: + adiw r25:r24, 3 ; align size to next multiple of 4 + andi r24, 0xfc ; mask lower two bits + + lds xl, heapPtr + lds xh, heapPtr+1 + +heapAllocFirstFit_loop: + ld r18, X+ ; read chunk header + ld r19, X+ + mov r16, r18 ; heap end reached? + or r16, r19 + breq heapAllocFirstFit_memFull + sbrc r17, HEAP_HEADER_BIT_USED + rjmp heapAllocFirstFit_next ; jump if used + ; current chunk free, check size + mov r16, r18 + mov r17, r19 + sub r16, r24 + sbc r17, r25 ; r17:r16=remainder + brcs heapAllocFirstFit_next ; too small + rcall heapUseChunk + sec + ret +heapAllocFirstFit_next: + add xl, r18 + adc xh, r19 + adiw xh:xl, 2 ; skip footer + rjmp heapAllocFirstFit_loop + +heapAllocFirstFit_memFull: + clc + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine heapAdjustStatsAlloc +; +; @param r25:r24 size of allocated chunk +; @clobbers r16, r17 + +heapAdjustStatsAlloc: + ; adjust heapUsed + lds r16, heapUsed + lds r17, heapUsed+1 + add r16, r24 + adc r17, r25 + sts heapUsed, r16 + sts heapUsed+1, r17 + + ; adjust heapFree + lds r16, heapFree + lds r17, heapFree+1 + sub r16, r24 + sbc r17, r25 + sts heapFree, r16 + sts heapFree+1, r17 + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine heapAdjustStatsFree +; +; @param r25:r24 size of released chunk +; @clobbers r16, r17 + +heapAdjustStatsFree: + ; adjust heapUsed + lds r16, heapUsed + lds r17, heapUsed+1 + sub r16, r24 + sbc r17, r25 + sts heapUsed, r16 + sts heapUsed+1, r17 + + ; adjust heapFree + lds r16, heapFree + lds r17, heapFree+1 + add r16, r24 + adc r17, r25 + sts heapFree, r16 + sts heapFree+1, r17 + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine Heap_Free +; +; @param X pointer to previously allocated data +; @clobbers r16, r17, r24, r25, X + +Heap_Free: + sbiw xh:xl, 2 ; go back to chunk header + ld r24, X+ ; read allocated size (and USED bit) + ld r25, X+ + sbrs r24, HEAP_HEADER_BIT_USED + rjmp Heap_Free_dblFree ; not in use (double free!!) + cbr r24, (1< defs.asm font8x8.asm + font6x8.asm font1.asm + font2.asm diff --git a/avr/modules/lcd2/font/defs.asm b/avr/modules/lcd2/font/defs.asm index 4f86f91..d2908c3 100644 --- a/avr/modules/lcd2/font/defs.asm +++ b/avr/modules/lcd2/font/defs.asm @@ -7,6 +7,8 @@ ; * Please see toplevel file COPYING of that project for license details. * ; *************************************************************************** +#ifndef AVR_MODULES_FONT_DEFS +#define AVR_MODULES_FONT_DEFS .equ FONT_OFFS_RENDERFN_LOW = 0 @@ -18,3 +20,7 @@ .equ FONT_OFFS_NUMCHARS = 7 + +#endif + + diff --git a/avr/modules/lcd2/font/font1.asm b/avr/modules/lcd2/font/font1.asm index 25a04de..7fd4710 100644 --- a/avr/modules/lcd2/font/font1.asm +++ b/avr/modules/lcd2/font/font1.asm @@ -30,7 +30,7 @@ font1_8x8: .db 128, 0 ; needed buffer size .db 8, 8 ; width, height of chars .db 32, 64 ; first char, num of chars in font -; data +; data (8x8_horizontal_LSB_2) .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, ; 0x20 .db 0x0C,0x1E,0x1E,0x0C,0x0C,0x00,0x0C,0x00, ; 0x21 .db 0x36,0x36,0x36,0x00,0x00,0x00,0x00,0x00, ; 0x22 diff --git a/avr/modules/lcd2/font/font2.asm b/avr/modules/lcd2/font/font2.asm new file mode 100644 index 0000000..6c6ec79 --- /dev/null +++ b/avr/modules/lcd2/font/font2.asm @@ -0,0 +1,179 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + +; *************************************************************************** +; This is a font from the project LCD_fonts at +; https://github.com/basti79/LCD-fonts.git +; which in turn is based on a post by Benedikt K. in a forum post on +; https://www.mikrocontroller.net/topic/54860 +; *************************************************************************** + + + +; *************************************************************************** +; code + +.cseg + + + +font2_6x8: +; header + .dw font6x8MonoRenderCharacter ; renderFn + .db 96, 0 ; needed buffer size + .db 6, 8 ; width, height of chars + .db 32, 65 ; first char, num of chars in font +; data (6x8_horizontal_LSB_2) +font: +.db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, ; 0x20 +.db 0x08,0x1C,0x1C,0x08,0x08,0x00,0x08,0x00, ; 0x21 +.db 0x36,0x36,0x12,0x00,0x00,0x00,0x00,0x00, ; 0x22 +.db 0x00,0x14,0x3E,0x14,0x14,0x3E,0x14,0x00, ; 0x23 +.db 0x04,0x1C,0x02,0x0C,0x10,0x0E,0x08,0x00, ; 0x24 +.db 0x26,0x26,0x10,0x08,0x04,0x32,0x32,0x00, ; 0x25 +.db 0x04,0x0A,0x0A,0x04,0x2A,0x12,0x2C,0x00, ; 0x26 +.db 0x0C,0x0C,0x04,0x00,0x00,0x00,0x00,0x00, ; 0x27 +.db 0x08,0x04,0x04,0x04,0x04,0x04,0x08,0x00, ; 0x28 +.db 0x04,0x08,0x08,0x08,0x08,0x08,0x04,0x00, ; 0x29 +.db 0x00,0x14,0x1C,0x3E,0x1C,0x14,0x00,0x00, ; 0x2A +.db 0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00, ; 0x2B +.db 0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x04, ; 0x2C +.db 0x00,0x00,0x00,0x3E,0x00,0x00,0x00,0x00, ; 0x2D +.db 0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x00, ; 0x2E +.db 0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00, ; 0x2F +.db 0x1C,0x22,0x32,0x2A,0x26,0x22,0x1C,0x00, ; 0x30 +.db 0x08,0x0C,0x08,0x08,0x08,0x08,0x1C,0x00, ; 0x31 +.db 0x1C,0x22,0x20,0x18,0x04,0x02,0x3E,0x00, ; 0x32 +.db 0x1C,0x22,0x20,0x1C,0x20,0x22,0x1C,0x00, ; 0x33 +.db 0x10,0x18,0x14,0x12,0x3E,0x10,0x10,0x00, ; 0x34 +.db 0x3E,0x02,0x02,0x1E,0x20,0x22,0x1C,0x00, ; 0x35 +.db 0x18,0x04,0x02,0x1E,0x22,0x22,0x1C,0x00, ; 0x36 +.db 0x3E,0x20,0x10,0x08,0x04,0x04,0x04,0x00, ; 0x37 +.db 0x1C,0x22,0x22,0x1C,0x22,0x22,0x1C,0x00, ; 0x38 +.db 0x1C,0x22,0x22,0x3C,0x20,0x10,0x0C,0x00, ; 0x39 +.db 0x00,0x00,0x0C,0x0C,0x00,0x0C,0x0C,0x00, ; 0x3A +.db 0x00,0x00,0x0C,0x0C,0x00,0x0C,0x0C,0x04, ; 0x3B +.db 0x10,0x08,0x04,0x02,0x04,0x08,0x10,0x00, ; 0x3C +.db 0x00,0x00,0x3E,0x00,0x00,0x3E,0x00,0x00, ; 0x3D +.db 0x04,0x08,0x10,0x20,0x10,0x08,0x04,0x00, ; 0x3E +.db 0x1C,0x22,0x20,0x18,0x08,0x00,0x08,0x00, ; 0x3F +.db 0x1C,0x22,0x3A,0x2A,0x3A,0x02,0x1C,0x00, ; 0x40 +.db 0x1C,0x22,0x22,0x22,0x3E,0x22,0x22,0x00, ; 0x41 +.db 0x1E,0x22,0x22,0x1E,0x22,0x22,0x1E,0x00, ; 0x42 +.db 0x1C,0x22,0x02,0x02,0x02,0x22,0x1C,0x00, ; 0x43 +.db 0x1E,0x22,0x22,0x22,0x22,0x22,0x1E,0x00, ; 0x44 +.db 0x3E,0x02,0x02,0x1E,0x02,0x02,0x3E,0x00, ; 0x45 +.db 0x3E,0x02,0x02,0x1E,0x02,0x02,0x02,0x00, ; 0x46 +.db 0x1C,0x22,0x02,0x3A,0x22,0x22,0x3C,0x00, ; 0x47 +.db 0x22,0x22,0x22,0x3E,0x22,0x22,0x22,0x00, ; 0x48 +.db 0x1C,0x08,0x08,0x08,0x08,0x08,0x1C,0x00, ; 0x49 +.db 0x20,0x20,0x20,0x20,0x22,0x22,0x1C,0x00, ; 0x4A +.db 0x22,0x12,0x0A,0x06,0x0A,0x12,0x22,0x00, ; 0x4B +.db 0x02,0x02,0x02,0x02,0x02,0x02,0x3E,0x00, ; 0x4C +.db 0x22,0x36,0x2A,0x22,0x22,0x22,0x22,0x00, ; 0x4D +.db 0x22,0x26,0x2A,0x32,0x22,0x22,0x22,0x00, ; 0x4E +.db 0x1C,0x22,0x22,0x22,0x22,0x22,0x1C,0x00, ; 0x4F +.db 0x1E,0x22,0x22,0x1E,0x02,0x02,0x02,0x00, ; 0x50 +.db 0x1C,0x22,0x22,0x22,0x2A,0x12,0x2C,0x00, ; 0x51 +.db 0x1E,0x22,0x22,0x1E,0x12,0x22,0x22,0x00, ; 0x52 +.db 0x1C,0x22,0x02,0x1C,0x20,0x22,0x1C,0x00, ; 0x53 +.db 0x3E,0x08,0x08,0x08,0x08,0x08,0x08,0x00, ; 0x54 +.db 0x22,0x22,0x22,0x22,0x22,0x22,0x1C,0x00, ; 0x55 +.db 0x22,0x22,0x22,0x22,0x22,0x14,0x08,0x00, ; 0x56 +.db 0x22,0x22,0x2A,0x2A,0x2A,0x2A,0x14,0x00, ; 0x57 +.db 0x22,0x22,0x14,0x08,0x14,0x22,0x22,0x00, ; 0x58 +.db 0x22,0x22,0x22,0x14,0x08,0x08,0x08,0x00, ; 0x59 +.db 0x1E,0x10,0x08,0x04,0x02,0x02,0x1E,0x00, ; 0x5A +.db 0x1C,0x04,0x04,0x04,0x04,0x04,0x1C,0x00, ; 0x5B +.db 0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00, ; 0x5C +.db 0x1C,0x10,0x10,0x10,0x10,0x10,0x1C,0x00, ; 0x5D +.db 0x08,0x14,0x22,0x00,0x00,0x00,0x00,0x00, ; 0x5E +.db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F, ; 0x5F +.db 0x0C,0x0C,0x08,0x00,0x00,0x00,0x00,0x00, ; 0x60 + + + + + + + + + + + +#if 0 +.db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, ; 0x20 +.db 0x20,0x70,0x70,0x20,0x20,0x00,0x20,0x00, ; 0x21 +.db 0xD8,0xD8,0x48,0x00,0x00,0x00,0x00,0x00, ; 0x22 +.db 0x00,0x50,0xF8,0x50,0x50,0xF8,0x50,0x00, ; 0x23 +.db 0x10,0x70,0x08,0x30,0x40,0x38,0x20,0x00, ; 0x24 +.db 0x98,0x98,0x40,0x20,0x10,0xC8,0xC8,0x00, ; 0x25 +.db 0x10,0x28,0x28,0x10,0xA8,0x48,0xB0,0x00, ; 0x26 +.db 0x30,0x30,0x10,0x00,0x00,0x00,0x00,0x00, ; 0x27 +.db 0x20,0x10,0x10,0x10,0x10,0x10,0x20,0x00, ; 0x28 +.db 0x10,0x20,0x20,0x20,0x20,0x20,0x10,0x00, ; 0x29 +.db 0x00,0x50,0x70,0xF8,0x70,0x50,0x00,0x00, ; 0x2A +.db 0x00,0x20,0x20,0xF8,0x20,0x20,0x00,0x00, ; 0x2B +.db 0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x10, ; 0x2C +.db 0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00, ; 0x2D +.db 0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00, ; 0x2E +.db 0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00, ; 0x2F +.db 0x70,0x88,0xC8,0xA8,0x98,0x88,0x70,0x00, ; 0x30 +.db 0x20,0x30,0x20,0x20,0x20,0x20,0x70,0x00, ; 0x31 +.db 0x70,0x88,0x80,0x60,0x10,0x08,0xF8,0x00, ; 0x32 +.db 0x70,0x88,0x80,0x70,0x80,0x88,0x70,0x00, ; 0x33 +.db 0x40,0x60,0x50,0x48,0xF8,0x40,0x40,0x00, ; 0x34 +.db 0xF8,0x08,0x08,0x78,0x80,0x88,0x70,0x00, ; 0x35 +.db 0x60,0x10,0x08,0x78,0x88,0x88,0x70,0x00, ; 0x36 +.db 0xF8,0x80,0x40,0x20,0x10,0x10,0x10,0x00, ; 0x37 +.db 0x70,0x88,0x88,0x70,0x88,0x88,0x70,0x00, ; 0x38 +.db 0x70,0x88,0x88,0xF0,0x80,0x40,0x30,0x00, ; 0x39 +.db 0x00,0x00,0x30,0x30,0x00,0x30,0x30,0x00, ; 0x3A +.db 0x00,0x00,0x30,0x30,0x00,0x30,0x30,0x10, ; 0x3B +.db 0x40,0x20,0x10,0x08,0x10,0x20,0x40,0x00, ; 0x3C +.db 0x00,0x00,0xF8,0x00,0x00,0xF8,0x00,0x00, ; 0x3D +.db 0x10,0x20,0x40,0x80,0x40,0x20,0x10,0x00, ; 0x3E +.db 0x70,0x88,0x80,0x60,0x20,0x00,0x20,0x00, ; 0x3F +.db 0x70,0x88,0xE8,0xA8,0xE8,0x08,0x70,0x00, ; 0x40 +.db 0x70,0x88,0x88,0x88,0xF8,0x88,0x88,0x00, ; 0x41 +.db 0x78,0x88,0x88,0x78,0x88,0x88,0x78,0x00, ; 0x42 +.db 0x70,0x88,0x08,0x08,0x08,0x88,0x70,0x00, ; 0x43 +.db 0x78,0x88,0x88,0x88,0x88,0x88,0x78,0x00, ; 0x44 +.db 0xF8,0x08,0x08,0x78,0x08,0x08,0xF8,0x00, ; 0x45 +.db 0xF8,0x08,0x08,0x78,0x08,0x08,0x08,0x00, ; 0x46 +.db 0x70,0x88,0x08,0xE8,0x88,0x88,0xF0,0x00, ; 0x47 +.db 0x88,0x88,0x88,0xF8,0x88,0x88,0x88,0x00, ; 0x48 +.db 0x70,0x20,0x20,0x20,0x20,0x20,0x70,0x00, ; 0x49 +.db 0x80,0x80,0x80,0x80,0x88,0x88,0x70,0x00, ; 0x4A +.db 0x88,0x48,0x28,0x18,0x28,0x48,0x88,0x00, ; 0x4B +.db 0x08,0x08,0x08,0x08,0x08,0x08,0xF8,0x00, ; 0x4C +.db 0x88,0xD8,0xA8,0x88,0x88,0x88,0x88,0x00, ; 0x4D +.db 0x88,0x98,0xA8,0xC8,0x88,0x88,0x88,0x00, ; 0x4E +.db 0x70,0x88,0x88,0x88,0x88,0x88,0x70,0x00, ; 0x4F +.db 0x78,0x88,0x88,0x78,0x08,0x08,0x08,0x00, ; 0x50 +.db 0x70,0x88,0x88,0x88,0xA8,0x48,0xB0,0x00, ; 0x51 +.db 0x78,0x88,0x88,0x78,0x48,0x88,0x88,0x00, ; 0x52 +.db 0x70,0x88,0x08,0x70,0x80,0x88,0x70,0x00, ; 0x53 +.db 0xF8,0x20,0x20,0x20,0x20,0x20,0x20,0x00, ; 0x54 +.db 0x88,0x88,0x88,0x88,0x88,0x88,0x70,0x00, ; 0x55 +.db 0x88,0x88,0x88,0x88,0x88,0x50,0x20,0x00, ; 0x56 +.db 0x88,0x88,0xA8,0xA8,0xA8,0xA8,0x50,0x00, ; 0x57 +.db 0x88,0x88,0x50,0x20,0x50,0x88,0x88,0x00, ; 0x58 +.db 0x88,0x88,0x88,0x50,0x20,0x20,0x20,0x00, ; 0x59 +.db 0x78,0x40,0x20,0x10,0x08,0x08,0x78,0x00, ; 0x5A +.db 0x70,0x10,0x10,0x10,0x10,0x10,0x70,0x00, ; 0x5B +.db 0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00, ; 0x5C +.db 0x70,0x40,0x40,0x40,0x40,0x40,0x70,0x00, ; 0x5D +.db 0x20,0x50,0x88,0x00,0x00,0x00,0x00,0x00, ; 0x5E +.db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC, ; 0x5F +.db 0x30,0x30,0x20,0x00,0x00,0x00,0x00,0x00, ; 0x60 +#endif + + diff --git a/avr/modules/lcd2/font/font6x8.asm b/avr/modules/lcd2/font/font6x8.asm new file mode 100644 index 0000000..50b5696 --- /dev/null +++ b/avr/modules/lcd2/font/font6x8.asm @@ -0,0 +1,96 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + +; *************************************************************************** +; code + +.cseg + + + + +; --------------------------------------------------------------------------- +; @routine font6x8RenderCharacter + +; @param R16 character to write +; @param R1:R0 background color +; @param R3:R2 foreground color +; @param Z pointer to font +; @param X pointer to RAM to store data to +; @param r18 char width in pixel +; @param r19 char height in pixel +; @clobbers r16, r17, r24, r25, x + +font6x8MonoRenderCharacter: + push zl + push zh + adiw zh:zl, FONT_OFFS_WIDTH + lpm r18, Z+ ; char width in pixels + lpm r19, Z ; char height in pixels + sbiw zh:zl, FONT_OFFS_WIDTH+1 + rcall font6x8GetCharPosInFont ; (r16, r17, r24, r25, z) + mov r25, r19 ; height in pixels +font6x8MonoRenderCharacter_loop1: + mov r24, r18 ; width in pixels + lpm r17, Z+ +font6x8MonoRenderCharacter_loop2: + lsr r17 + brcs font6x8MonoRenderCharacter_writeForeground + st X+, r0 + st X+, r1 + rjmp font6x8MonoRenderCharacter_loop2end +font6x8MonoRenderCharacter_writeForeground: + st X+, r2 + st X+, r3 +font6x8MonoRenderCharacter_loop2end: + dec r24 + brne font6x8MonoRenderCharacter_loop2 + dec r25 + brne font6x8MonoRenderCharacter_loop1 + pop zh + pop zl + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine font6x8GetCharPosInFont (same as font8x8GetCharPosInFont!) + +; @param R16 character to write +; @param Z pointer to font +; @return Z pointer to begin of char data +; @clobbers r16, r17, r24, r25, z + +font6x8GetCharPosInFont: + mov r24, r16 + adiw zh:zl, FONT_OFFS_FIRSTCHAR + lpm r24, Z+ ; first char num + lpm r25, Z+ ; num of chars + sub r16, r24 + brcs font6x8GetCharPosInFont_ret + cp r16, r25 + brcc font6x8GetCharPosInFont_ret + mov r24, r16 + clr r25 + lsl r24 ; x2 + rol r25 + lsl r24 ; x4 + rol r25 + lsl r24 ; x8 + rol r25 + add zl, r24 + adc zh, r25 +font6x8GetCharPosInFont_ret: + ret +; @end + + + diff --git a/avr/modules/lcd2/ili9341/defs.asm b/avr/modules/lcd2/ili9341/defs.asm index aa3aa70..aa37ed7 100644 --- a/avr/modules/lcd2/ili9341/defs.asm +++ b/avr/modules/lcd2/ili9341/defs.asm @@ -57,3 +57,5 @@ .equ WIN_OFFS_REL_X_HIGH = 11 + + diff --git a/avr/modules/lcd2/ili9341/main.asm b/avr/modules/lcd2/ili9341/main.asm index 933e1ba..9ec3266 100644 --- a/avr/modules/lcd2/ili9341/main.asm +++ b/avr/modules/lcd2/ili9341/main.asm @@ -97,8 +97,8 @@ ILI9341_Init: mov r7, r16 ; set font pos - ldi zl, LOW(font1_8x8*2) - ldi zh, HIGH(font1_8x8*2) + ldi zl, LOW(font2_6x8*2) + ldi zh, HIGH(font2_6x8*2) ; set buffer pos ; ldi xl, LOW(ILI9341_buffer) @@ -423,6 +423,6 @@ helloWorld: .db "Hello World", 0 -.include "modules/lcd2/font/font1.asm" +.include "modules/lcd2/font/font2.asm" diff --git a/avr/modules/lcd2/win/widget.asm b/avr/modules/lcd2/win/widget.asm new file mode 100644 index 0000000..4a070d6 --- /dev/null +++ b/avr/modules/lcd2/win/widget.asm @@ -0,0 +1,18 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + + +; --------------------------------------------------------------------------- +; @routine WID_Widget_new @global + + +WID_Widget_new: + + From 158cf994c52e84d5550207cf62c03b870180411d Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 24 May 2025 17:24:00 +0200 Subject: [PATCH 51/58] fixed a bug on t841. --- avr/modules/uart_hw/comonuart0.asm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/avr/modules/uart_hw/comonuart0.asm b/avr/modules/uart_hw/comonuart0.asm index 5133005..96c43a8 100644 --- a/avr/modules/uart_hw/comonuart0.asm +++ b/avr/modules/uart_hw/comonuart0.asm @@ -536,6 +536,8 @@ comOnUart0Init: lds r16, COM_ATTN_PUE cbr r16, COM_ATTN_PIN ; disable pullup on ATTN sts COM_ATTN_PUE, r16 +.else + cbi COM_ATTN_OUTPUT, COM_ATTN_PIN ; disable pullup on ATTN .endif rcall comOnUart0SetAttnInput M_UART_HW_Uart_Init 0 @@ -681,11 +683,9 @@ comOnUart0TxCharIsr: ; @clobbers none comOnUart0SetAttnInput: - cbi COM_ATTN_DDR, COM_ATTN_PIN ; set ATTN as input -.ifdef COM_ATTN_PUE - cbi COM_ATTN_PUE, COM_ATTN_PIN ; disable pullup on ATTN -.else - cbi COM_ATTN_OUTPUT, COM_ATTN_PIN ; disable pullup on ATTN + cbi COM_ATTN_DDR, COM_ATTN_PIN ; set ATTN as input +.ifndef COM_ATTN_PUE + cbi COM_ATTN_OUTPUT, COM_ATTN_PIN ; disable pullup on ATTN .endif .if COM_IRQ_BIT_ATTN == INT0 From 3e9aeeed05fdb02cbdab720ec3cd211a867aeb96 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 24 May 2025 17:24:46 +0200 Subject: [PATCH 52/58] allow for private tick counter and special timer frequencies. --- avr/devices/all/hw_tn841.asm | 4 ++++ avr/devices/t03/main/main.asm | 32 ++++++++++++++++++++++++++++++++ avr/modules/basetimer/main.asm | 4 ++++ 3 files changed, 40 insertions(+) diff --git a/avr/devices/all/hw_tn841.asm b/avr/devices/all/hw_tn841.asm index 1804319..8ca90c3 100644 --- a/avr/devices/all/hw_tn841.asm +++ b/avr/devices/all/hw_tn841.asm @@ -110,7 +110,11 @@ systemSetupTimer0: ; setup timer for IRQ every 100ms ldi r16, 78-1 out OCR0A, r16 +#ifdef BASETIMER_T841_FAST + ldi r16, 1 +#else ldi r16, 10 +#endif sts baseTimerModuleReloadValue, r16 sts baseTimerModuleTickCounter, r16 .endif diff --git a/avr/devices/t03/main/main.asm b/avr/devices/t03/main/main.asm index a37e92f..8947efb 100644 --- a/avr/devices/t03/main/main.asm +++ b/avr/devices/t03/main/main.asm @@ -53,6 +53,8 @@ #define MAIN_WITHOUT_MSG_HANDLING ; we do message handling ourselfes +#define BASETIMER_PRIVATE_TICK_FN ; we use our own system tick function +#define BASETIMER_T841_FAST ; call our tick every 10ms #define MODULES_CLOCK ;#define MODULES_COM @@ -90,6 +92,17 @@ .equ VALUE_ID_LEDSIMPLE_TIMING = 0x88 + +; *************************************************************************** +; data segment + +.dseg + +t03TickCounter: .byte 1 + + + + ; *************************************************************************** ; code segment @@ -148,6 +161,9 @@ firmwareVersion: .db FIRMWARE_VARIANT_TEMP_WINDOW, FIRMWARE_VERSION_MAJOR ; @routine firmwareStart @global firmwareStart: + cli + clr r16 + sts t03TickCounter, r16 rjmp main ; @end @@ -163,6 +179,22 @@ onSystemStart: +privateTimerTick: + lds r16, t03TickCounter + inc r16 + cpi r16, 10 + brcs privateTimerTick_store + clr r16 +privateTimerTick_store: + sts t03TickCounter, r16 + cpi r16, 0 + breq privateTimerTick_runSystemTick + ; TODO + ret +privateTimerTick_runSystemTick: + rjmp onSystemTimerTick + + diff --git a/avr/modules/basetimer/main.asm b/avr/modules/basetimer/main.asm index 077defc..55e46db 100644 --- a/avr/modules/basetimer/main.asm +++ b/avr/modules/basetimer/main.asm @@ -92,7 +92,11 @@ BaseTimer_Run: BaseTimer_Run_loop: ; for every timer tick push r24 push r25 +.ifdef BASETIMER_PRIVATE_TICK_FN + rcall privateTimerTick +.else rcall onSystemTimerTick +.endif pop r25 pop r24 sbiw r25:r24, 1 From b730fd068cf2597819dfae12c09fad3c220a70fb Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 24 May 2025 17:25:00 +0200 Subject: [PATCH 53/58] fixed apidoc. --- avr/modules/uart_hw/uart.asm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/avr/modules/uart_hw/uart.asm b/avr/modules/uart_hw/uart.asm index 3695514..6dff0d9 100644 --- a/avr/modules/uart_hw/uart.asm +++ b/avr/modules/uart_hw/uart.asm @@ -271,11 +271,11 @@ UART_StopRx: UART_StartTx: M_IO_READ r16, UCSRA - sbr r16, (1< Date: Sat, 24 May 2025 17:25:14 +0200 Subject: [PATCH 54/58] added README. --- avr/modules/uart_hw/README | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 avr/modules/uart_hw/README diff --git a/avr/modules/uart_hw/README b/avr/modules/uart_hw/README new file mode 100644 index 0000000..a8a7285 --- /dev/null +++ b/avr/modules/uart_hw/README @@ -0,0 +1,7 @@ +This folder contains multiple backends for hardware UART as provided by some AVR devices. + +uart.asm: simple UART code blocking for receiption and transmission +net_uart.asm: glue to connect NET interface to uart.asm + uses interrupt for ATTN line, no other interrupts used + + From 868c2b32f819563c99ee45a8c259c0c4b9af5e98 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 24 May 2025 17:25:24 +0200 Subject: [PATCH 55/58] Revert "allow for private tick counter and special timer frequencies." This reverts commit 3e9aeeed05fdb02cbdab720ec3cd211a867aeb96. --- avr/devices/all/hw_tn841.asm | 4 ---- avr/devices/t03/main/main.asm | 32 -------------------------------- avr/modules/basetimer/main.asm | 4 ---- 3 files changed, 40 deletions(-) diff --git a/avr/devices/all/hw_tn841.asm b/avr/devices/all/hw_tn841.asm index 8ca90c3..1804319 100644 --- a/avr/devices/all/hw_tn841.asm +++ b/avr/devices/all/hw_tn841.asm @@ -110,11 +110,7 @@ systemSetupTimer0: ; setup timer for IRQ every 100ms ldi r16, 78-1 out OCR0A, r16 -#ifdef BASETIMER_T841_FAST - ldi r16, 1 -#else ldi r16, 10 -#endif sts baseTimerModuleReloadValue, r16 sts baseTimerModuleTickCounter, r16 .endif diff --git a/avr/devices/t03/main/main.asm b/avr/devices/t03/main/main.asm index 8947efb..a37e92f 100644 --- a/avr/devices/t03/main/main.asm +++ b/avr/devices/t03/main/main.asm @@ -53,8 +53,6 @@ #define MAIN_WITHOUT_MSG_HANDLING ; we do message handling ourselfes -#define BASETIMER_PRIVATE_TICK_FN ; we use our own system tick function -#define BASETIMER_T841_FAST ; call our tick every 10ms #define MODULES_CLOCK ;#define MODULES_COM @@ -92,17 +90,6 @@ .equ VALUE_ID_LEDSIMPLE_TIMING = 0x88 - -; *************************************************************************** -; data segment - -.dseg - -t03TickCounter: .byte 1 - - - - ; *************************************************************************** ; code segment @@ -161,9 +148,6 @@ firmwareVersion: .db FIRMWARE_VARIANT_TEMP_WINDOW, FIRMWARE_VERSION_MAJOR ; @routine firmwareStart @global firmwareStart: - cli - clr r16 - sts t03TickCounter, r16 rjmp main ; @end @@ -179,22 +163,6 @@ onSystemStart: -privateTimerTick: - lds r16, t03TickCounter - inc r16 - cpi r16, 10 - brcs privateTimerTick_store - clr r16 -privateTimerTick_store: - sts t03TickCounter, r16 - cpi r16, 0 - breq privateTimerTick_runSystemTick - ; TODO - ret -privateTimerTick_runSystemTick: - rjmp onSystemTimerTick - - diff --git a/avr/modules/basetimer/main.asm b/avr/modules/basetimer/main.asm index 55e46db..077defc 100644 --- a/avr/modules/basetimer/main.asm +++ b/avr/modules/basetimer/main.asm @@ -92,11 +92,7 @@ BaseTimer_Run: BaseTimer_Run_loop: ; for every timer tick push r24 push r25 -.ifdef BASETIMER_PRIVATE_TICK_FN - rcall privateTimerTick -.else rcall onSystemTimerTick -.endif pop r25 pop r24 sbiw r25:r24, 1 From 027edb9abab63d7de582ebf04e2de3d09e0313d2 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 24 May 2025 17:26:59 +0200 Subject: [PATCH 56/58] removed waiting time between sending messages. now a message can be send after every interrupt. --- avr/modules/uart_hw/comonuart0.asm | 2 +- avr/modules/uart_hw/ttyonuart1.asm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/avr/modules/uart_hw/comonuart0.asm b/avr/modules/uart_hw/comonuart0.asm index 96c43a8..f4305da 100644 --- a/avr/modules/uart_hw/comonuart0.asm +++ b/avr/modules/uart_hw/comonuart0.asm @@ -10,7 +10,7 @@ .equ COMONUART0_IFACENUM = 1 .equ COMONUART0_READ_TIMEOUT = 3 -.equ COMONUART0_MSG_INTERVAL = 1 +.equ COMONUART0_MSG_INTERVAL = 0 diff --git a/avr/modules/uart_hw/ttyonuart1.asm b/avr/modules/uart_hw/ttyonuart1.asm index 2e436ea..2185ad2 100644 --- a/avr/modules/uart_hw/ttyonuart1.asm +++ b/avr/modules/uart_hw/ttyonuart1.asm @@ -9,7 +9,7 @@ .equ TTYONUART1_SKIPTIME = 2 -.equ TTYONUART1_MSG_INTERVAL = 2 +.equ TTYONUART1_MSG_INTERVAL = 0 .equ TTYONUART1_IFACENUM = 2 From 349c11d64157fd191f1c509fd75955d07e13ca9c Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 24 May 2025 17:45:33 +0200 Subject: [PATCH 57/58] reset uart_hw code to what works on t03. --- avr/modules/uart_hw/comonuart0.asm | 95 +++------------ avr/modules/uart_hw/lowlevel.asm | 1 - avr/modules/uart_hw/m_lowlevel_uart.asm | 146 +++++------------------- avr/modules/uart_hw/ttyonuart1.asm | 2 +- 4 files changed, 42 insertions(+), 202 deletions(-) diff --git a/avr/modules/uart_hw/comonuart0.asm b/avr/modules/uart_hw/comonuart0.asm index f4305da..60ebe7b 100644 --- a/avr/modules/uart_hw/comonuart0.asm +++ b/avr/modules/uart_hw/comonuart0.asm @@ -10,7 +10,7 @@ .equ COMONUART0_IFACENUM = 1 .equ COMONUART0_READ_TIMEOUT = 3 -.equ COMONUART0_MSG_INTERVAL = 0 +.equ COMONUART0_MSG_INTERVAL = 1 @@ -30,32 +30,17 @@ comOnUart0_iface: .byte UART_HW_IFACE_SIZE ComOnUart0_Init: ldi yl, LOW(comOnUart0_iface) ldi yh, HIGH(comOnUart0_iface) - rcall comOnUart0SetAttnInput ; (none) + rcall comOnUart0SetAttnInput ; (none) rcall UART_HW_Interface_Init ; (R16, R17, X) - rcall comOnUart0Init ; (R16, R17, X) + rcall comOnUart0Init ; (R16, R17, X) ldi r16, COMONUART0_IFACENUM std Y+NET_IFACE_OFFS_IFACENUM, r16 -.if COM_IRQ_BIT_ATTN == INT0 - M_IO_READ r16, MCUCR - cbr r16, (1< Date: Sat, 24 May 2025 17:49:01 +0200 Subject: [PATCH 58/58] t03: message forwarding is now much faster. this is very visible when flashing firmware to nodes via t03 device. --- avr/modules/uart_hw/comonuart0.asm | 2 +- avr/modules/uart_hw/ttyonuart1.asm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/avr/modules/uart_hw/comonuart0.asm b/avr/modules/uart_hw/comonuart0.asm index 60ebe7b..402dee0 100644 --- a/avr/modules/uart_hw/comonuart0.asm +++ b/avr/modules/uart_hw/comonuart0.asm @@ -10,7 +10,7 @@ .equ COMONUART0_IFACENUM = 1 .equ COMONUART0_READ_TIMEOUT = 3 -.equ COMONUART0_MSG_INTERVAL = 1 +.equ COMONUART0_MSG_INTERVAL = 0 diff --git a/avr/modules/uart_hw/ttyonuart1.asm b/avr/modules/uart_hw/ttyonuart1.asm index 2e436ea..2185ad2 100644 --- a/avr/modules/uart_hw/ttyonuart1.asm +++ b/avr/modules/uart_hw/ttyonuart1.asm @@ -9,7 +9,7 @@ .equ TTYONUART1_SKIPTIME = 2 -.equ TTYONUART1_MSG_INTERVAL = 2 +.equ TTYONUART1_MSG_INTERVAL = 0 .equ TTYONUART1_IFACENUM = 2