Library for the MAX11300
Dependents: MAX_IOT_KIT MAX_IOT_KIT
Fork of MAX11300 by
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.
Include the generated MAX113XXHex.h file into your project and update the #include in MAX113XX_Pixi.h.
Diff: MAX113XX_Pixi.cpp
- Revision:
- 9:094df3de3616
- Parent:
- 7:8669a53acd0d
- Child:
- 10:6efe114ef882
--- a/MAX113XX_Pixi.cpp Fri May 05 19:23:16 2017 +0000 +++ b/MAX113XX_Pixi.cpp Sat May 06 00:22:47 2017 +0000 @@ -30,9 +30,13 @@ * ownership rights. **********************************************************************/ + #include "MAX113XX_Pixi.h" -static const uint16_t port_config_design_vals[20] = { + +//20 port devices +#if defined(_MAX11300_DESIGNVALUE_H_) || defined(_MAX11301_DESIGNVALUE_H_) +static const uint16_t portConfigDesignVals[20] = { port_cfg_00_DESIGNVALUE, port_cfg_01_DESIGNVALUE, port_cfg_02_DESIGNVALUE, @@ -53,18 +57,45 @@ port_cfg_17_DESIGNVALUE, port_cfg_18_DESIGNVALUE, port_cfg_19_DESIGNVALUE}; +#endif + +//12 port devices... +#if defined(_MAX11311_DESIGNVALUE_H_) || defined(_MAX11312_DESIGNVALUE_H_) +static const uint16_t portConfigDesignVals[12] = { + port_cfg_p0_DESIGNVALUE, + port_cfg_p1_DESIGNVALUE, + port_cfg_p2_DESIGNVALUE, + port_cfg_p3_DESIGNVALUE, + port_cfg_p4_DESIGNVALUE, + port_cfg_p5_DESIGNVALUE, + port_cfg_p6_DESIGNVALUE, + port_cfg_p7_DESIGNVALUE, + port_cfg_p8_DESIGNVALUE, + port_cfg_p9_DESIGNVALUE, + port_cfg_p10_DESIGNVALUE, + port_cfg_p11_DESIGNVALUE}; +#endif + //************************** Base Class member fxs ***************************** -MAX113XX_Pixi::MAX113XX_Pixi(PinName cnvt): -m_cnvt(cnvt, 1) +MAX113XX_Pixi::MAX113XX_Pixi(Device_e device, PinName cnvt): +m_device(device), m_cnvt(cnvt, 1) { -} +} //********************************************************************* -MAX113XX_Pixi::CmdResult_e MAX113XX_Pixi::gpioWrite(MAX113XX_Ports_e port, - const uint8_t state) +MAX113XX_Pixi::CmdResult_e MAX113XX_Pixi::gpioWrite(Ports_e port, + const uint8_t state) { MAX113XX_Pixi::CmdResult_e result = MAX113XX_Pixi::OpFailure; + + if(m_device == MAX11300 || m_device == MAX11301) + { + } + else //12 port device + { + } + /* uint16_t temp; uint16_t port_mask; @@ -101,15 +132,24 @@ result = MAX113XX_Pixi::Success; } + */ return result; } //********************************************************************* -MAX113XX_Pixi::CmdResult_e MAX113XX_Pixi::gpioRead(MAX113XX_Ports_e port, uint8_t &state) +MAX113XX_Pixi::CmdResult_e MAX113XX_Pixi::gpioRead(Ports_e port, uint8_t &state) { MAX113XX_Pixi::CmdResult_e result = MAX113XX_Pixi::OpFailure; + if(m_device == MAX11300 || m_device == MAX11301) + { + } + else //12 port device + { + } + + /* if(((port_config_design_vals[port] & 0xF000) >> 12) == MAX113XX_Pixi::MODE_1) { if(port < MAX113XX_Pixi::PORT16) @@ -123,15 +163,23 @@ result = MAX113XX_Pixi::Success; } - + */ return result; } //********************************************************************* -MAX113XX_Pixi::CmdResult_e MAX113XX_Pixi::singleEndedADCRead(MAX113XX_Ports_e port, uint16_t &data) +MAX113XX_Pixi::CmdResult_e MAX113XX_Pixi::singleEndedADCRead(Ports_e port, uint16_t &data) { MAX113XX_Pixi::CmdResult_e result = MAX113XX_Pixi::OpFailure; + if(m_device == MAX11300 || m_device == MAX11301) + { + } + else //12 port device + { + } + + /* if(((port_config_design_vals[port] & 0xF000) >> 12) == MAX113XX_Pixi::MODE_7) { uint8_t num_samples = ((port_config_design_vals[port] & port_cfg_00_funcprm_nsamples) >> 5); @@ -139,31 +187,39 @@ while(num_samples--) { - this->m_cnvt = 0; + m_cnvt = 0; wait_us(1); - this->m_cnvt = 1; + m_cnvt = 1; wait_us(100); } data = readRegister(static_cast<MAX11300RegAddress_t>(adc_data_port_00 + port)); result = MAX113XX_Pixi::Success; } - + */ return result; } //********************************************************************* -MAX113XX_Pixi::CmdResult_e MAX113XX_Pixi::singleEndedDACWrite(MAX113XX_Ports_e port, +MAX113XX_Pixi::CmdResult_e MAX113XX_Pixi::singleEndedDACWrite(Ports_e port, const uint16_t data) { MAX113XX_Pixi::CmdResult_e result = MAX113XX_Pixi::OpFailure; + if(m_device == MAX11300 || m_device == MAX11301) + { + } + else //12 port device + { + } + + /* if(((port_config_design_vals[port] & 0xF000) >> 12) == MAX113XX_Pixi::MODE_5) { writeRegister(static_cast<MAX11300RegAddress_t>(dac_data_port_00 + port) , data); result = MAX113XX_Pixi::Success; } - + */ return result; } @@ -181,9 +237,18 @@ } +/// SPI first byte when writing MAX11300/11 +//(7-bit address in bits 0x7E; LSB=0 for write) +#define MAX113XXAddr_SPI_Write(RegAddr) ( (RegAddr << 1) ) + +/// SPI first byte when reading MAX11300/11 +//(7-bit address in bits 0x7E; LSB=1 for read) +#define MAX113XXAddr_SPI_Read(RegAddr) ( (RegAddr << 1) | 1 ) + //*************************** SPI Implementation ****************************** -MAX113XX_SPI::MAX113XX_SPI(SPI & spiBus, PinName cs, PinName cnvt): -MAX113XX_Pixi(cnvt), m_spiBus(spiBus), m_cs(cs, 1) +MAX113XX_SPI::MAX113XX_SPI(SPI & spiBus, PinName cs, +MAX113XX_Pixi::Device_e device, PinName cnvt): +MAX113XX_Pixi(device, cnvt), m_spiBus(spiBus), m_cs(cs, 1) { } @@ -195,22 +260,22 @@ } //********************************************************************* -void MAX113XX_SPI::writeRegister(MAX11300RegAddress_t reg, const uint16_t data) +void MAX113XX_SPI::writeRegister(uint8_t reg, const uint16_t data) { m_cs = 0; - m_spiBus.write(MAX11300Addr_SPI_Write(reg)); + m_spiBus.write(MAX113XXAddr_SPI_Write(reg)); m_spiBus.write(((0xFF00 & data) >> 8)); m_spiBus.write((0x00FF & data)); m_cs = 1; } //********************************************************************* -uint16_t MAX113XX_SPI::readRegister(MAX11300RegAddress_t reg) +uint16_t MAX113XX_SPI::readRegister(uint8_t reg) { uint16_t rtn_val = 0; m_cs = 0; - m_spiBus.write(MAX11300Addr_SPI_Read(reg)); + m_spiBus.write(MAX113XXAddr_SPI_Read(reg)); rtn_val |= (m_spiBus.write(0xFF) << 8); rtn_val |= m_spiBus.write(0xFF); m_cs = 1; @@ -219,29 +284,28 @@ } //********************************************************************* -void MAX113XX_SPI::blockWrite(MAX11300RegAddress_t reg, const uint16_t *data, +void MAX113XX_SPI::blockWrite(uint8_t reg, const uint16_t *data, const uint8_t num_reg) { for(uint8_t idx = 0; idx < num_reg; idx++) { - writeRegister(static_cast<MAX11300RegAddress_t>(reg + idx), data[idx]); + writeRegister((reg + idx), data[idx]); } } //********************************************************************* -void MAX113XX_SPI::blockRead(MAX11300RegAddress_t reg, uint16_t *data, - const uint8_t num_reg) +void MAX113XX_SPI::blockRead(uint8_t reg, uint16_t *data, const uint8_t num_reg) { for(uint8_t idx = 0; idx < num_reg; idx++) { - data[idx] = readRegister(static_cast<MAX11300RegAddress_t>(reg + idx)); + data[idx] = readRegister((reg + idx)); } } //*************************** I2C Implementation ****************************** -MAX113XX_I2C::MAX113XX_I2C(I2C &i2cBus, PinName cnvt): -MAX113XX_Pixi(cnvt), m_i2cBus(i2cBus) +MAX113XX_I2C::MAX113XX_I2C(I2C &i2cBus, MAX113XX_Pixi::Device_e device, PinName cnvt): +MAX113XX_Pixi(device, cnvt), m_i2cBus(i2cBus) { } @@ -253,13 +317,13 @@ } //********************************************************************* -void MAX113XX_I2C::writeRegister(MAX11300RegAddress_t reg, const uint16_t data) +void MAX113XX_I2C::writeRegister(uint8_t reg, const uint16_t data) { } //********************************************************************* -uint16_t MAX113XX_I2C::readRegister(MAX11300RegAddress_t reg) +uint16_t MAX113XX_I2C::readRegister(uint8_t reg) { uint16_t rtn_val = 0; @@ -267,16 +331,14 @@ } //********************************************************************* -void MAX113XX_I2C::blockWrite(MAX11300RegAddress_t reg, const uint16_t *data, +void MAX113XX_I2C::blockWrite(uint8_t reg, const uint16_t *data, const uint8_t num_reg) { } //********************************************************************* -void MAX113XX_I2C::blockRead(MAX11300RegAddress_t reg, uint16_t *data, - const uint8_t num_reg) +void MAX113XX_I2C::blockRead(uint8_t reg, uint16_t *data, const uint8_t num_reg) { } -