From fe555a4098b422525d9f2edc1191ccfdb9b9718d Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 21 Mar 2019 11:22:58 -0400 Subject: [PATCH] Allow NFC pins to be used for other purposes. --- .../makerdiary_nrf52840_mdk_usb_dongle/mpconfigboard.h | 4 ---- ports/nrf/common-hal/microcontroller/Pin.c | 10 ++++++++++ ports/nrf/mpconfigport.mk | 5 +++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ports/nrf/boards/makerdiary_nrf52840_mdk_usb_dongle/mpconfigboard.h b/ports/nrf/boards/makerdiary_nrf52840_mdk_usb_dongle/mpconfigboard.h index e8830bb8d7..d4096503d7 100644 --- a/ports/nrf/boards/makerdiary_nrf52840_mdk_usb_dongle/mpconfigboard.h +++ b/ports/nrf/boards/makerdiary_nrf52840_mdk_usb_dongle/mpconfigboard.h @@ -40,7 +40,3 @@ #define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE) #define BOARD_HAS_CRYSTAL 1 // according to the schematic we do - -// See https://github.com/adafruit/circuitpython/issues/1300, circuitpython -// doesn't yet support NFC so just force those pins to be GPIO. -#define CONFIG_NFCT_PINS_AS_GPIOS diff --git a/ports/nrf/common-hal/microcontroller/Pin.c b/ports/nrf/common-hal/microcontroller/Pin.c index 112654c7e0..b9c0ecacab 100644 --- a/ports/nrf/common-hal/microcontroller/Pin.c +++ b/ports/nrf/common-hal/microcontroller/Pin.c @@ -168,5 +168,15 @@ bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) { } #endif + #ifdef NRF52840 + // If NFC pins are enabled for NFC, don't allow them to be used for GPIO. + if (((NRF_UICR->NFCPINS & UICR_NFCPINS_PROTECT_Msk) == + (UICR_NFCPINS_PROTECT_NFC << UICR_NFCPINS_PROTECT_Pos)) && + (pin->number == 9 || pin->number == 10)) { + return false; + } + #endif + return pin_number_is_free(pin->number); + } diff --git a/ports/nrf/mpconfigport.mk b/ports/nrf/mpconfigport.mk index 55c1734b93..badfb6735d 100644 --- a/ports/nrf/mpconfigport.mk +++ b/ports/nrf/mpconfigport.mk @@ -27,3 +27,8 @@ CIRCUITPY_RTC = 0 # frequencyio not yet implemented CIRCUITPY_FREQUENCYIO = 0 + +# CircuitPython doesn't yet support NFC so force the NFC antenna pins to be GPIO. +# See https://github.com/adafruit/circuitpython/issues/1300 +# Defined here because system_nrf52840.c doesn't #include any of our own include files. +CFLAGS += -DCONFIG_NFCT_PINS_AS_GPIOS