From 763abb0fccfbea45466a415cb7c6ccccc86d2664 Mon Sep 17 00:00:00 2001 From: jhchun Date: Fri, 26 Jun 2026 17:40:05 +0900 Subject: [PATCH] =?UTF-8?q?Piezo=20=EC=B8=A1=EC=A0=95=20=ED=8C=8C=EB=9D=BC?= =?UTF-8?q?=EB=AF=B8=ED=84=B0=20=EA=B3=B5=EC=9A=A9=20=ED=97=A4=EB=8D=94=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EC=B5=9C=EB=8C=80=20=EC=83=98?= =?UTF-8?q?=ED=94=8C=20=EC=88=98=20118=EA=B0=9C=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - reb: 패킷에 채널 정보 2바이트가 추가되어 단일 패킷 최대 샘플 수를 119개에서 118개로 조정 --- .../command/handlers/cmd_piezo.c | 37 ++++++++++--------- .../ble_app_bladder_patch/hal/fds/fstorage.c | 11 +++--- .../measurement/adc121s051/dr_adc121s051.h | 5 ++- .../measurement/piezo/dr_piezo.h | 7 ++-- .../measurement/piezo/piezo_config.h | 29 +++++++++++++++ 5 files changed, 61 insertions(+), 28 deletions(-) create mode 100644 project/ble_peripheral/ble_app_bladder_patch/measurement/piezo/piezo_config.h diff --git a/project/ble_peripheral/ble_app_bladder_patch/command/handlers/cmd_piezo.c b/project/ble_peripheral/ble_app_bladder_patch/command/handlers/cmd_piezo.c index 6c1511e..6dfd45f 100644 --- a/project/ble_peripheral/ble_app_bladder_patch/command/handlers/cmd_piezo.c +++ b/project/ble_peripheral/ble_app_bladder_patch/command/handlers/cmd_piezo.c @@ -17,6 +17,7 @@ #include "dr_piezo.h" #include "dr_adc121s051.h" #include "led_control.h" +#include "../../measurement/piezo/piezo_config.h" static void mtb_send_rim_after_piezo(void) { @@ -64,48 +65,48 @@ static uint8_t clamp_piezo_freq_option(uint16_t raw_freq) static uint8_t clamp_piezo_cycles(uint16_t cycles) { - if (cycles < 3) + if (cycles < PIEZO_CONFIG_CYCLES_MIN) { - return 3; + return (uint8_t)PIEZO_CONFIG_CYCLES_MIN; } - if (cycles > 7) + if (cycles > PIEZO_CONFIG_CYCLES_MAX) { - return 7; + return (uint8_t)PIEZO_CONFIG_CYCLES_MAX; } return (uint8_t)cycles; } static uint16_t clamp_piezo_averaging(uint16_t averaging) { - if (averaging < 1) + if (averaging < PIEZO_CONFIG_AVERAGING_MIN) { - return 1; + return PIEZO_CONFIG_AVERAGING_MIN; } - if (averaging > 10) + if (averaging > PIEZO_CONFIG_AVERAGING_MAX) { - return 10; + return PIEZO_CONFIG_AVERAGING_MAX; } return averaging; } static uint16_t clamp_piezo_delay_us(uint16_t delay_us) { - if (delay_us > 50) + if (delay_us > PIEZO_CONFIG_DELAY_US_MAX) { - return 50; + return PIEZO_CONFIG_DELAY_US_MAX; } return delay_us; } static uint16_t clamp_piezo_num_samples(uint16_t num_samples) { - if (num_samples < 80) + if (num_samples < PIEZO_CONFIG_NUM_SAMPLES_MIN) { - return 80; + return PIEZO_CONFIG_NUM_SAMPLES_MIN; } - if (num_samples > 119) + if (num_samples > PIEZO_CONFIG_NUM_SAMPLES_MAX) { - return 119; + return PIEZO_CONFIG_NUM_SAMPLES_MAX; } return num_samples; } @@ -164,8 +165,8 @@ int Cmd_mpb(const ParsedCmd *cmd) *============================================================================*/ int Cmd_mpc(const ParsedCmd *cmd) { - uint16_t cycles = 5; - uint16_t freq_option = 1; + uint16_t cycles = DR_PIEZO_DEFAULT_CYCLES; + uint16_t freq_option = PIEZO_CONFIG_FREQ_OPTION_DEFAULT; uint16_t piezo_ch = 0; (void)dr_get_u16(cmd, 0, &cycles); @@ -177,7 +178,7 @@ int Cmd_mpc(const ParsedCmd *cmd) piezo_ch = 0; } - if (cycles < 3 || cycles > 7) + if (cycles < PIEZO_CONFIG_CYCLES_MIN || cycles > PIEZO_CONFIG_CYCLES_MAX) { dr_ble_return_1("rpc:", 2); return 1; @@ -224,7 +225,7 @@ int Cmd_mec(const ParsedCmd *cmd) uint16_t freq_option = 0; uint16_t delay_us = 20; uint16_t num_samples = 140; - uint16_t cycles = 5; + uint16_t cycles = DR_PIEZO_DEFAULT_CYCLES; uint16_t averaging = 1; uint16_t piezo_ch = 0; diff --git a/project/ble_peripheral/ble_app_bladder_patch/hal/fds/fstorage.c b/project/ble_peripheral/ble_app_bladder_patch/hal/fds/fstorage.c index 9eff739..a565654 100644 --- a/project/ble_peripheral/ble_app_bladder_patch/hal/fds/fstorage.c +++ b/project/ble_peripheral/ble_app_bladder_patch/hal/fds/fstorage.c @@ -40,6 +40,7 @@ #include "nrf_pwr_mgmt.h" #include "main.h" #include "debug_print.h" +#include "../../measurement/piezo/piezo_config.h" /* FDS record identifiers */ @@ -107,11 +108,11 @@ void fds_default_value_set(void) m_config.life_cycle = 0; /* Piezo measurement parameter defaults */ - m_config.piezo_freq_option = 1; /* 2.1 MHz */ - m_config.piezo_delay_us = 10; /* 10 us after burst */ - m_config.piezo_num_samples = 100; /* 100 samples */ - m_config.piezo_cycles = 3; /* 7 cycles */ - m_config.piezo_averaging = 3; /* 3x averaging */ + m_config.piezo_freq_option = PIEZO_CONFIG_FREQ_OPTION_DEFAULT; /* 2.1 MHz */ + m_config.piezo_delay_us = PIEZO_CONFIG_DELAY_US_DEFAULT; /* 10 us after burst */ + m_config.piezo_num_samples = PIEZO_CONFIG_NUM_SAMPLES_DEFAULT; /* 100 samples */ + m_config.piezo_cycles = PIEZO_CONFIG_CYCLES_DEFAULT; /* 3 cycles */ + m_config.piezo_averaging = PIEZO_CONFIG_AVERAGING_DEFAULT; /* 3x averaging */ /* Factory provisioning — default: not provisioned */ m_config.factory_provisioned = 0; diff --git a/project/ble_peripheral/ble_app_bladder_patch/measurement/adc121s051/dr_adc121s051.h b/project/ble_peripheral/ble_app_bladder_patch/measurement/adc121s051/dr_adc121s051.h index dddfe80..fe6f7ad 100644 --- a/project/ble_peripheral/ble_app_bladder_patch/measurement/adc121s051/dr_adc121s051.h +++ b/project/ble_peripheral/ble_app_bladder_patch/measurement/adc121s051/dr_adc121s051.h @@ -30,6 +30,7 @@ #include #include #include "nrf_gpio.h" +#include "../piezo/piezo_config.h" /*============================================================================== * PIN CONFIGURATION @@ -73,8 +74,8 @@ *============================================================================*/ #define DR_ADC_SCLK_MHZ 8.6f /**< SPI bit-bang SCLK frequency */ #define DR_ADC_CLOCKS_PER_SAMPLE 16 /**< ADC121S051: 16 SCLK per sample */ -#define DR_ADC_ECHO_SAMPLES_MAX 119 /**< Maximum samples */ -#define DR_ADC_ECHO_SAMPLES_DEFAULT 100 /**< Default samples */ +#define DR_ADC_ECHO_SAMPLES_MAX PIEZO_CONFIG_NUM_SAMPLES_MAX /**< Maximum samples */ +#define DR_ADC_ECHO_SAMPLES_DEFAULT PIEZO_CONFIG_NUM_SAMPLES_DEFAULT /**< Default samples */ #define DR_ADC_SAMPLE_INTERVAL_US 1.86f /**< 16 / 8.6MHz = 1.86us per sample */ #define DR_ADC_SOUND_SPEED_MM_US 1.54f /**< Sound speed in tissue (mm/us) */ diff --git a/project/ble_peripheral/ble_app_bladder_patch/measurement/piezo/dr_piezo.h b/project/ble_peripheral/ble_app_bladder_patch/measurement/piezo/dr_piezo.h index 97503db..9e77f20 100644 --- a/project/ble_peripheral/ble_app_bladder_patch/measurement/piezo/dr_piezo.h +++ b/project/ble_peripheral/ble_app_bladder_patch/measurement/piezo/dr_piezo.h @@ -32,6 +32,7 @@ #include #include #include "nrf_gpio.h" +#include "piezo_config.h" /*============================================================================== * Power control pin (+/-20V DC/DC converter) @@ -64,9 +65,9 @@ * Configuration *============================================================================*/ #define DR_PIEZO_FREQ_HZ 2100000 /**< Target frequency (set PIEZO_FREQ_MHZ in .c) */ -#define DR_PIEZO_DEFAULT_CYCLES 5 /**< Default burst cycles */ -#define DR_PIEZO_MIN_CYCLES 3 -#define DR_PIEZO_MAX_CYCLES 7 +#define DR_PIEZO_DEFAULT_CYCLES PIEZO_CONFIG_CYCLES_DEFAULT /**< Default burst cycles */ +#define DR_PIEZO_MIN_CYCLES PIEZO_CONFIG_CYCLES_MIN +#define DR_PIEZO_MAX_CYCLES PIEZO_CONFIG_CYCLES_MAX #define DR_PIEZO_MUX_SETTLING_US 1300 /**< MUX settling delay (us) */ /*============================================================================== diff --git a/project/ble_peripheral/ble_app_bladder_patch/measurement/piezo/piezo_config.h b/project/ble_peripheral/ble_app_bladder_patch/measurement/piezo/piezo_config.h new file mode 100644 index 0000000..7046a9e --- /dev/null +++ b/project/ble_peripheral/ble_app_bladder_patch/measurement/piezo/piezo_config.h @@ -0,0 +1,29 @@ +/*============================================================================== + * piezo_config.h - Shared piezo measurement parameter limits/defaults + *============================================================================*/ +#ifndef PIEZO_CONFIG_H +#define PIEZO_CONFIG_H + +/* Frequency option protocol: + * 0=1.8MHz, 1=2.1MHz, 2=2.0MHz, 3=1.7MHz, 4=2.2MHz, 9=1.9MHz + */ +#define PIEZO_CONFIG_FREQ_OPTION_DEFAULT 1U + +#define PIEZO_CONFIG_CYCLES_MIN 3U +#define PIEZO_CONFIG_CYCLES_MAX 7U +#define PIEZO_CONFIG_CYCLES_DEFAULT 7U + +#define PIEZO_CONFIG_AVERAGING_MIN 1U +#define PIEZO_CONFIG_AVERAGING_MAX 10U +#define PIEZO_CONFIG_AVERAGING_DEFAULT 10U + +#define PIEZO_CONFIG_DELAY_US_MIN 0U +#define PIEZO_CONFIG_DELAY_US_MAX 50U +#define PIEZO_CONFIG_DELAY_US_DEFAULT 10U + +#define PIEZO_CONFIG_NUM_SAMPLES_MIN 80U +#define PIEZO_CONFIG_NUM_SAMPLES_MAX 118U +#define PIEZO_CONFIG_NUM_SAMPLES_DEFAULT 100U + + +#endif /* PIEZO_CONFIG_H */