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 36:f6278b3e7c82, committed 2015-11-24
- Comitter:
- mapellil
- Date:
- Tue Nov 24 16:04:41 2015 +0000
- Parent:
- 35:407b0b127eb8
- Child:
- 37:837cffa6b530
- Commit message:
- Exposed GPIOs on constructor, code cleanup, doxy comment
Changed in this revision
--- a/Components/Display/Display_class.h Wed Nov 18 16:35:04 2015 +0000
+++ b/Components/Display/Display_class.h Tue Nov 24 16:04:41 2015 +0000
@@ -47,12 +47,6 @@
extern "C" {
#endif
-#define DISPLAY_USING_STMPE1600
-
-#ifndef DISPLAY_USING_STMPE1600
-#define FAST_DISPLAY // fast quick and dirty display to speed up
-#endif
-
#define DP (1<<7)
#define NOT_7_NO_DP( ... ) (uint8_t) ~( __VA_ARGS__ + DP )
#define S0 (1<<0)
@@ -141,8 +135,6 @@
['X']= NOT_7_NO_DP(S0+S3), // similar to H
['Y']= NOT_7_NO_DP(S0+S4),
['Z']= S0+S1+S6+S4+S3, // same as 2
-
-
};
#undef S0
@@ -159,232 +151,37 @@
/* Classes -------------------------------------------------------------------*/
/** Class representing Display
*/
-#ifndef DISPLAY_USING_STMPE1600
class Display
{
public:
-
-#ifndef FAST_DISPLAY
-
- Display(DevI2C &i2c, STMPE1600DigiOut &D1, STMPE1600DigiOut &D2, STMPE1600DigiOut &D3, STMPE1600DigiOut &D4,
- STMPE1600DigiOut &D_A, STMPE1600DigiOut &D_B, STMPE1600DigiOut &D_C, STMPE1600DigiOut &D_D,
- STMPE1600DigiOut &D_E, STMPE1600DigiOut &D_F, STMPE1600DigiOut &D_G)
- : Display_D1(D1), Display_D2(D2), Display_D3(D3), Display_D4(D4), Display_A(D_A), Display_B(D_B),
- Display_C(D_C), Display_D(D_D), Display_E(D_E), Display_F(D_F), Display_G(D_G), dev_i2c(i2c)
- {
- pDisplay_DGT[0] = &Display_D1;
- pDisplay_DGT[1] = &Display_D2;
- pDisplay_DGT[2] = &Display_D3;
- pDisplay_DGT[3] = &Display_D4;
- pDisplay_SEG[0] = &Display_A;
- pDisplay_SEG[1] = &Display_B;
- pDisplay_SEG[2] = &Display_C;
- pDisplay_SEG[3] = &Display_D;
- pDisplay_SEG[4] = &Display_E;
- pDisplay_SEG[5] = &Display_F;
- pDisplay_SEG[6] = &Display_G;
-
- for (int i=0; i<4; i++) { *pDisplay_DGT[i]=1; }
- for (int i=0; i<7; i++) { *pDisplay_SEG[i]=1; }
- }
-#else
- Display(DevI2C &i2c) : dev_i2c(i2c) {}
-#endif
-
-#ifndef FAST_DISPLAY
- void Digits_off (void) // all 4 digits off
- {
- Display_D1=1;
- Display_D2=1;
- Display_D3=1;
- Display_D4=1;
- }
-
- void Digits_on (void) // all 4 digits on
- {
- Display_D1=0;
- Display_D2=0;
- Display_D3=0;
- Display_D4=0;
- }
-
- void Digit_on (int digit) // digits on
- {
- *pDisplay_DGT[digit] = 0;
- }
-
- void Digit_off (int digit) // digits off
- {
- *pDisplay_DGT[digit] = 1;
- }
-
- void Segments_off () // all 7 segments off
- {
- Display_A=1;
- Display_B=1;
- Display_C=1;
- Display_D=1;
- Display_E=1;
- Display_F=1;
- Display_G=1;
- }
-
- void Segment_off (int seg) // segment off
- {
- *pDisplay_SEG[seg] = 1;
- }
-
- void Segment_on (int seg) // segment on
- {
- *pDisplay_SEG[seg] = 0;
- }
-
-
- void DisplayString (char str[4])
- {
- int i;
- const char *pc;
-
- for( i=0, pc=str; i<4 && *pc!=0 ; i++, pc++)
- {
- _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*pc], i);
- if( *(pc+1)== '.')
- {
- pc++;
- }
- wait_ms(DISPLAY_DELAY);
- Digits_off();
- }
- }
-
-
- void _V2_Set7Segment( int Leds, int digit )
- {
- //Digits_off();
- Segments_off(); // 7 seg off */
- int mask=1;
- for (int i=0; i<7; i++)
- {
- if (Leds & mask) Segment_on(i);
- mask = mask<<1;
- }
- Digit_on(digit);
- }
-
-
-#else
-
- void DisplayDigit (char *val, char dgt)
- {
- uint8_t data[2];
- uint16_t *pdata = (uint16_t*)data;
- dev_i2c.i2c_read(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7
- *pdata = *pdata | (uint16_t)0x0780; // all digits off
- dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7
-
- _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*val], dgt);
- }
-
- void DisplayString (char str[4], char strlen)
- {
- int i, dgt;
- const char *pc;
- uint8_t data[2];
- uint16_t *pdata = (uint16_t*)data;
-
- //dev_i2c.i2c_read(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7
- //*pdata = *pdata | (uint16_t)0x0780; // all digits off
- //dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7
-
- for(i=0, dgt=4-strlen, pc=str; i<strlen && *pc!=0; i++, pc++, dgt++)
- {
- _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*pc], dgt);
- if( *(pc+1)== '.')
- {
- pc++;
- }
- wait_ms(DISPLAY_DELAY);
- dev_i2c.i2c_read(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7
- *pdata = *pdata | (uint16_t)0x0780; // all digits off
- dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7
- }
- }
-
-
- void _V2_Set7Segment( int Leds, int digit )
- {
- //Digits_off();
- uint16_t dgt;
- dgt = 1<<digit;
- dgt = ((uint16_t)dgt)<<7;
- dgt = ~dgt;
- uint8_t data[2];
- uint16_t *pdata = (uint16_t*)data;
-
-
- /* set the exppinname state to lvl */
- dev_i2c.i2c_read(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7
- *pdata = *pdata | (uint16_t)0x007F; // 7 segments off
- dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7
-
- int mask=1;
- for (int i=0; i<7; i++)
- {
- if (Leds & mask) *pdata = *pdata & ~(uint16_t)mask;
- mask = mask<<1;
- }
- *pdata = *pdata & dgt;
- dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7
- }
-#endif
-
-
- private:
-
-#ifndef FAST_DISPLAY
- STMPE1600DigiOut &Display_D1;
- STMPE1600DigiOut &Display_D2;
- STMPE1600DigiOut &Display_D3;
- STMPE1600DigiOut &Display_D4;
- STMPE1600DigiOut *pDisplay_DGT[4]; // the 4 display digits
-
- STMPE1600DigiOut &Display_A;
- STMPE1600DigiOut &Display_B;
- STMPE1600DigiOut &Display_C;
- STMPE1600DigiOut &Display_D;
- STMPE1600DigiOut &Display_E;
- STMPE1600DigiOut &Display_F;
- STMPE1600DigiOut &Display_G;
- STMPE1600DigiOut *pDisplay_SEG[7]; // the 7 digit segmments
-#endif
- DevI2C &dev_i2c;
-};
-
-#else // defined DISPLAY_USING_STMPE1600
-
-class Display
-{
- public:
-
- Display(STMPE1600 &stmpe_1600) : stmpe1600(stmpe_1600) {
- stmpe1600.setGPIOdir (GPIO_7, OUTPUT); // Digit1
- stmpe1600.setGPIOdir (GPIO_8, OUTPUT); // Digit2
- stmpe1600.setGPIOdir (GPIO_9, OUTPUT); // Digit3
- stmpe1600.setGPIOdir (GPIO_10, OUTPUT); // Digit4
+ /** Constructor
+ * @param[in] &stmpe_1600 device handler to be used for display control
+ */
+ Display(STMPE1600 &stmpe_1600) : stmpe1600(stmpe_1600) {
+ stmpe1600.setGPIOdir (GPIO_7, OUTPUT); // Digit1
+ stmpe1600.setGPIOdir (GPIO_8, OUTPUT); // Digit2
+ stmpe1600.setGPIOdir (GPIO_9, OUTPUT); // Digit3
+ stmpe1600.setGPIOdir (GPIO_10, OUTPUT); // Digit4
- stmpe1600.setGPIOdir (GPIO_0, OUTPUT); // Digit4
- stmpe1600.setGPIOdir (GPIO_1, OUTPUT); // Digit4
- stmpe1600.setGPIOdir (GPIO_2, OUTPUT); // Digit4
- stmpe1600.setGPIOdir (GPIO_3, OUTPUT); // Digit4
- stmpe1600.setGPIOdir (GPIO_4, OUTPUT); // Digit4
- stmpe1600.setGPIOdir (GPIO_5, OUTPUT); // Digit4
- stmpe1600.setGPIOdir (GPIO_6, OUTPUT); // Digit4
-
- }
-
+ stmpe1600.setGPIOdir (GPIO_0, OUTPUT); // SegmentA
+ stmpe1600.setGPIOdir (GPIO_1, OUTPUT); // SegmentB
+ stmpe1600.setGPIOdir (GPIO_2, OUTPUT); // SegmentC
+ stmpe1600.setGPIOdir (GPIO_3, OUTPUT); // SegmentD
+ stmpe1600.setGPIOdir (GPIO_4, OUTPUT); // SegmentE
+ stmpe1600.setGPIOdir (GPIO_5, OUTPUT); // SegmentF
+ stmpe1600.setGPIOdir (GPIO_6, OUTPUT); // SegmentG
+ }
+
+ /*** Interface Methods ***/
+ /**
+ * @brief Print the string on display
+ * @param[in] String to be printed
+ * @param[in] String lenght [min 1, max 4]
+ * @return void
+ */
void DisplayString (char str[4], char strlen)
- {
+ {
int i, dgt;
const char *pc;
uint8_t data[2];
@@ -403,21 +200,28 @@
stmpe1600.write16bitReg(GPSR_0_7, pdata);
}
- }
-
- void DisplayDigit (char *val, char dgt)
- {
+ }
+
+ /**
+ * @brief Print the digit on display
+ * @param[in] Digit value to be printed
+ * @param[in] Digit to be used [min 0, max 3]
+ * @return void
+ */
+ void DisplayDigit (char *val, char dgt)
+ {
uint8_t data[2];
uint16_t *pdata = (uint16_t*)data;
- stmpe1600.read16bitReg(GPSR_0_7, pdata);
+ stmpe1600.read16bitReg(GPSR_0_7, pdata);
*pdata = *pdata | (uint16_t)0x0780; // all digits off
- stmpe1600.write16bitReg(GPSR_0_7, pdata);
+ stmpe1600.write16bitReg(GPSR_0_7, pdata);
_V2_Set7Segment( ascii_to_display_lut[(uint8_t)*val], dgt);
- }
+ }
- void _V2_Set7Segment( int Leds, int digit )
- {
+private:
+ void _V2_Set7Segment( int Leds, int digit )
+ {
//Digits_off();
uint16_t dgt;
dgt = 1<<digit;
@@ -428,9 +232,9 @@
/* set the exppinname state to lvl */
- stmpe1600.read16bitReg(GPSR_0_7, pdata);
+ stmpe1600.read16bitReg(GPSR_0_7, pdata);
*pdata = *pdata | (uint16_t)0x007F; // 7 segments off
- stmpe1600.write16bitReg(GPSR_0_7, pdata);
+ stmpe1600.write16bitReg(GPSR_0_7, pdata);
int mask=1;
for (int i=0; i<7; i++)
@@ -439,14 +243,10 @@
mask = mask<<1;
}
*pdata = *pdata & dgt;
- stmpe1600.write16bitReg(GPSR_0_7, pdata);
- }
-
- private:
- STMPE1600 &stmpe1600;
-
+ stmpe1600.write16bitReg(GPSR_0_7, pdata);
+ }
+ STMPE1600 &stmpe1600;
};
-#endif
#ifdef __cplusplus
}
--- a/Components/STMPE1600/stmpe1600_class.h Wed Nov 18 16:35:04 2015 +0000
+++ b/Components/STMPE1600/stmpe1600_class.h Tue Nov 24 16:04:41 2015 +0000
@@ -1,10 +1,10 @@
/**
******************************************************************************
- * @file vl6180x_class.h
+ * @file stmpe1600_class.h
* @author AST / EST
* @version V0.0.1
* @date 14-April-2015
- * @brief Header file for component VL6180X
+ * @brief Header file for component stmpe1600
******************************************************************************
* @attention
*
@@ -80,7 +80,7 @@
GPIO_13,
GPIO_14,
GPIO_15,
- NOT_CON
+ NOT_CON
} ExpGpioPinName;
typedef enum {
@@ -89,10 +89,18 @@
NOT_CONNECTED
}ExpGpioPinDirection;
-
+/* Classes -------------------------------------------------------------------*/
+/** Class representing a single stmpe1600 GPIO expander output pin
+ */
class STMPE1600DigiOut {
public:
+ /** Constructor
+ * @param[in] &i2c device I2C to be used for communication
+ * @param[in] outpinname the desired out pin name to be created
+ * @param[in] DevAddr the stmpe1600 I2C device addres (deft STMPE1600_DEF_DEVICE_ADDRESS)
+ * @param[in] lvl the default ot pin level
+ */
STMPE1600DigiOut (DevI2C &i2c, ExpGpioPinName outpinname, uint8_t DevAddr=STMPE1600_DEF_DEVICE_ADDRESS, bool lvl=STMPE1600_DEF_DIGIOUT_LVL): dev_i2c(i2c), expdevaddr(DevAddr), exppinname(outpinname)
{
uint8_t data[2];
@@ -106,6 +114,11 @@
write(lvl);
}
+ /**
+ * @brief Write on the out pin
+ * @param[in] lvl level to write
+ * @return 0 on Success
+ */
void write (int lvl)
{
uint8_t data[2];
@@ -116,7 +129,10 @@
if (lvl) *(uint16_t*)data = *(uint16_t*)data | (uint16_t)(1<<(uint16_t)exppinname);
dev_i2c.i2c_write(data, expdevaddr, GPSR_0_7, 2);
}
-
+
+ /**
+ * @brief Overload assignement operator
+ */
STMPE1600DigiOut& operator=(int lvl)
{
write (lvl);
@@ -129,9 +145,17 @@
ExpGpioPinName exppinname;
};
+/* Classes -------------------------------------------------------------------*/
+/** Class representing a single stmpe1600 GPIO expander input pin
+ */
class STMPE1600DigiIn
{
public:
+ /** Constructor
+ * @param[in] &i2c device I2C to be used for communication
+ * @param[in] inpinname the desired input pin name to be created
+ * @param[in] DevAddr the stmpe1600 I2C device addres (deft STMPE1600_DEF_DEVICE_ADDRESS)
+ */
STMPE1600DigiIn (DevI2C &i2c, ExpGpioPinName inpinname, uint8_t DevAddr=STMPE1600_DEF_DEVICE_ADDRESS): dev_i2c(i2c), expdevaddr(DevAddr), exppinname(inpinname)
{
uint8_t data[2];
@@ -142,6 +166,10 @@
dev_i2c.i2c_write(data, expdevaddr, GPDR_0_7, 2);
}
+ /**
+ * @brief Read the input pin
+ * @return The pin logical state 0 or 1
+ */
bool read ()
{
uint8_t data[2];
@@ -164,10 +192,16 @@
ExpGpioPinName exppinname;
};
-
+/* Classes -------------------------------------------------------------------*/
+/** Class representing a whole stmpe1600 component (16 gpio)
+ */
class STMPE1600 {
public:
+ /** Constructor
+ * @param[in] &i2c device I2C to be used for communication
+ * @param[in] DevAddr the stmpe1600 I2C device addres (deft STMPE1600_DEF_DEVICE_ADDRESS)
+ */
STMPE1600 (DevI2C &i2c, uint8_t DevAddr=STMPE1600_DEF_DEVICE_ADDRESS ) : dev_i2c(i2c)
{
dev_i2c = i2c;
@@ -180,51 +214,86 @@
write16bitReg (GPSR_0_7, &GPSR0_15);
}
+ /**
+ * @brief Write the SYS_CTRL register
+ * @param[in] Data to be written (bit fields)
+ */
void writeSYS_CTRL (uint8_t data) // data = SOFT_RESET reset the device
{
dev_i2c.i2c_write((uint8_t*)SYS_CTRL, expdevaddr, data, 1);
}
-
- bool setGPIO (ExpGpioPinName PinName)
- {
- if (PinName == NOT_CON) return true;
- GPSR0_15 = GPSR0_15 | ((uint16_t)0x0001<<PinName);
- write16bitReg (GPSR_0_7 , &GPSR0_15);
- return false;
- }
+
+ /**
+ * @brief Set the out pin
+ * @param[in] The pin name
+ * @return 0 on Success
+ */
+ bool setGPIO (ExpGpioPinName PinName)
+ {
+ if (PinName == NOT_CON) return true;
+ GPSR0_15 = GPSR0_15 | ((uint16_t)0x0001<<PinName);
+ write16bitReg (GPSR_0_7 , &GPSR0_15);
+ return false;
+ }
+
+ /**
+ * @brief Clear the out pin
+ * @param[in] The pin name
+ * @return 0 on Success
+ */
+ bool clrGPIO (ExpGpioPinName PinName)
+ {
+ if (PinName == NOT_CON) return true;
+ GPSR0_15 = GPSR0_15 & (~((uint16_t)0x0001<<PinName));
+ write16bitReg (GPSR_0_7 , &GPSR0_15);
+ return false;
+ }
+
+ /**
+ * @brief Read the input pin
+ * @param[in] The pin name
+ * @return The logical pin level
+ */
+ bool rdGPIO (ExpGpioPinName PinName)
+ {
+ uint16_t gpmr0_15;
+ if (PinName == NOT_CON) return true;
+ read16bitReg (GPMR_0_7, &gpmr0_15);
+ gpmr0_15 = gpmr0_15 & ((uint16_t)0x0001<<PinName);
+ if (gpmr0_15) return true;
+ return false;
+ }
+
+ /**
+ * @brief Set the pin direction
+ * @param[in] The pin name
+ * @param[in] The pin direction
+ * @return 0 on success
+ */
+ bool setGPIOdir (ExpGpioPinName PinName, ExpGpioPinDirection PinDir)
+ {
+ if (PinName == NOT_CON || PinDir == NOT_CONNECTED) return true;
+ GPDR0_15 = GPDR0_15 & (~((uint16_t)0x0001<<PinName)); // clear the Pin
+ GPDR0_15 = GPDR0_15 | ((uint16_t)PinDir<<PinName);
+ write16bitReg (GPDR_0_7 , &GPDR0_15);
+ return false;
+ }
- bool clrGPIO (ExpGpioPinName PinName)
- {
- if (PinName == NOT_CON) return true;
- GPSR0_15 = GPSR0_15 & (~((uint16_t)0x0001<<PinName));
- write16bitReg (GPSR_0_7 , &GPSR0_15);
- return false;
- }
-
- bool rdGPIO (ExpGpioPinName PinName)
- {
- uint16_t gpmr0_15;
- if (PinName == NOT_CON) return true;
- read16bitReg (GPMR_0_7, &gpmr0_15);
- gpmr0_15 = gpmr0_15 & ((uint16_t)0x0001<<PinName);
- if (gpmr0_15) return true;
- return false;
- }
-
- bool setGPIOdir (ExpGpioPinName PinName, ExpGpioPinDirection PinDir)
- {
- if (PinName == NOT_CON || PinDir == NOT_CONNECTED) return true;
- GPDR0_15 = GPDR0_15 & (~((uint16_t)0x0001<<PinName)); // clear the Pin
- GPDR0_15 = GPDR0_15 | ((uint16_t)PinDir<<PinName);
- write16bitReg (GPDR_0_7 , &GPDR0_15);
- return false;
- }
-
+ /**
+ * @brief Read a 16 bits register
+ * @param[in] The register address
+ * @param[in] The pointer to the read data
+ */
void read16bitReg (uint8_t Reg16Addr, uint16_t *Reg16Data)
{
dev_i2c.i2c_read((uint8_t*)Reg16Data, expdevaddr, Reg16Addr, 2);
}
-
+
+ /**
+ * @brief Write a 16 bits register
+ * @param[in] The register address
+ * @param[in] The pointer to the data to be written
+ */
void write16bitReg (uint8_t Reg16Addr, uint16_t *Reg16Data)
{
dev_i2c.i2c_write((uint8_t*)Reg16Data, expdevaddr, Reg16Addr, 2);
--- a/x_nucleo_6180xa1.cpp Wed Nov 18 16:35:04 2015 +0000
+++ b/x_nucleo_6180xa1.cpp Tue Nov 24 16:04:41 2015 +0000
@@ -42,7 +42,6 @@
/* Static variables ----------------------------------------------------------*/
X_NUCLEO_6180XA1* X_NUCLEO_6180XA1::_instance = NULL;
-
X_NUCLEO_6180XA1* X_NUCLEO_6180XA1::Instance(DevI2C *ext_i2c)
{
if(_instance==NULL)
@@ -52,6 +51,18 @@
return _instance;
}
+X_NUCLEO_6180XA1* X_NUCLEO_6180XA1::Instance(DevI2C *ext_i2c,
+ PinName gpio1_top, PinName gpio1_bottom,
+ PinName gpio1_left, PinName gpio1_right)
+{
+ if(_instance==NULL)
+ //_instance=new X_NUCLEO_6180XA1(ext_i2c);
+ _instance=new X_NUCLEO_6180XA1(ext_i2c, gpio1_top, gpio1_bottom, gpio1_left, gpio1_right);
+ else
+ VL6180x_ErrLog("Failed to create X_NUCLEO_6180XA1 instance\n\r");
+ return _instance;
+}
+
int X_NUCLEO_6180XA1::InitBoard()
{
--- a/x_nucleo_6180xa1.h Wed Nov 18 16:35:04 2015 +0000
+++ b/x_nucleo_6180xa1.h Tue Nov 24 16:04:41 2015 +0000
@@ -56,31 +56,22 @@
/* Classes--------------------------------------------------------------------*/
+/* Classes -------------------------------------------------------------------*/
+/** Class representing the X-NUCLEO-VL6180XA1 expansion board
+ */
class X_NUCLEO_6180XA1
{
public:
+ /** Constructor 1
+ * @param[in] &i2c device I2C to be used for communication
+ */
X_NUCLEO_6180XA1(DevI2C *ext_i2c) : dev_i2c(ext_i2c)
{
- stmpe1600 = new STMPE1600(*ext_i2c);
- stmpe1600->writeSYS_CTRL (SOFT_RESET);
+ stmpe1600 = new STMPE1600(*ext_i2c);
+ stmpe1600->writeSYS_CTRL (SOFT_RESET);
Switch = new SWITCH (*stmpe1600, GPIO_11);
- display = new Display(*stmpe1600);
-
- /*digit1=new STMPE1600DigiOut(*dev_i2c, GPIO_7);
- digit2=new STMPE1600DigiOut(*dev_i2c, GPIO_8);
- digit3=new STMPE1600DigiOut(*dev_i2c, GPIO_9);
- digit4=new STMPE1600DigiOut(*dev_i2c, GPIO_10);
+ display = new Display(*stmpe1600);
- dispA=new STMPE1600DigiOut(*dev_i2c, GPIO_0);
- dispB=new STMPE1600DigiOut(*dev_i2c, GPIO_1);
- dispC=new STMPE1600DigiOut(*dev_i2c, GPIO_2);
- dispD=new STMPE1600DigiOut(*dev_i2c, GPIO_3);
- dispE=new STMPE1600DigiOut(*dev_i2c, GPIO_4);
- dispF=new STMPE1600DigiOut(*dev_i2c, GPIO_5);
- dispG=new STMPE1600DigiOut(*dev_i2c, GPIO_6);*/
- //display=new Display(*digit1,*digit2,*digit3,*digit4,*dispA,*dispB,*dispC,*dispD,*dispE,*dispF,*dispG);
- //display=new Display(*ext_i2c);
-
gpio0_top=new STMPE1600DigiOut(*dev_i2c, GPIO_12);
sensor_top=new VL6180X(*dev_i2c, *gpio0_top, PB_0);
@@ -93,7 +84,35 @@
gpio0_right=new STMPE1600DigiOut(*dev_i2c, GPIO_15);
sensor_right=new VL6180X(*dev_i2c, *gpio0_right, PA_10);
}
-
+
+ /** Constructor 2
+ * @param[in] &i2c device I2C to be used for communication
+ * @param[in] PinName gpio1_top Mbed DigitalOut pin name to be used as a top sensor GPIO_1 INT
+ * @param[in] PinName gpio1_bottom Mbed DigitalOut pin name to be used as a bottom sensor GPIO_1 INT
+ * @param[in] PinName gpio1_left Mbed DigitalOut pin name to be used as a left sensor GPIO_1 INT
+ * @param[in] PinName gpio1_right Mbed DigitalOut pin name to be used as a right sensor GPIO_1 INT
+ */
+ X_NUCLEO_6180XA1(DevI2C *ext_i2c, PinName gpio1_top, PinName gpio1_bottom,
+ PinName gpio1_left, PinName gpio1_right) : dev_i2c(ext_i2c) {
+ stmpe1600 = new STMPE1600(*ext_i2c);
+ Switch = new SWITCH (*stmpe1600, GPIO_11);
+ display = new Display(*stmpe1600);
+
+ gpio0_top=new STMPE1600DigiOut(*dev_i2c, GPIO_12);
+ sensor_top=new VL6180X(*dev_i2c, *gpio0_top, gpio1_top);
+
+ gpio0_bottom=new STMPE1600DigiOut(*dev_i2c, GPIO_13);
+ sensor_bottom=new VL6180X(*dev_i2c, *gpio0_bottom, gpio1_bottom);
+
+ gpio0_left=new STMPE1600DigiOut(*dev_i2c, GPIO_14);
+ sensor_left=new VL6180X(*dev_i2c, *gpio0_left, gpio1_left);
+
+ gpio0_right=new STMPE1600DigiOut(*dev_i2c, GPIO_15);
+ sensor_right=new VL6180X(*dev_i2c, *gpio0_right, gpio1_right);
+ }
+
+ /** Destructor
+ */
~X_NUCLEO_6180XA1()
{
if(gpio0_top!=NULL)
@@ -136,62 +155,62 @@
delete sensor_right;
sensor_right=NULL;
}
- /*delete digit1;
- delete digit2;
- delete digit3;
- delete digit4;
- delete dispA;
- delete dispB;
- delete dispC;
- delete dispD;
- delete dispE;
- delete dispF;
- delete dispG;*/
- delete stmpe1600;
- delete Switch;
- delete display;
+ delete stmpe1600;
+ stmpe1600 = NULL;
+ delete Switch;
+ Switch = NULL;
+ delete display;
+ display = NULL;
_instance=NULL;
}
+ /**
+ * @brief Creates a singleton object instance
+ * @param[in] &i2c device I2C to be used for communication
+ * @return Pointer to the object instance
+ */
+ static X_NUCLEO_6180XA1 *Instance(DevI2C *ext_i2c);
+
+ /**
+ * @brief Creates a singleton object instance
+ * @param[in] &i2c device I2C to be used for communication
+ * @param[in] PinName gpio1_top the pin connected to top sensor INT
+ * @param[in] PinName gpio1_bottem the pin connected to bottom sensor INT
+ * @param[in] PinName gpio1_left the pin connected to left sensor INT
+ * @param[in] PinName gpio1_right the pin connected to right sensor INT
+ * @return Pointer to the object instance
+ */
+ static X_NUCLEO_6180XA1 *Instance(DevI2C *ext_i2c, PinName gpio1_top, PinName gpio1_bottom,
+ PinName gpio1_left, PinName gpio1_right);
+
+ /**
+ * @brief Initialize the board and sensors with deft values
+ * @return 0 on success
+ */
+ int InitBoard();
+
+ /**
+ * @brief Read the on board red slider switch
+ * @return 0 or 1 according to switch position
+ */
bool RdSwitch () {
return Switch->RdSwitch();
}
-
+
DevI2C *dev_i2c;
-
VL6180X *sensor_top;
VL6180X *sensor_bottom;
VL6180X *sensor_left;
VL6180X *sensor_right;
-
- STMPE1600 * stmpe1600;
- SWITCH * Switch;
-
+ STMPE1600 * stmpe1600;
+ SWITCH * Switch;
STMPE1600DigiOut *gpio0_top;
STMPE1600DigiOut *gpio0_bottom;
STMPE1600DigiOut *gpio0_left;
- STMPE1600DigiOut *gpio0_right;
+ STMPE1600DigiOut *gpio0_right;
+ Display *display;
- STMPE1600DigiOut *digit1;
- STMPE1600DigiOut *digit2;
- STMPE1600DigiOut *digit3;
- STMPE1600DigiOut *digit4;
-
- STMPE1600DigiOut *dispA;
- STMPE1600DigiOut *dispB;
- STMPE1600DigiOut *dispC;
- STMPE1600DigiOut *dispD;
- STMPE1600DigiOut *dispE;
- STMPE1600DigiOut *dispF;
- STMPE1600DigiOut *dispG;
-
- Display *display;
-
- static X_NUCLEO_6180XA1 *Instance(DevI2C *ext_i2c);
-
- int InitBoard();
-
- private:
+ private:
static X_NUCLEO_6180XA1 *_instance;
};

X-NUCLEO-6180XA1 Proximity and Ambient Light Sensor