Piezo 측정 파라미터 공용 헤더 추가 및 최대 샘플 수 118개로 변경

- reb: 패킷에 채널 정보 2바이트가 추가되어 단일 패킷 최대 샘플 수를 119개에서 118개로 조정
This commit is contained in:
2026-06-26 17:40:05 +09:00
parent 80d7086d09
commit 763abb0fcc
5 changed files with 61 additions and 28 deletions
@@ -17,6 +17,7 @@
#include "dr_piezo.h" #include "dr_piezo.h"
#include "dr_adc121s051.h" #include "dr_adc121s051.h"
#include "led_control.h" #include "led_control.h"
#include "../../measurement/piezo/piezo_config.h"
static void mtb_send_rim_after_piezo(void) 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) 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; return (uint8_t)cycles;
} }
static uint16_t clamp_piezo_averaging(uint16_t averaging) 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; return averaging;
} }
static uint16_t clamp_piezo_delay_us(uint16_t delay_us) 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; return delay_us;
} }
static uint16_t clamp_piezo_num_samples(uint16_t num_samples) 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; return num_samples;
} }
@@ -164,8 +165,8 @@ int Cmd_mpb(const ParsedCmd *cmd)
*============================================================================*/ *============================================================================*/
int Cmd_mpc(const ParsedCmd *cmd) int Cmd_mpc(const ParsedCmd *cmd)
{ {
uint16_t cycles = 5; uint16_t cycles = DR_PIEZO_DEFAULT_CYCLES;
uint16_t freq_option = 1; uint16_t freq_option = PIEZO_CONFIG_FREQ_OPTION_DEFAULT;
uint16_t piezo_ch = 0; uint16_t piezo_ch = 0;
(void)dr_get_u16(cmd, 0, &cycles); (void)dr_get_u16(cmd, 0, &cycles);
@@ -177,7 +178,7 @@ int Cmd_mpc(const ParsedCmd *cmd)
piezo_ch = 0; 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); dr_ble_return_1("rpc:", 2);
return 1; return 1;
@@ -224,7 +225,7 @@ int Cmd_mec(const ParsedCmd *cmd)
uint16_t freq_option = 0; uint16_t freq_option = 0;
uint16_t delay_us = 20; uint16_t delay_us = 20;
uint16_t num_samples = 140; uint16_t num_samples = 140;
uint16_t cycles = 5; uint16_t cycles = DR_PIEZO_DEFAULT_CYCLES;
uint16_t averaging = 1; uint16_t averaging = 1;
uint16_t piezo_ch = 0; uint16_t piezo_ch = 0;
@@ -40,6 +40,7 @@
#include "nrf_pwr_mgmt.h" #include "nrf_pwr_mgmt.h"
#include "main.h" #include "main.h"
#include "debug_print.h" #include "debug_print.h"
#include "../../measurement/piezo/piezo_config.h"
/* FDS record identifiers */ /* FDS record identifiers */
@@ -107,11 +108,11 @@ void fds_default_value_set(void)
m_config.life_cycle = 0; m_config.life_cycle = 0;
/* Piezo measurement parameter defaults */ /* Piezo measurement parameter defaults */
m_config.piezo_freq_option = 1; /* 2.1 MHz */ m_config.piezo_freq_option = PIEZO_CONFIG_FREQ_OPTION_DEFAULT; /* 2.1 MHz */
m_config.piezo_delay_us = 10; /* 10 us after burst */ m_config.piezo_delay_us = PIEZO_CONFIG_DELAY_US_DEFAULT; /* 10 us after burst */
m_config.piezo_num_samples = 100; /* 100 samples */ m_config.piezo_num_samples = PIEZO_CONFIG_NUM_SAMPLES_DEFAULT; /* 100 samples */
m_config.piezo_cycles = 3; /* 7 cycles */ m_config.piezo_cycles = PIEZO_CONFIG_CYCLES_DEFAULT; /* 3 cycles */
m_config.piezo_averaging = 3; /* 3x averaging */ m_config.piezo_averaging = PIEZO_CONFIG_AVERAGING_DEFAULT; /* 3x averaging */
/* Factory provisioning — default: not provisioned */ /* Factory provisioning — default: not provisioned */
m_config.factory_provisioned = 0; m_config.factory_provisioned = 0;
@@ -30,6 +30,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include "nrf_gpio.h" #include "nrf_gpio.h"
#include "../piezo/piezo_config.h"
/*============================================================================== /*==============================================================================
* PIN CONFIGURATION * PIN CONFIGURATION
@@ -73,8 +74,8 @@
*============================================================================*/ *============================================================================*/
#define DR_ADC_SCLK_MHZ 8.6f /**< SPI bit-bang SCLK frequency */ #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_CLOCKS_PER_SAMPLE 16 /**< ADC121S051: 16 SCLK per sample */
#define DR_ADC_ECHO_SAMPLES_MAX 119 /**< Maximum samples */ #define DR_ADC_ECHO_SAMPLES_MAX PIEZO_CONFIG_NUM_SAMPLES_MAX /**< Maximum samples */
#define DR_ADC_ECHO_SAMPLES_DEFAULT 100 /**< Default 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_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) */ #define DR_ADC_SOUND_SPEED_MM_US 1.54f /**< Sound speed in tissue (mm/us) */
@@ -32,6 +32,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include "nrf_gpio.h" #include "nrf_gpio.h"
#include "piezo_config.h"
/*============================================================================== /*==============================================================================
* Power control pin (+/-20V DC/DC converter) * Power control pin (+/-20V DC/DC converter)
@@ -64,9 +65,9 @@
* Configuration * Configuration
*============================================================================*/ *============================================================================*/
#define DR_PIEZO_FREQ_HZ 2100000 /**< Target frequency (set PIEZO_FREQ_MHZ in .c) */ #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_DEFAULT_CYCLES PIEZO_CONFIG_CYCLES_DEFAULT /**< Default burst cycles */
#define DR_PIEZO_MIN_CYCLES 3 #define DR_PIEZO_MIN_CYCLES PIEZO_CONFIG_CYCLES_MIN
#define DR_PIEZO_MAX_CYCLES 7 #define DR_PIEZO_MAX_CYCLES PIEZO_CONFIG_CYCLES_MAX
#define DR_PIEZO_MUX_SETTLING_US 1300 /**< MUX settling delay (us) */ #define DR_PIEZO_MUX_SETTLING_US 1300 /**< MUX settling delay (us) */
/*============================================================================== /*==============================================================================
@@ -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 */