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