File tree Expand file tree Collapse file tree 3 files changed +21
-0
lines changed
Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -44,4 +44,10 @@ fn main() {
4444 assert_eq ! ( ro_array_1, 0x3 ) ;
4545 println ! ( "MMIO read-only array[0]: 0x{:X}" , ro_array_0) ;
4646 println ! ( "MMIO read-only array[1]: 0x{:X}" , ro_array_1) ;
47+
48+ // Get the length of the arrays
49+ assert_eq ! ( mmio_uart. len_array_0( ) , 4 ) ;
50+ assert_eq ! ( mmio_uart. len_array_1( ) , 4 ) ;
51+ assert_eq ! ( mmio_uart. len_array_read_only( ) , 4 ) ;
52+ assert_eq ! ( mmio_uart. len_array_write_only( ) , 2 ) ;
4753}
Original file line number Diff line number Diff line change @@ -839,6 +839,7 @@ impl FieldParser {
839839 let unchecked_write_fn_name = format_ident ! ( "write_{}_unchecked" , field_ident) ;
840840 let unchecked_modify_fn_name = format_ident ! ( "modify_{}_unchecked" , field_ident) ;
841841 let modify_fn_name = format_ident ! ( "modify_{}" , field_ident) ;
842+ let array_len_func = format_ident ! ( "len_{}" , field_ident) ;
842843 let error_type = quote ! { derive_mmio:: OutOfBoundsError } ;
843844
844845 access_methods. append_all ( quote ! {
@@ -858,6 +859,16 @@ impl FieldParser {
858859 }
859860 } ) ;
860861
862+ access_methods. append_all ( quote ! {
863+ #[ doc = "Length of the array `" ]
864+ #[ doc = stringify!( #field_ident) ]
865+ #[ doc = "`." ]
866+ #[ inline]
867+ pub const fn #array_len_func( & self ) -> usize {
868+ #array_len
869+ }
870+ } ) ;
871+
861872 if let Some ( read_access) = access. read {
862873 let mut opt_mut = TokenStream :: new ( ) ;
863874 if read_access == ReadAccess :: Normal {
Original file line number Diff line number Diff line change @@ -320,6 +320,10 @@ impl MmioUart {
320320 pub unsafe fn modify_bank_unchecked<F: FnOnce(u32) -> u32>(&mut self, index: usize, f: F) {
321321 // ...
322322 }
323+
324+ pub const fn len_bank(&self) -> usize {
325+ 4
326+ }
323327}
324328```
325329
You can’t perform that action at this time.
0 commit comments