Library for the MAX11300

Committer:
j3
Date:
Tue May 09 22:06:19 2017 +0000
Revision:
13:546dd29b1c7a
Parent:
12:8054ee101bad
Child:
14:cc5349db13a3
Working on Library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 7:8669a53acd0d 1 /**********************************************************************
j3 7:8669a53acd0d 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
j3 7:8669a53acd0d 3 *
j3 7:8669a53acd0d 4 * Permission is hereby granted, free of charge, to any person obtaining a
j3 7:8669a53acd0d 5 * copy of this software and associated documentation files (the "Software"),
j3 7:8669a53acd0d 6 * to deal in the Software without restriction, including without limitation
j3 7:8669a53acd0d 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 7:8669a53acd0d 8 * and/or sell copies of the Software, and to permit persons to whom the
j3 7:8669a53acd0d 9 * Software is furnished to do so, subject to the following conditions:
j3 7:8669a53acd0d 10 *
j3 7:8669a53acd0d 11 * The above copyright notice and this permission notice shall be included
j3 7:8669a53acd0d 12 * in all copies or substantial portions of the Software.
j3 7:8669a53acd0d 13 *
j3 7:8669a53acd0d 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 7:8669a53acd0d 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 7:8669a53acd0d 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 7:8669a53acd0d 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 7:8669a53acd0d 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 7:8669a53acd0d 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 7:8669a53acd0d 20 * OTHER DEALINGS IN THE SOFTWARE.
j3 7:8669a53acd0d 21 *
j3 7:8669a53acd0d 22 * Except as contained in this notice, the name of Maxim Integrated
j3 7:8669a53acd0d 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 7:8669a53acd0d 24 * Products, Inc. Branding Policy.
j3 7:8669a53acd0d 25 *
j3 7:8669a53acd0d 26 * The mere transfer of this software does not imply any licenses
j3 7:8669a53acd0d 27 * of trade secrets, proprietary technology, copyrights, patents,
j3 7:8669a53acd0d 28 * trademarks, maskwork rights, or any other form of intellectual
j3 7:8669a53acd0d 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 7:8669a53acd0d 30 * ownership rights.
j3 7:8669a53acd0d 31 **********************************************************************/
j3 7:8669a53acd0d 32
j3 7:8669a53acd0d 33
j3 7:8669a53acd0d 34 #ifndef _MAX113XX_PIXI_H_
j3 7:8669a53acd0d 35 #define _MAX113XX_PIXI_H_
j3 7:8669a53acd0d 36
j3 9:094df3de3616 37
j3 7:8669a53acd0d 38 #include "mbed.h"
j3 12:8054ee101bad 39 #include "MAX11300Hex.h"
j3 9:094df3de3616 40
j3 7:8669a53acd0d 41
j3 7:8669a53acd0d 42 /**
j3 8:4291f7e54863 43 @brief MAX113XX - PIXI, 20/12-Port Programmable Mixed-Signal I/O with
j3 7:8669a53acd0d 44 12-Bit ADC, 12-Bit DAC, Analog Switches, and GPIO
j3 7:8669a53acd0d 45
j3 8:4291f7e54863 46 The MAX113XX family integrates a PIXI™, 12-bit, multichannel, analog-to-digital
j3 7:8669a53acd0d 47 converter (ADC) and a 12-bit, multichannel, buffered digital-to-analog
j3 8:4291f7e54863 48 converter (DAC) in a single integrated circuit (IC). These devices offers
j3 8:4291f7e54863 49 20/12 mixed-signal high-voltage, bipolar ports, which are configurable as an
j3 7:8669a53acd0d 50 ADC analog input, a DAC analog output, a general-purpose input port (GPI),
j3 7:8669a53acd0d 51 a general-purpose output port (GPO), or an analog switch terminal.
j3 7:8669a53acd0d 52 One internal and two external temperature sensors track junction and
j3 7:8669a53acd0d 53 environmental temperature, respectively. Adjacent pairs of ports are
j3 7:8669a53acd0d 54 configurable as a logic-level translator for open-drain devices or an
j3 7:8669a53acd0d 55 analog switch.
j3 7:8669a53acd0d 56
j3 7:8669a53acd0d 57 Use configuration software found at
j3 7:8669a53acd0d 58 https://www.maximintegrated.com/en/products/analog/data-converters/analog-to-digital-converters/MAX11300.html/tb_tab2
j3 9:094df3de3616 59 to generate MAX113XXHex.h file
j3 7:8669a53acd0d 60 */
j3 7:8669a53acd0d 61 class MAX113XX_Pixi
j3 7:8669a53acd0d 62 {
j3 7:8669a53acd0d 63 public:
j3 7:8669a53acd0d 64
j3 10:6efe114ef882 65 ///Pixi devices
j3 9:094df3de3616 66 enum Device_e
j3 9:094df3de3616 67 {
j3 9:094df3de3616 68 MAX11300 = 0,
j3 9:094df3de3616 69 MAX11301,
j3 9:094df3de3616 70 MAX11311,
j3 9:094df3de3616 71 MAX11312
j3 9:094df3de3616 72 };
j3 9:094df3de3616 73
j3 9:094df3de3616 74 ///MAX113XX Ports
j3 9:094df3de3616 75 enum Ports_e
j3 7:8669a53acd0d 76 {
j3 7:8669a53acd0d 77 PORT0,
j3 7:8669a53acd0d 78 PORT1,
j3 7:8669a53acd0d 79 PORT2,
j3 7:8669a53acd0d 80 PORT3,
j3 7:8669a53acd0d 81 PORT4,
j3 7:8669a53acd0d 82 PORT5,
j3 7:8669a53acd0d 83 PORT6,
j3 7:8669a53acd0d 84 PORT7,
j3 7:8669a53acd0d 85 PORT8,
j3 7:8669a53acd0d 86 PORT9,
j3 7:8669a53acd0d 87 PORT10,
j3 7:8669a53acd0d 88 PORT11,
j3 7:8669a53acd0d 89 PORT12,
j3 7:8669a53acd0d 90 PORT13,
j3 7:8669a53acd0d 91 PORT14,
j3 7:8669a53acd0d 92 PORT15,
j3 7:8669a53acd0d 93 PORT16,
j3 7:8669a53acd0d 94 PORT17,
j3 7:8669a53acd0d 95 PORT18,
j3 7:8669a53acd0d 96 PORT19
j3 7:8669a53acd0d 97 };
j3 7:8669a53acd0d 98
j3 9:094df3de3616 99 ///MAX113XX Port Modes
j3 9:094df3de3616 100 enum PortModes_e
j3 7:8669a53acd0d 101 {
j3 7:8669a53acd0d 102 ///HIGH_Z
j3 7:8669a53acd0d 103 MODE_0,
j3 7:8669a53acd0d 104 ///Digital input with programmable threshold, GPI
j3 7:8669a53acd0d 105 MODE_1,
j3 7:8669a53acd0d 106 ///Bidirectional level translator terminal
j3 7:8669a53acd0d 107 MODE_2,
j3 7:8669a53acd0d 108 ///Register-driven digital output with DAC-controlled level, GPO
j3 7:8669a53acd0d 109 MODE_3,
j3 7:8669a53acd0d 110 ///Unidirectional path output with DAC-controlled level, GPO
j3 7:8669a53acd0d 111 MODE_4,
j3 7:8669a53acd0d 112 ///Analog output for DAC
j3 7:8669a53acd0d 113 MODE_5,
j3 7:8669a53acd0d 114 ///Analog output for DAC with ADC monitoring
j3 7:8669a53acd0d 115 MODE_6,
j3 7:8669a53acd0d 116 ///Positive analog input to single-ended ADC
j3 7:8669a53acd0d 117 MODE_7,
j3 7:8669a53acd0d 118 ///Positive analog input to differential ADC
j3 7:8669a53acd0d 119 MODE_8,
j3 7:8669a53acd0d 120 ///Negative analog input to differential ADC
j3 7:8669a53acd0d 121 MODE_9,
j3 7:8669a53acd0d 122 ///Analog output for DAC and negative analog input to differential ADC
j3 7:8669a53acd0d 123 MODE_10,
j3 7:8669a53acd0d 124 ///Terminal to GPI-controlled analog switch
j3 7:8669a53acd0d 125 MODE_11,
j3 7:8669a53acd0d 126 ///Terminal to register-controlled analog switch
j3 7:8669a53acd0d 127 MODE_12
j3 7:8669a53acd0d 128 };
j3 7:8669a53acd0d 129
j3 13:546dd29b1c7a 130 ///Temperature sensors
j3 13:546dd29b1c7a 131 enum TempSensor_e
j3 13:546dd29b1c7a 132 {
j3 13:546dd29b1c7a 133 Internal,
j3 13:546dd29b1c7a 134 External1,
j3 13:546dd29b1c7a 135 External2
j3 13:546dd29b1c7a 136 };
j3 13:546dd29b1c7a 137
j3 10:6efe114ef882 138 ///Command results
j3 7:8669a53acd0d 139 enum CmdResult_e
j3 7:8669a53acd0d 140 {
j3 7:8669a53acd0d 141 ///Failed operation
j3 7:8669a53acd0d 142 OpFailure,
j3 7:8669a53acd0d 143 ///Successful operation
j3 7:8669a53acd0d 144 Success
j3 7:8669a53acd0d 145 };
j3 7:8669a53acd0d 146
j3 13:546dd29b1c7a 147 MAX113XX_Pixi(Device_e device, PinName cnvt=NC);
j3 7:8669a53acd0d 148
j3 12:8054ee101bad 149 ///@brief Read single ended ADC configured port
j3 12:8054ee101bad 150 ///@param[in] port - single ended ADC configured port
j3 12:8054ee101bad 151 ///@param[out] data - contents of ADC data register
j3 12:8054ee101bad 152 ///@return Result of operation
j3 12:8054ee101bad 153 CmdResult_e singleEndedADCRead(Ports_e port, uint16_t &data);
j3 12:8054ee101bad 154
j3 12:8054ee101bad 155 ///@brief Read differential ADC configured port
j3 12:8054ee101bad 156 ///@param[in] posPort - positive port
j3 13:546dd29b1c7a 157 ///@param[out] data - contents of positive port ADC data register
j3 12:8054ee101bad 158 ///@return Result of operation
j3 13:546dd29b1c7a 159 CmdResult_e differentialADCRead(Ports_e posPort, int16_t &data);
j3 12:8054ee101bad 160
j3 12:8054ee101bad 161 ///@brief Write DAC configured port
j3 12:8054ee101bad 162 ///@param[in] port - DAC configured port
j3 12:8054ee101bad 163 ///@param[in] data - value to be written to DAC data register
j3 12:8054ee101bad 164 ///@return Result of operation
j3 12:8054ee101bad 165 CmdResult_e dacWrite(Ports_e port, const uint16_t data);
j3 7:8669a53acd0d 166
j3 13:546dd29b1c7a 167 ///@brief Write DAC configured port and read ADC for port
j3 13:546dd29b1c7a 168 ///@param[in] port - DAC w/ADC Monitor configured port
j3 13:546dd29b1c7a 169 ///@param[in] data - value to be written to DAC data register
j3 13:546dd29b1c7a 170 ///@param[out] adcData - value read from adc
j3 13:546dd29b1c7a 171 ///@return Result of operation
j3 13:546dd29b1c7a 172 CmdResult_e dacWriteADCMonitor(Ports_e port, const uint16_t data,
j3 13:546dd29b1c7a 173 uint16_t &adcData);
j3 13:546dd29b1c7a 174
j3 7:8669a53acd0d 175 ///@brief Reads gpi configured port
j3 7:8669a53acd0d 176 ///@param[in] port - gpi congigured port to be read
j3 7:8669a53acd0d 177 ///@param[out] state - lsb of state matches port state
j3 7:8669a53acd0d 178 ///@return Result of operation
j3 9:094df3de3616 179 CmdResult_e gpioRead(Ports_e port, uint8_t &state);
j3 7:8669a53acd0d 180
j3 12:8054ee101bad 181 ///@brief Writes gpo configured port with lsb of state
j3 12:8054ee101bad 182 ///@param[in] port - gpo congigured port to be written
j3 12:8054ee101bad 183 ///@param[in] state - lsb of state is written to port
j3 12:8054ee101bad 184 ///@return Result of operation
j3 12:8054ee101bad 185 CmdResult_e gpioWrite(Ports_e port, const uint8_t state);
j3 7:8669a53acd0d 186
j3 12:8054ee101bad 187 ///@brief Sets the state of a software controlled analog switch
j3 13:546dd29b1c7a 188 ///@param[in] lowPort - Port with lowest index
j3 13:546dd29b1c7a 189 ///@param[in] state - True for closed, false for hi-z
j3 12:8054ee101bad 190 ///@return Result of operation
j3 13:546dd29b1c7a 191 CmdResult_e setAnalogSwitchState(Ports_e lowPort, bool state);
j3 13:546dd29b1c7a 192
j3 13:546dd29b1c7a 193 ///@brief Reads temperature sensor
j3 13:546dd29b1c7a 194 ///@param[in] sensor - internal, or external sensor one or two
j3 13:546dd29b1c7a 195 ///@return Result of operation
j3 13:546dd29b1c7a 196 CmdResult_e readTempSensor(TempSensor_e sensor, float &data);
j3 7:8669a53acd0d 197
j3 10:6efe114ef882 198 ///@brief Dumps pixi memory to provided Serial object
j3 10:6efe114ef882 199 ///@param[in] ser - output device
j3 10:6efe114ef882 200 ///@return None
j3 12:8054ee101bad 201 void dumpMemory(Serial &ser);
j3 7:8669a53acd0d 202
j3 7:8669a53acd0d 203 protected:
j3 7:8669a53acd0d 204
j3 9:094df3de3616 205 Device_e m_device;
j3 7:8669a53acd0d 206 DigitalOut m_cnvt;
j3 7:8669a53acd0d 207
j3 7:8669a53acd0d 208 ///@brief Writes given register with data
j3 7:8669a53acd0d 209 ///@param[in] reg - register to be written
j3 7:8669a53acd0d 210 ///@param[in] data - data to write
j3 7:8669a53acd0d 211 ///@return none
j3 9:094df3de3616 212 virtual void writeRegister(uint8_t reg, const uint16_t data) = 0;
j3 7:8669a53acd0d 213
j3 7:8669a53acd0d 214 ///@brief Reads given register
j3 7:8669a53acd0d 215 ///@param[in] reg - register to read
j3 7:8669a53acd0d 216 ///@return contents of register
j3 9:094df3de3616 217 virtual uint16_t readRegister(uint8_t reg) = 0;
j3 7:8669a53acd0d 218
j3 7:8669a53acd0d 219 ///@brief Writes a block of data starting at given register
j3 7:8669a53acd0d 220 ///@param[in] reg - register to start writing at
j3 7:8669a53acd0d 221 ///@param[in] data - pointer to data buffer
j3 7:8669a53acd0d 222 ///@param[in] num_reg - number of registers to be written
j3 7:8669a53acd0d 223 ///@return none
j3 9:094df3de3616 224 virtual void blockWrite(uint8_t reg, const uint16_t *data,
j3 9:094df3de3616 225 const uint8_t num_reg) = 0;
j3 7:8669a53acd0d 226
j3 7:8669a53acd0d 227 ///@brief Reads a block of data starting at given register
j3 7:8669a53acd0d 228 ///@param[in] reg - register to start reading at
j3 7:8669a53acd0d 229 ///@param[in] data - pointer to data buffer
j3 7:8669a53acd0d 230 ///@param[in] num_reg - number of registers to be read
j3 7:8669a53acd0d 231 ///@return none
j3 9:094df3de3616 232 virtual void blockRead(uint8_t reg, uint16_t *data,
j3 9:094df3de3616 233 const uint8_t num_reg) = 0;
j3 7:8669a53acd0d 234 };
j3 7:8669a53acd0d 235
j3 7:8669a53acd0d 236
j3 7:8669a53acd0d 237 /**
j3 7:8669a53acd0d 238 @brief SPI Declaration for MAX113XX parts
j3 7:8669a53acd0d 239 */
j3 7:8669a53acd0d 240 class MAX113XX_SPI: public MAX113XX_Pixi
j3 7:8669a53acd0d 241 {
j3 7:8669a53acd0d 242
j3 7:8669a53acd0d 243 public:
j3 7:8669a53acd0d 244
j3 7:8669a53acd0d 245 ///@brief MAX113XX_SPI Constructor
j3 7:8669a53acd0d 246 ///@param[in] spiBus - reference to SPI bus for this device
j3 7:8669a53acd0d 247 ///@param[in] cs - pin to be used for chip select
j3 10:6efe114ef882 248 ///@param[in] device - pixi device; MAX11300, MAX11301,...
j3 7:8669a53acd0d 249 ///@param[in] cnvrt - pin to be used for convert
j3 9:094df3de3616 250 MAX113XX_SPI(SPI & spiBus, PinName cs, MAX113XX_Pixi::Device_e device,
j3 13:546dd29b1c7a 251 PinName cnvt=NC);
j3 7:8669a53acd0d 252
j3 7:8669a53acd0d 253 ///@brief MAX113XX_SPI Destructor
j3 7:8669a53acd0d 254 ~MAX113XX_SPI();
j3 7:8669a53acd0d 255
j3 7:8669a53acd0d 256 private:
j3 7:8669a53acd0d 257
j3 7:8669a53acd0d 258 SPI & m_spiBus;
j3 7:8669a53acd0d 259 DigitalOut m_cs;
j3 7:8669a53acd0d 260
j3 9:094df3de3616 261 virtual void writeRegister(uint8_t reg, const uint16_t data);
j3 7:8669a53acd0d 262
j3 9:094df3de3616 263 virtual uint16_t readRegister(uint8_t reg);
j3 7:8669a53acd0d 264
j3 9:094df3de3616 265 virtual void blockWrite(uint8_t reg, const uint16_t *data,
j3 7:8669a53acd0d 266 const uint8_t num_reg);
j3 7:8669a53acd0d 267
j3 9:094df3de3616 268 virtual void blockRead(uint8_t reg, uint16_t *data, const uint8_t num_reg);
j3 7:8669a53acd0d 269 };
j3 7:8669a53acd0d 270
j3 7:8669a53acd0d 271
j3 7:8669a53acd0d 272 /**
j3 7:8669a53acd0d 273 @brief I2C Declaration for MAX113XX parts
j3 7:8669a53acd0d 274 */
j3 7:8669a53acd0d 275 class MAX113XX_I2C: public MAX113XX_Pixi
j3 7:8669a53acd0d 276 {
j3 7:8669a53acd0d 277
j3 7:8669a53acd0d 278 public:
j3 7:8669a53acd0d 279
j3 7:8669a53acd0d 280 ///@brief MAX113XX_I2C Constructor
j3 7:8669a53acd0d 281 ///@param[in] i2cBus - reference to I2C bus for this device
j3 10:6efe114ef882 282 ///@param[in] device - pixi device; MAX11300, MAX11301,...
j3 7:8669a53acd0d 283 ///@param[in] cnvrt - pin to be used for convert
j3 13:546dd29b1c7a 284 MAX113XX_I2C(I2C &i2cBus, MAX113XX_Pixi::Device_e device, PinName cnvt=NC);
j3 7:8669a53acd0d 285
j3 7:8669a53acd0d 286 ///@brief MAX113XX_I2C Destructor
j3 7:8669a53acd0d 287 ~MAX113XX_I2C();
j3 7:8669a53acd0d 288
j3 7:8669a53acd0d 289 private:
j3 7:8669a53acd0d 290
j3 7:8669a53acd0d 291 I2C &m_i2cBus;
j3 7:8669a53acd0d 292
j3 9:094df3de3616 293 virtual void writeRegister(uint8_t reg, const uint16_t data);
j3 7:8669a53acd0d 294
j3 9:094df3de3616 295 virtual uint16_t readRegister(uint8_t reg);
j3 7:8669a53acd0d 296
j3 9:094df3de3616 297 virtual void blockWrite(uint8_t reg, const uint16_t *data,
j3 7:8669a53acd0d 298 const uint8_t num_reg);
j3 7:8669a53acd0d 299
j3 9:094df3de3616 300 virtual void blockRead(uint8_t reg, uint16_t *data, const uint8_t num_reg);
j3 7:8669a53acd0d 301 };
j3 7:8669a53acd0d 302
j3 7:8669a53acd0d 303
j3 7:8669a53acd0d 304 #endif /* _MAX113XX_PIXI_H_ */