Library to handle the X-NUCLEO-6180XA1 Proximity and ambient light sensor expansion board based on VL6180X.
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Dependents: HelloWorld_6180XA1 SunTracker_BLE Servo_6180XA1 BLE_HR_Light ... more
Fork of X_NUCLEO_6180XA1 by
X-NUCLEO-6180XA1 Proximity and Ambient Light Sensor Expansion Board Firmware Package
Introduction
This firmware package includes Components Device Drivers and Board Support Package for STMicroelectronics' X-NUCLEO-6180XA1 Proximity and ambient light sensor expansion board based on VL6180X.
Firmware Library
Class X_NUCLEO_6180XA1 is intended to represent the Proximity and ambient light sensor expansion board with the same name.
The expansion board is providing the support of the following components:
- on-board VL6180X proximity and ambient light sensor,
- up to three additional VL6180X Satellites,
- on-board 4-digit display
It is intentionally implemented as a singleton because only one X-NUCLEO-VL6180XA1 at a time might be deployed in a HW component stack. In order to get the singleton instance you have to call class method `Instance()`, e.g.:
// Sensors expansion board singleton instance static X_NUCLEO_6180XA1 *6180X_expansion_board = X_NUCLEO_6180XA1::Instance();
Arduino Connector Compatibility Warning
Using the X-NUCLEO-6180XA1 expansion board with the NUCLEO-F429ZI requires adopting the following patch:
- to remove R46 resistor connected to
A3pin; - to solder R47 resistor connected to
A5pin.
Alternatively, you can route the Nucleo board’s A5 pin directly to the expansion board’s A3 pin with a wire.
In case you patch your expansion board or route the pin, the interrupt signal for the front sensor will be driven on A5 pin rather than on A3 pin.
Example Applications
Revision 26:db0cdc5ecc0a, committed 2015-11-04
- Comitter:
- gallonm
- Date:
- Wed Nov 04 09:11:52 2015 +0100
- Parent:
- 25:126b760a3f55
- Child:
- 27:22c6f69967d9
- Commit message:
- Settled AlsSetThresholds and AlsGetThresholds.
Modified the function parameters.
Implemented the computation from lux to raw device value.
Changed in this revision
--- a/Components/VL6180X/vl6180x_class.cpp Mon Nov 02 13:49:54 2015 +0000
+++ b/Components/VL6180X/vl6180x_class.cpp Wed Nov 04 09:11:52 2015 +0100
@@ -528,7 +528,7 @@
if( status ) break;
status = VL6180x_AlsSetAnalogueGain(dev, 0);
if( status ) break;
- status = VL6180x_AlsSetThresholds(dev, 0, 0xFFFF);
+ status = VL6180x_AlsSetThresholds(dev, 0, 1800);
if( status ) break;
/* set Als InterruptMode to new sample */
status=VL6180x_AlsConfigInterrupt(dev, CONFIG_GPIO_INTERRUPT_DISABLED);
@@ -725,10 +725,12 @@
-int VL6180X::VL6180x_AlsSetThresholds(VL6180xDev_t dev, uint16_t low, uint16_t high) {
+int VL6180X::VL6180x_AlsSetThresholds(VL6180xDev_t dev, lux_t low, lux_t high) {
int status;
uint32_t AlsAnGain, IntPeriod, AlsScaler, GainFix, RawAlsHigh, RawAlsLow;
+ uint16_t RawThreshLow, RawThreshHigh;
const uint32_t LuxResxIntIme =(uint32_t)(0.56f* DEF_INT_PEFRIOD *(1<<LUXRES_FIX_PREC));
+ void *ptr;
LOG_FUNCTION_START("%d %d", (int )low, (int)high);
AlsAnGain=VL6180xDevDataGet(dev, AlsGainCode);
@@ -738,16 +740,18 @@
IntPeriod++;
RawAlsLow=low*AlsScaler*GainFix;
RawAlsLow=RawAlsLow*IntPeriod;
- RawAlsLow=RawAlsLow/LuxResxIntIme;
-
+ RawAlsLow=RawAlsLow/LuxResxIntIme;
RawAlsHigh=high*(AlsScaler*GainFix);
RawAlsHigh=RawAlsHigh*IntPeriod;
RawAlsHigh=RawAlsHigh/LuxResxIntIme;
- status = VL6180x_WrByte(dev, SYSALS_THRESH_LOW, (uint16_t)RawAlsLow);
+ ptr=&RawAlsLow;
+ RawThreshLow=*(uint16_t*)ptr;
+ status = VL6180x_WrWord(dev, SYSALS_THRESH_LOW, RawThreshLow);
if(!status ){
- status = VL6180x_WrByte(dev, SYSALS_THRESH_HIGH, (uint16_t)RawAlsHigh);
+ ptr=&RawAlsHigh;
+ RawThreshHigh=*(uint16_t*)ptr;
+ status = VL6180x_WrWord(dev, SYSALS_THRESH_HIGH, RawThreshHigh);
}
-
LOG_FUNCTION_END(status) ;
return status;
}
@@ -2896,7 +2900,7 @@
else
return (r_status|l_status);
- case(range_continuous_interrrupt_high_threshold):
+ case(range_continuous_interrupt_high_threshold):
status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_LEVEL_HIGH);
status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED);
if((!r_status)&&(!l_status))
@@ -3229,9 +3233,9 @@
int VL6180X::AlsSetLowThreshold(uint16_t threshold)
{
int status;
- uint16_t low, high;
+ lux_t low, high;
- status=VL6180x_AlsGetThresholds(Device, &low, &high);
+ status=AlsGetThresholds(Device, &low, &high);
if(!status)
status=VL6180x_AlsSetThresholds(Device, threshold, high);
return status;
@@ -3241,31 +3245,47 @@
int VL6180X::AlsSetHighThreshold(uint16_t threshold)
{
int status;
- uint16_t low, high;
+ lux_t low, high;
- status=VL6180x_AlsGetThresholds(Device, &low, &high);
+ status=AlsGetThresholds(Device, &low, &high);
if(!status)
status=VL6180x_AlsSetThresholds(Device, low, threshold);
return status;
}
-int VL6180X::VL6180x_AlsGetThresholds(VL6180xDev_t dev, uint16_t *low, uint16_t *high)
+int VL6180X::AlsGetThresholds(VL6180xDev_t dev, lux_t *low, lux_t *high)
{
int status;
+ uint16_t RawAlsLow, RawAlsHigh;
+ uint32_t luxLowValue, luxHighValue, IntPeriod, AlsAnGain, GainFix, AlsScaler;
+ const uint32_t LuxResxIntIme =(uint32_t)(0.56f* DEF_INT_PEFRIOD *(1<<LUXRES_FIX_PREC));
- status=VL6180x_RdWord(dev, SYSALS_THRESH_LOW, low);
+ status=VL6180x_RdWord(dev, SYSALS_THRESH_LOW, &RawAlsLow);
if(status)
{
VL6180x_ErrLog("rd SYSALS_THRESH_LOW fail");
return status;
}
- status=VL6180x_RdWord(dev, SYSALS_THRESH_HIGH, high);
+ status=VL6180x_RdWord(dev, SYSALS_THRESH_HIGH, &RawAlsHigh);
if(status)
{
VL6180x_ErrLog("rd SYSALS_THRESH_HIGH fail");
return status;
}
+ AlsAnGain=VL6180xDevDataGet(dev, AlsGainCode);
+ IntPeriod=VL6180xDevDataGet(dev, IntegrationPeriod);
+ AlsScaler=VL6180xDevDataGet(dev, AlsScaler);
+ GainFix=AlsGainLookUp[AlsAnGain];
+ IntPeriod++;
+ luxLowValue=(uint32_t)RawAlsLow*LuxResxIntIme;
+ luxLowValue=luxLowValue/IntPeriod;
+ luxLowValue=luxLowValue/(AlsScaler*GainFix);
+ luxHighValue=(uint32_t)RawAlsHigh*LuxResxIntIme;
+ luxHighValue=luxHighValue/IntPeriod;
+ luxHighValue=luxHighValue/(AlsScaler*GainFix);
+ *low=luxLowValue;
+ *high=luxHighValue;
return status;
}
@@ -3281,7 +3301,7 @@
case(range_continuous_polling_high_threshold):
case(range_continuous_polling_out_of_window):
case(range_continuous_interrupt_low_threshold):
- case(range_continuous_interrrupt_high_threshold):
+ case(range_continuous_interrupt_high_threshold):
case(range_continuous_interrupt_out_of_window):
return GetRangeMeas(operating_mode, Data);
@@ -3351,7 +3371,7 @@
else
return NOT_READY;
}
- else if((operating_mode==range_continuous_polling_high_threshold)||(operating_mode==range_continuous_interrrupt_high_threshold))
+ else if((operating_mode==range_continuous_polling_high_threshold)||(operating_mode==range_continuous_interrupt_high_threshold))
{
if(IntStatus.status.Range==RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD)
status=VL6180x_RangeGetMeasurement(Device, &RangeData);
@@ -3509,7 +3529,7 @@
case(range_continuous_polling_high_threshold):
case(range_continuous_polling_out_of_window):
case(range_continuous_interrupt_low_threshold):
- case(range_continuous_interrrupt_high_threshold):
+ case(range_continuous_interrupt_high_threshold):
case(range_continuous_interrupt_out_of_window):
return StopRangeMeasurement(operating_mode);
@@ -3599,7 +3619,7 @@
VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail");
return status;
}
- status=VL6180x_AlsSetThresholds(Device, 0x0, 0xFFFF);
+ status=VL6180x_AlsSetThresholds(Device, 0x0, 1800);
if(status)
VL6180x_ErrLog("VL6180x_AlsSetThresholds fail");
return status;
--- a/Components/VL6180X/vl6180x_class.h Mon Nov 02 13:49:54 2015 +0000
+++ b/Components/VL6180X/vl6180x_class.h Wed Nov 04 09:11:52 2015 +0100
@@ -78,7 +78,7 @@
als_continuous_polling_high_threshold,
als_continuous_polling_out_of_window,
range_continuous_interrupt_low_threshold,
- range_continuous_interrrupt_high_threshold,
+ range_continuous_interrupt_high_threshold,
range_continuous_interrupt_out_of_window,
als_continuous_interrupt_low_threshold,
als_continuous_interrupt_high_threshold,
@@ -277,7 +277,7 @@
return VL6180x_AlsSetAnalogueGain(Device, gain);
}
- int AlsSetThresholds(uint16_t low, uint16_t high)
+ int AlsSetThresholds(lux_t low, lux_t high)
{
return VL6180x_AlsSetThresholds(Device, low, high);
}
@@ -473,7 +473,7 @@
int VL6180x_AlsSetIntegrationPeriod(VL6180xDev_t dev, uint16_t period_ms);
int VL6180x_AlsSetInterMeasurementPeriod(VL6180xDev_t dev, uint16_t intermeasurement_period_ms);
int VL6180x_AlsSetAnalogueGain(VL6180xDev_t dev, uint8_t gain);
- int VL6180x_AlsSetThresholds(VL6180xDev_t dev, uint16_t low, uint16_t high);
+ int VL6180x_AlsSetThresholds(VL6180xDev_t dev, lux_t low, lux_t high);
int VL6180x_AlsGetInterruptStatus(VL6180xDev_t dev, uint8_t *pIntStatus);
int VL6180x_StaticInit(VL6180xDev_t dev);
int VL6180x_RangeWaitDeviceReady(VL6180xDev_t dev, int MaxLoop );
@@ -563,7 +563,7 @@
int AlsMeasIntContinuousMode(void (*fptr)(void));
int InterleavedMode(void (*fptr)(void));
int StartInterleavedMode();
- int VL6180x_AlsGetThresholds(VL6180xDev_t dev, uint16_t *low, uint16_t *high);
+ int AlsGetThresholds(VL6180xDev_t dev, lux_t *low, lux_t *high);
/* IO Device */

X-NUCLEO-6180XA1 Proximity and Ambient Light Sensor