| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
#ifndef __AD717X_H__ |
| 44 |
#define __AD717X_H__ |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
#include <stdint.h> |
| 50 |
|
| 51 |
typedef enum ad717x_crc_mode ad717x_crc_mode; |
| 52 |
|
| 53 |
enum ad717x_crc_mode |
| 54 |
{ |
| 55 |
AD717X_DISABLE, |
| 56 |
AD717X_USE_CRC, |
| 57 |
AD717X_USE_XOR, |
| 58 |
}; |
| 59 |
|
| 60 |
|
| 61 |
typedef struct _ad717x_st_reg |
| 62 |
{ |
| 63 |
int32_t addr; |
| 64 |
int32_t value; |
| 65 |
int32_t size; |
| 66 |
}ad717x_st_reg; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
struct ad717x_device { |
| 77 |
uint8_t slave_select_id; |
| 78 |
ad717x_st_reg *regs; |
| 79 |
uint8_t num_regs; |
| 80 |
ad717x_crc_mode useCRC; |
| 81 |
}; |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
#define AD717X_COMM_REG 0x00 |
| 89 |
#define AD717X_STATUS_REG 0x00 |
| 90 |
#define AD717X_ADCMODE_REG 0x01 |
| 91 |
#define AD717X_IFMODE_REG 0x02 |
| 92 |
#define AD717X_REGCHECK_REG 0x03 |
| 93 |
#define AD717X_DATA_REG 0x04 |
| 94 |
#define AD717X_GPIOCON_REG 0x06 |
| 95 |
#define AD717X_ID_REG 0x07 |
| 96 |
#define AD717X_CHMAP0_REG 0x10 |
| 97 |
#define AD717X_CHMAP1_REG 0x11 |
| 98 |
#define AD717X_CHMAP2_REG 0x12 |
| 99 |
#define AD717X_CHMAP3_REG 0x13 |
| 100 |
#define AD717X_CHMAP4_REG 0x14 |
| 101 |
#define AD717X_CHMAP5_REG 0x15 |
| 102 |
#define AD717X_CHMAP6_REG 0x16 |
| 103 |
#define AD717X_CHMAP7_REG 0x17 |
| 104 |
#define AD717X_CHMAP8_REG 0x18 |
| 105 |
#define AD717X_CHMAP9_REG 0x19 |
| 106 |
#define AD717X_CHMAP10_REG 0x1A |
| 107 |
#define AD717X_CHMAP11_REG 0x1B |
| 108 |
#define AD717X_CHMAP12_REG 0x1C |
| 109 |
#define AD717X_CHMAP13_REG 0x1D |
| 110 |
#define AD717X_CHMAP14_REG 0x1E |
| 111 |
#define AD717X_CHMAP15_REG 0x1F |
| 112 |
#define AD717X_SETUPCON0_REG 0x20 |
| 113 |
#define AD717X_SETUPCON1_REG 0x21 |
| 114 |
#define AD717X_SETUPCON2_REG 0x22 |
| 115 |
#define AD717X_SETUPCON3_REG 0x23 |
| 116 |
#define AD717X_SETUPCON4_REG 0x24 |
| 117 |
#define AD717X_SETUPCON5_REG 0x25 |
| 118 |
#define AD717X_SETUPCON6_REG 0x26 |
| 119 |
#define AD717X_SETUPCON7_REG 0x27 |
| 120 |
#define AD717X_FILTCON0_REG 0x28 |
| 121 |
#define AD717X_FILTCON1_REG 0x29 |
| 122 |
#define AD717X_FILTCON2_REG 0x2A |
| 123 |
#define AD717X_FILTCON3_REG 0x2B |
| 124 |
#define AD717X_FILTCON4_REG 0x2C |
| 125 |
#define AD717X_FILTCON5_REG 0x2D |
| 126 |
#define AD717X_FILTCON6_REG 0x2E |
| 127 |
#define AD717X_FILTCON7_REG 0x2F |
| 128 |
#define AD717X_OFFSET0_REG 0x30 |
| 129 |
#define AD717X_OFFSET1_REG 0x31 |
| 130 |
#define AD717X_OFFSET2_REG 0x32 |
| 131 |
#define AD717X_OFFSET3_REG 0x33 |
| 132 |
#define AD717X_OFFSET4_REG 0x34 |
| 133 |
#define AD717X_OFFSET5_REG 0x35 |
| 134 |
#define AD717X_OFFSET6_REG 0x36 |
| 135 |
#define AD717X_OFFSET7_REG 0x37 |
| 136 |
#define AD717X_GAIN0_REG 0x38 |
| 137 |
#define AD717X_GAIN1_REG 0x39 |
| 138 |
#define AD717X_GAIN2_REG 0x3A |
| 139 |
#define AD717X_GAIN3_REG 0x3B |
| 140 |
#define AD717X_GAIN4_REG 0x3C |
| 141 |
#define AD717X_GAIN5_REG 0x3D |
| 142 |
#define AD717X_GAIN6_REG 0x3E |
| 143 |
#define AD717X_GAIN7_REG 0x3F |
| 144 |
|
| 145 |
|
| 146 |
#define AD717X_COMM_REG_WEN (0 << 7) |
| 147 |
#define AD717X_COMM_REG_WR (0 << 6) |
| 148 |
#define AD717X_COMM_REG_RD (1 << 6) |
| 149 |
#define AD717X_COMM_REG_RA(x) ((x) & 0x3F) |
| 150 |
|
| 151 |
|
| 152 |
#define AD717X_STATUS_REG_RDY (1 << 7) |
| 153 |
#define AD717X_STATUS_REG_ADC_ERR (1 << 6) |
| 154 |
#define AD717X_STATUS_REG_CRC_ERR (1 << 5) |
| 155 |
#define AD717X_STATUS_REG_REG_ERR (1 << 4) |
| 156 |
#define AD717X_STATUS_REG_CH(x) ((x) & 0x03) |
| 157 |
|
| 158 |
|
| 159 |
#define AD717X_ADCMODE_REG_REF_EN (1 << 15) |
| 160 |
#define AD717X_ADCMODE_SING_CYC (1 << 13) |
| 161 |
#define AD717X_ADCMODE_REG_DELAY(x) (((x) & 0x7) << 8) |
| 162 |
#define AD717X_ADCMODE_REG_MODE(x) (((x) & 0x7) << 4) |
| 163 |
#define AD717X_ADCMODE_REG_CLKSEL(x)) (((x) & 0x3) << 2) |
| 164 |
|
| 165 |
|
| 166 |
#define AD717X_ADCMODE_REG_HIDE_DELAY (1 << 14) |
| 167 |
|
| 168 |
|
| 169 |
#define AD717X_IFMODE_REG_ALT_SYNC (1 << 12) |
| 170 |
#define AD717X_IFMODE_REG_IOSTRENGTH (1 << 11) |
| 171 |
#define AD717X_IFMODE_REG_HIDE_DELAY (1 << 10) |
| 172 |
#define AD717X_IFMODE_REG_DOUT_RESET (1 << 8) |
| 173 |
#define AD717X_IFMODE_REG_CONT_READ (1 << 7) |
| 174 |
#define AD717X_IFMODE_REG_DATA_STAT (1 << 6) |
| 175 |
#define AD717X_IFMODE_REG_REG_CHECK (1 << 5) |
| 176 |
#define AD717X_IFMODE_REG_XOR_EN (0x01 << 2) |
| 177 |
#define AD717X_IFMODE_REG_CRC_EN (0x02 << 2) |
| 178 |
#define AD717X_IFMODE_REG_XOR_STAT(x) (((x) & AD717X_IFMODE_REG_XOR_EN) == AD717X_IFMODE_REG_XOR_EN) |
| 179 |
#define AD717X_IFMODE_REG_CRC_STAT(x) (((x) & AD717X_IFMODE_REG_CRC_EN) == AD717X_IFMODE_REG_CRC_EN) |
| 180 |
#define AD717X_IFMODE_REG_DATA_WL16 (1 << 0) |
| 181 |
|
| 182 |
|
| 183 |
#define AD717X_GPIOCON_REG_MUX_IO (1 << 12) |
| 184 |
#define AD717X_GPIOCON_REG_SYNC_EN (1 << 11) |
| 185 |
#define AD717X_GPIOCON_REG_ERR_EN(x) (((x) & 0x3) << 9) |
| 186 |
#define AD717X_GPIOCON_REG_ERR_DAT (1 << 8) |
| 187 |
#define AD717X_GPIOCON_REG_IP_EN1 (1 << 5) |
| 188 |
#define AD717X_GPIOCON_REG_IP_EN0 (1 << 4) |
| 189 |
#define AD717X_GPIOCON_REG_OP_EN1 (1 << 3) |
| 190 |
#define AD717X_GPIOCON_REG_OP_EN0 (1 << 2) |
| 191 |
#define AD717X_GPIOCON_REG_DATA1 (1 << 1) |
| 192 |
#define AD717X_GPIOCON_REG_DATA0 (1 << 0) |
| 193 |
|
| 194 |
|
| 195 |
#define AD717X_GPIOCON_REG_GP_DATA3 (1 << 7) |
| 196 |
#define AD717X_GPIOCON_REG_GP_DATA2 (1 << 6) |
| 197 |
#define AD717X_GPIOCON_REG_GP_DATA1 (1 << 1) |
| 198 |
#define AD717X_GPIOCON_REG_GP_DATA0 (1 << 0) |
| 199 |
|
| 200 |
|
| 201 |
#define AD717X_GPIOCON_REG_PDSW (1 << 14) |
| 202 |
#define AD717X_GPIOCON_REG_OP_EN2_3 (1 << 13) |
| 203 |
|
| 204 |
|
| 205 |
#define AD717X_CHMAP_REG_CH_EN (1 << 15) |
| 206 |
#define AD717X_CHMAP_REG_SETUP_SEL(x) (((x) & 0x3) << 12) |
| 207 |
#define AD717X_CHMAP_REG_AINPOS(x) (((x) & 0x1F) << 5) |
| 208 |
#define AD717X_CHMAP_REG_AINNEG(x) (((x) & 0x1F) << 0) |
| 209 |
|
| 210 |
|
| 211 |
#define AD717X_SETUP_CONF_REG_BI_UNIPOLAR (1 << 12) |
| 212 |
#define AD717X_SETUP_CONF_REG_REF_SEL(x) (((x) & 0x3) << 4) |
| 213 |
|
| 214 |
|
| 215 |
#define AD717X_SETUP_CONF_REG_REF_BUF(x) (((x) & 0x3) << 10) |
| 216 |
#define AD717X_SETUP_CONF_REG_AIN_BUF(x) (((x) & 0x3) << 8) |
| 217 |
#define AD717X_SETUP_CONF_REG_BURNOUT_EN (1 << 7) |
| 218 |
#define AD717X_SETUP_CONF_REG_BUFCHOPMAX (1 << 6) |
| 219 |
|
| 220 |
|
| 221 |
#define AD717X_SETUP_CONF_REG_REFBUF_P (1 << 11) |
| 222 |
#define AD717X_SETUP_CONF_REG_REFBUF_N (1 << 10) |
| 223 |
#define AD717X_SETUP_CONF_REG_AINBUF_P (1 << 9) |
| 224 |
#define AD717X_SETUP_CONF_REG_AINBUF_N (1 << 8) |
| 225 |
|
| 226 |
|
| 227 |
#define AD717X_FILT_CONF_REG_SINC3_MAP (1 << 15) |
| 228 |
#define AD717X_FILT_CONF_REG_ENHFILTEN (1 << 11) |
| 229 |
#define AD717X_FILT_CONF_REG_ENHFILT(x) (((x) & 0x7) << 8) |
| 230 |
#define AD717X_FILT_CONF_REG_ORDER(x) (((x) & 0x3) << 5) |
| 231 |
#define AD717X_FILT_CONF_REG_ODR(x) (((x) & 0x1F) << 0) |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
#define AD717X_CRC8_POLYNOMIAL_REPRESENTATION 0x07 |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
ad717x_st_reg *AD717X_GetReg(struct ad717x_device *device, uint8_t reg_address); |
| 244 |
|
| 245 |
|
| 246 |
int32_t AD717X_ReadRegister(struct ad717x_device *device, uint8_t addr); |
| 247 |
|
| 248 |
|
| 249 |
int32_t AD717X_WriteRegister(struct ad717x_device *device, uint8_t); |
| 250 |
|
| 251 |
|
| 252 |
int32_t AD717X_Reset(struct ad717x_device *device); |
| 253 |
|
| 254 |
|
| 255 |
int32_t AD717X_WaitForReady(struct ad717x_device *device, uint32_t timeout); |
| 256 |
|
| 257 |
|
| 258 |
int32_t AD717X_ReadData(struct ad717x_device *device, int32_t* pData); |
| 259 |
|
| 260 |
|
| 261 |
uint8_t AD717X_ComputeCRC8(uint8_t* pBuf, uint8_t bufSize); |
| 262 |
|
| 263 |
|
| 264 |
uint8_t AD717X_ComputeXOR8(uint8_t * pBuf, uint8_t bufSize); |
| 265 |
|
| 266 |
|
| 267 |
int32_t AD717X_UpdateCRCSetting(struct ad717x_device *device); |
| 268 |
|
| 269 |
|
| 270 |
int32_t AD717X_Setup(struct ad717x_device *device, uint8_t slave_select, |
| 271 |
ad717x_st_reg *regs, uint8_t num_regs); |
| 272 |
|
| 273 |
#endif |