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