diff --git a/project/ble_peripheral/ble_app_bladder_patch/command/cmd_common.h b/project/ble_peripheral/ble_app_bladder_patch/command/cmd_common.h index 85cc211..6846489 100644 --- a/project/ble_peripheral/ble_app_bladder_patch/command/cmd_common.h +++ b/project/ble_peripheral/ble_app_bladder_patch/command/cmd_common.h @@ -50,6 +50,8 @@ extern int imu_read_direct(void); extern int imu_read_temperature_x100(uint16_t *temp_x100, float *temp_c); extern int imu_fifo_capture_start(void); extern int imu_fifo_capture_stop_and_send_rim(void); +extern int imu_fifo_capture_wait_samples_and_send_rim(uint16_t target_samples, uint32_t timeout_ms); +extern void imu_fifo_capture_disable(void); extern void battery_timer_stop(void); extern void main_timer_start(void); extern void hw_i2c_init_once(void); diff --git a/project/ble_peripheral/ble_app_bladder_patch/command/cmd_table.c b/project/ble_peripheral/ble_app_bladder_patch/command/cmd_table.c index ee856e1..f2db2e5 100644 --- a/project/ble_peripheral/ble_app_bladder_patch/command/cmd_table.c +++ b/project/ble_peripheral/ble_app_bladder_patch/command/cmd_table.c @@ -41,6 +41,7 @@ static const CmdEntry m_cmd_table[] = { { "msn?", true, Cmd_msn }, { "mst?", true, Cmd_mst }, { "msp?", true, Cmd_msp }, + { "mim?", true, Cmd_mim }, /* D. Piezo ultrasound */ { "mpa?", true, Cmd_mpa }, diff --git a/project/ble_peripheral/ble_app_bladder_patch/command/handlers/cmd_sensor.c b/project/ble_peripheral/ble_app_bladder_patch/command/handlers/cmd_sensor.c index 84379ae..c1677ee 100644 --- a/project/ble_peripheral/ble_app_bladder_patch/command/handlers/cmd_sensor.c +++ b/project/ble_peripheral/ble_app_bladder_patch/command/handlers/cmd_sensor.c @@ -4,6 +4,7 @@ * msn? -> rsn: battery ADC measurement * mst? -> rso: IMU die temperature reading * msp? -> rsp: IMU 6-axis single read + * mim? -> rim: IMU FIFO 15-sample read * all_sensors() bulk-measurement helper used by the mbb? handler *============================================================================*/ @@ -47,6 +48,7 @@ int Cmd_mst(const ParsedCmd *cmd) /*============================================================================== * msp? -> rsp: IMU 6-axis single read + * mim? -> rim: IMU FIFO 15-sample read * * Request: [TAG 4B "msp?"] [CRC 2B] * Response: rsp: + accel(xyz) + gyro(xyz) (transmitted inside imu_read_direct) @@ -61,6 +63,33 @@ int Cmd_msp(const ParsedCmd *cmd) return 1; } +/*============================================================================== + * mim? -> rim: IMU FIFO-only capture + * + * Request: [TAG 4B "mim?"] [CRC 2B] + * Response: rim: [total_sample_count u16 BE] + * [samples: 12B each ax,ay,az,gx,gy,gz ...] + * + * Uses the same FIFO/rim path as mtb? but without piezo reb:/raa: packets. + * At 50 Hz, 15 samples are about 300 ms; timeout leaves margin for startup. + *============================================================================*/ +int Cmd_mim(const ParsedCmd *cmd) +{ + int rc; + (void)cmd; + + rc = imu_fifo_capture_start(); + if (rc != 0) + { + (void)imu_fifo_capture_stop_and_send_rim(); + imu_fifo_capture_disable(); + return 1; + } + + (void)imu_fifo_capture_wait_samples_and_send_rim(15, 500); + return 1; +} + /*============================================================================== * all_sensors() - Bulk-measurement helper for the mbb? handler * diff --git a/project/ble_peripheral/ble_app_bladder_patch/command/handlers/cmd_sensor.h b/project/ble_peripheral/ble_app_bladder_patch/command/handlers/cmd_sensor.h index 0118eee..0b01b73 100644 --- a/project/ble_peripheral/ble_app_bladder_patch/command/handlers/cmd_sensor.h +++ b/project/ble_peripheral/ble_app_bladder_patch/command/handlers/cmd_sensor.h @@ -9,6 +9,7 @@ int Cmd_msn(const ParsedCmd *cmd); /* msn? -> rsn: battery ADC measurement */ int Cmd_mst(const ParsedCmd *cmd); /* mst? -> rso: IMU die temperature */ int Cmd_msp(const ParsedCmd *cmd); /* msp? -> rsp: IMU 6-axis single read */ +int Cmd_mim(const ParsedCmd *cmd); /* mim? -> rim: IMU FIFO 15 samples */ /* Helper for the mbb? handler: sequentially measures battery / IMU / temperature, then emits a single rbb: response. * Called from Cmd_mbb() in cmd_piezo.c. */ void all_sensors(void); diff --git a/project/ble_peripheral/ble_app_bladder_patch/main.h b/project/ble_peripheral/ble_app_bladder_patch/main.h index 7be5a8f..e404304 100644 --- a/project/ble_peripheral/ble_app_bladder_patch/main.h +++ b/project/ble_peripheral/ble_app_bladder_patch/main.h @@ -51,6 +51,7 @@ * - VBTFW0119 260615 jhChun * : Replaced all TMP235 temperature paths with IMU register direct-read temperature and removed legacy TMP235 build references. * : Unify both IMU direct-read and FIFO outputs as raw data in datasheet axis convention. +* : Added mim? command (rim:, IMU FIFO-only 15 samples at 50 Hz). * - VBTFW0120 260615 jhChun : Add EMC mitigation logic for BLE link stability: extended supervision timeout and dynamic TX power control based on RSSI, RSSI silence, HVN latency, and TX queue congestion. ------------------------------------------------------------------------- */ #define FIRMWARE_VERSION "VBTFW0120" diff --git a/project/ble_peripheral/ble_app_bladder_patch/measurement/imu/app_raw/app_raw.c b/project/ble_peripheral/ble_app_bladder_patch/measurement/imu/app_raw/app_raw.c index 054e707..c4471c5 100644 --- a/project/ble_peripheral/ble_app_bladder_patch/measurement/imu/app_raw/app_raw.c +++ b/project/ble_peripheral/ble_app_bladder_patch/measurement/imu/app_raw/app_raw.c @@ -986,3 +986,48 @@ int imu_fifo_capture_stop_and_send_rim(void) imu_fifo_send_rim_packets(packet_count); return 0; } + +int imu_fifo_capture_wait_samples_and_send_rim(uint16_t target_samples, uint32_t timeout_ms) +{ + int rc = 0; + uint8_t count_raw[2] = {0}; + uint16_t packet_count = 0; + uint32_t waited_ms = 0; + const uint32_t poll_ms = 10U; + + if (target_samples == 0U) + { + return imu_fifo_capture_stop_and_send_rim(); + } + + if (!s_fifo_capture_active) + { + imu_fifo_send_rim_packets(0); + return -1; + } + + while (waited_ms <= timeout_ms) + { + rc = inv_imu_read_reg(&icm_driver, FIFO_COUNTH, 2, count_raw); + if (rc != 0) + { + DBG_PRINTF("[IMU FIFO] count read fail %d\r\n", rc); + imu_fifo_send_rim_packets(0); + imu_fifo_power_off(); + return rc; + } + + packet_count = (uint16_t)count_raw[0] | ((uint16_t)count_raw[1] << 8); + if (packet_count > target_samples) + { + break; + } + + dr_sd_delay_ms(poll_ms); + waited_ms += poll_ms; + } + + rc = imu_fifo_capture_stop_and_send_rim(); + imu_fifo_capture_disable(); + return rc; +} diff --git a/project/ble_peripheral/ble_app_bladder_patch/measurement/imu/app_raw/app_raw.h b/project/ble_peripheral/ble_app_bladder_patch/measurement/imu/app_raw/app_raw.h index e85fcef..c5c51d2 100644 --- a/project/ble_peripheral/ble_app_bladder_patch/measurement/imu/app_raw/app_raw.h +++ b/project/ble_peripheral/ble_app_bladder_patch/measurement/imu/app_raw/app_raw.h @@ -122,6 +122,13 @@ int imu_fifo_capture_start(void); */ int imu_fifo_capture_stop_and_send_rim(void); +/** + * \brief Wait until at least target_samples FIFO records are available, then drain + * FIFO and send rim: packets. + * \return 0=success, negative=error + */ +int imu_fifo_capture_wait_samples_and_send_rim(uint16_t target_samples, uint32_t timeout_ms); + /** * \brief Stop IMU FIFO capture without sending rim: packets. */