-
Notifications
You must be signed in to change notification settings - Fork 276
Added support for pins_with_function!() and pin_with_name!() #963
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,8 @@ | ||
| //! Types for the Binary Info system | ||
| use crate::consts::{TAG_RASPBERRY_PI}; | ||
|
|
||
| // pico-sck/src/common/pico_binary_info/include/pico/binary_info/structure.h | ||
| const BI_PINS_ENCODING_MULTI: u32 = 2; | ||
|
|
||
| /// This is the 'Binary Info' header block that `picotool` looks for in your UF2 | ||
| /// file/ELF file/Pico in Bootloader Mode to give you useful metadata about your | ||
|
|
@@ -116,7 +120,7 @@ pub enum DataType { | |
| BlockDevice = 7, | ||
| /// GPIO pins, with their function | ||
| PinsWithFunction = 8, | ||
| /// GPIO pins, with their name | ||
| /// GPIO pins, with their name pico-sdk: BINARY_INFO_TYPE_PINS_WITH_NAME | ||
| PinsWithName = 9, | ||
| /// GPIO pins, with multiple names? | ||
| PinsWithNames = 10, | ||
|
|
@@ -161,6 +165,7 @@ impl StringEntry { | |
| // core::ffi::c_char` pointers between threads. We only allow these to be | ||
| // created with static string slices, so it's OK. | ||
| unsafe impl Sync for StringEntry {} | ||
| unsafe impl Sync for PinWithNameEntry {} | ||
|
|
||
| /// An entry which contains both an ID (e.g. `ID_RP_BINARY_END`) and an integer. | ||
| #[repr(C)] | ||
|
|
@@ -189,6 +194,62 @@ impl IntegerEntry { | |
| } | ||
| } | ||
|
|
||
| /// An entry which contains a pin_encoding. | ||
| #[repr(C)] | ||
| pub struct PinsWithFunctionEntry { | ||
| header: EntryCommon, | ||
| pin_encoding: u32, | ||
| } | ||
|
|
||
| impl PinsWithFunctionEntry { | ||
| /// Create a new `PinsWithFunctionEntry` | ||
| pub const fn new(pin_0: u32, pin_1: u32, func: u32) -> PinsWithFunctionEntry { | ||
| PinsWithFunctionEntry { | ||
| header: EntryCommon { | ||
| data_type: DataType::PinsWithFunction, | ||
| tag: TAG_RASPBERRY_PI, | ||
| }, | ||
| pin_encoding: BI_PINS_ENCODING_MULTI | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's worth noting that this is a value with multiple fields, and raspberry pi seem to indicate that there are no more pins by setting two consecutive fields to the same value. You could also consider using bitbybit::bitfield to describe this 32-bit value, and avoid needing to do a bunch of shifts using magic numbers. I have examples you can refer to
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could then change this to take a slice of pins, rather than only two pins. |
||
| | (func << 3) | ||
| | (pin_0 << 7) | ||
| | (pin_1 << 12) | ||
| | (pin_1 << 17) | ||
| } | ||
| } | ||
|
|
||
| /// Get this entry's address | ||
| pub const fn addr(&self) -> EntryAddr { | ||
| EntryAddr(self as *const Self as *const u32) | ||
| } | ||
| } | ||
|
|
||
| /// An entry which contains a pin and a name. | ||
| #[repr(C)] | ||
| pub struct PinWithNameEntry { | ||
| header: EntryCommon, | ||
| pin_mask: u32, | ||
| label: *const core::ffi::c_char, | ||
| } | ||
|
|
||
| impl PinWithNameEntry { | ||
| /// Create a new `PinWithNameEntry` | ||
| pub const fn new(pin: u32, name: &'static core::ffi::CStr) -> PinWithNameEntry { | ||
| PinWithNameEntry { | ||
| header: EntryCommon { | ||
| data_type: DataType::PinsWithName, | ||
| tag: TAG_RASPBERRY_PI, | ||
| }, | ||
| pin_mask: 1u32 << pin, | ||
| label: name.as_ptr() | ||
| } | ||
| } | ||
|
|
||
| /// Get this entry's address | ||
| pub const fn addr(&self) -> EntryAddr { | ||
| EntryAddr(self as *const Self as *const u32) | ||
| } | ||
| } | ||
|
|
||
| /// An alias for IntegerEntry, taking a pointer instead of an integer | ||
| #[repr(C)] | ||
| pub struct PointerEntry { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.