Skip to content

Commit

Permalink
use ! as default
Browse files Browse the repository at this point in the history
This allows boards that don't have certain functionality to ignore it
while not allowing fake implementations to be created that don't
actually do anything.
  • Loading branch information
bradjc committed Oct 9, 2024
1 parent 61c8471 commit 269d9ef
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions boards/components/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Copyright Tock Contributors 2022.

#![feature(associated_type_defaults)]
#![feature(never_type)]
#![no_std]

pub mod adc;
Expand Down Expand Up @@ -99,6 +100,7 @@ pub mod udp_mux;
pub mod usb;

use kernel::hil::led::Led;
use kernel::hil::pwm::Pwm;
use kernel::hil::time::Alarm;
use kernel::platform::chip::Chip;
use kernel::process::Process;
Expand All @@ -117,5 +119,7 @@ pub trait ComponentTypes<'a> {
type LedType: Led;
type LedDriver: SyscallDriver = ();

type PwmType: Pwm = !;

fn get_alarm(&self) -> &Self::AlarmType;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

//! Tock kernel for the Nordic Semiconductor nRF52840 development kit (DK).

#![feature(associated_type_defaults)]
#![no_std]
// Disable this attribute when documenting, as a workaround for
// https://github.com/rust-lang/rust/issues/62184.
Expand Down
21 changes: 21 additions & 0 deletions kernel/src/hil/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,24 @@ pub trait PwmPin {
/// Same as the `get_maximum_duty_cycle` function in the `Pwm` trait.
fn get_maximum_duty_cycle(&self) -> usize;
}

impl Pwm for ! {
type Pin = ();
fn start(
&self,
_pin: &Self::Pin,
_frequency_hz: usize,
_duty_cycle: usize,
) -> Result<(), ErrorCode> {
Err(ErrorCode::NOSUPPORT)
}
fn stop(&self, _pin: &Self::Pin) -> Result<(), ErrorCode> {
Err(ErrorCode::NOSUPPORT)
}
fn get_maximum_frequency_hz(&self) -> usize {
0
}
fn get_maximum_duty_cycle(&self) -> usize {
0
}
}
1 change: 1 addition & 0 deletions kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
//! this use case. It is likely we will have to create new interfaces as new
//! use cases are discovered.

#![feature(never_type)]
#![warn(unreachable_pub)]
#![no_std]

Expand Down

0 comments on commit 269d9ef

Please sign in to comment.