Library for the MAX11300

Dependents:   MAX_IOT_KIT MAX_IOT_KIT

Fork of MAX11300 by Maxim Integrated

The MAX11300/01/11/12 are configurable mixed signal integrated circuits. The MAX11300/11 offer a SPI interface while the MAX11301/12 offer an I2C interface. The MAX11300/01 are 20 port devices while the MAX11311/12 are 12 port devices.

This library supports the family of parts by providing member functions that can manipulate the GPIO, ADC, DAC, and analog switches of the device, after it has been configured. For configuration of the device, this library requires a header file that can be generated by the MAX11300/01/11/12 Configuration Software. The configuration software can be found at the following link.

https://www.maximintegrated.com/en/products/analog/data-converters/analog-to-digital-converters/MAX11300.html/tb_tab2

Include the generated MAX113XXHex.h file into your project and update the #include in MAX113XX_Pixi.h.

MAX113XX_Pixi.h

Committer:
j3
Date:
2017-05-05
Revision:
7:8669a53acd0d
Child:
8:4291f7e54863

File content as of revision 7:8669a53acd0d:

/**********************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
**********************************************************************/


#ifndef _MAX113XX_PIXI_H_
#define _MAX113XX_PIXI_H_

#include "mbed.h"
#include "MAX113XX_Pixi_Config.h" 

/**
@brief MAX11300 - PIXI, 20-Port Programmable Mixed-Signal I/O with 
12-Bit ADC, 12-Bit DAC, Analog Switches, and GPIO

The MAX11300 integrates a PIXI™, 12-bit, multichannel, analog-to-digital 
converter (ADC) and a 12-bit, multichannel, buffered digital-to-analog 
converter (DAC) in a single integrated circuit (IC). This device offers 
20 mixed-signal high-voltage, bipolar ports, which are configurable as an 
ADC analog input, a DAC analog output, a general-purpose input port (GPI), 
a general-purpose output port (GPO), or an analog switch terminal. 
One internal and two external temperature sensors track junction and 
environmental temperature, respectively. Adjacent pairs of ports are 
configurable as a logic-level translator for open-drain devices or an 
analog switch.

Use configuration software found at
https://www.maximintegrated.com/en/products/analog/data-converters/analog-to-digital-converters/MAX11300.html/tb_tab2
to generate MAX11300hex.h file
*/
class MAX113XX_Pixi
{
    public:
    
    ///MAX11300 Ports
    enum MAX113XX_Ports_e
    {
        PORT0,
        PORT1,
        PORT2,
        PORT3,
        PORT4,
        PORT5,
        PORT6,
        PORT7,
        PORT8,
        PORT9,
        PORT10,
        PORT11,
        PORT12,
        PORT13,
        PORT14,
        PORT15,
        PORT16,
        PORT17,
        PORT18,
        PORT19
    };
    
    ///MAX11300 Port Modes
    enum MAX113XX_PortModes_e
    {
        ///HIGH_Z
        MODE_0,
        ///Digital input with programmable threshold, GPI 
        MODE_1,
        ///Bidirectional level translator terminal
        MODE_2,
        ///Register-driven digital output with DAC-controlled level, GPO
        MODE_3,
        ///Unidirectional path output with DAC-controlled level, GPO 
        MODE_4,
        ///Analog output for DAC
        MODE_5,
        ///Analog output for DAC with ADC monitoring
        MODE_6,
        ///Positive analog input to single-ended ADC
        MODE_7,
        ///Positive analog input to differential ADC
        MODE_8,
        ///Negative analog input to differential ADC
        MODE_9,
        ///Analog output for DAC and negative analog input to differential ADC
        MODE_10,
        ///Terminal to GPI-controlled analog switch
        MODE_11,
        ///Terminal to register-controlled analog switch
        MODE_12
    };
    
    enum CmdResult_e
    {
        ///Failed operation
        OpFailure, 
        ///Successful operation
        Success 
    };
    
    MAX113XX_Pixi(PinName cnvt);
    
    ///@brief Writes gpo configured port with lsb of state
    ///@param[in] port - gpo congigured port to be written
    ///@param[in] state - lsb of state is written to port
    ///@return Result of operation 
    CmdResult_e gpioWrite(MAX113XX_Ports_e port, const uint8_t state);
    
    ///@brief Reads gpi configured port
    ///@param[in] port - gpi congigured port to be read
    ///@param[out] state - lsb of state matches port state
    ///@return Result of operation 
    CmdResult_e gpioRead(MAX113XX_Ports_e port, uint8_t &state);
    
    ///@brief Read single ended ADC configured port
    ///@param[in] port - single ended ADC configured port
    ///@param[out] data - contents of ADC data register
    ///@return Result of operation
    CmdResult_e singleEndedADCRead(MAX113XX_Ports_e port, uint16_t &data);
    
    ///@brief Write single ended DAC configured port
    ///@param[in] port - single ended DAC configured port
    ///@param[in] data - value to be written to DAC data register
    ///@return Result of operation
    CmdResult_e singleEndedDACWrite(MAX113XX_Ports_e port, 
                                       const uint16_t data);
    
    void dumpPixiMemory(Serial &ser, MAX113XX_Pixi &pixi);

protected:
    
    DigitalOut m_cnvt;
    
    ///@brief Writes given register with data
    ///@param[in] reg - register to be written
    ///@param[in] data - data to write
    ///@return none
    virtual void writeRegister(MAX11300RegAddress_t reg, 
                                const uint16_t data) = 0;
    
    ///@brief Reads given register
    ///@param[in] reg - register to read
    ///@return contents of register
    virtual uint16_t readRegister(MAX11300RegAddress_t reg) = 0;
    
    ///@brief Writes a block of data starting at given register
    ///@param[in] reg - register to start writing at
    ///@param[in] data - pointer to data buffer
    ///@param[in] num_reg - number of registers to be written
    ///@return none
    virtual void blockWrite(MAX11300RegAddress_t reg, const uint16_t *data, 
                             const uint8_t num_reg) = 0;
    
    ///@brief Reads a block of data starting at given register
    ///@param[in] reg - register to start reading at
    ///@param[in] data - pointer to data buffer
    ///@param[in] num_reg - number of registers to be read
    ///@return none
    virtual void blockRead(MAX11300RegAddress_t reg, uint16_t *data, 
                            const uint8_t num_reg) = 0;
};


/**
@brief SPI Declaration for MAX113XX parts
*/
class MAX113XX_SPI: public MAX113XX_Pixi
{

public:

    ///@brief MAX113XX_SPI Constructor
    ///@param[in] spiBus - reference to SPI bus for this device
    ///@param[in] cs - pin to be used for chip select
    ///@param[in] cnvrt - pin to be used for convert
    MAX113XX_SPI(SPI & spiBus, PinName cs, PinName cnvt);
    
    ///@brief MAX113XX_SPI Destructor
    ~MAX113XX_SPI();
    
private:

    SPI & m_spiBus;
    DigitalOut m_cs;
    
    virtual void writeRegister(MAX11300RegAddress_t reg, 
                               const uint16_t data);
    
    virtual uint16_t readRegister(MAX11300RegAddress_t reg);
    
    virtual void blockWrite(MAX11300RegAddress_t reg, const uint16_t *data, 
                            const uint8_t num_reg);
    
    virtual void blockRead(MAX11300RegAddress_t reg, uint16_t *data, 
                           const uint8_t num_reg);
};


/**
@brief I2C Declaration for MAX113XX parts
*/
class MAX113XX_I2C: public MAX113XX_Pixi
{

public:

    ///@brief MAX113XX_I2C Constructor
    ///@param[in] i2cBus - reference to I2C bus for this device
    ///@param[in] cnvrt - pin to be used for convert
    MAX113XX_I2C(I2C &i2cBus, PinName cnvt);
    
    ///@brief MAX113XX_I2C Destructor
    ~MAX113XX_I2C();
    
private:

    I2C &m_i2cBus;
    
    virtual void writeRegister(MAX11300RegAddress_t reg, 
                               const uint16_t data);
    
    virtual uint16_t readRegister(MAX11300RegAddress_t reg);
    
    virtual void blockWrite(MAX11300RegAddress_t reg, const uint16_t *data, 
                            const uint8_t num_reg);
    
    virtual void blockRead(MAX11300RegAddress_t reg, uint16_t *data, 
                           const uint8_t num_reg);
};


#endif /* _MAX113XX_PIXI_H_ */