Skip to content
Closed
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ version = "0.1.0"
[workspace.package]
# This must be kept in sync with rust-toolchain.toml; please see that file for
# more information.
rust-version = "1.77"
rust-version = "1.87"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be split out into a separate PR

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. Looking at the individual commits, it seems like there are 3 separate PRs here (Rust update, const ASM, and something about a heap setup?).

The Rust update is the largest one because of all the clippy-induced refactorings.


[features]
rust_embedded = [
Expand Down
43 changes: 21 additions & 22 deletions apis/interface/buttons/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
#![no_std]
//! The Buttons driver
//!
//! # Example
//! ```ignore
//! use libtock::Buttons;
//!
//! // Read button state
//! Buttons::is_pressed(0);
//!
//! // Register for events
//!
//! let listener = ButtonListener(|button, state| {
//! // make use of the button's state
//! });
//!
//! share::scope(|subscribe| {
//! if let Ok(()) = Buttons::register_listener(&listener, subscribe) {
//! // yield
//! }
//! });
//! ```

use libtock_platform::{
share::Handle, subscribe::OneId, DefaultConfig, ErrorCode, Subscribe, Syscalls, Upcall,
};

/// The Buttons driver
///
/// # Example
/// ```ignore
/// use libtock::Buttons;
///
/// // Read button state
/// Buttons::is_pressed(0);
///
/// // Register for events
///
/// let listener = ButtonListener(|button, state| {
/// // make use of the button's state
/// });
///
/// share::scope(|subscribe| {
/// if let Ok(()) = Buttons::register_listener(&listener, subscribe) {
/// // yield
/// }
/// });
/// ```

pub struct Buttons<S: Syscalls>(S);

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
Expand Down
1 change: 0 additions & 1 deletion apis/interface/leds/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use libtock_platform::{ErrorCode, Syscalls};
/// // Turn on led 0
/// let _ = Leds::on(0);
/// ```

pub struct Leds<S: Syscalls>(S);

impl<S: Syscalls> Leds<S> {
Expand Down
1 change: 0 additions & 1 deletion apis/kernel/low_level_debug/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use libtock_platform::Syscalls;
/// // Prints 0x45 and the app which called it.
/// LowLevelDebug::print_1(0x45);
/// ```

pub struct LowLevelDebug<S: Syscalls>(S);

impl<S: Syscalls> LowLevelDebug<S> {
Expand Down
12 changes: 8 additions & 4 deletions apis/net/ieee802154/src/rx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const EMPTY_FRAME: Frame = Frame {

/// The ring buffer that is shared with kernel using allow-rw syscall, with kernel acting
/// as a producer of frames and we acting a consumer.

///
/// The `N` parameter specifies the capacity of the buffer in number of frames.
/// Unfortunately, due to a design flaw of the ring buffer, it can never be fully utilised,
/// as it's impossible to distinguish an empty buffer from a full one. The kernel code
Expand Down Expand Up @@ -52,6 +52,12 @@ pub struct RxRingBuffer<const N: usize> {
frames: [Frame; N],
}

impl<const N: usize> Default for RxRingBuffer<N> {
fn default() -> Self {
Self::new()
}
}

impl<const N: usize> RxRingBuffer<N> {
/// Creates a new [RxRingBuffer] that can be used to receive frames into.
pub const fn new() -> Self {
Expand Down Expand Up @@ -116,9 +122,7 @@ impl<'buf, const N: usize, S: Syscalls, C: Config> RxSingleBufferOperator<'buf,
}
}
}
impl<'buf, const N: usize, S: Syscalls, C: Config> RxOperator
for RxSingleBufferOperator<'buf, N, S, C>
{
impl<const N: usize, S: Syscalls, C: Config> RxOperator for RxSingleBufferOperator<'_, N, S, C> {
fn receive_frame(&mut self) -> Result<&mut Frame, ErrorCode> {
if self.buf.has_frame() {
Ok(self.buf.next_frame())
Expand Down
19 changes: 9 additions & 10 deletions apis/peripherals/alarm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#![no_std]
//! The alarm driver
//!
//! # Example
//! ```ignore
//! use libtock2::Alarm;
//!
//! // Wait for timeout
//! Alarm::sleep(Alarm::Milliseconds(2500));
//! ```

use core::cell::Cell;
use libtock_platform as platform;
use libtock_platform::share;
use libtock_platform::{DefaultConfig, ErrorCode, Syscalls};

/// The alarm driver
///
/// # Example
/// ```ignore
/// use libtock2::Alarm;
///
/// // Wait for timeout
/// Alarm::sleep(Alarm::Milliseconds(2500));
/// ```

pub struct Alarm<S: Syscalls, C: platform::subscribe::Config = DefaultConfig>(S, C);

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
Expand Down
29 changes: 14 additions & 15 deletions apis/peripherals/gpio/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
#![no_std]
//! The GPIO driver.
//!
//! # Example
//! ```ignore
//! use libtock::gpio;
//!
//! // Set pin to high.
//! let pin = gpio::Gpio::get_pin(0).unwrap().make_output().unwrap();
//! let _ = pin.set();
//! ```

use core::marker::PhantomData;

use libtock_platform::{
share::Handle, subscribe::OneId, DefaultConfig, ErrorCode, Subscribe, Syscalls, Upcall,
};

/// The GPIO driver.
///
/// # Example
/// ```ignore
/// use libtock::gpio;
///
/// // Set pin to high.
/// let pin = gpio::Gpio::get_pin(0).unwrap().make_output().unwrap();
/// let _ = pin.set();
/// ```

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum GpioState {
Low = 0,
Expand Down Expand Up @@ -145,7 +144,7 @@ pub struct OutputPin<'a, S: Syscalls> {
pin: &'a Pin<S>,
}

impl<'a, S: Syscalls> OutputPin<'a, S> {
impl<S: Syscalls> OutputPin<'_, S> {
pub fn toggle(&mut self) -> Result<(), ErrorCode> {
Gpio::<S>::toggle(self.pin.pin_number)
}
Expand All @@ -162,7 +161,7 @@ pub struct InputPin<'a, S: Syscalls, P: Pull> {
_pull: PhantomData<P>,
}

impl<'a, S: Syscalls, P: Pull> InputPin<'a, S, P> {
impl<S: Syscalls, P: Pull> InputPin<'_, S, P> {
pub fn read(&self) -> Result<GpioState, ErrorCode> {
Gpio::<S>::read(self.pin.pin_number)
}
Expand Down Expand Up @@ -232,12 +231,12 @@ impl<S: Syscalls> Gpio<S> {
}

#[cfg(feature = "rust_embedded")]
impl<'a, S: Syscalls> embedded_hal::digital::ErrorType for OutputPin<'a, S> {
impl<S: Syscalls> embedded_hal::digital::ErrorType for OutputPin<'_, S> {
type Error = ErrorCode;
}

#[cfg(feature = "rust_embedded")]
impl<'a, S: Syscalls> embedded_hal::digital::OutputPin for OutputPin<'a, S> {
impl<S: Syscalls> embedded_hal::digital::OutputPin for OutputPin<'_, S> {
fn set_low(&mut self) -> Result<(), Self::Error> {
self.clear()
}
Expand Down
2 changes: 1 addition & 1 deletion demos/st7789-slint/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ unsafe fn setup_heap() {

const HEAP_SIZE: usize = 1024 * 6;
static mut HEAP_MEM: [MaybeUninit<u8>; HEAP_SIZE] = [MaybeUninit::uninit(); HEAP_SIZE];
unsafe { HEAP.init(HEAP_MEM.as_ptr() as usize, HEAP_SIZE) }
unsafe { HEAP.init(&raw mut HEAP_MEM as usize, HEAP_SIZE) }
}

// Display
Expand Down
2 changes: 1 addition & 1 deletion nightly/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This is the nightly Rust toolchain used by `make test`.
[toolchain]
channel = "nightly-2024-11-11"
channel = "nightly-2025-05-19"
components = ["miri", "rust-src"]
1 change: 0 additions & 1 deletion panic_handlers/debug_panic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use libtock_platform::{ErrorCode, Syscalls};
use libtock_runtime::TockSyscalls;

/// This handler requires some 0x400 bytes of stack

#[panic_handler]
fn panic_handler(info: &core::panic::PanicInfo) -> ! {
// Signal a panic using the LowLevelDebug capsule (if available).
Expand Down
12 changes: 6 additions & 6 deletions platform/src/allow_ro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub struct AllowRo<'share, S: Syscalls, const DRIVER_NUM: u32, const BUFFER_NUM:
// We can't derive(Default) because S is not Default, and derive(Default)
// generates a Default implementation that requires S to be Default. Instead, we
// manually implement Default.
impl<'share, S: Syscalls, const DRIVER_NUM: u32, const BUFFER_NUM: u32> Default
for AllowRo<'share, S, DRIVER_NUM, BUFFER_NUM>
impl<S: Syscalls, const DRIVER_NUM: u32, const BUFFER_NUM: u32> Default
for AllowRo<'_, S, DRIVER_NUM, BUFFER_NUM>
{
fn default() -> Self {
Self {
Expand All @@ -45,16 +45,16 @@ impl<'share, S: Syscalls, const DRIVER_NUM: u32, const BUFFER_NUM: u32> Default
}
}

impl<'share, S: Syscalls, const DRIVER_NUM: u32, const BUFFER_NUM: u32> Drop
for AllowRo<'share, S, DRIVER_NUM, BUFFER_NUM>
impl<S: Syscalls, const DRIVER_NUM: u32, const BUFFER_NUM: u32> Drop
for AllowRo<'_, S, DRIVER_NUM, BUFFER_NUM>
{
fn drop(&mut self) {
S::unallow_ro(DRIVER_NUM, BUFFER_NUM);
}
}

impl<'share, S: Syscalls, const DRIVER_NUM: u32, const BUFFER_NUM: u32> List
for AllowRo<'share, S, DRIVER_NUM, BUFFER_NUM>
impl<S: Syscalls, const DRIVER_NUM: u32, const BUFFER_NUM: u32> List
for AllowRo<'_, S, DRIVER_NUM, BUFFER_NUM>
{
}

Expand Down
12 changes: 6 additions & 6 deletions platform/src/allow_rw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub struct AllowRw<'share, S: Syscalls, const DRIVER_NUM: u32, const BUFFER_NUM:
// We can't derive(Default) because S is not Default, and derive(Default)
// generates a Default implementation that requires S to be Default. Instead, we
// manually implement Default.
impl<'share, S: Syscalls, const DRIVER_NUM: u32, const BUFFER_NUM: u32> Default
for AllowRw<'share, S, DRIVER_NUM, BUFFER_NUM>
impl<S: Syscalls, const DRIVER_NUM: u32, const BUFFER_NUM: u32> Default
for AllowRw<'_, S, DRIVER_NUM, BUFFER_NUM>
{
fn default() -> Self {
Self {
Expand All @@ -45,16 +45,16 @@ impl<'share, S: Syscalls, const DRIVER_NUM: u32, const BUFFER_NUM: u32> Default
}
}

impl<'share, S: Syscalls, const DRIVER_NUM: u32, const BUFFER_NUM: u32> Drop
for AllowRw<'share, S, DRIVER_NUM, BUFFER_NUM>
impl<S: Syscalls, const DRIVER_NUM: u32, const BUFFER_NUM: u32> Drop
for AllowRw<'_, S, DRIVER_NUM, BUFFER_NUM>
{
fn drop(&mut self) {
S::unallow_rw(DRIVER_NUM, BUFFER_NUM);
}
}

impl<'share, S: Syscalls, const DRIVER_NUM: u32, const BUFFER_NUM: u32> List
for AllowRw<'share, S, DRIVER_NUM, BUFFER_NUM>
impl<S: Syscalls, const DRIVER_NUM: u32, const BUFFER_NUM: u32> List
for AllowRw<'_, S, DRIVER_NUM, BUFFER_NUM>
{
}

Expand Down
14 changes: 9 additions & 5 deletions platform/src/command_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl CommandReturn {
if !self.is_failure() {
return None;
}
Some(unsafe { transmute(self.r1) })
Some(unsafe { transmute::<u32, ErrorCode>(self.r1) })
}

/// Returns the error code and value if this CommandReturn is of type
Expand All @@ -148,7 +148,7 @@ impl CommandReturn {
if !self.is_failure_u32() {
return None;
}
Some((unsafe { transmute(self.r1) }, self.r2))
Some((unsafe { transmute::<u32, ErrorCode>(self.r1) }, self.r2))
}

/// Returns the error code and return values if this CommandReturn is of
Expand All @@ -157,7 +157,11 @@ impl CommandReturn {
if !self.is_failure_2_u32() {
return None;
}
Some((unsafe { transmute(self.r1) }, self.r2, self.r3))
Some((
unsafe { transmute::<u32, ErrorCode>(self.r1) },
self.r2,
self.r3,
))
}

/// Returns the error code and return value if this CommandReturn is of type
Expand All @@ -167,7 +171,7 @@ impl CommandReturn {
return None;
}
Some((
unsafe { transmute(self.r1) },
unsafe { transmute::<u32, ErrorCode>(self.r1) },
self.r2 as u64 + ((self.r3 as u64) << 32),
))
}
Expand Down Expand Up @@ -244,7 +248,7 @@ impl CommandReturn {
let ec: ErrorCode = if return_variant == E::RETURN_VARIANT {
// Safety: E::RETURN_VARIANT must be a failure variant, and
// failure variants must contain a valid ErrorCode in r1.
unsafe { transmute(r1) }
unsafe { transmute::<u32, ErrorCode>(r1) }
} else {
r2 = 0;
r3 = 0;
Expand Down
2 changes: 1 addition & 1 deletion platform/src/error_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl TryFrom<u32> for ErrorCode {

fn try_from(value: u32) -> Result<Self, Self::Error> {
if (1..=1024).contains(&value) {
Ok(unsafe { transmute(value) })
Ok(unsafe { transmute::<u32, ErrorCode>(value) })
} else {
Err(NotAnErrorCode)
}
Expand Down
1 change: 0 additions & 1 deletion platform/src/raw_syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::Register;
/// # Safety
/// `RawSyscalls` is unsafe because `unsafe` code depends on its methods to
/// return the correct register values.

// The RawSyscalls trait is designed to minimize the complexity and size of its
// implementation, as its implementation is difficult to test (it cannot be used
// in unit tests, with sanitizers, or in Miri). It is also designed to minimize
Expand Down
4 changes: 2 additions & 2 deletions platform/src/share/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ pub struct Handle<'handle, L: List> {
// We can't #[derive(Clone, Copy)] because derive's implementations of Clone and
// Copy have `L: Clone` and `L: Copy` constraints, respectively. We don't want
// those constraints, so we manually implement Clone and Copy.
impl<'handle, L: List> Clone for Handle<'handle, L> {
impl<L: List> Clone for Handle<'_, L> {
fn clone(&self) -> Self {
*self
}
}

impl<'handle, L: List> Copy for Handle<'handle, L> {}
impl<L: List> Copy for Handle<'_, L> {}

impl<'handle, L: List> Handle<'handle, L> {
/// Constructs a new `Handle`, typing its lifetime to the provided list.
Expand Down
Loading