|
|
@ -58,7 +58,7 @@ uint8_t port_spi_transmit_receive(uint8_t tx) { |
|
|
|
} |
|
|
|
|
|
|
|
/* ads129X发送指令 */ |
|
|
|
uint8_t ads129X_send_cmd(uint8_t cmd) { |
|
|
|
uint8_t ads129x_send_cmd(uint8_t cmd) { |
|
|
|
uint8_t rx = 0; |
|
|
|
|
|
|
|
ADS129X_CS_RESET(); /* 选中设备 */ |
|
|
@ -73,7 +73,7 @@ uint8_t ads129X_send_cmd(uint8_t cmd) { |
|
|
|
} |
|
|
|
|
|
|
|
/* ads129X读写寄存器,自动根据指令类型区分读和写操作 */ |
|
|
|
uint8_t ads129X_rw_reg(uint8_t cmd, uint8_t data) { |
|
|
|
uint8_t ads129x_rw_reg(uint8_t cmd, uint8_t data) { |
|
|
|
uint8_t rx = 0; |
|
|
|
|
|
|
|
ADS129X_CS_RESET(); /* 选中设备 */ |
|
|
@ -93,8 +93,8 @@ uint8_t ads129X_rw_reg(uint8_t cmd, uint8_t data) { |
|
|
|
return rx; |
|
|
|
} |
|
|
|
|
|
|
|
uint8_t ads129X_read_reg(uint8_t add) { return ads129X_rw_reg(ADS129X_COMMAND_RREG | add, 0); } |
|
|
|
void ads129X_write_reg(uint8_t add, uint8_t data) { ads129X_rw_reg(ADS129X_COMMAND_WREG | add, data); } |
|
|
|
uint8_t ads129x_read_reg(uint8_t add) { return ads129x_rw_reg(ADS129X_COMMAND_RREG | add, 0); } |
|
|
|
void ads129x_write_reg(uint8_t add, uint8_t data) { ads129x_rw_reg(ADS129X_COMMAND_WREG | add, data); } |
|
|
|
|
|
|
|
/* 从指定寄存器开始读写一定数量的寄存器 */ |
|
|
|
void ads129X_write_multiregs(uint8_t reg, uint8_t* ch, uint8_t size) { |
|
|
@ -138,8 +138,8 @@ void ads129X_read_multiregs(uint8_t reg, uint8_t* ch, uint8_t size) { |
|
|
|
ADS129X_CS_SET(); |
|
|
|
} |
|
|
|
|
|
|
|
static void ads129x_readback_reg(ads129x_regs_t* regcache) { ads129X_read_multiregs(ADS129X_REG_ID, (uint8_t*)regcache, sizeof(ads129x_regs_t)); } |
|
|
|
static void ads129x_dump_reg(ads129x_regs_t* regcache) { |
|
|
|
static void ads129x_readback_regs(ads129x_regs_t* regcache) { ads129X_read_multiregs(ADS129X_REG_ID, (uint8_t*)regcache, sizeof(ads129x_regs_t)); } |
|
|
|
static void ads129x_dump_regs(ads129x_regs_t* regcache) { |
|
|
|
ZLOGI("id : %x", regcache->id); |
|
|
|
ZLOGI("cfg1 : %x", regcache->cfg1); |
|
|
|
ZLOGI("cfg2 : %x", regcache->cfg2); |
|
|
@ -154,7 +154,7 @@ static void ads129x_dump_reg(ads129x_regs_t* regcache) { |
|
|
|
ZLOGI("gpio : %x", regcache->gpio); |
|
|
|
} |
|
|
|
|
|
|
|
static bool ads129x_write_reg(ads129x_regs_t* writeval) { |
|
|
|
static bool ads129x_write_regs(ads129x_regs_t* writeval) { |
|
|
|
static ads129x_regs_t rdbak; |
|
|
|
ads129X_write_multiregs(ADS129X_REG_ID, (uint8_t*)writeval, sizeof(ads129x_regs_t)); |
|
|
|
ads129X_read_multiregs(ADS129X_REG_ID, (uint8_t*)&rdbak, sizeof(ads129x_regs_t)); |
|
|
@ -202,25 +202,36 @@ uint8_t ads129x_init(ads129x_cfg_t* cfg) { |
|
|
|
ADS129X_REST_SET(); |
|
|
|
port_ads129x_delay_ms(100); /* 硬件复位 */ |
|
|
|
|
|
|
|
ads129X_send_cmd(ADS129X_COMMAND_SDATAC); /* 软件复位,并停止连续读状态 */ |
|
|
|
ads129x_send_cmd(ADS129X_COMMAND_SDATAC); /* 软件复位,并停止连续读状态 */ |
|
|
|
port_ads129x_delay_ms(100); |
|
|
|
ads129X_send_cmd(ADS129X_COMMAND_RESET); |
|
|
|
ads129x_send_cmd(ADS129X_COMMAND_RESET); |
|
|
|
port_ads129x_delay_ms(1000); |
|
|
|
ads129X_send_cmd(ADS129X_COMMAND_SDATAC); |
|
|
|
ads129x_send_cmd(ADS129X_COMMAND_SDATAC); |
|
|
|
port_ads129x_delay_ms(100); |
|
|
|
|
|
|
|
static ads129x_regs_t regcache; |
|
|
|
ads129x_readback_regs(®cache); |
|
|
|
ads129x_dump_regs(®cache); |
|
|
|
regcache.cfg1 = 0x02; |
|
|
|
regcache.cfg2 = 0xE0; |
|
|
|
regcache.loff = 0xF0; |
|
|
|
regcache.ch1set = 0x00; |
|
|
|
regcache.ch2set = 0x00; |
|
|
|
regcache.rld_sens = 0x20; |
|
|
|
regcache.loff_sens = 0x03; |
|
|
|
ads129x_write_regs(®cache); |
|
|
|
|
|
|
|
nrf_gpio_pin_set(ads129x_cfg->pwdnpin); |
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#if 0 |
|
|
|
uint8_t ads129x_start_capture(bool test) { |
|
|
|
ads129X_send_cmd(ADS129X_COMMAND_SDATAC); /* 进入停止连续读模式 */ |
|
|
|
port_delay_ms(100); |
|
|
|
ads129x_send_cmd(ADS129X_COMMAND_SDATAC); /* 进入停止连续读模式 */ |
|
|
|
port_delay_ms(10); |
|
|
|
|
|
|
|
static ads129x_regs_t regcache; |
|
|
|
ads129x_readback_reg(®cache); |
|
|
|
ads129x_dump_reg(®cache); |
|
|
|
ads129x_readback_regs(®cache); |
|
|
|
ads129x_dump_regs(®cache); |
|
|
|
|
|
|
|
regcache.cfg1 = 0x02; |
|
|
|
regcache.cfg2 = 0xE0; |
|
|
@ -246,17 +257,25 @@ uint8_t ads129x_start_capture(bool test) { |
|
|
|
regcache.ch2set = ADS129X_SET_BITS(regcache.ch2set, ADS129X_MUXx, ADS129X_CHx_INPUT_TEST); |
|
|
|
} |
|
|
|
|
|
|
|
ads129x_write_reg(®cache); |
|
|
|
ads129x_write_regs(®cache); |
|
|
|
|
|
|
|
port_delay_ms(10); |
|
|
|
ads129X_send_cmd(ADS129X_COMMAND_START); /* 发送开始数据转换(等效于拉高START引脚) */ |
|
|
|
ads129x_send_cmd(ADS129X_COMMAND_START); /* 发送开始数据转换(等效于拉高START引脚) */ |
|
|
|
port_delay_ms(10); |
|
|
|
|
|
|
|
ads129x_read_data_loop(); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
uint8_t ads129x_stop_capture() {} |
|
|
|
uint8_t ads129x_start_capture() { |
|
|
|
ads129x_send_cmd(ADS129X_COMMAND_START); /* 发送开始数据转换(等效于拉高START引脚) */ |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
uint8_t ads129x_stop_capture() { |
|
|
|
ads129x_send_cmd(ADS129X_COMMAND_STOP); /* 发送停止数据转换(等效于拉低START引脚) */ |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
static int32_t i24toi32(uint8_t* p_i32) { |
|
|
|
int32_t rev = 0; |
|
|
@ -301,11 +320,9 @@ void ads129x_read_data(ads129x_capture_data_t* capture_data) { |
|
|
|
|
|
|
|
uint8_t ads129x_get_lead_off_state() { |
|
|
|
// FLIP2,FLIP1,LOFF2N,LOFF2P,LOFF1N,LOFF1P |
|
|
|
uint8_t leadoffstate = ads129X_read_reg(ADS129X_REG_LOFFSTAT); |
|
|
|
uint8_t leadoffstate = ads129x_read_reg(ADS129X_REG_LOFFSTAT); |
|
|
|
return leadoffstate; |
|
|
|
} |
|
|
|
|
|
|
|
uint8_t ads129x_enter_low_power_mode() { return 0; } |
|
|
|
uint8_t ads129x_enter_lead_off_detect_mode() { return 0; } |
|
|
|
|
|
|
|
uint8_t ads129x_data_is_ready() { return ADS129X_DRDY_GET(); } |