Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: veml60xx.h
- Revision:
- 1:d8d62aee6d5b
- Parent:
- 0:40b4ebf843c6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/veml60xx.h Thu Apr 21 23:32:50 2016 +0000
@@ -0,0 +1,212 @@
+#ifndef VEML60XX_H
+#define VEML60XX_H
+
+#include "mbed.h"
+
+// I2C address
+#define VEML60_WADDR 0x20 //i2c address write mode
+#define VEML60_RADDR 0x21 //i2c address read mode
+
+
+// VEMP6040 and VEML6075 common register set
+#define VEML60xx_CONF_REG 0x00 //rw Config Register
+
+// VEML6075-only register set
+#define VEML6075_UVA_DATA_REG 0x07 //ro 16 bit UVA data Register
+#define VEML6075_DUMMY_REG 0x08 //ro 16 bit dummy Register
+#define VEML6075_UVB_DATA_REG 0x09 //ro 16 bit UVB data Register
+#define VEML6075_UV_COMP1_REG 0x0A //ro 16 bit UV compensation Register 1
+#define VEML6075_UV_COMP2_REG 0x0B //ro 16 bit UV compensation Register 2
+#define VEML6075_CHIP_ID_REG 0x0C //ro 16 bit Chip ID Register
+
+// VEML6040-only register set
+#define VEML6040_R_DATA_REG 0x08 //ro 16 bit RED data
+#define VEML6040_G_DATA_REG 0x09 //ro 16 bit GREEN data
+#define VEML6040_B_DATA_REG 0x0A //ro 16 bit BLUE data
+#define VEML6040_W_DATA_REG 0x0B //ro 16 bit WHITE data
+
+// VEML6040 and VEML6075 common config register bits
+#define VEML60xx_CONF_BITS_IT 0x70 //VEML6075 -> 0x00 = 50mS, 0x10 = 100mS, 0x20 = 200mS, 0x30 = 400mS, 0x40 = 800mS, 0x50-0x70 = reserved
+ //VEML6040 -> 0x00 = 40mS, 0x10 = 80mS, 0x20 = 160mS, 0x30 = 320mS, 0x40 = 640mS, 0x50 = 1280mS, 0x60-0x70 = reserved
+#define VEML60xx_CONF_BITS_IT_50m40m 0x00
+#define VEML60xx_CONF_BITS_IT_100m80m 0x10
+#define VEML60xx_CONF_BITS_IT_200m160m 0x20
+#define VEML60xx_CONF_BITS_IT_400m320m 0x30
+#define VEML60xx_CONF_BITS_IT_800m640m 0x40
+
+#define VEML60xx_CONF_BITS_TRIG 0x04 //0x00 = idle, 0x04 = trigger (measurement), auto returns to 0x00 note: AF == 1
+#define VEML60xx_CONF_BITS_AF 0x02 //0x00 = auto, 0x02 = force (mode)
+#define VEML60xx_CONF_BITS_SD 0x01 //0x00 = run, 0x01 = shut down
+
+// VEML6075-only config register bits
+#define VEML6075_CONF_BITS_HD 0x08 //0x00 = normal, 0x08 = high (dynamic setting)
+
+// VEML6040-only config register bits
+#define VEML6040_CONF_BITS_IT_1280m 0x50
+
+// VEML6075-only ID contents
+#define VEML6075_DEVICE_ID 0x0026 //expected device ID
+
+// VEML6040-only ID contents
+#define VEML6040_DEVICE_ID 0x0123 //expected device ID
+
+// VEML6075-only conversion coefficients
+#define VEML6075_UVA_COEF_A 3.33
+#define VEML6075_UVA_COEF_B 2.50
+#define VEML6075_UVB_COEF_C 3.67
+#define VEML6075_UVB_COEF_D 2.75
+
+// VEML6040-only conversion coefficients
+#define VEML6040_LUX_STEP_000 0.18
+#define VEML6040_LUX_STEP_001 0.09
+#define VEML6040_LUX_STEP_010 0.045
+#define VEML6040_LUX_STEP_011 0.0225
+#define VEML6040_LUX_STEP_100 0.01125
+#define VEML6040_LUX_STEP_101 0.005625
+
+// VEML6075-only conversion coefficients
+#define VEML6075_UVA_RESP 0.0011
+#define VEML6075_UVB_RESP 0.00125
+
+
+ /**
+ * Create VEML60 controller class
+ *
+ * @param VEML class
+ *
+ */
+class veml60xx {
+
+public:
+
+ /**
+ * Public data structure for VEML60xx data values.
+ *
+ **/
+ typedef struct {
+ uint16_t conf_reg; /*!< VEML60xx config register mirror */
+
+ uint16_t uva_d; /*!< VEML6075 UVA data */
+ uint16_t dummy_d; /*!< VEML6075 Dummy data */
+ uint16_t uvb_d; /*!< VEML6075 UVB data */
+ uint16_t uv_c1; /*!< VEML6075 UV comp1 data */
+ uint16_t uv_c2; /*!< VEML6075 UV comp2 data */
+ uint16_t id; /*!< VEML6075 Device ID*/
+ double uva_comp; /*!< VEML6075 UVA compensated data */
+ double uvb_comp; /*!< VEML6075 UVB compensated data */
+ double uv_index; /*!< VEML6075 UV Index */
+
+ uint16_t r_d; /*!< VEML6040 RED data */
+ uint16_t g_d; /*!< VEML6040 GREEN data */
+ uint16_t b_d; /*!< VEML6040 BLUE data */
+ uint16_t w_d; /*!< VEML6040 WHITE data */
+ double lux_step; /*!< VEML6040 Lux value per step */
+
+ bool is6075; /*!< connected device is a VEML6075 */
+ bool is6040; /*!< connected device is a VEML6040 */
+ } veml60xx_struct;
+
+ /**
+ * Create a VME60xx object using the specified I2C object
+ *
+ * @param sda - mbed I2C interface pin
+ *
+ * @param scl - mbed I2C interface pin
+ *
+ * @param set_I2C_frequency
+ */
+ veml60xx(PinName sda, PinName scl, int i2cFrequency);
+
+ /**
+ * Destructor
+ *
+ * @param --none--
+ */
+ ~veml60xx();
+
+ /**
+ * Get VEMP6075 ID Register
+ *
+ * Note: the VEMP6040 seems to have an ID register. It's not published
+ *
+ * @param pointer to struct veml60xx_struct
+ *
+ * @return ID Register value
+ */
+ uint16_t getID(veml60xx_struct& Pntr);
+
+ /**
+ * Get VEMPxx Config Register
+ *
+ * @param pointer to struct veml60xx_struct
+ *
+ * @return Config Register value
+ */
+ uint16_t getConfig(veml60xx_struct& Pntr);
+
+ /**
+ * Get VEMP60xx Raw Data
+ *
+ * @param pointer to struct veml60xx_struct
+ *
+ * @return raw data put into struct vemp60xx_struct
+ */
+ uint16_t getRawData(veml60xx_struct& Pntr);
+
+ /**
+ * Convert the VEMP6075 Raw Data
+ *
+ * @param pointer to struct veml60xx_struct
+ *
+ * @return converted data put into struct vemp60xx_struct
+ */
+ void convertRawData(veml60xx_struct& Pntr);
+
+ /**
+ * Initialize the VEMP60xx
+ *
+ * Sets up the command register to proper operating mode
+ *
+ * @param pointer to struct veml60xx_struct
+ *
+ * @param val any value to be or'd into the config register
+ *
+ * @return 0
+ */
+ void setConfig(veml60xx_struct& Pntr, uint16_t val);
+
+ /**
+ * Trigger a VEMP60xx conversion cycle
+ *
+ * Must be in manual trigger mode (AF == 1)
+ *
+ * Example: uv.setConfig(struct_ptr, VEML60xx_CONF_BITS_AF);
+ *
+ * @param pointer to struct veml60xx_struct
+ *
+ * @return 0 TRIG properly set
+ * @return 1 TRIG has been previously set
+ * @return 2 AF bit not set (in AUTO mode)
+ */
+ uint16_t startAccess(veml60xx_struct& Pntr);
+
+ /**
+ * Automatically adjust Lux scaling level
+ *
+ * Change CONF_BITS_IT by +-1 if count bits saturated or too low
+ *
+ * @param pointer to struct veml60xx_struct
+ *
+ * @return true = IT scale value has changed
+ * @return false = IT scale value not changed, could be at its limit
+ */
+ bool autoAdjustLux(veml60xx_struct& Pntr);
+
+private:
+ char vemlBuffer[4];
+
+protected:
+ I2C* _i2c_;
+
+};
+#endif
\ No newline at end of file