Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNS - I2C ToF #26

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open

SNS - I2C ToF #26

wants to merge 48 commits into from

Conversation

Aux1r
Copy link

@Aux1r Aux1r commented Oct 14, 2024

initial commit for time of flight sensor code, hope the folder structure is okay

Copy link

linear bot commented Oct 14, 2024

@Aux1r Aux1r changed the title initial commit SNS - I2C ToF Oct 14, 2024
@davidbeechey davidbeechey marked this pull request as draft October 15, 2024 10:17
@Aux1r
Copy link
Author

Aux1r commented Oct 21, 2024

Datasheet available here for the VL6180V1 ToF Sensor: https://www.st.com/en/imaging-and-photonics-solutions/vl6180.html#overview

@Aux1r Aux1r changed the title SNS - I2C ToF SNS - I2C ToF (HYPE-27) Oct 21, 2024
@davidbeechey davidbeechey changed the title SNS - I2C ToF (HYPE-27) SNS - I2C ToF Oct 31, 2024
@Aux1r
Copy link
Author

Aux1r commented Oct 31, 2024

  • Added functions for i2c trait to allow reading and writing to registers with 16 bit addresses.
  • Created new() function, start_ss_measure() function which starts a singleshot measurement, poll_range() function that polls to see if a new range reslt is available, read_range() that reads this value.

A lot of these functions were implemented using the 'example code' provided in the VL6180 application sheet: https://www.st.com/resource/en/application_note/an4545-vl6180x-basic-ranging-application-note-stmicroelectronics.pdf

TODO:

  • Implement continuous mode measurements
  • Verify decoding of RESULT_RANGE_VAL is appropriate (and actually returns us the value in mm)
  • Verify poll_range() function works (not sure how Rust likes the while loop)
  • Add clear_interrupts() function and checks for if the system is 'fresh out of reset' (refer to Application Sheet)

lib/io/src/i2c.rs Outdated Show resolved Hide resolved
lib/sensors/src/tof.rs Outdated Show resolved Hide resolved
@Aux1r Aux1r marked this pull request as ready for review November 14, 2024 18:35
@davidbeechey davidbeechey added needs-testing Needs testing in the lab before merging needs-reviews Needs reviews, otherwise finished labels Nov 15, 2024
@Aux1r Aux1r requested a review from davidbeechey November 16, 2024 15:43
Tests are failing though, not sure why
Copy link
Collaborator

@davidbeechey davidbeechey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very nearly done now! The tests aren't working properly (not sure why). A few comments here to fix and think about the API. Apart from those functionality points, would be good to add Rust doc comments to all of your functions

boards/stm32l476rg/src/tasks/tof.rs Show resolved Hide resolved
Comment on lines +26 to +36
// Check that the sensor has powered up
// Note: the sensor will either need to be power cycled or the SYS_FRESH_OUT_RESET register will need to be written to 0x01 if it has already been configured
let mut boot_status = i2c
.read_byte_16(device_address, SYSTEM_FRESH_OUT_OF_RESET)
.unwrap_or_default();
while boot_status != 1 {
boot_status = i2c
.read_byte_16(device_address, SYSTEM_FRESH_OUT_OF_RESET)
.unwrap_or_default();
}
defmt::info!("ToF sensor booted");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about this again: To take advantage of the SYSTEM_FRESH_OUT_OF_RESET register, you could just check if it is configured and if it is, skip initialising all of the registers (just extract that logic into an init_sensor (or similar) function

lib/sensors/src/tof.rs Outdated Show resolved Hide resolved
lib/sensors/src/tof.rs Show resolved Hide resolved
lib/sensors/src/tof.rs Show resolved Hide resolved
lib/sensors/src/tof.rs Outdated Show resolved Hide resolved
lib/sensors/src/tof.rs Outdated Show resolved Hide resolved
lib/sensors/src/tof.rs Show resolved Hide resolved
@davidbeechey davidbeechey removed the needs-testing Needs testing in the lab before merging label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-reviews Needs reviews, otherwise finished
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants