From 26732972803634989dc8c20e6e67df0b2c7d031e Mon Sep 17 00:00:00 2001 From: Julien Cretin Date: Wed, 12 Apr 2023 15:29:50 +0200 Subject: [PATCH 1/6] Support architectures without atomics with polyfill --- Cargo.toml | 1 + src/bus.rs | 2 +- src/endpoint.rs | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e1da13e..0a1b32d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ authors = ["Matti Virkkunen "] repository = "https://github.com/mvirkkunen/usb-device" [dependencies] +atomic-polyfill = "1.0.2" defmt = { version = "0.3", optional = true } [dev-dependencies] diff --git a/src/bus.rs b/src/bus.rs index dd0f0ba..c250f76 100644 --- a/src/bus.rs +++ b/src/bus.rs @@ -6,7 +6,7 @@ use crate::{Result, UsbDirection, UsbError}; use core::cell::RefCell; use core::mem; use core::ptr; -use core::sync::atomic::{AtomicPtr, Ordering}; +use atomic_polyfill::{AtomicPtr, Ordering}; /// A trait for device-specific USB peripherals. Implement this to add support for a new hardware /// platform. diff --git a/src/endpoint.rs b/src/endpoint.rs index de7c75f..a503cc5 100644 --- a/src/endpoint.rs +++ b/src/endpoint.rs @@ -1,7 +1,7 @@ use crate::bus::UsbBus; use crate::{Result, UsbDirection}; use core::marker::PhantomData; -use core::sync::atomic::{AtomicPtr, Ordering}; +use atomic_polyfill::{AtomicPtr, Ordering}; /// Trait for endpoint type markers. pub trait EndpointDirection { From 8291ac0ee1ec57ba992d13334db7d4b455d3ef1e Mon Sep 17 00:00:00 2001 From: Julien Cretin Date: Mon, 24 Apr 2023 17:36:14 +0200 Subject: [PATCH 2/6] Fix formatting --- src/bus.rs | 2 +- src/endpoint.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bus.rs b/src/bus.rs index c250f76..ea6bbc5 100644 --- a/src/bus.rs +++ b/src/bus.rs @@ -3,10 +3,10 @@ use crate::endpoint::{ IsochronousUsageType, }; use crate::{Result, UsbDirection, UsbError}; +use atomic_polyfill::{AtomicPtr, Ordering}; use core::cell::RefCell; use core::mem; use core::ptr; -use atomic_polyfill::{AtomicPtr, Ordering}; /// A trait for device-specific USB peripherals. Implement this to add support for a new hardware /// platform. diff --git a/src/endpoint.rs b/src/endpoint.rs index a503cc5..d465e8f 100644 --- a/src/endpoint.rs +++ b/src/endpoint.rs @@ -1,7 +1,7 @@ use crate::bus::UsbBus; use crate::{Result, UsbDirection}; -use core::marker::PhantomData; use atomic_polyfill::{AtomicPtr, Ordering}; +use core::marker::PhantomData; /// Trait for endpoint type markers. pub trait EndpointDirection { From dd0e0df775dc3f99f6d3bc593d3b147a129a3d2c Mon Sep 17 00:00:00 2001 From: Julien Cretin Date: Mon, 24 Apr 2023 17:52:35 +0200 Subject: [PATCH 3/6] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21d83ff..b9ec7a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. * New enums and allocators for Isochronous endpoints ([#60](https://github.com/rust-embedded-community/usb-device/pull/60)). * Ability to select USB revision ([#116](https://github.com/rust-embedded-community/usb-device/pull/116)). * Added support for alternate settings on interfaces ([#114](https://github.com/rust-embedded-community/usb-device/pull/114)). +* Added support for architectures without atomics ([#115](https://github.com/rust-embedded-community/usb-device/pull/115)). ### Changed * `EndpointType` enum now has fields for isochronous synchronization and usage ([#60](https://github.com/rust-embedded-community/usb-device/pull/60)). From 8f4ace5ee89abc0fc1e728dc20f32963cfed3dca Mon Sep 17 00:00:00 2001 From: Julien Cretin Date: Mon, 24 Apr 2023 18:00:36 +0200 Subject: [PATCH 4/6] Add documentation --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 2663065..8700c64 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,11 @@ class. The UsbBus trait is intended to be implemented by device-specific crates to provide a driver for each device's USB peripheral. +Target architectures without native atomic support (e.g. `riscv32imc`) need a `critical-section` +implementation. This is often provided by the architecture crate (e.g. `riscv`) under some feature +flag. See `critical-section` [README](https://github.com/rust-embedded/critical-section) for more +information. + Hardware driver crates ---------------------- From 505463f01f46ded366f3c814226cfd189505e26a Mon Sep 17 00:00:00 2001 From: ia0 Date: Mon, 24 Apr 2023 23:05:58 +0200 Subject: [PATCH 5/6] Use portable-atomic instead of deprecated atomic-polyfill --- Cargo.toml | 2 +- src/bus.rs | 2 +- src/endpoint.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0a1b32d..7693656 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,8 +10,8 @@ authors = ["Matti Virkkunen "] repository = "https://github.com/mvirkkunen/usb-device" [dependencies] -atomic-polyfill = "1.0.2" defmt = { version = "0.3", optional = true } +portable-atomic = { version = "1.2.0", default-features = false } [dev-dependencies] rusb = "0.9.1" diff --git a/src/bus.rs b/src/bus.rs index 9f81dac..398b192 100644 --- a/src/bus.rs +++ b/src/bus.rs @@ -3,10 +3,10 @@ use crate::endpoint::{ IsochronousUsageType, }; use crate::{Result, UsbDirection, UsbError}; -use atomic_polyfill::{AtomicPtr, Ordering}; use core::cell::RefCell; use core::mem; use core::ptr; +use portable_atomic::{AtomicPtr, Ordering}; /// A trait for device-specific USB peripherals. Implement this to add support for a new hardware /// platform. diff --git a/src/endpoint.rs b/src/endpoint.rs index d465e8f..2b31eec 100644 --- a/src/endpoint.rs +++ b/src/endpoint.rs @@ -1,7 +1,7 @@ use crate::bus::UsbBus; use crate::{Result, UsbDirection}; -use atomic_polyfill::{AtomicPtr, Ordering}; use core::marker::PhantomData; +use portable_atomic::{AtomicPtr, Ordering}; /// Trait for endpoint type markers. pub trait EndpointDirection { From 9c266b940a99f7ff44317688f955d816a8ac18ab Mon Sep 17 00:00:00 2001 From: ia0 Date: Mon, 24 Apr 2023 23:06:07 +0200 Subject: [PATCH 6/6] Revert "Add documentation" This reverts commit 8f4ace5ee89abc0fc1e728dc20f32963cfed3dca. --- README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/README.md b/README.md index 8700c64..2663065 100644 --- a/README.md +++ b/README.md @@ -17,11 +17,6 @@ class. The UsbBus trait is intended to be implemented by device-specific crates to provide a driver for each device's USB peripheral. -Target architectures without native atomic support (e.g. `riscv32imc`) need a `critical-section` -implementation. This is often provided by the architecture crate (e.g. `riscv`) under some feature -flag. See `critical-section` [README](https://github.com/rust-embedded/critical-section) for more -information. - Hardware driver crates ----------------------