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

HIL: remove 'static from sensors #1959

Merged
merged 1 commit into from
Jun 19, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion boards/components/src/ninedof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl NineDofComponent {
impl Component for NineDofComponent {
type StaticInput = (
&'static mut MaybeUninit<NineDof<'static>>,
&'static [&'static dyn kernel::hil::sensors::NineDof],
&'static [&'static dyn kernel::hil::sensors::NineDof<'static>],
);
type Output = &'static capsules::ninedof::NineDof<'static>;

Expand Down
6 changes: 3 additions & 3 deletions boards/components/src/temperature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ use kernel::create_capability;
use kernel::hil;
use kernel::static_init;

pub struct TemperatureComponent<T: 'static + hil::sensors::TemperatureDriver> {
pub struct TemperatureComponent<T: 'static + hil::sensors::TemperatureDriver<'static>> {
board_kernel: &'static kernel::Kernel,
temp_sensor: &'static T,
}

impl<T: 'static + hil::sensors::TemperatureDriver> TemperatureComponent<T> {
impl<T: 'static + hil::sensors::TemperatureDriver<'static>> TemperatureComponent<T> {
pub fn new(
board_kernel: &'static kernel::Kernel,
temp_sensor: &'static T,
Expand All @@ -30,7 +30,7 @@ impl<T: 'static + hil::sensors::TemperatureDriver> TemperatureComponent<T> {
}
}

impl<T: 'static + hil::sensors::TemperatureDriver> Component for TemperatureComponent<T> {
impl<T: 'static + hil::sensors::TemperatureDriver<'static>> Component for TemperatureComponent<T> {
type StaticInput = ();
type Output = &'static TemperatureSensor<'static>;

Expand Down
4 changes: 2 additions & 2 deletions capsules/src/ambient_light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ pub struct App {
}

pub struct AmbientLight<'a> {
sensor: &'a dyn hil::sensors::AmbientLight,
sensor: &'a dyn hil::sensors::AmbientLight<'a>,
command_pending: Cell<bool>,
apps: Grant<App>,
}

impl<'a> AmbientLight<'a> {
pub fn new(sensor: &'a dyn hil::sensors::AmbientLight, grant: Grant<App>) -> AmbientLight {
pub fn new(sensor: &'a dyn hil::sensors::AmbientLight<'a>, grant: Grant<App>) -> AmbientLight {
AmbientLight {
sensor: sensor,
command_pending: Cell::new(false),
Expand Down
8 changes: 4 additions & 4 deletions capsules/src/analog_sensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ impl<A: hil::adc::Adc> hil::adc::Client for AnalogLightSensor<'_, A> {
}
}

impl<A: hil::adc::Adc> hil::sensors::AmbientLight for AnalogLightSensor<'_, A> {
fn set_client(&self, client: &'static dyn hil::sensors::AmbientLightClient) {
impl<'a, A: hil::adc::Adc> hil::sensors::AmbientLight<'a> for AnalogLightSensor<'a, A> {
fn set_client(&self, client: &'a dyn hil::sensors::AmbientLightClient) {
self.client.set(client);
}

Expand Down Expand Up @@ -107,8 +107,8 @@ impl<A: hil::adc::Adc> hil::adc::Client for AnalogTemperatureSensor<'_, A> {
}
}

impl<A: hil::adc::Adc> hil::sensors::TemperatureDriver for AnalogTemperatureSensor<'_, A> {
fn set_client(&self, client: &'static dyn hil::sensors::TemperatureClient) {
impl<'a, A: hil::adc::Adc> hil::sensors::TemperatureDriver<'a> for AnalogTemperatureSensor<'a, A> {
fn set_client(&self, client: &'a dyn hil::sensors::TemperatureClient) {
self.client.set(client);
}

Expand Down
6 changes: 3 additions & 3 deletions capsules/src/fxos8700cq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pub struct Fxos8700cq<'a> {
interrupt_pin1: &'a dyn gpio::InterruptPin,
state: Cell<State>,
buffer: TakeCell<'static, [u8]>,
callback: OptionalCell<&'static dyn hil::sensors::NineDofClient>,
callback: OptionalCell<&'a dyn hil::sensors::NineDofClient>,
}

impl<'a> Fxos8700cq<'a> {
Expand Down Expand Up @@ -317,8 +317,8 @@ impl I2CClient for Fxos8700cq<'_> {
}
}

impl hil::sensors::NineDof for Fxos8700cq<'_> {
fn set_client(&self, client: &'static dyn hil::sensors::NineDofClient) {
impl<'a> hil::sensors::NineDof<'a> for Fxos8700cq<'a> {
fn set_client(&self, client: &'a dyn hil::sensors::NineDofClient) {
self.callback.set(client);
}

Expand Down
4 changes: 2 additions & 2 deletions capsules/src/humidity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ pub struct App {
}

pub struct HumiditySensor<'a> {
driver: &'a dyn hil::sensors::HumidityDriver,
driver: &'a dyn hil::sensors::HumidityDriver<'a>,
apps: Grant<App>,
busy: Cell<bool>,
}

impl<'a> HumiditySensor<'a> {
pub fn new(
driver: &'a dyn hil::sensors::HumidityDriver,
driver: &'a dyn hil::sensors::HumidityDriver<'a>,
grant: Grant<App>,
) -> HumiditySensor<'a> {
HumiditySensor {
Expand Down
4 changes: 2 additions & 2 deletions capsules/src/isl29035.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ impl<'a, A: time::Alarm<'a>> Isl29035<'a, A> {
}
}

impl<'a, A: time::Alarm<'a>> AmbientLight for Isl29035<'a, A> {
fn set_client(&self, client: &'static dyn AmbientLightClient) {
impl<'a, A: time::Alarm<'a>> AmbientLight<'a> for Isl29035<'a, A> {
fn set_client(&self, client: &'a dyn AmbientLightClient) {
self.client.set(client);
}

Expand Down
4 changes: 2 additions & 2 deletions capsules/src/l3gd20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ impl spi::SpiMasterClient for L3gd20Spi<'_> {
}
}

impl<'a> sensors::NineDof for L3gd20Spi<'a> {
impl<'a> sensors::NineDof<'a> for L3gd20Spi<'a> {
fn set_client(&self, nine_dof_client: &'a dyn sensors::NineDofClient) {
self.nine_dof_client.replace(nine_dof_client);
}
Expand All @@ -520,7 +520,7 @@ impl<'a> sensors::NineDof for L3gd20Spi<'a> {
}
}

impl<'a> sensors::TemperatureDriver for L3gd20Spi<'a> {
impl<'a> sensors::TemperatureDriver<'a> for L3gd20Spi<'a> {
fn set_client(&self, temperature_client: &'a dyn sensors::TemperatureClient) {
self.temperature_client.replace(temperature_client);
}
Expand Down
4 changes: 2 additions & 2 deletions capsules/src/lsm303dlhc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ impl Driver for Lsm303dlhcI2C<'_> {
}
}

impl<'a> sensors::NineDof for Lsm303dlhcI2C<'a> {
impl<'a> sensors::NineDof<'a> for Lsm303dlhcI2C<'a> {
fn set_client(&self, nine_dof_client: &'a dyn sensors::NineDofClient) {
self.nine_dof_client.replace(nine_dof_client);
}
Expand All @@ -747,7 +747,7 @@ impl<'a> sensors::NineDof for Lsm303dlhcI2C<'a> {
}
}

impl<'a> sensors::TemperatureDriver for Lsm303dlhcI2C<'a> {
impl<'a> sensors::TemperatureDriver<'a> for Lsm303dlhcI2C<'a> {
fn set_client(&self, temperature_client: &'a dyn sensors::TemperatureClient) {
self.temperature_client.replace(temperature_client);
}
Expand Down
2 changes: 1 addition & 1 deletion capsules/src/mlx90614.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl<'a> Driver for Mlx90614SMBus<'a> {
}
}

impl<'a> sensors::TemperatureDriver for Mlx90614SMBus<'a> {
impl<'a> sensors::TemperatureDriver<'a> for Mlx90614SMBus<'a> {
fn set_client(&self, temperature_client: &'a dyn sensors::TemperatureClient) {
self.temperature_client.replace(temperature_client);
}
Expand Down
4 changes: 2 additions & 2 deletions capsules/src/ninedof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ impl Default for App {
}

pub struct NineDof<'a> {
drivers: &'a [&'a dyn hil::sensors::NineDof],
drivers: &'a [&'a dyn hil::sensors::NineDof<'a>],
apps: Grant<App>,
current_app: OptionalCell<AppId>,
}

impl<'a> NineDof<'a> {
pub fn new(drivers: &'a [&'a dyn hil::sensors::NineDof], grant: Grant<App>) -> NineDof<'a> {
pub fn new(drivers: &'a [&'a dyn hil::sensors::NineDof<'a>], grant: Grant<App>) -> NineDof<'a> {
NineDof {
drivers: drivers,
apps: grant,
Expand Down
12 changes: 6 additions & 6 deletions capsules/src/si7021.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ enum OnDeck {
pub struct SI7021<'a, A: time::Alarm<'a>> {
i2c: &'a dyn i2c::I2CDevice,
alarm: &'a A,
temp_callback: OptionalCell<&'static dyn kernel::hil::sensors::TemperatureClient>,
humidity_callback: OptionalCell<&'static dyn kernel::hil::sensors::HumidityClient>,
temp_callback: OptionalCell<&'a dyn kernel::hil::sensors::TemperatureClient>,
humidity_callback: OptionalCell<&'a dyn kernel::hil::sensors::HumidityClient>,
state: Cell<State>,
on_deck: Cell<OnDeck>,
buffer: TakeCell<'static, [u8]>,
Expand Down Expand Up @@ -240,7 +240,7 @@ impl<'a, A: time::Alarm<'a>> i2c::I2CClient for SI7021<'a, A> {
}
}

impl<'a, A: time::Alarm<'a>> kernel::hil::sensors::TemperatureDriver for SI7021<'a, A> {
impl<'a, A: time::Alarm<'a>> kernel::hil::sensors::TemperatureDriver<'a> for SI7021<'a, A> {
fn read_temperature(&self) -> kernel::ReturnCode {
self.buffer.take().map_or_else(
|| {
Expand All @@ -263,12 +263,12 @@ impl<'a, A: time::Alarm<'a>> kernel::hil::sensors::TemperatureDriver for SI7021<
)
}

fn set_client(&self, client: &'static dyn kernel::hil::sensors::TemperatureClient) {
fn set_client(&self, client: &'a dyn kernel::hil::sensors::TemperatureClient) {
self.temp_callback.set(client);
}
}

impl<'a, A: time::Alarm<'a>> kernel::hil::sensors::HumidityDriver for SI7021<'a, A> {
impl<'a, A: time::Alarm<'a>> kernel::hil::sensors::HumidityDriver<'a> for SI7021<'a, A> {
fn read_humidity(&self) -> kernel::ReturnCode {
self.buffer.take().map_or_else(
|| {
Expand All @@ -291,7 +291,7 @@ impl<'a, A: time::Alarm<'a>> kernel::hil::sensors::HumidityDriver for SI7021<'a,
)
}

fn set_client(&self, client: &'static dyn kernel::hil::sensors::HumidityClient) {
fn set_client(&self, client: &'a dyn kernel::hil::sensors::HumidityClient) {
self.humidity_callback.set(client);
}
}
Expand Down
4 changes: 2 additions & 2 deletions capsules/src/temperature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ pub struct App {
}

pub struct TemperatureSensor<'a> {
driver: &'a dyn hil::sensors::TemperatureDriver,
driver: &'a dyn hil::sensors::TemperatureDriver<'a>,
apps: Grant<App>,
busy: Cell<bool>,
}

impl<'a> TemperatureSensor<'a> {
pub fn new(
driver: &'a dyn hil::sensors::TemperatureDriver,
driver: &'a dyn hil::sensors::TemperatureDriver<'a>,
grant: Grant<App>,
) -> TemperatureSensor<'a> {
TemperatureSensor {
Expand Down
12 changes: 6 additions & 6 deletions chips/nrf5x/src/temperature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ register_bitfields! [u32,
]
];

pub struct Temp {
pub struct Temp<'a> {
registers: StaticRef<TempRegisters>,
client: OptionalCell<&'static dyn kernel::hil::sensors::TemperatureClient>,
client: OptionalCell<&'a dyn kernel::hil::sensors::TemperatureClient>,
}

pub static mut TEMP: Temp = Temp::new();

impl Temp {
const fn new() -> Temp {
impl<'a> Temp<'a> {
const fn new() -> Temp<'a> {
Temp {
registers: TEMP_BASE,
client: OptionalCell::empty(),
Expand Down Expand Up @@ -149,7 +149,7 @@ impl Temp {
}
}

impl kernel::hil::sensors::TemperatureDriver for Temp {
impl<'a> kernel::hil::sensors::TemperatureDriver<'a> for Temp<'a> {
fn read_temperature(&self) -> kernel::ReturnCode {
let regs = &*self.registers;
self.enable_interrupts();
Expand All @@ -158,7 +158,7 @@ impl kernel::hil::sensors::TemperatureDriver for Temp {
kernel::ReturnCode::SUCCESS
}

fn set_client(&self, client: &'static dyn kernel::hil::sensors::TemperatureClient) {
fn set_client(&self, client: &'a dyn kernel::hil::sensors::TemperatureClient) {
self.client.set(client);
}
}
16 changes: 8 additions & 8 deletions kernel/src/hil/sensors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use crate::returncode::ReturnCode;

/// A basic interface for a temperature sensor
pub trait TemperatureDriver {
fn set_client(&self, client: &'static dyn TemperatureClient);
pub trait TemperatureDriver<'a> {
fn set_client(&self, client: &'a dyn TemperatureClient);
fn read_temperature(&self) -> ReturnCode;
}

Expand All @@ -18,8 +18,8 @@ pub trait TemperatureClient {
}

/// A basic interface for a humidity sensor
pub trait HumidityDriver {
fn set_client(&self, client: &'static dyn HumidityClient);
pub trait HumidityDriver<'a> {
fn set_client(&self, client: &'a dyn HumidityClient);
fn read_humidity(&self) -> ReturnCode;
}

Expand All @@ -32,10 +32,10 @@ pub trait HumidityClient {
}

/// A basic interface for an ambient light sensor.
pub trait AmbientLight {
pub trait AmbientLight<'a> {
/// Set the client to be notified when the capsule has data ready or has
/// finished some command. This is likely called in a board's `main.rs`.
fn set_client(&self, client: &'static dyn AmbientLightClient);
fn set_client(&self, client: &'a dyn AmbientLightClient);

/// Get a single instantaneous reading of the ambient light intensity.
fn read_light_intensity(&self) -> ReturnCode {
Expand All @@ -58,11 +58,11 @@ pub trait AmbientLightClient {
/// gyroscope) sensor. Any interface functions that a chip cannot implement
/// can be ignored by the chip capsule and an error will automatically be
/// returned.
pub trait NineDof {
pub trait NineDof<'a> {
/// Set the client to be notified when the capsule has data ready or
/// has finished some command. This is likely called in a board's main.rs
/// and is set to the virtual_ninedof.rs driver.
fn set_client(&self, client: &'static dyn NineDofClient);
fn set_client(&self, client: &'a dyn NineDofClient);

/// Get a single instantaneous reading of the acceleration in the
/// X,Y,Z directions.
Expand Down