Skip to content

Commit

Permalink
Rename, again
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoernQ committed Jan 17, 2025
1 parent c92f91e commit 7091b11
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 53 deletions.
8 changes: 5 additions & 3 deletions esp-hal/MIGRATING-0.23.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ The more descriptive `gpio::Level` enum is now used to specify output levels of

## SPI Changes

`spi::DataMode` changed the meaning of `DataMode::Single` - it now means 3-wire SPI. Use `DataMode::FourWire` to get the previous behavior.
`spi::DataMode` changed the meaning of `DataMode::Single` - it now means 3-wire SPI (using one data line).

Use `DataMode::SingleTwoDataLines` to get the previous behavior.

```diff
- DataMode::Single,
+ DataMode::FourWire,
+ DataMode::SingleTwoDataLines,
```

`Spi` now offers both, `with_mosi` and `with_sio0`. Consider using `with_sio` for half-duplex SPI except for [DataMode::FourWire] or for a mixed-bus.
`Spi` now offers both, `with_mosi` and `with_sio0`. Consider using `with_sio` for half-duplex SPI except for [DataMode::SingleTwoDataLines] or for a mixed-bus.
24 changes: 13 additions & 11 deletions esp-hal/src/spi/master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl Command {

fn mode(&self) -> DataMode {
match self {
Command::None => DataMode::FourWire,
Command::None => DataMode::SingleTwoDataLines,
Command::_1Bit(_, mode)
| Command::_2Bit(_, mode)
| Command::_3Bit(_, mode)
Expand Down Expand Up @@ -401,7 +401,7 @@ impl Address {

fn mode(&self) -> DataMode {
match self {
Address::None => DataMode::FourWire,
Address::None => DataMode::SingleTwoDataLines,
Address::_1Bit(_, mode)
| Address::_2Bit(_, mode)
| Address::_3Bit(_, mode)
Expand Down Expand Up @@ -640,7 +640,8 @@ where
/// Assign the MOSI (Master Out Slave In) pin for the SPI instance.
///
/// Enables output functionality for the pin, and connects it to the MOSI.
/// You want to use this for full-duplex SPI or [DataMode::FourWire]
/// You want to use this for full-duplex SPI or
/// [DataMode::SingleTwoDataLines]
pub fn with_mosi<MOSI: PeripheralOutput>(self, mosi: impl Peripheral<P = MOSI> + 'd) -> Self {
crate::into_mapped_ref!(mosi);
mosi.enable_output(false);
Expand All @@ -654,8 +655,8 @@ where
///
/// Enables both input and output functionality for the pin, and connects it
/// to the MOSI signal and SIO0 input signal.
/// Use this for half-duplex SPI except for [DataMode::FourWire]. The pin is
/// configured to open-drain mode.
/// Use this for half-duplex SPI except for [DataMode::SingleTwoDataLines].
/// The pin is configured to open-drain mode.
pub fn with_sio0<MOSI: PeripheralOutput>(self, mosi: impl Peripheral<P = MOSI> + 'd) -> Self {
crate::into_mapped_ref!(mosi);
mosi.enable_output(true);
Expand All @@ -671,7 +672,8 @@ where
///
/// Enables input functionality for the pin, and connects it to the MISO
/// signal.
/// You want to use this for full-duplex SPI or [DataMode::FourWire]
/// You want to use this for full-duplex SPI or
/// [DataMode::SingleTwoDataLines]
pub fn with_miso<MISO: PeripheralInput>(self, miso: impl Peripheral<P = MISO> + 'd) -> Self {
crate::into_mapped_ref!(miso);
miso.enable_input(true);
Expand All @@ -685,8 +687,8 @@ where
///
/// Enables both input and output functionality for the pin, and connects it
/// to the MISO signal and SIO1 input signal.
/// Use this for half-duplex SPI except for [DataMode::FourWire]. The pin is
/// configured to open-drain mode.
/// Use this for half-duplex SPI except for [DataMode::SingleTwoDataLines].
/// The pin is configured to open-drain mode.
///
/// Note: You do not need to call [Self::with_miso] when this is used.
pub fn with_sio1<SIO1: PeripheralOutput>(self, miso: impl Peripheral<P = SIO1> + 'd) -> Self {
Expand Down Expand Up @@ -1543,7 +1545,7 @@ mod dma {
{
// On the ESP32, if we don't have data, the address is always sent
// on a single line, regardless of its data mode.
if bytes_to_write == 0 && address.mode() != DataMode::FourWire {
if bytes_to_write == 0 && address.mode() != DataMode::SingleTwoDataLines {
return self.set_up_address_workaround(cmd, address, dummy);
}
}
Expand Down Expand Up @@ -2609,13 +2611,13 @@ impl Driver {
) -> Result<(), Error> {
let reg_block = self.register_block();
match cmd_mode {
DataMode::FourWire => (),
DataMode::SingleTwoDataLines => (),
// FIXME: more detailed error - Only 1-bit commands are supported.
_ => return Err(Error::Unsupported),
}

match address_mode {
DataMode::FourWire => {
DataMode::SingleTwoDataLines => {
reg_block.ctrl().modify(|_, w| {
w.fread_dio().clear_bit();
w.fread_qio().clear_bit();
Expand Down
12 changes: 6 additions & 6 deletions esp-hal/src/spi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ pub enum BitOrder {
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[instability::unstable]
pub enum DataMode {
/// 4-Wire Data Mode - 1 bit, two data lines. (MOSI, MISO)
FourWire,
/// 3-Wire Data Mode, Clock, CS and one data line (SIO0)
/// 1 bit, two data lines. (MOSI, MISO)
SingleTwoDataLines,
/// 1 bit, 1 data line (SIO0)
Single,
/// `Dual` Data Mode - 2 bits, two data lines. (SIO0, SIO1)
/// 2 bits, two data lines. (SIO0, SIO1)
Dual,
/// `Quad` Data Mode - 4 bit, 4 data lines. (SIO0 .. SIO3)
/// 4 bit, 4 data lines. (SIO0 .. SIO3)
Quad,
#[cfg(spi_octal)]
/// `Octal` Data Mode - 8 bit, 8 data lines. (SIO0 .. SIO7)
/// 8 bit, 8 data lines. (SIO0 .. SIO7)
Octal,
}

Expand Down
8 changes: 4 additions & 4 deletions hil-test/tests/qspi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ cfg_if::cfg_if! {

cfg_if::cfg_if! {
if #[cfg(esp32)] {
const COMMAND_DATA_MODES: [DataMode; 1] = [DataMode::FourWire];
const COMMAND_DATA_MODES: [DataMode; 1] = [DataMode::SingleTwoDataLines];
} else {
const COMMAND_DATA_MODES: [DataMode; 2] = [DataMode::FourWire, DataMode::Quad];
const COMMAND_DATA_MODES: [DataMode; 2] = [DataMode::SingleTwoDataLines, DataMode::Quad];
}
}

Expand Down Expand Up @@ -155,7 +155,7 @@ fn execute_write(
assert_eq!(unit0.value() + unit1.value(), 8);

if data_on_multiple_pins {
if command_data_mode == DataMode::FourWire {
if command_data_mode == DataMode::SingleTwoDataLines {
assert_eq!(unit0.value(), 1);
assert_eq!(unit1.value(), 7);
} else {
Expand All @@ -173,7 +173,7 @@ fn execute_write(
assert_eq!(unit0.value() + unit1.value(), 4);

if data_on_multiple_pins {
if command_data_mode == DataMode::FourWire {
if command_data_mode == DataMode::SingleTwoDataLines {
assert_eq!(unit0.value(), 1);
assert_eq!(unit1.value(), 3);
} else {
Expand Down
8 changes: 4 additions & 4 deletions hil-test/tests/spi_half_duplex_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ mod tests {

let transfer = spi
.half_duplex_read(
DataMode::FourWire,
DataMode::SingleTwoDataLines,
Command::None,
Address::None,
0,
Expand All @@ -93,7 +93,7 @@ mod tests {

let transfer = spi
.half_duplex_read(
DataMode::FourWire,
DataMode::SingleTwoDataLines,
Command::None,
Address::None,
0,
Expand Down Expand Up @@ -124,7 +124,7 @@ mod tests {

let mut buffer = [0xAA; DMA_BUFFER_SIZE];
spi.half_duplex_read(
DataMode::FourWire,
DataMode::SingleTwoDataLines,
Command::None,
Address::None,
0,
Expand All @@ -138,7 +138,7 @@ mod tests {
ctx.miso_mirror.set_high();

spi.half_duplex_read(
DataMode::FourWire,
DataMode::SingleTwoDataLines,
Command::None,
Address::None,
0,
Expand Down
8 changes: 4 additions & 4 deletions hil-test/tests/spi_half_duplex_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,21 @@ mod tests {

#[test]
fn test_spi_writes_are_correctly_by_pcnt(ctx: Context) {
super::perform_spi_writes_are_correctly_by_pcnt(ctx, DataMode::FourWire);
super::perform_spi_writes_are_correctly_by_pcnt(ctx, DataMode::SingleTwoDataLines);
}

#[test]
fn test_spidmabus_writes_are_correctly_by_pcnt(ctx: Context) {
super::perform_spidmabus_writes_are_correctly_by_pcnt(ctx, DataMode::FourWire);
super::perform_spidmabus_writes_are_correctly_by_pcnt(ctx, DataMode::SingleTwoDataLines);
}

#[test]
fn test_spi_writes_are_correctly_by_pcnt_tree_wire(ctx: Context) {
super::perform_spi_writes_are_correctly_by_pcnt(ctx, DataMode::FourWire);
super::perform_spi_writes_are_correctly_by_pcnt(ctx, DataMode::SingleTwoDataLines);
}

#[test]
fn test_spidmabus_writes_are_correctly_by_pcnt_tree_wire(ctx: Context) {
super::perform_spidmabus_writes_are_correctly_by_pcnt(ctx, DataMode::FourWire);
super::perform_spidmabus_writes_are_correctly_by_pcnt(ctx, DataMode::SingleTwoDataLines);
}
}
24 changes: 18 additions & 6 deletions hil-test/tests/spi_half_duplex_write_psram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ mod tests {
dma_tx_buf.fill(&[0b0110_1010; DMA_BUFFER_SIZE]);
let transfer = spi
.half_duplex_write(
DataMode::FourWire,
DataMode::SingleTwoDataLines,
Command::None,
Address::None,
0,
Expand All @@ -117,7 +117,7 @@ mod tests {

let transfer = spi
.half_duplex_write(
DataMode::FourWire,
DataMode::SingleTwoDataLines,
Command::None,
Address::None,
0,
Expand Down Expand Up @@ -153,13 +153,25 @@ mod tests {

let buffer = [0b0110_1010; DMA_BUFFER_SIZE];
// Write the buffer where each byte has 3 pos edges.
spi.half_duplex_write(DataMode::FourWire, Command::None, Address::None, 0, &buffer)
.unwrap();
spi.half_duplex_write(
DataMode::SingleTwoDataLines,
Command::None,
Address::None,
0,
&buffer,
)
.unwrap();

assert_eq!(unit.value(), (3 * DMA_BUFFER_SIZE) as _);

spi.half_duplex_write(DataMode::FourWire, Command::None, Address::None, 0, &buffer)
.unwrap();
spi.half_duplex_write(
DataMode::SingleTwoDataLines,
Command::None,
Address::None,
0,
&buffer,
)
.unwrap();

assert_eq!(unit.value(), (6 * DMA_BUFFER_SIZE) as _);
}
Expand Down
20 changes: 10 additions & 10 deletions qa-test/src/bin/qspi_flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ fn main() -> ! {
dma_tx_buf.set_length(0);
let transfer = spi
.half_duplex_write(
DataMode::FourWire,
Command::_8Bit(0x06, DataMode::FourWire),
DataMode::SingleTwoDataLines,
Command::_8Bit(0x06, DataMode::SingleTwoDataLines),
Address::None,
0,
0,
Expand All @@ -113,9 +113,9 @@ fn main() -> ! {
// erase sector
let transfer = spi
.half_duplex_write(
DataMode::FourWire,
Command::_8Bit(0x20, DataMode::FourWire),
Address::_24Bit(0x000000, DataMode::FourWire),
DataMode::SingleTwoDataLines,
Command::_8Bit(0x20, DataMode::SingleTwoDataLines),
Address::_24Bit(0x000000, DataMode::SingleTwoDataLines),
0,
dma_tx_buf.len(),
dma_tx_buf,
Expand All @@ -128,8 +128,8 @@ fn main() -> ! {
// write enable
let transfer = spi
.half_duplex_write(
DataMode::FourWire,
Command::_8Bit(0x06, DataMode::FourWire),
DataMode::SingleTwoDataLines,
Command::_8Bit(0x06, DataMode::SingleTwoDataLines),
Address::None,
0,
dma_tx_buf.len(),
Expand All @@ -147,8 +147,8 @@ fn main() -> ! {
let transfer = spi
.half_duplex_write(
DataMode::Quad,
Command::_8Bit(0x32, DataMode::FourWire),
Address::_24Bit(0x000000, DataMode::FourWire),
Command::_8Bit(0x32, DataMode::SingleTwoDataLines),
Address::_24Bit(0x000000, DataMode::SingleTwoDataLines),
0,
dma_tx_buf.len(),
dma_tx_buf,
Expand All @@ -163,7 +163,7 @@ fn main() -> ! {
let transfer = spi
.half_duplex_read(
DataMode::Quad,
Command::_8Bit(0xeb, DataMode::FourWire),
Command::_8Bit(0xeb, DataMode::SingleTwoDataLines),
Address::_32Bit(0x000000 << 8, DataMode::Quad),
4,
dma_rx_buf.len(),
Expand Down
10 changes: 5 additions & 5 deletions qa-test/src/bin/spi_halfduplex_read_manufacturer_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ fn main() -> ! {
// READ MANUFACTURER ID FROM FLASH CHIP
let mut data = [0u8; 2];
spi.half_duplex_read(
DataMode::FourWire,
Command::_8Bit(0x90, DataMode::FourWire),
Address::_24Bit(0x000000, DataMode::FourWire),
DataMode::SingleTwoDataLines,
Command::_8Bit(0x90, DataMode::SingleTwoDataLines),
Address::_24Bit(0x000000, DataMode::SingleTwoDataLines),
0,
&mut data,
)
Expand All @@ -97,7 +97,7 @@ fn main() -> ! {
let mut data = [0u8; 2];
spi.half_duplex_read(
DataMode::Dual,
Command::_8Bit(0x92, DataMode::FourWire),
Command::_8Bit(0x92, DataMode::SingleTwoDataLines),
Address::_32Bit(0x000000_00, DataMode::Dual),
0,
&mut data,
Expand All @@ -110,7 +110,7 @@ fn main() -> ! {
let mut data = [0u8; 2];
spi.half_duplex_read(
DataMode::Quad,
Command::_8Bit(0x94, DataMode::FourWire),
Command::_8Bit(0x94, DataMode::SingleTwoDataLines),
Address::_32Bit(0x000000_00, DataMode::Quad),
4,
&mut data,
Expand Down

0 comments on commit 7091b11

Please sign in to comment.