Now you can use NC as InterruptIn

Dependencies:   X_NUCLEO_COMMON

Fork of X_NUCLEO_6180XA1 by ST

Committer:
gallonm
Date:
Tue Oct 27 15:25:11 2015 +0100
Revision:
16:0d4776564733
Parent:
15:454710d17358
Child:
23:dfb5ccc7b780
Added display class.
Updated STMPE1600 class.
Updated cfg.h with the modify of the range scaling.
Updated platform.h with the addition of printf.
Updated x_nucleo_6180xa1.h and x_nucleo_6180xa1.cpp

Who changed what in which revision?

UserRevisionLine numberNew 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>&copy; 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 16:0d4776564733 46 #define VersionId (uint8_t)0x02
gallonm 16:0d4776564733 47 #define SystemControl (uint8_t)0x03
gallonm 16:0d4776564733 48 #define IEGPIOR_0_7 (uint8_t)0x08
gallonm 7:2dc81120c917 49 #define IEGPIOR_8_15 (uint8_t)0x09
gallonm 16:0d4776564733 50 #define ISGPIOR_0_7 (uint8_t)0x0A
gallonm 7:2dc81120c917 51 #define ISGPIOR_8_15 (uint8_t)0x0B
gallonm 16:0d4776564733 52 #define GPMR_0_7 (uint8_t)0x10
gallonm 16:0d4776564733 53 #define GPMR_8_15 (uint8_t)0x11
gallonm 16:0d4776564733 54 #define GPSR_0_7 (uint8_t)0x12
gallonm 16:0d4776564733 55 #define GPSR_8_15 (uint8_t)0x13
gallonm 16:0d4776564733 56 #define GPDR_0_7 (uint8_t)0x14
gallonm 16:0d4776564733 57 #define GPDR_8_15 (uint8_t)0x15
gallonm 16:0d4776564733 58 #define GPIR_0_7 (uint8_t)0x16
gallonm 16:0d4776564733 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 15:454710d17358 63 GPIO_0=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 16:0d4776564733 82 INPUT = 0,
gallonm 7:2dc81120c917 83 OUTPUT,
gallonm 16:0d4776564733 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 16:0d4776564733 92 {
gallonm 16:0d4776564733 93 uint8_t data[2];
gallonm 16:0d4776564733 94 /* set the exppinname as output */
gallonm 16:0d4776564733 95 dev_i2c.i2c_read(data, expdevaddr, GPDR_0_7, 1);
gallonm 16:0d4776564733 96 dev_i2c.i2c_read(&data[1], expdevaddr, GPDR_8_15, 1);
gallonm 16:0d4776564733 97 *(uint16_t*)data = *(uint16_t*)data | (1<<(uint16_t)exppinname); // set gpio as out
gallonm 16:0d4776564733 98 dev_i2c.i2c_write(data, expdevaddr, GPDR_0_7, 1);
gallonm 16:0d4776564733 99 dev_i2c.i2c_write(&data[1], expdevaddr, GPDR_8_15, 1);
gallonm 16:0d4776564733 100 write(lvl);
gallonm 16:0d4776564733 101 }
gallonm 7:2dc81120c917 102
gallonm 7:2dc81120c917 103 void write (int lvl) {
gallonm 7:2dc81120c917 104 uint8_t data[2];
gallonm 7:2dc81120c917 105 /* set the exppinname state to lvl */
gallonm 16:0d4776564733 106 dev_i2c.i2c_read(data, expdevaddr, GPSR_0_7, 2);
licio.mapelli@st.com 8:f943a1fca15f 107 *(uint16_t*)data = *(uint16_t*)data & (uint16_t)(~(1<<(uint16_t)exppinname)); // set pin mask
gallonm 16:0d4776564733 108 if (lvl) *(uint16_t*)data = *(uint16_t*)data | (uint16_t)(1<<(uint16_t)exppinname);
gallonm 16:0d4776564733 109 dev_i2c.i2c_write(data, expdevaddr, GPSR_0_7, 2);
gallonm 7:2dc81120c917 110 }
gallonm 7:2dc81120c917 111
gallonm 16:0d4776564733 112 STMPE1600DigiOut& operator=(int lvl)
gallonm 16:0d4776564733 113 {
gallonm 16:0d4776564733 114 write (lvl);
gallonm 16:0d4776564733 115 return *this;
gallonm 16:0d4776564733 116 }
gallonm 7:2dc81120c917 117
gallonm 7:2dc81120c917 118 private:
gallonm 16:0d4776564733 119 DevI2C &dev_i2c;
gallonm 16:0d4776564733 120 uint8_t expdevaddr;
gallonm 16:0d4776564733 121 ExpGpioPinName exppinname;
gallonm 7:2dc81120c917 122 };
gallonm 7:2dc81120c917 123
gallonm 16:0d4776564733 124 class STMPE1600DigiIn
gallonm 16:0d4776564733 125 {
gallonm 7:2dc81120c917 126 public:
gallonm 16:0d4776564733 127 STMPE1600DigiIn (DevI2C &i2c, ExpGpioPinName inpinname, uint8_t DevAddr=STMPE1600_DEF_DEVICE_ADDRESS*2): dev_i2c(i2c), expdevaddr(DevAddr), exppinname(inpinname)
gallonm 7:2dc81120c917 128 {
gallonm 7:2dc81120c917 129 uint8_t data[2];
gallonm 7:2dc81120c917 130 /* set the exppinname as input pin direction */
gallonm 16:0d4776564733 131 dev_i2c.i2c_read(data, expdevaddr, GPDR_0_7, 2);
gallonm 12:71d589e6fd2c 132 *(uint16_t*)data = *(uint16_t*)data & (uint16_t)(~(1<<(uint16_t)exppinname)); // set gpio as in
gallonm 16:0d4776564733 133 dev_i2c.i2c_write(data, expdevaddr, GPDR_0_7, 2);
gallonm 7:2dc81120c917 134 }
gallonm 7:2dc81120c917 135
gallonm 7:2dc81120c917 136 bool read () {
gallonm 7:2dc81120c917 137 uint8_t data[2];
gallonm 7:2dc81120c917 138 /* read the exppinname */
gallonm 16:0d4776564733 139 dev_i2c.i2c_read(data, expdevaddr, GPMR_0_7, 2);
licio.mapelli@st.com 8:f943a1fca15f 140 *(uint16_t*)data = *(uint16_t*)data & (uint16_t)(1<<(uint16_t)exppinname); // mask the in gpio
gallonm 7:2dc81120c917 141 if (data[0] || data[1]) return 1;
gallonm 7:2dc81120c917 142 return 0;
gallonm 7:2dc81120c917 143 }
gallonm 7:2dc81120c917 144
gallonm 16:0d4776564733 145 operator int()
gallonm 16:0d4776564733 146 {
gallonm 16:0d4776564733 147 return read();
gallonm 16:0d4776564733 148 }
gallonm 7:2dc81120c917 149
gallonm 7:2dc81120c917 150 private:
gallonm 16:0d4776564733 151 DevI2C &dev_i2c;
gallonm 16:0d4776564733 152 uint8_t expdevaddr;
gallonm 16:0d4776564733 153 ExpGpioPinName exppinname;
gallonm 7:2dc81120c917 154 };
gallonm 7:2dc81120c917 155
gallonm 7:2dc81120c917 156
gallonm 16:0d4776564733 157 /*
gallonm 16:0d4776564733 158 class STMPE1600 {
gallonm 16:0d4776564733 159
gallonm 16:0d4776564733 160 public:
gallonm 16:0d4776564733 161 STMPE1600 (DevI2C &i2c,
gallonm 16:0d4776564733 162 ExpGpioPinDirection GPDR0, ExpGpioPinDirection GPDR1, ExpGpioPinDirection GPDR2,
gallonm 16:0d4776564733 163 ExpGpioPinDirection GPDR3, ExpGpioPinDirection GPDR4, ExpGpioPinDirection GPDR5,
gallonm 16:0d4776564733 164 ExpGpioPinDirection GPDR6, ExpGpioPinDirection GPDR7, ExpGpioPinDirection GPDR8,
gallonm 16:0d4776564733 165 ExpGpioPinDirection GPDR9, ExpGpioPinDirection GPDR10, ExpGpioPinDirection GPDR11,
gallonm 16:0d4776564733 166 ExpGpioPinDirection GPDR12, ExpGpioPinDirection GPDR13, ExpGpioPinDirection GPDR14, ExpGpioPinDirection GPDR15, uint8_t DevAddr=STMPE1600_DEF_DEVICE_ADDRESS ) :dev_i2c(i2c)
gallonm 16:0d4776564733 167
gallonm 16:0d4776564733 168 {
gallonm 16:0d4776564733 169 dev_i2c = i2c;
gallonm 16:0d4776564733 170 expdevaddr = DevAddr;
gallonm 16:0d4776564733 171 GPDR0_15 = (uint16_t)0; // gpio dir all IN
gallonm 16:0d4776564733 172 GPSR0_15 = (uint16_t)0x0ffff; // gpio status all 1
gallonm 16:0d4776564733 173 if (GPDR0 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0001;
gallonm 16:0d4776564733 174 if (GPDR1 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0002;
gallonm 16:0d4776564733 175 if (GPDR2 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0004;
gallonm 16:0d4776564733 176 if (GPDR3 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0008;
gallonm 16:0d4776564733 177 if (GPDR4 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0010;
gallonm 16:0d4776564733 178 if (GPDR5 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0020;
gallonm 16:0d4776564733 179 if (GPDR6 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0040;
gallonm 16:0d4776564733 180 if (GPDR7 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0080;
gallonm 16:0d4776564733 181 if (GPDR8 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0100;
gallonm 16:0d4776564733 182 if (GPDR9 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0200;
gallonm 16:0d4776564733 183 if (GPDR10 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0400;
gallonm 16:0d4776564733 184 if (GPDR11 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0800;
gallonm 16:0d4776564733 185 if (GPDR12 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x1000;
gallonm 16:0d4776564733 186 if (GPDR13 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x2000;
gallonm 16:0d4776564733 187 if (GPDR14 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x4000;
gallonm 16:0d4776564733 188 if (GPDR15 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x8000;
gallonm 16:0d4776564733 189 dev_i2c.i2c_write((uint8_t*)&GPDR0_15, expdevaddr, GPDR_0_7, 2);
gallonm 16:0d4776564733 190 dev_i2c.i2c_write((uint8_t*)&GPSR0_15, expdevaddr, GPSR_0_7, 2);
gallonm 16:0d4776564733 191 }
gallonm 16:0d4776564733 192
gallonm 16:0d4776564733 193 void readGPSR0_15 (uint16_t * gpsr0_15){
gallonm 16:0d4776564733 194 dev_i2c.i2c_read((uint8_t*)gpsr0_15, expdevaddr, GPSR_0_7, 2);
gallonm 16:0d4776564733 195 GPSR0_15 = gpsr0_15;
gallonm 16:0d4776564733 196 }
gallonm 16:0d4776564733 197
gallonm 16:0d4776564733 198 void writeGPSR0_15 (uint16_t *gpsr0_15){
gallonm 16:0d4776564733 199 dev_i2c.i2c_write((uint8_t*)*gpsr0_15, expdevaddr, GPSR_0_7, 2);
gallonm 16:0d4776564733 200 GPSR0_15 = *gpsr0_15;
gallonm 16:0d4776564733 201 }
gallonm 16:0d4776564733 202
gallonm 16:0d4776564733 203 private:
gallonm 16:0d4776564733 204 DevI2C &dev_i2c;
gallonm 16:0d4776564733 205 uint16_t GPDR0_15;
gallonm 16:0d4776564733 206 uint16_t GPSR0_15;
gallonm 16:0d4776564733 207 uint8_t expdevaddr;
gallonm 16:0d4776564733 208 };
gallonm 16:0d4776564733 209 */
gallonm 7:2dc81120c917 210 #endif // __STMPE1600_CLASS