sdio_host/
sd_cmd.rs

1//! SD-specific command definitions.
2
3use crate::common_cmd::{cmd, Cmd, Resp, R1, R3};
4
5/// R6: Published RCA response
6pub struct R6;
7/// R7: Card interface condition
8pub struct R7;
9
10impl Resp for R6 {}
11impl Resp for R7 {}
12
13/// CMD3: Send RCA
14pub fn send_relative_address() -> Cmd<R6> {
15    cmd(3, 0)
16}
17
18/// CMD6: Switch Function Command
19pub fn cmd6(arg: u32) -> Cmd<R1> {
20    cmd(6, arg)
21}
22
23/// CMD8: Sends memory card interface conditions
24pub fn send_if_cond(voltage: u8, checkpattern: u8) -> Cmd<R7> {
25    let arg = u32::from(voltage & 0xF) << 8 | u32::from(checkpattern);
26    cmd(8, arg)
27}
28
29/// CMD11: Switch to 1.8V bus signaling level
30pub fn voltage_switch() -> Cmd<R1> {
31    cmd(11, 0)
32}
33
34/// CMD19: Send tuning pattern
35pub fn send_tuning_block(addr: u32) -> Cmd<R1> {
36    cmd(19, addr)
37}
38
39/// CMD20: Speed class control
40pub fn speed_class_control(arg: u32) -> Cmd<R1> {
41    cmd(20, arg)
42}
43
44/// CMD22: Address extension
45pub fn address_extension(arg: u32) -> Cmd<R1> {
46    cmd(22, arg)
47}
48
49/// CMD23: Defines the number of blocks (read/write) for a block read or write
50/// operation
51pub fn set_block_count(blockcount: u32) -> Cmd<R1> {
52    cmd(23, blockcount)
53}
54
55/// CMD32: Sets the address of the first write block to be erased
56pub fn erase_wr_blk_start_addr(address: u32) -> Cmd<R1> {
57    cmd(35, address)
58}
59
60/// CMD33: Sets the address of the last write block of the continuous range to
61/// be erased
62pub fn erase_wr_blk_end_addr(address: u32) -> Cmd<R1> {
63    cmd(35, address)
64}
65
66/// CMD36: Sets the address of the last erase group within a continuous range to
67/// be selected for erase
68///
69/// Address is either byte address or sector address (set in OCR)
70pub fn erase_group_end(address: u32) -> Cmd<R1> {
71    cmd(36, address)
72}
73
74/// ACMD6: Bus Width
75/// * `bw4bit` - Enable 4 bit bus width
76pub fn set_bus_width(bw4bit: bool) -> Cmd<R1> {
77    let arg = if bw4bit { 0b10 } else { 0b00 };
78    cmd(6, arg)
79}
80
81/// ACMD13: SD Status
82pub fn sd_status() -> Cmd<R1> {
83    cmd(13, 0)
84}
85
86/// ACMD41: App Op Command
87///
88/// * `host_high_capacity_support` - Host supports high capacity cards
89/// * `sdxc_power_control` - Controls the maximum power and default speed mode of SDXC and SDUC cards
90/// * `switch_to_1_8v_request` - Switch to 1.8V signaling
91/// * `voltage_window` - 9-bit bitfield that represents the voltage window
92/// supported by the host. Use 0x1FF to indicate support for the full range of
93/// voltages
94pub fn sd_send_op_cond(
95    host_high_capacity_support: bool,
96    sdxc_power_control: bool,
97    switch_to_1_8v_request: bool,
98    voltage_window: u16,
99) -> Cmd<R3> {
100    let arg = u32::from(host_high_capacity_support) << 30
101        | u32::from(sdxc_power_control) << 28
102        | u32::from(switch_to_1_8v_request) << 24
103        | u32::from(voltage_window & 0x1FF) << 15;
104    cmd(41, arg)
105}
106
107/// ACMD51: Reads the SCR
108pub fn send_scr() -> Cmd<R1> {
109    cmd(51, 0)
110}