Librairie adaptée au laboratoire 2
Dependencies: ST_INTERFACES X_NUCLEO_COMMON
Fork of X_NUCLEO_6180XA1 by
Revision 33:1573db91352c, committed 2015-11-17
- Comitter:
- licio.mapelli@st.com
- Date:
- Tue Nov 17 17:15:47 2015 +0100
- Parent:
- 32:ef97c377d27b
- Child:
- 34:5bcffb4c5b47
- Commit message:
- Added Switch class, added self contained Display class, added STMPE1600 component
and modified X_NUCLEO_6180XA1 class accordingly
Changed in this revision
--- a/Components/Display/Display_class.h Tue Nov 10 10:46:15 2015 +0000
+++ b/Components/Display/Display_class.h Tue Nov 17 17:15:47 2015 +0100
@@ -47,7 +47,11 @@
extern "C" {
#endif
-#define FAST_DISPLAY
+#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 )
@@ -155,7 +159,8 @@
/* Classes -------------------------------------------------------------------*/
/** Class representing Display
*/
-
+#ifndef DISPLAY_USING_STMPE1600
+
class Display
{
public:
@@ -356,6 +361,82 @@
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
+
+ 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
+
+ }
+
+ void DisplayString (char str[4], char strlen)
+ {
+ int i, dgt;
+ const char *pc;
+ uint8_t data[2];
+ uint16_t *pdata = (uint16_t*)data;
+
+ 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);
+ stmpe1600.read16bitReg(GPSR_0_7, pdata);
+ *pdata = *pdata | (uint16_t)0x0780; // all digits off
+ stmpe1600.write16bitReg(GPSR_0_7, pdata);
+ }
+
+ }
+
+ 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 */
+ stmpe1600.read16bitReg(GPSR_0_7, pdata);
+ *pdata = *pdata | (uint16_t)0x007F; // 7 segments off
+ stmpe1600.write16bitReg(GPSR_0_7, pdata);
+
+ int mask=1;
+ for (int i=0; i<7; i++)
+ {
+ if (Leds & mask) *pdata = *pdata & ~(uint16_t)mask;
+ mask = mask<<1;
+ }
+ *pdata = *pdata & dgt;
+ stmpe1600.write16bitReg(GPSR_0_7, pdata);
+ }
+
+ private:
+ STMPE1600 &stmpe1600;
+
+};
+#endif
+
#ifdef __cplusplus
}
#endif
--- a/Components/STMPE1600/stmpe1600_class.h Tue Nov 10 10:46:15 2015 +0000
+++ b/Components/STMPE1600/stmpe1600_class.h Tue Nov 17 17:15:47 2015 +0100
@@ -43,20 +43,24 @@
#define STMPE1600_DEF_DIGIOUT_LVL 1
/** STMPE1600 registr map **/
+#define ChipID_0_7 (uint8_t)0x00
+#define ChipID_8_15 (uint8_t)0x01
#define VersionId (uint8_t)0x02
-#define SystemControl (uint8_t)0x03
-#define IEGPIOR_0_7 (uint8_t)0x08
-#define IEGPIOR_8_15 (uint8_t)0x09
-#define ISGPIOR_0_7 (uint8_t)0x0A
-#define ISGPIOR_8_15 (uint8_t)0x0B
-#define GPMR_0_7 (uint8_t)0x10
-#define GPMR_8_15 (uint8_t)0x11
-#define GPSR_0_7 (uint8_t)0x12
-#define GPSR_8_15 (uint8_t)0x13
-#define GPDR_0_7 (uint8_t)0x14
-#define GPDR_8_15 (uint8_t)0x15
-#define GPIR_0_7 (uint8_t)0x16
-#define GPIR_8_15 (uint8_t)0x17
+#define SYS_CTRL (uint8_t)0x03
+#define IEGPIOR_0_7 (uint8_t)0x08
+#define IEGPIOR_8_15 (uint8_t)0x09
+#define ISGPIOR_0_7 (uint8_t)0x0A
+#define ISGPIOR_8_15 (uint8_t)0x0B
+#define GPMR_0_7 (uint8_t)0x10
+#define GPMR_8_15 (uint8_t)0x11
+#define GPSR_0_7 (uint8_t)0x12
+#define GPSR_8_15 (uint8_t)0x13
+#define GPDR_0_7 (uint8_t)0x14
+#define GPDR_8_15 (uint8_t)0x15
+#define GPIR_0_7 (uint8_t)0x16
+#define GPIR_8_15 (uint8_t)0x17
+
+#define SOFT_RESET (uint8_t)0x80
typedef enum {
// GPIO Expander pin names
@@ -75,7 +79,8 @@
GPIO_12,
GPIO_13,
GPIO_14,
- GPIO_15
+ GPIO_15,
+ NOT_CON
} ExpGpioPinName;
typedef enum {
@@ -91,6 +96,7 @@
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];
+ if (exppinname == NOT_CON) return;
/* set the exppinname as output */
dev_i2c.i2c_read(data, expdevaddr, GPDR_0_7, 1);
dev_i2c.i2c_read(&data[1], expdevaddr, GPDR_8_15, 1);
@@ -103,6 +109,7 @@
void write (int lvl)
{
uint8_t data[2];
+ if (exppinname == NOT_CON) return;
/* set the exppinname state to lvl */
dev_i2c.i2c_read(data, expdevaddr, GPSR_0_7, 2);
*(uint16_t*)data = *(uint16_t*)data & (uint16_t)(~(1<<(uint16_t)exppinname)); // set pin mask
@@ -128,6 +135,7 @@
STMPE1600DigiIn (DevI2C &i2c, ExpGpioPinName inpinname, uint8_t DevAddr=STMPE1600_DEF_DEVICE_ADDRESS): dev_i2c(i2c), expdevaddr(DevAddr), exppinname(inpinname)
{
uint8_t data[2];
+ if (exppinname == NOT_CON) return;
/* set the exppinname as input pin direction */
dev_i2c.i2c_read(data, expdevaddr, GPDR_0_7, 2);
*(uint16_t*)data = *(uint16_t*)data & (uint16_t)(~(1<<(uint16_t)exppinname)); // set gpio as in
@@ -137,6 +145,7 @@
bool read ()
{
uint8_t data[2];
+ if (exppinname == NOT_CON) return 0;
/* read the exppinname */
dev_i2c.i2c_read(data, expdevaddr, GPMR_0_7, 2);
*(uint16_t*)data = *(uint16_t*)data & (uint16_t)(1<<(uint16_t)exppinname); // mask the in gpio
@@ -156,59 +165,76 @@
};
-/*
class STMPE1600 {
public:
- STMPE1600 (DevI2C &i2c, ExpGpioPinDirection GPDR0, ExpGpioPinDirection GPDR1, ExpGpioPinDirection GPDR2,
- ExpGpioPinDirection GPDR3, ExpGpioPinDirection GPDR4, ExpGpioPinDirection GPDR5,
- ExpGpioPinDirection GPDR6, ExpGpioPinDirection GPDR7, ExpGpioPinDirection GPDR8,
- ExpGpioPinDirection GPDR9, ExpGpioPinDirection GPDR10, ExpGpioPinDirection GPDR11,
- ExpGpioPinDirection GPDR12, ExpGpioPinDirection GPDR13, ExpGpioPinDirection GPDR14,
- ExpGpioPinDirection GPDR15, uint8_t DevAddr=STMPE1600_DEF_DEVICE_ADDRESS ) :dev_i2c(i2c)
-
+ STMPE1600 (DevI2C &i2c, uint8_t DevAddr=STMPE1600_DEF_DEVICE_ADDRESS ) : dev_i2c(i2c)
{
dev_i2c = i2c;
expdevaddr = DevAddr;
+ writeSYS_CTRL (SOFT_RESET);
+
GPDR0_15 = (uint16_t)0; // gpio dir all IN
+ write16bitReg (GPDR_0_7, &GPDR0_15);
GPSR0_15 = (uint16_t)0x0ffff; // gpio status all 1
- if (GPDR0 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0001;
- if (GPDR1 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0002;
- if (GPDR2 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0004;
- if (GPDR3 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0008;
- if (GPDR4 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0010;
- if (GPDR5 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0020;
- if (GPDR6 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0040;
- if (GPDR7 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0080;
- if (GPDR8 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0100;
- if (GPDR9 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0200;
- if (GPDR10 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0400;
- if (GPDR11 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0800;
- if (GPDR12 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x1000;
- if (GPDR13 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x2000;
- if (GPDR14 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x4000;
- if (GPDR15 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x8000;
- dev_i2c.i2c_write((uint8_t*)&GPDR0_15, expdevaddr, GPDR_0_7, 2);
- dev_i2c.i2c_write((uint8_t*)&GPSR0_15, expdevaddr, GPSR_0_7, 2);
+ write16bitReg (GPSR_0_7, &GPSR0_15);
}
-
- void readGPSR0_15 (uint16_t * gpsr0_15)
+
+ void writeSYS_CTRL (uint8_t data) // data = SOFT_RESET reset the device
{
- dev_i2c.i2c_read((uint8_t*)gpsr0_15, expdevaddr, GPSR_0_7, 2);
- GPSR0_15 = gpsr0_15;
+ dev_i2c.i2c_write((uint8_t*)SYS_CTRL, expdevaddr, data, 1);
}
- void writeGPSR0_15 (uint16_t *gpsr0_15)
- {
- dev_i2c.i2c_write((uint8_t*)*gpsr0_15, expdevaddr, GPSR_0_7, 2);
- GPSR0_15 = *gpsr0_15;
- }
+ 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;
+ }
+
+ 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;
+ }
- private:
+ 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;
+ }
+
+ void read16bitReg (uint8_t Reg16Addr, uint16_t *Reg16Data)
+ {
+ dev_i2c.i2c_read((uint8_t*)Reg16Data, expdevaddr, Reg16Addr, 2);
+ }
+
+ void write16bitReg (uint8_t Reg16Addr, uint16_t *Reg16Data)
+ {
+ dev_i2c.i2c_write((uint8_t*)Reg16Data, expdevaddr, Reg16Addr, 2);
+ }
+
+ private:
DevI2C &dev_i2c;
- uint16_t GPDR0_15;
- uint16_t GPSR0_15;
- uint8_t expdevaddr;
+ uint16_t GPDR0_15; // local copy of bit direction reg
+ uint16_t GPSR0_15; // local copy of bit status reg
+ uint8_t expdevaddr; // expander device i2c addr
};
-*/
+
#endif // __STMPE1600_CLASS
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/Switch/Switch_class.h Tue Nov 17 17:15:47 2015 +0100
@@ -0,0 +1,82 @@
+/**
+ ******************************************************************************
+ * @file Switch_class.h
+ * @author AST / EST
+ * @version V0.0.1
+ * @date 14-April-2015
+ * @brief Header file for red switch
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+*/
+
+#ifndef __SWITCH_H
+#define __SWITCH_H
+
+/* Includes ------------------------------------------------------------------*/
+#include "mbed.h"
+#include "stmpe1600_class.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+ RANGE = 0,
+ ALS
+}SwitchState;
+
+/* Classes -------------------------------------------------------------------*/
+/** Class representing Red Switch
+ */
+
+class SWITCH
+{
+ public:
+ SWITCH(STMPE1600 &stmpe_1600, ExpGpioPinName Pin_Name=GPIO_11) : stmpe1600(stmpe_1600), PinName(Pin_Name) {
+ stmpe1600.setGPIOdir(PinName, INPUT);
+ }
+
+ bool RdSwitch () {
+ return stmpe1600.rdGPIO(PinName);
+ }
+
+ operator int()
+ {
+ return RdSwitch();
+ }
+
+ private:
+ STMPE1600 &stmpe1600;
+ ExpGpioPinName PinName;
+};
+
+#ifdef __cplusplus
+}
+#endif
+#endif // __SWITCH_H
\ No newline at end of file
--- a/Components/VL6180X/vl6180x_cfg.h Tue Nov 10 10:46:15 2015 +0000 +++ b/Components/VL6180X/vl6180x_cfg.h Tue Nov 17 17:15:47 2015 +0100 @@ -108,7 +108,8 @@ */ //#define VL6180x_EXTENDED_RANGE 0 -#define EXTENDED_RANGE_50CM 0 +//#define EXTENDED_RANGE_50CM 0 +#define EXTENDED_RANGE_50CM 1 #if EXTENDED_RANGE_50CM #define VL6180x_UPSCALE_SUPPORT -3
--- a/x_nucleo_6180xa1.h Tue Nov 10 10:46:15 2015 +0000
+++ b/x_nucleo_6180xa1.h Tue Nov 17 17:15:47 2015 +0100
@@ -46,6 +46,7 @@
#include "Display_class.h"
#include "stmpe1600_class.h"
#include "DevI2C.h"
+#include "Switch_class.h"
/** New device addresses */
#define NEW_SENSOR_TOP_ADDRESS 0x10
@@ -60,7 +61,12 @@
public:
X_NUCLEO_6180XA1(DevI2C *ext_i2c) : dev_i2c(ext_i2c)
{
- digit1=new STMPE1600DigiOut(*dev_i2c, GPIO_7);
+ 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);
@@ -71,9 +77,9 @@
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);
+ 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);
+ //display=new Display(*ext_i2c);
gpio0_top=new STMPE1600DigiOut(*dev_i2c, GPIO_12);
sensor_top=new VL6180X(*dev_i2c, *gpio0_top, PB_0);
@@ -98,7 +104,7 @@
if(sensor_top!=NULL)
{
delete sensor_top;
- sensor_top=NULL;
+ sensor_top=NULL;
}
if(gpio0_bottom!=NULL)
{
@@ -108,7 +114,7 @@
if(sensor_bottom!=NULL)
{
delete sensor_bottom;
- sensor_bottom=NULL;
+ sensor_bottom=NULL;
}
if(gpio0_left!=NULL)
{
@@ -118,7 +124,7 @@
if(sensor_left!=NULL)
{
delete sensor_left;
- sensor_left=NULL;
+ sensor_left=NULL;
}
if(gpio0_right!=NULL)
{
@@ -128,9 +134,9 @@
if(sensor_right!=NULL)
{
delete sensor_right;
- sensor_right=NULL;
+ sensor_right=NULL;
}
- delete digit1;
+ /*delete digit1;
delete digit2;
delete digit3;
delete digit4;
@@ -140,18 +146,27 @@
delete dispD;
delete dispE;
delete dispF;
- delete dispG;
- delete display;
+ delete dispG;*/
+ delete stmpe1600;
+ delete Switch;
+ delete display;
_instance=NULL;
}
-
+
+ bool RdSwitch () {
+ return Switch->RdSwitch();
+ }
+
DevI2C *dev_i2c;
VL6180X *sensor_top;
VL6180X *sensor_bottom;
VL6180X *sensor_left;
VL6180X *sensor_right;
-
+
+ STMPE1600 * stmpe1600;
+ SWITCH * Switch;
+
STMPE1600DigiOut *gpio0_top;
STMPE1600DigiOut *gpio0_bottom;
STMPE1600DigiOut *gpio0_left;
