rust-embedded / embedded-hal

A Hardware Abstraction Layer (HAL) for embedded systems
Apache License 2.0
1.95k stars 197 forks source link

add SPI struct for master/slave bit #434

Closed DmitriLyalikov closed 1 year ago

DmitriLyalikov commented 1 year ago

I am working on a downstream implementation for a spi slave, and would like to ask, is there a reason that the Spi Mode struct does not include a master or slave type as well? I would like to add this, and I am working actually on the driver for the rp2040 hal. What is the philosophy for not doing this at the generic hal level?

/// SPI mode

[derive(Clone, Copy, PartialEq, Eq)]

pub struct Mode { /// Clock polarity pub polarity: Polarity, /// Clock phase pub phase: Phase, }

Dirbaio commented 1 year ago

The current SPI traits are intentionally for SPI master mode only. The reason is for slave mode the API should be different, so it should be a different trait, not a "mode" bit in the existing trait. See previous discussion at https://github.com/rust-embedded/embedded-hal/pull/396