20 #define _LTC2499_RESULT_MASK 0xC0000000
21 #define _LTC2499_RESULT_OVERFLOW 0xC0000000
22 #define _LTC2499_RESULT_UNDERFLOW 0x00000000
26 #define _LTC2499_CH_PREAMBLE 0x80
27 #define _LTC2499_CH_ENABLE 0x20
28 #define _LTC2499_CH_SGL 0x10
29 #define _LTC2499_CH_SIGN 0x08
31 #define _LTC2499_CFG_KEEPPREV 0x00
33 #define _LTC2499_CFG_ENABLE 0x80
34 #define _LTC2499_CFG_TMP 0x40
35 #define _LTC2499_CFG_REJ_5060HZ 0x00
36 #define _LTC2499_CFG_REJ_60HZ 0x20
37 #define _LTC2499_CFG_REJ_50HZ 0x10
38 #define _LTC2499_CFG_SPEED 0x08
47 uint32_t t = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | ( data[3] & 0xC0 );
48 switch (t & _LTC2499_RESULT_MASK)
50 case _LTC2499_RESULT_OVERFLOW:
52 *value = LTC2499_MAX_VALUE;
54 case _LTC2499_RESULT_UNDERFLOW:
56 *value = LTC2499_MIN_VALUE;
60 *value = (int32_t)t << 1;
68 static inline uint32_t flt2bits(LTC2499Filter fltCfg) {
70 case ltc2499Filter50Hz:
return _LTC2499_CFG_REJ_50HZ;
71 case ltc2499Filter60Hz:
return _LTC2499_CFG_REJ_60HZ;
72 case ltc2499Filter50And60Hz:
return _LTC2499_CFG_REJ_5060HZ;
73 default:
return _LTC2499_CFG_REJ_5060HZ;
80 cfg[0] = _LTC2499_CH_PREAMBLE;
81 if (posCh != LTC2499_CH_KEEPPREV)
84 cfg[0] |= _LTC2499_CH_ENABLE | ( diff ? 0 : _LTC2499_CH_SGL);
85 cfg[0] |= ( posCh >> 1 ) | ( posCh & 1 ? _LTC2499_CH_SIGN : 0);
89 cfg[1] = _LTC2499_CFG_ENABLE | (speed2x ? _LTC2499_CFG_SPEED : 0);
90 cfg[1] |= flt2bits(fltCfg);
92 return i2cWrite(dev, addr, cfg,
sizeof(cfg));
95 bool ltc2499CfgTemp(
I2C_Device * dev,
int addr, LTC2499Filter fltCfg)
98 cfg[0] = _LTC2499_CH_PREAMBLE;
99 cfg[1] = _LTC2499_CFG_ENABLE | _LTC2499_CFG_TMP | flt2bits(fltCfg);
101 return i2cWrite(dev, addr, cfg,
sizeof(cfg));
bool i2cWrite(I2C_Device *dev, i2cAddr addr, uint8_t *bytes, int len)
Writes to the I2C device.
bool ltc2499Read(I2C_Device *dev, int addr, int32_t *value, LTC2499Status *result)
Reads the LTC ADC at I2C address 'addr'.
bool ltc2499CfgExt(I2C_Device *dev, int addr, bool diff, uint8_t posCh, LTC2499Filter fltCfg, bool speed2x)
Configure LTC2499 with external input.
Structure defines OpenCores I2C Device.
Driver of the LTC2499 ADC as found on the power board.
bool i2cRead(I2C_Device *dev, i2cAddr addr, uint8_t *bytes, int len)
Reads from the I2C device.
static bool errRebase(const char *name)
Rebases the cause of the error message.
LTC2499Status
The status enum, indicating any issues with the value (underflow/overflow).