Library for the MAX11300
Diff: MAX113XX_Pixi.cpp
- Revision:
- 12:8054ee101bad
- Parent:
- 11:31e7ca030b8f
- Child:
- 13:546dd29b1c7a
diff -r 31e7ca030b8f -r 8054ee101bad MAX113XX_Pixi.cpp --- a/MAX113XX_Pixi.cpp Mon May 08 19:24:55 2017 +0000 +++ b/MAX113XX_Pixi.cpp Tue May 09 19:04:38 2017 +0000 @@ -36,6 +36,27 @@ //20 port devices #if defined(_MAX11300_DESIGNVALUE_H_) || defined(_MAX11301_DESIGNVALUE_H_) + +static const uint16_t configDesignVals[18] = { + gpo_data_15_to_0_DESIGNVALUE, + gpo_data_19_to_16_DESIGNVALUE, + 0, //reserved + device_control_DESIGNVALUE, + interrupt_mask_DESIGNVALUE, + gpi_irqmode_7_to_0_DESIGNVALUE, + gpi_irqmode_15_to_8_DESIGNVALUE, + gpi_irqmode_19_to_16_DESIGNVALUE, + 0, //reserved + dac_preset_data_1_DESIGNVALUE, + dac_preset_data_2_DESIGNVALUE, + tmp_mon_cfg_DESIGNVALUE, + tmp_mon_int_hi_thresh_DESIGNVALUE, + tmp_mon_int_lo_thresh_DESIGNVALUE, + tmp_mon_ext1_hi_thresh_DESIGNVALUE, + tmp_mon_ext1_lo_thresh_DESIGNVALUE, + tmp_mon_ext2_hi_thresh_DESIGNVALUE, + tmp_mon_ext2_lo_thresh_DESIGNVALUE}; + static const uint16_t portConfigDesignVals[20] = { port_cfg_00_DESIGNVALUE, port_cfg_01_DESIGNVALUE, @@ -57,23 +78,29 @@ port_cfg_17_DESIGNVALUE, port_cfg_18_DESIGNVALUE, port_cfg_19_DESIGNVALUE}; - -static const uint16_t deviceDesignVals[15] = { - device_control_DESIGNVALUE, - interrupt_mask_DESIGNVALUE, - gpi_irqmode_7_to_0_DESIGNVALUE, - gpi_irqmode_15_to_8_DESIGNVALUE, - gpi_irqmode_19_to_16_DESIGNVALUE, - 0, //reserved - dac_preset_data_1_DESIGNVALUE, - dac_preset_data_2_DESIGNVALUE, - tmp_mon_cfg_DESIGNVALUE, - tmp_mon_int_hi_thresh_DESIGNVALUE, - tmp_mon_int_lo_thresh_DESIGNVALUE, - tmp_mon_ext1_hi_thresh_DESIGNVALUE, - tmp_mon_ext1_lo_thresh_DESIGNVALUE, - tmp_mon_ext2_hi_thresh_DESIGNVALUE, - tmp_mon_ext2_lo_thresh_DESIGNVALUE}; + +static const uint16_t dacDesignVals[20]= { + dac_data_port_00_DESIGNVALUE, + dac_data_port_01_DESIGNVALUE, + dac_data_port_02_DESIGNVALUE, + dac_data_port_03_DESIGNVALUE, + dac_data_port_04_DESIGNVALUE, + dac_data_port_05_DESIGNVALUE, + dac_data_port_06_DESIGNVALUE, + dac_data_port_07_DESIGNVALUE, + dac_data_port_08_DESIGNVALUE, + dac_data_port_09_DESIGNVALUE, + dac_data_port_10_DESIGNVALUE, + dac_data_port_11_DESIGNVALUE, + dac_data_port_12_DESIGNVALUE, + dac_data_port_13_DESIGNVALUE, + dac_data_port_14_DESIGNVALUE, + dac_data_port_15_DESIGNVALUE, + dac_data_port_16_DESIGNVALUE, + dac_data_port_17_DESIGNVALUE, + dac_data_port_18_DESIGNVALUE, + dac_data_port_19_DESIGNVALUE}; + #endif //12 port devices... @@ -100,6 +127,103 @@ { } +//********************************************************************* +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) //20 port device + { + if(((portConfigDesignVals[port] & 0xF000) >> 12) == MAX113XX_Pixi::MODE_7) + { + uint8_t num_samples = ((portConfigDesignVals[port] & port_cfg_00_funcprm_nsamples) >> 5); + num_samples = (1 << num_samples); + + while(num_samples--) + { + m_cnvt = 0; + wait_us(1); + m_cnvt = 1; + wait_us(100); + } + data = readRegister((adc_data_port_00 + port)); + + result = MAX113XX_Pixi::Success; + } + } + else //12 port device + { + } + + return result; +} + +//********************************************************************* +MAX113XX_Pixi::CmdResult_e MAX113XX_Pixi::differentialADCRead(Ports_e posPort, + Ports_e negPort, + uint16_t &data) +{ + MAX113XX_Pixi::CmdResult_e result = MAX113XX_Pixi::OpFailure; + + if(m_device == MAX11300 || m_device == MAX11301) //20 port device + { + } + else //12 port device + { + } + + return result; +} + +//********************************************************************* +MAX113XX_Pixi::CmdResult_e MAX113XX_Pixi::dacWrite(Ports_e port, + const uint16_t data) +{ + MAX113XX_Pixi::CmdResult_e result = MAX113XX_Pixi::OpFailure; + + if(m_device == MAX11300 || m_device == MAX11301) //20 port device + { + if(((portConfigDesignVals[port] & 0xF000) >> 12) == MAX113XX_Pixi::MODE_5) + { + writeRegister((dac_data_port_00 + port) , data); + result = MAX113XX_Pixi::Success; + } + } + else //12 port device + { + } + + return result; +} + +//********************************************************************* +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) //20 port device + { + if(((portConfigDesignVals[port] & 0xF000) >> 12) == MAX113XX_Pixi::MODE_1) + { + if(port < MAX113XX_Pixi::PORT16) + { + state = (readRegister(gpi_data_15_to_0) >> port); + } + else + { + state = (readRegister(gpi_data_19_to_16) >> (port - MAX113XX_Pixi::PORT16)); + } + + result = MAX113XX_Pixi::Success; + } + } + else //12 port device + { + } + + return result; +} //********************************************************************* MAX113XX_Pixi::CmdResult_e MAX113XX_Pixi::gpioWrite(Ports_e port, @@ -154,25 +278,14 @@ } //********************************************************************* -MAX113XX_Pixi::CmdResult_e MAX113XX_Pixi::gpioRead(Ports_e port, uint8_t &state) +MAX113XX_Pixi::CmdResult_e MAX113XX_Pixi::setAnalogSwitchState(Ports_e portA, + Ports_e portB, + bool state) { MAX113XX_Pixi::CmdResult_e result = MAX113XX_Pixi::OpFailure; if(m_device == MAX11300 || m_device == MAX11301) //20 port device { - if(((portConfigDesignVals[port] & 0xF000) >> 12) == MAX113XX_Pixi::MODE_1) - { - if(port < MAX113XX_Pixi::PORT16) - { - state = (readRegister(gpi_data_15_to_0) >> port); - } - else - { - state = (readRegister(gpi_data_19_to_16) >> (port - MAX113XX_Pixi::PORT16)); - } - - result = MAX113XX_Pixi::Success; - } } else //12 port device { @@ -182,66 +295,14 @@ } //********************************************************************* -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) //20 port device - { - if(((portConfigDesignVals[port] & 0xF000) >> 12) == MAX113XX_Pixi::MODE_7) - { - uint8_t num_samples = ((portConfigDesignVals[port] & port_cfg_00_funcprm_nsamples) >> 5); - num_samples = (1 << num_samples); - - while(num_samples--) - { - m_cnvt = 0; - wait_us(1); - m_cnvt = 1; - wait_us(100); - } - data = readRegister((adc_data_port_00 + port)); - - result = MAX113XX_Pixi::Success; - } - } - else //12 port device - { - } - - return result; -} - -//********************************************************************* -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) //20 port device - { - if(((portConfigDesignVals[port] & 0xF000) >> 12) == MAX113XX_Pixi::MODE_5) - { - writeRegister((dac_data_port_00 + port) , data); - result = MAX113XX_Pixi::Success; - } - } - else //12 port device - { - } - - return result; -} - -//********************************************************************* -void MAX113XX_Pixi::dumpPixiMemory(Serial &ser, MAX113XX_Pixi &pixi) +void MAX113XX_Pixi::dumpMemory(Serial &ser) { uint16_t mem[0x74]; - pixi.blockRead(dev_id, mem, 0x74); + blockRead(dev_id, mem, 0x74); for(uint8_t idx = 0; idx < 0x74; idx++) { - ser.printf("Register 0x%2x = 0x%4x\r\n", idx, mem[idx]); + ser.printf("Register 0x%02x = 0x%04x\r\n", idx, mem[idx]); } ser.printf("\r\n"); } @@ -262,8 +323,9 @@ { if((m_device == MAX11300) || (m_device == MAX11301)) //20 port device { - blockWrite(device_control, deviceDesignVals, 15); + blockWrite(gpo_data_15_to_0, configDesignVals, 18); blockWrite(port_cfg_00, portConfigDesignVals, 20); + blockWrite(dac_data_port_00, dacDesignVals, 20); wait(0.1); } else //12 port device @@ -338,8 +400,9 @@ { if((m_device == MAX11300) || (m_device == MAX11301)) //20 port device { - blockWrite(device_control, deviceDesignVals, 15); + blockWrite(gpo_data_15_to_0, configDesignVals, 18); blockWrite(port_cfg_00, portConfigDesignVals, 20); + blockWrite(dac_data_port_00, dacDesignVals, 20); wait(0.1); } else //12 port device