diff options
author | Daniel Friesel <derf@finalrewind.org> | 2021-12-26 16:05:02 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2021-12-26 16:05:02 +0100 |
commit | 0b0bcc80bf689592dcb3236eed3e166d82cd7802 (patch) | |
tree | 7e811ee941000219048f3649087e9fa9fb98f08b /include | |
parent | bb9ea6b5445d256e294e6644623e63fd8ba0594e (diff) |
add basic MAX44006 driver
Diffstat (limited to 'include')
-rw-r--r-- | include/driver/max44006.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/include/driver/max44006.h b/include/driver/max44006.h new file mode 100644 index 0000000..ae5ad12 --- /dev/null +++ b/include/driver/max44006.h @@ -0,0 +1,80 @@ +/* + * Copyright 2021 Daniel Friesel + * + * SPDX-License-Identifier: BSD-2-Clause + */ +#ifndef MAX44006_H +#define MAX44006_H + +#include <stdint.h> + +/** + * Driver for MAX44006 RGB, IR, and Temperature Sensor. + * Does not support interrupts. + */ +class MAX44006 { + public: + + enum registers { + interruptStatusReg = 0x00, + mainConfigReg = 0x01, + ambientConfigReg = 0x02, + }; + + enum interruptStatus { + AMBINTS = 0b00000001, + PWRON = 0b00000010, + SHDN = 0b00001000, + RESET = 0b00010000, + }; + + enum mainConfig { + AMBINTE = 0b00000001, + AMBSEL_00 = 0b00000000, + AMBSEL_01 = 0b00000100, + AMBSEL_10 = 0b00001000, + AMBSEL_11 = 0b00001100, + MODE_00 = 0b00000000, + MODE_01 = 0b00010000, + MODE_10 = 0b00100000, + }; + + enum ambientConfig { + AMBPGA_00 = 0b00000000, + AMBPGA_01 = 0b00000001, + AMBPGA_10 = 0b00000010, + AMBPGA_11 = 0b00000011, + AMBTIM_000 = 0b00000000, + AMBTIM_001 = 0b00000100, + AMBTIM_010 = 0b00001000, + AMBTIM_011 = 0b00001100, + AMBTIM_100 = 0b00010000, + TEMPEN = 0b00100000, + COMPPEN = 0b01000000, + TRIm = 0b10000000, + }; + + private: + MAX44006(const MAX44006 ©); + unsigned char const address; + unsigned char txbuf[2]; + unsigned char rxbuf[10]; + + unsigned char ambtim; + unsigned char ambpga; + + uint16_t clear, red, green, blue, ir; + + public: + + MAX44006(unsigned char const addr = 0x45) : address(addr) {} + + uint8_t init(); + + uint16_t getTemperature(); + bool getLight(float *red, float *green, float *blue, float *clear, float *ir); +}; + +extern MAX44006 max44006; + +#endif |