avr: added device n27.

This commit is contained in:
Martin Preuss
2025-06-25 00:05:47 +02:00
parent bf50871208
commit 81721ab7eb
11 changed files with 687 additions and 0 deletions

View File

@@ -36,6 +36,7 @@
n24
n25
n26
n27
t03
</subdirs>

2
avr/devices/n27/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*.eep.hex
*.obj

22
avr/devices/n27/0BUILD Normal file
View File

@@ -0,0 +1,22 @@
<?xml?>
<gwbuild>
<subdirs>
boot
main
</subdirs>
<data dist="true" install="$(datadir)/aqhome/devices/nodes">
aqua_n27.xml
</data>
<extradist>
defs.asm
README
</extradist>
</gwbuild>

15
avr/devices/n27/README Normal file
View File

@@ -0,0 +1,15 @@
N27
===
- Role: Air quality and climate sensors
- MCU: AtTiny84
- Connection: RJ45
- Predecessor: N24, N23, N19
- Periphery:
- PIR sensor (AMN31112)
- TWI interface
- SI7021 temperature and humidity sensor
or
- SGP-30/40 air quality sensor

View File

@@ -0,0 +1,27 @@
<device name="aqua_n27" driver="nodes">
<manufacturer>AQUA</manufacturer>
<devicetype>N</devicetype>
<deviceversion>27</deviceversion>
<values>
<value name="SI7021_TEMP" id="0x01" type="sensor" dataType="rational" modality="temperature" units="C" denom="100" />
<value name="SI7021_HUM" id="0x02" type="sensor" dataType="rational" modality="humidity" units="%" denom="1" />
<value name="MOTION" id="0x07" type="sensor" dataType="rational" modality="motion" denom="1" />
<value name="SGP40_VALUE" id="0x08" type="sensor" dataType="rational" modality="tvoc" denom="1" />
<value name="SGP30_TVOC" id="0x09" type="sensor" dataType="rational" modality="tvoc" denom="1" />
<value name="SGP30_CO2" id="0x0a" type="sensor" dataType="rational" modality="co2" denom="1" />
<value name="LIGHT" id="0x0b" type="sensor" dataType="rational" modality="light" denom="1" />
<value name="stats_packets_in" id="0xe0" type="sensor" dataType="uint16" denom="1" />
<value name="stats_packets_out" id="0xe1" type="sensor" dataType="uint16" denom="1" />
<value name="stats_content_errors" id="0xe2" type="sensor" dataType="uint16" denom="1" />
<value name="stats_io_errors" id="0xe3" type="sensor" dataType="uint16" denom="1" />
<value name="stats_nobuf_errors" id="0xe4" type="sensor" dataType="uint16" denom="1" />
<value name="stats_collision_errors" id="0xe5" type="sensor" dataType="uint16" denom="1" />
<value name="stats_busy_errors" id="0xe6" type="sensor" dataType="uint16" denom="1" />
<value name="LEDTIMING" id="0x88" type="actor" dataType="uint16" />
</values>
</device>

View File

@@ -0,0 +1,32 @@
<?xml?>
<gwbuild>
<target type="AvrHexFile" name="n27_boot" >
<includes type="avrasm" >
-I $(builddir)
-I $(srcdir)
-I $(topsrcdir)/avr
-I $(topbuilddir)/avr
</includes>
<sources type="avrasm" >
boot.asm
</sources>
</target>
<subdirs>
</subdirs>
<extradist>
</extradist>
</gwbuild>

View File

@@ -0,0 +1,157 @@
; ***************************************************************************
; 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 base system node on AtTiny 84
;
; This is for the maintenance system (i.e. the flash loader).
;
; All definitions and changes should go into this file.
; ***************************************************************************
.equ clock=1000000 ; Define the clock frequency
.nolist
.include "include/tn84def.inc" ; Define device ATtiny84
.list
.include "version.asm"
.include "../defs.asm"
.include "common/calls.asm"
.include "devices/all/defs.asm"
#define COM_ACCEPT_ALL_DEST
; ***************************************************************************
; defines
; ---------------------------------------------------------------------------
; generic
.include "common/utils_wait.asm"
.include "modules/com2/defs.asm"
.include "modules/comproto/defs.asm"
; ---------------------------------------------------------------------------
; firmware settings
; ---------------------------------------------------------------------------
; LED
.equ LED_DDR = DDRA
.equ LED_PORT = PORTA
.equ LED_PIN = PINA
.equ LED_PINNUM = PORTA3
; ***************************************************************************
; code segment
.cseg
.org 0x0000
; ---------------------------------------------------------------------------
; Reset and interrupt vectors
; rjmp start ; Reset vector
rjmp main ; Reset vector
reti ; EXT_INT0
reti ; PCI0
reti ; PCI1
reti ; WATCHDOG
reti ; ICP1
reti ; OC1A
reti ; OC1B
reti ; OVF1
reti ; OC0A
reti ; OC0B
reti ; OVF0
reti ; ACI
reti ; ADCC
reti ; ERDY
reti ; USI_STR
reti ; USI_OVF
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:
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_bitbang.asm"
.include "modules/flash/flash1p.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 clock == 8000000
ldi r16, (1<<CLKPCE)
ldi r17, 0
out CLKPR, r16
out CLKPR, r17
.endif
.if clock == 1000000
ldi r16, (1<<CLKPCE)
ldi r17, (1<<CLKPS1) | (1<<CLKPS0)
out CLKPR, r16
out CLKPR, r17
.endif
ret

159
avr/devices/n27/defs.asm Normal file
View File

@@ -0,0 +1,159 @@
; ***************************************************************************
; 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. *
; ***************************************************************************
; ***************************************************************************
;
; AtTiny84
; --------
; VCC 1 14 GND
; AUX-PB0 PB0 2 13 PA0 LUM
; PIR PB1 3 12 PA1 COM-DATA
; /RESET PB3 4 11 PA2 AUX-PA2
; PB2 5 10 PA3 LED
; COM_ATTN PA7 6 9 PA4 TWI-SCL
; TWI-SDA PA6 7 8 PA5
; --------
;
; ***************************************************************************
.equ BOOTLOADER_ADDR = 0xd00
.equ FIRMWARE_VARIANT_BOOT = 0
.equ FIRMWARE_VARIANT_TEMP_WINDOW = 1
.equ DEVICEINFO_ID = 'N'
.equ DEVICEINFO_VERSION = 27
.equ DEVICEINFO_REVISION = 0
; ---------------------------------------------------------------------------
; LED module
.equ LED_SIMPLE_ONTIME = 1 ; shorter
.equ LED_SIMPLE_OFFTIME = 50 ; longer
.equ LED_SIMPLE_DDR = DDRA
.equ LED_SIMPLE_PORT = PORTA
.equ LED_SIMPLE_PORTIN = PINA
.equ LED_SIMPLE_PINNUM = PORTA3
; ---------------------------------------------------------------------------
; COM module
.equ COM_BIT_LENGTH = 52000 ; 104000ns=9600, 52000ns=19200, 26000ns=38400
.equ COM_HALFBIT_LENGTH = 26000 ; see https://de.wikipedia.org/wiki/Universal_Asynchronous_Receiver_Transmitter
.equ COM_DATA_DDR = DDRA
.equ COM_DATA_INPUT = PINA
.equ COM_DATA_OUTPUT = PORTA
.equ COM_DATA_PIN = PORTA1
.equ COM_ATTN_DDR = DDRA
.equ COM_ATTN_INPUT = PINA
.equ COM_ATTN_OUTPUT = PORTA
.equ COM_ATTN_PIN = PORTA7
.equ COM_IRQ_ADDR_ATTN = PCMSK0
.equ COM_IRQ_BIT_ATTN = PCINT7 ; bit 7 in PCMSK0
.equ COM_IRQ_GIFR_ATTN = PCIF0
.equ COM_IRQ_GIMSK_ATTN = PCIE0
; ---------------------------------------------------------------------------
; TWI master module
;.equ TWI_BIT_LENGTH = 10000 ; 100000 and 200000 works for display: 10000, 100000, 200000
.equ TWI_BIT_LENGTH = 1 ; 10, 100, 500, 100000 and 200000 works for display: 10000, 100000, 200000
.equ TWI_DDR_SCL = DDRA
.equ TWI_PORT_SCL = PORTA
.equ TWI_PIN_SCL = PINA
.equ TWI_PINNUM_SCL = PORTA4
.equ TWI_DDR_SDA = DDRA
.equ TWI_PORT_SDA = PORTA
.equ TWI_PIN_SDA = PINA
.equ TWI_PINNUM_SDA = PORTA6
; ---------------------------------------------------------------------------
; LCD module
.equ LCD_TWI_ADDRESS = 0x3c
; ---------------------------------------------------------------------------
; SI 7021
.equ SI7021_ADDR = 0x40
; ---------------------------------------------------------------------------
; SGB 30
.equ SGP30_ADDR = 0x58
; ---------------------------------------------------------------------------
; SGB 40
.equ SGP40_ADDR = 0x59
; ---------------------------------------------------------------------------
; 1-Wire Master
;
.equ OWI_DDR = DDRB
.equ OWI_PORTOUT = PORTB
.equ OWI_PORTIN = PINB
.equ OWI_PINNUM = PORTB2
; ---------------------------------------------------------------------------
; Motion Sensor
;
.equ MOTION_DDR = DDRB
.equ MOTION_INPUT = PINB
.equ MOTION_OUTPUT = PORTB
.equ MOTION_PIN = PORTB1
; ---------------------------------------------------------------------------
; CCS 811
;
.equ CCS811_ADDR = 0x5a ; or 0x5b
; ---------------------------------------------------------------------------
; Brightness
.equ BRIGHTNESS_ADC_PORT = PORTA ; adc0
.equ BRIGHTNESS_ADC_DDR = DDRA
.equ BRIGHTNESS_ADC_PIN = PORTA0
.equ BRIGHTNESS_ADC_MUX = 0

View File

@@ -0,0 +1,34 @@
<?xml?>
<gwbuild>
<target type="AvrHexFile" name="n27_firmware" >
<includes type="avrasm" >
-I $(builddir)
-I $(srcdir)
-I $(topsrcdir)/avr
-I $(topbuilddir)/avr
</includes>
<sources type="avrasm" >
main.asm
</sources>
</target>
<subdirs>
</subdirs>
<extradist>
data.asm
</extradist>
</gwbuild>

View File

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

View File

@@ -0,0 +1,224 @@
; ***************************************************************************
; 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/tn84def.inc" ; Define device ATtiny84
.list
.include "../defs.asm"
.include "./data.asm"
.include "version.asm"
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_wait.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
; #define MODULES_TIMER
#define MODULES_CLOCK
#define MODULES_LED_SIMPLE
#define MODULES_NETWORK
#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 MODULES_BRIGHTNESS
#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_BRIGHTNESS = 0x0b
;.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 (will be removed as soon as we can flash data over COM)
; rjmp main ; Reset vector
rjmp BOOTLOADER_ADDR ; Reset vector ; use this for flashed system
reti ; EXT_INT0
rjmp UART_BitBang_PcintIsr ; PCI0
reti ; PCI1
reti ; WATCHDOG
reti ; ICP1
reti ; OC1A
reti ; OC1B
reti ; OVF1
rjmp baseTimerIrqOC0A ; OC0A
reti ; OC0B
reti ; OVF0
reti ; ACI
reti ; ADCC
reti ; ERDY
reti ; USI_STR
reti ; USI_OVF
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_tn84.asm"
.include "devices/all/includes.asm"
; ---------------------------------------------------------------------------
; defines for network interface
.equ netInterfaceData = uart_bitbang_iface