embassy_stm32/qspi/
enums.rs

1//! Enums used in QSPI configuration.
2
3#[allow(dead_code)]
4#[derive(Copy, Clone)]
5pub(crate) enum QspiMode {
6    IndirectWrite,
7    IndirectRead,
8    AutoPolling,
9    MemoryMapped,
10}
11
12impl Into<u8> for QspiMode {
13    fn into(self) -> u8 {
14        match self {
15            QspiMode::IndirectWrite => 0b00,
16            QspiMode::IndirectRead => 0b01,
17            QspiMode::AutoPolling => 0b10,
18            QspiMode::MemoryMapped => 0b11,
19        }
20    }
21}
22
23/// QSPI lane width
24#[allow(dead_code)]
25#[derive(Copy, Clone)]
26pub enum QspiWidth {
27    /// None
28    NONE,
29    /// Single lane
30    SING,
31    /// Dual lanes
32    DUAL,
33    /// Quad lanes
34    QUAD,
35}
36
37impl Into<u8> for QspiWidth {
38    fn into(self) -> u8 {
39        match self {
40            QspiWidth::NONE => 0b00,
41            QspiWidth::SING => 0b01,
42            QspiWidth::DUAL => 0b10,
43            QspiWidth::QUAD => 0b11,
44        }
45    }
46}
47
48/// Flash bank selection
49#[allow(dead_code)]
50#[derive(Copy, Clone)]
51pub enum FlashSelection {
52    /// Bank 1
53    Flash1,
54    /// Bank 2
55    Flash2,
56}
57
58impl Into<bool> for FlashSelection {
59    fn into(self) -> bool {
60        match self {
61            FlashSelection::Flash1 => false,
62            FlashSelection::Flash2 => true,
63        }
64    }
65}
66
67/// QSPI memory size.
68#[allow(missing_docs)]
69#[derive(Copy, Clone)]
70pub enum MemorySize {
71    _1KiB,
72    _2KiB,
73    _4KiB,
74    _8KiB,
75    _16KiB,
76    _32KiB,
77    _64KiB,
78    _128KiB,
79    _256KiB,
80    _512KiB,
81    _1MiB,
82    _2MiB,
83    _4MiB,
84    _8MiB,
85    _16MiB,
86    _32MiB,
87    _64MiB,
88    _128MiB,
89    _256MiB,
90    _512MiB,
91    _1GiB,
92    _2GiB,
93    _4GiB,
94    Other(u8),
95}
96
97impl Into<u8> for MemorySize {
98    fn into(self) -> u8 {
99        match self {
100            MemorySize::_1KiB => 9,
101            MemorySize::_2KiB => 10,
102            MemorySize::_4KiB => 11,
103            MemorySize::_8KiB => 12,
104            MemorySize::_16KiB => 13,
105            MemorySize::_32KiB => 14,
106            MemorySize::_64KiB => 15,
107            MemorySize::_128KiB => 16,
108            MemorySize::_256KiB => 17,
109            MemorySize::_512KiB => 18,
110            MemorySize::_1MiB => 19,
111            MemorySize::_2MiB => 20,
112            MemorySize::_4MiB => 21,
113            MemorySize::_8MiB => 22,
114            MemorySize::_16MiB => 23,
115            MemorySize::_32MiB => 24,
116            MemorySize::_64MiB => 25,
117            MemorySize::_128MiB => 26,
118            MemorySize::_256MiB => 27,
119            MemorySize::_512MiB => 28,
120            MemorySize::_1GiB => 29,
121            MemorySize::_2GiB => 30,
122            MemorySize::_4GiB => 31,
123            MemorySize::Other(val) => val,
124        }
125    }
126}
127
128/// QSPI Address size
129#[derive(Copy, Clone)]
130pub enum AddressSize {
131    /// 8-bit address
132    _8Bit,
133    /// 16-bit address
134    _16Bit,
135    /// 24-bit address
136    _24bit,
137    /// 32-bit address
138    _32bit,
139}
140
141impl Into<u8> for AddressSize {
142    fn into(self) -> u8 {
143        match self {
144            AddressSize::_8Bit => 0b00,
145            AddressSize::_16Bit => 0b01,
146            AddressSize::_24bit => 0b10,
147            AddressSize::_32bit => 0b11,
148        }
149    }
150}
151
152/// Time the Chip Select line stays high.
153#[allow(missing_docs)]
154#[derive(Copy, Clone)]
155pub enum ChipSelectHighTime {
156    _1Cycle,
157    _2Cycle,
158    _3Cycle,
159    _4Cycle,
160    _5Cycle,
161    _6Cycle,
162    _7Cycle,
163    _8Cycle,
164}
165
166impl Into<u8> for ChipSelectHighTime {
167    fn into(self) -> u8 {
168        match self {
169            ChipSelectHighTime::_1Cycle => 0,
170            ChipSelectHighTime::_2Cycle => 1,
171            ChipSelectHighTime::_3Cycle => 2,
172            ChipSelectHighTime::_4Cycle => 3,
173            ChipSelectHighTime::_5Cycle => 4,
174            ChipSelectHighTime::_6Cycle => 5,
175            ChipSelectHighTime::_7Cycle => 6,
176            ChipSelectHighTime::_8Cycle => 7,
177        }
178    }
179}
180
181/// FIFO threshold.
182#[allow(missing_docs)]
183#[derive(Copy, Clone)]
184pub enum FIFOThresholdLevel {
185    _1Bytes,
186    _2Bytes,
187    _3Bytes,
188    _4Bytes,
189    _5Bytes,
190    _6Bytes,
191    _7Bytes,
192    _8Bytes,
193    _9Bytes,
194    _10Bytes,
195    _11Bytes,
196    _12Bytes,
197    _13Bytes,
198    _14Bytes,
199    _15Bytes,
200    _16Bytes,
201    _17Bytes,
202    _18Bytes,
203    _19Bytes,
204    _20Bytes,
205    _21Bytes,
206    _22Bytes,
207    _23Bytes,
208    _24Bytes,
209    _25Bytes,
210    _26Bytes,
211    _27Bytes,
212    _28Bytes,
213    _29Bytes,
214    _30Bytes,
215    _31Bytes,
216    _32Bytes,
217}
218
219impl Into<u8> for FIFOThresholdLevel {
220    fn into(self) -> u8 {
221        match self {
222            FIFOThresholdLevel::_1Bytes => 0,
223            FIFOThresholdLevel::_2Bytes => 1,
224            FIFOThresholdLevel::_3Bytes => 2,
225            FIFOThresholdLevel::_4Bytes => 3,
226            FIFOThresholdLevel::_5Bytes => 4,
227            FIFOThresholdLevel::_6Bytes => 5,
228            FIFOThresholdLevel::_7Bytes => 6,
229            FIFOThresholdLevel::_8Bytes => 7,
230            FIFOThresholdLevel::_9Bytes => 8,
231            FIFOThresholdLevel::_10Bytes => 9,
232            FIFOThresholdLevel::_11Bytes => 10,
233            FIFOThresholdLevel::_12Bytes => 11,
234            FIFOThresholdLevel::_13Bytes => 12,
235            FIFOThresholdLevel::_14Bytes => 13,
236            FIFOThresholdLevel::_15Bytes => 14,
237            FIFOThresholdLevel::_16Bytes => 15,
238            FIFOThresholdLevel::_17Bytes => 16,
239            FIFOThresholdLevel::_18Bytes => 17,
240            FIFOThresholdLevel::_19Bytes => 18,
241            FIFOThresholdLevel::_20Bytes => 19,
242            FIFOThresholdLevel::_21Bytes => 20,
243            FIFOThresholdLevel::_22Bytes => 21,
244            FIFOThresholdLevel::_23Bytes => 22,
245            FIFOThresholdLevel::_24Bytes => 23,
246            FIFOThresholdLevel::_25Bytes => 24,
247            FIFOThresholdLevel::_26Bytes => 25,
248            FIFOThresholdLevel::_27Bytes => 26,
249            FIFOThresholdLevel::_28Bytes => 27,
250            FIFOThresholdLevel::_29Bytes => 28,
251            FIFOThresholdLevel::_30Bytes => 29,
252            FIFOThresholdLevel::_31Bytes => 30,
253            FIFOThresholdLevel::_32Bytes => 31,
254        }
255    }
256}
257
258/// Dummy cycle count
259#[allow(missing_docs)]
260#[derive(Copy, Clone)]
261pub enum DummyCycles {
262    _0,
263    _1,
264    _2,
265    _3,
266    _4,
267    _5,
268    _6,
269    _7,
270    _8,
271    _9,
272    _10,
273    _11,
274    _12,
275    _13,
276    _14,
277    _15,
278    _16,
279    _17,
280    _18,
281    _19,
282    _20,
283    _21,
284    _22,
285    _23,
286    _24,
287    _25,
288    _26,
289    _27,
290    _28,
291    _29,
292    _30,
293    _31,
294}
295
296impl Into<u8> for DummyCycles {
297    fn into(self) -> u8 {
298        match self {
299            DummyCycles::_0 => 0,
300            DummyCycles::_1 => 1,
301            DummyCycles::_2 => 2,
302            DummyCycles::_3 => 3,
303            DummyCycles::_4 => 4,
304            DummyCycles::_5 => 5,
305            DummyCycles::_6 => 6,
306            DummyCycles::_7 => 7,
307            DummyCycles::_8 => 8,
308            DummyCycles::_9 => 9,
309            DummyCycles::_10 => 10,
310            DummyCycles::_11 => 11,
311            DummyCycles::_12 => 12,
312            DummyCycles::_13 => 13,
313            DummyCycles::_14 => 14,
314            DummyCycles::_15 => 15,
315            DummyCycles::_16 => 16,
316            DummyCycles::_17 => 17,
317            DummyCycles::_18 => 18,
318            DummyCycles::_19 => 19,
319            DummyCycles::_20 => 20,
320            DummyCycles::_21 => 21,
321            DummyCycles::_22 => 22,
322            DummyCycles::_23 => 23,
323            DummyCycles::_24 => 24,
324            DummyCycles::_25 => 25,
325            DummyCycles::_26 => 26,
326            DummyCycles::_27 => 27,
327            DummyCycles::_28 => 28,
328            DummyCycles::_29 => 29,
329            DummyCycles::_30 => 30,
330            DummyCycles::_31 => 31,
331        }
332    }
333}