-
Notifications
You must be signed in to change notification settings - Fork 37
Refactor to use boards #59
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: master
Are you sure you want to change the base?
Changes from 2 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 |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| pub use rp2040::RP2040; | ||
| pub use rp2350::RP2350; | ||
|
|
||
| use crate::address_range::AddressRange; | ||
|
|
||
| pub mod rp2040; | ||
| pub mod rp2350; | ||
|
|
||
| /// This is a helper struct, which allows you to iterate over every board defined | ||
| #[derive(Default)] | ||
| pub struct BoardIter { | ||
| inner: std::vec::IntoIter<Box<dyn BoardInfo>>, | ||
| } | ||
|
|
||
| impl BoardIter { | ||
| /// Creates a new BoardIter | ||
| pub fn new() -> Self { | ||
| Self { | ||
| inner: vec![Box::new(RP2040) as Box<dyn BoardInfo>, Box::new(RP2350)].into_iter(), | ||
| } | ||
| } | ||
|
|
||
| pub fn find_by_name(name: &str) -> Option<Box<dyn BoardInfo>> { | ||
| Self::new() | ||
| .find(|board| board.board_name().eq_ignore_ascii_case(name)) | ||
| .map(|v| v as _) | ||
| } | ||
| } | ||
|
|
||
| impl Iterator for BoardIter { | ||
| type Item = Box<dyn BoardInfo>; | ||
| fn next(&mut self) -> Option<Self::Item> { | ||
| self.inner.next() | ||
| } | ||
| } | ||
|
|
||
| /// This is the version of the firmware on the usb device | ||
| #[allow(unused)] | ||
| #[derive(Debug, Clone)] | ||
| pub struct UsbVersion(pub u8, pub u8, pub u8); | ||
|
|
||
| /// This is the usb device information from the usb device. It is possible to generate this information with something like | ||
| /// nusb | ||
| #[allow(unused)] | ||
| #[derive(Debug, Clone)] | ||
| pub struct UsbDevice { | ||
| pub bus_number: u8, | ||
| pub address: u8, | ||
| pub vendor_id: u16, | ||
| pub product_id: u16, | ||
| pub version: UsbVersion, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Default)] | ||
| pub struct AddressLocations<'a> { | ||
| pub address_ranges_ram: Option<&'a [AddressRange]>, | ||
| pub address_ranges_flash: Option<&'a [AddressRange]>, | ||
| pub main_ram_start: Option<u64>, | ||
|
datdenkikniet marked this conversation as resolved.
|
||
| pub main_ram_end: Option<u64>, | ||
| pub xip_sram_start: Option<u64>, | ||
|
Collaborator
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 feel like XIP-RAM is a somewhat RP2xxx specific thing. Does it belong in this struct, or can we do without it, somehow? E.g. abstract away whatever meaning we attach it behind some function?
Contributor
Author
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. Probably should abstract it out into some function instead. |
||
| pub xip_sram_end: Option<u64>, | ||
| } | ||
|
|
||
| /// This trait helps by allowing for definitions of multiple different boards. | ||
| pub trait BoardInfo { | ||
|
Collaborator
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. Given that we Since the required info is quite concrete and practically none of it actually depends on the concrete instantiation of our It would prevent us from having an implementor of Mostly asking because all of these functions only take
Contributor
Author
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. Makes perfect sense to make a trait to get the info! Will do so! |
||
| /// Check if the board is connected to the specified UsbDevice | ||
| fn is_device_board(&self, device: &UsbDevice) -> bool; | ||
|
|
||
| /// Returns the proper family id to use for the uf2 device | ||
| fn family_id(&self) -> u32; | ||
|
|
||
| /// Optional, just sent to a sensible default of 256, as long as it is less than 512 - 32 it should be okay, but boards very, and so does the bootloader firmware | ||
| fn page_size(&self) -> u32 { | ||
| 256 | ||
| } | ||
|
|
||
| /// Optional, with a default erase size of 4096 | ||
| fn flash_sector_erase_size(&self) -> u64 { | ||
| 4096 | ||
| } | ||
|
|
||
| fn address_locations<'a>(&'a self) -> AddressLocations<'a> { | ||
| AddressLocations::default() | ||
| } | ||
|
|
||
| /// Get the board's name | ||
| fn board_name(&self) -> String; | ||
|
BjornTheProgrammer marked this conversation as resolved.
Outdated
|
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,81 @@ | ||||||
| use crate::{ | ||||||
| address_range::{AddressRange, AddressRangeType}, | ||||||
| boards::{AddressLocations, BoardInfo, UsbDevice}, | ||||||
| }; | ||||||
|
|
||||||
| #[derive(Debug, Default, Clone)] | ||||||
| pub struct RP2040; | ||||||
|
|
||||||
| impl BoardInfo for RP2040 { | ||||||
| fn is_device_board(&self, device: &UsbDevice) -> bool { | ||||||
| if device.vendor_id == 0x2e8a || device.product_id == 0x0003 { | ||||||
|
Collaborator
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. This should probably be an
Contributor
Author
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. Actually I don't really think this should be a double &&. Why should we use a double &&?
Collaborator
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'm referring to the condition in the if statement, not the function. For the function I agree, a double-reference makes very little sense :P
Suggested change
Contributor
Author
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. Oh 😅, that makes a lot more sense. |
||||||
| return true; | ||||||
| } | ||||||
| false | ||||||
| } | ||||||
|
|
||||||
| fn family_id(&self) -> u32 { | ||||||
| 0xe48bff56 | ||||||
| } | ||||||
|
|
||||||
| fn address_locations<'a>(&'a self) -> AddressLocations<'a> { | ||||||
| AddressLocations { | ||||||
| address_ranges_ram: Some(RP2040_ADDRESS_RANGES_RAM), | ||||||
| address_ranges_flash: Some(RP2040_ADDRESS_RANGES_FLASH), | ||||||
| main_ram_start: Some(MAIN_RAM_START_RP2040), | ||||||
| main_ram_end: Some(MAIN_RAM_END_RP2040), | ||||||
| xip_sram_start: Some(XIP_SRAM_START_RP2040), | ||||||
| xip_sram_end: Some(XIP_SRAM_END_RP2040), | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| fn board_name(&self) -> String { | ||||||
| "rp2040".to_string() | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| pub const MAIN_RAM_START_RP2040: u64 = 0x20000000; | ||||||
| pub const MAIN_RAM_END_RP2040: u64 = 0x20042000; | ||||||
| pub const FLASH_START_RP2040: u64 = 0x10000000; | ||||||
| pub const FLASH_END_RP2040: u64 = 0x15000000; | ||||||
|
|
||||||
| pub const XIP_SRAM_START_RP2040: u64 = 0x15000000; | ||||||
| pub const XIP_SRAM_END_RP2040: u64 = 0x15004000; | ||||||
|
|
||||||
| pub const MAIN_RAM_BANKED_START_RP2040: u64 = 0x21000000; | ||||||
| pub const MAIN_RAM_BANKED_END_RP2040: u64 = 0x21040000; | ||||||
|
|
||||||
| pub const ROM_START_RP2040: u64 = 0x00000000; | ||||||
| pub const ROM_END_RP2040: u64 = 0x00004000; | ||||||
|
|
||||||
| pub const RP2040_ADDRESS_RANGES_FLASH: &[AddressRange] = &[ | ||||||
| AddressRange::new( | ||||||
| FLASH_START_RP2040, | ||||||
| FLASH_END_RP2040, | ||||||
| AddressRangeType::Contents, | ||||||
| ), | ||||||
| AddressRange::new( | ||||||
| MAIN_RAM_START_RP2040, | ||||||
| MAIN_RAM_END_RP2040, | ||||||
| AddressRangeType::NoContents, | ||||||
| ), | ||||||
| AddressRange::new( | ||||||
| MAIN_RAM_BANKED_START_RP2040, | ||||||
| MAIN_RAM_BANKED_END_RP2040, | ||||||
| AddressRangeType::NoContents, | ||||||
| ), | ||||||
| ]; | ||||||
|
|
||||||
| pub const RP2040_ADDRESS_RANGES_RAM: &[AddressRange] = &[ | ||||||
| AddressRange::new( | ||||||
| MAIN_RAM_START_RP2040, | ||||||
| MAIN_RAM_END_RP2040, | ||||||
| AddressRangeType::Contents, | ||||||
| ), | ||||||
| AddressRange::new( | ||||||
| XIP_SRAM_START_RP2040, | ||||||
| XIP_SRAM_END_RP2040, | ||||||
| AddressRangeType::Contents, | ||||||
| ), | ||||||
| AddressRange::new(ROM_START_RP2040, ROM_END_RP2040, AddressRangeType::Ignore), // for now we ignore the bootrom if present | ||||||
| ]; | ||||||
Uh oh!
There was an error while loading. Please reload this page.