Loading include/driver/tsl2591.h 0 → 100644 +30 −0 Original line number Diff line number Diff line /* * Copyright 2020 Daniel Friesel * * SPDX-License-Identifier: BSD-2-Clause */ #ifndef TSL2591_H #define TSL2591_H class TSL2591 { private: TSL2591(const TSL2591 ©); unsigned char const address = 0x29; unsigned char txbuf[2]; unsigned char rxbuf[4]; public: TSL2591() {} unsigned short ch0; unsigned short ch1; void init(); unsigned char getStatus(); void read(); }; extern TSL2591 tsl2591; #endif src/app/datalogger/main.cc +13 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,9 @@ #ifdef DRIVER_MPU9250 #include "driver/mpu9250.h" #endif #ifdef DRIVER_TSL2591 #include "driver/tsl2591.h" #endif void loop(void) { Loading Loading @@ -127,6 +130,12 @@ void loop(void) kout.printf_float(max44009.getLux()); kout << endl; #endif #ifdef DRIVER_TSL2591 tsl2591.read(); kout << dec << "TSL2591 CH0: " << tsl2591.ch0 << " / CH1: " << tsl2591.ch1; kout << hex << " (status: 0x" << tsl2591.getStatus() << ")" << endl; #endif } int main(void) Loading Loading @@ -211,6 +220,10 @@ int main(void) mpu9250.init(); #endif #ifdef DRIVER_TSL2591 tsl2591.init(); #endif arch.idle_loop(); return 0; Loading src/driver/tsl2591.cc 0 → 100644 +38 −0 Original line number Diff line number Diff line /* * Copyright 2020 Daniel Friesel * * SPDX-License-Identifier: BSD-2-Clause */ #include "driver/tsl2591.h" #if defined(MULTIPASS_ARCH_HAS_I2C) && !defined(DRIVER_SOFTI2C) #include "driver/i2c.h" #else #include "driver/soft_i2c.h" #endif void TSL2591::init() { txbuf[0] = 0xa0; txbuf[1] = 0x03; i2c.xmit(address, 2, txbuf, 0, rxbuf); txbuf[0] = 0xa1; txbuf[1] = 0x01; // 200ms integration time i2c.xmit(address, 2, txbuf, 0, rxbuf); } void TSL2591::read() { txbuf[0] = 0xb4; i2c.xmit(address, 1, txbuf, 4, rxbuf); ch0 = (rxbuf[1] << 8) + rxbuf[0]; ch1 = (rxbuf[3] << 8) + rxbuf[2]; } unsigned char TSL2591::getStatus() { txbuf[0] = 0xb3; i2c.xmit(address, 1, txbuf, 1, rxbuf); return rxbuf[0]; } TSL2591 tsl2591; Loading
include/driver/tsl2591.h 0 → 100644 +30 −0 Original line number Diff line number Diff line /* * Copyright 2020 Daniel Friesel * * SPDX-License-Identifier: BSD-2-Clause */ #ifndef TSL2591_H #define TSL2591_H class TSL2591 { private: TSL2591(const TSL2591 ©); unsigned char const address = 0x29; unsigned char txbuf[2]; unsigned char rxbuf[4]; public: TSL2591() {} unsigned short ch0; unsigned short ch1; void init(); unsigned char getStatus(); void read(); }; extern TSL2591 tsl2591; #endif
src/app/datalogger/main.cc +13 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,9 @@ #ifdef DRIVER_MPU9250 #include "driver/mpu9250.h" #endif #ifdef DRIVER_TSL2591 #include "driver/tsl2591.h" #endif void loop(void) { Loading Loading @@ -127,6 +130,12 @@ void loop(void) kout.printf_float(max44009.getLux()); kout << endl; #endif #ifdef DRIVER_TSL2591 tsl2591.read(); kout << dec << "TSL2591 CH0: " << tsl2591.ch0 << " / CH1: " << tsl2591.ch1; kout << hex << " (status: 0x" << tsl2591.getStatus() << ")" << endl; #endif } int main(void) Loading Loading @@ -211,6 +220,10 @@ int main(void) mpu9250.init(); #endif #ifdef DRIVER_TSL2591 tsl2591.init(); #endif arch.idle_loop(); return 0; Loading
src/driver/tsl2591.cc 0 → 100644 +38 −0 Original line number Diff line number Diff line /* * Copyright 2020 Daniel Friesel * * SPDX-License-Identifier: BSD-2-Clause */ #include "driver/tsl2591.h" #if defined(MULTIPASS_ARCH_HAS_I2C) && !defined(DRIVER_SOFTI2C) #include "driver/i2c.h" #else #include "driver/soft_i2c.h" #endif void TSL2591::init() { txbuf[0] = 0xa0; txbuf[1] = 0x03; i2c.xmit(address, 2, txbuf, 0, rxbuf); txbuf[0] = 0xa1; txbuf[1] = 0x01; // 200ms integration time i2c.xmit(address, 2, txbuf, 0, rxbuf); } void TSL2591::read() { txbuf[0] = 0xb4; i2c.xmit(address, 1, txbuf, 4, rxbuf); ch0 = (rxbuf[1] << 8) + rxbuf[0]; ch1 = (rxbuf[3] << 8) + rxbuf[2]; } unsigned char TSL2591::getStatus() { txbuf[0] = 0xb3; i2c.xmit(address, 1, txbuf, 1, rxbuf); return rxbuf[0]; } TSL2591 tsl2591;