i2c driver for VL6180x distance sensor

Dependents:   m3Dpi

Committer:
sillevl
Date:
Sat Dec 19 13:27:01 2015 +0000
Revision:
2:2e0406672e67
Parent:
1:6a00afc8dc84
add registernames and continuous mode

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sillevl 0:84c73bed7d92 1 #pragma once
sillevl 0:84c73bed7d92 2
sillevl 0:84c73bed7d92 3 #include "mbed.h"
sillevl 0:84c73bed7d92 4
sillevl 0:84c73bed7d92 5 class VL6180x
sillevl 0:84c73bed7d92 6 {
sillevl 0:84c73bed7d92 7
sillevl 0:84c73bed7d92 8 public:
sillevl 0:84c73bed7d92 9 struct Identification {
sillevl 0:84c73bed7d92 10 char model;
sillevl 0:84c73bed7d92 11 char modelRevMajor;
sillevl 0:84c73bed7d92 12 char modelRevMinor;
sillevl 0:84c73bed7d92 13 char moduleRevMajor;
sillevl 0:84c73bed7d92 14 char moduleRevMinor;
sillevl 0:84c73bed7d92 15 int date;
sillevl 0:84c73bed7d92 16 int time;
sillevl 0:84c73bed7d92 17 };
sillevl 0:84c73bed7d92 18
sillevl 0:84c73bed7d92 19 VL6180x(PinName sda, PinName scl, char _address = 0xE0);
sillevl 1:6a00afc8dc84 20 VL6180x(I2C &i2c, char address = 0xE0 );
sillevl 0:84c73bed7d92 21 void initialize();
sillevl 0:84c73bed7d92 22
sillevl 0:84c73bed7d92 23 int getDistance();
sillevl 2:2e0406672e67 24 int getSingleDistance();
sillevl 0:84c73bed7d92 25 float getAmbientLight();
sillevl 0:84c73bed7d92 26 Identification getIdentification();
sillevl 0:84c73bed7d92 27 static void printIdentification(Identification id);
sillevl 2:2e0406672e67 28 void startContinuousOperation();
sillevl 0:84c73bed7d92 29
sillevl 0:84c73bed7d92 30 void setRegister(int register, int value);
sillevl 0:84c73bed7d92 31 int getRegister(int reg);
sillevl 0:84c73bed7d92 32
sillevl 0:84c73bed7d92 33 void setAddress(int address);
sillevl 0:84c73bed7d92 34
sillevl 0:84c73bed7d92 35 protected:
sillevl 0:84c73bed7d92 36 int address;
sillevl 0:84c73bed7d92 37 I2C i2c;
sillevl 0:84c73bed7d92 38
sillevl 0:84c73bed7d92 39 static const int I2C_SLAVE_DEFAULT_ADDRESS = 0x52;
sillevl 2:2e0406672e67 40
sillevl 2:2e0406672e67 41 static const int IDENTIFICATION_MODEL_ID = 0x000;
sillevl 2:2e0406672e67 42 static const int IDENTIFICATION_MODEL_REV_MAJOR = 0x001;
sillevl 2:2e0406672e67 43 static const int IDENTIFICATION_MODEL_REV_MINOR = 0x002;
sillevl 2:2e0406672e67 44 static const int IDENTIFICATION_MODULE_REV_MAJOR = 0x003;
sillevl 2:2e0406672e67 45 static const int IDENTIFICATION_MODULE_REV_MINOR = 0x004;
sillevl 2:2e0406672e67 46 static const int IDENTIFICATION_DATE_HI = 0x006;
sillevl 2:2e0406672e67 47 static const int IDENTIFICATION_DATE_LO = 0x007;
sillevl 2:2e0406672e67 48 static const int IDENTIFICATION_TIME = 0x008;
sillevl 2:2e0406672e67 49 static const int SYSTEM_MODE_GPIO0 = 0x010;
sillevl 2:2e0406672e67 50 static const int SYSTEM_MODE_GPIO1 = 0x011;
sillevl 2:2e0406672e67 51 static const int SYSTEM_HISTORY_CTRL = 0x012;
sillevl 2:2e0406672e67 52 static const int SYSTEM_INTERRUPT_CONFIG_GPIO = 0x014;
sillevl 2:2e0406672e67 53 static const int SYSTEM_INTERRUPT_CLEAR = 0x015;
sillevl 2:2e0406672e67 54 static const int SYSTEM_FRESH_OUT_OF_RESET = 0x016;
sillevl 2:2e0406672e67 55 static const int SYSTEM_GROUPED_PARAMETER_HOLD = 0x017;
sillevl 2:2e0406672e67 56 static const int SYSRANGE_START = 0x018;
sillevl 2:2e0406672e67 57 static const int SYSRANGE_THRESH_HIGH = 0x019;
sillevl 2:2e0406672e67 58 static const int SYSRANGE_THRESH_LOW = 0x01A;
sillevl 2:2e0406672e67 59 static const int SYSRANGE_INTERMEASUREMENT_PERIOD = 0x01B;
sillevl 2:2e0406672e67 60 static const int SYSRANGE_MAX_CONVERGENCE_TIME = 0x01C;
sillevl 2:2e0406672e67 61 static const int SYSRANGE_CROSSTALK_COMPENSATION_RATE = 0x01E;
sillevl 2:2e0406672e67 62 static const int SYSRANGE_CROSSTALK_VALID_HEIGHT = 0x021;
sillevl 2:2e0406672e67 63 static const int SYSRANGE_EARLY_CONVERGENCE_ESTIMATE = 0x022;
sillevl 2:2e0406672e67 64 static const int SYSRANGE_PART_TO_PART_RANGE_OFFSET = 0x024;
sillevl 2:2e0406672e67 65 static const int SYSRANGE_RANGE_IGNORE_VALID_HEIGHT = 0x025;
sillevl 2:2e0406672e67 66 static const int SYSRANGE_RANGE_IGNORE_THRESHOLD = 0x026;
sillevl 2:2e0406672e67 67 static const int SYSRANGE_MAX_AMBIENT_LEVEL_MULT = 0x02C;
sillevl 2:2e0406672e67 68 static const int SYSRANGE_RANGE_CHECK_ENABLES = 0x02D;
sillevl 2:2e0406672e67 69 static const int SYSRANGE_VHV_RECALIBRATE = 0x02E;
sillevl 2:2e0406672e67 70 static const int SYSRANGE_VHV_REPEAT_RATE = 0x031;
sillevl 2:2e0406672e67 71 static const int SYSALS_START = 0x038;
sillevl 2:2e0406672e67 72 static const int SYSALS_THRESH_HIGH = 0x03A;
sillevl 2:2e0406672e67 73 static const int SYSALS_THRESH_LOW = 0x03C;
sillevl 2:2e0406672e67 74 static const int SYSALS_INTERMEASUREMENT_PERIOD = 0x03E;
sillevl 2:2e0406672e67 75 static const int SYSALS_ANALOGUE_GAIN = 0x03F;
sillevl 2:2e0406672e67 76 static const int SYSALS_INTEGRATION_PERIOD = 0x040;
sillevl 2:2e0406672e67 77 static const int RESULT_RANGE_STATUS = 0x04D;
sillevl 2:2e0406672e67 78 static const int RESULT_ALS_STATUS = 0x04E;
sillevl 2:2e0406672e67 79 static const int RESULT_INTERRUPT_STATUS_GPIO = 0x04F;
sillevl 2:2e0406672e67 80 static const int RESULT_ALS_VAL = 0x050;
sillevl 2:2e0406672e67 81 static const int RESULT_HISTORY_BUFFER_0 = 0x052;
sillevl 2:2e0406672e67 82 static const int RESULT_HISTORY_BUFFER_1 = 0x054;
sillevl 2:2e0406672e67 83 static const int RESULT_HISTORY_BUFFER_2 = 0x056;
sillevl 2:2e0406672e67 84 static const int RESULT_HISTORY_BUFFER_3 = 0x058;
sillevl 2:2e0406672e67 85 static const int RESULT_HISTORY_BUFFER_4 = 0x05A;
sillevl 2:2e0406672e67 86 static const int RESULT_HISTORY_BUFFER_5 = 0x05C;
sillevl 2:2e0406672e67 87 static const int RESULT_HISTORY_BUFFER_6 = 0x05E;
sillevl 2:2e0406672e67 88 static const int RESULT_HISTORY_BUFFER_7 = 0x060;
sillevl 2:2e0406672e67 89 static const int RESULT_RANGE_VAL = 0x062;
sillevl 2:2e0406672e67 90 static const int RESULT_RANGE_RAW = 0x064;
sillevl 2:2e0406672e67 91 static const int RESULT_RANGE_RETURN_RATE = 0x066;
sillevl 2:2e0406672e67 92 static const int RESULT_RANGE_REFERENCE_RATE = 0x068;
sillevl 2:2e0406672e67 93 static const int RESULT_RANGE_RETURN_SIGNAL_COUNT = 0x06C;
sillevl 2:2e0406672e67 94 static const int RESULT_RANGE_REFERENCE_SIGNAL_COUNT = 0x070;
sillevl 2:2e0406672e67 95 static const int RESULT_RANGE_RETURN_AMB_COUNT = 0x074;
sillevl 2:2e0406672e67 96 static const int RESULT_RANGE_REFERENCE_AMB_COUNT = 0x078;
sillevl 2:2e0406672e67 97 static const int RESULT_RANGE_RETURN_CONV_TIME = 0x07C;
sillevl 2:2e0406672e67 98 static const int RESULT_RANGE_REFERENCE_CONV_TIME = 0x080;
sillevl 2:2e0406672e67 99 static const int READOUT_AVERAGING_SAMPLE_PERIOD = 0x10A;
sillevl 2:2e0406672e67 100 static const int FIRMWARE_BOOTUP = 0x119;
sillevl 2:2e0406672e67 101 static const int FIRMWARE_RESULT_SCALER = 0x120;
sillevl 0:84c73bed7d92 102 static const int I2C_SLAVE_DEVICE_ADDRESS = 0x212;
sillevl 0:84c73bed7d92 103 static const int INTERLEAVED_MODE_ENABLE = 0x2A3;
sillevl 0:84c73bed7d92 104 };