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

Fix System Pin Feature Gate #38

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ jobs:
run: echo "::set-output name=pac_matrix::$(ls ./pac --indicator-style=none | grep atsam | cut -c 3- | jq -ncR '[inputs]')"
- id: boards
run: echo "::set-output name=board_matrix::$(ls ./boards --indicator-style=none | jq -ncR '[inputs]')"
- id: features
run: echo "::set-output name=feature_matrix::[\"reconfigurable-system-pins\",\"usart-spi-host-without-select\"]"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Having the features hard coded like this isn't pretty, but I have no idea how to parse the actual list of features and not catch the internal-only features.

Copy link
Member

Choose a reason for hiding this comment

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

There is probably a better way to check different feature permutations (and maybe streamline the CI further), but we can delay that until we have more feature gates. Ideally they will be de-coupled, so we could just check with --all-features, but I don't know if we can separate the PACs from this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

There a cargo extensions crate called cargo-hack that can do feature permutations.

Raised #42 about this.

outputs:
pac_matrix: ${{ steps.pacs.outputs.pac_matrix }}
board_matrix: ${{ steps.boards.outputs.board_matrix }}
feature_matrix: ${{ steps.features.outputs.feature_matrix }}

build:
needs: setup
Expand All @@ -27,8 +30,21 @@ jobs:
- name: Install Rust (thumbv7em)
run: rustup show
- name: Build HAL for ${{ matrix.pac }}
run: |
cargo check --package atsamx7x-hal --features ${{ matrix.pac }},unproven
run: cargo check --package atsamx7x-hal --features ${{ matrix.pac }},unproven

build-features:
needs: setup
runs-on: ubuntu-latest
strategy:
matrix:
features: ${{ fromJson(needs.setup.outputs.feature_matrix) }}
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Install Rust (thumbv7em)
run: rustup show
- name: Build HAL for ${{ matrix.features }}
run: cargo check --package atsamx7x-hal --features ${{ matrix.features }},samv71q21b,unproven

board-examples:
needs: setup
Expand All @@ -55,7 +71,7 @@ jobs:
- name: Install Rust (thumbv7em)
run: rustup show
- name: Lint HAL
run: cargo clippy --package atsamx7x-hal --no-deps --features samv71q21b,unproven -- --deny warnings
run: cargo clippy --package atsamx7x-hal --no-deps --features samv71q21b,unproven,reconfigurable-system-pins -- --deny warnings

clippy-examples:
needs: [setup, build, board-examples]
Expand All @@ -82,7 +98,7 @@ jobs:
- name: Install Rust (thumbv7em)
run: rustup show
- name: Build HAL documentation
run: cargo doc --package atsamx7x-hal --no-deps --features samv71q21b,unproven
run: cargo doc --package atsamx7x-hal --no-deps --features samv71q21b,unproven,reconfigurable-system-pins
- name: Build HAL doc tests
run: cargo test --package atsamx7x-hal --doc --features samv71q21b,unproven --target x86_64-unknown-linux-gnu

Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
### Fixed

- HAL build when targeting `sams70n19b`.
- The special-on-reset pins `PB4/5/6/7/12` are now completely unavailable, if the `reconfigurable-system-pins` feature is not enabled.
- `Usart<Usart1>` and `Twi<TwiHS1>` are now only available if the `reconfigurable-system-pins` feature is enabled, as they cannot obtain a valid pin configuration without it.
Copy link
Member

Choose a reason for hiding this comment

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

Move these under Changed.


## [v0.3.0] 2022-08-26

Expand Down
5 changes: 5 additions & 0 deletions hal/src/pio/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,17 @@ banks!(
(PB1, 1),
(PB2, 2),
(PB3, 3),
#[cfg(feature = "reconfigurable-system-pins")]
(PB4, 4),
#[cfg(feature = "reconfigurable-system-pins")]
(PB5, 5),
#[cfg(feature = "reconfigurable-system-pins")]
(PB6, 6),
#[cfg(feature = "reconfigurable-system-pins")]
(PB7, 7),
(PB8, 8),
(PB9, 9),
#[cfg(feature = "reconfigurable-system-pins")]
(PB12, 12),
#[cfg(not(feature = "pins-64"))]
(PB13, 13),
Expand Down
2 changes: 1 addition & 1 deletion hal/src/pio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ On reset the following [`Pin`]s:
- [`Pin<PB12, _>`]

are in "system I/O mode" where they provide debug, trace, and flash-erase functionality.
By default, trying to configure these pins yield no effect, but can be enabled via the `reconfigurable-system-pins` feature.
By default, trying to configure these pins will cause a compile error, but can they be enabled via the `reconfigurable-system-pins` feature.
*/

use crate::generics;
Expand Down
3 changes: 3 additions & 0 deletions hal/src/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ impl_pwm!(
Pin<PA1, PeripheralA>,
#[cfg(not(feature = "pins-64"))]
Pin<PA19, PeripheralB>,
#[cfg(feature = "reconfigurable-system-pins")]
Pin<PB5, PeripheralB>,
Pin<PD10, PeripheralB>,
Pin<PD24, PeripheralB>,
Expand Down Expand Up @@ -488,6 +489,7 @@ impl_pwm!(
Pin<PA20, PeripheralB>,
#[cfg(not(feature = "pins-64"))]
Pin<PA30, PeripheralA>,
#[cfg(feature = "reconfigurable-system-pins")]
Pin<PB12, PeripheralA>,
#[cfg(feature = "pins-144")]
Pin<PC1, PeripheralB>,
Expand All @@ -510,6 +512,7 @@ impl_pwm!(
Pin<PA13, PeripheralB>,
#[cfg(not(feature = "pins-64"))]
Pin<PA25, PeripheralB>,
#[cfg(feature = "reconfigurable-system-pins")]
Pin<PB4, PeripheralB>,
#[cfg(feature = "pins-144")]
Pin<PC19, PeripheralB>,
Expand Down
10 changes: 9 additions & 1 deletion hal/src/serial/twi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ feripheral, by use of the [`Twi`] abstraction. The peripheral
supports I²C, which is also the only protocol currently
implemented.

# System [`Pin`]s

[`Twi<TwiHS1>`] can only obtain a legal pin configuration with the `reconfigurable-system-pins` feature and is therefore also hidden behind said feature gate.

# Example usage

```no_run
Expand Down Expand Up @@ -41,11 +45,13 @@ twi.write_read(0x0, &[0b1000_0000], &mut buffer).unwrap();
use crate::clocks::{Clock, Hertz, HostClock, PeripheralIdentifier};
use crate::ehal::blocking;
use crate::generics;
#[cfg(feature = "reconfigurable-system-pins")]
use crate::pac::TWIHS1;
Copy link
Member

Choose a reason for hiding this comment

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

Why is this gated?

Copy link
Member

Choose a reason for hiding this comment

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

Nevermind. It's because the peripheral requires the system pins.

#[cfg(not(feature = "pins-64"))]
use crate::pac::TWIHS2;
use crate::pac::{
twihs0::{sr::R as StatusRegister, RegisterBlock},
TWIHS0, TWIHS1,
TWIHS0,
};
use crate::pio::*;

Expand Down Expand Up @@ -286,6 +292,8 @@ impl_twi!(
DATA: Pin<PA3, PeripheralA>,
CLOCK: Pin<PA4, PeripheralA>,
},

#[cfg(feature = "reconfigurable-system-pins")]
TwiHS1: {
DATA: Pin<PB4, PeripheralA>,
CLOCK: Pin<PB5, PeripheralA>,
Expand Down
10 changes: 9 additions & 1 deletion hal/src/serial/usart/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ these have yet to be implemented.
Mode support depends on what [`Pin`]s that are available for the
[`Usart`]; refer to [`UsartPins`].

# System [`Pin`]s

[`Usart<Usart1>`] can only obtain a legal pin configuration with the `reconfigurable-system-pins` feature and is therefore also hidden behind said feature gate.

# Example usage

```no_run
Expand Down Expand Up @@ -83,15 +87,17 @@ let _ = spi.read().unwrap();
pub use super::uart::{ChannelMode, ParityMode, UartConfiguration};
use crate::clocks::{Clock, Hertz, HostClock, Pck, Pck4, PeripheralIdentifier};
use crate::generics::{self, Token};
#[cfg(feature = "reconfigurable-system-pins")]
use crate::pac::USART1;
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

#[cfg(not(feature = "pins-64"))]
use crate::pac::USART2;
use crate::pac::{
usart0::us_mr_usart_mode::CHMODESELECT_A as HwChannelMode,
usart0::us_mr_usart_mode::PARSELECT_A as HwParityMode,
usart0::us_mr_usart_mode::USART_MODESELECT_A as HwUsartMode,
usart0::us_mr_usart_mode::USCLKSSELECT_A as UsartClockSource, usart0::RegisterBlock, USART0,
USART1,
};

use crate::pio::*;
use crate::serial::Bps;

Expand Down Expand Up @@ -630,6 +636,7 @@ impl_usart!(
CTS: [ Pin<PB2,PeripheralC> ],
RTS: [ Pin<PB3,PeripheralC> ],
},
#[cfg(feature = "reconfigurable-system-pins")]
Usart1: {
SCK: [
#[cfg(not(feature = "pins-64"))]
Expand Down Expand Up @@ -676,6 +683,7 @@ cfg_if::cfg_if! {
}
}
);
#[cfg(feature = "reconfigurable-system-pins")]
impl_pins!(
Usart1: {
(/* TX */ Pin<PB4, PeripheralD>, /* RX */ Pin<PA21, PeripheralA>, /* SCK */ Pin<PA23, PeripheralA>): {
Expand Down