Librairie adaptée au laboratoire 2
Dependencies: ST_INTERFACES X_NUCLEO_COMMON
Fork of X_NUCLEO_6180XA1 by
Revision 23:dfb5ccc7b780, committed 2015-10-30
- Comitter:
- gallonm
- Date:
- Fri Oct 30 11:35:36 2015 +0100
- Parent:
- 22:1a6327e9a7e6
- Child:
- 24:025afc3fe30f
- Commit message:
- Updated Display_class.h
Updated stmpe1600_class.h
Updated vl6180x_class.cpp
Introduced comments on vl6180x_class.h and vl6180x_class.cpp
Updated x_nucleo_6180xa1.h
Changed in this revision
--- a/Components/Display/Display_class.h Wed Oct 28 14:56:22 2015 +0000 +++ b/Components/Display/Display_class.h Fri Oct 30 11:35:36 2015 +0100 @@ -163,27 +163,26 @@ #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; + 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; } - } + 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 @@ -242,10 +241,12 @@ int i; const char *pc; - for( i=0, pc=str; i<4 && *pc!=0 ; i++, 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++; + if( *(pc+1)== '.') + { + pc++; } wait_ms(DISPLAY_DELAY); Digits_off(); @@ -253,11 +254,13 @@ } - void _V2_Set7Segment( int Leds, int digit ){ + void _V2_Set7Segment( int Leds, int digit ) + { //Digits_off(); - Segments_off(); // 7 seg off */ + Segments_off(); // 7 seg off */ int mask=1; - for (int i=0; i<7; i++) { + for (int i=0; i<7; i++) + { if (Leds & mask) Segment_on(i); mask = mask<<1; } @@ -271,9 +274,9 @@ { 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 + 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); } @@ -285,26 +288,28 @@ 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 + //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 + 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 ){ + void _V2_Set7Segment( int Leds, int digit ) + { //Digits_off(); - uint16_t dgt; dgt = 1<<digit; dgt = ((uint16_t)dgt)<<7; @@ -319,35 +324,36 @@ 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++) { + 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_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 + 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; + DevI2C &dev_i2c; }; #ifdef __cplusplus
--- a/Components/STMPE1600/stmpe1600_class.h Wed Oct 28 14:56:22 2015 +0000 +++ b/Components/STMPE1600/stmpe1600_class.h Fri Oct 30 11:35:36 2015 +0100 @@ -98,16 +98,17 @@ dev_i2c.i2c_write(data, expdevaddr, GPDR_0_7, 1); dev_i2c.i2c_write(&data[1], expdevaddr, GPDR_8_15, 1); write(lvl); - } + } - void write (int lvl) { - uint8_t data[2]; - /* 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 - if (lvl) *(uint16_t*)data = *(uint16_t*)data | (uint16_t)(1<<(uint16_t)exppinname); - dev_i2c.i2c_write(data, expdevaddr, GPSR_0_7, 2); - } + void write (int lvl) + { + uint8_t data[2]; + /* 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 + if (lvl) *(uint16_t*)data = *(uint16_t*)data | (uint16_t)(1<<(uint16_t)exppinname); + dev_i2c.i2c_write(data, expdevaddr, GPSR_0_7, 2); + } STMPE1600DigiOut& operator=(int lvl) { @@ -124,23 +125,24 @@ class STMPE1600DigiIn { public: - STMPE1600DigiIn (DevI2C &i2c, ExpGpioPinName inpinname, uint8_t DevAddr=STMPE1600_DEF_DEVICE_ADDRESS*2): dev_i2c(i2c), expdevaddr(DevAddr), exppinname(inpinname) - { - uint8_t data[2]; - /* 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 - dev_i2c.i2c_write(data, expdevaddr, GPDR_0_7, 2); - } + STMPE1600DigiIn (DevI2C &i2c, ExpGpioPinName inpinname, uint8_t DevAddr=STMPE1600_DEF_DEVICE_ADDRESS): dev_i2c(i2c), expdevaddr(DevAddr), exppinname(inpinname) + { + uint8_t data[2]; + /* 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 + dev_i2c.i2c_write(data, expdevaddr, GPDR_0_7, 2); + } - bool read () { - uint8_t data[2]; - /* 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 - if (data[0] || data[1]) return 1; - return 0; - } + bool read () + { + uint8_t data[2]; + /* 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 + if (data[0] || data[1]) return 1; + return 0; + } operator int() { @@ -158,53 +160,55 @@ 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, 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) - { - dev_i2c = i2c; - expdevaddr = DevAddr; - GPDR0_15 = (uint16_t)0; // gpio dir all IN - 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); - } + { + dev_i2c = i2c; + expdevaddr = DevAddr; + GPDR0_15 = (uint16_t)0; // gpio dir all IN + 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); + } - void readGPSR0_15 (uint16_t * gpsr0_15){ - dev_i2c.i2c_read((uint8_t*)gpsr0_15, expdevaddr, GPSR_0_7, 2); - GPSR0_15 = gpsr0_15; - } + void readGPSR0_15 (uint16_t * gpsr0_15) + { + dev_i2c.i2c_read((uint8_t*)gpsr0_15, expdevaddr, GPSR_0_7, 2); + GPSR0_15 = gpsr0_15; + } - void writeGPSR0_15 (uint16_t *gpsr0_15){ - dev_i2c.i2c_write((uint8_t*)*gpsr0_15, expdevaddr, GPSR_0_7, 2); - GPSR0_15 = *gpsr0_15; - } + void writeGPSR0_15 (uint16_t *gpsr0_15) + { + dev_i2c.i2c_write((uint8_t*)*gpsr0_15, expdevaddr, GPSR_0_7, 2); + GPSR0_15 = *gpsr0_15; + } private: - DevI2C &dev_i2c; - uint16_t GPDR0_15; - uint16_t GPSR0_15; - uint8_t expdevaddr; - }; + DevI2C &dev_i2c; + uint16_t GPDR0_15; + uint16_t GPSR0_15; + uint8_t expdevaddr; +}; */ #endif // __STMPE1600_CLASS
--- a/Components/VL6180X/vl6180x_class.cpp Wed Oct 28 14:56:22 2015 +0000 +++ b/Components/VL6180X/vl6180x_class.cpp Fri Oct 30 11:35:36 2015 +0100 @@ -725,12 +725,13 @@ -int VL6180X::VL6180x_AlsSetThresholds(VL6180xDev_t dev, uint8_t low, uint8_t high) { +int VL6180X::VL6180x_AlsSetThresholds(VL6180xDev_t dev, uint8_t low, uint8_t high) { int status; LOG_FUNCTION_START("%d %d", (int )low, (int)high); - - status = VL6180x_WrByte(dev, SYSALS_THRESH_LOW, low); //FIXME i valori passati devono essere uint16_t (vedi registri), inoltre i valori delle soglie NON sono in lux! bisogna invertire il calcolo fatto nella VL6180x_AlsGetLux() + /*FIXME arguments have to be uint16_t (see SYSALS_THRESH_LOW and SYSALS_THRESH_HIGH registers) + Furthermore threshold values are not lux! You need to invert the computation made in VL6180x_AlsGetLux() */ + status = VL6180x_WrByte(dev, SYSALS_THRESH_LOW, low); if(!status ){ status = VL6180x_WrByte(dev, SYSALS_THRESH_HIGH, high); } @@ -2686,7 +2687,7 @@ VL6180x_On(); status=VL6180x_WaitDeviceBooted(Device); if(status) - printf("WaitDeviceBooted fail\n\r"); + VL6180x_ErrLog("WaitDeviceBooted fail\n\r"); status=IsPresent(); if(!status) {
--- a/Components/VL6180X/vl6180x_class.h Wed Oct 28 14:56:22 2015 +0000 +++ b/Components/VL6180X/vl6180x_class.h Fri Oct 30 11:35:36 2015 +0100 @@ -122,7 +122,9 @@ /** Destructor */ - //~VL6180X(){} + //virtual ~VL6180X(){} + /* FIXME warning: VL6180X class inherits from GenericSensor, RangeSensor and LightSensor, that haven`t a destructor. + The warning should request to introduce a virtual destructor to make sure to delete the object */ /* turns on the sensor */ void VL6180x_On(void)
--- a/x_nucleo_6180xa1.h Wed Oct 28 14:56:22 2015 +0000 +++ b/x_nucleo_6180xa1.h Fri Oct 30 11:35:36 2015 +0100 @@ -120,16 +120,6 @@ delete sensor_left; sensor_left=NULL; } - if(gpio0_left!=NULL) - { - delete gpio0_left; - gpio0_left=NULL; - } - if(sensor_left!=NULL) - { - delete sensor_left; - sensor_left=NULL; - } if(gpio0_right!=NULL) { delete gpio0_right;