Skip to content
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

Add gpio functionaliy to lpc845 #155

Merged
merged 8 commits into from
Apr 11, 2019
Merged

Conversation

david-sawatzke
Copy link
Member

@david-sawatzke david-sawatzke commented Mar 31, 2019

  • Add compatibility layer for differently named peripherals raw_compat (Unfortunately couldn't find a way to do the same for registers)
  • Add pin assignments for for lpc845
    • Currently a few are commented out, as gpio1 & pinenable1 are currently missing
    • There's now also a Dac & capacitive measurement, I think the best way to handle them is to rename pin_state::Adc to pin_state::Analog.
  • Disable UARTFRG & IRC for lpc845, as they don't exist
  • Add Peripherals to lpc845. As the gpio is per default disabled, this also meant adding an additional new constructor(?) for disabled gpio peripherals and renaming the old one to new_enabled.
  • Add a gpio example. Currently without accurate timing, as that isn't ported yet

As an aside: What's your policy about rom routines, as the fro (internal oscillator) of the lpc845 doesn't seem to be configurable otherwise

@hannobraun
Copy link
Member

Thanks for the pull request, @david-sawatzke. I haven't taken the time to look at it in detail so far, but I have a note about the general approach.

I think the large number of #[cfg(...)] in the code is unfortunate. I think some of those can't be avoided (for register names, for example, unless we find a clever solution here too). But in some cases it looks like it might be avoided.

For example, why define IrcDerivedClock in -common, when it's only used in lpc82x-hal? Maybe the syscon module in -common should only define what's generally available, and more specific syscon modules in the two HALs should define the device-specific stuff and re-export the common stuff. Maybe a similar approach could be used for pin_state too?

I haven't tried this myself though, so maybe there are problems I'm not seeing right now. In any case, I think it's fine to merge the current approach now and find better solutions later.

As an aside: What's your policy about rom routines, as the fro (internal oscillator) of the lpc845 doesn't seem to be configurable otherwise

There's no policy right now, except that I decided not to use them years ago without ever revisiting that decision. If using ROM routines is required to get something to work, then that's what we're going to do.

@david-sawatzke
Copy link
Member Author

This approach will probably lead to code duplication, e.g. with syscon I'd add an unsafe Parts::new, which then gets called, so all the SYSCON impls can stay the same. But they still have to be defined in the same crate. I think "copying" them with macros may be the best approach, instead of copying them manually or using cfg everywhere. What do you think?

We'd also have to add constructors to the structs describing parts of the SYSCON or expose their phantom data and probably other stuff, so this should at least be a separate PR.

@david-sawatzke david-sawatzke changed the title WIP: Add gpio functionaliy to lpc845 Add gpio functionaliy to lpc845 Apr 6, 2019
@hannobraun
Copy link
Member

This approach will probably lead to code duplication, e.g. with syscon I'd add an unsafe Parts::new, which then gets called, so all the SYSCON impls can stay the same. But they still have to be defined in the same crate. I think "copying" them with macros may be the best approach, instead of copying them manually or using cfg everywhere. What do you think?

Not sure what I think. What you say makes sense, but I don't think I fully grasp all the issues right now. I need to get my hands dirty and see for myself what's possible and what's not. Only problem is to find the time to do it :-)

Copy link
Member

@hannobraun hannobraun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally got time to review this. Sorry for the delay.

I left some comments, but since all of them are nice-to-haves, I'm going to merge this immediately. My general concern about too much #[cfg(...) in the common crate remains, but as long as I only have a vague feeling that it could be done better, that's no reason to delay any pull requests.

Thank you, @david-sawatzke!

#[cfg(feature = "845")]
use crate::raw_compat::gpio::{CLR, DIRSET, PIN, SET};
#[cfg(feature = "82x")]
use crate::raw_compat::gpio::{CLR0 as CLR, DIRSET0 as DIRSET, PIN0 as PIN, SET0 as SET};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can keep this as-is for now, but this looks like something that should happen in raw_compat.

#[cfg(feature = "845")]
use crate::raw::syscon::{
pdruncfg, presetctrl0 as presetctrl, starterp1, sysahbclkctrl0 as sysahbclkctrl, PDRUNCFG,
PRESETCTRL0 as PRESETCTRL, STARTERP1, SYSAHBCLKCTRL0 as SYSAHBCLKCTRL,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same. Looks like a job for raw_compat.

loop {
// For this simple demo accurate timing isn't required and this is the
// simplest Method to delay
for _ in 0..1000000 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to add a comment here about which optimization level this was tested with. Compiling with or without --release makes a big difference when using this method :-)

@hannobraun hannobraun merged commit c425908 into lpc-rs:master Apr 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants