8000 components: fxo: update to new _static by bradjc · Pull Request #3237 · tock/tock · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

components: fxo: update to new _static #3237

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

Merged
merged 1 commit into from
Oct 7, 2022
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
44 changes: 31 additions & 13 deletions boards/components/src/fxos8700.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,72 @@
//! -----
//! ```rust
//! let fxos8700 = components::fxos8700::Fxos8700Component::new(mux_i2c, PinId::AdB1_00.get_pin().as_ref().unwrap())
//! .finalize(());
//! .finalize(components::fxos8700_component_static!());
//!
//! let ninedof = components::ninedof::NineDofComponent::new(board_kernel)
//! .finalize(components::ninedof_component_helper!(fxos8700));
//! .finalize(components::ninedof_component_static!(fxos8700));
//! ```

// Based on the component written for sam4l by:
// Author: Philip Levis <pal@cs.stanford.edu>
// Last modified: 6/03/2020

use capsules::fxos8700cq;
use capsules::fxos8700cq::Fxos8700cq;
use capsules::virtual_i2c::{I2CDevice, MuxI2C};

use kernel::component::Component;

use core::mem::MaybeUninit;
use kernel::hil;
use kernel::hil::gpio;
use kernel::static_init;

#[macro_export]
macro_rules! fxos8700_component_static {
() => {{
let i2c_device = kernel::static_buf!(capsules::virtual_i2c::I2CDevice);
let buffer = kernel::static_buf!([u8; capsules::fxos8700cq::BUF_LEN]);
let fxo = kernel::static_buf!(capsules::fxos8700cq::Fxos8700cq<'static>);

(i2c_device, buffer, fxo)
};};
Copy link
Contributor
@twilfredo twilfredo Sep 28, 2022

Choose a reason for hiding this comment

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

Suggested change
};};
}};

Does this not generate a warning here? Similar to in #3245

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm confused what is causing the warning, or not causing the warning in the case of capsules. I've seen other PRs that add the semicolon to fix something, so I'm not really sure what the right thing to do is.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought it might be for when the macro returns something, like in this case and in #3245 . But if there's no warnings I'm not sure either...🤔

}

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

impl Fxos8700Component {
pub fn new<'a>(
i2c: &'static MuxI2C<'static>,
i2c_address: u8,
gpio: &'static dyn hil::gpio::InterruptPin<'static>,
) -> Fxos8700Component {
Fxos8700Component {
i2c_mux: i2c,
i2c_address,
gpio: gpio,
}
}
}

impl Component for Fxos8700Component {
type StaticInput = ();
type Output = &'static fxos8700cq::Fxos8700cq<'static>;

unsafe fn finalize(self, _s: Self::StaticInput) -> Self::Output {
let fxos8700_i2c = static_init!(I2CDevice, I2CDevice::new(self.i2c_mux, 0x1f));
let fxos8700 = static_init!(
fxos8700cq::Fxos8700cq<'static>,
fxos8700cq::Fxos8700cq::new(fxos8700_i2c, self.gpio, &mut fxos8700cq::BUF)
);
type StaticInput = (
&'static mut MaybeUninit<I2CDevice<'static>>,
&'static mut MaybeUninit<[u8; capsules::fxos8700cq::BUF_LEN]>,
&'static mut MaybeUninit<Fxos8700cq<'static>>,
);
type Output = &'static Fxos8700cq<'static>;

unsafe fn finalize(self, s: Self::StaticInput) -> Self::Output {
let fxos8700_i2c = s.0.write(I2CDevice::new(self.i2c_mux, self.i2c_address));
let buffer = s.1.write([0; capsules::fxos8700cq::BUF_LEN]);
let fxos8700 = s.2.write(Fxos8700cq::new(fxos8700_i2c, self.gpio, buffer));

fxos8700_i2c.set_client(fxos8700);
self.gpio.set_client(fxos8700);

fxos8700
}
}
16 changes: 4 additions & 12 deletions boards/hail/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#![deny(missing_docs)]

use capsules::virtual_alarm::VirtualMuxAlarm;
use capsules::virtual_i2c::{I2CDevice, MuxI2C};
use capsules::virtual_i2c::MuxI2C;
use capsules::virtual_spi::VirtualSpiMasterDevice;
use kernel::capabilities;
use kernel::component::Component;
Expand Down Expand Up @@ -366,17 +366,9 @@ pub unsafe fn main() {
.finalize(components::alarm_component_helper!(sam4l::ast::Ast));

// FXOS8700CQ accelerometer, device address 0x1e
let fxos8700_i2c = static_init!(I2CDevice, I2CDevice::new(sensors_i2c, 0x1e));
let fxos8700 = static_init!(
capsules::fxos8700cq::Fxos8700cq<'static>,
capsules::fxos8700cq::Fxos8700cq::new(
fxos8700_i2c,
&peripherals.pa[9],
&mut capsules::fxos8700cq::BUF
)
);
fxos8700_i2c.set_client(fxos8700);
peripherals.pa[9].set_client(fxos8700);
let fxos8700 =
components::fxos8700::Fxos8700Component::new(sensors_i2c, 0x1e, &peripherals.pa[9])
.finalize(components::fxos8700_component_static!());

let ninedof =
components::ninedof::NineDofComponent::new(board_kernel, capsules::ninedof::DRIVER_NUM)
Expand Down
109 changes: 0 additions & 109 deletions boards/imix/src/imix_components/fxos8700.rs

This file was deleted.

2 changes: 0 additions & 2 deletions boards/imix/src/imix_components/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
pub mod adc;
pub mod fxos8700;
pub mod rf233;
pub mod test;
pub mod usb;

pub use self::adc::AdcComponent;
pub use self::fxos8700::NineDofComponent;
pub use self::rf233::RF233Component;
pub use self::usb::UsbComponent;
15 changes: 7 additions & 8 deletions boards/imix/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ use components::rng::RngComponent;
use components::si7021::{HumidityComponent, SI7021Component};
use components::spi::{SpiComponent, SpiSyscallComponent};
use imix_components::adc::AdcComponent;
use imix_components::fxos8700::NineDofComponent;
use imix_components::rf233::RF233Component;
use imix_components::usb::UsbComponent;

Expand Down Expand Up @@ -416,13 +415,13 @@ pub unsafe fn main() {
.finalize(());
let humidity =
HumidityComponent::new(board_kernel, capsules::humidity::DRIVER_NUM, si7021).finalize(());
let ninedof = NineDofComponent::new(
board_kernel,
capsules::ninedof::DRIVER_NUM,
mux_i2c,
&peripherals.pc[13],
)
.finalize(());

let fxos8700 = components::fxos8700::Fxos8700Component::new(mux_i2c, 0x1e, &peripherals.pc[13])
.finalize(components::fxos8700_component_static!());

let ninedof =
components::ninedof::NineDofComponent::new(board_kernel, capsules::ninedof::DRIVER_NUM)
.finalize(components::ninedof_component_helper!(fxos8700));

// SPI MUX, SPI syscall driver and RF233 radio
let mux_spi = components::spi::SpiMuxComponent::new(&peripherals.spi, dynamic_deferred_caller)
Expand Down
3 changes: 2 additions & 1 deletion boards/imxrt1050-evkb/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,10 @@ pub unsafe fn main() {
// Fxos8700 sensor
let fxos8700 = components::fxos8700::Fxos8700Component::new(
mux_i2c,
0x1f,
peripherals.ports.pin(PinId::AdB1_00),
)
.finalize(());
.finalize(components::fxos8700_component_static!());

// Ninedof
let ninedof =
Expand Down
3 changes: 2 additions & 1 deletion capsules/src/fxos8700cq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ use kernel::hil::i2c::{Error, I2CClient, I2CDevice};
use kernel::utilities::cells::{OptionalCell, TakeCell};
use kernel::ErrorCode;

pub static mut BUF: [u8; 6] = [0; 6];
/// Recommended buffer length for this driver.
pub const BUF_LEN: usize = 6;

#[allow(dead_code)]
enum Registers {
Expand Down
0