Loading include/driver/ds2482.h 0 → 100644 +26 −0 Original line number Diff line number Diff line /* * Copyright 2021 Daniel Friesel * * SPDX-License-Identifier: BSD-2-Clause * * DS2482-100 Single-Channel 1-Wire Master */ #pragma once class DS2482 { private: DS2482(const DS2482 ©); unsigned char const address; unsigned char txbuf[2]; unsigned char rxbuf[1]; public: DS2482(unsigned char const addr) : address(addr) {} void setup(); void busReset(); unsigned char status(); void readROM(unsigned char *data, unsigned char len); }; extern DS2482 ds2482; src/app/datalogger/main.cc +21 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,9 @@ #ifdef CONFIG_driver_ccs811 #include "driver/ccs811.h" #endif #ifdef CONFIG_driver_ds2482 #include "driver/ds2482.h" #endif #ifdef CONFIG_driver_max44009 #include "driver/max44009.h" #endif Loading Loading @@ -103,6 +106,20 @@ void loop(void) kout << "CCS811 tVOC / eCO₂ : " << ccs811.tvoc << " ppb / " << ccs811.eco2 << " ppm" << endl; #endif #ifdef CONFIG_driver_ds2482 unsigned char addr[8]; ds2482.readROM(addr, 8); kout << hex << "DS2482 ROM address: "; for (unsigned char i = 0; i < 8; i++) { kout << (unsigned int)addr[i]; } kout << " / "; for (signed char i = 7; i >= 0; i--) { kout << (unsigned int)addr[i]; } kout << endl; #endif #ifdef CONFIG_driver_hdc1080 /* hdc1080.heater(1); Loading Loading @@ -223,6 +240,10 @@ int main(void) arch.delay_ms(50); #endif #ifdef CONFIG_driver_ds2482 ds2482.setup(); #endif #ifdef CONFIG_driver_hdc1080 hdc1080.init(); if (hdc1080.getManufacturerID() != 0x5449) { Loading src/driver/Kconfig +4 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,10 @@ depends on meta_driver_i2c && !driver_bme280 && (arch_arduino_nano || arch_msp43 # ccs811 is broken and incomplete config driver_ds2482 bool "DS2482-100 Single-Channel 1-Wire Master" depends on meta_driver_i2c # dummy is AEMR-specific and not included in Kconfig config driver_eeprom24lc64 Loading src/driver/ds2482.cc 0 → 100644 +58 −0 Original line number Diff line number Diff line /* * Copyright 2021 Daniel Friesel * * SPDX-License-Identifier: BSD-2-Clause * * DS2482-100 Single-Channel 1-Wire Master */ #include "driver/ds2482.h" #if defined(MULTIPASS_ARCH_HAS_I2C) && !defined(CONFIG_driver_softi2c) #include "driver/i2c.h" #else #include "driver/soft_i2c.h" #endif #include "arch.h" void DS2482::setup() { txbuf[0] = 0xf0; i2c.xmit(address, 1, txbuf, 0, rxbuf); txbuf[0] = 0xd2; txbuf[1] = 0xf0; // default setting: passive pull-up, standard speed i2c.xmit(address, 2, txbuf, 0, rxbuf); } void DS2482::busReset() { txbuf[0] = 0xb4; i2c.xmit(address, 1, txbuf, 0, rxbuf); } unsigned char DS2482::status() { txbuf[0] = 0xe1; txbuf[0] = 0xf0; i2c.xmit(address, 2, txbuf, 1, rxbuf); return rxbuf[0]; } void DS2482::readROM(unsigned char *data, unsigned char len) { busReset(); arch.delay_ms(2); // reset low time (630us) + reset high time (614us) txbuf[0] = 0xa5; txbuf[1] = 0x33; i2c.xmit(address, 2, txbuf, 0, rxbuf); arch.delay_us(800); for (unsigned char i = 0; i < len; i++) { txbuf[0] = 0x96; i2c.xmit(address, 1, txbuf, 0, rxbuf); arch.delay_us(800); txbuf[0] = 0xe1; txbuf[1] = 0xe1; i2c.xmit(address, 2, txbuf, 1, rxbuf); data[i] = rxbuf[0]; } } DS2482 ds2482(0x18); Loading
include/driver/ds2482.h 0 → 100644 +26 −0 Original line number Diff line number Diff line /* * Copyright 2021 Daniel Friesel * * SPDX-License-Identifier: BSD-2-Clause * * DS2482-100 Single-Channel 1-Wire Master */ #pragma once class DS2482 { private: DS2482(const DS2482 ©); unsigned char const address; unsigned char txbuf[2]; unsigned char rxbuf[1]; public: DS2482(unsigned char const addr) : address(addr) {} void setup(); void busReset(); unsigned char status(); void readROM(unsigned char *data, unsigned char len); }; extern DS2482 ds2482;
src/app/datalogger/main.cc +21 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,9 @@ #ifdef CONFIG_driver_ccs811 #include "driver/ccs811.h" #endif #ifdef CONFIG_driver_ds2482 #include "driver/ds2482.h" #endif #ifdef CONFIG_driver_max44009 #include "driver/max44009.h" #endif Loading Loading @@ -103,6 +106,20 @@ void loop(void) kout << "CCS811 tVOC / eCO₂ : " << ccs811.tvoc << " ppb / " << ccs811.eco2 << " ppm" << endl; #endif #ifdef CONFIG_driver_ds2482 unsigned char addr[8]; ds2482.readROM(addr, 8); kout << hex << "DS2482 ROM address: "; for (unsigned char i = 0; i < 8; i++) { kout << (unsigned int)addr[i]; } kout << " / "; for (signed char i = 7; i >= 0; i--) { kout << (unsigned int)addr[i]; } kout << endl; #endif #ifdef CONFIG_driver_hdc1080 /* hdc1080.heater(1); Loading Loading @@ -223,6 +240,10 @@ int main(void) arch.delay_ms(50); #endif #ifdef CONFIG_driver_ds2482 ds2482.setup(); #endif #ifdef CONFIG_driver_hdc1080 hdc1080.init(); if (hdc1080.getManufacturerID() != 0x5449) { Loading
src/driver/Kconfig +4 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,10 @@ depends on meta_driver_i2c && !driver_bme280 && (arch_arduino_nano || arch_msp43 # ccs811 is broken and incomplete config driver_ds2482 bool "DS2482-100 Single-Channel 1-Wire Master" depends on meta_driver_i2c # dummy is AEMR-specific and not included in Kconfig config driver_eeprom24lc64 Loading
src/driver/ds2482.cc 0 → 100644 +58 −0 Original line number Diff line number Diff line /* * Copyright 2021 Daniel Friesel * * SPDX-License-Identifier: BSD-2-Clause * * DS2482-100 Single-Channel 1-Wire Master */ #include "driver/ds2482.h" #if defined(MULTIPASS_ARCH_HAS_I2C) && !defined(CONFIG_driver_softi2c) #include "driver/i2c.h" #else #include "driver/soft_i2c.h" #endif #include "arch.h" void DS2482::setup() { txbuf[0] = 0xf0; i2c.xmit(address, 1, txbuf, 0, rxbuf); txbuf[0] = 0xd2; txbuf[1] = 0xf0; // default setting: passive pull-up, standard speed i2c.xmit(address, 2, txbuf, 0, rxbuf); } void DS2482::busReset() { txbuf[0] = 0xb4; i2c.xmit(address, 1, txbuf, 0, rxbuf); } unsigned char DS2482::status() { txbuf[0] = 0xe1; txbuf[0] = 0xf0; i2c.xmit(address, 2, txbuf, 1, rxbuf); return rxbuf[0]; } void DS2482::readROM(unsigned char *data, unsigned char len) { busReset(); arch.delay_ms(2); // reset low time (630us) + reset high time (614us) txbuf[0] = 0xa5; txbuf[1] = 0x33; i2c.xmit(address, 2, txbuf, 0, rxbuf); arch.delay_us(800); for (unsigned char i = 0; i < len; i++) { txbuf[0] = 0x96; i2c.xmit(address, 1, txbuf, 0, rxbuf); arch.delay_us(800); txbuf[0] = 0xe1; txbuf[1] = 0xe1; i2c.xmit(address, 2, txbuf, 1, rxbuf); data[i] = rxbuf[0]; } } DS2482 ds2482(0x18);