Skip to content

Commit

Permalink
Merge #3467
Browse files Browse the repository at this point in the history
3467: hil: i2c: remove 'static from client r=bradjc a=lschuermann

### Pull Request Overview

Part of #1074.

This used to be based on a WIP version by `@bradjc,` until I realized that it branched off on `198ff4173`; that's 3 years old! So re-doing these (mechanical) changes seemed easier than fixing 3 years worth of conflicts. Thanks to `@bradjc` for the initial version though!


### Testing Strategy

This pull request was tested by compiling.


### TODO or Help Wanted

N/A


### Documentation Updated

- [x] ~Updated the relevant files in `/docs`,~ or no updates are required.

### Formatting

- [x] Ran `make prepush`.


Co-authored-by: Leon Schuermann <leon@is.currently.online>
  • Loading branch information
bors[bot] and lschuermann committed Jun 8, 2023
2 parents f5bd104 + 46b49ec commit 25f1919
Show file tree
Hide file tree
Showing 42 changed files with 223 additions and 174 deletions.
24 changes: 18 additions & 6 deletions boards/acd52832/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ pub struct Platform {
'static,
capsules_extra::mcp230xx::MCP230xx<
'static,
capsules_core::virtualizers::virtual_i2c::I2CDevice<'static, nrf52832::i2c::TWI>,
capsules_core::virtualizers::virtual_i2c::I2CDevice<
'static,
nrf52832::i2c::TWI<'static>,
>,
>,
>,
light: &'static capsules_extra::ambient_light::AmbientLight<'static>,
Expand Down Expand Up @@ -359,7 +362,7 @@ pub unsafe fn main() {

// Create shared mux for the I2C bus
let i2c_mux = static_init!(
capsules_core::virtualizers::virtual_i2c::MuxI2C<'static, nrf52832::i2c::TWI>,
capsules_core::virtualizers::virtual_i2c::MuxI2C<'static, nrf52832::i2c::TWI<'static>>,
capsules_core::virtualizers::virtual_i2c::MuxI2C::new(&base_peripherals.twi0, None,)
);
kernel::deferred_call::DeferredCallClient::register(i2c_mux);
Expand All @@ -381,13 +384,16 @@ pub unsafe fn main() {
)
.finalize();
let mcp23017_i2c = static_init!(
capsules_core::virtualizers::virtual_i2c::I2CDevice<'static, nrf52832::i2c::TWI>,
capsules_core::virtualizers::virtual_i2c::I2CDevice<'static, nrf52832::i2c::TWI<'static>>,
capsules_core::virtualizers::virtual_i2c::I2CDevice::new(i2c_mux, 0x40)
);
let mcp23017 = static_init!(
capsules_extra::mcp230xx::MCP230xx<
'static,
capsules_core::virtualizers::virtual_i2c::I2CDevice<'static, nrf52832::i2c::TWI>,
capsules_core::virtualizers::virtual_i2c::I2CDevice<
'static,
nrf52832::i2c::TWI<'static>,
>,
>,
capsules_extra::mcp230xx::MCP230xx::new(
mcp23017_i2c,
Expand All @@ -410,7 +416,10 @@ pub unsafe fn main() {
// administrative layer that provides a single interface to them all.
let async_gpio_ports = static_init!(
[&'static capsules_extra::mcp230xx::MCP230xx<
capsules_core::virtualizers::virtual_i2c::I2CDevice<'static, nrf52832::i2c::TWI>,
capsules_core::virtualizers::virtual_i2c::I2CDevice<
'static,
nrf52832::i2c::TWI<'static>,
>,
>; 1],
[mcp23017]
);
Expand All @@ -421,7 +430,10 @@ pub unsafe fn main() {
'static,
capsules_extra::mcp230xx::MCP230xx<
'static,
capsules_core::virtualizers::virtual_i2c::I2CDevice<'static, nrf52832::i2c::TWI>,
capsules_core::virtualizers::virtual_i2c::I2CDevice<
'static,
nrf52832::i2c::TWI<'static>,
>,
>,
>,
capsules_extra::gpio_async::GPIOAsync::new(
Expand Down
6 changes: 3 additions & 3 deletions boards/components/src/apds9960.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ macro_rules! apds9960_component_static {
};};
}

pub struct Apds9960Component<I: 'static + i2c::I2CMaster> {
pub struct Apds9960Component<I: 'static + i2c::I2CMaster<'static>> {
i2c_mux: &'static MuxI2C<'static, I>,
i2c_address: u8,
interrupt_pin: &'static dyn gpio::InterruptPin<'static>,
}

impl<I: 'static + i2c::I2CMaster> Apds9960Component<I> {
impl<I: 'static + i2c::I2CMaster<'static>> Apds9960Component<I> {
pub fn new(
i2c_mux: &'static MuxI2C<'static, I>,
i2c_address: u8,
Expand All @@ -48,7 +48,7 @@ impl<I: 'static + i2c::I2CMaster> Apds9960Component<I> {
}
}

impl<I: 'static + i2c::I2CMaster> Component for Apds9960Component<I> {
impl<I: 'static + i2c::I2CMaster<'static>> Component for Apds9960Component<I> {
type StaticInput = (
&'static mut MaybeUninit<I2CDevice<'static, I>>,
&'static mut MaybeUninit<APDS9960<'static, I2CDevice<'static, I>>>,
Expand Down
6 changes: 3 additions & 3 deletions boards/components/src/bme280.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ macro_rules! bme280_component_static {
};};
}

pub struct Bme280Component<I: 'static + i2c::I2CMaster> {
pub struct Bme280Component<I: 'static + i2c::I2CMaster<'static>> {
i2c_mux: &'static MuxI2C<'static, I>,
i2c_address: u8,
}

impl<I: 'static + i2c::I2CMaster> Bme280Component<I> {
impl<I: 'static + i2c::I2CMaster<'static>> Bme280Component<I> {
pub fn new(i2c: &'static MuxI2C<'static, I>, i2c_address: u8) -> Self {
Bme280Component {
i2c_mux: i2c,
Expand All @@ -56,7 +56,7 @@ impl<I: 'static + i2c::I2CMaster> Bme280Component<I> {
}
}

impl<I: 'static + i2c::I2CMaster> Component for Bme280Component<I> {
impl<I: 'static + i2c::I2CMaster<'static>> Component for Bme280Component<I> {
type StaticInput = (
&'static mut MaybeUninit<I2CDevice<'static, I>>,
&'static mut MaybeUninit<[u8; 26]>,
Expand Down
8 changes: 5 additions & 3 deletions boards/components/src/bmp280.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ macro_rules! bmp280_component_static {
};};
}

pub struct Bmp280Component<A: 'static + Alarm<'static>, I: 'static + i2c::I2CMaster> {
pub struct Bmp280Component<A: 'static + Alarm<'static>, I: 'static + i2c::I2CMaster<'static>> {
i2c_mux: &'static MuxI2C<'static, I>,
i2c_address: u8,
alarm_mux: &'static MuxAlarm<'static, A>,
}

impl<A: 'static + Alarm<'static>, I: 'static + i2c::I2CMaster> Bmp280Component<A, I> {
impl<A: 'static + Alarm<'static>, I: 'static + i2c::I2CMaster<'static>> Bmp280Component<A, I> {
pub fn new(
i2c_mux: &'static MuxI2C<'static, I>,
i2c_address: u8,
Expand All @@ -76,7 +76,9 @@ impl<A: 'static + Alarm<'static>, I: 'static + i2c::I2CMaster> Bmp280Component<A
}
}

impl<A: 'static + Alarm<'static>, I: 'static + i2c::I2CMaster> Component for Bmp280Component<A, I> {
impl<A: 'static + Alarm<'static>, I: 'static + i2c::I2CMaster<'static>> Component
for Bmp280Component<A, I>
{
type StaticInput = (
&'static mut MaybeUninit<I2CDevice<'static, I>>,
&'static mut MaybeUninit<VirtualMuxAlarm<'static, A>>,
Expand Down
6 changes: 3 additions & 3 deletions boards/components/src/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ impl<S: 'static + spi::SpiMaster> Component for SpiMasterBusComponent<S> {
}
}

pub struct I2CMasterBusComponent<I: 'static + i2c::I2CMaster> {
pub struct I2CMasterBusComponent<I: 'static + i2c::I2CMaster<'static>> {
i2c_mux: &'static MuxI2C<'static, I>,
address: u8,
}

impl<I: 'static + i2c::I2CMaster> I2CMasterBusComponent<I> {
impl<I: 'static + i2c::I2CMaster<'static>> I2CMasterBusComponent<I> {
pub fn new(i2c_mux: &'static MuxI2C<'static, I>, address: u8) -> I2CMasterBusComponent<I> {
I2CMasterBusComponent {
i2c_mux: i2c_mux,
Expand All @@ -163,7 +163,7 @@ impl<I: 'static + i2c::I2CMaster> I2CMasterBusComponent<I> {
}
}

impl<I: 'static + i2c::I2CMaster> Component for I2CMasterBusComponent<I> {
impl<I: 'static + i2c::I2CMaster<'static>> Component for I2CMasterBusComponent<I> {
type StaticInput = (
&'static mut MaybeUninit<I2CMasterBus<'static, I2CDevice<'static, I>>>,
&'static mut MaybeUninit<I2CDevice<'static, I>>,
Expand Down
6 changes: 3 additions & 3 deletions boards/components/src/ccs811.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ macro_rules! ccs811_component_static {
};};
}

pub struct Ccs811Component<I: 'static + i2c::I2CMaster> {
pub struct Ccs811Component<I: 'static + i2c::I2CMaster<'static>> {
i2c_mux: &'static MuxI2C<'static, I>,
i2c_address: u8,
}

impl<I: 'static + i2c::I2CMaster> Ccs811Component<I> {
impl<I: 'static + i2c::I2CMaster<'static>> Ccs811Component<I> {
pub fn new(i2c: &'static MuxI2C<'static, I>, i2c_address: u8) -> Self {
Ccs811Component {
i2c_mux: i2c,
Expand All @@ -56,7 +56,7 @@ impl<I: 'static + i2c::I2CMaster> Ccs811Component<I> {
}
}

impl<I: 'static + i2c::I2CMaster> Component for Ccs811Component<I> {
impl<I: 'static + i2c::I2CMaster<'static>> Component for Ccs811Component<I> {
type StaticInput = (
&'static mut MaybeUninit<I2CDevice<'static, I>>,
&'static mut MaybeUninit<[u8; 6]>,
Expand Down
6 changes: 3 additions & 3 deletions boards/components/src/ft6x06.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ macro_rules! ft6x06_component_static {
};};
}

pub struct Ft6x06Component<I: 'static + i2c::I2CMaster> {
pub struct Ft6x06Component<I: 'static + i2c::I2CMaster<'static>> {
i2c_mux: &'static MuxI2C<'static, I>,
i2c_address: u8,
interrupt_pin: &'static dyn gpio::InterruptPin<'static>,
}

impl<I: 'static + i2c::I2CMaster> Ft6x06Component<I> {
impl<I: 'static + i2c::I2CMaster<'static>> Ft6x06Component<I> {
pub fn new(
i2c_mux: &'static MuxI2C<'static, I>,
i2c_address: u8,
Expand All @@ -62,7 +62,7 @@ impl<I: 'static + i2c::I2CMaster> Ft6x06Component<I> {
}
}

impl<I: 'static + i2c::I2CMaster> Component for Ft6x06Component<I> {
impl<I: 'static + i2c::I2CMaster<'static>> Component for Ft6x06Component<I> {
type StaticInput = (
&'static mut MaybeUninit<I2CDevice<'static, I>>,
&'static mut MaybeUninit<Ft6x06<'static, I2CDevice<'static, I>>>,
Expand Down
6 changes: 3 additions & 3 deletions boards/components/src/fxos8700.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ macro_rules! fxos8700_component_static {
};};
}

pub struct Fxos8700Component<I: 'static + i2c::I2CMaster> {
pub struct Fxos8700Component<I: 'static + i2c::I2CMaster<'static>> {
i2c_mux: &'static MuxI2C<'static, I>,
i2c_address: u8,
gpio: &'static dyn gpio::InterruptPin<'static>,
}

impl<I: 'static + i2c::I2CMaster> Fxos8700Component<I> {
impl<I: 'static + i2c::I2CMaster<'static>> Fxos8700Component<I> {
pub fn new<'a>(
i2c: &'static MuxI2C<'static, I>,
i2c_address: u8,
Expand All @@ -62,7 +62,7 @@ impl<I: 'static + i2c::I2CMaster> Fxos8700Component<I> {
}
}

impl<I: 'static + i2c::I2CMaster> Component for Fxos8700Component<I> {
impl<I: 'static + i2c::I2CMaster<'static>> Component for Fxos8700Component<I> {
type StaticInput = (
&'static mut MaybeUninit<I2CDevice<'static, I>>,
&'static mut MaybeUninit<[u8; capsules_extra::fxos8700cq::BUF_LEN]>,
Expand Down
6 changes: 3 additions & 3 deletions boards/components/src/hts221.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ macro_rules! hts221_component_static {
};};
}

pub struct Hts221Component<I: 'static + i2c::I2CMaster> {
pub struct Hts221Component<I: 'static + i2c::I2CMaster<'static>> {
i2c_mux: &'static MuxI2C<'static, I>,
i2c_address: u8,
}

impl<I: 'static + i2c::I2CMaster> Hts221Component<I> {
impl<I: 'static + i2c::I2CMaster<'static>> Hts221Component<I> {
pub fn new(i2c: &'static MuxI2C<'static, I>, i2c_address: u8) -> Self {
Hts221Component {
i2c_mux: i2c,
Expand All @@ -51,7 +51,7 @@ impl<I: 'static + i2c::I2CMaster> Hts221Component<I> {
}
}

impl<I: 'static + i2c::I2CMaster> Component for Hts221Component<I> {
impl<I: 'static + i2c::I2CMaster<'static>> Component for Hts221Component<I> {
type StaticInput = (
&'static mut MaybeUninit<I2CDevice<'static, I>>,
&'static mut MaybeUninit<[u8; 17]>,
Expand Down
17 changes: 11 additions & 6 deletions boards/components/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,23 @@ macro_rules! i2c_component_static {
};};
}

pub struct I2CMuxComponent<I: 'static + i2c::I2CMaster, S: 'static + i2c::SMBusMaster = NoSMBus> {
pub struct I2CMuxComponent<
I: 'static + i2c::I2CMaster<'static>,
S: 'static + i2c::SMBusMaster<'static> = NoSMBus,
> {
i2c: &'static I,
smbus: Option<&'static S>,
}

impl<I: 'static + i2c::I2CMaster, S: 'static + i2c::SMBusMaster> I2CMuxComponent<I, S> {
impl<I: 'static + i2c::I2CMaster<'static>, S: 'static + i2c::SMBusMaster<'static>>
I2CMuxComponent<I, S>
{
pub fn new(i2c: &'static I, smbus: Option<&'static S>) -> Self {
I2CMuxComponent { i2c, smbus }
}
}

impl<I: 'static + i2c::I2CMaster, S: 'static + i2c::SMBusMaster> Component
impl<I: 'static + i2c::I2CMaster<'static>, S: 'static + i2c::SMBusMaster<'static>> Component
for I2CMuxComponent<I, S>
{
type StaticInput = &'static mut MaybeUninit<MuxI2C<'static, I, S>>;
Expand All @@ -71,12 +76,12 @@ impl<I: 'static + i2c::I2CMaster, S: 'static + i2c::SMBusMaster> Component
}
}

pub struct I2CComponent<I: 'static + i2c::I2CMaster> {
pub struct I2CComponent<I: 'static + i2c::I2CMaster<'static>> {
i2c_mux: &'static MuxI2C<'static, I>,
address: u8,
}

impl<I: 'static + i2c::I2CMaster> I2CComponent<I> {
impl<I: 'static + i2c::I2CMaster<'static>> I2CComponent<I> {
pub fn new(mux: &'static MuxI2C<'static, I>, address: u8) -> Self {
I2CComponent {
i2c_mux: mux,
Expand All @@ -85,7 +90,7 @@ impl<I: 'static + i2c::I2CMaster> I2CComponent<I> {
}
}

impl<I: 'static + i2c::I2CMaster> Component for I2CComponent<I> {
impl<I: 'static + i2c::I2CMaster<'static>> Component for I2CComponent<I> {
type StaticInput = &'static mut MaybeUninit<I2CDevice<'static, I>>;
type Output = &'static I2CDevice<'static, I>;

Expand Down
11 changes: 8 additions & 3 deletions boards/components/src/isl29035.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,17 @@ macro_rules! ambient_light_component_static {
};};
}

pub struct Isl29035Component<A: 'static + time::Alarm<'static>, I: 'static + i2c::I2CMaster> {
pub struct Isl29035Component<
A: 'static + time::Alarm<'static>,
I: 'static + i2c::I2CMaster<'static>,
> {
i2c_mux: &'static MuxI2C<'static, I>,
alarm_mux: &'static MuxAlarm<'static, A>,
}

impl<A: 'static + time::Alarm<'static>, I: 'static + i2c::I2CMaster> Isl29035Component<A, I> {
impl<A: 'static + time::Alarm<'static>, I: 'static + i2c::I2CMaster<'static>>
Isl29035Component<A, I>
{
pub fn new(i2c: &'static MuxI2C<'static, I>, alarm: &'static MuxAlarm<'static, A>) -> Self {
Isl29035Component {
i2c_mux: i2c,
Expand All @@ -80,7 +85,7 @@ impl<A: 'static + time::Alarm<'static>, I: 'static + i2c::I2CMaster> Isl29035Com
}
}

impl<A: 'static + time::Alarm<'static>, I: 'static + i2c::I2CMaster> Component
impl<A: 'static + time::Alarm<'static>, I: 'static + i2c::I2CMaster<'static>> Component
for Isl29035Component<A, I>
{
type StaticInput = (
Expand Down
6 changes: 3 additions & 3 deletions boards/components/src/lps25hb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ macro_rules! lps25hb_component_static {
};};
}

pub struct Lps25hbComponent<I: 'static + i2c::I2CMaster> {
pub struct Lps25hbComponent<I: 'static + i2c::I2CMaster<'static>> {
i2c_mux: &'static MuxI2C<'static, I>,
i2c_address: u8,
interrupt_pin: &'static dyn gpio::InterruptPin<'static>,
board_kernel: &'static kernel::Kernel,
driver_num: usize,
}

impl<I: 'static + i2c::I2CMaster> Lps25hbComponent<I> {
impl<I: 'static + i2c::I2CMaster<'static>> Lps25hbComponent<I> {
pub fn new(
i2c_mux: &'static MuxI2C<'static, I>,
i2c_address: u8,
Expand All @@ -56,7 +56,7 @@ impl<I: 'static + i2c::I2CMaster> Lps25hbComponent<I> {
}
}

impl<I: 'static + i2c::I2CMaster> Component for Lps25hbComponent<I> {
impl<I: 'static + i2c::I2CMaster<'static>> Component for Lps25hbComponent<I> {
type StaticInput = (
&'static mut MaybeUninit<I2CDevice<'static, I>>,
&'static mut MaybeUninit<LPS25HB<'static, I2CDevice<'static, I>>>,
Expand Down
6 changes: 3 additions & 3 deletions boards/components/src/lsm303agr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ macro_rules! lsm303agr_component_static {
};};
}

pub struct Lsm303agrI2CComponent<I: 'static + i2c::I2CMaster> {
pub struct Lsm303agrI2CComponent<I: 'static + i2c::I2CMaster<'static>> {
i2c_mux: &'static MuxI2C<'static, I>,
accelerometer_i2c_address: u8,
magnetometer_i2c_address: u8,
board_kernel: &'static kernel::Kernel,
driver_num: usize,
}

impl<I: 'static + i2c::I2CMaster> Lsm303agrI2CComponent<I> {
impl<I: 'static + i2c::I2CMaster<'static>> Lsm303agrI2CComponent<I> {
pub fn new(
i2c_mux: &'static MuxI2C<'static, I>,
accelerometer_i2c_address: Option<u8>,
Expand All @@ -80,7 +80,7 @@ impl<I: 'static + i2c::I2CMaster> Lsm303agrI2CComponent<I> {
}
}

impl<I: 'static + i2c::I2CMaster> Component for Lsm303agrI2CComponent<I> {
impl<I: 'static + i2c::I2CMaster<'static>> Component for Lsm303agrI2CComponent<I> {
type StaticInput = (
&'static mut MaybeUninit<I2CDevice<'static, I>>,
&'static mut MaybeUninit<I2CDevice<'static, I>>,
Expand Down

0 comments on commit 25f1919

Please sign in to comment.