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

treewide: Rust updates #20303

Merged
merged 5 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cpu/nrf5x_common/periph/i2c_nrf52_nrf9160.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
* As this implementation is based on the nRF5x TWIM peripheral, it can not
* issue a read following a read (or a write following a write) without
* creating a (repeated) start condition:
* <https://devzone.nordicsemi.com/f/nordic-q-a/66615/nrf52840-twim-how-to-write-multiple-buffers-without-repeated-start-condition>,

Check warning on line 25 in cpu/nrf5x_common/periph/i2c_nrf52_nrf9160.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
* backed also by later experiments discussed in the [Rust embedded
* channel](https://matrix.to/#/!BHcierreUuwCMxVqOf:matrix.org/$JwNejRaeJx_tvqKgS88GenDG8ZNHrkTW09896dIehQ8?via=matrix.org&via=catircservices.org&via=tchncs.de).

Check warning on line 27 in cpu/nrf5x_common/periph/i2c_nrf52_nrf9160.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
* Due to this shortcoming in the hardware, any operations with I2C_NOSTART
* fail.
*
Expand Down Expand Up @@ -126,6 +126,16 @@
DEBUG("[i2c] finish: stop event occurred\n");
}

if (inten_success_flag & TWIM_INTEN_LASTTX_Msk) {
/* The interrupt is raised already when the last TX is started, but we
* have to wait until it was actually transmitted lest the transmission
* would be suppressed immediately by the next following write --
* careful here: enabling DEBUG introduces enough latency that the
* issue doesn't show up any more. */
while (bus(dev)->TXD.AMOUNT != bus(dev)->TXD.MAXCNT &&
!bus(dev)->EVENTS_ERROR) {}
}

if (bus(dev)->EVENTS_ERROR) {
bus(dev)->EVENTS_ERROR = 0;
if (bus(dev)->ERRORSRC & TWIM_ERRORSRC_ANACK_Msk) {
Expand Down
4 changes: 1 addition & 3 deletions drivers/lsm303agr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ license = "LGPL-2.1-only"
publish = false

[dependencies]
lsm303agr = "^0.2"
lsm303agr = "1.0"
riot-wrappers = "^0.8"
# Whatever lsm uses
nb = "*"
1 change: 1 addition & 0 deletions drivers/lsm303agr/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
USEMODULE += rust_riotmodules
USEMODULE += ztimer_msec

FEATURES_REQUIRED += periph_i2c
15 changes: 8 additions & 7 deletions drivers/lsm303agr/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![no_std]

use lsm303agr::{interface, mode, Lsm303agr, AccelOutputDataRate::Hz50};
use lsm303agr::{interface, mode, Lsm303agr, AccelOutputDataRate::Hz50, AccelMode};

use riot_wrappers::{saul, println, i2c, cstr::cstr, mutex::Mutex};
use saul::{Phydat, registration};
Expand Down Expand Up @@ -59,9 +59,11 @@ fn init() -> Result<(), &'static str> {
for (&i2cdev, (lsm, (reg, reg_mag))) in I2C_DEVICES.iter().zip(lsm.iter_mut().zip(reg.iter_mut().zip(reg_mag.iter_mut()))) {
let mut device = Lsm303agr::new_with_i2c(i2c::I2CDevice::new(i2cdev));

let mut init_clock = riot_wrappers::ztimer::Clock::msec();

device.init()
.map_err(|_| "Device initialization failed")?;
device.set_accel_odr(Hz50)
device.set_accel_mode_and_odr(&mut init_clock, AccelMode::Normal, Hz50)
.map_err(|_| "Device configuration failed")?;

let lsm = lsm.insert(SaulLSM { device: Mutex::new(device) });
Expand Down Expand Up @@ -90,10 +92,10 @@ impl registration::Drivable for &SaulLSM {
let mut device = self.device.try_lock()
.ok_or(registration::Error)?;

let data = device.accel_data()
let data = device.acceleration()
.map_err(|_| registration::Error)?;
// Data is in the +-2g range by default, which doesn't overflow even the i16 SAUL uses
Ok(Phydat::new(&[data.x as _, data.y as _, data.z as _], Some(saul::Unit::GForce), -3))
Ok(Phydat::new(&[data.x_mg() as _, data.y_mg() as _, data.z_mg() as _], Some(saul::Unit::GForce), -3))
}
}

Expand All @@ -115,9 +117,8 @@ impl registration::Drivable for MagAspect {
let mut device = self.0.device.try_lock()
.ok_or(registration::Error)?;

let data = nb::block!(device.mag_data())
let data = device.magnetic_field()
.map_err(|_| registration::Error)?;
// Original data is in nanotesla
return Ok(Phydat::fit(&[data.x, data.y, data.z], Some(saul::Unit::T), -9))
return Ok(Phydat::fit(&[data.x_nt(), data.y_nt(), data.z_nt()], Some(saul::Unit::T), -9))
}
}
Loading
Loading