Skip to content

Commit 15fd991

Browse files
committed
ports: analog: Add peripherals for MAX32650 & MAX32666
Signed-off-by: Brandon <[email protected]>
1 parent c7ca35a commit 15fd991

File tree

20 files changed

+739
-0
lines changed

20 files changed

+739
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2025 Brandon Hurst, Analog Devices, Inc.
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#include "gpios.h"
8+
9+
volatile mxc_gpio_regs_t *gpio_ports[NUM_GPIO_PORTS] =
10+
{MXC_GPIO0, MXC_GPIO1, MXC_GPIO2, MXC_GPIO3};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2025 Brandon Hurst, Analog Devices, Inc.
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#pragma once
8+
9+
#include "py/obj.h"
10+
#include "py/mphal.h"
11+
12+
// MSDK HAL includes
13+
#include "gpio.h"
14+
#include "gpio_regs.h"
15+
#include "max32650.h"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc.
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#include "peripherals/pins.h"
8+
9+
#include "common-hal/busio/I2C.h"
10+
#include "max32_i2c.h"
11+
#include "max32650.h"
12+
13+
#include "py/runtime.h"
14+
#include "py/mperrno.h"
15+
16+
const mxc_gpio_cfg_t i2c_maps[NUM_I2C] = {
17+
// I2C0
18+
{ MXC_GPIO2, (MXC_GPIO_PIN_7 | MXC_GPIO_PIN_8), MXC_GPIO_FUNC_ALT1,
19+
MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
20+
// I2C1
21+
{ MXC_GPIO2, (MXC_GPIO_PIN_17 | MXC_GPIO_PIN_18), MXC_GPIO_FUNC_ALT1,
22+
MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
23+
};
24+
25+
int pinsToI2c(const mcu_pin_obj_t *sda, const mcu_pin_obj_t *scl) {
26+
for (int i = 0; i < NUM_I2C; i++) {
27+
if ((i2c_maps[i].port == (MXC_GPIO_GET_GPIO(sda->port)))
28+
&& (i2c_maps[i].mask == ((sda->mask) | (scl->mask)))) {
29+
return i;
30+
}
31+
}
32+
33+
mp_raise_ValueError_varg(MP_ERROR_TEXT("Invalid %q"), MP_QSTR_pins);
34+
return -1;
35+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc.
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#pragma once
8+
9+
#include "i2c_regs.h"
10+
#include "mxc_sys.h"
11+
#include "i2c.h"
12+
#include "peripherals/pins.h"
13+
14+
#define NUM_I2C 2
15+
16+
int pinsToI2c(const mcu_pin_obj_t *sda, const mcu_pin_obj_t *scl);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc.
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#include "peripherals/pins.h"
8+
9+
#include "common-hal/busio/SPI.h"
10+
#include "max32_spi.h"
11+
#include "max32650.h"
12+
13+
#include "py/runtime.h"
14+
#include "py/mperrno.h"
15+
16+
const mxc_gpio_cfg_t spi_maps[NUM_SPI] = {
17+
// SPI0
18+
{ MXC_GPIO2, (MXC_GPIO_PIN_27 | MXC_GPIO_PIN_28 | MXC_GPIO_PIN_29),
19+
MXC_GPIO_FUNC_ALT2, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
20+
// SPI1
21+
{ MXC_GPIO1, (MXC_GPIO_PIN_26 | MXC_GPIO_PIN_28 | MXC_GPIO_PIN_29),
22+
MXC_GPIO_FUNC_ALT1, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
23+
// SPI2
24+
{ MXC_GPIO2, (MXC_GPIO_PIN_2 | MXC_GPIO_PIN_3 | MXC_GPIO_PIN_4),
25+
MXC_GPIO_FUNC_ALT1, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
26+
// SPI3
27+
{ MXC_GPIO0, (MXC_GPIO_PIN_16 | MXC_GPIO_PIN_20 | MXC_GPIO_PIN_21),
28+
MXC_GPIO_FUNC_ALT1, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
29+
// SPI4
30+
{ MXC_GPIO1, (MXC_GPIO_PIN_1 | MXC_GPIO_PIN_2 | MXC_GPIO_PIN_3),
31+
MXC_GPIO_FUNC_ALT1, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
32+
};
33+
34+
int pinsToSpi(const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso,
35+
const mcu_pin_obj_t *sck) {
36+
for (int i = 0; i < NUM_SPI; i++) {
37+
if ((spi_maps[i].port == (MXC_GPIO_GET_GPIO(mosi->port)))
38+
&& (spi_maps[i].mask == ((mosi->mask) | (miso->mask) | (sck->mask)))) {
39+
return i;
40+
}
41+
}
42+
mp_raise_ValueError_varg(MP_ERROR_TEXT("Invalid %q"), MP_QSTR_pins);
43+
return -1;
44+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc.
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#pragma once
8+
9+
#include "spi_regs.h"
10+
#include "mxc_sys.h"
11+
#include "spi.h"
12+
#include "peripherals/pins.h"
13+
14+
// 3 APB SPI + 1 AHB QSPI
15+
#define NUM_SPI 4
16+
17+
int pinsToSpi(const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso,
18+
const mcu_pin_obj_t *sck);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc.
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#include "peripherals/pins.h"
8+
9+
#include "common-hal/busio/UART.h"
10+
#include "max32_uart.h"
11+
#include "max32650.h"
12+
13+
#include "py/runtime.h"
14+
#include "py/mperrno.h"
15+
16+
const mxc_gpio_cfg_t uart_maps[NUM_UARTS] = {
17+
{ MXC_GPIO2, (MXC_GPIO_PIN_11 | MXC_GPIO_PIN_12), MXC_GPIO_FUNC_ALT1,
18+
MXC_GPIO_PAD_WEAK_PULL_UP, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
19+
{ MXC_GPIO2, (MXC_GPIO_PIN_14 | MXC_GPIO_PIN_16), MXC_GPIO_FUNC_ALT1,
20+
MXC_GPIO_PAD_WEAK_PULL_UP, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
21+
{ MXC_GPIO1, (MXC_GPIO_PIN_9 | MXC_GPIO_PIN_10), MXC_GPIO_FUNC_ALT1,
22+
MXC_GPIO_PAD_WEAK_PULL_UP, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
23+
};
24+
25+
int pinsToUart(const mcu_pin_obj_t *rx, const mcu_pin_obj_t *tx) {
26+
for (int i = 0; i < NUM_UARTS; i++) {
27+
if ((uart_maps[i].port == (MXC_GPIO_GET_GPIO(tx->port)))
28+
&& (uart_maps[i].mask == ((tx->mask) | (rx->mask)))) {
29+
return i;
30+
}
31+
}
32+
mp_raise_ValueError_varg(MP_ERROR_TEXT("Invalid %q"), MP_QSTR_pins);
33+
return -1;
34+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc.
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#pragma once
8+
9+
#include "uart_regs.h"
10+
#include "mxc_sys.h"
11+
#include "uart.h"
12+
#include "peripherals/pins.h"
13+
14+
#define NUM_UARTS 3
15+
16+
int pinsToUart(const mcu_pin_obj_t *rx, const mcu_pin_obj_t *tx);
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc.
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#include "py/obj.h"
8+
#include "py/mphal.h"
9+
#include "peripherals/pins.h"
10+
#include "max32650.h"
11+
12+
const mcu_pin_obj_t pin_P0_00 = PIN(0, 0);
13+
const mcu_pin_obj_t pin_P0_01 = PIN(0, 1);
14+
const mcu_pin_obj_t pin_P0_02 = PIN(0, 2);
15+
const mcu_pin_obj_t pin_P0_03 = PIN(0, 3);
16+
const mcu_pin_obj_t pin_P0_04 = PIN(0, 4);
17+
const mcu_pin_obj_t pin_P0_05 = PIN(0, 5);
18+
const mcu_pin_obj_t pin_P0_06 = PIN(0, 6);
19+
const mcu_pin_obj_t pin_P0_07 = PIN(0, 7);
20+
const mcu_pin_obj_t pin_P0_08 = PIN(0, 8);
21+
const mcu_pin_obj_t pin_P0_09 = PIN(0, 9);
22+
const mcu_pin_obj_t pin_P0_10 = PIN(0, 10);
23+
const mcu_pin_obj_t pin_P0_11 = PIN(0, 11);
24+
const mcu_pin_obj_t pin_P0_12 = PIN(0, 12);
25+
const mcu_pin_obj_t pin_P0_13 = PIN(0, 13);
26+
const mcu_pin_obj_t pin_P0_14 = PIN(0, 14);
27+
const mcu_pin_obj_t pin_P0_15 = PIN(0, 15);
28+
const mcu_pin_obj_t pin_P0_16 = PIN(0, 16);
29+
const mcu_pin_obj_t pin_P0_17 = PIN(0, 17);
30+
const mcu_pin_obj_t pin_P0_18 = PIN(0, 18);
31+
const mcu_pin_obj_t pin_P0_19 = PIN(0, 19);
32+
const mcu_pin_obj_t pin_P0_20 = PIN(0, 20);
33+
const mcu_pin_obj_t pin_P0_21 = PIN(0, 21);
34+
const mcu_pin_obj_t pin_P0_22 = PIN(0, 22);
35+
const mcu_pin_obj_t pin_P0_23 = PIN(0, 23);
36+
const mcu_pin_obj_t pin_P0_24 = PIN(0, 24);
37+
const mcu_pin_obj_t pin_P0_25 = PIN(0, 25);
38+
const mcu_pin_obj_t pin_P0_26 = PIN(0, 26);
39+
const mcu_pin_obj_t pin_P0_27 = PIN(0, 27);
40+
const mcu_pin_obj_t pin_P0_28 = PIN(0, 28);
41+
const mcu_pin_obj_t pin_P0_29 = PIN(0, 29);
42+
const mcu_pin_obj_t pin_P0_30 = PIN(0, 30);
43+
const mcu_pin_obj_t pin_P0_31 = PIN(0, 31);
44+
45+
const mcu_pin_obj_t pin_P1_00 = PIN(1, 0);
46+
const mcu_pin_obj_t pin_P1_01 = PIN(1, 1);
47+
const mcu_pin_obj_t pin_P1_02 = PIN(1, 2);
48+
const mcu_pin_obj_t pin_P1_03 = PIN(1, 3);
49+
const mcu_pin_obj_t pin_P1_04 = PIN(1, 4);
50+
const mcu_pin_obj_t pin_P1_05 = PIN(1, 5);
51+
const mcu_pin_obj_t pin_P1_06 = PIN(1, 6);
52+
const mcu_pin_obj_t pin_P1_07 = PIN(1, 7);
53+
const mcu_pin_obj_t pin_P1_08 = PIN(1, 8);
54+
const mcu_pin_obj_t pin_P1_09 = PIN(1, 9);
55+
const mcu_pin_obj_t pin_P1_10 = PIN(1, 10);
56+
const mcu_pin_obj_t pin_P1_11 = PIN(1, 11);
57+
const mcu_pin_obj_t pin_P1_12 = PIN(1, 12);
58+
const mcu_pin_obj_t pin_P1_13 = PIN(1, 13);
59+
const mcu_pin_obj_t pin_P1_14 = PIN(1, 14);
60+
const mcu_pin_obj_t pin_P1_15 = PIN(1, 15);
61+
const mcu_pin_obj_t pin_P1_16 = PIN(1, 16);
62+
const mcu_pin_obj_t pin_P1_17 = PIN(1, 17);
63+
const mcu_pin_obj_t pin_P1_18 = PIN(1, 18);
64+
const mcu_pin_obj_t pin_P1_19 = PIN(1, 19);
65+
const mcu_pin_obj_t pin_P1_20 = PIN(1, 20);
66+
const mcu_pin_obj_t pin_P1_21 = PIN(1, 21);
67+
const mcu_pin_obj_t pin_P1_22 = PIN(1, 22);
68+
const mcu_pin_obj_t pin_P1_23 = PIN(1, 23);
69+
const mcu_pin_obj_t pin_P1_24 = PIN(1, 24);
70+
const mcu_pin_obj_t pin_P1_25 = PIN(1, 25);
71+
const mcu_pin_obj_t pin_P1_26 = PIN(1, 26);
72+
const mcu_pin_obj_t pin_P1_27 = PIN(1, 27);
73+
const mcu_pin_obj_t pin_P1_28 = PIN(1, 28);
74+
const mcu_pin_obj_t pin_P1_29 = PIN(1, 29);
75+
const mcu_pin_obj_t pin_P1_30 = PIN(1, 30);
76+
const mcu_pin_obj_t pin_P1_31 = PIN(1, 31);
77+
78+
const mcu_pin_obj_t pin_P2_00 = PIN(2, 0);
79+
const mcu_pin_obj_t pin_P2_01 = PIN(2, 1);
80+
const mcu_pin_obj_t pin_P2_02 = PIN(2, 2);
81+
const mcu_pin_obj_t pin_P2_03 = PIN(2, 3);
82+
const mcu_pin_obj_t pin_P2_04 = PIN(2, 4);
83+
const mcu_pin_obj_t pin_P2_05 = PIN(2, 5);
84+
const mcu_pin_obj_t pin_P2_06 = PIN(2, 6);
85+
const mcu_pin_obj_t pin_P2_07 = PIN(2, 7);
86+
const mcu_pin_obj_t pin_P2_08 = PIN(2, 8);
87+
const mcu_pin_obj_t pin_P2_09 = PIN(2, 9);
88+
const mcu_pin_obj_t pin_P2_10 = PIN(2, 10);
89+
const mcu_pin_obj_t pin_P2_11 = PIN(2, 11);
90+
const mcu_pin_obj_t pin_P2_12 = PIN(2, 12);
91+
const mcu_pin_obj_t pin_P2_13 = PIN(2, 13);
92+
const mcu_pin_obj_t pin_P2_14 = PIN(2, 14);
93+
const mcu_pin_obj_t pin_P2_15 = PIN(2, 15);
94+
const mcu_pin_obj_t pin_P2_16 = PIN(2, 16);
95+
const mcu_pin_obj_t pin_P2_17 = PIN(2, 17);
96+
const mcu_pin_obj_t pin_P2_18 = PIN(2, 18);
97+
const mcu_pin_obj_t pin_P2_19 = PIN(2, 19);
98+
const mcu_pin_obj_t pin_P2_20 = PIN(2, 20);
99+
const mcu_pin_obj_t pin_P2_21 = PIN(2, 21);
100+
const mcu_pin_obj_t pin_P2_22 = PIN(2, 22);
101+
const mcu_pin_obj_t pin_P2_23 = PIN(2, 23);
102+
const mcu_pin_obj_t pin_P2_24 = PIN(2, 24);
103+
const mcu_pin_obj_t pin_P2_25 = PIN(2, 25);
104+
const mcu_pin_obj_t pin_P2_26 = PIN(2, 26);
105+
const mcu_pin_obj_t pin_P2_27 = PIN(2, 27);
106+
const mcu_pin_obj_t pin_P2_28 = PIN(2, 28);
107+
const mcu_pin_obj_t pin_P2_29 = PIN(2, 29);
108+
const mcu_pin_obj_t pin_P2_30 = PIN(2, 30);
109+
const mcu_pin_obj_t pin_P2_31 = PIN(2, 31);
110+
111+
const mcu_pin_obj_t pin_P3_00 = PIN(3, 0);
112+
const mcu_pin_obj_t pin_P3_01 = PIN(3, 1);
113+
const mcu_pin_obj_t pin_P3_02 = PIN(3, 2);
114+
const mcu_pin_obj_t pin_P3_03 = PIN(3, 3);
115+
const mcu_pin_obj_t pin_P3_04 = PIN(3, 4);
116+
const mcu_pin_obj_t pin_P3_05 = PIN(3, 5);
117+
const mcu_pin_obj_t pin_P3_06 = PIN(3, 6);
118+
const mcu_pin_obj_t pin_P3_07 = PIN(3, 7);
119+
const mcu_pin_obj_t pin_P3_08 = PIN(3, 8);
120+
const mcu_pin_obj_t pin_P3_09 = PIN(3, 9);

0 commit comments

Comments
 (0)