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

Adding support for Nordic nRF52833 #148

Merged
merged 5 commits into from
May 27, 2020
Merged

Conversation

blueluna
Copy link
Member

This PR adds support for the Nordic nRF52833. This chip is similar to the nRF52840 with less flash and memory, no CryptoCell, some radio differences and probably som other smaller differences.

I have tested using clocks, gpio, timer and uarte in a RTFM program running on a Nordic nRF52833-DK.

Copy link
Contributor

@jonas-schievink jonas-schievink left a comment

Choose a reason for hiding this comment

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

Great! We're approaching #[cfg]-hell though, maybe we should rethink how we handle different chips...

nrf-hal-common/Cargo.toml Outdated Show resolved Hide resolved
@fmckeogh
Copy link
Contributor

Is there a good pattern for solving #[cfg] hell?

@jonas-schievink
Copy link
Contributor

I could imagine using a build.rs script to set various cfgs based on the enabled features. Other than that and cfg_if, I don't think there are any good solutions.

@Yatekii
Copy link
Contributor

Yatekii commented May 23, 2020

When you're talking about cfg-hell you mean from a developer perspective, right? Because from a user perspective I like it quite much :)

@blueluna
Copy link
Member Author

With regards to cfg-hell. I experimented a bit with adding a build.rs that generated features from the features defined in Cargo.toml. I am on the fence on if the result is better or not. Maybe open a issue for cfg opportunity for improvement?

impl Instance for SPIM0 {}

#[cfg(feature = "peripheral_spim1_enable")]
impl Instance for SPIM1 {}

#[cfg(feature = "peripheral_spim2_enable")]
impl Instance for SPIM2 {}

#[cfg(feature = "peripheral_spim3_enable")]
impl Instance for SPIM3 {}

build.rs

use std::env;

fn is_feature_enabled(name: &str) -> bool {
    match env::var(format!("CARGO_FEATURE_{}", name.to_uppercase())) {
        Ok(val) => {
            if val == "1" {
                true
            } else {
                false
            }
        }
        Err(_) => false,
    }
}

fn get_chip_code() -> u32 {
    if is_feature_enabled("51") {
        51
    } else if is_feature_enabled("52810") {
        52810
    } else if is_feature_enabled("52811") {
        52811
    } else if is_feature_enabled("52820") {
        52820
    } else if is_feature_enabled("52832") {
        52832
    } else if is_feature_enabled("52833") {
        52833
    } else if is_feature_enabled("52840") {
        52840
    } else if is_feature_enabled("5340") {
        5340
    } else if is_feature_enabled("9160") {
        9160
    } else {
        0
    }
}

fn spim_count(chip_code: u32) -> u32 {
    match chip_code {
        52833 | 52840 => 4,
        52832 => 3,
        _ => 1,
    }
}

fn emit_feature(value: &str) {
    println!("cargo:rustc-cfg=feature=\"{}\"", value);
}

fn main() {
    let chip_code = get_chip_code();
    for n in 0..spim_count(chip_code) {
        emit_feature(&format!("peripheral_spim{}_enable", n));
    }
}

Copy link
Contributor

@jonas-schievink jonas-schievink left a comment

Choose a reason for hiding this comment

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

PR looks good to me, thanks!

@jonas-schievink jonas-schievink merged commit 7e174b4 into nrf-rs:master May 27, 2020
@jonas-schievink jonas-schievink mentioned this pull request Dec 16, 2021
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.

4 participants