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

Add ADC Channel parameter to the ADC API #555

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion apis/peripherals/adc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub struct ADCListener<F: Fn(u16)>(pub F);

impl<F: Fn(u16)> Upcall<OneId<DRIVER_NUM, 0>> for ADCListener<F> {
fn upcall(&self, _adc_mode: u32, _channel: u32, sample: u32) {
self.0(sample as u32 as u16)
self.0(sample as u16)
}
}

Expand Down
11 changes: 9 additions & 2 deletions examples/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ fn main() {
writeln!(Console::writer(), "adc driver unavailable").unwrap();
return;
}
//getting the number of channels
let number_channels: usize = match Adc::get_number_of_channels() {
Ok(channel) => channel as usize,
Err(_) => {
writeln!(Console::writer(), "can't get number of channels").unwrap();
return;
}
};
nikkoxp marked this conversation as resolved.
Show resolved Hide resolved
loop {
//testing for channels 0, 1 and 2
for i in 0..2 {
for i in 0..number_channels {
match Adc::read_single_sample_sync(i) {
Ok(adc_val) => writeln!(Console::writer(), "Sample: {}\n", adc_val).unwrap(),
Err(_) => writeln!(Console::writer(), "error while reading sample",).unwrap(),
Expand Down
Loading