Skip to content

Commit 154a7eb

Browse files
committed
ports: analog: Update SPI peripheral helpers
- Fix pinsToSpi function signature to correctly matchup pins - Pin changes for MAX32665 to match package on common Eval boards - Use '&' instead of '==' for pinmasks to allow for easier pin usage in C code (This may make it simpler to copy GPIO structs from MSDK down the line) Signed-off-by: Brandon-Hurst <brandon.hurst97@gmail.com>
1 parent 2b9f722 commit 154a7eb

3 files changed

Lines changed: 12 additions & 15 deletions

File tree

ports/analog/peripherals/max32650/max32_spi.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ const mxc_gpio_cfg_t spi_maps[NUM_SPI] = {
2929
MXC_GPIO_FUNC_ALT1, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
3030
};
3131

32-
int pinsToSpi(const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso,
33-
const mcu_pin_obj_t *sck) {
32+
int pinsToSpi(const mcu_pin_obj_t *sck, const mcu_pin_obj_t *mosi,
33+
const mcu_pin_obj_t *miso) {
3434
for (int i = 0; i < NUM_SPI; i++) {
3535
if ((spi_maps[i].port == (MXC_GPIO_GET_GPIO(mosi->port)))
36-
&& (spi_maps[i].mask == ((mosi->mask) | (miso->mask) | (sck->mask)))) {
36+
&& (spi_maps[i].mask & ((mosi->mask) | (miso->mask) | (sck->mask)))) {
3737
return i;
3838
}
3939
}

ports/analog/peripherals/max32665/max32_spi.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,22 @@
1919

2020
const mxc_gpio_cfg_t spi_maps[NUM_SPI] = {
2121
// SPI0A
22-
{ MXC_GPIO1,
23-
(MXC_GPIO_PIN_9 | MXC_GPIO_PIN_10 | MXC_GPIO_PIN_11 | MXC_GPIO_PIN_12 | MXC_GPIO_PIN_13),
22+
{ MXC_GPIO1, (MXC_GPIO_PIN_9 | MXC_GPIO_PIN_10 | MXC_GPIO_PIN_11),
2423
MXC_GPIO_FUNC_ALT1, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
2524
// SPI1
26-
{ MXC_GPIO0,
27-
(MXC_GPIO_PIN_17 | MXC_GPIO_PIN_18 | MXC_GPIO_PIN_19 | MXC_GPIO_PIN_20 | MXC_GPIO_PIN_21),
25+
{ MXC_GPIO0, (MXC_GPIO_PIN_17 | MXC_GPIO_PIN_18 | MXC_GPIO_PIN_19),
2826
MXC_GPIO_FUNC_ALT2, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
2927
// SPI2
30-
{ MXC_GPIO0,
31-
(MXC_GPIO_PIN_25 | MXC_GPIO_PIN_26 | MXC_GPIO_PIN_27 | MXC_GPIO_PIN_28 | MXC_GPIO_PIN_29),
28+
{ MXC_GPIO0, (MXC_GPIO_PIN_25 | MXC_GPIO_PIN_26 | MXC_GPIO_PIN_27),
3229
MXC_GPIO_FUNC_ALT2, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
3330
};
3431

3532

36-
int pinsToSpi(const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso,
37-
const mcu_pin_obj_t *sck) {
33+
int pinsToSpi(const mcu_pin_obj_t *sck, const mcu_pin_obj_t *mosi,
34+
const mcu_pin_obj_t *miso) {
3835
for (int i = 0; i < NUM_SPI; i++) {
3936
if ((spi_maps[i].port == (MXC_GPIO_GET_GPIO(mosi->port)))
40-
&& (spi_maps[i].mask == ((mosi->mask) | (miso->mask) | (sck->mask)))) {
37+
&& (spi_maps[i].mask & ((mosi->mask) | (miso->mask) | (sck->mask)))) {
4138
return i;
4239
}
4340
}

ports/analog/peripherals/max32690/max32_spi.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ const mxc_gpio_cfg_t spi_maps[NUM_SPI] = {
3131
MXC_GPIO_FUNC_ALT1, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
3232
};
3333

34-
int pinsToSpi(const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso,
35-
const mcu_pin_obj_t *sck) {
34+
int pinsToSpi(const mcu_pin_obj_t *sck, const mcu_pin_obj_t *mosi,
35+
const mcu_pin_obj_t *miso) {
3636
for (int i = 0; i < NUM_SPI; i++) {
3737
if ((spi_maps[i].port == (MXC_GPIO_GET_GPIO(mosi->port)))
38-
&& (spi_maps[i].mask == ((mosi->mask) | (miso->mask) | (sck->mask)))) {
38+
&& (spi_maps[i].mask & ((mosi->mask) | (miso->mask) | (sck->mask)))) {
3939
return i;
4040
}
4141
}

0 commit comments

Comments
 (0)