Feature/add optional accelerometer readout#43
Open
Sebi1128 wants to merge 2 commits into
Open
Conversation
This change keeps backward-compatible streaming behavior for ultrasound data while making accelerometer streaming optional. Tested the following cases: 1. accelerometer requested - firmware starts correctly - ultrasound data streams correctly - accelerometer data is appended to outgoing frames 2. accelerometer not requested - firmware starts correctly - ultrasound data streams correctly - accelerometer remains off 3. repeated configuration updates - switching between enabled and disabled modes works correctly
There was a problem hiding this comment.
Pull request overview
Integrates optional IIS2DH accelerometer readout/streaming into the nRF52 acquisition firmware, with BLE-side configuration parsing to enable/disable streaming at runtime for backward compatibility with older GUIs.
Changes:
- Added an IIS2DH (I2C/TWI) driver module and frame post-processing to inject (or zero-fill) accelerometer bytes into the outgoing data stream.
- Added BLE config-packet parsing to request accelerometer streaming and a deferred apply mechanism in
main.c. - Adjusted SPI “frame complete” handling to defer frame finalization until after ACC/non-ACC post-processing.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 16 comments.
Show a summary per file
| File | Description |
|---|---|
| fw/nrf52/ble_peripheral/US_probe_nRF52_firmware/us_spi.c | Switches from finalizing frames in the SPI completion ISR to signaling “ready for IMU post-processing”. |
| fw/nrf52/ble_peripheral/US_probe_nRF52_firmware/us_ble.c | Parses incoming config packets to request accel streaming and forwards commands to the MSP430. |
| fw/nrf52/ble_peripheral/US_probe_nRF52_firmware/main.c | Applies accel enable/disable requests and triggers IMU insertion / non-IMU finalization in the main loop. |
| fw/nrf52/ble_peripheral/US_probe_nRF52_firmware/iis2dh.c | New IIS2DH driver + frame finalization/IMU insertion logic. |
| fw/nrf52/ble_peripheral/US_probe_nRF52_firmware/iis2dh.h | New IIS2DH public API, register definitions, and configuration types. |
| fw/nrf52/ble_peripheral/US_probe_nRF52_firmware/pca10040/s132/ses/US_probe_nRF52_firmware.emProject | Adds IIS2DH sources and TWI/TWIM-related sources to the SES project. |
| fw/nrf52/ble_peripheral/US_probe_nRF52_firmware/CHANGELOG.md | Adds a 1.2.3 entry describing the new optional accelerometer streaming feature. |
| CHANGELOG.md | Adds a top-level 1.2.3 entry mentioning optional nRF52 accelerometer streaming. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
172
to
+180
| if(buffer_content>MAX_BUFFER_NUMBER_OF_US_FRAMES-1) | ||
| { | ||
| // Buffer overflow error handling | ||
| //APP_ERROR_CHECK(1); | ||
| } | ||
|
|
||
| buffer_counter++; | ||
| if(buffer_counter == MAX_BUFFER_NUMBER_OF_US_FRAMES) | ||
| buffer_counter = 0; | ||
|
|
||
| BLE_packet_ready = 1; | ||
| // Buffer ready to add IMU data | ||
| flag_add_IMU = true; | ||
|
|
Comment on lines
200
to
206
| timers_init(); | ||
| power_management_init(); | ||
| us_ble_init(); | ||
| gpio_init(); | ||
| us_spi_init(); | ||
| IIS2DH_init(); | ||
|
|
Comment on lines
+217
to
+225
| // Only decode config packets: start byte 0xFA, transFreq at bytes 5..8 | ||
| if ((len >= 9) && (rx[0] == 0xFA)) | ||
| { | ||
| uint32_t transFreq = read_u32_le(&rx[5]); | ||
|
|
||
| // If transFreq contains code 101, enable accelerometer | ||
| accel_stream_requested = (transFreq == 101u); | ||
| accel_stream_update_pending = true; | ||
| } |
Comment on lines
+227
to
229
| // Forward packet unchanged to MSP430 | ||
| memcpy(m_tx_buf_1, rx, len); | ||
| msp_conf_received = true; |
Comment on lines
+37
to
+40
| #define IIS2DH_REG_INT_COUNTER_REG | ||
| #define IIS2DH_REG_TEMP_CFG_REG 0x1F | ||
| #define IIS2DH_REG_REFERENCE | ||
| #define IIS2DH_REG_STATUS_REG |
Comment on lines
+282
to
+286
| // Zero out the 6 bytes that would normally carry accel data | ||
| uint8_t *dst = &m_rx_buf[3 + buffer_counter * NUMBER_OF_XFERS].buffer[0] + 202 - 6; | ||
| dst[0] = 0; | ||
| dst[1] = 0; | ||
| dst[2] = 0; |
| @@ -5,7 +5,21 @@ All notable changes to this project will be documented in this file. | |||
| The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | |||
| and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | |||
|
|
|||
Comment on lines
+82
to
+90
| //Set the flag to false to show the receiving is not yet completed | ||
| IIS2DH_xfer_done = false; | ||
|
|
||
| // Send the register address where we want to read the data from | ||
| err_code = nrf_drv_twi_tx(&IIS2DH_twi, IIS2DH_ADDRESS, ®ister_address, 1, true); | ||
|
|
||
| //Wait for the transmission to be completed | ||
| while (IIS2DH_xfer_done == false){} | ||
|
|
Comment on lines
+127
to
+132
| // Send the register address where we want to read the data from | ||
| err_code = nrf_drv_twi_tx(&IIS2DH_twi, IIS2DH_ADDRESS, wxbuffer_with_address, number_of_bytes+1, true); | ||
|
|
||
| //Wait for the transmission to be completed | ||
| while (IIS2DH_xfer_done == false){} | ||
|
|
| bool setupTemp(); | ||
| int8_t getTemp(); | ||
|
|
||
| bool setupAccelormeter(IIS2DH_OperatingModes mode, IIS2DH_DataRate rate, IIS2DH_FullScale fs); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Integrate the readout of the accelerometer in the WULPUS firmware (nRF52). The accelerometer is only enabled upon request to keep backward compatibility with older GUIs.