Changes to the library related to interrupt mode.
Dependencies: ST_INTERFACES X_NUCLEO_COMMON
Dependents: Display_53L0A1_IntSatelites Display_53L0A1_InterruptMode
Fork of X_NUCLEO_53L0A1 by
Revision 11:c955adfbb19b, committed 2017-06-14
- Comitter:
- JerrySzczurak
- Date:
- Wed Jun 14 13:35:05 2017 +0000
- Parent:
- 10:faf8d62ce6d1
- Child:
- 12:820afb1af4ef
- Commit message:
- Changes to library related to interrupt mode.
Changed in this revision
--- a/Components/VL53L0X/vl53l0x_class.cpp Wed Jun 07 14:58:36 2017 +0000
+++ b/Components/VL53L0X/vl53l0x_class.cpp Wed Jun 14 13:35:05 2017 +0000
@@ -4112,7 +4112,6 @@
Status = VL53L0X_ClearInterruptMask(Dev, 0);
}
-
LOG_FUNCTION_END(Status);
return Status;
}
@@ -5030,8 +5029,7 @@
return 0;
}
-
-int VL53L0X::ReadID(uint8_t *id)
+int VL53L0X::read_id(uint8_t *id)
{
int status = 0;
uint16_t rl_id=0;
@@ -5042,6 +5040,11 @@
return -1;
}
+
+int VL53L0X::ReadID(uint8_t *id)
+{
+ return read_id(id);
+}
VL53L0X_Error VL53L0X::WaitMeasurementDataReady(VL53L0X_DEV Dev)
@@ -5148,9 +5151,30 @@
}
return status;
}
-
-
-
+
+int VL53L0X::RangeMeasIntContinuousMode(void (*fptr)(void))
+{
+ int status, ClrStatus;
+
+ status = VL53L0X_SetGpioConfig(Device, 0, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING,
+ VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY,
+ VL53L0X_INTERRUPTPOLARITY_HIGH);
+
+ if (!status)
+ {
+ AttachInterruptMeasureDetectionIRQ(fptr);
+ EnableInterruptMeasureDetectionIRQ();
+ }
+
+ ClrStatus=ClearInterrupt(VL53L0X_REG_RESULT_INTERRUPT_STATUS|VL53L0X_REG_RESULT_RANGE_STATUS);
+ if(ClrStatus)
+ VL53L0X_ErrLog("VL53L0X_ClearErrorInterrupt fail\r\n");
+ if(!status)
+ {
+ status=RangeStartContinuousMode();
+ }
+ return status;
+}
int VL53L0X::StartMeasurement(OperatingMode operating_mode, void (*fptr)(void))
@@ -5167,7 +5191,23 @@
uint8_t preRangeVcselPeriod = 14;
uint8_t finalRangeVcselPeriod = 10;
-
+ if (operating_mode == range_continuous_interrupt)
+ {
+ if (gpio1Int==NULL)
+ {
+ printf ("GPIO1 Error\r\n");
+ return 1;
+ }
+ printf ("Setting up GPIO Config\r\n");
+ Status = VL53L0X_SetDeviceMode(Device, VL53L0X_DEVICEMODE_GPIO_DRIVE);
+ if (Status == VL53L0X_ERROR_NONE) {
+ Status = RangeConfigInterrupt(VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY);
+ }
+ if (Status == VL53L0X_ERROR_NONE) {
+ Status = RangeMeasIntContinuousMode(fptr);
+ }
+ return Status;
+ }
if (operating_mode == range_single_shot_polling)
{
// singelshot, polled ranging
@@ -5290,6 +5330,11 @@
}
}
+ if (operating_mode == range_continuous_interrupt)
+ {
+ Status = VL53L0X_GetRangingMeasurementData(Device, Data);
+ VL53L0X_ClearInterruptMask(Device, VL53L0X_REG_SYSTEM_INTERRUPT_CLEAR | VL53L0X_REG_RESULT_INTERRUPT_STATUS);
+ }
return Status;
}
@@ -5332,9 +5377,8 @@
int VL53L0X::HandleIRQ(OperatingMode operating_mode, VL53L0X_RangingMeasurementData_t *Data)
{
int status;
-
+ status=GetMeasurement(operating_mode, Data);
EnableInterruptMeasureDetectionIRQ();
- status=GetMeasurement(operating_mode, Data);
return status;
}
--- a/Components/VL53L0X/vl53l0x_class.h Wed Jun 07 14:58:36 2017 +0000
+++ b/Components/VL53L0X/vl53l0x_class.h Wed Jun 14 13:35:05 2017 +0000
@@ -303,7 +303,7 @@
* @param[in] &pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT
* @param[in] DevAddr device address, 0x29 by default
*/
- VL53L0X(DevI2C &i2c, DigitalOut &pin, PinName pin_gpio1, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : RangeSensor(), dev_i2c(i2c), gpio0(&pin)
+ VL53L0X(DevI2C &i2c, DigitalOut &pin, PinName pin_gpio1, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : dev_i2c(i2c), gpio0(&pin)
{
MyDevice.I2cDevAddr=DevAddr;
MyDevice.comms_type=1; // VL53L0X_COMMS_I2C
@@ -320,7 +320,7 @@
* @param[in] pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT
* @param[in] device address, 0x29 by default
*/
- VL53L0X(DevI2C &i2c, STMPE1600DigiOut &pin, PinName pin_gpio1, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : RangeSensor(), dev_i2c(i2c), expgpio0(&pin)
+ VL53L0X(DevI2C &i2c, STMPE1600DigiOut &pin, PinName pin_gpio1, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : dev_i2c(i2c), expgpio0(&pin)
{
MyDevice.I2cDevAddr=DevAddr;
MyDevice.comms_type=1; // VL53L0X_COMMS_I2C
@@ -479,6 +479,7 @@
// return 1;
}
+
/**
*
* @brief One time device initialization
@@ -495,9 +496,16 @@
* @param void
* @return 0 on success, @a #CALIBRATION_WARNING if failed
*/
+ virtual int init(void *init)
+ {
+ return VL53L0X_DataInit(Device);
+ }
+
+/** deprecated Init funtion from ComponentObject. for backward compatibility
+*/
virtual int Init(void * NewAddr)
{
- return VL53L0X_DataInit(Device);
+ return init(NewAddr);
}
/**
@@ -576,8 +584,9 @@
*/
int RangeStartContinuousMode()
{
-// return VL6180x_RangeStartContinuousMode(Device);
- return 1;
+ int status;
+ status = RangeSetSystemMode(VL53L0X_REG_SYSRANGE_MODE_START_STOP|VL53L0X_REG_SYSRANGE_MODE_BACKTOBACK);
+ return status;
}
/**
@@ -687,7 +696,7 @@
* @param pRange_mm Pointer to range distance
* @return 0 on success
*/
- virtual int GetDistance(uint32_t *piData)
+ virtual int get_distance(uint32_t *piData)
{
int status=0;
VL53L0X_RangingMeasurementData_t pRangingMeasurementData;
@@ -707,7 +716,11 @@
StopMeasurement(range_single_shot_polling);
return status;
}
-
+/* Deprecated funtion from RangeSensor class. For backward compatibility*/
+ virtual int GetDistance(uint32_t *piData)
+ {
+ return get_distance(piData);
+ }
/**
* @brief Configure ranging interrupt reported to application
*
@@ -721,8 +734,18 @@
*/
int RangeConfigInterrupt(uint8_t ConfigGpioInt)
{
-// return VL6180x_RangeConfigInterrupt(Device, ConfigGpioInt);
- return 1;
+ int status;
+ if( ConfigGpioInt<= VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY)
+ {
+ status = VL53L0X_UpdateByte(Device, VL53L0X_REG_SYSTEM_INTERRUPT_CONFIG_GPIO, (uint8_t)(~(0x7<<0)), ConfigGpioInt);
+ }
+ else
+ {
+ status = 1;
+ }
+ // return VL6180x_RangeConfigInterrupt(Device, ConfigGpioInt);
+
+ return status;
}
/**
@@ -974,9 +997,24 @@
* @return 0 on success
*/
int RangeSetSystemMode(uint8_t mode)
- {
+ {
+ int status;
+ /* FIXME we are not checking device is ready via @a VL6180X_RangeWaitDeviceReady
+ * so if called back to back real fast we are not checking
+ * if previous mode "set" got absorbed => bit 0 must be 0 so that it work
+ */
+ if( mode <= 3){
+ status=VL53L0X_WrByte(Device, VL53L0X_REG_SYSRANGE_START, mode);
+ if( status ){
+ VL53L0X_ErrLog("SYSRANGE_START wr fail");
+ }
+ }
+ else{
+ status = 1;
+ }
+ return status;
// return VL6180x_RangeSetSystemMode(Device, mode);
- return 1;
+// return 1;
}
/** @} */
@@ -1044,8 +1082,7 @@
if(!status)
Device->I2cDevAddr=NewAddr;
return status;
-
-// return 1;
+
}
/**
@@ -1134,8 +1171,9 @@
*/
int ClearInterrupt(uint8_t IntClear)
{
+ int status = VL53L0X_WrByte(Device, VL53L0X_REG_SYSTEM_INTERRUPT_CLEAR, IntClear);
// return VL6180x_ClearInterrupt(Device, IntClear );
- return 1;
+ return status;
}
/**
@@ -1339,9 +1377,13 @@
uint8_t *Revision,
VL53L0X_DeviceInfo_t *pVL53L0X_DeviceInfo);
- /* Read function of the ID device */
-// virtual int ReadID();
+ /* deprecated Read function from Component class for backward compatibility*/
+ // virtual int ReadID();
virtual int ReadID(uint8_t *id);
+
+ /* Read function of the ID device */
+ // virtual int read_id();
+ virtual int read_id(uint8_t *id);
VL53L0X_Error WaitMeasurementDataReady(VL53L0X_DEV Dev);
VL53L0X_Error WaitStopCompleted(VL53L0X_DEV Dev);
--- a/ST_INTERFACES.lib Wed Jun 07 14:58:36 2017 +0000 +++ b/ST_INTERFACES.lib Wed Jun 14 13:35:05 2017 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ST/code/ST_INTERFACES/#e2bf4d06a8fc +https://developer.mbed.org/teams/ST/code/ST_INTERFACES/#d3c9b33b992c
--- a/X_NUCLEO_COMMON.lib Wed Jun 07 14:58:36 2017 +0000 +++ b/X_NUCLEO_COMMON.lib Wed Jun 14 13:35:05 2017 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ST/code/X_NUCLEO_COMMON/#12be3dfc15fd +https://developer.mbed.org/teams/ST/code/X_NUCLEO_COMMON/#0dbcdb8dab03
--- a/x_nucleo_53l0a1.cpp Wed Jun 07 14:58:36 2017 +0000
+++ b/x_nucleo_53l0a1.cpp Wed Jun 14 13:35:05 2017 +0000
@@ -119,4 +119,3 @@
else
return 0;
}
-
