- FDS 피에조 파라미터 구조체 변경 (pd_adc_cnt/pd_delay_us 삭제, piezo 5개 필드 추가)

- maa/mbb 앱 파라미터 수신 → FDS 저장 기능 추가
- magic_number 변경 (0x20260319), cycles 범위 3~7로 제한

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
jhChun
2026-03-18 18:20:52 +09:00
parent 3ecd81c252
commit aa3c040ae0
6 changed files with 120 additions and 50 deletions

View File

@@ -56,6 +56,7 @@ extern void dr_piezo_power_off(void);
/*==============================================================================
* DEBUG CONFIGURATION
*============================================================================*/
#define DEBUG_ADC
#ifdef DEBUG_ADC
#include "nrf_log.h"
#define ADC_LOG(...) NRF_LOG_INFO(__VA_ARGS__)
@@ -1330,7 +1331,7 @@ static dr_adc_err_t maa_async_capture_channel(uint8_t ch)
if (g_plat.log) g_plat.log("[maa] capturing CH%u\r\n", ch);
return dr_adc_capture_channel_only(
dr_adc_err_t err = dr_adc_capture_channel_only(
g_maa_ctx.freq_option,
g_maa_ctx.delay_us,
g_maa_ctx.num_samples,
@@ -1339,6 +1340,23 @@ static dr_adc_err_t maa_async_capture_channel(uint8_t ch)
ch,
&g_maa_ctx.channels[ch]
);
/* 캡처 성공 시 원시 데이터 덤프 (10진수) */
if (err == DR_ADC_OK && g_plat.log)
{
dr_maa_channel_t *c = &g_maa_ctx.channels[ch];
g_plat.log("[maa] CH%u raw (%u samples):\r\n", ch, c->num_samples);
for (uint16_t i = 0; i < c->num_samples; i++)
{
g_plat.log("%u ", c->samples[i]);
if ((i + 1) % 16 == 0) g_plat.log("\r\n");
}
if (c->num_samples % 16 != 0) g_plat.log("\r\n");
}
return err;
}
/**
@@ -1387,9 +1405,10 @@ static bool maa_async_send_data_packet(void)
{
dr_maa_channel_t *ch = &g_maa_ctx.channels[g_maa_ctx.current_ch];
uint8_t *buf = g_maa_ctx.ble_buffer;
uint16_t total_data_bytes = ch->num_samples * 2;
if (g_maa_ctx.data_offset >= total_data_bytes) {
if (g_maa_ctx.data_offset >= total_data_bytes)
{
return false; /* All data sent */
}
@@ -1405,7 +1424,8 @@ static bool maa_async_send_data_packet(void)
/* Copy sample data */
uint16_t src_sample_idx = g_maa_ctx.data_offset / 2;
uint16_t dst_idx = 6;
for (uint16_t i = 0; i < chunk_size / 2 && src_sample_idx < ch->num_samples; i++, src_sample_idx++) {
for (uint16_t i = 0; i < chunk_size / 2 && src_sample_idx < ch->num_samples; i++, src_sample_idx++)
{
uint16_t sample = ch->samples[src_sample_idx];
buf[dst_idx++] = (uint8_t)(sample & 0xFF);
buf[dst_idx++] = (uint8_t)(sample >> 8);
@@ -1417,8 +1437,7 @@ static bool maa_async_send_data_packet(void)
g_maa_ctx.data_offset += chunk_size;
g_maa_ctx.current_pkt++;
ADC_LOG("maa_async: CH%u red:%u (%u/%u bytes)",
g_maa_ctx.current_ch, pkt_idx, g_maa_ctx.data_offset, total_data_bytes);
ADC_LOG("maa_async: CH%u red:%u (%u/%u bytes)", g_maa_ctx.current_ch, pkt_idx, g_maa_ctx.data_offset, total_data_bytes);
return (g_maa_ctx.data_offset < total_data_bytes);
}
@@ -1450,7 +1469,8 @@ static void maa_async_send_completion(uint16_t status)
ADC_LOG("maa_async: complete, status=0x%04X", status);
/* 완료 콜백 호출 (mbb? 등에서 센서 측정 체인 트리거용) */
if (g_maa_ctx.on_complete_cb) {
if (g_maa_ctx.on_complete_cb)
{
void (*cb)(void) = g_maa_ctx.on_complete_cb;
g_maa_ctx.on_complete_cb = NULL; /* 1회성: 재호출 방지 */
cb();
@@ -1465,7 +1485,8 @@ dr_adc_err_t maa_async_start(uint8_t freq_option, uint16_t delay_us,
uint16_t num_samples, uint8_t cycles,
uint16_t averaging, uint8_t *ble_buffer)
{
if (g_maa_ctx.state != MAA_ASYNC_IDLE) {
if (g_maa_ctx.state != MAA_ASYNC_IDLE)
{
ADC_LOG("maa_async_start: busy");
return DR_ADC_ERR_NOT_INIT; /* Already running */
}
@@ -1492,7 +1513,9 @@ dr_adc_err_t maa_async_start(uint8_t freq_option, uint16_t delay_us,
/* Capture CH0 */
g_maa_ctx.state = MAA_ASYNC_CAPTURING;
dr_adc_err_t err = maa_async_capture_channel(0);
if (err != DR_ADC_OK) {
if (err != DR_ADC_OK)
{
ADC_LOG("maa_async_start: CH0 capture failed (%d)", err);
maa_async_send_completion(0xFFF0);
return err;
@@ -1506,26 +1529,34 @@ dr_adc_err_t maa_async_start(uint8_t freq_option, uint16_t delay_us,
bool maa_async_on_tx_ready(void)
{
if (g_maa_ctx.state == MAA_ASYNC_IDLE) {
if (g_maa_ctx.state == MAA_ASYNC_IDLE)
{
return false;
}
switch (g_maa_ctx.state) {
case MAA_ASYNC_TX_DATA:
/* Send next data packet */
if (!maa_async_send_data_packet()) {
if (!maa_async_send_data_packet())
{
/* Current channel done, move to next */
g_maa_ctx.current_ch++;
if (g_maa_ctx.current_ch >= MAA_NUM_CHANNELS) {
if (g_maa_ctx.current_ch >= MAA_NUM_CHANNELS)
{
/* All channels done */
g_maa_ctx.state = MAA_ASYNC_COMPLETE;
maa_async_send_completion(0x0000);
return false;
} else {
}
else
{
/* Capture next channel */
g_maa_ctx.state = MAA_ASYNC_CAPTURING;
dr_adc_err_t err = maa_async_capture_channel(g_maa_ctx.current_ch);
if (err != DR_ADC_OK) {
if (err != DR_ADC_OK)
{
ADC_LOG("maa_async: CH%u capture failed", g_maa_ctx.current_ch);
maa_async_send_completion(0xFFF0 | g_maa_ctx.current_ch);
return false;