Skip to content

Commit 2f50fd5

Browse files
committed
const associated ICE
1 parent 3e703b6 commit 2f50fd5

File tree

7 files changed

+20
-21
lines changed

7 files changed

+20
-21
lines changed

src/gpio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
use core::marker::PhantomData;
5858

5959
mod alt;
60-
pub(crate) use alt::{Const, PinA, SetAlternate};
60+
pub(crate) use alt::{PinA, SetAlternate};
6161
mod convert;
6262
pub use convert::PinMode;
6363
mod partially_erased;

src/gpio/alt.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use super::{marker, Alternate, NoPin, OpenDrain, Pin, PinMode, PushPull};
22
use crate::{gpio, i2c, i2s, pac, serial, spi};
33

4-
pub struct Const<const A: u8>;
5-
64
pub trait SetAlternate<const A: u8, Otype> {
75
fn set_alt_mode(&mut self);
86
fn restore_mode(&mut self);
@@ -50,23 +48,23 @@ impl<const P: char, const N: u8, const A: u8> SetAlternate<A, OpenDrain>
5048
}
5149

5250
pub trait PinA<PIN, PER> {
53-
type A;
51+
const A: u8;
5452
}
5553

5654
impl<PIN, PER> PinA<PIN, PER> for NoPin
5755
where
5856
PIN: crate::Sealed,
5957
PER: crate::Sealed,
6058
{
61-
type A = Const<0>;
59+
const A: u8 = 0;
6260
}
6361

6462
macro_rules! pin {
6563
( $(<$Pin:ty, $I2C:ident> for [$($PX:ident<$A:literal>),*]),*) => {
6664
$(
6765
$(
6866
impl<MODE> PinA<$Pin, pac::$I2C> for gpio::$PX<MODE> {
69-
type A = Const<$A>;
67+
const A: u8 = $A;
7068
}
7169
)*
7270
)*

src/i2c.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use core::ops::Deref;
33
use crate::pac::{self, i2c1};
44
use crate::rcc::{Enable, Reset};
55

6-
use crate::gpio::{Const, OpenDrain, PinA, SetAlternate};
6+
use crate::gpio::{OpenDrain, PinA, SetAlternate};
77
use crate::pac::RCC;
88

99
use crate::rcc::Clocks;
@@ -85,8 +85,8 @@ pub trait Pins<I2C> {
8585

8686
impl<I2C, SCL, SDA, const SCLA: u8, const SDAA: u8> Pins<I2C> for (SCL, SDA)
8787
where
88-
SCL: PinA<Scl, I2C, A = Const<SCLA>> + SetAlternate<SCLA, OpenDrain>,
89-
SDA: PinA<Sda, I2C, A = Const<SDAA>> + SetAlternate<SDAA, OpenDrain>,
88+
SCL: PinA<Scl, I2C, A = { SCLA }> + SetAlternate<SCLA, OpenDrain>,
89+
SDA: PinA<Sda, I2C, A = { SDAA }> + SetAlternate<SDAA, OpenDrain>,
9090
{
9191
fn set_alt_mode(&mut self) {
9292
self.0.set_alt_mode();

src/i2s.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! This module is only available if the `i2s` feature is enabled.
44
55
use crate::gpio::marker::{Interruptable, Readable};
6-
use crate::gpio::{Const, NoPin, Pin, PinA, PushPull, SetAlternate};
6+
use crate::gpio::{NoPin, Pin, PinA, PushPull, SetAlternate};
77
use crate::pac::{self, RCC};
88
use crate::rcc;
99
use crate::rcc::Clocks;
@@ -85,10 +85,10 @@ impl<
8585
const SDA: u8,
8686
> Pins<SPI> for (Pin<WSP, WSN, WSM>, CK, MCLK, SD)
8787
where
88-
Pin<WSP, WSN, WSM>: PinA<Ws, SPI, A = Const<WSA>> + SetAlternate<WSA, PushPull>,
89-
CK: PinA<Ck, SPI, A = Const<CKA>> + SetAlternate<CKA, PushPull>,
90-
MCLK: PinA<Mck, SPI, A = Const<MCLKA>> + SetAlternate<MCLKA, PushPull>,
91-
SD: PinA<Sd, SPI, A = Const<SDA>> + SetAlternate<SDA, PushPull>,
88+
Pin<WSP, WSN, WSM>: PinA<Ws, SPI, A = { WSA }> + SetAlternate<WSA, PushPull>,
89+
CK: PinA<Ck, SPI, A = { CKA }> + SetAlternate<CKA, PushPull>,
90+
MCLK: PinA<Mck, SPI, A = { MCLKA }> + SetAlternate<MCLKA, PushPull>,
91+
SD: PinA<Sd, SPI, A = { SDA }> + SetAlternate<SDA, PushPull>,
9292
{
9393
type WsPin = Pin<WSP, WSN, Ws>;
9494
fn set_alt_mode(&mut self) {

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![no_std]
22
#![allow(non_camel_case_types)]
3+
#![feature(associated_const_equality)]
34

45
#[cfg(not(feature = "device-selected"))]
56
compile_error!(

src/serial.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use nb::block;
2626
mod hal_02;
2727
mod hal_1;
2828

29-
use crate::gpio::{Const, PinA, PushPull, SetAlternate};
29+
use crate::gpio::{PinA, PushPull, SetAlternate};
3030

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

@@ -191,8 +191,8 @@ pub trait Pins<USART> {
191191
}
192192
impl<USART, TX, RX, const TXA: u8, const RXA: u8> Pins<USART> for (TX, RX)
193193
where
194-
TX: PinA<TxPin, USART, A = Const<TXA>> + SetAlternate<TXA, PushPull>,
195-
RX: PinA<RxPin, USART, A = Const<RXA>> + SetAlternate<RXA, PushPull>,
194+
TX: PinA<TxPin, USART, A = { TXA }> + SetAlternate<TXA, PushPull>,
195+
RX: PinA<RxPin, USART, A = { RXA }> + SetAlternate<RXA, PushPull>,
196196
{
197197
fn set_alt_mode(&mut self) {
198198
self.0.set_alt_mode();

src/spi.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use core::ops::Deref;
33
use core::ptr;
44

55
use crate::dma::traits::PeriAddress;
6-
use crate::gpio::{Const, NoPin, PinA, PushPull, SetAlternate};
6+
use crate::gpio::{NoPin, PinA, PushPull, SetAlternate};
77
use crate::pac;
88

99
/// Clock polarity
@@ -72,9 +72,9 @@ pub trait Pins<SPI> {
7272
impl<SPI, SCK, MISO, MOSI, const SCKA: u8, const MISOA: u8, const MOSIA: u8> Pins<SPI>
7373
for (SCK, MISO, MOSI)
7474
where
75-
SCK: PinA<Sck, SPI, A = Const<SCKA>> + SetAlternate<SCKA, PushPull>,
76-
MISO: PinA<Miso, SPI, A = Const<MISOA>> + SetAlternate<MISOA, PushPull>,
77-
MOSI: PinA<Mosi, SPI, A = Const<MOSIA>> + SetAlternate<MOSIA, PushPull>,
75+
SCK: PinA<Sck, SPI, A = { SCKA }> + SetAlternate<SCKA, PushPull>,
76+
MISO: PinA<Miso, SPI, A = { MISOA }> + SetAlternate<MISOA, PushPull>,
77+
MOSI: PinA<Mosi, SPI, A = { MOSIA }> + SetAlternate<MOSIA, PushPull>,
7878
{
7979
fn set_alt_mode(&mut self) {
8080
self.0.set_alt_mode();

0 commit comments

Comments
 (0)