From 269d9ef1710ffce32f0b473cb3c04d212b24b0f2 Mon Sep 17 00:00:00 2001 From: Brad Campbell Date: Wed, 9 Oct 2024 12:31:24 -0400 Subject: [PATCH] use ! as default 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. --- boards/components/src/lib.rs | 4 ++++ .../nrf52840dk-test-appid-sha256/src/main.rs | 1 - kernel/src/hil/pwm.rs | 21 +++++++++++++++++++ kernel/src/lib.rs | 1 + 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/boards/components/src/lib.rs b/boards/components/src/lib.rs index 48be3eeab9..9c8e32ed7e 100644 --- a/boards/components/src/lib.rs +++ b/boards/components/src/lib.rs @@ -3,6 +3,7 @@ // Copyright Tock Contributors 2022. #![feature(associated_type_defaults)] +#![feature(never_type)] #![no_std] pub mod adc; @@ -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; @@ -117,5 +119,7 @@ pub trait ComponentTypes<'a> { type LedType: Led; type LedDriver: SyscallDriver = (); + type PwmType: Pwm = !; + fn get_alarm(&self) -> &Self::AlarmType; } diff --git a/boards/configurations/nrf52840dk/nrf52840dk-test-appid-sha256/src/main.rs b/boards/configurations/nrf52840dk/nrf52840dk-test-appid-sha256/src/main.rs index ed060c595f..6e6ef24b82 100644 --- a/boards/configurations/nrf52840dk/nrf52840dk-test-appid-sha256/src/main.rs +++ b/boards/configurations/nrf52840dk/nrf52840dk-test-appid-sha256/src/main.rs @@ -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. diff --git a/kernel/src/hil/pwm.rs b/kernel/src/hil/pwm.rs index 3bf943897c..d219a1cbb1 100644 --- a/kernel/src/hil/pwm.rs +++ b/kernel/src/hil/pwm.rs @@ -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 + } +} diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 65b8443cd8..4c066f3925 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -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]