Browse Source

update

3lead_uart_test_ok_version
zhaohe 1 year ago
parent
commit
423844cad1
  1. 4
      .vscode/settings.json
  2. 2
      app/app.uvprojx
  3. 4
      app/config/sdk_config.h
  4. 11
      app/src/one_conduction/display_manager.c
  5. 76
      app/src/one_conduction/one_conduction_board.c
  6. 138
      app/src/one_conduction/one_conduction_main.c

4
.vscode/settings.json

@ -85,7 +85,9 @@
"wave_drawer.h": "c",
"sample_data_manager.h": "c",
"zeeprom_fs.h": "c",
"config.h": "c"
"config.h": "c",
"stdarg.h": "c",
"nrf_uarte.h": "c"
},
"files.encoding": "gbk"
}

2
app/app.uvprojx

@ -313,7 +313,7 @@
</ArmAdsMisc>
<Cads>
<interw>1</interw>
<Optim>1</Optim>
<Optim>4</Optim>
<oTime>0</oTime>
<SplitLS>0</SplitLS>
<OneElfS>1</OneElfS>

4
app/config/sdk_config.h

@ -7734,7 +7734,7 @@
// <e> NRF_LOG_BACKEND_RTT_ENABLED - nrf_log_backend_rtt - Log RTT backend
//==========================================================
#ifndef NRF_LOG_BACKEND_RTT_ENABLED
#define NRF_LOG_BACKEND_RTT_ENABLED 1
#define NRF_LOG_BACKEND_RTT_ENABLED 0
#endif
// <o> NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE - Size of buffer for partially processed strings.
// <i> Size of the buffer is a trade-off between RAM usage and processing.
@ -7794,7 +7794,7 @@
// <268435456=> 1000000 baud
#ifndef NRF_LOG_BACKEND_UART_BAUDRATE
#define NRF_LOG_BACKEND_UART_BAUDRATE 30801920
#define NRF_LOG_BACKEND_UART_BAUDRATE 251658240
#endif
// <o> NRF_LOG_BACKEND_UART_TEMP_BUFFER_SIZE - Size of buffer for partially processed strings.

11
app/src/one_conduction/display_manager.c

@ -32,7 +32,6 @@ PageState_t* dsp_mgr_get_state(void) { return NULL; }
int compute_x_pos_by_center(int16_t x, int16_t width) { return x - width / 2; }
int compute_y_pos_by_center(int16_t y, int16_t height) { return y - height / 2; }
#define SCREEN_CENTER_X 64
#define SCREEN_CENTER_Y 32
@ -249,7 +248,7 @@ void dsp_mgr_change_to_sampling(int progress_s, int heartrate) { //
dsp_mgr_change_to_page(kPage_sampling);
}
void samplePage_update_state(int progress_s, int wave_y, int heartrate) { //
void samplePage_update_state(int progress_s, int wave_y, int heartrate, bool update_screen) { //
sample_page_state_t* sps = &m_sample_page_state;
uint8_t xchange, ychange;
@ -273,15 +272,17 @@ void samplePage_update_state(int progress_s, int wave_y, int heartrate) { //
} else {
ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y, &xchange, &ychange, fmt("<>%3d", heartrate), &font_asicc16x8_lib);
}
ssd1306_basic_gram_update();
if (update_screen) ssd1306_basic_gram_update();
}
void samplePage_schedule() {
static int count = 0;
count++;
int capturetime = hwss_has_captured_time_ms();
int wave_y = (int)hwss_read_val();
int heartrate = (int)hwss_read_heart_rate();
// ZLOGI("samplePage_schedule %d %d %d", capturetime, wave_y, heartrate);
samplePage_update_state(capturetime / 1000, wave_y, heartrate);
samplePage_update_state(capturetime / 1000, wave_y, heartrate, count % 3 == 0);
}
//
@ -353,7 +354,7 @@ void dsp_mgr_init(void) {
if (!timer_inited) {
ZERROR_CHECK(app_timer_create(&m_dsp_mgr_schedule_tmr, APP_TIMER_MODE_REPEATED, dsp_mgr_schedule_tmr_cb));
}
ZERROR_CHECK(app_timer_start(m_dsp_mgr_schedule_tmr, APP_TIMER_TICKS(30), NULL));
ZERROR_CHECK(app_timer_start(m_dsp_mgr_schedule_tmr, APP_TIMER_TICKS(10), NULL));
timer_inited = true;
}
void dsp_mgr_uninit(void) {

76
app/src/one_conduction/one_conduction_board.c

@ -53,12 +53,58 @@
/*******************************************************************************
* ADC *
*******************************************************************************/
typedef enum {
ADC_UNSET_CH = 0,
ADC_BATTERY_CH,
ADC_ECG_CH,
} adc_channel_t;
adc_channel_t m_now_adc_channel = ADC_UNSET_CH;
void SingleLeadECG_adc_module_init() {
nrf_drv_saadc_config_t adccfg = NRFX_SAADC_DEFAULT_CONFIG;
adccfg.resolution = NRF_SAADC_RESOLUTION_12BIT; // 4096
ZERROR_CHECK(nrf_drv_saadc_init(&adccfg, NULL));
nrf_saadc_channel_config_t channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(ECG_ADC_PIN);
channel_config.acq_time = NRF_SAADC_ACQTIME_40US;
ZERROR_CHECK(nrfx_saadc_channel_init(ECG_ADC_CHANNEL, &channel_config));
}
void SingleLeadECG_adc_set_ch(adc_channel_t ch) {
if (m_now_adc_channel != ch) {
if (m_now_adc_channel == ADC_ECG_CH) {
nrfx_saadc_channel_uninit(ECG_ADC_CHANNEL);
} else if (m_now_adc_channel == ADC_BATTERY_CH) {
nrfx_saadc_channel_uninit(BATTERY_ADC_CHANNEL);
}
if (ch == ADC_ECG_CH) {
nrf_saadc_channel_config_t channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(ECG_ADC_PIN);
channel_config.acq_time = NRF_SAADC_ACQTIME_40US;
ZERROR_CHECK(nrfx_saadc_channel_init(ECG_ADC_CHANNEL, &channel_config));
} else if (ch == ADC_BATTERY_CH) {
nrf_saadc_channel_config_t channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(BATTERY_ADC_PIN);
channel_config.acq_time = NRF_SAADC_ACQTIME_10US;
ZERROR_CHECK(nrfx_saadc_channel_init(BATTERY_ADC_CHANNEL, &channel_config));
}
}
m_now_adc_channel = ch;
}
int16_t SingleLeadECG_adc_get_val(adc_channel_t ch) {
// SingleLeadECG_adc_set_ch(ch);
if (ch == ADC_ECG_CH) {
return znrf_adc_channel_read_val(ECG_ADC_CHANNEL);
} else if (ch == ADC_BATTERY_CH) {
return znrf_adc_channel_read_val(BATTERY_ADC_CHANNEL);
}
return 0;
}
void SingleLeadECG_adc_module_deinit() {
// SingleLeadECG_adc_set_ch(ADC_UNSET_CH);
nrfx_saadc_channel_uninit(ECG_ADC_CHANNEL);
nrf_drv_saadc_uninit();
}
void SingleLeadECG_adc_module_deinit() { nrf_drv_saadc_uninit(); }
/*******************************************************************************
* *
@ -199,13 +245,9 @@ void SingleLeadECG_led_blue_set_state(bool state) {
* PLOD: 01
*/
void SingleLeadECG_ecg_init() {
nrf_saadc_channel_config_t channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(ECG_ADC_PIN);
channel_config.acq_time = NRF_SAADC_ACQTIME_40US;
ZERROR_CHECK(nrfx_saadc_channel_init(ECG_ADC_CHANNEL, &channel_config));
}
void SingleLeadECG_ecg_init() {}
void SingleLeadECG_ecg_deinit() { nrfx_saadc_channel_uninit(ECG_ADC_CHANNEL); }
void SingleLeadECG_ecg_deinit() {}
void SingleLeadECG_ecg_io_init() {
nrf_gpio_cfg_sense_input(ECG_NLOD_PIN, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_NOSENSE);
@ -214,27 +256,17 @@ void SingleLeadECG_ecg_io_init() {
uint32_t SingleLeadECG_ecg_nlod_get_connected_state() { return nrf_gpio_pin_read(ECG_NLOD_PIN); }
uint32_t SingleLeadECG_ecg_plod_get_connected_state() { return !nrf_gpio_pin_read(ECG_PLOD_PIN); }
int16_t SingleLeadECG_ecg_plod_get_ecg_val() { return znrf_adc_channel_read_val(ECG_ADC_CHANNEL); }
int16_t SingleLeadECG_ecg_plod_get_ecg_val() { return SingleLeadECG_adc_get_val(ADC_ECG_CH); }
/*******************************************************************************
* BATTERY *
*******************************************************************************/
void SingleLeadECG_battery_init() {
nrf_saadc_channel_config_t channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(BATTERY_ADC_PIN);
channel_config.acq_time = NRF_SAADC_ACQTIME_10US;
ZERROR_CHECK(nrfx_saadc_channel_init(BATTERY_ADC_CHANNEL, &channel_config));
}
void SingleLeadECG_battery_deinit() { nrfx_saadc_channel_uninit(BATTERY_ADC_CHANNEL); }
int16_t SingleLeadECG_battery_get_adc_val() {
int16_t val = znrf_adc_channel_read_val(BATTERY_ADC_CHANNEL);
if (val < 0) val = 0;
return val;
}
void SingleLeadECG_battery_init() {}
void SingleLeadECG_battery_deinit() {}
int16_t SingleLeadECG_battery_get_adc_val() { return SingleLeadECG_adc_get_val(ADC_BATTERY_CH); }
int16_t SingleLeadECG_battery_val() { return 50; }
void SingleLeadECG_battery_charge_detect_io_init() { //
void SingleLeadECG_battery_charge_detect_io_init() { //
nrf_gpio_cfg_sense_input(BATTERY_CHARGE_DETECT_PIN, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_NOSENSE);
}
bool SingleLeadECG_battery_charge_get_state() { return nrf_gpio_pin_read(BATTERY_CHARGE_DETECT_PIN) == 0; }

138
app/src/one_conduction/one_conduction_main.c

@ -9,6 +9,7 @@
#include "one_conduction_board.h"
#include "sample_data_manager.h"
#include "znordic.h"
#if 1
typedef enum {
// ´ý»ú
kdevice_state_standby = 0,
@ -165,6 +166,9 @@ static void state_machine_change_to_state(device_state_t state) {
static uint32_t cur_state_haspassed_ms() { return znordic_haspassed_ms(m_change_to_cur_state_tp); }
static bool m_poweronflag;
static void power_on() {
if (m_poweronflag) {
return;
}
SingleLeadECG_adc_module_init();
SingleLeadECG_beep_init();
SingleLeadECG_led_init();
@ -448,12 +452,12 @@ void on_service_init(void) {
zdatachannle_init.data_handler = zdatachannel_data_handler;
ZERROR_CHECK(zdatachannel_init(&m_zhrs, &zdatachannle_init));
}
#if 1
void one_conduction_main() {
APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, 20);
g_nrf_log_tx_pin = 41;
znordic_init(0, 20);
znordic_init();
NRF_LOG_INFO("compile time :%s", __TIME__);
NRF_LOG_INFO("Version :%d", VERSION);
NRF_LOG_INFO("Manufacturer :%s", MANUFACTURER_NAME);
@ -465,6 +469,8 @@ void one_conduction_main() {
};
zble_module_init(&cfg);
hwss_init();
// power_on();
// hwss_start_capture();
#if 1
SingleLeadECG_ecg_io_init();
@ -476,20 +482,130 @@ void one_conduction_main() {
ZERROR_CHECK(app_timer_start(m_plod_state_event_detect_tmr, APP_TIMER_TICKS(30), NULL));
ZERROR_CHECK(app_timer_start(m_charge_event_detect_tmr, APP_TIMER_TICKS(100), NULL));
#endif
znordic_loop();
}
#else
// ZERROR_CHECK();
while (true) {
app_sched_execute();
if (NRF_LOG_PROCESS() == false) {
nrf_pwr_mgmt_run();
}
}
void one_conduction_main() {
APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, 20);
g_nrf_log_tx_pin = 41;
znordic_init();
static zble_module_cfg_t cfg = //
{
.deviceName = BLE_NAME,
.on_service_init = on_service_init,
};
zble_module_init(&cfg);
hwss_init();
NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
NRF_LOG_INTERNAL_FLUSH();
// SingleLeadECG_ecg_init();
// SingleLeadECG_adc_module_init();
SingleLeadECG_beep_init();
SingleLeadECG_led_init();
SingleLeadECG_ecg_init();
SingleLeadECG_battery_init();
// hwss_init();
// sample_data_mgr_init();
// dsp_mgr_init();
// zble_module_start_adv();
hwss_start_capture();
// znordic_loop();
znordic_loop();
}
#endif
// ZERROR_CHECK(app_timer_start(m_state_machine_driver_tmr, APP_TIMER_TICKS(5), NULL));
// zble_module_start_adv();
// dsp_mgr_init();
// dsp_mgr_poweron();
// dsp_mgr_change_to_sampling();
// dsp_mgr_change_to_sampling();
#else
#include <stdarg.h>
#if defined(UART_PRESENT)
#include "nrf_uart.h"
#endif
#if defined(UARTE_PRESENT)
#include "nrf_uarte.h"
#endif
#define UART_TX_BUF_SIZE 256 /**< UART TX buffer size. */
#define UART_RX_BUF_SIZE 256 /**< UART RX buffer size. */
uint32_t err_code;
app_uart_comm_params_t const comm_params = //
{
.rx_pin_no = UART_PIN_DISCONNECTED,
.tx_pin_no = 41,
.rts_pin_no = UART_PIN_DISCONNECTED,
.cts_pin_no = UART_PIN_DISCONNECTED,
.flow_control = APP_UART_FLOW_CONTROL_DISABLED,
.use_parity = false,
.baud_rate = NRF_UARTE_BAUDRATE_921600,
};
void uart_error_handle(app_uart_evt_t* p_event) {}
void uartinit() {
APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_error_handle, APP_IRQ_PRIORITY_LOWEST, err_code);
APP_ERROR_CHECK(err_code);
}
void zchip_log(const char* fmt, ...) {
static char tx[256] = {0};
va_list args;
va_start(args, fmt);
vsprintf(tx, fmt, args);
for (size_t i = 0; i < strlen(tx); i++) {
app_uart_put(tx[i]);
}
va_end(args);
}
static void test_tx_timer_cb(void* p_context) {
static uint32_t data;
data++;
// SingleLeadECG_ecg_nlod_get_connected_state();
// SingleLeadECG_ecg_plod_get_connected_state();
// SingleLeadECG_ecg_plod_get_ecg_val();
// ZLOGI("%d nlod %d plod %d ecg:%d", data, SingleLeadECG_ecg_nlod_get_connected_state(), SingleLeadECG_ecg_plod_get_connected_state(), SingleLeadECG_ecg_plod_get_ecg_val());
// ZLOGI("%d,%d,%d", SingleLeadECG_ecg_nlod_get_connected_state(), SingleLeadECG_ecg_plod_get_connected_state(), SingleLeadECG_ecg_plod_get_ecg_val());
// zchip_log("%d,%d,%d\n", SingleLeadECG_ecg_nlod_get_connected_state(), SingleLeadECG_ecg_plod_get_connected_state(), SingleLeadECG_ecg_plod_get_ecg_val());
ZLOGI("%d,%d,%d", SingleLeadECG_ecg_nlod_get_connected_state(), SingleLeadECG_ecg_plod_get_connected_state(), SingleLeadECG_ecg_plod_get_ecg_val());
// app_uart_put('c');
// app_uart_put('c');
// app_uart_put('c');
// app_uart_put('c');
// app_uart_put('c');
// NRF_LOG_INFO("......");
}
void app_event_process_cb(void* p_event_data, uint16_t event_size) {}
extern uint32_t g_nrf_log_tx_pin;
APP_TIMER_DEF(m_test_tx_timer);
void one_conduction_main() {
g_nrf_log_tx_pin = 41;
APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
znordic_init();
SingleLeadECG_adc_module_init();
hwss_init();
// uartinit();
NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
NRF_LOG_INTERNAL_FLUSH();
SingleLeadECG_ecg_init();
hwss_start_capture();
ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
// ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(5), NULL));
znordic_loop();
}
#endif
Loading…
Cancel
Save