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.
Fork of X_NUCLEO_53L0A1 by
Revision 12:f6e2bad00dc7, committed 2017-06-14
- Comitter:
- johnAlexander
- Date:
- Wed Jun 14 14:39:27 2017 +0000
- Parent:
- 11:ceaa5a026412
- Child:
- 13:615f7e38568c
- Commit message:
- Add ranging_continuous_interrupt support.
Changed in this revision
--- a/Components/VL53L0X/vl53l0x_class.cpp Mon Jun 12 13:59:20 2017 +0000
+++ b/Components/VL53L0X/vl53l0x_class.cpp Wed Jun 14 14:39:27 2017 +0000
@@ -4112,7 +4112,6 @@
Status = VL53L0X_ClearInterruptMask(Dev, 0);
}
-
LOG_FUNCTION_END(Status);
return Status;
}
@@ -5152,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))
@@ -5171,6 +5191,30 @@
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_CONTINUOUS_RANGING);
+
+ if (Status == VL53L0X_ERROR_NONE) {
+ Status = RangeConfigInterrupt(VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY);
+ }
+ if (Status == VL53L0X_ERROR_NONE) {
+ Status = RangeMeasIntContinuousMode(fptr);
+ }
+
+ if(Status == VL53L0X_ERROR_NONE)
+ {
+ printf ("Call of VL53L0X_StartMeasurement\n");
+ Status = VL53L0X_StartMeasurement(Device);
+ }
+ return Status;
+ }
if (operating_mode == range_single_shot_polling)
{
@@ -5294,6 +5338,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;
}
@@ -5336,9 +5385,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 Mon Jun 12 13:59:20 2017 +0000
+++ b/Components/VL53L0X/vl53l0x_class.h Wed Jun 14 14:39:27 2017 +0000
@@ -61,7 +61,7 @@
#define STATUS_FAIL 0x01
-#define VL53L0X_OsDelay(...) wait_ms(2) // 2 msec delay. can also use wait(float secs)/wait_us(int)
+#define VL53L0X_OsDelay(...) HAL_Delay(2)
#ifdef USE_EMPTY_STRING
#define VL53L0X_STRING_DEVICE_INFO_NAME ""
@@ -584,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;
}
/**
@@ -733,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;
}
/**
@@ -986,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;
}
/** @} */
@@ -1056,8 +1082,7 @@
if(!status)
Device->I2cDevAddr=NewAddr;
return status;
-
-// return 1;
+
}
/**
@@ -1146,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;
}
/**
