Skip to content
Open
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 .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
steps:
- id: set-matrix
run: |
echo 'rust_versions={"rust": ["stable", "1.70"]}' >> "$GITHUB_OUTPUT"
echo 'rust_versions={"rust": ["stable", "1.85"]}' >> "$GITHUB_OUTPUT"

# Build the library
build:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"
name = "derive-mmio"
readme = "README.md"
repository = "https://github.com/knurling-rs/derive-mmio"
rust-version = "1.70"
rust-version = "1.85"
version = "0.6.1"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ For more details about the framework check the documentation at

## MSRV

The minimum supported Rust version is 1.76 (or Ferrocene 24.05). `derive-mmio`
The minimum supported Rust version is 1.85 (or Ferrocene 25.05). `derive-mmio`
is tested against the latest stable Rust version and the MSRV.

## Support
Expand Down
6 changes: 6 additions & 0 deletions examples/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,10 @@ fn main() {
assert_eq!(ro_array_1, 0x3);
println!("MMIO read-only array[0]: 0x{:X}", ro_array_0);
println!("MMIO read-only array[1]: 0x{:X}", ro_array_1);

// Get the length of the arrays
assert_eq!(mmio_uart.len_array_0(), 4);
assert_eq!(mmio_uart.len_array_1(), 4);
assert_eq!(mmio_uart.len_array_read_only(), 4);
assert_eq!(mmio_uart.len_array_write_only(), 2);
}
15 changes: 13 additions & 2 deletions macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ impl FieldParser {
self.bound_checks.push(quote! {
derive_mmio::is_mmio::<#inner_mmio_path>();
});
let array_len_func = format_ident!("{}_array_len", field_ident);
let array_len_func = format_ident!("len_{}", field_ident);
let field_ident_unchecked = format_ident!("{}_unchecked", field_ident);

let field_ident_shared = format_ident!("{}_shared", field_ident);
Expand Down Expand Up @@ -601,7 +601,7 @@ impl FieldParser {
)
}

#[doc = "Length of the inner MMIO array`"]
#[doc = "Length of the inner MMIO array `"]
#[doc = stringify!(#field_ident)]
#[doc = "`."]
#[inline]
Expand Down Expand Up @@ -839,6 +839,7 @@ impl FieldParser {
let unchecked_write_fn_name = format_ident!("write_{}_unchecked", field_ident);
let unchecked_modify_fn_name = format_ident!("modify_{}_unchecked", field_ident);
let modify_fn_name = format_ident!("modify_{}", field_ident);
let array_len_func = format_ident!("len_{}", field_ident);
let error_type = quote! { derive_mmio::OutOfBoundsError };

access_methods.append_all(quote! {
Expand All @@ -858,6 +859,16 @@ impl FieldParser {
}
});

access_methods.append_all(quote! {
#[doc = "Length of the array `"]
#[doc = stringify!(#field_ident)]
#[doc = "`."]
#[inline]
pub const fn #array_len_func(&self) -> usize {
#array_len
}
});

if let Some(read_access) = access.read {
let mut opt_mut = TokenStream::new();
if read_access == ReadAccess::Normal {
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ impl MmioUart {
pub unsafe fn modify_bank_unchecked<F: FnOnce(u32) -> u32>(&mut self, index: usize, f: F) {
// ...
}

pub const fn len_bank(&self) -> usize {
4
}
}
```

Expand Down
2 changes: 1 addition & 1 deletion tests/inner_mmio_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn main() {

// Safety: We're pointing at a real object
let mut mmio_uart = unsafe { Uart::new_mmio(core::ptr::addr_of_mut!(uart)) };
assert_eq!(mmio_uart.banks_array_len(), 2);
assert_eq!(mmio_uart.len_banks(), 2);
let bank0 = mmio_uart.banks_shared(0).unwrap();
assert_eq!(bank0.read_data(), 0x2);
assert_eq!(bank0.read_status(), 0x3);
Expand Down
30 changes: 25 additions & 5 deletions tests/no_compile/cant_fake_inner_block.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error[E0599]: no function or associated item named `new_mmio` found for struct `UartBank` in the current scope
--> tests/no_compile/cant_fake_inner_block.rs:14:10
|
4 | struct UartBank {
4 | struct UartBank {
| --------------- function or associated item `new_mmio` not found for this struct
...
14 | #[derive(derive_mmio::Mmio)]
Expand All @@ -13,24 +13,44 @@ error[E0277]: the trait bound `MmioUartBank<'_>: _MmioMarker` is not satisfied
--> tests/no_compile/cant_fake_inner_block.rs:20:13
|
20 | bank_0: UartBank,
| ^^^^^^^^ the trait `_MmioMarker` is not implemented for `MmioUartBank<'_>`
| ^^^^^^^^ unsatisfied trait bound
|
= help: the trait `_MmioMarker` is implemented for `MmioUart<'_>`
help: the trait `_MmioMarker` is not implemented for `MmioUartBank<'_>`
--> tests/no_compile/cant_fake_inner_block.rs:9:1
|
9 | struct MmioUartBank<'a> {
| ^^^^^^^^^^^^^^^^^^^^^^^
help: the trait `_MmioMarker` is implemented for `MmioUart<'_>`
--> tests/no_compile/cant_fake_inner_block.rs:14:10
|
14 | #[derive(derive_mmio::Mmio)]
| ^^^^^^^^^^^^^^^^^
note: required by a bound in `is_mmio`
--> src/lib.rs
|
| pub const fn is_mmio<M: _MmioMarker>() {}
| ^^^^^^^^^^^ required by this bound in `is_mmio`
= note: this error originates in the derive macro `derive_mmio::Mmio` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `MmioUartBank<'_>: _MmioMarker` is not satisfied
--> tests/no_compile/cant_fake_inner_block.rs:22:13
|
22 | bank_1: UartBank,
| ^^^^^^^^ the trait `_MmioMarker` is not implemented for `MmioUartBank<'_>`
| ^^^^^^^^ unsatisfied trait bound
|
= help: the trait `_MmioMarker` is implemented for `MmioUart<'_>`
help: the trait `_MmioMarker` is not implemented for `MmioUartBank<'_>`
--> tests/no_compile/cant_fake_inner_block.rs:9:1
|
9 | struct MmioUartBank<'a> {
| ^^^^^^^^^^^^^^^^^^^^^^^
help: the trait `_MmioMarker` is implemented for `MmioUart<'_>`
--> tests/no_compile/cant_fake_inner_block.rs:14:10
|
14 | #[derive(derive_mmio::Mmio)]
| ^^^^^^^^^^^^^^^^^
note: required by a bound in `is_mmio`
--> src/lib.rs
|
| pub const fn is_mmio<M: _MmioMarker>() {}
| ^^^^^^^^^^^ required by this bound in `is_mmio`
= note: this error originates in the derive macro `derive_mmio::Mmio` (in Nightly builds, run with -Z macro-backtrace for more info)
2 changes: 1 addition & 1 deletion tests/no_compile/double_read.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ error: `#[mmio(...)]` found second read argument
error[E0599]: no function or associated item named `new_mmio` found for struct `Uart` in the current scope
--> tests/no_compile/double_read.rs:13:40
|
3 | struct Uart {
3 | struct Uart {
| ----------- function or associated item `new_mmio` not found for this struct
...
13 | let mut mmio_uart = unsafe { Uart::new_mmio(core::ptr::addr_of_mut!(uart)) };
Expand Down
2 changes: 1 addition & 1 deletion tests/no_compile/duplicate_field_attr.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ error: `#[mmio(...)]` found second write argument
error[E0599]: no function or associated item named `new_mmio` found for struct `Uart` in the current scope
--> tests/no_compile/duplicate_field_attr.rs:14:40
|
4 | struct Uart {
4 | struct Uart {
| ----------- function or associated item `new_mmio` not found for this struct
...
14 | let mut mmio_uart = unsafe { Uart::new_mmio(core::ptr::addr_of_mut!(uart)) };
Expand Down
16 changes: 13 additions & 3 deletions tests/no_compile/inner_array_invalid_type.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error[E0599]: no function or associated item named `new_mmio` found for struct `UartBank` in the current scope
--> tests/no_compile/inner_array_invalid_type.rs:15:10
|
4 | struct UartBank {
4 | struct UartBank {
| --------------- function or associated item `new_mmio` not found for this struct
...
15 | #[derive(derive_mmio::Mmio)]
Expand All @@ -13,11 +13,21 @@ error[E0277]: the trait bound `MmioUartBank<'_>: _MmioMarker` is not satisfied
--> tests/no_compile/inner_array_invalid_type.rs:20:13
|
20 | banks: [UartBank; 2],
| ^^^^^^^^ the trait `_MmioMarker` is not implemented for `MmioUartBank<'_>`
| ^^^^^^^^ unsatisfied trait bound
|
= help: the trait `_MmioMarker` is implemented for `MmioUart<'_>`
help: the trait `_MmioMarker` is not implemented for `MmioUartBank<'_>`
--> tests/no_compile/inner_array_invalid_type.rs:9:1
|
9 | struct MmioUartBank<'a> {
| ^^^^^^^^^^^^^^^^^^^^^^^
help: the trait `_MmioMarker` is implemented for `MmioUart<'_>`
--> tests/no_compile/inner_array_invalid_type.rs:15:10
|
15 | #[derive(derive_mmio::Mmio)]
| ^^^^^^^^^^^^^^^^^
note: required by a bound in `is_mmio`
--> src/lib.rs
|
| pub const fn is_mmio<M: _MmioMarker>() {}
| ^^^^^^^^^^^ required by this bound in `is_mmio`
= note: this error originates in the derive macro `derive_mmio::Mmio` (in Nightly builds, run with -Z macro-backtrace for more info)
2 changes: 1 addition & 1 deletion tests/no_compile/modify_standalone.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ error: Detected Modify field attribute without read and/or write access specifie
error[E0599]: no function or associated item named `new_mmio` found for struct `Uart` in the current scope
--> tests/no_compile/modify_standalone.rs:15:40
|
4 | struct Uart {
4 | struct Uart {
| ----------- function or associated item `new_mmio` not found for this struct
...
15 | let mut mmio_uart = unsafe { Uart::new_mmio(core::ptr::addr_of_mut!(uart)) };
Expand Down
2 changes: 1 addition & 1 deletion tests/no_compile/modify_without_read.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ error: Detected Modify field attribute without read and/or write access specifie
error[E0599]: no function or associated item named `new_mmio` found for struct `Uart` in the current scope
--> tests/no_compile/modify_without_read.rs:14:40
|
4 | struct Uart {
4 | struct Uart {
| ----------- function or associated item `new_mmio` not found for this struct
...
14 | let mut mmio_uart = unsafe { Uart::new_mmio(core::ptr::addr_of_mut!(uart)) };
Expand Down
2 changes: 1 addition & 1 deletion tests/no_compile/modify_without_write.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ error: Detected Modify field attribute without read and/or write access specifie
error[E0599]: no function or associated item named `new_mmio` found for struct `Uart` in the current scope
--> tests/no_compile/modify_without_write.rs:14:40
|
4 | struct Uart {
4 | struct Uart {
| ----------- function or associated item `new_mmio` not found for this struct
...
14 | let mut mmio_uart = unsafe { Uart::new_mmio(core::ptr::addr_of_mut!(uart)) };
Expand Down
4 changes: 2 additions & 2 deletions tests/no_compile/no_modify.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error[E0599]: no method named `modify_uart` found for struct `MmioUart` in the current scope
error[E0599]: no method named `modify_uart` found for struct `MmioUart<'a>` in the current scope
--> tests/no_compile/no_modify.rs:14:15
|
1 | #[derive(derive_mmio::Mmio)]
1 | #[derive(derive_mmio::Mmio)]
| ----------------- method `modify_uart` not found for this struct
...
14 | mmio_uart.modify_uart();
Expand Down
4 changes: 2 additions & 2 deletions tests/no_compile/read_only.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error[E0599]: no method named `write_status` found for struct `MmioUart` in the current scope
error[E0599]: no method named `write_status` found for struct `MmioUart<'a>` in the current scope
--> tests/no_compile/read_only.rs:16:15
|
1 | #[derive(derive_mmio::Mmio)]
1 | #[derive(derive_mmio::Mmio)]
| ----------------- method `write_status` not found for this struct
...
16 | mmio_uart.write_status();
Expand Down
2 changes: 1 addition & 1 deletion tests/no_compile/unimpl_send.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ error[E0277]: `*const ()` cannot be sent between threads safely
note: required for `__Wrapper<'_, *const ()>` to implement `Send`
--> tests/no_compile/unimpl_send.rs:8:1
|
8 | #[negative_impl::negative_impl]
8 | #[negative_impl::negative_impl]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: 2 redundant requirements hidden
= note: required for `MmioCpuPrivateRegBlock<'_>` to implement `Send`
Expand Down
Loading