3 changed files with 374 additions and 319 deletions
-
2441.c
-
2app/src/basic/ads1293/ads1293.c
-
447app/src/main.c
@ -0,0 +1,244 @@ |
|||
#if 0 |
|||
|
|||
#define ADS1293_SPI_SCK_PIN (32 + 9) |
|||
#define ADS1293_SPI_MOSI_PIN 15 |
|||
#define ADS1293_SPI_MISO_PIN 20 |
|||
#define ADS1293_SPI_CS0_PIN 3 |
|||
#define ADS1293_SPI_CS1_PIN 29 |
|||
#define ADS1293_READY_PIN 31 |
|||
#define LINE_DET_PIN 10 |
|||
#include "board/ads_cfg.h" |
|||
|
|||
/******************************************************************************* |
|||
* 3µ¼Áª-ADS1293-²âÊÔ * |
|||
*******************************************************************************/ |
|||
APP_TIMER_DEF(m_init_tmr); |
|||
APP_TIMER_DEF(m_report_tmr); |
|||
ZDATACHANNEL_DEF(m_zhrs, 2 /**/, 1 /*client num*/); |
|||
static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(2); /**< SPI instance. */ |
|||
static ads1293_t m_ads1293_0; // U2 |
|||
// static ads1293_t m_ads1293_1; // U3 |
|||
static void zdatachannel_data_handler(zdatachannel_evt_t* p_evt); |
|||
static void on_service_init(void); |
|||
static void zdatachanel_send_log(const char* fmt, ...); |
|||
static void three_lead_ecg_ecg_init(); |
|||
|
|||
uint32_t get_ready_pin_state_get() { return nrf_gpio_pin_read(ADS1293_READY_PIN); } |
|||
|
|||
static void m_report_tmr_cb(void* p_context) { |
|||
static int id = 0; |
|||
id++; |
|||
|
|||
#if 0 |
|||
uint8_t leadoffstate = ads1293_spi_readreg(&m_ads1293_0, TI_ADS1293_ERROR_LOD_REG); |
|||
zdatachanel_send_log("%d%d%d%d_%d%d%d%d\n", // |
|||
leadoffstate >> 7 & 0x1, leadoffstate >> 6 & 0x1, leadoffstate >> 5 & 0x1, leadoffstate >> 4 & 0x1, // |
|||
leadoffstate >> 3 & 0x1, leadoffstate >> 2 & 0x1, leadoffstate >> 1 & 0x1, leadoffstate >> 0 & 0x1); // |
|||
#endif |
|||
|
|||
#if 0 |
|||
uint8_t state = ads1293_spi_readreg(&m_ads1293_0, TI_ADS1293_CONFIG_REG); |
|||
zdatachanel_send_log("ads_%d config:%x\n", m_ads1293_0.id, state); |
|||
#endif |
|||
static bool state = false; |
|||
bool now = get_ready_pin_state_get(); |
|||
if (state != now) { |
|||
state = now; |
|||
zdatachanel_send_log("%d\n", now); |
|||
} |
|||
|
|||
// zdatachanel_send_log("%d\n", id); |
|||
} |
|||
|
|||
static void init_tmr_cb(void* p_context) { |
|||
nrf_gpio_cfg_input(LINE_DET_PIN, NRF_GPIO_PIN_PULLUP); |
|||
three_lead_ecg_ecg_init(); |
|||
ads1293_spi_writereg(&m_ads1293_0, TI_ADS1293_CONFIG_REG, 0x01); |
|||
nrf_delay_ms(1000); |
|||
ZERROR_CHECK(app_timer_start(m_report_tmr, APP_TIMER_TICKS(1), NULL)); |
|||
} |
|||
|
|||
int main() { |
|||
APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20); |
|||
znordic_init(); |
|||
NRF_LOG_INFO("compile time :%s", __TIME__); |
|||
static zble_module_cfg_t cfg = // |
|||
{ |
|||
.deviceName = "ThreeLeadECG", |
|||
.on_service_init = on_service_init, |
|||
}; |
|||
zble_module_init(&cfg); |
|||
zble_module_start_adv(); |
|||
ZERROR_CHECK(app_timer_create(&m_init_tmr, APP_TIMER_MODE_SINGLE_SHOT, init_tmr_cb)); |
|||
ZERROR_CHECK(app_timer_start(m_init_tmr, APP_TIMER_TICKS(3000), NULL)); |
|||
|
|||
ZERROR_CHECK(app_timer_create(&m_report_tmr, APP_TIMER_MODE_REPEATED, m_report_tmr_cb)); |
|||
znordic_loop(); |
|||
} |
|||
|
|||
/******************************************************************************* |
|||
* UTILS * |
|||
*******************************************************************************/ |
|||
|
|||
/******************************************************************************* |
|||
* CODE * |
|||
*******************************************************************************/ |
|||
|
|||
static void ads1293_spi_tx_rx_0(uint8_t* tx, uint8_t* rx, uint8_t len) { |
|||
nrf_gpio_pin_clear(ADS1293_SPI_CS0_PIN); |
|||
nrf_drv_spi_transfer(&spi, tx, len, rx, len); |
|||
nrf_gpio_pin_set(ADS1293_SPI_CS0_PIN); |
|||
} |
|||
static void ads1293_spi_tx_rx_1(uint8_t* tx, uint8_t* rx, uint8_t len) { |
|||
nrf_gpio_pin_clear(ADS1293_SPI_CS1_PIN); |
|||
nrf_drv_spi_transfer(&spi, tx, len, rx, len); |
|||
nrf_gpio_pin_set(ADS1293_SPI_CS1_PIN); |
|||
} |
|||
|
|||
static void ads1293_spi_writereg_and_check(ads1293_t* ads, uint8_t addr, uint8_t data) { |
|||
uint8_t readbak = 0; |
|||
// readonly add |
|||
if (addr == 0x19 || addr == 0x1a || addr == 0x1b || addr == 0x1c || addr == 0x40 || addr == 0x30) { |
|||
return; |
|||
} |
|||
ads1293_spi_writereg_and_readbak(ads, addr, data, &readbak); |
|||
if (readbak != data) { |
|||
zdatachanel_send_log("ads_%d write %x failed,w:%x readbak:%x\n", ads->id, addr, data, readbak); |
|||
} |
|||
} |
|||
|
|||
static adscfg_t prvads0cfg[] = { |
|||
{0x00, 0x00}, // |
|||
{0x01, 0x0a}, // |
|||
{0x02, 0x1a}, // |
|||
{0x03, 0x00}, // |
|||
{0x04, 0x00}, // |
|||
{0x05, 0x00}, // |
|||
{0x06, 0x04}, // |
|||
{0x07, 0x0f}, // |
|||
{0x08, 0xff}, // |
|||
{0x09, 0x00}, // |
|||
{0x0a, 0x07}, // |
|||
{0x0b, 0x00}, // |
|||
{0x0c, 0x04}, // |
|||
{0x0d, 0x00}, // |
|||
{0x0e, 0x00}, // |
|||
{0x0f, 0x00}, // |
|||
{0x10, 0x00}, // |
|||
{0x11, 0x00}, // |
|||
{0x12, 0x04}, // |
|||
{0x13, 0x00}, // |
|||
{0x14, 0x00}, // |
|||
{0x15, 0x00}, // |
|||
{0x16, 0x00}, // |
|||
{0x17, 0x05}, // |
|||
{0x18, 0x00}, // |
|||
{0x19, 0x00}, // |
|||
{0x1a, 0x00}, // |
|||
{0x1b, 0x00}, // |
|||
{0x1c, 0x00}, // |
|||
{0x1d, 0x00}, // |
|||
{0x21, 0x02}, // |
|||
{0x22, 0x02}, // |
|||
{0x23, 0x02}, // |
|||
{0x24, 0x02}, // |
|||
{0x25, 0x00}, // |
|||
{0x26, 0x00}, // |
|||
{0x27, 0x08}, // |
|||
{0x28, 0x00}, // |
|||
{0x29, 0x00}, // |
|||
{0x2a, 0x00}, // |
|||
{0x2b, 0x00}, // |
|||
{0x2c, 0x00}, // |
|||
{0x2d, 0x00}, // |
|||
{0x2e, 0x33}, // |
|||
{0x2f, 0x30}, // |
|||
{0x30, 0x00}, // |
|||
{0x31, 0x00}, // |
|||
{0x32, 0x00}, // |
|||
{0x33, 0x00}, // |
|||
{0x34, 0x00}, // |
|||
{0x35, 0x00}, // |
|||
{0x36, 0x00}, // |
|||
{0x37, 0x00}, // |
|||
{0x38, 0x00}, // |
|||
{0x39, 0x00}, // |
|||
{0x3a, 0x00}, // |
|||
{0x3b, 0x00}, // |
|||
{0x3c, 0x00}, // |
|||
{0x3d, 0x00}, // |
|||
{0x3e, 0x00}, // |
|||
{0x3f, 0x00}, // |
|||
{0x40, 0xff}, // |
|||
{0x50, 0x00}, // |
|||
{0x60, 0x00}, // |
|||
{0x62, 0x00}, // |
|||
}; |
|||
|
|||
void three_lead_ecg_ecg_init() { |
|||
nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG; |
|||
spi_config.ss_pin = NRF_DRV_SPI_PIN_NOT_USED; // NRF_DRV_SPI_PIN_NOT_USED |
|||
spi_config.miso_pin = ADS1293_SPI_MISO_PIN; |
|||
spi_config.mosi_pin = ADS1293_SPI_MOSI_PIN; |
|||
spi_config.sck_pin = ADS1293_SPI_SCK_PIN; |
|||
spi_config.frequency = NRF_DRV_SPI_FREQ_8M; |
|||
spi_config.mode = NRF_DRV_SPI_MODE_3; |
|||
// spi_config.mode = |
|||
ZERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, NULL, NULL)); |
|||
|
|||
znrf_gpio_cfg_output(ADS1293_SPI_CS0_PIN, NRF_GPIO_PIN_NOPULL); |
|||
znrf_gpio_cfg_output(ADS1293_SPI_CS1_PIN, NRF_GPIO_PIN_NOPULL); |
|||
nrf_gpio_cfg_input(ADS1293_READY_PIN, NRF_GPIO_PIN_PULLUP); |
|||
|
|||
nrf_gpio_pin_set(ADS1293_SPI_CS0_PIN); |
|||
nrf_gpio_pin_set(ADS1293_SPI_CS1_PIN); |
|||
|
|||
m_ads1293_0.spi_tx_rx = ads1293_spi_tx_rx_0; |
|||
m_ads1293_0.id = 0; |
|||
// m_ads1293_1.spi_tx_rx = ads1293_spi_tx_rx_1; |
|||
// m_ads1293_1.id = 1; |
|||
|
|||
ads1293_spi_init(&m_ads1293_0, ads1293_spi_tx_rx_0); |
|||
// ads1293_spi_init(&m_ads1293_1, ads1293_spi_tx_rx_1); |
|||
|
|||
uint8_t revid = ads1293_spi_readreg(&m_ads1293_0, TI_ADS1293_REVID_REG); |
|||
zdatachanel_send_log("ads1293_0 revid: %d\n", revid); |
|||
// revid = ads1293_spi_readreg(&m_ads1293_1, TI_ADS1293_REVID_REG); |
|||
// zdatachanel_send_log("ads1293_1 revid: %d\n", revid); |
|||
|
|||
zdatachanel_send_log("reset ads1293_0\n"); |
|||
ads1293_spi_writereg(&m_ads1293_0, TI_ADS1293_CONFIG_REG, 0); |
|||
nrf_delay_ms(1000); |
|||
|
|||
for (uint16_t i = 0; i < ZARRAY_SIZE(prvads0cfg); i++) { |
|||
ads1293_spi_writereg_and_check(&m_ads1293_0, prvads0cfg[i].add, prvads0cfg[i].data); |
|||
zdatachanel_send_log("[%d]ads1293_0 write %x:%x\n", i, prvads0cfg[i].add, prvads0cfg[i].data); |
|||
} |
|||
// for (uint16_t i = 0; i < ZARRAY_SIZE(ads1cfg); i++) { |
|||
// ads1293_spi_writereg_and_check(&m_ads1293_1, ads1cfg[i].add, ads1cfg[i].data); |
|||
// } |
|||
|
|||
// ads1293_spi_writereg(&m_ads1293_1, TI_ADS1293_CONFIG_REG, 0x01); |
|||
} |
|||
|
|||
static void zdatachanel_send_log(const char* fmt, ...) { |
|||
static char tx[256] = {0}; |
|||
static uint16_t len = 0; |
|||
va_list args; |
|||
va_start(args, fmt); |
|||
len = vsprintf(tx, fmt, args); |
|||
int ret; |
|||
do { |
|||
ret = zdatachannel_data_send((uint8_t*)tx, &len); |
|||
} while (ret != 0); |
|||
va_end(args); |
|||
} |
|||
static void zdatachannel_data_handler(zdatachannel_evt_t* p_evt) {} |
|||
static void on_service_init(void) { |
|||
ZLOGI("init zdatachannel service"); |
|||
zdatachannel_init_t zdatachannle_init; |
|||
memset(&zdatachannle_init, 0, sizeof(zdatachannle_init)); |
|||
zdatachannle_init.data_handler = zdatachannel_data_handler; |
|||
ZERROR_CHECK(zdatachannel_init(&m_zhrs, &zdatachannle_init)); |
|||
} |
|||
#endif |
Write
Preview
Loading…
Cancel
Save
Reference in new issue