Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 480b459

Browse files
bors[bot]bradjc
andauthored
Merge #3455
3455: Remove 'static from ADC HIL client r=lschuermann a=bradjc ### Pull Request Overview Part of #1074. Removes the 'static from the ADC set client calls. ### Testing Strategy travis ### 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: Brad Campbell <[email protected]>
2 parents 280c3e9 + 0e0293a commit 480b459

File tree

22 files changed

+110
-102
lines changed

22 files changed

+110
-102
lines changed

boards/components/src/adc.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ macro_rules! adc_dedicated_component_static {
5757
};};
5858
}
5959

60-
pub struct AdcMuxComponent<A: 'static + adc::Adc> {
60+
pub struct AdcMuxComponent<A: 'static + adc::Adc<'static>> {
6161
adc: &'static A,
6262
}
6363

64-
impl<A: 'static + adc::Adc> AdcMuxComponent<A> {
64+
impl<A: 'static + adc::Adc<'static>> AdcMuxComponent<A> {
6565
pub fn new(adc: &'static A) -> Self {
6666
AdcMuxComponent { adc: adc }
6767
}
6868
}
6969

70-
impl<A: 'static + adc::Adc> Component for AdcMuxComponent<A> {
70+
impl<A: 'static + adc::Adc<'static>> Component for AdcMuxComponent<A> {
7171
type StaticInput = &'static mut MaybeUninit<MuxAdc<'static, A>>;
7272
type Output = &'static MuxAdc<'static, A>;
7373

@@ -80,12 +80,12 @@ impl<A: 'static + adc::Adc> Component for AdcMuxComponent<A> {
8080
}
8181
}
8282

83-
pub struct AdcComponent<A: 'static + adc::Adc> {
83+
pub struct AdcComponent<A: 'static + adc::Adc<'static>> {
8484
adc_mux: &'static MuxAdc<'static, A>,
8585
channel: A::Channel,
8686
}
8787

88-
impl<A: 'static + adc::Adc> AdcComponent<A> {
88+
impl<A: 'static + adc::Adc<'static>> AdcComponent<A> {
8989
pub fn new(mux: &'static MuxAdc<'static, A>, channel: A::Channel) -> Self {
9090
AdcComponent {
9191
adc_mux: mux,
@@ -94,7 +94,7 @@ impl<A: 'static + adc::Adc> AdcComponent<A> {
9494
}
9595
}
9696

97-
impl<A: 'static + adc::Adc> Component for AdcComponent<A> {
97+
impl<A: 'static + adc::Adc<'static>> Component for AdcComponent<A> {
9898
type StaticInput = &'static mut MaybeUninit<AdcDevice<'static, A>>;
9999
type Output = &'static AdcDevice<'static, A>;
100100

@@ -124,7 +124,7 @@ impl AdcVirtualComponent {
124124
impl Component for AdcVirtualComponent {
125125
type StaticInput = (
126126
&'static mut MaybeUninit<AdcVirtualized<'static>>,
127-
&'static [&'static dyn kernel::hil::adc::AdcChannel],
127+
&'static [&'static dyn kernel::hil::adc::AdcChannel<'static>],
128128
);
129129
type Output = &'static capsules_core::adc::AdcVirtualized<'static>;
130130

@@ -148,15 +148,17 @@ impl Component for AdcVirtualComponent {
148148
}
149149

150150
pub struct AdcDedicatedComponent<
151-
A: kernel::hil::adc::Adc + kernel::hil::adc::AdcHighSpeed + 'static,
151+
A: kernel::hil::adc::Adc<'static> + kernel::hil::adc::AdcHighSpeed<'static> + 'static,
152152
> {
153153
adc: &'static A,
154154
channels: &'static [A::Channel],
155155
board_kernel: &'static kernel::Kernel,
156156
driver_num: usize,
157157
}
158158

159-
impl<A: kernel::hil::adc::Adc + kernel::hil::adc::AdcHighSpeed + 'static> AdcDedicatedComponent<A> {
159+
impl<A: kernel::hil::adc::Adc<'static> + kernel::hil::adc::AdcHighSpeed<'static> + 'static>
160+
AdcDedicatedComponent<A>
161+
{
160162
pub fn new(
161163
adc: &'static A,
162164
channels: &'static [A::Channel],
@@ -172,8 +174,8 @@ impl<A: kernel::hil::adc::Adc + kernel::hil::adc::AdcHighSpeed + 'static> AdcDed
172174
}
173175
}
174176

175-
impl<A: kernel::hil::adc::Adc + kernel::hil::adc::AdcHighSpeed + 'static> Component
176-
for AdcDedicatedComponent<A>
177+
impl<A: kernel::hil::adc::Adc<'static> + kernel::hil::adc::AdcHighSpeed<'static> + 'static>
178+
Component for AdcDedicatedComponent<A>
177179
{
178180
type StaticInput = (
179181
&'static mut MaybeUninit<AdcDedicated<'static, A>>,

boards/components/src/adc_microphone.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ macro_rules! adc_microphone_component_static {
5050
}
5151

5252
pub struct AdcMicrophoneComponent<
53-
A: 'static + adc::Adc,
53+
A: 'static + adc::Adc<'static>,
5454
P: 'static + gpio::Pin,
5555
const BUF_LEN: usize,
5656
> {
@@ -59,7 +59,7 @@ pub struct AdcMicrophoneComponent<
5959
pin: Option<&'static P>,
6060
}
6161

62-
impl<A: 'static + adc::Adc, P: 'static + gpio::Pin, const BUF_LEN: usize>
62+
impl<A: 'static + adc::Adc<'static>, P: 'static + gpio::Pin, const BUF_LEN: usize>
6363
AdcMicrophoneComponent<A, P, BUF_LEN>
6464
{
6565
pub fn new(
@@ -75,7 +75,7 @@ impl<A: 'static + adc::Adc, P: 'static + gpio::Pin, const BUF_LEN: usize>
7575
}
7676
}
7777

78-
impl<A: 'static + adc::Adc, P: 'static + gpio::Pin, const BUF_LEN: usize> Component
78+
impl<A: 'static + adc::Adc<'static>, P: 'static + gpio::Pin, const BUF_LEN: usize> Component
7979
for AdcMicrophoneComponent<A, P, BUF_LEN>
8080
{
8181
type StaticInput = (

boards/components/src/temperature_rp2040.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ macro_rules! temperature_rp2040_adc_component_static {
2222
};};
2323
}
2424

25-
pub struct TemperatureRp2040Component<A: 'static + adc::Adc> {
25+
pub struct TemperatureRp2040Component<A: 'static + adc::Adc<'static>> {
2626
adc_mux: &'static capsules_core::virtualizers::virtual_adc::MuxAdc<'static, A>,
2727
adc_channel: A::Channel,
2828
slope: f32,
2929
v_27: f32,
3030
}
3131

32-
impl<A: 'static + adc::Adc> TemperatureRp2040Component<A> {
32+
impl<A: 'static + adc::Adc<'static>> TemperatureRp2040Component<A> {
3333
pub fn new(
3434
adc_mux: &'static capsules_core::virtualizers::virtual_adc::MuxAdc<'static, A>,
3535
adc_channel: A::Channel,
@@ -45,7 +45,7 @@ impl<A: 'static + adc::Adc> TemperatureRp2040Component<A> {
4545
}
4646
}
4747

48-
impl<A: 'static + adc::Adc> Component for TemperatureRp2040Component<A> {
48+
impl<A: 'static + adc::Adc<'static>> Component for TemperatureRp2040Component<A> {
4949
type StaticInput = (
5050
&'static mut MaybeUninit<AdcDevice<'static, A>>,
5151
&'static mut MaybeUninit<TemperatureRp2040<'static>>,

boards/components/src/temperature_stm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ macro_rules! temperature_stm_adc_component_static {
2222
};};
2323
}
2424

25-
pub struct TemperatureSTMComponent<A: 'static + adc::Adc> {
25+
pub struct TemperatureSTMComponent<A: 'static + adc::Adc<'static>> {
2626
adc_mux: &'static capsules_core::virtualizers::virtual_adc::MuxAdc<'static, A>,
2727
adc_channel: A::Channel,
2828
slope: f32,
2929
v_25: f32,
3030
}
3131

32-
impl<A: 'static + adc::Adc> TemperatureSTMComponent<A> {
32+
impl<A: 'static + adc::Adc<'static>> TemperatureSTMComponent<A> {
3333
pub fn new(
3434
adc_mux: &'static capsules_core::virtualizers::virtual_adc::MuxAdc<'static, A>,
3535
adc_channel: A::Channel,
@@ -45,7 +45,7 @@ impl<A: 'static + adc::Adc> TemperatureSTMComponent<A> {
4545
}
4646
}
4747

48-
impl<A: 'static + adc::Adc> Component for TemperatureSTMComponent<A> {
48+
impl<A: 'static + adc::Adc<'static>> Component for TemperatureSTMComponent<A> {
4949
type StaticInput = (
5050
&'static mut MaybeUninit<AdcDevice<'static, A>>,
5151
&'static mut MaybeUninit<TemperatureSTM<'static>>,

boards/hail/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ struct Hail {
8282
>,
8383
>,
8484
nrf51822: &'static capsules_extra::nrf51822_serialization::Nrf51822Serialization<'static>,
85-
adc: &'static capsules_core::adc::AdcDedicated<'static, sam4l::adc::Adc>,
85+
adc: &'static capsules_core::adc::AdcDedicated<'static, sam4l::adc::Adc<'static>>,
8686
led: &'static capsules_core::led::LedDriver<
8787
'static,
8888
LedLow<'static, sam4l::gpio::GPIOPin<'static>>,

boards/imix/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ struct Imix {
138138
temp: &'static capsules_extra::temperature::TemperatureSensor<'static>,
139139
humidity: &'static capsules_extra::humidity::HumiditySensor<'static>,
140140
ambient_light: &'static capsules_extra::ambient_light::AmbientLight<'static>,
141-
adc: &'static capsules_core::adc::AdcDedicated<'static, sam4l::adc::Adc>,
141+
adc: &'static capsules_core::adc::AdcDedicated<'static, sam4l::adc::Adc<'static>>,
142142
led: &'static capsules_core::led::LedDriver<
143143
'static,
144144
LedHigh<'static, sam4l::gpio::GPIOPin<'static>>,

capsules/core/src/adc.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub const DRIVER_NUM: usize = driver::NUM::Adc as usize;
7272
/// Virtualized, and can be use by multiple applications at the same time;
7373
/// requests are queued. Does not support continuous or high-speed sampling.
7474
pub struct AdcVirtualized<'a> {
75-
drivers: &'a [&'a dyn hil::adc::AdcChannel],
75+
drivers: &'a [&'a dyn hil::adc::AdcChannel<'a>],
7676
apps: Grant<AppSys, UpcallCount<1>, AllowRoCount<0>, AllowRwCount<0>>,
7777
current_process: OptionalCell<ProcessId>,
7878
}
@@ -81,10 +81,10 @@ pub struct AdcVirtualized<'a> {
8181
/// Not currently virtualized: does not share the ADC with other capsules
8282
/// and only one application can use it at a time. Supports continuous and
8383
/// high speed sampling.
84-
pub struct AdcDedicated<'a, A: hil::adc::Adc + hil::adc::AdcHighSpeed> {
84+
pub struct AdcDedicated<'a, A: hil::adc::Adc<'a> + hil::adc::AdcHighSpeed<'a>> {
8585
// ADC driver
8686
adc: &'a A,
87-
channels: &'a [<A as hil::adc::Adc>::Channel],
87+
channels: &'a [<A as hil::adc::Adc<'a>>::Channel],
8888

8989
// ADC state
9090
active: Cell<bool>,
@@ -155,7 +155,7 @@ impl Default for AppSys {
155155
/// swap. In testing, it seems to keep up fine.
156156
pub const BUF_LEN: usize = 128;
157157

158-
impl<'a, A: hil::adc::Adc + hil::adc::AdcHighSpeed> AdcDedicated<'a, A> {
158+
impl<'a, A: hil::adc::Adc<'a> + hil::adc::AdcHighSpeed<'a>> AdcDedicated<'a, A> {
159159
/// Create a new `Adc` application interface.
160160
///
161161
/// - `adc` - ADC driver to provide application access to
@@ -165,7 +165,7 @@ impl<'a, A: hil::adc::Adc + hil::adc::AdcHighSpeed> AdcDedicated<'a, A> {
165165
pub fn new(
166166
adc: &'a A,
167167
grant: Grant<App, UpcallCount<1>, AllowRoCount<0>, AllowRwCount<2>>,
168-
channels: &'a [<A as hil::adc::Adc>::Channel],
168+
channels: &'a [<A as hil::adc::Adc<'a>>::Channel],
169169
adc_buf1: &'static mut [u16; 128],
170170
adc_buf2: &'static mut [u16; 128],
171171
adc_buf3: &'static mut [u16; 128],
@@ -639,7 +639,7 @@ impl<'a> AdcVirtualized<'a> {
639639
///
640640
/// - `drivers` - Virtual ADC drivers to provide application access to
641641
pub fn new(
642-
drivers: &'a [&'a dyn hil::adc::AdcChannel],
642+
drivers: &'a [&'a dyn hil::adc::AdcChannel<'a>],
643643
grant: Grant<AppSys, UpcallCount<1>, AllowRoCount<0>, AllowRwCount<0>>,
644644
) -> AdcVirtualized<'a> {
645645
AdcVirtualized {
@@ -730,7 +730,9 @@ impl<'a> AdcVirtualized<'a> {
730730
}
731731

732732
/// Callbacks from the ADC driver
733-
impl<A: hil::adc::Adc + hil::adc::AdcHighSpeed> hil::adc::Client for AdcDedicated<'_, A> {
733+
impl<'a, A: hil::adc::Adc<'a> + hil::adc::AdcHighSpeed<'a>> hil::adc::Client
734+
for AdcDedicated<'a, A>
735+
{
734736
/// Single sample operation complete.
735737
///
736738
/// Collects the sample and provides a callback to the application.
@@ -810,7 +812,9 @@ impl<A: hil::adc::Adc + hil::adc::AdcHighSpeed> hil::adc::Client for AdcDedicate
810812
}
811813

812814
/// Callbacks from the High Speed ADC driver
813-
impl<A: hil::adc::Adc + hil::adc::AdcHighSpeed> hil::adc::HighSpeedClient for AdcDedicated<'_, A> {
815+
impl<'a, A: hil::adc::Adc<'a> + hil::adc::AdcHighSpeed<'a>> hil::adc::HighSpeedClient
816+
for AdcDedicated<'a, A>
817+
{
814818
/// Internal buffer has filled from a buffered sampling operation.
815819
/// Copies data over to application buffer, determines if more data is
816820
/// needed, and performs a callback to the application if ready. If
@@ -1142,7 +1146,7 @@ impl<A: hil::adc::Adc + hil::adc::AdcHighSpeed> hil::adc::HighSpeedClient for Ad
11421146
}
11431147

11441148
/// Implementations of application syscalls
1145-
impl<A: hil::adc::Adc + hil::adc::AdcHighSpeed> SyscallDriver for AdcDedicated<'_, A> {
1149+
impl<'a, A: hil::adc::Adc<'a> + hil::adc::AdcHighSpeed<'a>> SyscallDriver for AdcDedicated<'a, A> {
11461150
/// Method for the application to command or query this driver.
11471151
///
11481152
/// - `command_num` - which command call this is

capsules/core/src/virtualizers/virtual_adc.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ use kernel::utilities::cells::OptionalCell;
1212
use kernel::ErrorCode;
1313

1414
/// ADC Mux
15-
pub struct MuxAdc<'a, A: hil::adc::Adc> {
15+
pub struct MuxAdc<'a, A: hil::adc::Adc<'a>> {
1616
adc: &'a A,
1717
devices: List<'a, AdcDevice<'a, A>>,
1818
inflight: OptionalCell<&'a AdcDevice<'a, A>>,
1919
}
2020

21-
impl<'a, A: hil::adc::Adc> hil::adc::Client for MuxAdc<'a, A> {
21+
impl<'a, A: hil::adc::Adc<'a>> hil::adc::Client for MuxAdc<'a, A> {
2222
fn sample_ready(&self, sample: u16) {
2323
self.inflight.take().map(|inflight| {
2424
for node in self.devices.iter() {
@@ -35,7 +35,7 @@ impl<'a, A: hil::adc::Adc> hil::adc::Client for MuxAdc<'a, A> {
3535
}
3636
}
3737

38-
impl<'a, A: hil::adc::Adc> MuxAdc<'a, A> {
38+
impl<'a, A: hil::adc::Adc<'a>> MuxAdc<'a, A> {
3939
pub const fn new(adc: &'a A) -> MuxAdc<'a, A> {
4040
MuxAdc {
4141
adc: adc,
@@ -78,15 +78,15 @@ pub(crate) enum Operation {
7878
}
7979

8080
/// Virtual ADC device
81-
pub struct AdcDevice<'a, A: hil::adc::Adc> {
81+
pub struct AdcDevice<'a, A: hil::adc::Adc<'a>> {
8282
mux: &'a MuxAdc<'a, A>,
8383
channel: A::Channel,
8484
operation: OptionalCell<Operation>,
8585
next: ListLink<'a, AdcDevice<'a, A>>,
8686
client: OptionalCell<&'a dyn hil::adc::Client>,
8787
}
8888

89-
impl<'a, A: hil::adc::Adc> AdcDevice<'a, A> {
89+
impl<'a, A: hil::adc::Adc<'a>> AdcDevice<'a, A> {
9090
pub const fn new(mux: &'a MuxAdc<'a, A>, channel: A::Channel) -> AdcDevice<'a, A> {
9191
let adc_user = AdcDevice {
9292
mux: mux,
@@ -103,13 +103,13 @@ impl<'a, A: hil::adc::Adc> AdcDevice<'a, A> {
103103
}
104104
}
105105

106-
impl<'a, A: hil::adc::Adc> ListNode<'a, AdcDevice<'a, A>> for AdcDevice<'a, A> {
106+
impl<'a, A: hil::adc::Adc<'a>> ListNode<'a, AdcDevice<'a, A>> for AdcDevice<'a, A> {
107107
fn next(&'a self) -> &'a ListLink<'a, AdcDevice<'a, A>> {
108108
&self.next
109109
}
110110
}
111111

112-
impl<A: hil::adc::Adc> hil::adc::AdcChannel for AdcDevice<'_, A> {
112+
impl<'a, A: hil::adc::Adc<'a>> hil::adc::AdcChannel<'a> for AdcDevice<'a, A> {
113113
fn sample(&self) -> Result<(), ErrorCode> {
114114
self.operation.set(Operation::OneSample);
115115
self.mux.do_next_op();
@@ -133,7 +133,7 @@ impl<A: hil::adc::Adc> hil::adc::AdcChannel for AdcDevice<'_, A> {
133133
fn get_voltage_reference_mv(&self) -> Option<usize> {
134134
self.mux.get_voltage_reference_mv()
135135
}
136-
fn set_client(&self, client: &'static dyn hil::adc::Client) {
136+
fn set_client(&self, client: &'a dyn hil::adc::Client) {
137137
self.client.set(client);
138138
}
139139
}

capsules/extra/src/adc_microphone.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ enum State {
1818
}
1919

2020
pub struct AdcMicrophone<'a, P: gpio::Pin> {
21-
adc: &'a dyn adc::AdcChannel,
21+
adc: &'a dyn adc::AdcChannel<'a>,
2222
enable_pin: Option<&'a P>,
2323
spl_client: OptionalCell<&'a dyn SoundPressureClient>,
2424
spl_buffer: TakeCell<'a, [u16]>,
@@ -28,7 +28,7 @@ pub struct AdcMicrophone<'a, P: gpio::Pin> {
2828

2929
impl<'a, P: gpio::Pin> AdcMicrophone<'a, P> {
3030
pub fn new(
31-
adc: &'a dyn adc::AdcChannel,
31+
adc: &'a dyn adc::AdcChannel<'a>,
3232
enable_pin: Option<&'a P>,
3333
spl_buffer: &'a mut [u16],
3434
) -> AdcMicrophone<'a, P> {

0 commit comments

Comments
 (0)