|
|
@ -41,6 +41,9 @@ static adscfg_t m_prvads1cfg[] = // |
|
|
|
{0x25, 0x00}, {0x26, 0x00}, {0x27, 0x08}, {0x28, 0x40}, {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}, |
|
|
|
}; |
|
|
|
|
|
|
|
static adscfg_t m_prvads0cfg_cache[65]; |
|
|
|
static adscfg_t m_prvads1cfg_cache[65]; |
|
|
|
/******************************************************************************* |
|
|
|
* VARIABLE * |
|
|
|
*******************************************************************************/ |
|
|
@ -72,7 +75,7 @@ volatile static bool m_drop_state_triggered = false; |
|
|
|
*******************************************************************************/ |
|
|
|
|
|
|
|
// READY_PIN 中断回调函数 |
|
|
|
static void ads1293_ready_pin_irq(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action); |
|
|
|
//static void ads1293_ready_pin_irq(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action); |
|
|
|
// 缓冲区切换BUFFER |
|
|
|
static void prvf_buffer_switch(void); |
|
|
|
|
|
|
@ -196,6 +199,38 @@ static void ads1293_spi_writereg_and_check(ads1293_t* ads, uint8_t addr, uint8_t |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static void tryloadcfg_from_fatfs(const char* file, adscfg_t* cfg, uint16_t cfgsize, uint16_t* cfg_ret_size) { |
|
|
|
// |
|
|
|
*cfg_ret_size = 0; |
|
|
|
|
|
|
|
static FIL fd; |
|
|
|
FRESULT ff_result = f_open(&fd, (const TCHAR*)file, FA_READ); |
|
|
|
if (ff_result != FR_OK) { |
|
|
|
ZLOGE("open %s failed\n", file); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
char line[128]; |
|
|
|
int niterm = 0; |
|
|
|
f_gets(line, 128, &fd); |
|
|
|
|
|
|
|
while (f_gets(line, 128, &fd)) { |
|
|
|
uint32_t addr; |
|
|
|
uint32_t value; |
|
|
|
sscanf(line, "%x,%x", &addr, &value); |
|
|
|
cfg[niterm].add = addr; |
|
|
|
cfg[niterm].data = value; |
|
|
|
niterm++; |
|
|
|
|
|
|
|
if (niterm >= cfgsize) { |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
*cfg_ret_size = niterm; |
|
|
|
ZLOGI("load %s cfg size:%d\n", file, niterm); |
|
|
|
f_close(&fd); |
|
|
|
} |
|
|
|
|
|
|
|
static void ads1293_init() { |
|
|
|
/******************************************************************************* |
|
|
|
* SPI初始化 * |
|
|
@ -232,11 +267,43 @@ static void ads1293_init() { |
|
|
|
|
|
|
|
ads1293_spi_writereg(&m_ads1293_0, TI_ADS1293_CONFIG_REG, 0); |
|
|
|
|
|
|
|
for (uint16_t i = 0; i < ZARRAY_SIZE(m_prvads0cfg); i++) { |
|
|
|
ads1293_spi_writereg_and_check(&m_ads1293_0, m_prvads0cfg[i].add, m_prvads0cfg[i].data); |
|
|
|
uint16_t cfgsize = 0; |
|
|
|
tryloadcfg_from_fatfs("0.cfg", m_prvads0cfg_cache, ZARRAY_SIZE(m_prvads0cfg_cache), &cfgsize); |
|
|
|
if (cfgsize > 0) { |
|
|
|
ZLOGI("load 0.cfg from fatfs\n"); |
|
|
|
|
|
|
|
if (memcmp(m_prvads0cfg_cache, m_prvads0cfg, sizeof(m_prvads0cfg)) != 0) { |
|
|
|
ZLOGI("0.cfg is different from default\n"); |
|
|
|
} else { |
|
|
|
ZLOGI("0.cfg is same as default\n"); |
|
|
|
} |
|
|
|
|
|
|
|
for (uint16_t i = 0; i < cfgsize; i++) { |
|
|
|
ads1293_spi_writereg_and_check(&m_ads1293_0, m_prvads0cfg_cache[i].add, m_prvads0cfg_cache[i].data); |
|
|
|
} |
|
|
|
} else { |
|
|
|
for (uint16_t i = 0; i < ZARRAY_SIZE(m_prvads0cfg); i++) { |
|
|
|
ads1293_spi_writereg_and_check(&m_ads1293_0, m_prvads0cfg[i].add, m_prvads0cfg[i].data); |
|
|
|
} |
|
|
|
} |
|
|
|
for (uint16_t i = 0; i < ZARRAY_SIZE(m_prvads1cfg); i++) { |
|
|
|
ads1293_spi_writereg_and_check(&m_ads1293_1, m_prvads1cfg[i].add, m_prvads1cfg[i].data); |
|
|
|
|
|
|
|
tryloadcfg_from_fatfs("1.cfg", m_prvads1cfg_cache, ZARRAY_SIZE(m_prvads1cfg_cache), &cfgsize); |
|
|
|
if (cfgsize > 0) { |
|
|
|
ZLOGI("load 1.cfg from fatfs\n"); |
|
|
|
|
|
|
|
if (memcmp(m_prvads1cfg_cache, m_prvads1cfg, sizeof(m_prvads1cfg)) != 0) { |
|
|
|
ZLOGI("1.cfg is different from default\n"); |
|
|
|
} else { |
|
|
|
ZLOGI("1.cfg is same as default\n"); |
|
|
|
} |
|
|
|
|
|
|
|
for (uint16_t i = 0; i < cfgsize; i++) { |
|
|
|
ads1293_spi_writereg_and_check(&m_ads1293_1, m_prvads1cfg_cache[i].add, m_prvads1cfg_cache[i].data); |
|
|
|
} |
|
|
|
} else { |
|
|
|
for (uint16_t i = 0; i < ZARRAY_SIZE(m_prvads1cfg); i++) { |
|
|
|
ads1293_spi_writereg_and_check(&m_ads1293_1, m_prvads1cfg[i].add, m_prvads1cfg[i].data); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -259,7 +326,7 @@ void ads1293_sample_one_frame(); |
|
|
|
void nrfx_timer_event_handler(nrf_timer_event_t event_type, void* p_context) { // |
|
|
|
ads1293_sample_one_frame(); |
|
|
|
} |
|
|
|
static void ads1293_ready_pin_irq(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { ads1293_sample_one_frame(); } |
|
|
|
//static void ads1293_ready_pin_irq(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { ads1293_sample_one_frame(); } |
|
|
|
static void ads1293_sample_one_frame() { |
|
|
|
if (!m_work_flag) { |
|
|
|
return; |
|
|
|