diff --git a/avr/apps/reportsensors/main.asm b/avr/apps/reportsensors/main.asm index a584b1a..94a7dd8 100644 --- a/avr/apps/reportsensors/main.asm +++ b/avr/apps/reportsensors/main.asm @@ -53,6 +53,13 @@ AppReportSensors_Fini: ; AppReportSensors_OnEverySecond: + in r15, SREG + push r15 + cli + rcall AppReportSensors_OnEverySecond_noIrqs + out SREG, r15 + ret +AppReportSensors_OnEverySecond_noIrqs: lds r16, reportSensorTimer inc r16 cpi r16, APP_REPORT_SENSORS_INTERVAL_SECS @@ -60,6 +67,13 @@ AppReportSensors_OnEverySecond: clr r16 AppReportSensors_OnEverySecond_store: sts reportSensorTimer, r16 + +#ifdef MODULES_SGP30 +; push r16 +; rcall SGP30_Measure +; pop r16 +#endif + #ifdef MODULES_SI7021 cpi r16, 1 breq AppReportSensors_OnEverySecond_measureValue1 @@ -70,11 +84,30 @@ AppReportSensors_OnEverySecond_store: cpi r16, 49 breq AppReportSensors_OnEverySecond_sendValue2 #endif + +#ifdef MODULES_SGP40 + cpi r16, 27 + breq AppReportSensors_OnEverySecond_measureValue4 + cpi r16, 55 + breq AppReportSensors_OnEverySecond_sendValue4 +#endif + +#ifdef MODULES_SGP30 + cpi r16, 29 + breq AppReportSensors_OnEverySecond_measureValue5 + cpi r16, 57 + breq AppReportSensors_OnEverySecond_sendValue5 + cpi r16, 59 + breq AppReportSensors_OnEverySecond_sendValue6 +#endif + #ifdef MODULES_DS18B20 cpi r16, 9 breq AppReportSensors_OnEverySecond_sendValue3 #endif + ret + #ifdef MODULES_SI7021 AppReportSensors_OnEverySecond_measureValue1: rjmp SI7021_MeasureTemp @@ -85,10 +118,29 @@ AppReportSensors_OnEverySecond_sendValue1: AppReportSensors_OnEverySecond_sendValue2: rjmp SI7021_SendHumidity #endif + #ifdef MODULES_DS18B20 AppReportSensors_OnEverySecond_sendValue3: rjmp Ds18b20_SendTemperature #endif + +#ifdef MODULES_SGP40 + AppReportSensors_OnEverySecond_measureValue4: + rjmp SGP40_MeasureRawSignal + AppReportSensors_OnEverySecond_sendValue4: + rjmp SGP40_SendTVOC +#endif + +#ifdef MODULES_SGP30 + AppReportSensors_OnEverySecond_measureValue5: + rjmp SGP30_Measure + AppReportSensors_OnEverySecond_sendValue5: + rjmp SGP30_SendTVOC + ret + AppReportSensors_OnEverySecond_sendValue6: + rjmp SGP30_SendCO2 +#endif + ; @end diff --git a/avr/devices/all/includes.asm b/avr/devices/all/includes.asm index b6323bc..a526ebc 100644 --- a/avr/devices/all/includes.asm +++ b/avr/devices/all/includes.asm @@ -88,6 +88,20 @@ .include "common/multiply.asm" #endif +#ifdef MODULES_SGP30 +.include "modules/sgp30/main.asm" + #ifdef MODULES_NETWORK + .include "modules/sgp30/send.asm" + #endif +#endif + +#ifdef MODULES_SGP40 +.include "modules/sgp40/main.asm" + #ifdef MODULES_NETWORK + .include "modules/sgp40/send.asm" + #endif +#endif + #ifdef MODULES_OWI_MASTER .include "modules/owimaster/main.asm" #endif diff --git a/avr/devices/all/main.asm b/avr/devices/all/main.asm index 3fc3ee1..c86ffe4 100644 --- a/avr/devices/all/main.asm +++ b/avr/devices/all/main.asm @@ -148,6 +148,7 @@ sysOnEveryMinute: #ifdef APPS_STATS rcall AppStats_OnEveryMinute #endif + rjmp onEveryMinute ; @end diff --git a/avr/devices/all/modules.asm b/avr/devices/all/modules.asm index 56d566b..04592d4 100644 --- a/avr/devices/all/modules.asm +++ b/avr/devices/all/modules.asm @@ -87,6 +87,14 @@ initModules: rcall SI7021_Init #endif +#ifdef MODULES_SGP30 + rcall SGP30_Init +#endif + +#ifdef MODULES_SGP40 + rcall SGP40_Init +#endif + #ifdef MODULES_DS18B20 rcall Ds18b20_Init #endif diff --git a/avr/devices/n23/defs.asm b/avr/devices/n23/defs.asm index 276db01..0373b4a 100644 --- a/avr/devices/n23/defs.asm +++ b/avr/devices/n23/defs.asm @@ -103,6 +103,19 @@ +; --------------------------------------------------------------------------- +; SGB 30 + +.equ SGP30_ADDR = 0x58 + + + +; --------------------------------------------------------------------------- +; SGB 40 + +.equ SGP40_ADDR = 0x59 + + ; --------------------------------------------------------------------------- ; 1-Wire Master ; diff --git a/avr/devices/n23/main/main.asm b/avr/devices/n23/main/main.asm index 6987604..2eb7f8b 100644 --- a/avr/devices/n23/main/main.asm +++ b/avr/devices/n23/main/main.asm @@ -69,6 +69,8 @@ ;#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 diff --git a/avr/modules/0BUILD b/avr/modules/0BUILD index c5d7f25..16da38b 100644 --- a/avr/modules/0BUILD +++ b/avr/modules/0BUILD @@ -19,6 +19,8 @@ motion owimaster reed + sgp30 + sgp40 si7021 sk6812 stats diff --git a/avr/modules/sgp30/0BUILD b/avr/modules/sgp30/0BUILD new file mode 100644 index 0000000..c3dec70 --- /dev/null +++ b/avr/modules/sgp30/0BUILD @@ -0,0 +1,12 @@ + + + + + + main.asm + send.asm + + + + + diff --git a/avr/modules/sgp30/main.asm b/avr/modules/sgp30/main.asm new file mode 100644 index 0000000..9332a5a --- /dev/null +++ b/avr/modules/sgp30/main.asm @@ -0,0 +1,327 @@ +; *************************************************************************** +; 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 SGP30_FLAGS_PRESENT_BIT = 7 +.equ SGP30_FLAGS_DATAVALID_BIT = 6 + + +.equ SGP30_CMD_INIT = 0x2003 +.equ SGP30_CMD_MEASURE = 0x2008 + +.equ SGP30_VALUE_TVOC = 0x01 +.equ SGP30_VALUE_CO2 = 0x02 + + + +; *************************************************************************** +; data + +.dseg + +sgp30DataBegin: + sgp30Flags: .byte 1 + sgp30LastCo2: .byte 2 + sgp30LastTvoc: .byte 2 +sgp30DataEnd: + + + + +; *************************************************************************** +; code + +.cseg + + + +; --------------------------------------------------------------------------- +; SGP30_Init +; + +SGP30_Init: + ldi xh, HIGH(sgp30DataBegin) + ldi xl, LOW(sgp30DataBegin) + clr r16 + ldi r17, (sgp30DataEnd-sgp30DataBegin) + rcall Utils_FillSram + + rjmp sg30InitIfNeeded +; @end + + + +; --------------------------------------------------------------------------- +; SGP30_Fini +; + +SGP30_Fini: + sec + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine SGP30_GetValue @global +; +; @param R16 value to get (SI7021_VALUE_TEMP, SI7021_VALUE_HUMIDITY) +; @return CFLAG set if value available, cleared otherwise +; @return R19:R18 value +; @return R21:R20 denom (e.g. 100, meaning value must be divided by 100) +; @clobbers + +SGP30_GetValue: + lds r18, sgp30Flags + andi r18, (1< + + + + + main.asm + send.asm + + + + + diff --git a/avr/modules/sgp40/main.asm b/avr/modules/sgp40/main.asm new file mode 100644 index 0000000..ecff006 --- /dev/null +++ b/avr/modules/sgp40/main.asm @@ -0,0 +1,212 @@ +; *************************************************************************** +; 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 SGP40_FLAGS_PRESENT_BIT = 7 +.equ SGP40_FLAGS_DATAVALID_BIT = 6 + +.equ SGP40_CMD_MEASURE = 0x260f + + + +; *************************************************************************** +; data + +.dseg + +sgp40DataBegin: + sgp40Flags: .byte 1 + sgp40LastValue: .byte 2 +sgp40DataEnd: + + + +; *************************************************************************** +; code + +.cseg + + + +; --------------------------------------------------------------------------- +; SGP40_Init +; + +SGP40_Init: + ldi xh, HIGH(sgp40DataBegin) + ldi xl, LOW(sgp40DataBegin) + clr r16 + ldi r17, (sgp40DataEnd-sgp40DataBegin) + rcall Utils_FillSram + + ; check presence + rcall sgp40CheckPresence + brcc SGP40_Init_error + lds r16, sgp40Flags + ori r16, (1<