SPISlave: Add explicit pinmap support

pull/11892/head
Przemyslaw Stekiel 2019-08-09 09:28:57 +02:00
parent beec0f1e84
commit 3a38c6bae0
2 changed files with 20 additions and 0 deletions

View File

@ -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).

View File

@ -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;