Creating a project about VL6180XA1 for TT_Mxx

Committer:
ThunderSoft
Date:
Fri Apr 26 09:34:53 2019 +0000
Revision:
3:7a97a01bad5e
Parent:
0:293917667c17
"update the mbed-os code to support TT_M4G9"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ThunderSoft 0:293917667c17 1 #ifndef VL6180X_h
ThunderSoft 0:293917667c17 2 #define VL6180X_h
ThunderSoft 0:293917667c17 3
ThunderSoft 0:293917667c17 4 #include "mbed.h"
ThunderSoft 0:293917667c17 5
ThunderSoft 0:293917667c17 6 class VL6180X
ThunderSoft 0:293917667c17 7 {
ThunderSoft 0:293917667c17 8 public:
ThunderSoft 0:293917667c17 9 // register addresses
ThunderSoft 0:293917667c17 10 enum regAddr
ThunderSoft 0:293917667c17 11 {
ThunderSoft 0:293917667c17 12 IDENTIFICATION__MODEL_ID = 0x000,
ThunderSoft 0:293917667c17 13 IDENTIFICATION__MODEL_REV_MAJOR = 0x001,
ThunderSoft 0:293917667c17 14 IDENTIFICATION__MODEL_REV_MINOR = 0x002,
ThunderSoft 0:293917667c17 15 IDENTIFICATION__MODULE_REV_MAJOR = 0x003,
ThunderSoft 0:293917667c17 16 IDENTIFICATION__MODULE_REV_MINOR = 0x004,
ThunderSoft 0:293917667c17 17 IDENTIFICATION__DATE_HI = 0x006,
ThunderSoft 0:293917667c17 18 IDENTIFICATION__DATE_LO = 0x007,
ThunderSoft 0:293917667c17 19 IDENTIFICATION__TIME = 0x008, // 16-bit
ThunderSoft 0:293917667c17 20
ThunderSoft 0:293917667c17 21 SYSTEM__MODE_GPIO0 = 0x010,
ThunderSoft 0:293917667c17 22 SYSTEM__MODE_GPIO1 = 0x011,
ThunderSoft 0:293917667c17 23 SYSTEM__HISTORY_CTRL = 0x012,
ThunderSoft 0:293917667c17 24 SYSTEM__INTERRUPT_CONFIG_GPIO = 0x014,
ThunderSoft 0:293917667c17 25 SYSTEM__INTERRUPT_CLEAR = 0x015,
ThunderSoft 0:293917667c17 26 SYSTEM__FRESH_OUT_OF_RESET = 0x016,
ThunderSoft 0:293917667c17 27 SYSTEM__GROUPED_PARAMETER_HOLD = 0x017,
ThunderSoft 0:293917667c17 28
ThunderSoft 0:293917667c17 29 SYSRANGE__START = 0x018,
ThunderSoft 0:293917667c17 30 SYSRANGE__THRESH_HIGH = 0x019,
ThunderSoft 0:293917667c17 31 SYSRANGE__THRESH_LOW = 0x01A,
ThunderSoft 0:293917667c17 32 SYSRANGE__INTERMEASUREMENT_PERIOD = 0x01B,
ThunderSoft 0:293917667c17 33 SYSRANGE__MAX_CONVERGENCE_TIME = 0x01C,
ThunderSoft 0:293917667c17 34 SYSRANGE__CROSSTALK_COMPENSATION_RATE = 0x01E, // 16-bit
ThunderSoft 0:293917667c17 35 SYSRANGE__CROSSTALK_VALID_HEIGHT = 0x021,
ThunderSoft 0:293917667c17 36 SYSRANGE__EARLY_CONVERGENCE_ESTIMATE = 0x022, // 16-bit
ThunderSoft 0:293917667c17 37 SYSRANGE__PART_TO_PART_RANGE_OFFSET = 0x024,
ThunderSoft 0:293917667c17 38 SYSRANGE__RANGE_IGNORE_VALID_HEIGHT = 0x025,
ThunderSoft 0:293917667c17 39 SYSRANGE__RANGE_IGNORE_THRESHOLD = 0x026, // 16-bit
ThunderSoft 0:293917667c17 40 SYSRANGE__MAX_AMBIENT_LEVEL_MULT = 0x02C,
ThunderSoft 0:293917667c17 41 SYSRANGE__RANGE_CHECK_ENABLES = 0x02D,
ThunderSoft 0:293917667c17 42 SYSRANGE__VHV_RECALIBRATE = 0x02E,
ThunderSoft 0:293917667c17 43 SYSRANGE__VHV_REPEAT_RATE = 0x031,
ThunderSoft 0:293917667c17 44
ThunderSoft 0:293917667c17 45 SYSALS__START = 0x038,
ThunderSoft 0:293917667c17 46 SYSALS__THRESH_HIGH = 0x03A,
ThunderSoft 0:293917667c17 47 SYSALS__THRESH_LOW = 0x03C,
ThunderSoft 0:293917667c17 48 SYSALS__INTERMEASUREMENT_PERIOD = 0x03E,
ThunderSoft 0:293917667c17 49 SYSALS__ANALOGUE_GAIN = 0x03F,
ThunderSoft 0:293917667c17 50 SYSALS__INTEGRATION_PERIOD = 0x040,
ThunderSoft 0:293917667c17 51
ThunderSoft 0:293917667c17 52 RESULT__RANGE_STATUS = 0x04D,
ThunderSoft 0:293917667c17 53 RESULT__ALS_STATUS = 0x04E,
ThunderSoft 0:293917667c17 54 RESULT__INTERRUPT_STATUS_GPIO = 0x04F,
ThunderSoft 0:293917667c17 55 RESULT__ALS_VAL = 0x050, // 16-bit
ThunderSoft 0:293917667c17 56 RESULT__HISTORY_BUFFER_0 = 0x052, // 16-bit
ThunderSoft 0:293917667c17 57 RESULT__HISTORY_BUFFER_1 = 0x054, // 16-bit
ThunderSoft 0:293917667c17 58 RESULT__HISTORY_BUFFER_2 = 0x056, // 16-bit
ThunderSoft 0:293917667c17 59 RESULT__HISTORY_BUFFER_3 = 0x058, // 16-bit
ThunderSoft 0:293917667c17 60 RESULT__HISTORY_BUFFER_4 = 0x05A, // 16-bit
ThunderSoft 0:293917667c17 61 RESULT__HISTORY_BUFFER_5 = 0x05C, // 16-bit
ThunderSoft 0:293917667c17 62 RESULT__HISTORY_BUFFER_6 = 0x05E, // 16-bit
ThunderSoft 0:293917667c17 63 RESULT__HISTORY_BUFFER_7 = 0x060, // 16-bit
ThunderSoft 0:293917667c17 64 RESULT__RANGE_VAL = 0x062,
ThunderSoft 0:293917667c17 65 RESULT__RANGE_RAW = 0x064,
ThunderSoft 0:293917667c17 66 RESULT__RANGE_RETURN_RATE = 0x066, // 16-bit
ThunderSoft 0:293917667c17 67 RESULT__RANGE_REFERENCE_RATE = 0x068, // 16-bit
ThunderSoft 0:293917667c17 68 RESULT__RANGE_RETURN_SIGNAL_COUNT = 0x06C, // 32-bit
ThunderSoft 0:293917667c17 69 RESULT__RANGE_REFERENCE_SIGNAL_COUNT = 0x070, // 32-bit
ThunderSoft 0:293917667c17 70 RESULT__RANGE_RETURN_AMB_COUNT = 0x074, // 32-bit
ThunderSoft 0:293917667c17 71 RESULT__RANGE_REFERENCE_AMB_COUNT = 0x078, // 32-bit
ThunderSoft 0:293917667c17 72 RESULT__RANGE_RETURN_CONV_TIME = 0x07C, // 32-bit
ThunderSoft 0:293917667c17 73 RESULT__RANGE_REFERENCE_CONV_TIME = 0x080, // 32-bit
ThunderSoft 0:293917667c17 74
ThunderSoft 0:293917667c17 75 RANGE_SCALER = 0x096, // 16-bit - see STSW-IMG003 core/inc/vl6180x_def.h
ThunderSoft 0:293917667c17 76
ThunderSoft 0:293917667c17 77 READOUT__AVERAGING_SAMPLE_PERIOD = 0x10A,
ThunderSoft 0:293917667c17 78 FIRMWARE__BOOTUP = 0x119,
ThunderSoft 0:293917667c17 79 FIRMWARE__RESULT_SCALER = 0x120,
ThunderSoft 0:293917667c17 80 I2C_SLAVE__DEVICE_ADDRESS = 0x212,
ThunderSoft 0:293917667c17 81 INTERLEAVED_MODE__ENABLE = 0x2A3,
ThunderSoft 0:293917667c17 82 };
ThunderSoft 0:293917667c17 83
ThunderSoft 0:293917667c17 84 uint8_t last_status; // status of last I2C transmission
ThunderSoft 0:293917667c17 85
ThunderSoft 0:293917667c17 86 VL6180X(I2C *_i2c);
ThunderSoft 0:293917667c17 87
ThunderSoft 0:293917667c17 88 /**
ThunderSoft 0:293917667c17 89 * @brief Read device's ID.
ThunderSoft 0:293917667c17 90 * @return [device ID] 0x64.
ThunderSoft 0:293917667c17 91 */
ThunderSoft 0:293917667c17 92 uint8_t readID()
ThunderSoft 0:293917667c17 93 {
ThunderSoft 0:293917667c17 94 return readReg(IDENTIFICATION__MODEL_ID);
ThunderSoft 0:293917667c17 95 }
ThunderSoft 0:293917667c17 96
ThunderSoft 0:293917667c17 97 void setAddress(uint8_t new_addr);
ThunderSoft 0:293917667c17 98
ThunderSoft 0:293917667c17 99 void init(void);
ThunderSoft 0:293917667c17 100
ThunderSoft 0:293917667c17 101 void configureDefault(void);
ThunderSoft 0:293917667c17 102
ThunderSoft 0:293917667c17 103 void writeReg(uint16_t reg, uint8_t value);
ThunderSoft 0:293917667c17 104 void writeReg16Bit(uint16_t reg, uint16_t value);
ThunderSoft 0:293917667c17 105 void writeReg32Bit(uint16_t reg, uint32_t value);
ThunderSoft 0:293917667c17 106 uint8_t readReg(uint16_t reg);
ThunderSoft 0:293917667c17 107 uint16_t readReg16Bit(uint16_t reg);
ThunderSoft 0:293917667c17 108 uint32_t readReg32Bit(uint16_t reg);
ThunderSoft 0:293917667c17 109
ThunderSoft 0:293917667c17 110 uint32_t millis()
ThunderSoft 0:293917667c17 111 {
ThunderSoft 0:293917667c17 112 return 2;
ThunderSoft 0:293917667c17 113 }
ThunderSoft 0:293917667c17 114
ThunderSoft 0:293917667c17 115 void setScaling(uint8_t new_scaling);
ThunderSoft 0:293917667c17 116 inline uint8_t getScaling(void) { return scaling; }
ThunderSoft 0:293917667c17 117
ThunderSoft 0:293917667c17 118 uint8_t readRangeSingle(void);
ThunderSoft 0:293917667c17 119 inline uint16_t readRangeSingleMillimeters(void) { return (uint16_t)scaling * readRangeSingle(); }
ThunderSoft 0:293917667c17 120 uint16_t readAmbientSingle(void);
ThunderSoft 0:293917667c17 121
ThunderSoft 0:293917667c17 122 void startRangeContinuous(uint16_t period = 100);
ThunderSoft 0:293917667c17 123 void startAmbientContinuous(uint16_t period = 500);
ThunderSoft 0:293917667c17 124 void startInterleavedContinuous(uint16_t period = 500);
ThunderSoft 0:293917667c17 125 void stopContinuous();
ThunderSoft 0:293917667c17 126
ThunderSoft 0:293917667c17 127 uint8_t readRangeContinuous(void);
ThunderSoft 0:293917667c17 128 inline uint16_t readRangeContinuousMillimeters(void) { return (uint16_t)scaling * readRangeContinuous(); }
ThunderSoft 0:293917667c17 129 uint16_t readAmbientContinuous(void);
ThunderSoft 0:293917667c17 130
ThunderSoft 0:293917667c17 131 inline void setTimeout(uint16_t timeout) { io_timeout = timeout; }
ThunderSoft 0:293917667c17 132 inline uint16_t getTimeout(void) { return io_timeout; }
ThunderSoft 0:293917667c17 133 bool timeoutOccurred(void);
ThunderSoft 0:293917667c17 134
ThunderSoft 0:293917667c17 135 private:
ThunderSoft 0:293917667c17 136 I2C *i2c;
ThunderSoft 0:293917667c17 137 uint8_t address;
ThunderSoft 0:293917667c17 138 uint8_t scaling;
ThunderSoft 0:293917667c17 139 uint8_t ptp_offset;
ThunderSoft 0:293917667c17 140 uint16_t io_timeout;
ThunderSoft 0:293917667c17 141 bool did_timeout;
ThunderSoft 0:293917667c17 142 };
ThunderSoft 0:293917667c17 143
ThunderSoft 0:293917667c17 144 #endif
ThunderSoft 0:293917667c17 145
ThunderSoft 0:293917667c17 146
ThunderSoft 0:293917667c17 147
ThunderSoft 0:293917667c17 148