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

Cache bus clock register and support clock source #2897

Closed
wants to merge 3 commits into from
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: 2 additions & 0 deletions esp-hal-procmacros/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Added `#[builder_lite_into]` attribute that generates the setter with `impl Into<T>` parameter (#2897)

### Changed

### Fixed
Expand Down
16 changes: 13 additions & 3 deletions esp-hal-procmacros/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,22 @@ pub fn builder_lite_derive(item: TokenStream) -> TokenStream {
_ => None,
});

let (field_type, field_assigns) = if let Some(inner_type) = maybe_path_type {
(inner_type, quote! { Some(#field_ident) })
let (mut field_type, mut field_assigns) = if let Some(inner_type) = maybe_path_type {
(quote! { #inner_type }, quote! { Some(#field_ident) })
} else {
(field_type, quote! { #field_ident })
(quote! { #field_type }, quote! { #field_ident })
};

// Wrap type and assignment with `Into` if needed.
if field
.attrs
.iter()
.any(|attr| attr.path().is_ident("builder_lite_into"))
{
field_type = quote! { impl Into<#field_type> };
field_assigns = quote! { #field_ident .into() };
}

fns.push(quote! {
#[doc = concat!(" Assign the given value to the `", stringify!(#field_ident) ,"` field.")]
#[must_use]
Expand Down
2 changes: 1 addition & 1 deletion esp-hal-procmacros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ pub fn blocking_main(args: TokenStream, input: TokenStream) -> TokenStream {
/// ```
///
/// [Builder Lite]: https://matklad.github.io/2022/05/29/builder-lite.html
#[proc_macro_derive(BuilderLite)]
#[proc_macro_derive(BuilderLite, attributes(builder_lite_into))]
pub fn builder_lite_derive(item: TokenStream) -> TokenStream {
builder::builder_lite_derive(item)
}
5 changes: 5 additions & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- SPI: Added support for 3-wire SPI (#2919)

- `spi::master::BusClockConfig` (#2897)

### Changed
- RMT: `TxChannelConfig` and `RxChannelConfig` now support the builder-lite pattern (#2978)
- RMT: Some fields of `TxChannelConfig` and `RxChannelConfig` are now `gpio::Level`-valued instead of `bool` (#2989)
Expand All @@ -24,6 +26,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- `Async` drivers are no longer `Send` (#2980)

- SPI `Config::frequency` has been replaced by `clock`. (#2897)
- SPI `Config::with_frequency` has been renamed to `with_clock`. (#2897)

### Fixed

- `DmaDescriptor` is now `#[repr(C)]` (#2988)
Expand Down
14 changes: 14 additions & 0 deletions esp-hal/MIGRATING-0.23.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,17 @@ Use `DataMode::SingleTwoDataLines` to get the previous behavior.
```

`Spi` now offers both, `with_mosi` and `with_sio0`. Consider using `with_sio` for half-duplex SPI except for [DataMode::SingleTwoDataLines] or for a mixed-bus.

### SPI master driver configuration

SPI `Config::with_frequency` has been renamed to `with_clock`. This function now takes either
a `fugit::HertzU32` or `BusClockConfig`.

```diff
let config = Config::default()
- .with_frequency(10.MHz());
+ .with_clock(10.MHz());
```

The new structure supports configuring a clock source, although currently only `ClockSource::Apb`
is available.
2 changes: 1 addition & 1 deletion esp-hal/src/dma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
//!
//! let mut spi = Spi::new(
//! peripherals.SPI2,
//! Config::default().with_frequency(100.kHz()).with_mode(Mode::_0)
//! Config::default().with_clock(100.kHz()).with_mode(Mode::_0)
//! )
//! .unwrap()
//! .with_sck(sclk)
Expand Down
Loading
Loading