earlgrey/
pinmux_config.rs

1// Licensed under the Apache License, Version 2.0 or the MIT License.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// Copyright Tock Contributors 2022.
4
5//! Chip sepcific pinmux Configurations
6
7use crate::pinmux::{SelectInput, SelectOutput};
8use crate::registers::top_earlgrey::{
9    MuxedPads, PinmuxInsel, PinmuxOutsel, PinmuxPeripheralIn, NUM_MIO_PADS,
10};
11
12/// Number of input selector entry (Last input + 1)
13pub const INPUT_NUM: usize = PinmuxPeripheralIn::UsbdevSense as usize + 1;
14/// Number of output selctor entry
15pub const OUTPUT_NUM: usize = NUM_MIO_PADS;
16
17/// Representations of Earlgrey pinmux configuration on targeted board
18pub trait EarlGreyPinmuxConfig {
19    /// Array representing configuration of pinmux input selctor
20    const INPUT: &'static [PinmuxInsel; INPUT_NUM];
21
22    /// Array representing configurations of pinmux output selecto
23    const OUTPUT: &'static [PinmuxOutsel; OUTPUT_NUM];
24
25    /// Setup pinmux configurations for all multiplexed pads
26    fn setup() {
27        // setup pinmux input
28        for index in 0..INPUT_NUM {
29            if let Ok(peripheral) = PinmuxPeripheralIn::try_from(index as u32) {
30                peripheral.connect_input(Self::INPUT[index]);
31            }
32        }
33        // setup pinmux output
34        for index in 0..OUTPUT_NUM {
35            if let Ok(pad) = MuxedPads::try_from(index as u32) {
36                pad.connect_output(Self::OUTPUT[index]);
37            }
38        }
39    }
40}