adamgreig / assign-resources Goto Github PK
View Code? Open in Web Editor NEWRust macro to split up fields of a Peripherals struct into new structs
Rust macro to split up fields of a Peripherals struct into new structs
Given the following use of the macro:
monitoring_adc: MonitoringAdcResources {
spi: SPI6,
sck: PA5,
mosi: // ... etc
}
the expanded macro (according to rust analyzer, but the compiler errors indicate the same) looks like this
#[allow(dead_code, non_snake_case)]
struct MonitoringAdcResources {
pub spi: peripherals::SPI6,
sck: peripherals::PA5,
mosi: //...
}
I think all fields should be pub
, not just the first one.
And it might be good to have an option to make the entire struct pub
. I kept getting errors when using this in a lib and then referencing the structs in the binaries (i.e., the lib has the board definition and the binaries contain programs that use this board).
Unfortunately I am a total macro newbie, but I'd be happy to make a PR if I figure out how to make this work.
I was wondering whether there is a specific reason for doing peripherals::$resource_field
instead of just $resource_field
.
The user will have to use embassy_stm32::peripherals
anyway and could just as well do use embassy_stm32::peripherals::*
(or not?).
Removing this prefix would make the macro a lot more flexible and allow to include arbitrary resources into it, e.g., an instance of a driver, some array, etc.
I am trying to reuse the resources struct with a new hardware iteration that has some pin changes. However, I would like to keep the old config around and switch between the assignments with a feature.
Unfortunately, I am not make the macro repeat the feature attribute again before the type alias and I keep getting "the name ResetPin
is defined multiple times" errors. Any ideas how this could be fixed?
#[cfg(feature="feat")]
reset: PD7 = ResetPin,
#[cfg(not(feature = "feat"))]
reset: PG3 = ResetPin,
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.