tm4c_hal/
gpio.rs

1//! Code for GPIO pins
2
3use core::marker::PhantomData;
4
5/// All unlocked pin modes implement this
6pub trait IsUnlocked {}
7
8/// All input modes implement this
9pub trait InputMode {}
10
11/// All output modes implement this
12pub trait OutputMode {}
13
14/// OpenDrain modes implement this
15pub trait OpenDrainMode {
16    /// Is pull-up enabled
17    fn pup() -> bool;
18}
19
20/// All the different Alternate Functions you can choose implement this
21pub trait AlternateFunctionChoice {
22    /// Which Alternate Function (numbered 1 through 15) is this?
23    fn number() -> u32;
24}
25
26/// Input mode (type state)
27pub struct Input<MODE>
28where
29    MODE: InputMode,
30{
31    _mode: PhantomData<MODE>,
32}
33impl<MODE> IsUnlocked for Input<MODE> where MODE: InputMode {}
34
35/// Sub-mode of Input: Floating input (type state)
36pub struct Floating;
37impl InputMode for Floating {}
38impl OpenDrainMode for Floating {
39    /// Pull-up is not enabled
40    fn pup() -> bool {
41        false
42    }
43}
44
45/// Sub-mode of Input: Pulled down input (type state)
46pub struct PullDown;
47impl InputMode for PullDown {}
48
49/// Sub-mode of Input: Pulled up input (type state)
50pub struct PullUp;
51impl InputMode for PullUp {}
52impl OpenDrainMode for PullUp {
53    /// Pull-up is enabled
54    fn pup() -> bool {
55        true
56    }
57}
58
59/// Tri-state
60pub struct Tristate;
61impl IsUnlocked for Tristate {}
62
63/// Output mode (type state)
64pub struct Output<MODE>
65where
66    MODE: OutputMode,
67{
68    _mode: PhantomData<MODE>,
69}
70impl<MODE> IsUnlocked for Output<MODE> where MODE: OutputMode {}
71
72/// AlternateFunction mode (type state for a GPIO pin)
73pub struct AlternateFunction<AF, MODE>
74where
75    AF: AlternateFunctionChoice,
76    MODE: OutputMode,
77{
78    _func: PhantomData<AF>,
79    _mode: PhantomData<MODE>,
80}
81impl<AF, MODE> IsUnlocked for AlternateFunction<AF, MODE>
82where
83    AF: AlternateFunctionChoice,
84    MODE: OutputMode,
85{
86}
87
88/// Sub-mode of Output/AlternateFunction: Push pull output (type state for
89/// Output)
90pub struct PushPull;
91impl OutputMode for PushPull {}
92impl OutputMode for PullDown {}
93impl OutputMode for PullUp {}
94
95/// Sub-mode of Output/AlternateFunction: Open drain output (type state for
96/// Output)
97pub struct OpenDrain<ODM>
98where
99    ODM: OpenDrainMode,
100{
101    _pull: PhantomData<ODM>,
102}
103impl<ODM> OutputMode for OpenDrain<ODM> where ODM: OpenDrainMode {}
104
105/// Alternate function 1 (type state)
106pub struct AF1;
107impl AlternateFunctionChoice for AF1 {
108    fn number() -> u32 {
109        1
110    }
111}
112
113/// Alternate function 2 (type state)
114pub struct AF2;
115impl AlternateFunctionChoice for AF2 {
116    fn number() -> u32 {
117        2
118    }
119}
120
121/// Alternate function 3 (type state)
122pub struct AF3;
123impl AlternateFunctionChoice for AF3 {
124    fn number() -> u32 {
125        3
126    }
127}
128
129/// Alternate function 4 (type state)
130pub struct AF4;
131impl AlternateFunctionChoice for AF4 {
132    fn number() -> u32 {
133        4
134    }
135}
136
137/// Alternate function 5 (type state)
138pub struct AF5;
139impl AlternateFunctionChoice for AF5 {
140    fn number() -> u32 {
141        5
142    }
143}
144
145/// Alternate function 6 (type state)
146pub struct AF6;
147impl AlternateFunctionChoice for AF6 {
148    fn number() -> u32 {
149        6
150    }
151}
152
153/// Alternate function 7 (type state)
154pub struct AF7;
155impl AlternateFunctionChoice for AF7 {
156    fn number() -> u32 {
157        7
158    }
159}
160
161/// Alternate function 8 (type state)
162pub struct AF8;
163impl AlternateFunctionChoice for AF8 {
164    fn number() -> u32 {
165        8
166    }
167}
168
169/// Alternate function 9 (type state)
170pub struct AF9;
171impl AlternateFunctionChoice for AF9 {
172    fn number() -> u32 {
173        9
174    }
175}
176
177// 10 through 13 are not available on this chip.
178
179/// Alternate function 14 (type state)
180pub struct AF14;
181impl AlternateFunctionChoice for AF14 {
182    fn number() -> u32 {
183        14
184    }
185}
186
187/// Pin is locked through the GPIOCR register
188pub struct Locked;
189
190/// Sets when a GPIO pin triggers an interrupt.
191pub enum InterruptMode {
192    /// Interrupt when level is low
193    LevelLow,
194    /// Interrupt when level is high
195    LevelHigh,
196    /// Interrupt on rising edge
197    EdgeRising,
198    /// Interrupt on falling edge
199    EdgeFalling,
200    /// Interrupt on both rising and falling edges
201    EdgeBoth,
202    /// Disable interrupts on this pin
203    Disabled,
204}
205
206// End of file