Skip to content

Commit c7c0af8

Browse files
Arto KinnunenCruz Monrreal II
authored andcommitted
Add spi_get_peripheral_name to MCUEpresso spi_api
Fix issue #9149. Port changes from #9845 also to targets: K64F, K66F, KW24D and KW41Z
1 parent 5d3059c commit c7c0af8

File tree

9 files changed

+77
-5
lines changed

9 files changed

+77
-5
lines changed

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K66F/TARGET_FRDM/PeripheralNames.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ typedef enum {
124124
DAC_0 = 0
125125
} DACName;
126126

127-
127+
#define DEVICE_SPI_COUNT 3
128128
typedef enum {
129129
SPI_0 = 0,
130130
SPI_1 = 1,

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K66F/spi_api.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@ static SPI_Type *const spi_address[] = SPI_BASE_PTRS;
3232
/* Array of SPI bus clock frequencies */
3333
static clock_name_t const spi_clocks[] = SPI_CLOCK_FREQS;
3434

35+
SPIName spi_get_peripheral_name(PinName mosi, PinName miso, PinName sclk) {
36+
SPIName spi_mosi = (SPIName)pinmap_peripheral(mosi, PinMap_SPI_MOSI);
37+
SPIName spi_miso = (SPIName)pinmap_peripheral(miso, PinMap_SPI_MISO);
38+
SPIName spi_sclk = (SPIName)pinmap_peripheral(sclk, PinMap_SPI_SCLK);
39+
40+
SPIName spi_per;
41+
42+
// If 3 wire SPI is used, the miso is not connected.
43+
if (miso == NC) {
44+
spi_per = (SPIName)pinmap_merge(spi_mosi, spi_sclk);
45+
} else {
46+
SPIName spi_data = (SPIName)pinmap_merge(spi_mosi, spi_miso);
47+
spi_per = (SPIName)pinmap_merge(spi_data, spi_sclk);
48+
}
49+
50+
return spi_per;
51+
}
52+
3553
void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
3654
{
3755
// determine the SPI to use

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KW24D/TARGET_FRDM/PeripheralNames.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ typedef enum {
9393
DAC_0 = 0
9494
} DACName;
9595

96-
96+
#define DEVICE_SPI_COUNT 2
9797
typedef enum {
9898
SPI_0 = 0,
9999
SPI_1 = 1,

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KW24D/spi_api.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@ static SPI_Type *const spi_address[] = SPI_BASE_PTRS;
3232
/* Array of SPI bus clock frequencies */
3333
static clock_name_t const spi_clocks[] = SPI_CLOCK_FREQS;
3434

35+
SPIName spi_get_peripheral_name(PinName mosi, PinName miso, PinName sclk) {
36+
SPIName spi_mosi = (SPIName)pinmap_peripheral(mosi, PinMap_SPI_MOSI);
37+
SPIName spi_miso = (SPIName)pinmap_peripheral(miso, PinMap_SPI_MISO);
38+
SPIName spi_sclk = (SPIName)pinmap_peripheral(sclk, PinMap_SPI_SCLK);
39+
40+
SPIName spi_per;
41+
42+
// If 3 wire SPI is used, the miso is not connected.
43+
if (miso == NC) {
44+
spi_per = (SPIName)pinmap_merge(spi_mosi, spi_sclk);
45+
} else {
46+
SPIName spi_data = (SPIName)pinmap_merge(spi_mosi, spi_miso);
47+
spi_per = (SPIName)pinmap_merge(spi_data, spi_sclk);
48+
}
49+
50+
return spi_per;
51+
}
52+
3553
void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
3654
{
3755
// determine the SPI to use

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KW41Z/TARGET_FRDM/PeripheralNames.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ typedef enum {
6363
DAC_0 = 0
6464
} DACName;
6565

66-
66+
#define DEVICE_SPI_COUNT 2
6767
typedef enum {
6868
SPI_0 = 0,
6969
SPI_1 = 1,

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KW41Z/TARGET_RAPIDIOT/PeripheralNames.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ typedef enum {
6464
DAC_0 = 0
6565
} DACName;
6666

67-
67+
#define DEVICE_SPI_COUNT 2
6868
typedef enum {
6969
SPI_0 = 0,
7070
SPI_1 = 1,

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KW41Z/spi_api.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@ static SPI_Type *const spi_address[] = SPI_BASE_PTRS;
3232
/* Array of SPI bus clock frequencies */
3333
static clock_name_t const spi_clocks[] = SPI_CLOCK_FREQS;
3434

35+
SPIName spi_get_peripheral_name(PinName mosi, PinName miso, PinName sclk) {
36+
SPIName spi_mosi = (SPIName)pinmap_peripheral(mosi, PinMap_SPI_MOSI);
37+
SPIName spi_miso = (SPIName)pinmap_peripheral(miso, PinMap_SPI_MISO);
38+
SPIName spi_sclk = (SPIName)pinmap_peripheral(sclk, PinMap_SPI_SCLK);
39+
40+
SPIName spi_per;
41+
42+
// If 3 wire SPI is used, the miso is not connected.
43+
if (miso == NC) {
44+
spi_per = (SPIName)pinmap_merge(spi_mosi, spi_sclk);
45+
} else {
46+
SPIName spi_data = (SPIName)pinmap_merge(spi_mosi, spi_miso);
47+
spi_per = (SPIName)pinmap_merge(spi_data, spi_sclk);
48+
}
49+
50+
return spi_per;
51+
}
52+
3553
void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
3654
{
3755
// determine the SPI to use

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralNames.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ typedef enum {
123123
DAC_0 = 0
124124
} DACName;
125125

126-
126+
#define DEVICE_SPI_COUNT 3
127127
typedef enum {
128128
SPI_0 = 0,
129129
SPI_1 = 1,

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/spi_api.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ static SPI_Type *const spi_address[] = SPI_BASE_PTRS;
3333
/* Array of SPI bus clock frequencies */
3434
static clock_name_t const spi_clocks[] = SPI_CLOCK_FREQS;
3535

36+
SPIName spi_get_peripheral_name(PinName mosi, PinName miso, PinName sclk) {
37+
SPIName spi_mosi = (SPIName)pinmap_peripheral(mosi, PinMap_SPI_MOSI);
38+
SPIName spi_miso = (SPIName)pinmap_peripheral(miso, PinMap_SPI_MISO);
39+
SPIName spi_sclk = (SPIName)pinmap_peripheral(sclk, PinMap_SPI_SCLK);
40+
41+
SPIName spi_per;
42+
43+
// If 3 wire SPI is used, the miso is not connected.
44+
if (miso == NC) {
45+
spi_per = (SPIName)pinmap_merge(spi_mosi, spi_sclk);
46+
} else {
47+
SPIName spi_data = (SPIName)pinmap_merge(spi_mosi, spi_miso);
48+
spi_per = (SPIName)pinmap_merge(spi_data, spi_sclk);
49+
}
50+
51+
return spi_per;
52+
}
53+
3654
void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
3755
{
3856
// determine the SPI to use

0 commit comments

Comments
 (0)