summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoy Hooper <rhooper@toybox.ca>2019-12-20 19:22:27 -0500
committerRoy Hooper <rhooper@toybox.ca>2019-12-20 19:22:27 -0500
commit09d4fe03249eee6561dfec232c85344eba4d07a4 (patch)
treeec73240b8c8ecfb38b0273339bfb599a838e847e
parentb90c39456be8d3633d8ef8362f21a2455758bf5e (diff)
parente6fd513cfa5460e2dfec138346749ede46afd243 (diff)
Merge branch 'master' into new-pixelbuf-api
-rw-r--r--.github/workflows/build.yml2
-rw-r--r--BUILDING.md82
-rw-r--r--docs/index.rst1
m---------frozen/Adafruit_CircuitPython_BusDevice0
m---------frozen/Adafruit_CircuitPython_CircuitPlayground0
m---------frozen/Adafruit_CircuitPython_Crickit0
m---------frozen/Adafruit_CircuitPython_HID0
m---------frozen/Adafruit_CircuitPython_Motor0
m---------frozen/Adafruit_CircuitPython_NeoPixel0
m---------frozen/Adafruit_CircuitPython_SD0
m---------lib/mp30
m---------lib/tinyusb0
-rw-r--r--ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.mk3
-rw-r--r--ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.h2
-rwxr-xr-xports/nrf/Makefile2
-rw-r--r--ports/nrf/common-hal/analogio/AnalogIn.c51
-rw-r--r--ports/nrf/common-hal/audiopwmio/PWMAudioOut.c4
-rw-r--r--ports/nrf/common-hal/busio/I2C.c12
-rw-r--r--ports/nrf/common-hal/busio/SPI.c3
-rw-r--r--ports/nrf/common-hal/busio/UART.c8
-rw-r--r--ports/nrf/common-hal/microcontroller/Processor.c39
-rw-r--r--ports/nrf/common-hal/os/__init__.c12
-rw-r--r--ports/nrf/common-hal/pulseio/PulseIn.c2
-rw-r--r--ports/nrf/common-hal/rtc/RTC.c4
m---------ports/nrf/nrfx0
-rw-r--r--ports/nrf/nrfx_config.h5
-rw-r--r--ports/nrf/peripherals/nrf/nrf52840/power.c4
-rw-r--r--ports/nrf/peripherals/nrf/nvm.c6
-rw-r--r--py/circuitpy_mpconfig.h2
-rw-r--r--shared-bindings/displayio/Display.c9
-rw-r--r--shared-bindings/displayio/Display.h1
-rw-r--r--shared-bindings/random/__init__.c4
-rw-r--r--shared-module/displayio/Display.c17
-rw-r--r--shared-module/displayio/display_core.c9
-rw-r--r--shared-module/displayio/display_core.h2
-rw-r--r--supervisor/shared/display.c1
-rw-r--r--supervisor/shared/usb/usb.c2
-rw-r--r--supervisor/shared/usb/usb_msc_flash.c41
-rw-r--r--supervisor/usb.h4
-rw-r--r--tools/gen_display_resources.py9
40 files changed, 252 insertions, 91 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 01335ccfc..e87190c72 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -174,7 +174,7 @@ jobs:
run: |
sudo apt-get install -y gettext
pip install requests sh click setuptools awscli
- wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/RC2.1/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2
+ wget https://adafruit-circuit-python.s3.amazonaws.com/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2
sudo tar -C /usr --strip-components=1 -xaf gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2
- name: Versions
run: |
diff --git a/BUILDING.md b/BUILDING.md
new file mode 100644
index 000000000..73499d65d
--- /dev/null
+++ b/BUILDING.md
@@ -0,0 +1,82 @@
+
+# Building CircuitPython
+
+Welcome to CircuitPython!
+
+This document is a quick-start guide only.
+
+Detailed guides on how to build CircuitPython can be found in the Adafruit Learn system at
+https://learn.adafruit.com/building-circuitpython/
+
+## Setup
+
+Please ensure you setup your build environment appropriately, as per the guide. You will need:
+
+* Linux: https://learn.adafruit.com/building-circuitpython/linux
+* MacOS: https://learn.adafruit.com/building-circuitpython/macos
+* Windows Subsystem for Linux (WSL): https://learn.adafruit.com/building-circuitpython/windows-subsystem-for-linux
+
+### Submodules
+
+This project has a bunch of git submodules. You will need to update them regularly.
+
+ git submodule sync
+ git submodule update --init
+
+### mpy-cross
+
+As part of the build process, mpy-cross is needed to compile .py files into .mpy files.
+To compile (or recompile) mpy-cross:
+
+ make -C mpy-cross
+
+# Building
+
+There a number of ports of CircuitPython! To build for your board, change to the appropriate ports directory and build.
+
+Examples:
+
+ cd ports/atmel-samd
+ make BOARD=circuitplayground_express
+
+ cd ports/nrf
+ make BOARD=circuitplayground_bluefruit
+
+If you aren't sure what boards exist, have a peek in the boards subdirectory of your port.
+If you have a fast computer with many cores, consider adding `-j` to your build flags, such as `-j17` on
+a 6-core 12-thread machine.
+
+# Testing
+
+If you are working on changes to the core language, you might find it useful to run the test suite.
+The test suite in the top level `tests` directory. It needs the unix port to run.
+
+ cd ports/unix
+ make axtls
+ make micropython
+
+Then you can run the test suite:
+
+ cd ../../tests
+ ./run-tests
+
+A successful run will say something like
+
+ 676 tests performed (19129 individual testcases)
+ 676 tests passed
+ 30 tests skipped: buffered_writer builtin_help builtin_range_binop class_delattr_setattr cmd_parsetree extra_coverage framebuf1 framebuf16 framebuf2 framebuf4 framebuf8 framebuf_subclass mpy_invalid namedtuple_asdict non_compliant resource_stream schedule sys_getsizeof urandom_extra ure_groups ure_span ure_sub ure_sub_unmatched vfs_basic vfs_fat_fileio1 vfs_fat_fileio2 vfs_fat_more vfs_fat_oldproto vfs_fat_ramdisk vfs_userfs
+
+# Debugging
+
+The easiest way to debug CircuitPython on hardware is with a JLink device, JLinkGDBServer, and an appropriate GDB.
+Instructions can be found at https://learn.adafruit.com/debugging-the-samd21-with-gdb
+
+If using JLink, you'll need both the `JLinkGDBServer` and `arm-none-eabi-gdb` running.
+
+Example:
+
+ JLinkGDBServer -if SWD -device ATSAMD51J19
+ arm-none-eabi-gdb build-metro_m4_express/firmware.elf -iex "target extended-remote :2331"
+
+If your port/build includes `arm-none-eabi-gdb-py`, consider using it instead, as it can be used for better register
+debugging with https://github.com/bnahill/PyCortexMDebug
diff --git a/docs/index.rst b/docs/index.rst
index a85772fdc..6dadddfc1 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -43,6 +43,7 @@ Full Table of Contents
../README
../CONTRIBUTING
+ ../BUILDING
../CODE_OF_CONDUCT
../license.rst
diff --git a/frozen/Adafruit_CircuitPython_BusDevice b/frozen/Adafruit_CircuitPython_BusDevice
-Subproject 52d87bd7e571af66ecb57ee32b5af9253113415
+Subproject 2000ae3a7c5d60b850c9546a16425aee279e2a3
diff --git a/frozen/Adafruit_CircuitPython_CircuitPlayground b/frozen/Adafruit_CircuitPython_CircuitPlayground
-Subproject d87ea261c40ecbc6d893d72d337beefbea1cf93
+Subproject 82ba9e40dfff41fdc0541636afde4936c930d86
diff --git a/frozen/Adafruit_CircuitPython_Crickit b/frozen/Adafruit_CircuitPython_Crickit
-Subproject a6100fb5d867c7f4980f071119bfa7e0a76e1d4
+Subproject 5534662902a223ac8562e6f999d6359e4c17dab
diff --git a/frozen/Adafruit_CircuitPython_HID b/frozen/Adafruit_CircuitPython_HID
-Subproject 89faee0eb08a6855e14f117c514fecf2dd90769
+Subproject a23b80569f23ef109667dd8c595d319e8a30d62
diff --git a/frozen/Adafruit_CircuitPython_Motor b/frozen/Adafruit_CircuitPython_Motor
-Subproject ddc74844983b35b027bd45091c7b8bb3c8d7a2d
+Subproject f69fc9b47fa25ba1414eb3d5c82f05013280c0d
diff --git a/frozen/Adafruit_CircuitPython_NeoPixel b/frozen/Adafruit_CircuitPython_NeoPixel
-Subproject b94f06d85c2678d608d904c23e9c0c4172c76b1
+Subproject ff99d55115f81899902c2c4a84fdfbea9ae8382
diff --git a/frozen/Adafruit_CircuitPython_SD b/frozen/Adafruit_CircuitPython_SD
-Subproject 5ad33e4ca219f0e216beab439cfa259cde32016
+Subproject dd0fe8530a2dcc64ac95bb3e116af2158dcd7cd
diff --git a/lib/mp3 b/lib/mp3
-Subproject 2a3cc7873b5c642d4bb60043dc14d2555e3377a
+Subproject c3c664bf4db6a36d11808dfcbb5dbf7cff1715b
diff --git a/lib/tinyusb b/lib/tinyusb
-Subproject e413c9efa303d70de019a91aa415384fe80ca78
+Subproject 7a05b177a43b368fea1d60ca344fe4ae9902a43
diff --git a/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.mk b/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.mk
index a6ed28aa7..04b4b7792 100644
--- a/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.mk
+++ b/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.mk
@@ -13,9 +13,10 @@ EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C"
# Turn off features and optimizations for Crickit build to make room for additional frozen libs.
LONGINT_IMPL = NONE
CIRCUITPY_DISPLAYIO = 0
-CIRCUITPY_PIXELBUF = 0
CIRCUITPY_FREQUENCYIO = 0
+CIRCUITPY_GAMEPAD = 0
CIRCUITPY_I2CSLAVE = 0
+CIRCUITPY_PIXELBUF = 0
SUPEROPT_GC = 0
CFLAGS_INLINE_LIMIT = 55
diff --git a/ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.h b/ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.h
index 4486e8a6d..c9a7ce040 100644
--- a/ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.h
+++ b/ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.h
@@ -43,3 +43,5 @@
// USB is always used internally so skip the pin objects for it.
#define IGNORE_PIN_PA24 1
#define IGNORE_PIN_PA25 1
+
+#define MICROPY_PY_URE 0
diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile
index e6070fc32..f38b9f684 100755
--- a/ports/nrf/Makefile
+++ b/ports/nrf/Makefile
@@ -138,6 +138,7 @@ SRC_NRFX = $(addprefix nrfx/,\
drivers/src/nrfx_uarte.c \
drivers/src/nrfx_gpiote.c \
drivers/src/nrfx_rtc.c \
+ drivers/src/nrfx_nvmc.c \
)
ifdef EXTERNAL_FLASH_DEVICES
@@ -167,7 +168,6 @@ SRC_C += \
lib/utils/pyexec.c \
lib/utils/stdout_helpers.c \
lib/utils/sys_stdio_mphal.c \
- nrfx/hal/nrf_nvmc.c \
nrfx/mdk/system_$(MCU_SUB_VARIANT).c \
peripherals/nrf/cache.c \
peripherals/nrf/clocks.c \
diff --git a/ports/nrf/common-hal/analogio/AnalogIn.c b/ports/nrf/common-hal/analogio/AnalogIn.c
index 44ebe9b4d..3bc097019 100644
--- a/ports/nrf/common-hal/analogio/AnalogIn.c
+++ b/ports/nrf/common-hal/analogio/AnalogIn.c
@@ -36,12 +36,12 @@
void analogin_init(void) {
// Calibrate the ADC once, on startup.
- nrf_saadc_enable();
- nrf_saadc_event_clear(NRF_SAADC_EVENT_CALIBRATEDONE);
- nrf_saadc_task_trigger(NRF_SAADC_TASK_CALIBRATEOFFSET);
- while (nrf_saadc_event_check(NRF_SAADC_EVENT_CALIBRATEDONE) == 0) { }
- nrf_saadc_event_clear(NRF_SAADC_EVENT_CALIBRATEDONE);
- nrf_saadc_disable();
+ nrf_saadc_enable(NRF_SAADC);
+ nrf_saadc_event_clear(NRF_SAADC, NRF_SAADC_EVENT_CALIBRATEDONE);
+ nrf_saadc_task_trigger(NRF_SAADC, NRF_SAADC_TASK_CALIBRATEOFFSET);
+ while (nrf_saadc_event_check(NRF_SAADC, NRF_SAADC_EVENT_CALIBRATEDONE) == 0) { }
+ nrf_saadc_event_clear(NRF_SAADC, NRF_SAADC_EVENT_CALIBRATEDONE);
+ nrf_saadc_disable(NRF_SAADC);
}
void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, const mcu_pin_obj_t *pin) {
@@ -81,34 +81,33 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
.reference = NRF_SAADC_REFERENCE_VDD4,
.acq_time = NRF_SAADC_ACQTIME_3US,
.mode = NRF_SAADC_MODE_SINGLE_ENDED,
- .burst = NRF_SAADC_BURST_DISABLED,
- .pin_p = self->pin->adc_channel,
- .pin_n = self->pin->adc_channel,
+ .burst = NRF_SAADC_BURST_DISABLED
};
- nrf_saadc_resolution_set(NRF_SAADC_RESOLUTION_14BIT);
- nrf_saadc_oversample_set(NRF_SAADC_OVERSAMPLE_DISABLED);
- nrf_saadc_enable();
+ nrf_saadc_resolution_set(NRF_SAADC, NRF_SAADC_RESOLUTION_14BIT);
+ nrf_saadc_oversample_set(NRF_SAADC, NRF_SAADC_OVERSAMPLE_DISABLED);
+ nrf_saadc_enable(NRF_SAADC);
- for (uint32_t i = 0; i < NRF_SAADC_CHANNEL_COUNT; i++)
- nrf_saadc_channel_input_set(i, NRF_SAADC_INPUT_DISABLED, NRF_SAADC_INPUT_DISABLED);
+ for (uint32_t i = 0; i < SAADC_CH_NUM; i++)
+ nrf_saadc_channel_input_set(NRF_SAADC, i, NRF_SAADC_INPUT_DISABLED, NRF_SAADC_INPUT_DISABLED);
- nrf_saadc_channel_init(CHANNEL_NO, &config);
- nrf_saadc_buffer_init(&value, 1);
+ nrf_saadc_channel_init(NRF_SAADC, CHANNEL_NO, &config);
+ nrf_saadc_channel_input_set(NRF_SAADC, CHANNEL_NO, self->pin->adc_channel, self->pin->adc_channel);
+ nrf_saadc_buffer_init(NRF_SAADC, &value, 1);
- nrf_saadc_task_trigger(NRF_SAADC_TASK_START);
- while (nrf_saadc_event_check(NRF_SAADC_EVENT_STARTED) == 0);
- nrf_saadc_event_clear(NRF_SAADC_EVENT_STARTED);
+ nrf_saadc_task_trigger(NRF_SAADC, NRF_SAADC_TASK_START);
+ while (nrf_saadc_event_check(NRF_SAADC, NRF_SAADC_EVENT_STARTED) == 0);
+ nrf_saadc_event_clear(NRF_SAADC, NRF_SAADC_EVENT_STARTED);
- nrf_saadc_task_trigger(NRF_SAADC_TASK_SAMPLE);
- while (nrf_saadc_event_check(NRF_SAADC_EVENT_END) == 0);
- nrf_saadc_event_clear(NRF_SAADC_EVENT_END);
+ nrf_saadc_task_trigger(NRF_SAADC, NRF_SAADC_TASK_SAMPLE);
+ while (nrf_saadc_event_check(NRF_SAADC, NRF_SAADC_EVENT_END) == 0);
+ nrf_saadc_event_clear(NRF_SAADC, NRF_SAADC_EVENT_END);
- nrf_saadc_task_trigger(NRF_SAADC_TASK_STOP);
- while (nrf_saadc_event_check(NRF_SAADC_EVENT_STOPPED) == 0);
- nrf_saadc_event_clear(NRF_SAADC_EVENT_STOPPED);
+ nrf_saadc_task_trigger(NRF_SAADC, NRF_SAADC_TASK_STOP);
+ while (nrf_saadc_event_check(NRF_SAADC, NRF_SAADC_EVENT_STOPPED) == 0);
+ nrf_saadc_event_clear(NRF_SAADC, NRF_SAADC_EVENT_STOPPED);
- nrf_saadc_disable();
+ nrf_saadc_disable(NRF_SAADC);
if (value < 0)
value = 0;
diff --git a/ports/nrf/common-hal/audiopwmio/PWMAudioOut.c b/ports/nrf/common-hal/audiopwmio/PWMAudioOut.c
index d9226628f..cdb57bbe1 100644
--- a/ports/nrf/common-hal/audiopwmio/PWMAudioOut.c
+++ b/ports/nrf/common-hal/audiopwmio/PWMAudioOut.c
@@ -225,10 +225,6 @@ void common_hal_audiopwmio_pwmaudioout_play(audiopwmio_pwmaudioout_obj_t* self,
self->loop = loop;
uint32_t sample_rate = audiosample_sample_rate(sample);
- uint32_t max_sample_rate = 62500;
- if (sample_rate > max_sample_rate) {
- mp_raise_ValueError_varg(translate("Sample rate too high. It must be less than %d"), max_sample_rate);
- }
self->bytes_per_sample = audiosample_bits_per_sample(sample) / 8;
uint32_t max_buffer_length;
diff --git a/ports/nrf/common-hal/busio/I2C.c b/ports/nrf/common-hal/busio/I2C.c
index 8a2ebde3b..7a079ff7f 100644
--- a/ports/nrf/common-hal/busio/I2C.c
+++ b/ports/nrf/common-hal/busio/I2C.c
@@ -133,9 +133,8 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *
mp_raise_RuntimeError(translate("SDA or SCL needs a pull up"));
}
- nrfx_twim_config_t config = NRFX_TWIM_DEFAULT_CONFIG;
- config.scl = scl->number;
- config.sda = sda->number;
+ nrfx_twim_config_t config = NRFX_TWIM_DEFAULT_CONFIG(scl->number, sda->number);
+
// change freq. only if it's less than the default 400K
if (frequency < 100000) {
config.frequency = NRF_TWIM_FREQ_100K;
@@ -248,8 +247,10 @@ uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr, const u
// break into MAX_XFER_LEN transaction
while ( len ) {
const size_t xact_len = MIN(len, I2C_MAX_XFER_LEN);
+ nrfx_twim_xfer_desc_t xfer_desc = NRFX_TWIM_XFER_DESC_TX(addr, (uint8_t*) data, xact_len);
+ uint32_t const flags = (stopBit ? 0 : NRFX_TWIM_FLAG_TX_NO_STOP);
- if ( NRFX_SUCCESS != (err = nrfx_twim_tx(&self->twim_peripheral->twim, addr, data, xact_len, !stopBit)) ) {
+ if ( NRFX_SUCCESS != (err = nrfx_twim_xfer(&self->twim_peripheral->twim, &xfer_desc, flags)) ) {
break;
}
@@ -274,8 +275,9 @@ uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t addr, uint8_t
// break into MAX_XFER_LEN transaction
while ( len ) {
const size_t xact_len = MIN(len, I2C_MAX_XFER_LEN);
+ nrfx_twim_xfer_desc_t xfer_desc = NRFX_TWIM_XFER_DESC_RX(addr, data, xact_len);
- if ( NRFX_SUCCESS != (err = nrfx_twim_rx(&self->twim_peripheral->twim, addr, data, xact_len)) ) {
+ if ( NRFX_SUCCESS != (err = nrfx_twim_xfer(&self->twim_peripheral->twim, &xfer_desc, 0)) ) {
break;
}
diff --git a/ports/nrf/common-hal/busio/SPI.c b/ports/nrf/common-hal/busio/SPI.c
index 5f1aac193..d2977909e 100644
--- a/ports/nrf/common-hal/busio/SPI.c
+++ b/ports/nrf/common-hal/busio/SPI.c
@@ -135,7 +135,8 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *
mp_raise_ValueError(translate("All SPI peripherals are in use"));
}
- nrfx_spim_config_t config = NRFX_SPIM_DEFAULT_CONFIG;
+ nrfx_spim_config_t config = NRFX_SPIM_DEFAULT_CONFIG(NRFX_SPIM_PIN_NOT_USED, NRFX_SPIM_PIN_NOT_USED,
+ NRFX_SPIM_PIN_NOT_USED, NRFX_SPIM_PIN_NOT_USED);
config.frequency = NRF_SPIM_FREQ_8M;
config.sck_pin = clock->number;
diff --git a/ports/nrf/common-hal/busio/UART.c b/ports/nrf/common-hal/busio/UART.c
index 9cdc197e7..0579db414 100644
--- a/ports/nrf/common-hal/busio/UART.c
+++ b/ports/nrf/common-hal/busio/UART.c
@@ -163,10 +163,12 @@ void common_hal_busio_uart_construct (busio_uart_obj_t *self,
.pselcts = NRF_UARTE_PSEL_DISCONNECTED,
.pselrts = NRF_UARTE_PSEL_DISCONNECTED,
.p_context = self,
- .hwfc = NRF_UARTE_HWFC_DISABLED,
- .parity = (parity == PARITY_NONE) ? NRF_UARTE_PARITY_EXCLUDED : NRF_UARTE_PARITY_INCLUDED,
.baudrate = get_nrf_baud(baudrate),
- .interrupt_priority = 7
+ .interrupt_priority = 7,
+ .hal_cfg = {
+ .hwfc = NRF_UARTE_HWFC_DISABLED,
+ .parity = (parity == PARITY_NONE) ? NRF_UARTE_PARITY_EXCLUDED : NRF_UARTE_PARITY_INCLUDED
+ }
};
nrfx_uarte_uninit(self->uarte);
diff --git a/ports/nrf/common-hal/microcontroller/Processor.c b/ports/nrf/common-hal/microcontroller/Processor.c
index abfd5b865..03d9c4d3f 100644
--- a/ports/nrf/common-hal/microcontroller/Processor.c
+++ b/ports/nrf/common-hal/microcontroller/Processor.c
@@ -75,35 +75,34 @@ float common_hal_mcu_processor_get_voltage(void) {
.reference = NRF_SAADC_REFERENCE_INTERNAL,
.acq_time = NRF_SAADC_ACQTIME_10US,
.mode = NRF_SAADC_MODE_SINGLE_ENDED,
- .burst = NRF_SAADC_BURST_DISABLED,
- .pin_p = NRF_SAADC_INPUT_VDD,
- .pin_n = NRF_SAADC_INPUT_VDD,
+ .burst = NRF_SAADC_BURST_DISABLED
};
- nrf_saadc_resolution_set(NRF_SAADC_RESOLUTION_14BIT);
- nrf_saadc_oversample_set(NRF_SAADC_OVERSAMPLE_DISABLED);
- nrf_saadc_enable();
+ nrf_saadc_resolution_set(NRF_SAADC, NRF_SAADC_RESOLUTION_14BIT);
+ nrf_saadc_oversample_set(NRF_SAADC, NRF_SAADC_OVERSAMPLE_DISABLED);
+ nrf_saadc_enable(NRF_SAADC);
- for (uint32_t i = 0; i < NRF_SAADC_CHANNEL_COUNT; i++) {
- nrf_saadc_channel_input_set(i, NRF_SAADC_INPUT_DISABLED, NRF_SAADC_INPUT_DISABLED);
+ for (uint32_t i = 0; i < SAADC_CH_NUM; i++) {
+ nrf_saadc_channel_input_set(NRF_SAADC, i, NRF_SAADC_INPUT_DISABLED, NRF_SAADC_INPUT_DISABLED);
}
- nrf_saadc_channel_init(0, &config);
- nrf_saadc_buffer_init(&value, 1);
+ nrf_saadc_channel_init(NRF_SAADC, 0, &config);
+ nrf_saadc_channel_input_set(NRF_SAADC, 0, NRF_SAADC_INPUT_VDD, NRF_SAADC_INPUT_VDD);
+ nrf_saadc_buffer_init(NRF_SAADC, &value, 1);
- nrf_saadc_task_trigger(NRF_SAADC_TASK_START);
- while (nrf_saadc_event_check(NRF_SAADC_EVENT_STARTED) == 0) { }
- nrf_saadc_event_clear(NRF_SAADC_EVENT_STARTED);
+ nrf_saadc_task_trigger(NRF_SAADC, NRF_SAADC_TASK_START);
+ while (nrf_saadc_event_check(NRF_SAADC, NRF_SAADC_EVENT_STARTED) == 0) { }
+ nrf_saadc_event_clear(NRF_SAADC, NRF_SAADC_EVENT_STARTED);
- nrf_saadc_task_trigger(NRF_SAADC_TASK_SAMPLE);
- while (nrf_saadc_event_check(NRF_SAADC_EVENT_END) == 0) { }
- nrf_saadc_event_clear(NRF_SAADC_EVENT_END);
+ nrf_saadc_task_trigger(NRF_SAADC, NRF_SAADC_TASK_SAMPLE);
+ while (nrf_saadc_event_check(NRF_SAADC, NRF_SAADC_EVENT_END) == 0) { }
+ nrf_saadc_event_clear(NRF_SAADC, NRF_SAADC_EVENT_END);
- nrf_saadc_task_trigger(NRF_SAADC_TASK_STOP);
- while (nrf_saadc_event_check(NRF_SAADC_EVENT_STOPPED) == 0) { }
- nrf_saadc_event_clear(NRF_SAADC_EVENT_STOPPED);
+ nrf_saadc_task_trigger(NRF_SAADC, NRF_SAADC_TASK_STOP);
+ while (nrf_saadc_event_check(NRF_SAADC, NRF_SAADC_EVENT_STOPPED) == 0) { }
+ nrf_saadc_event_clear(NRF_SAADC, NRF_SAADC_EVENT_STOPPED);
- nrf_saadc_disable();
+ nrf_saadc_disable(NRF_SAADC);
if (value < 0) {
value = 0;
diff --git a/ports/nrf/common-hal/os/__init__.c b/ports/nrf/common-hal/os/__init__.c
index 7671cc2a5..e38226f94 100644
--- a/ports/nrf/common-hal/os/__init__.c
+++ b/ports/nrf/common-hal/os/__init__.c
@@ -70,17 +70,17 @@ bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) {
return NRF_SUCCESS == sd_rand_application_vector_get(buffer, length);
#endif
- nrf_rng_event_clear(NRF_RNG_EVENT_VALRDY);
- nrf_rng_task_trigger(NRF_RNG_TASK_START);
+ nrf_rng_event_clear(NRF_RNG, NRF_RNG_EVENT_VALRDY);
+ nrf_rng_task_trigger(NRF_RNG, NRF_RNG_TASK_START);
for (uint32_t i = 0; i < length; i++) {
- while (nrf_rng_event_get(NRF_RNG_EVENT_VALRDY) == 0);
- nrf_rng_event_clear(NRF_RNG_EVENT_VALRDY);
+ while (nrf_rng_event_check(NRF_RNG, NRF_RNG_EVENT_VALRDY) == 0);
+ nrf_rng_event_clear(NRF_RNG, NRF_RNG_EVENT_VALRDY);
- buffer[i] = nrf_rng_random_value_get();
+ buffer[i] = nrf_rng_random_value_get(NRF_RNG);
}
- nrf_rng_task_trigger(NRF_RNG_TASK_STOP);
+ nrf_rng_task_trigger(NRF_RNG, NRF_RNG_TASK_STOP);
return true;
}
diff --git a/ports/nrf/common-hal/pulseio/PulseIn.c b/ports/nrf/common-hal/pulseio/PulseIn.c
index 383966831..b47cc6273 100644
--- a/ports/nrf/common-hal/pulseio/PulseIn.c
+++ b/ports/nrf/common-hal/pulseio/PulseIn.c
@@ -112,7 +112,7 @@ void pulsein_reset(void) {
if ( nrfx_gpiote_is_init() ) {
nrfx_gpiote_uninit();
}
- nrfx_gpiote_init();
+ nrfx_gpiote_init(NRFX_GPIOTE_CONFIG_IRQ_PRIORITY);
memset(_objs, 0, sizeof(_objs));
}
diff --git a/ports/nrf/common-hal/rtc/RTC.c b/ports/nrf/common-hal/rtc/RTC.c
index 57138350c..a8ea36688 100644
--- a/ports/nrf/common-hal/rtc/RTC.c
+++ b/ports/nrf/common-hal/rtc/RTC.c
@@ -59,8 +59,8 @@ void rtc_handler(nrfx_rtc_int_type_t int_type) {
}
void rtc_init(void) {
- if (!nrf_clock_lf_is_running()) {
- nrf_clock_task_trigger(NRF_CLOCK_TASK_LFCLKSTART);
+ if (!nrf_clock_lf_is_running(NRF_CLOCK)) {
+ nrf_clock_task_trigger(NRF_CLOCK, NRF_CLOCK_TASK_LFCLKSTART);
}
nrfx_rtc_counter_clear(&rtc_instance);
nrfx_rtc_init(&rtc_instance, &rtc_config, rtc_handler);
diff --git a/ports/nrf/nrfx b/ports/nrf/nrfx
-Subproject 3d268263be2390ab760f75a3da72689ef13031a
+Subproject 3f55e49eb11e6db0da1da09e189bb094222702c
diff --git a/ports/nrf/nrfx_config.h b/ports/nrf/nrfx_config.h
index cafec6aa1..82f6514df 100644
--- a/ports/nrf/nrfx_config.h
+++ b/ports/nrf/nrfx_config.h
@@ -3,7 +3,7 @@
// Power
#define NRFX_POWER_ENABLED 1
-#define NRFX_POWER_CONFIG_IRQ_PRIORITY 7
+#define NRFX_POWER_DEFAULT_CONFIG_IRQ_PRIORITY 7
// NOTE: THIS WORKAROUND CAUSES BLE CODE TO CRASH.
// It doesn't work with the SoftDevice.
@@ -116,4 +116,7 @@
#define NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS 1
#define NRFX_GPIOTE_CONFIG_IRQ_PRIORITY 7
+// NVM controller
+#define NRFX_NVMC_ENABLED 1
+
#endif // NRFX_CONFIG_H__
diff --git a/ports/nrf/peripherals/nrf/nrf52840/power.c b/ports/nrf/peripherals/nrf/nrf52840/power.c
index 9f7a9fa17..794872c5d 100644
--- a/ports/nrf/peripherals/nrf/nrf52840/power.c
+++ b/ports/nrf/peripherals/nrf/nrf52840/power.c
@@ -25,7 +25,7 @@
*/
#include "nrfx.h"
-#include "nrf_nvmc.h"
+#include "nrfx_nvmc.h"
void nrf_peripherals_power_init(void) {
// Set GPIO reference voltage to 3.3V if it isn't already. REGOUT0 will get reset to 0xfffffff
@@ -33,7 +33,7 @@ void nrf_peripherals_power_init(void) {
// This matters only when "high voltage mode" is enabled, which is true on the PCA10059,
// and might be true on other boards.
if (NRF_UICR->REGOUT0 == 0xffffffff) {
- nrf_nvmc_write_word((uint32_t) &NRF_UICR->REGOUT0, UICR_REGOUT0_VOUT_3V3 << UICR_REGOUT0_VOUT_Pos);
+ nrfx_nvmc_word_write((uint32_t) &NRF_UICR->REGOUT0, UICR_REGOUT0_VOUT_3V3 << UICR_REGOUT0_VOUT_Pos);
// Must reset to make enable change.
NVIC_SystemReset();
}
diff --git a/ports/nrf/peripherals/nrf/nvm.c b/ports/nrf/peripherals/nrf/nvm.c
index 7118b9c87..1501ccfc9 100644
--- a/ports/nrf/peripherals/nrf/nvm.c
+++ b/ports/nrf/peripherals/nrf/nvm.c
@@ -30,7 +30,7 @@
#include <stdio.h>
#include <string.h>
-#include "nrf_nvmc.h"
+#include "nrfx_nvmc.h"
#define FLASH_PAGE_SIZE (4096)
@@ -90,7 +90,7 @@ bool nrf_nvm_safe_flash_page_write(uint32_t page_addr, uint8_t *data) {
}
#endif
- nrf_nvmc_page_erase(page_addr);
- nrf_nvmc_write_bytes(page_addr, data, FLASH_PAGE_SIZE);
+ nrfx_nvmc_page_erase(page_addr);
+ nrfx_nvmc_bytes_write(page_addr, data, FLASH_PAGE_SIZE);
return true;
}
diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h
index 3161938c4..932d4f855 100644
--- a/py/circuitpy_mpconfig.h
+++ b/py/circuitpy_mpconfig.h
@@ -193,7 +193,9 @@ typedef long mp_off_t;
#define MICROPY_PY_UERRNO (CIRCUITPY_FULL_BUILD)
// Opposite setting is deliberate.
#define MICROPY_PY_UERRNO_ERRORCODE (!CIRCUITPY_FULL_BUILD)
+#ifndef MICROPY_PY_URE
#define MICROPY_PY_URE (CIRCUITPY_FULL_BUILD)
+#endif
#define MICROPY_PY_URE_MATCH_GROUPS (CIRCUITPY_FULL_BUILD)
#define MICROPY_PY_URE_MATCH_SPAN_START_END (CIRCUITPY_FULL_BUILD)
#define MICROPY_PY_URE_SUB (CIRCUITPY_FULL_BUILD)
diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c
index 5ce7b3581..5759e8ad2 100644
--- a/shared-bindings/displayio/Display.c
+++ b/shared-bindings/displayio/Display.c
@@ -394,11 +394,18 @@ STATIC mp_obj_t displayio_display_obj_get_rotation(mp_obj_t self_in) {
return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_display_get_rotation(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_rotation_obj, displayio_display_obj_get_rotation);
+STATIC mp_obj_t displayio_display_obj_set_rotation(mp_obj_t self_in, mp_obj_t value) {
+ displayio_display_obj_t *self = native_display(self_in);
+ common_hal_displayio_display_set_rotation(self, mp_obj_get_int(value));
+ return mp_const_none;
+}
+MP_DEFINE_CONST_FUN_OBJ_2(displayio_display_set_rotation_obj, displayio_display_obj_set_rotation);
+
const mp_obj_property_t displayio_display_rotation_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&displayio_display_get_rotation_obj,
- (mp_obj_t)&mp_const_none_obj,
+ (mp_obj_t)&displayio_display_set_rotation_obj,
(mp_obj_t)&mp_const_none_obj},
};
diff --git a/shared-bindings/displayio/Display.h b/shared-bindings/displayio/Display.h
index ca2b2d476..b82a68ebe 100644
--- a/shared-bindings/displayio/Display.h
+++ b/shared-bindings/displayio/Display.h
@@ -58,6 +58,7 @@ void common_hal_displayio_display_set_auto_refresh(displayio_display_obj_t* self
uint16_t common_hal_displayio_display_get_width(displayio_display_obj_t* self);
uint16_t common_hal_displayio_display_get_height(displayio_display_obj_t* self);
uint16_t common_hal_displayio_display_get_rotation(displayio_display_obj_t* self);
+void common_hal_displayio_display_set_rotation(displayio_display_obj_t* self, int rotation);
bool common_hal_displayio_display_get_auto_brightness(displayio_display_obj_t* self);
void common_hal_displayio_display_set_auto_brightness(displayio_display_obj_t* self, bool auto_brightness);
diff --git a/shared-bindings/random/__init__.c b/shared-bindings/random/__init__.c
index fdef91443..110d59aa4 100644
--- a/shared-bindings/random/__init__.c
+++ b/shared-bindings/random/__init__.c
@@ -33,11 +33,11 @@
#include "shared-bindings/random/__init__.h"
#include "supervisor/shared/translate.h"
-//| :mod:`random` --- psuedo-random numbers and choices
+//| :mod:`random` --- pseudo-random numbers and choices
//| ========================================================
//|
//| .. module:: random
-//| :synopsis: psuedo-random numbers and choices
+//| :synopsis: pseudo-random numbers and choices
//| :platform: SAMD21, ESP8266
//|
//| The `random` module is a strict subset of the CPython `cpython:random`
diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c
index 11db0f8ff..299c8ad35 100644
--- a/shared-module/displayio/Display.c
+++ b/shared-module/displayio/Display.c
@@ -308,10 +308,27 @@ STATIC void _refresh_display(displayio_display_obj_t* self) {
displayio_display_core_finish_refresh(&self->core);
}
+void common_hal_displayio_display_set_rotation(displayio_display_obj_t* self, int rotation){
+ bool transposed = (self->core.rotation == 90 || self->core.rotation == 270);
+ bool will_transposed = (rotation == 90 || rotation == 270);
+ if(transposed != will_transposed) {
+ int tmp = self->core.width;
+ self->core.width = self->core.height;
+ self->core.height = tmp;
+ }
+ displayio_display_core_set_rotation(&self->core, rotation);
+ supervisor_stop_terminal();
+ supervisor_start_terminal(self->core.width, self->core.height);
+ if (self->core.current_group != NULL) {
+ displayio_group_update_transform(self->core.current_group, &self->core.transform);
+ }
+}
+
uint16_t common_hal_displayio_display_get_rotation(displayio_display_obj_t* self){
return self->core.rotation;
}
+
bool common_hal_displayio_display_refresh(displayio_display_obj_t* self, uint32_t target_ms_per_frame, uint32_t maximum_ms_per_real_frame) {
if (!self->auto_refresh && !self->first_manual_refresh) {
uint64_t current_time = supervisor_ticks_ms64();
diff --git a/shared-module/displayio/display_core.c b/shared-module/displayio/display_core.c
index 658daa8d6..120b70f76 100644
--- a/shared-module/displayio/display_core.c
+++ b/shared-module/displayio/display_core.c
@@ -86,6 +86,15 @@ void displayio_display_core_construct(displayio_display_core_t* self,
self->height = height;
self->ram_width = ram_width;
self->ram_height = ram_height;
+
+ displayio_display_core_set_rotation(self, rotation);
+}
+
+void displayio_display_core_set_rotation( displayio_display_core_t* self,
+ int rotation) {
+ int height = self->height;
+ int width = self->width;
+
rotation = rotation % 360;
self->rotation = rotation;
self->transform.x = 0;
diff --git a/shared-module/displayio/display_core.h b/shared-module/displayio/display_core.h
index 3a69cd40a..1c3d0f09c 100644
--- a/shared-module/displayio/display_core.h
+++ b/shared-module/displayio/display_core.h
@@ -68,6 +68,8 @@ uint16_t displayio_display_core_get_height(displayio_display_core_t* self);
void displayio_display_core_set_dither(displayio_display_core_t* self, bool dither);
bool displayio_display_core_get_dither(displayio_display_core_t* self);
+void displayio_display_core_set_rotation(displayio_display_core_t* self, int rotation);
+
bool displayio_display_core_bus_free(displayio_display_core_t *self);
bool displayio_display_core_begin_transaction(displayio_display_core_t* self);
void displayio_display_core_end_transaction(displayio_display_core_t* self);
diff --git a/supervisor/shared/display.c b/supervisor/shared/display.c
index c6fda0f16..855432d64 100644
--- a/supervisor/shared/display.c
+++ b/supervisor/shared/display.c
@@ -81,6 +81,7 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) {
grid->pixel_width = width_in_tiles * grid->tile_width;
grid->pixel_height = height_in_tiles * grid->tile_height;
grid->tiles = tiles;
+ grid->full_change = true;
common_hal_terminalio_terminal_construct(&supervisor_terminal, grid, &supervisor_terminal_font);
}
diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c
index c1d70c5b0..a0178528d 100644
--- a/supervisor/shared/usb/usb.c
+++ b/supervisor/shared/usb/usb.c
@@ -87,10 +87,12 @@ void usb_background(void) {
// Invoked when device is mounted
void tud_mount_cb(void) {
+ usb_msc_mount();
}
// Invoked when device is unmounted
void tud_umount_cb(void) {
+ usb_msc_umount();
}
// Invoked when usb bus is suspended
diff --git a/supervisor/shared/usb/usb_msc_flash.c b/supervisor/shared/usb/usb_msc_flash.c
index 205cb7b50..0376cfc1d 100644
--- a/supervisor/shared/usb/usb_msc_flash.c
+++ b/supervisor/shared/usb/usb_msc_flash.c
@@ -41,6 +41,18 @@
static bool ejected[1];
+void usb_msc_mount(void) {
+ // Reset the ejection tracking every time we're plugged into USB. This allows for us to battery
+ // power the device, eject, unplug and plug it back in to get the drive.
+ for (uint8_t i = 0; i < sizeof(ejected); i++) {
+ ejected[i] = false;
+ }
+}
+
+void usb_msc_umount(void) {
+
+}
+
// The root FS is always at the end of the list.
static fs_user_mount_t* get_vfs(int lun) {
// TODO(tannewt): Return the mount which matches the lun where 0 is the end
@@ -198,19 +210,34 @@ bool tud_msc_test_unit_ready_cb(uint8_t lun) {
// - Start = 0 : stopped power mode, if load_eject = 1 : unload disk storage
// - Start = 1 : active mode, if load_eject = 1 : load disk storage
bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, bool load_eject) {
+ if (lun > 1) {
+ return false;
+ }
+ fs_user_mount_t* current_mount = get_vfs(lun);
+ if (current_mount == NULL) {
+ return false;
+ }
if (load_eject) {
- if (lun > 1) {
- return false;
- } else {
- fs_user_mount_t* current_mount = get_vfs(lun);
- if (current_mount == NULL) {
- return false;
- }
+ if (!start) {
+ // Eject but first flush.
if (disk_ioctl(current_mount, CTRL_SYNC, NULL) != RES_OK) {
return false;
} else {
ejected[lun] = true;
}
+ } else {
+ // We can only load if it hasn't been ejected.
+ return !ejected[lun];
+ }
+ } else {
+ if (!start) {
+ // Stop the unit but don't eject.
+ if (disk_ioctl(current_mount, CTRL_SYNC, NULL) != RES_OK) {
+ return false;
+ }
+ } else {
+ // Start the unit, but only if not ejected.
+ return !ejected[lun];
}
}
diff --git a/supervisor/usb.h b/supervisor/usb.h
index c87540d40..0cc361619 100644
--- a/supervisor/usb.h
+++ b/supervisor/usb.h
@@ -41,4 +41,8 @@ void init_usb_hardware(void);
bool usb_enabled(void);
void usb_init(void);
+// Propagate plug/unplug events to the MSC logic.
+void usb_msc_mount(void);
+void usb_msc_umount(void);
+
#endif // MICROPY_INCLUDED_SUPERVISOR_USB_H
diff --git a/tools/gen_display_resources.py b/tools/gen_display_resources.py
index 781b5e69b..c08daf477 100644
--- a/tools/gen_display_resources.py
+++ b/tools/gen_display_resources.py
@@ -48,18 +48,19 @@ for c in sample_characters:
all_characters += c
if args.extra_characters:
all_characters.extend(args.extra_characters)
+all_characters = "".join(sorted(set(all_characters)))
filtered_characters = all_characters
# Try to pre-load all of the glyphs. Misses will still be slow later.
-f.load_glyphs(set(all_characters))
+f.load_glyphs(set(ord(c) for c in all_characters))
# Get each glyph.
-for c in all_characters:
- g = f.get_glyph(ord(c))
- if not g:
+for c in set(all_characters):
+ if ord(c) not in f._glyphs:
print("Font missing character:", c, ord(c))
filtered_characters = filtered_characters.replace(c, "")
continue
+ g = f.get_glyph(ord(c))
if g["shift"][1] != 0:
raise RuntimeError("y shift")