Now you can use NC as InterruptIn
Fork of X_NUCLEO_6180XA1 by
Components/STMPE1600/stmpe1600_class.h@10:4954b09b72d8, 2015-10-06 (annotated)
- Committer:
- gallonm
- Date:
- Tue Oct 06 09:03:10 2015 +0200
- Revision:
- 10:4954b09b72d8
- Parent:
- 8:f943a1fca15f
- Child:
- 12:71d589e6fd2c
Fitted all api files (reinserted original api files)
Modified file platform.h and removed vl6180x_appcfg.h from the include
Modified value of the define SINGLE_DEVICE_DRIVER
Updated file stmpe1600_class.h
Fitted the ReadID function and I2C functions (read and write)
Updated file vl6180x_class.cpp
Introduced functions InitSensor and StartMeasurement
Fitted the constructor and the destructor of x_nucleo_6180xa1
Added the instance to create a singleton object
Introduced InitBoard function
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gallonm | 7:2dc81120c917 | 1 | /** |
gallonm | 7:2dc81120c917 | 2 | ****************************************************************************** |
gallonm | 7:2dc81120c917 | 3 | * @file vl6180x_class.h |
gallonm | 7:2dc81120c917 | 4 | * @author AST / EST |
gallonm | 7:2dc81120c917 | 5 | * @version V0.0.1 |
gallonm | 7:2dc81120c917 | 6 | * @date 14-April-2015 |
gallonm | 7:2dc81120c917 | 7 | * @brief Header file for component VL6180X |
gallonm | 7:2dc81120c917 | 8 | ****************************************************************************** |
gallonm | 7:2dc81120c917 | 9 | * @attention |
gallonm | 7:2dc81120c917 | 10 | * |
gallonm | 7:2dc81120c917 | 11 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
gallonm | 7:2dc81120c917 | 12 | * |
gallonm | 7:2dc81120c917 | 13 | * Redistribution and use in source and binary forms, with or without modification, |
gallonm | 7:2dc81120c917 | 14 | * are permitted provided that the following conditions are met: |
gallonm | 7:2dc81120c917 | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
gallonm | 7:2dc81120c917 | 16 | * this list of conditions and the following disclaimer. |
gallonm | 7:2dc81120c917 | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
gallonm | 7:2dc81120c917 | 18 | * this list of conditions and the following disclaimer in the documentation |
gallonm | 7:2dc81120c917 | 19 | * and/or other materials provided with the distribution. |
gallonm | 7:2dc81120c917 | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
gallonm | 7:2dc81120c917 | 21 | * may be used to endorse or promote products derived from this software |
gallonm | 7:2dc81120c917 | 22 | * without specific prior written permission. |
gallonm | 7:2dc81120c917 | 23 | * |
gallonm | 7:2dc81120c917 | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
gallonm | 7:2dc81120c917 | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
gallonm | 7:2dc81120c917 | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
gallonm | 7:2dc81120c917 | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
gallonm | 7:2dc81120c917 | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
gallonm | 7:2dc81120c917 | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
gallonm | 7:2dc81120c917 | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
gallonm | 7:2dc81120c917 | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
gallonm | 7:2dc81120c917 | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
gallonm | 7:2dc81120c917 | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
gallonm | 7:2dc81120c917 | 34 | * |
gallonm | 7:2dc81120c917 | 35 | ****************************************************************************** |
gallonm | 7:2dc81120c917 | 36 | */ |
gallonm | 7:2dc81120c917 | 37 | #ifndef __STMPE1600_CLASS |
gallonm | 7:2dc81120c917 | 38 | #define __STMPE1600_CLASS |
gallonm | 7:2dc81120c917 | 39 | /* Includes ------------------------------------------------------------------*/ |
gallonm | 10:4954b09b72d8 | 40 | #include "DevI2C.h" |
gallonm | 7:2dc81120c917 | 41 | |
licio.mapelli@st.com | 8:f943a1fca15f | 42 | #define STMPE1600_DEF_DEVICE_ADDRESS (uint8_t)0x42*2 |
licio.mapelli@st.com | 8:f943a1fca15f | 43 | #define STMPE1600_DEF_DIGIOUT_LVL 1 |
gallonm | 7:2dc81120c917 | 44 | |
gallonm | 7:2dc81120c917 | 45 | /** STMPE1600 registr map **/ |
gallonm | 7:2dc81120c917 | 46 | #define VersionId (uint8_t)0x02 |
gallonm | 7:2dc81120c917 | 47 | #define SystemControl (uint8_t)0x03 |
gallonm | 7:2dc81120c917 | 48 | #define IEGPIOR_0_7 (uint8_t)0x08 |
gallonm | 7:2dc81120c917 | 49 | #define IEGPIOR_8_15 (uint8_t)0x09 |
gallonm | 7:2dc81120c917 | 50 | #define ISGPIOR_0_7 (uint8_t)0x0A |
gallonm | 7:2dc81120c917 | 51 | #define ISGPIOR_8_15 (uint8_t)0x0B |
gallonm | 7:2dc81120c917 | 52 | #define GPMR_0_7 (uint8_t)0x10 |
gallonm | 7:2dc81120c917 | 53 | #define GPMR_8_15 (uint8_t)0x11 |
gallonm | 7:2dc81120c917 | 54 | #define GPSR_0_7 (uint8_t)0x12 |
gallonm | 7:2dc81120c917 | 55 | #define GPSR_8_15 (uint8_t)0x13 |
gallonm | 7:2dc81120c917 | 56 | #define GPDR_0_7 (uint8_t)0x14 |
gallonm | 7:2dc81120c917 | 57 | #define GPDR_8_15 (uint8_t)0x15 |
gallonm | 7:2dc81120c917 | 58 | #define GPIR_0_7 (uint8_t)0x16 |
gallonm | 7:2dc81120c917 | 59 | #define GPIR_8_15 (uint8_t)0x17 |
gallonm | 7:2dc81120c917 | 60 | |
gallonm | 7:2dc81120c917 | 61 | typedef enum { |
gallonm | 7:2dc81120c917 | 62 | // GPIO Expander pin names |
gallonm | 7:2dc81120c917 | 63 | GPIO_0, |
gallonm | 7:2dc81120c917 | 64 | GPIO_1, |
gallonm | 7:2dc81120c917 | 65 | GPIO_2, |
gallonm | 7:2dc81120c917 | 66 | GPIO_3, |
gallonm | 7:2dc81120c917 | 67 | GPIO_4, |
gallonm | 7:2dc81120c917 | 68 | GPIO_5, |
gallonm | 7:2dc81120c917 | 69 | GPIO_6, |
gallonm | 7:2dc81120c917 | 70 | GPIO_7, |
gallonm | 7:2dc81120c917 | 71 | GPIO_8, |
gallonm | 7:2dc81120c917 | 72 | GPIO_9, |
gallonm | 7:2dc81120c917 | 73 | GPIO_10, |
gallonm | 7:2dc81120c917 | 74 | GPIO_11, |
gallonm | 7:2dc81120c917 | 75 | GPIO_12, |
gallonm | 7:2dc81120c917 | 76 | GPIO_13, |
gallonm | 7:2dc81120c917 | 77 | GPIO_14, |
gallonm | 7:2dc81120c917 | 78 | GPIO_15 |
gallonm | 7:2dc81120c917 | 79 | } ExpGpioPinName; |
gallonm | 7:2dc81120c917 | 80 | |
gallonm | 7:2dc81120c917 | 81 | typedef enum { |
gallonm | 7:2dc81120c917 | 82 | INPUT, |
gallonm | 7:2dc81120c917 | 83 | OUTPUT, |
gallonm | 7:2dc81120c917 | 84 | NOT_CONNECTED |
gallonm | 7:2dc81120c917 | 85 | }ExpGpioPinDirection; |
gallonm | 7:2dc81120c917 | 86 | |
gallonm | 7:2dc81120c917 | 87 | |
gallonm | 7:2dc81120c917 | 88 | class STMPE1600DigiOut { |
gallonm | 7:2dc81120c917 | 89 | |
gallonm | 7:2dc81120c917 | 90 | public: |
gallonm | 7:2dc81120c917 | 91 | 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) |
gallonm | 7:2dc81120c917 | 92 | { |
gallonm | 7:2dc81120c917 | 93 | uint8_t data[2]; |
gallonm | 7:2dc81120c917 | 94 | /* set the exppinname as output */ |
gallonm | 7:2dc81120c917 | 95 | dev_i2c.i2c_read(data, expdevaddr, GPDR_0_7, 1); |
gallonm | 7:2dc81120c917 | 96 | dev_i2c.i2c_read(&data[1], expdevaddr, GPDR_8_15, 1); |
gallonm | 7:2dc81120c917 | 97 | *(uint16_t*)data = *(uint16_t*)data | (1<<(uint16_t)exppinname); // set gopio as out |
gallonm | 7:2dc81120c917 | 98 | dev_i2c.i2c_write(data, expdevaddr, GPDR_0_7, 1); |
gallonm | 7:2dc81120c917 | 99 | dev_i2c.i2c_write(&data[1], expdevaddr, GPDR_8_15, 1); |
gallonm | 7:2dc81120c917 | 100 | write(lvl); |
gallonm | 7:2dc81120c917 | 101 | |
gallonm | 7:2dc81120c917 | 102 | } |
gallonm | 7:2dc81120c917 | 103 | |
gallonm | 7:2dc81120c917 | 104 | void write (int lvl) { |
gallonm | 7:2dc81120c917 | 105 | uint8_t data[2]; |
gallonm | 7:2dc81120c917 | 106 | /* set the exppinname state to lvl */ |
gallonm | 7:2dc81120c917 | 107 | dev_i2c.i2c_read(data, expdevaddr, GPSR_0_7, 1); |
gallonm | 7:2dc81120c917 | 108 | dev_i2c.i2c_read(&data[1], expdevaddr, GPSR_8_15, 1); |
licio.mapelli@st.com | 8:f943a1fca15f | 109 | *(uint16_t*)data = *(uint16_t*)data & (uint16_t)(~(1<<(uint16_t)exppinname)); // set pin mask |
licio.mapelli@st.com | 8:f943a1fca15f | 110 | if (lvl) *(uint16_t*)data = *(uint16_t*)data | (uint16_t)(1<<(uint16_t)exppinname); |
gallonm | 7:2dc81120c917 | 111 | dev_i2c.i2c_write(data, expdevaddr, GPSR_0_7, 1); |
gallonm | 7:2dc81120c917 | 112 | dev_i2c.i2c_write(&data[1], expdevaddr, GPSR_8_15, 1); |
gallonm | 7:2dc81120c917 | 113 | } |
gallonm | 7:2dc81120c917 | 114 | |
gallonm | 7:2dc81120c917 | 115 | STMPE1600DigiOut& operator=(int lvl) { |
gallonm | 7:2dc81120c917 | 116 | write (lvl); |
gallonm | 7:2dc81120c917 | 117 | return *this; |
gallonm | 7:2dc81120c917 | 118 | } |
gallonm | 7:2dc81120c917 | 119 | |
gallonm | 7:2dc81120c917 | 120 | private: |
gallonm | 7:2dc81120c917 | 121 | DevI2C &dev_i2c; |
gallonm | 7:2dc81120c917 | 122 | uint8_t expdevaddr; |
gallonm | 7:2dc81120c917 | 123 | ExpGpioPinName exppinname; |
gallonm | 7:2dc81120c917 | 124 | }; |
gallonm | 7:2dc81120c917 | 125 | |
gallonm | 7:2dc81120c917 | 126 | class STMPE1600DigiIn { |
gallonm | 7:2dc81120c917 | 127 | |
gallonm | 7:2dc81120c917 | 128 | public: |
licio.mapelli@st.com | 8:f943a1fca15f | 129 | STMPE1600DigiIn (DevI2C &i2c, ExpGpioPinName inpinname, uint8_t DevAddr=STMPE1600_DEF_DEVICE_ADDRESS*2): dev_i2c(i2c), expdevaddr(DevAddr*2), exppinname(inpinname) |
gallonm | 7:2dc81120c917 | 130 | { |
gallonm | 7:2dc81120c917 | 131 | uint8_t data[2]; |
gallonm | 7:2dc81120c917 | 132 | /* set the exppinname as input pin direction */ |
gallonm | 7:2dc81120c917 | 133 | dev_i2c.i2c_read(data, expdevaddr, GPDR_0_7, 1); |
gallonm | 7:2dc81120c917 | 134 | dev_i2c.i2c_read(&data[1], expdevaddr, GPDR_8_15, 1); |
licio.mapelli@st.com | 8:f943a1fca15f | 135 | *(uint16_t*)data = *(uint16_t*)data & (uint16_t)(~(1<<(uint16_t)exppinname)); // set gopio as in |
gallonm | 7:2dc81120c917 | 136 | dev_i2c.i2c_write(data, expdevaddr, GPDR_0_7, 1); |
gallonm | 7:2dc81120c917 | 137 | dev_i2c.i2c_write(&data[1], expdevaddr, GPDR_8_15, 1); |
gallonm | 7:2dc81120c917 | 138 | } |
gallonm | 7:2dc81120c917 | 139 | |
gallonm | 7:2dc81120c917 | 140 | bool read () { |
gallonm | 7:2dc81120c917 | 141 | uint8_t data[2]; |
gallonm | 7:2dc81120c917 | 142 | /* read the exppinname */ |
gallonm | 7:2dc81120c917 | 143 | dev_i2c.i2c_read(data, expdevaddr, GPMR_0_7, 1); |
gallonm | 7:2dc81120c917 | 144 | dev_i2c.i2c_read(&data[1], expdevaddr, GPMR_8_15, 1); |
licio.mapelli@st.com | 8:f943a1fca15f | 145 | *(uint16_t*)data = *(uint16_t*)data & (uint16_t)(1<<(uint16_t)exppinname); // mask the in gpio |
gallonm | 7:2dc81120c917 | 146 | if (data[0] || data[1]) return 1; |
gallonm | 7:2dc81120c917 | 147 | return 0; |
gallonm | 7:2dc81120c917 | 148 | } |
gallonm | 7:2dc81120c917 | 149 | |
gallonm | 7:2dc81120c917 | 150 | operator int() { |
gallonm | 7:2dc81120c917 | 151 | return read(); |
gallonm | 7:2dc81120c917 | 152 | } |
gallonm | 7:2dc81120c917 | 153 | |
gallonm | 7:2dc81120c917 | 154 | private: |
gallonm | 7:2dc81120c917 | 155 | DevI2C &dev_i2c; |
gallonm | 7:2dc81120c917 | 156 | uint8_t expdevaddr; |
gallonm | 7:2dc81120c917 | 157 | ExpGpioPinName exppinname; |
gallonm | 7:2dc81120c917 | 158 | }; |
gallonm | 7:2dc81120c917 | 159 | |
gallonm | 7:2dc81120c917 | 160 | |
gallonm | 7:2dc81120c917 | 161 | #endif // __STMPE1600_CLASS |