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

api: adc: exists needs to handle number of channels #485

Merged
merged 4 commits into from
Aug 8, 2023
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
11 changes: 10 additions & 1 deletion apis/adc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ impl<S: Syscalls> Adc<S> {
/// Returns Ok() if the driver was present.This does not necessarily mean
/// that the driver is working.
pub fn exists() -> Result<(), ErrorCode> {
S::command(DRIVER_NUM, EXISTS, 0, 0).to_result()
// Note! The "exists" command should return directly return `Result<(),
// ErrorCode>` (i.e. with no `.and()` call), but the current ADC driver
// in the kernel returns the number of ADC channels instead of just
// success. This will be fixed in a future release of Tock, but for now
// we workaround this issue.
//
// https://github.com/tock/tock/issues/3375
S::command(DRIVER_NUM, EXISTS, 0, 0)
.to_result::<u32, ErrorCode>()
.and(Ok(()))
}

// Initiate a sample reading
Expand Down
2 changes: 1 addition & 1 deletion unittest/src/fake/adc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl crate::fake::SyscallDriver for Adc {

fn command(&self, command_id: u32, _argument0: u32, _argument1: u32) -> CommandReturn {
match command_id {
EXISTS => crate::command_return::success(),
EXISTS => crate::command_return::success_u32(1),

SINGLE_SAMPLE => {
if self.busy.get() {
Expand Down
4 changes: 2 additions & 2 deletions unittest/src/fake/adc/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use libtock_platform::{share, DefaultConfig, YieldNoWaitReturn};
fn command() {
let adc = Adc::new();

assert!(adc.command(EXISTS, 1, 2).is_success());
assert!(adc.command(EXISTS, 1, 2).is_success_u32());

assert!(adc.command(SINGLE_SAMPLE, 0, 0).is_success());

Expand All @@ -33,7 +33,7 @@ fn kernel_integration() {
let kernel = fake::Kernel::new();
let adc = Adc::new();
kernel.add_driver(&adc);
assert!(fake::Syscalls::command(DRIVER_NUM, EXISTS, 1, 2).is_success());
assert!(fake::Syscalls::command(DRIVER_NUM, EXISTS, 1, 2).is_success_u32());
assert!(fake::Syscalls::command(DRIVER_NUM, SINGLE_SAMPLE, 0, 0).is_success());
assert_eq!(
fake::Syscalls::command(DRIVER_NUM, SINGLE_SAMPLE, 0, 0).get_failure(),
Expand Down
Loading