mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #10033 from artokin/port_SPI_peripheral_names
Port spi_get_peripheral_name fix to some Freescale boardspull/10046/head
commit
76c2192028
|
@ -124,7 +124,7 @@ typedef enum {
|
||||||
DAC_0 = 0
|
DAC_0 = 0
|
||||||
} DACName;
|
} DACName;
|
||||||
|
|
||||||
|
#define DEVICE_SPI_COUNT 3
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SPI_0 = 0,
|
SPI_0 = 0,
|
||||||
SPI_1 = 1,
|
SPI_1 = 1,
|
||||||
|
|
|
@ -32,6 +32,25 @@ static SPI_Type *const spi_address[] = SPI_BASE_PTRS;
|
||||||
/* Array of SPI bus clock frequencies */
|
/* Array of SPI bus clock frequencies */
|
||||||
static clock_name_t const spi_clocks[] = SPI_CLOCK_FREQS;
|
static clock_name_t const spi_clocks[] = SPI_CLOCK_FREQS;
|
||||||
|
|
||||||
|
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)
|
void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
|
||||||
{
|
{
|
||||||
// determine the SPI to use
|
// determine the SPI to use
|
||||||
|
@ -119,7 +138,8 @@ int spi_master_write(spi_t *obj, int value)
|
||||||
}
|
}
|
||||||
|
|
||||||
int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length,
|
int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length,
|
||||||
char *rx_buffer, int rx_length, char write_fill) {
|
char *rx_buffer, int rx_length, char write_fill)
|
||||||
|
{
|
||||||
int total = (tx_length > rx_length) ? tx_length : rx_length;
|
int total = (tx_length > rx_length) ? tx_length : rx_length;
|
||||||
|
|
||||||
// Default write is done in each and every call, in future can create HAL API instead
|
// Default write is done in each and every call, in future can create HAL API instead
|
||||||
|
|
|
@ -93,7 +93,7 @@ typedef enum {
|
||||||
DAC_0 = 0
|
DAC_0 = 0
|
||||||
} DACName;
|
} DACName;
|
||||||
|
|
||||||
|
#define DEVICE_SPI_COUNT 2
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SPI_0 = 0,
|
SPI_0 = 0,
|
||||||
SPI_1 = 1,
|
SPI_1 = 1,
|
||||||
|
|
|
@ -32,6 +32,25 @@ static SPI_Type *const spi_address[] = SPI_BASE_PTRS;
|
||||||
/* Array of SPI bus clock frequencies */
|
/* Array of SPI bus clock frequencies */
|
||||||
static clock_name_t const spi_clocks[] = SPI_CLOCK_FREQS;
|
static clock_name_t const spi_clocks[] = SPI_CLOCK_FREQS;
|
||||||
|
|
||||||
|
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)
|
void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
|
||||||
{
|
{
|
||||||
// determine the SPI to use
|
// determine the SPI to use
|
||||||
|
@ -118,7 +137,8 @@ int spi_master_write(spi_t *obj, int value)
|
||||||
}
|
}
|
||||||
|
|
||||||
int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length,
|
int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length,
|
||||||
char *rx_buffer, int rx_length, char write_fill) {
|
char *rx_buffer, int rx_length, char write_fill)
|
||||||
|
{
|
||||||
int total = (tx_length > rx_length) ? tx_length : rx_length;
|
int total = (tx_length > rx_length) ? tx_length : rx_length;
|
||||||
|
|
||||||
for (int i = 0; i < total; i++) {
|
for (int i = 0; i < total; i++) {
|
||||||
|
|
|
@ -63,7 +63,7 @@ typedef enum {
|
||||||
DAC_0 = 0
|
DAC_0 = 0
|
||||||
} DACName;
|
} DACName;
|
||||||
|
|
||||||
|
#define DEVICE_SPI_COUNT 2
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SPI_0 = 0,
|
SPI_0 = 0,
|
||||||
SPI_1 = 1,
|
SPI_1 = 1,
|
||||||
|
|
|
@ -64,7 +64,7 @@ typedef enum {
|
||||||
DAC_0 = 0
|
DAC_0 = 0
|
||||||
} DACName;
|
} DACName;
|
||||||
|
|
||||||
|
#define DEVICE_SPI_COUNT 2
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SPI_0 = 0,
|
SPI_0 = 0,
|
||||||
SPI_1 = 1,
|
SPI_1 = 1,
|
||||||
|
|
|
@ -32,6 +32,25 @@ static SPI_Type *const spi_address[] = SPI_BASE_PTRS;
|
||||||
/* Array of SPI bus clock frequencies */
|
/* Array of SPI bus clock frequencies */
|
||||||
static clock_name_t const spi_clocks[] = SPI_CLOCK_FREQS;
|
static clock_name_t const spi_clocks[] = SPI_CLOCK_FREQS;
|
||||||
|
|
||||||
|
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)
|
void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
|
||||||
{
|
{
|
||||||
// determine the SPI to use
|
// determine the SPI to use
|
||||||
|
@ -118,7 +137,8 @@ int spi_master_write(spi_t *obj, int value)
|
||||||
}
|
}
|
||||||
|
|
||||||
int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length,
|
int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length,
|
||||||
char *rx_buffer, int rx_length, char write_fill) {
|
char *rx_buffer, int rx_length, char write_fill)
|
||||||
|
{
|
||||||
int total = (tx_length > rx_length) ? tx_length : rx_length;
|
int total = (tx_length > rx_length) ? tx_length : rx_length;
|
||||||
|
|
||||||
for (int i = 0; i < total; i++) {
|
for (int i = 0; i < total; i++) {
|
||||||
|
|
|
@ -123,7 +123,7 @@ typedef enum {
|
||||||
DAC_0 = 0
|
DAC_0 = 0
|
||||||
} DACName;
|
} DACName;
|
||||||
|
|
||||||
|
#define DEVICE_SPI_COUNT 3
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SPI_0 = 0,
|
SPI_0 = 0,
|
||||||
SPI_1 = 1,
|
SPI_1 = 1,
|
||||||
|
|
|
@ -33,6 +33,25 @@ static SPI_Type *const spi_address[] = SPI_BASE_PTRS;
|
||||||
/* Array of SPI bus clock frequencies */
|
/* Array of SPI bus clock frequencies */
|
||||||
static clock_name_t const spi_clocks[] = SPI_CLOCK_FREQS;
|
static clock_name_t const spi_clocks[] = SPI_CLOCK_FREQS;
|
||||||
|
|
||||||
|
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)
|
void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
|
||||||
{
|
{
|
||||||
// determine the SPI to use
|
// determine the SPI to use
|
||||||
|
@ -128,7 +147,8 @@ int spi_master_write(spi_t *obj, int value)
|
||||||
}
|
}
|
||||||
|
|
||||||
int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length,
|
int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length,
|
||||||
char *rx_buffer, int rx_length, char write_fill) {
|
char *rx_buffer, int rx_length, char write_fill)
|
||||||
|
{
|
||||||
int total = (tx_length > rx_length) ? tx_length : rx_length;
|
int total = (tx_length > rx_length) ? tx_length : rx_length;
|
||||||
|
|
||||||
// Default write is done in each and every call, in future can create HAL API instead
|
// Default write is done in each and every call, in future can create HAL API instead
|
||||||
|
|
Loading…
Reference in New Issue