Skip to content

Commit 585597a

Browse files
committed
pin files rework; implement pin claiming; add more boards
1 parent 0e8d146 commit 585597a

File tree

43 files changed

+1274
-313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1274
-313
lines changed

ports/atmel-samd/boards/gemma_m0/pins.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
2121

2222
{ MP_ROM_QSTR(MP_QSTR_APA102_MOSI), MP_ROM_PTR(&pin_PA00) },
2323
{ MP_ROM_QSTR(MP_QSTR_APA102_SCK), MP_ROM_PTR(&pin_PA01) },
24+
2425
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
2526
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
2627
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },

ports/nrf/Makefile

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ ifneq ($(SD), )
2424
include drivers/bluetooth/bluetooth_common.mk
2525
endif
2626

27-
# qstr definitions (must come before including py.mk)
28-
QSTR_DEFS = qstrdefsport.h $(BUILD)/pins_qstr.h
29-
3027
FROZEN_MPY_DIR = freeze
3128

3229
# include py core make definitions
@@ -53,6 +50,7 @@ INC += -I./nrfx/drivers/include
5350
INC += -I../../lib/mp-readline
5451
INC += -I./drivers/bluetooth
5552
INC += -I./drivers
53+
INC += -I./peripherals
5654
INC += -I../../lib/tinyusb/src
5755
INC += -I./usb
5856

@@ -105,6 +103,7 @@ SRC_C += \
105103
drivers/bluetooth/ble_drv.c \
106104
drivers/bluetooth/ble_uart.c \
107105
boards/$(BOARD)/board.c \
106+
boards/$(BOARD)/pins.c \
108107
nrfx/mdk/system_$(MCU_SUB_VARIANT).c \
109108
nrfx/hal/nrf_nvmc.c \
110109
device/$(MCU_VARIANT)/startup_$(MCU_SUB_VARIANT).c \
@@ -119,6 +118,7 @@ SRC_C += \
119118
lib/utils/sys_stdio_mphal.c \
120119
lib/libc/string0.c \
121120
lib/mp-readline/readline.c \
121+
peripherals/nrf/$(MCU_CHIP)/pins.c \
122122
supervisor/shared/memory.c
123123

124124
DRIVERS_SRC_C += $(addprefix modules/,\
@@ -150,6 +150,7 @@ SRC_COMMON_HAL += \
150150
busio/I2C.c \
151151
busio/SPI.c \
152152
busio/UART.c \
153+
neopixel_write/__init__.c \
153154
pulseio/__init__.c \
154155
pulseio/PulseIn.c \
155156
pulseio/PulseOut.c \
@@ -238,7 +239,6 @@ FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR) -type f -name '*.py')
238239
FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/,$(FROZEN_MPY_PY_FILES:.py=.mpy))
239240

240241
OBJ += $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
241-
OBJ += $(BUILD)/pins_gen.o
242242
OBJ += $(addprefix $(BUILD)/, $(SRC_NRFX:.c=.o))
243243
OBJ += $(addprefix $(BUILD)/, $(DRIVERS_SRC_C:.c=.o))
244244
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_EXPANDED:.c=.o))
@@ -333,7 +333,7 @@ dfu-flash: $(BUILD)/dfu-package.zip
333333
$(NRFUTIL) --verbose dfu serial --package $^ -p $(SERIAL) -b 115200 --singlebank $(DFU_TOUCH)
334334

335335
## Create DFU package file
336-
dfu-gen: $(BUILD)/dfu-package.zip
336+
dfu-gen: $(BUILD)/dfu-package.zip
337337

338338
$(BUILD)/dfu-package.zip: $(BUILD)/$(OUTPUT_FILENAME).hex
339339
$(NRFUTIL) dfu genpkg --sd-req 0xFFFE --dev-type 0x0052 --application $^ $(BUILD)/dfu-package.zip
@@ -350,29 +350,8 @@ SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_MOD) $(DRIVERS_SRC_C) $(SRC_COMMON_
350350
# SRC_QSTR
351351
SRC_QSTR_AUTO_DEPS +=
352352

353-
# Making OBJ use an order-only depenedency on the generated pins.h file
354-
# has the side effect of making the pins.h file before we actually compile
355-
# any of the objects. The normal dependency generation will deal with the
356-
# case when pins.h is modified. But when it doesn't exist, we don't know
357-
# which source files might need it.
358-
$(OBJ): | $(HEADER_BUILD)/pins.h
359-
360-
# Use a pattern rule here so that make will only call make-pins.py once to make
361-
# both pins_g.c and pins.h
362-
$(BUILD)/%_gen.c $(HEADER_BUILD)/%.h $(BUILD)/%_qstr.h: boards/$(BOARD)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD)
363-
$(ECHO) "Create $@"
364-
$(Q)$(PYTHON) $(MAKE_PINS) --board $(BOARD_PINS) --af $(AF_FILE) --prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) --qstr $(GEN_PINS_QSTR) > $(GEN_PINS_SRC)
365-
366-
$(BUILD)/pins_gen.o: $(BUILD)/pins_gen.c
367-
$(call compile_c)
368-
369-
MAKE_PINS = boards/make-pins.py
370-
BOARD_PINS = boards/$(BOARD)/pins.csv
371353
AF_FILE = $(MCU_VARIANT)_af.csv
372354
PREFIX_FILE = boards/$(MCU_VARIANT)_prefix.c
373-
GEN_PINS_SRC = $(BUILD)/pins_gen.c
374-
GEN_PINS_HDR = $(HEADER_BUILD)/pins.h
375-
GEN_PINS_QSTR = $(BUILD)/pins_qstr.h
376355

377356
ifneq ($(FROZEN_DIR),)
378357
# To use frozen source modules, put your .py files in a subdirectory (eg scripts/)

ports/nrf/board_busses.c

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "shared-bindings/busio/I2C.h"
28+
#include "shared-bindings/busio/SPI.h"
29+
#include "shared-bindings/busio/UART.h"
30+
31+
#include "shared-bindings/microcontroller/Pin.h"
32+
#include "supervisor/shared/translate.h"
33+
#include "mpconfigboard.h"
34+
#include "nrf/pins.h"
35+
#include "py/runtime.h"
36+
37+
#if !defined(DEFAULT_I2C_BUS_SDA) || !defined(DEFAULT_I2C_BUS_SCL)
38+
STATIC mp_obj_t board_i2c(void) {
39+
mp_raise_NotImplementedError(translate("No default I2C bus"));
40+
return NULL;
41+
}
42+
#else
43+
STATIC mp_obj_t i2c_singleton = NULL;
44+
45+
STATIC mp_obj_t board_i2c(void) {
46+
47+
if (i2c_singleton == NULL) {
48+
busio_i2c_obj_t *self = m_new_obj(busio_i2c_obj_t);
49+
self->base.type = &busio_i2c_type;
50+
51+
assert_pin_free(DEFAULT_I2C_BUS_SDA);
52+
assert_pin_free(DEFAULT_I2C_BUS_SCL);
53+
common_hal_busio_i2c_construct(self, DEFAULT_I2C_BUS_SCL, DEFAULT_I2C_BUS_SDA, 400000, 0);
54+
i2c_singleton = (mp_obj_t)self;
55+
}
56+
return i2c_singleton;
57+
58+
}
59+
#endif
60+
MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c);
61+
62+
#if !defined(DEFAULT_SPI_BUS_SCK) || !defined(DEFAULT_SPI_BUS_MISO) || !defined(DEFAULT_SPI_BUS_MOSI)
63+
STATIC mp_obj_t board_spi(void) {
64+
mp_raise_NotImplementedError(translate("No default SPI bus"));
65+
return NULL;
66+
}
67+
#else
68+
STATIC mp_obj_t spi_singleton = NULL;
69+
70+
STATIC mp_obj_t board_spi(void) {
71+
72+
if (spi_singleton == NULL) {
73+
busio_spi_obj_t *self = m_new_obj(busio_spi_obj_t);
74+
self->base.type = &busio_spi_type;
75+
assert_pin_free(DEFAULT_SPI_BUS_SCK);
76+
assert_pin_free(DEFAULT_SPI_BUS_MOSI);
77+
assert_pin_free(DEFAULT_SPI_BUS_MISO);
78+
const mcu_pin_obj_t* clock = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_SCK);
79+
const mcu_pin_obj_t* mosi = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MOSI);
80+
const mcu_pin_obj_t* miso = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MISO);
81+
common_hal_busio_spi_construct(self, clock, mosi, miso);
82+
spi_singleton = (mp_obj_t)self;
83+
}
84+
return spi_singleton;
85+
}
86+
#endif
87+
MP_DEFINE_CONST_FUN_OBJ_0(board_spi_obj, board_spi);
88+
89+
#if !defined(DEFAULT_UART_BUS_RX) || !defined(DEFAULT_UART_BUS_TX)
90+
STATIC mp_obj_t board_uart(void) {
91+
mp_raise_NotImplementedError(translate("No default UART bus"));
92+
return NULL;
93+
}
94+
#else
95+
STATIC mp_obj_t uart_singleton = NULL;
96+
97+
STATIC mp_obj_t board_uart(void) {
98+
if (uart_singleton == NULL) {
99+
busio_uart_obj_t *self = m_new_obj(busio_uart_obj_t);
100+
self->base.type = &busio_uart_type;
101+
102+
assert_pin_free(DEFAULT_UART_BUS_RX);
103+
assert_pin_free(DEFAULT_UART_BUS_TX);
104+
105+
const mcu_pin_obj_t* rx = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_RX);
106+
const mcu_pin_obj_t* tx = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_TX);
107+
108+
common_hal_busio_uart_construct(self, tx, rx, 9600, 8, PARITY_NONE, 1, 1000, 64);
109+
uart_singleton = (mp_obj_t)self;
110+
}
111+
return uart_singleton;
112+
}
113+
#endif
114+
MP_DEFINE_CONST_FUN_OBJ_0(board_uart_obj, board_uart);

ports/nrf/board_busses.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef MICROPY_INCLUDED_NRF_BOARD_BUSSES_H
28+
#define MICROPY_INCLUDED_NRF_BOARD_BUSSES_H
29+
30+
void board_i2c(void);
31+
extern mp_obj_fun_builtin_fixed_t board_i2c_obj;
32+
33+
void board_spi(void);
34+
extern mp_obj_fun_builtin_fixed_t board_spi_obj;
35+
36+
void board_uart(void);
37+
extern mp_obj_fun_builtin_fixed_t board_uart_obj;
38+
39+
#endif // MICROPY_INCLUDED_NRF_BOARD_BUSSES_H

ports/nrf/boards/feather_nrf52832/mpconfigboard.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,13 @@
3434

3535
#define PORT_HEAP_SIZE (32 * 1024)
3636
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
37+
38+
#define DEFAULT_I2C_BUS_SCL (&pin_P0_26)
39+
#define DEFAULT_I2C_BUS_SDA (&pin_P0_25)
40+
41+
#define DEFAULT_SPI_BUS_SCK (&pin_P0_12)
42+
#define DEFAULT_SPI_BUS_MOSI (&pin_P0_13)
43+
#define DEFAULT_SPI_BUS_MISO (&pin_P0_14)
44+
45+
#define DEFAULT_UART_BUS_RX (&pin_P0_08)
46+
#define DEFAULT_UART_BUS_TX (&pin_P0_06)
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
MCU_SERIES = m4
22
MCU_VARIANT = nrf52
3+
# Historical: nrf52 means nrf52832
34
MCU_SUB_VARIANT = nrf52
5+
MCU_CHIP = nrf52832
46
SD ?= s132
57
SOFTDEV_VERSION ?= 2.0.1
68

79
LD_FILE = boards/feather_nrf52832/custom_nrf52832_dfu_app_$(SOFTDEV_VERSION).ld
810
BOOT_FILE = boards/feather_nrf52832/bootloader/feather52_bootloader_$(SOFTDEV_VERSION)_s132_single
911

1012
BOOT_SETTING_ADDR = 0x7F000
11-
NRF_DEFINES += -DNRF52832_XXAA
13+
NRF_DEFINES += -DNRF52832_XXAA -DNRF52832
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "shared-bindings/board/__init__.h"
2+
3+
#include "board_busses.h"
4+
5+
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
6+
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_P0_02) },
7+
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_P0_03) },
8+
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_P0_04) },
9+
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_P0_05) },
10+
{ MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_P0_28) },
11+
{ MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_P0_29) },
12+
13+
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_P0_12) },
14+
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_P0_13) },
15+
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_P0_14) },
16+
17+
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_P0_08) },
18+
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_P0_06) },
19+
20+
{ MP_ROM_QSTR(MP_QSTR_DFU), MP_ROM_PTR(&pin_P0_20) },
21+
22+
{ MP_ROM_QSTR(MP_QSTR_NFC1), MP_ROM_PTR(&pin_P0_09) },
23+
{ MP_ROM_QSTR(MP_QSTR_NFC2), MP_ROM_PTR(&pin_P0_10) },
24+
25+
{ MP_ROM_QSTR(MP_QSTR_27), MP_ROM_PTR(&pin_P0_27) },
26+
27+
{ MP_ROM_QSTR(MP_QSTR_D30), MP_ROM_PTR(&pin_P0_30) },
28+
{ MP_ROM_QSTR(MP_QSTR_A6), MP_ROM_PTR(&pin_P0_30) },
29+
30+
{ MP_ROM_QSTR(MP_QSTR_D31), MP_ROM_PTR(&pin_P0_31) },
31+
{ MP_ROM_QSTR(MP_QSTR_A7), MP_ROM_PTR(&pin_P0_31) },
32+
33+
{ MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_P0_07) },
34+
{ MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_P0_11) },
35+
{ MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_P0_15) },
36+
{ MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_P0_16) },
37+
38+
{ MP_ROM_QSTR(MP_QSTR_L), MP_ROM_PTR(&pin_P0_17) },
39+
40+
{ MP_ROM_QSTR(MP_QSTR_LED_BLUE), MP_ROM_PTR(&pin_P0_19) },
41+
42+
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_P0_26) },
43+
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_P0_25) },
44+
};
45+
46+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

ports/nrf/boards/feather_nrf52832/pins.csv

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)