Skip to content

Commit

Permalink
Merge pull request #9845 from jarlamsa/stm_spi_peripheral_name
Browse files Browse the repository at this point in the history
Add spi_get_peripheral_name() to stm_spi
  • Loading branch information
0xc0170 committed Mar 1, 2019
2 parents 7ed16fb + a9f0924 commit 857cd9f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Expand Up @@ -57,6 +57,7 @@ typedef enum {
UART_8 = (int)UART8_BASE
} UARTName;

#define SPI_COUNT 6
typedef enum {
SPI_1 = (int)SPI1_BASE,
SPI_2 = (int)SPI2_BASE,
Expand Down
18 changes: 18 additions & 0 deletions targets/TARGET_STM/stm_spi_api.c
Expand Up @@ -92,6 +92,24 @@ void init_spi(spi_t *obj)
}
}

SPIName spi_get_peripheral_name(PinName mosi, PinName miso, PinName sclk) {
SPIName spi_mosi = (SPIName)pinmap_peripheral(mosi, PinMap_SPI_MOSI);
SPIName spi_miso = (SPIName)pinmap_peripheral(miso, PinMap_SPI_MISO);
SPIName spi_sclk = (SPIName)pinmap_peripheral(sclk, PinMap_SPI_SCLK);

SPIName spi_per;

// If 3 wire SPI is used, the miso is not connected.
if (miso == NC) {
spi_per = (SPIName)pinmap_merge(spi_mosi, spi_sclk);
} else {
SPIName spi_data = (SPIName)pinmap_merge(spi_mosi, spi_miso);
spi_per = (SPIName)pinmap_merge(spi_data, spi_sclk);
}

return spi_per;
}

void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
{
struct spi_s *spiobj = SPI_S(obj);
Expand Down

0 comments on commit 857cd9f

Please sign in to comment.