diff --git a/drivers/SPISlave.h b/drivers/SPISlave.h index 5b9ae58557..749e45294f 100644 --- a/drivers/SPISlave.h +++ b/drivers/SPISlave.h @@ -71,6 +71,14 @@ public: */ SPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel); + /** Create a SPI slave connected to the specified pins. + * + * @note Either mosi or miso can be specified as NC if not used. + * + * @param explicit_pinmap reference to strucure which holds static pinmap. + */ + SPISlave(const spi_pinmap_t &pinmap); + /** Configure the data transmission format. * * @param bits Number of bits per SPI frame (4 - 16). diff --git a/drivers/source/SPISlave.cpp b/drivers/source/SPISlave.cpp index db870cdea2..a8a1f74c4c 100644 --- a/drivers/source/SPISlave.cpp +++ b/drivers/source/SPISlave.cpp @@ -15,6 +15,7 @@ * limitations under the License. */ #include "drivers/SPISlave.h" +#include "mbed_assert.h" #if DEVICE_SPISLAVE @@ -31,6 +32,17 @@ SPISlave::SPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel) : spi_frequency(&_spi, _hz); } +SPISlave::SPISlave(const spi_pinmap_t &pinmap) : + _spi(), + _bits(8), + _mode(0), + _hz(1000000) +{ + spi_init_direct(&_spi, &pinmap); + spi_format(&_spi, _bits, _mode, 1); + spi_frequency(&_spi, _hz); +} + void SPISlave::format(int bits, int mode) { _bits = bits;