sdmmc-core 0.5.0

SD/MMC core data structures and algorithms
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
//! Card-Specific Data (`CSD`) register.

use crate::Crc7;
use crate::result::{Error, Result};

mod bl_len;
mod ccc;
mod copied;
mod dsr_imp;
mod erase_blk_en;
mod file_format;
mod file_format_grp;
pub mod mmc;
mod nsac;
mod perm_write_protect;
mod r2w_factor;
mod read_bl_partial;
mod read_blk_misalign;
mod sector_size;
mod structure;
mod tmp_write_protect;
mod tran_speed;
pub mod v1;
pub mod v2;
pub mod v3;
mod vdd_curr;
mod wp_grp_enable;
mod wp_grp_size;
mod wp_upc;
mod write_bl_len;
mod write_bl_partial;
mod write_blk_misalign;

pub use bl_len::*;
pub use ccc::*;
pub use copied::Copied;
pub use dsr_imp::DsrImplemented;
pub use erase_blk_en::EraseBlockEnable;
pub use file_format::*;
pub use file_format_grp::FileFormatGroup;
pub use mmc::{ContentProtectionApp, CsdMmc, CsdStructure as MmcCsdStructure, Ecc};
pub use nsac::*;
pub use perm_write_protect::PermanentWriteProtect;
pub use r2w_factor::WriteSpeedFactor;
pub use read_bl_partial::ReadBlockPartial;
pub use read_blk_misalign::ReadBlockMisalign;
pub use sector_size::SectorSize;
pub use structure::CsdStructure as SdCsdStructure;
pub use tmp_write_protect::TemporaryWriteProtect;
pub use tran_speed::*;
pub use v1::CsdV1;
pub use v2::CsdV2;
pub use v3::CsdV3;
pub use vdd_curr::*;
pub use wp_grp_enable::WriteProtectGroupEnable;
pub use wp_grp_size::WriteProtectGroupSize;
pub use wp_upc::WriteProtectUntilPowerCycle;
pub use write_bl_len::*;
pub use write_bl_partial::WriteBlockPartial;
pub use write_blk_misalign::WriteBlockMisalign;

/// Represents the byte length of the `CSD` register.
pub const CSD_LEN: usize = 16;

/// Represents the `CSD_STRUCTURE` field of the [Csd] register.
pub enum CsdStructure {
    /// Represents the `CSD_STRUCTURE` field in the SD Card protocol specification.
    Sd(SdCsdStructure),
    /// Represents the `CSD_STRUCTURE` field in the MMC protocol specification.
    Mmc(MmcCsdStructure),
}

impl CsdStructure {
    /// Attempts to convert the [CsdStructure] into its inner representation.
    pub const fn into_sd(self) -> Result<SdCsdStructure> {
        match self {
            Self::Sd(csd) => Ok(csd),
            _ => Err(Error::Invalid),
        }
    }

    /// Attempts to convert the [CsdStructure] into its inner representation.
    pub const fn into_mmc(self) -> Result<MmcCsdStructure> {
        match self {
            Self::Mmc(csd) => Ok(csd),
            _ => Err(Error::Invalid),
        }
    }
}

/// Represents the `TAAC` field of the [Csd] register.
pub enum Taac {
    /// Represents the `TAAC` field in the SD Card V1 protocol specification.
    V1(v1::TimeAsyncAccessCycles),
    /// Represents the `TAAC` field in the SD Card V2 protocol specification.
    V2(v2::TimeAsyncAccessCycles),
    /// Represents the `TAAC` field in the SD Card V3 protocol specification.
    V3(v3::TimeAsyncAccessCycles),
    /// Represents the `TAAC` field in the MMC protocol specification.
    Mmc(mmc::TimeAsyncAccessCycles),
}

impl Taac {
    /// Attempts to convert the [Taac] into its inner representation.
    pub const fn into_v1(self) -> Result<v1::TimeAsyncAccessCycles> {
        match self {
            Self::V1(taac) => Ok(taac),
            _ => Err(Error::Invalid),
        }
    }

    /// Attempts to convert the [Taac] into its inner representation.
    pub const fn into_v2(self) -> Result<v2::TimeAsyncAccessCycles> {
        match self {
            Self::V2(taac) => Ok(taac),
            _ => Err(Error::Invalid),
        }
    }

    /// Attempts to convert the [Taac] into its inner representation.
    pub const fn into_v3(self) -> Result<v3::TimeAsyncAccessCycles> {
        match self {
            Self::V3(taac) => Ok(taac),
            _ => Err(Error::Invalid),
        }
    }

    /// Attempts to convert the [Taac] into its inner representation.
    pub const fn into_mmc(self) -> Result<mmc::TimeAsyncAccessCycles> {
        match self {
            Self::Mmc(taac) => Ok(taac),
            _ => Err(Error::Invalid),
        }
    }
}

/// Represents the Card-Specific Data (CSD) register value returned in a `R2` response in SD mode.
#[repr(C)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Csd {
    V1(CsdV1),
    V2(CsdV2),
    V3(CsdV3),
    Mmc(CsdMmc),
}

impl Csd {
    /// Represents the byte length of the `CSD` register.
    pub const LEN: usize = CSD_LEN;

    /// Creates a new [Csd].
    pub const fn new() -> Self {
        Self::V1(CsdV1::new())
    }

    /// Gets the byte length of the [Csd].
    pub const fn len(&self) -> usize {
        Self::LEN
    }

    /// Gets whether the [Csd] is empty: always false.
    pub const fn is_empty(&self) -> bool {
        false
    }

    /// Parses the byte slice into a [CsdV1] register variant.
    pub const fn parse_v1(val: &[u8]) -> Result<Self> {
        match CsdV1::try_from_bytes(val) {
            Ok(v) => Ok(Self::V1(v)),
            Err(err) => Err(err),
        }
    }

    /// Parses the byte slice into a [CsdV2] register variant.
    pub const fn parse_v2(val: &[u8]) -> Result<Self> {
        match CsdV2::try_from_bytes(val) {
            Ok(v) => Ok(Self::V2(v)),
            Err(err) => Err(err),
        }
    }

    /// Parses the byte slice into a [CsdV3] register variant.
    pub const fn parse_v3(val: &[u8]) -> Result<Self> {
        match CsdV3::try_from_bytes(val) {
            Ok(v) => Ok(Self::V3(v)),
            Err(err) => Err(err),
        }
    }

    /// Parses the byte slice into a [CsdMmc] register variant.
    pub const fn parse_mmc(val: &[u8]) -> Result<Self> {
        match CsdMmc::try_from_bytes(val) {
            Ok(v) => Ok(Self::Mmc(v)),
            Err(err) => Err(err),
        }
    }

    /// Attempts to convert a byte slice into a [Csd].
    pub const fn try_from_bytes(val: &[u8]) -> Result<Self> {
        match val.len() {
            len if len < Self::LEN => Err(Error::invalid_length(len, Self::LEN)),
            _ => {
                let is_mmc = matches!(
                    mmc::SpecificationVersion::try_from_inner((val[0] >> 2) & 0xf),
                    Ok(mmc::SpecificationVersion::Version4x5x),
                );

                match SdCsdStructure::from_raw(val[0]) {
                    Ok(SdCsdStructure::V1) if !is_mmc => Self::parse_v1(val),
                    Ok(SdCsdStructure::V2) if !is_mmc => Self::parse_v2(val),
                    Ok(SdCsdStructure::V3) if !is_mmc => Self::parse_v3(val),
                    _ if is_mmc => Self::parse_mmc(val),
                    _ => Err(Error::Invalid),
                }
            }
        }
    }

    /// Converts the [Csd] into a byte array.
    pub const fn bytes(&self) -> [u8; Self::LEN] {
        match self {
            Self::V1(csd) => csd.into_inner(),
            Self::V2(csd) => csd.into_inner(),
            Self::V3(csd) => csd.into_inner(),
            Self::Mmc(csd) => csd.into_inner(),
        }
    }

    /// Gets the `CSD_STRUCTURE` field of the [Csd] register.
    pub const fn csd_structure(&self) -> Result<CsdStructure> {
        match self {
            Self::V1(csd) => match csd.csd_structure() {
                Ok(c) => Ok(CsdStructure::Sd(c)),
                Err(err) => Err(err),
            },
            Self::V2(csd) => match csd.csd_structure() {
                Ok(c) => Ok(CsdStructure::Sd(c)),
                Err(err) => Err(err),
            },
            Self::V3(csd) => match csd.csd_structure() {
                Ok(c) => Ok(CsdStructure::Sd(c)),
                Err(err) => Err(err),
            },
            Self::Mmc(csd) => Ok(CsdStructure::Mmc(csd.csd_structure())),
        }
    }

    /// Gets the `TAAC` field of the [Csd] register.
    pub const fn taac(&self) -> Result<Taac> {
        match self {
            Self::V1(csd) => match csd.taac() {
                Ok(taac) => Ok(Taac::V1(taac)),
                Err(err) => Err(err),
            },
            Self::V2(csd) => match csd.taac() {
                Ok(taac) => Ok(Taac::V2(taac)),
                Err(err) => Err(err),
            },
            Self::V3(csd) => match csd.taac() {
                Ok(taac) => Ok(Taac::V3(taac)),
                Err(err) => Err(err),
            },
            Self::Mmc(csd) => match csd.taac() {
                Ok(taac) => Ok(Taac::Mmc(taac)),
                Err(err) => Err(err),
            },
        }
    }

    /// Gets the `NSAC` field of the [Csd] register.
    pub const fn nsac(&self) -> Result<NsAccessCycles> {
        match self {
            Self::V1(csd) => Ok(csd.nsac()),
            Self::V2(csd) => csd.nsac(),
            Self::V3(csd) => csd.nsac(),
            Self::Mmc(csd) => Ok(csd.nsac()),
        }
    }

    /// Gets the `TRAN_SPEED` field of the [Csd] register.
    pub const fn tran_speed(&self) -> Result<TransferSpeed> {
        match self {
            Self::V1(csd) => csd.tran_speed(),
            Self::V2(csd) => csd.tran_speed(),
            Self::V3(csd) => csd.tran_speed(),
            Self::Mmc(csd) => csd.tran_speed(),
        }
    }

    /// Gets the `CCC` field of the [Csd] register.
    pub const fn ccc(&self) -> CardCommandClass {
        match self {
            Self::V1(csd) => csd.ccc(),
            Self::V2(csd) => csd.ccc(),
            Self::V3(csd) => csd.ccc(),
            Self::Mmc(csd) => csd.ccc(),
        }
    }

    /// Gets the effective value of the `C_SIZE` field of the [Csd] register.
    ///
    /// # Note
    ///
    /// The effective size is calculated with the algorithm:
    ///
    /// ```no_build,no_run
    /// size = C_SIZE + 1
    /// ```
    pub const fn c_size(&self) -> usize {
        match self {
            Self::V1(csd) => csd.c_size().size(),
            Self::V2(csd) => csd.c_size().size(),
            Self::V3(csd) => csd.c_size().size(),
            Self::Mmc(csd) => csd.c_size().size(),
        }
    }

    /// Gets the effective value of the `C_SIZE_MULT` field of the [Csd] register.
    ///
    /// # Note
    ///
    /// The effective size is calculated with the algorithm:
    ///
    /// ```no_build,no_run
    /// mult = C_SIZE_MULT + 2
    /// ```
    ///
    /// For [CsdV2] and [CsdV3], `C_SIZE_MULT` is always `1`.
    pub const fn c_size_mult(&self) -> usize {
        match self {
            Self::V1(csd) => csd.c_size_mult().mult(),
            Self::V2(csd) => 1,
            Self::V3(csd) => 1,
            Self::Mmc(csd) => csd.c_size_mult().mult(),
        }
    }

    /// Gets the capacity of device indicated by the [Csd] register.
    pub const fn capacity(&self) -> Result<u64> {
        match self {
            Self::V1(csd) => match csd.capacity() {
                Ok(c) => Ok(c as u64),
                Err(err) => Err(err),
            },
            Self::V2(csd) => Ok(csd.capacity()),
            Self::V3(csd) => Ok(csd.capacity()),
            Self::Mmc(csd) => match csd.capacity() {
                Ok(c) => Ok(c as u64),
                Err(err) => Err(err),
            },
        }
    }

    /// Gets the `ERASE_SIZE` field of the [Csd] register.
    pub const fn erase_size(&self) -> u32 {
        match self {
            Self::V1(_) => 1,
            Self::V2(_) => 1,
            Self::V3(_) => 1,
            Self::Mmc(csd) => csd.erase_size() as u32,
        }
    }

    /// Attempts to get the `READ_BL_LEN` field for the [Csd].
    pub const fn read_bl_len(&self) -> Result<BlockLength> {
        match self {
            Self::V1(csd) => csd.read_bl_len(),
            Self::V2(csd) => csd.read_bl_len(),
            Self::V3(csd) => csd.read_bl_len(),
            Self::Mmc(csd) => csd.read_bl_len(),
        }
    }

    /// Gets the `READ_BL_PARTIAL` field for the [Csd] register.
    pub const fn read_bl_partial(&self) -> ReadBlockPartial {
        match self {
            Self::V1(csd) => csd.read_bl_partial(),
            Self::V2(csd) => csd.read_bl_partial(),
            Self::V3(csd) => csd.read_bl_partial(),
            Self::Mmc(csd) => csd.read_bl_partial(),
        }
    }

    /// Gets the `READ_BLK_MISALIGN` field for the [Csd] register.
    pub const fn read_blk_misalign(&self) -> ReadBlockMisalign {
        match self {
            Self::V1(csd) => csd.read_blk_misalign(),
            Self::V2(csd) => csd.read_blk_misalign(),
            Self::V3(csd) => csd.read_blk_misalign(),
            Self::Mmc(csd) => csd.read_blk_misalign(),
        }
    }

    /// Attempts to get the `WRITE_BL_LEN` field for the [Csd].
    pub const fn write_bl_len(&self) -> Result<BlockLength> {
        match self {
            Self::V1(csd) => csd.write_bl_len(),
            Self::V2(csd) => csd.write_bl_len(),
            Self::V3(csd) => csd.write_bl_len(),
            Self::Mmc(csd) => csd.write_bl_len(),
        }
    }

    /// Gets the `WRITE_BL_PARTIAL` field for the [Csd] register.
    pub const fn write_bl_partial(&self) -> WriteBlockPartial {
        match self {
            Self::V1(csd) => csd.write_bl_partial(),
            Self::V2(csd) => csd.write_bl_partial(),
            Self::V3(csd) => csd.write_bl_partial(),
            Self::Mmc(csd) => csd.write_bl_partial(),
        }
    }

    /// Gets the `WRITE_BLK_MISALIGN` field for the [Csd] register.
    pub const fn write_blk_misalign(&self) -> WriteBlockMisalign {
        match self {
            Self::V1(csd) => csd.write_blk_misalign(),
            Self::V2(csd) => csd.write_blk_misalign(),
            Self::V3(csd) => csd.write_blk_misalign(),
            Self::Mmc(csd) => csd.write_blk_misalign(),
        }
    }

    /// Gets the `DSR_IMP` field for the [Csd] register.
    pub const fn dsr_imp(&self) -> DsrImplemented {
        match self {
            Self::V1(csd) => csd.dsr_imp(),
            Self::V2(csd) => csd.dsr_imp(),
            Self::V3(csd) => csd.dsr_imp(),
            Self::Mmc(csd) => csd.dsr_imp(),
        }
    }

    /// Gets the `VDD_R_CURR_MIN` field for the [Csd] register.
    pub const fn vdd_r_curr_min(&self) -> Result<VddCurrentMin> {
        match self {
            Self::V1(csd) => csd.vdd_r_curr_min(),
            Self::V2(csd) => Err(Error::unimplemented()),
            Self::V3(csd) => Err(Error::unimplemented()),
            Self::Mmc(csd) => csd.vdd_r_curr_min(),
        }
    }

    /// Gets the `VDD_R_CURR_MAX` field for the [Csd] register.
    pub const fn vdd_r_curr_max(&self) -> Result<VddCurrentMax> {
        match self {
            Self::V1(csd) => csd.vdd_r_curr_max(),
            Self::V2(csd) => Err(Error::unimplemented()),
            Self::V3(csd) => Err(Error::unimplemented()),
            Self::Mmc(csd) => csd.vdd_r_curr_max(),
        }
    }

    /// Gets the `VDD_W_CURR_MIN` field for the [Csd] register.
    pub const fn vdd_w_curr_min(&self) -> Result<VddCurrentMin> {
        match self {
            Self::V1(csd) => csd.vdd_w_curr_min(),
            Self::V2(csd) => Err(Error::unimplemented()),
            Self::V3(csd) => Err(Error::unimplemented()),
            Self::Mmc(csd) => csd.vdd_w_curr_min(),
        }
    }

    /// Gets the `VDD_W_CURR_MAX` field for the [Csd] register.
    pub const fn vdd_w_curr_max(&self) -> Result<VddCurrentMax> {
        match self {
            Self::V1(csd) => csd.vdd_w_curr_max(),
            Self::V2(csd) => Err(Error::unimplemented()),
            Self::V3(csd) => Err(Error::unimplemented()),
            Self::Mmc(csd) => csd.vdd_w_curr_max(),
        }
    }

    /// Gets the `ERASE_BLK_EN` field for the [Csd] register.
    pub const fn erase_blk_en(&self) -> Result<EraseBlockEnable> {
        match self {
            Self::V1(csd) => Ok(csd.erase_blk_en()),
            Self::V2(csd) => Ok(csd.erase_blk_en()),
            Self::V3(csd) => Ok(csd.erase_blk_en()),
            Self::Mmc(csd) => Err(Error::unimplemented()),
        }
    }

    /// Gets the `SECTOR_SIZE` field for the [Csd] register.
    pub const fn sector_size(&self) -> Result<SectorSize> {
        match self {
            Self::V1(csd) => Ok(csd.sector_size()),
            Self::V2(csd) => csd.sector_size(),
            Self::V3(csd) => csd.sector_size(),
            Self::Mmc(csd) => Err(Error::unimplemented()),
        }
    }

    /// Gets the `WP_GRP_SIZE` field of the [Csd] register.
    pub const fn wp_grp_size(&self) -> usize {
        match self {
            Self::V1(csd) => csd.wp_grp_size().size(),
            Self::V2(csd) => csd.wp_grp_size().size(),
            Self::V3(csd) => csd.wp_grp_size().size(),
            Self::Mmc(csd) => csd.wp_grp_size().size(),
        }
    }

    /// Gets the `WP_GRP_ENABLE` field of the [Csd] register.
    pub const fn wp_grp_enable(&self) -> WriteProtectGroupEnable {
        match self {
            Self::V1(csd) => csd.wp_grp_enable(),
            Self::V2(csd) => csd.wp_grp_enable(),
            Self::V3(csd) => csd.wp_grp_enable(),
            Self::Mmc(csd) => csd.wp_grp_enable(),
        }
    }

    /// Gets the `DEFAULT_ECC` field of the [Csd] register.
    pub const fn default_ecc(&self) -> Result<Ecc> {
        match self {
            Self::V1(csd) => Err(Error::unimplemented()),
            Self::V2(csd) => Err(Error::unimplemented()),
            Self::V3(csd) => Err(Error::unimplemented()),
            Self::Mmc(csd) => csd.default_ecc(),
        }
    }

    /// Gets the `R2W_FACTOR` field of the [Csd] register.
    pub const fn r2w_factor(&self) -> Result<WriteSpeedFactor> {
        match self {
            Self::V1(csd) => csd.r2w_factor(),
            Self::V2(csd) => csd.r2w_factor(),
            Self::V3(csd) => csd.r2w_factor(),
            Self::Mmc(csd) => csd.r2w_factor(),
        }
    }

    /// Gets the `CONTENT_PROT_APP` field of the [Csd] register.
    pub const fn content_prot_app(&self) -> Result<ContentProtectionApp> {
        match self {
            Self::V1(csd) => Err(Error::unimplemented()),
            Self::V2(csd) => Err(Error::unimplemented()),
            Self::V3(csd) => Err(Error::unimplemented()),
            Self::Mmc(csd) => Ok(csd.content_prot_app()),
        }
    }

    /// Gets the `FILE_FORMAT_GRP` field of the [Csd] register.
    pub const fn file_format_grp(&self) -> FileFormatGroup {
        match self {
            Self::V1(csd) => csd.file_format_grp(),
            Self::V2(csd) => csd.file_format_grp(),
            Self::V3(csd) => csd.file_format_grp(),
            Self::Mmc(csd) => csd.file_format_grp(),
        }
    }

    /// Gets the `COPY` field of the [Csd] register.
    pub const fn copy(&self) -> Copied {
        match self {
            Self::V1(csd) => csd.copy(),
            Self::V2(csd) => csd.copy(),
            Self::V3(csd) => csd.copy(),
            Self::Mmc(csd) => csd.copy(),
        }
    }

    /// Gets the `PERM_WRITE_PROTECT` field of the [Csd] register.
    pub const fn perm_write_protect(&self) -> PermanentWriteProtect {
        match self {
            Self::V1(csd) => csd.perm_write_protect(),
            Self::V2(csd) => csd.perm_write_protect(),
            Self::V3(csd) => csd.perm_write_protect(),
            Self::Mmc(csd) => csd.perm_write_protect(),
        }
    }

    /// Gets the `TMP_WRITE_PROTECT` field of the [Csd] register.
    pub const fn tmp_write_protect(&self) -> TemporaryWriteProtect {
        match self {
            Self::V1(csd) => csd.tmp_write_protect(),
            Self::V2(csd) => csd.tmp_write_protect(),
            Self::V3(csd) => csd.tmp_write_protect(),
            Self::Mmc(csd) => csd.tmp_write_protect(),
        }
    }

    /// Gets the `WP_UPC` field of the [Csd] register.
    pub const fn wp_upc(&self) -> Result<WriteProtectUntilPowerCycle> {
        match self {
            Self::V1(csd) => Ok(csd.wp_upc()),
            Self::V2(csd) => Ok(csd.wp_upc()),
            Self::V3(csd) => Ok(csd.wp_upc()),
            Self::Mmc(csd) => Err(Error::unimplemented()),
        }
    }

    /// Gets the `FILE_FORMAT` field of the [Csd] register.
    pub const fn file_format(&self) -> Result<FileFormat> {
        match self {
            Self::V1(csd) => csd.file_format(),
            Self::V2(csd) => csd.file_format(),
            Self::V3(csd) => csd.file_format(),
            Self::Mmc(csd) => csd.file_format(),
        }
    }

    /// Gets the `ECC` field of the [Csd] register.
    pub const fn ecc(&self) -> Result<Ecc> {
        match self {
            Self::V1(csd) => Err(Error::unimplemented()),
            Self::V2(csd) => Err(Error::unimplemented()),
            Self::V3(csd) => Err(Error::unimplemented()),
            Self::Mmc(csd) => csd.ecc(),
        }
    }

    /// Gets the `CRC` field of the [Csd] register.
    pub const fn crc(&self) -> Crc7 {
        match self {
            Self::V1(csd) => csd.crc(),
            Self::V2(csd) => csd.crc(),
            Self::V3(csd) => csd.crc(),
            Self::Mmc(csd) => csd.crc(),
        }
    }
}

impl Default for Csd {
    fn default() -> Self {
        Self::new()
    }
}

impl TryFrom<&[u8]> for Csd {
    type Error = Error;

    fn try_from(val: &[u8]) -> Result<Csd> {
        Csd::try_from_bytes(val)
    }
}

impl From<Csd> for [u8; Csd::LEN] {
    fn from(val: Csd) -> Self {
        val.bytes()
    }
}