Skip to content

Commit

Permalink
const associated ICE
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Feb 18, 2023
1 parent 3e703b6 commit 2f50fd5
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
use core::marker::PhantomData;

mod alt;
pub(crate) use alt::{Const, PinA, SetAlternate};
pub(crate) use alt::{PinA, SetAlternate};
mod convert;
pub use convert::PinMode;
mod partially_erased;
Expand Down
8 changes: 3 additions & 5 deletions src/gpio/alt.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use super::{marker, Alternate, NoPin, OpenDrain, Pin, PinMode, PushPull};
use crate::{gpio, i2c, i2s, pac, serial, spi};

pub struct Const<const A: u8>;

pub trait SetAlternate<const A: u8, Otype> {
fn set_alt_mode(&mut self);
fn restore_mode(&mut self);
Expand Down Expand Up @@ -50,23 +48,23 @@ impl<const P: char, const N: u8, const A: u8> SetAlternate<A, OpenDrain>
}

pub trait PinA<PIN, PER> {
type A;
const A: u8;
}

impl<PIN, PER> PinA<PIN, PER> for NoPin
where
PIN: crate::Sealed,
PER: crate::Sealed,
{
type A = Const<0>;
const A: u8 = 0;
}

macro_rules! pin {
( $(<$Pin:ty, $I2C:ident> for [$($PX:ident<$A:literal>),*]),*) => {
$(
$(
impl<MODE> PinA<$Pin, pac::$I2C> for gpio::$PX<MODE> {
type A = Const<$A>;
const A: u8 = $A;
}
)*
)*
Expand Down
6 changes: 3 additions & 3 deletions src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::ops::Deref;
use crate::pac::{self, i2c1};
use crate::rcc::{Enable, Reset};

use crate::gpio::{Const, OpenDrain, PinA, SetAlternate};
use crate::gpio::{OpenDrain, PinA, SetAlternate};
use crate::pac::RCC;

use crate::rcc::Clocks;
Expand Down Expand Up @@ -85,8 +85,8 @@ pub trait Pins<I2C> {

impl<I2C, SCL, SDA, const SCLA: u8, const SDAA: u8> Pins<I2C> for (SCL, SDA)
where
SCL: PinA<Scl, I2C, A = Const<SCLA>> + SetAlternate<SCLA, OpenDrain>,
SDA: PinA<Sda, I2C, A = Const<SDAA>> + SetAlternate<SDAA, OpenDrain>,
SCL: PinA<Scl, I2C, A = { SCLA }> + SetAlternate<SCLA, OpenDrain>,
SDA: PinA<Sda, I2C, A = { SDAA }> + SetAlternate<SDAA, OpenDrain>,
{
fn set_alt_mode(&mut self) {
self.0.set_alt_mode();
Expand Down
10 changes: 5 additions & 5 deletions src/i2s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! This module is only available if the `i2s` feature is enabled.
use crate::gpio::marker::{Interruptable, Readable};
use crate::gpio::{Const, NoPin, Pin, PinA, PushPull, SetAlternate};
use crate::gpio::{NoPin, Pin, PinA, PushPull, SetAlternate};
use crate::pac::{self, RCC};
use crate::rcc;
use crate::rcc::Clocks;
Expand Down Expand Up @@ -85,10 +85,10 @@ impl<
const SDA: u8,
> Pins<SPI> for (Pin<WSP, WSN, WSM>, CK, MCLK, SD)
where
Pin<WSP, WSN, WSM>: PinA<Ws, SPI, A = Const<WSA>> + SetAlternate<WSA, PushPull>,
CK: PinA<Ck, SPI, A = Const<CKA>> + SetAlternate<CKA, PushPull>,
MCLK: PinA<Mck, SPI, A = Const<MCLKA>> + SetAlternate<MCLKA, PushPull>,
SD: PinA<Sd, SPI, A = Const<SDA>> + SetAlternate<SDA, PushPull>,
Pin<WSP, WSN, WSM>: PinA<Ws, SPI, A = { WSA }> + SetAlternate<WSA, PushPull>,
CK: PinA<Ck, SPI, A = { CKA }> + SetAlternate<CKA, PushPull>,
MCLK: PinA<Mck, SPI, A = { MCLKA }> + SetAlternate<MCLKA, PushPull>,
SD: PinA<Sd, SPI, A = { SDA }> + SetAlternate<SDA, PushPull>,
{
type WsPin = Pin<WSP, WSN, Ws>;
fn set_alt_mode(&mut self) {
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![no_std]
#![allow(non_camel_case_types)]
#![feature(associated_const_equality)]

#[cfg(not(feature = "device-selected"))]
compile_error!(
Expand Down
6 changes: 3 additions & 3 deletions src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use nb::block;
mod hal_02;
mod hal_1;

use crate::gpio::{Const, PinA, PushPull, SetAlternate};
use crate::gpio::{PinA, PushPull, SetAlternate};

use crate::pac::{self, RCC};

Expand Down Expand Up @@ -191,8 +191,8 @@ pub trait Pins<USART> {
}
impl<USART, TX, RX, const TXA: u8, const RXA: u8> Pins<USART> for (TX, RX)
where
TX: PinA<TxPin, USART, A = Const<TXA>> + SetAlternate<TXA, PushPull>,
RX: PinA<RxPin, USART, A = Const<RXA>> + SetAlternate<RXA, PushPull>,
TX: PinA<TxPin, USART, A = { TXA }> + SetAlternate<TXA, PushPull>,
RX: PinA<RxPin, USART, A = { RXA }> + SetAlternate<RXA, PushPull>,
{
fn set_alt_mode(&mut self) {
self.0.set_alt_mode();
Expand Down
8 changes: 4 additions & 4 deletions src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::ops::Deref;
use core::ptr;

use crate::dma::traits::PeriAddress;
use crate::gpio::{Const, NoPin, PinA, PushPull, SetAlternate};
use crate::gpio::{NoPin, PinA, PushPull, SetAlternate};
use crate::pac;

/// Clock polarity
Expand Down Expand Up @@ -72,9 +72,9 @@ pub trait Pins<SPI> {
impl<SPI, SCK, MISO, MOSI, const SCKA: u8, const MISOA: u8, const MOSIA: u8> Pins<SPI>
for (SCK, MISO, MOSI)
where
SCK: PinA<Sck, SPI, A = Const<SCKA>> + SetAlternate<SCKA, PushPull>,
MISO: PinA<Miso, SPI, A = Const<MISOA>> + SetAlternate<MISOA, PushPull>,
MOSI: PinA<Mosi, SPI, A = Const<MOSIA>> + SetAlternate<MOSIA, PushPull>,
SCK: PinA<Sck, SPI, A = { SCKA }> + SetAlternate<SCKA, PushPull>,
MISO: PinA<Miso, SPI, A = { MISOA }> + SetAlternate<MISOA, PushPull>,
MOSI: PinA<Mosi, SPI, A = { MOSIA }> + SetAlternate<MOSIA, PushPull>,
{
fn set_alt_mode(&mut self) {
self.0.set_alt_mode();
Expand Down

0 comments on commit 2f50fd5

Please sign in to comment.