Skip to content

Commit 06a2fe1

Browse files
authored
Merge branch 'adafruit:main' into issue-9937
2 parents 3da2914 + b044c4c commit 06a2fe1

File tree

20 files changed

+99
-28
lines changed

20 files changed

+99
-28
lines changed

Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -156,22 +156,28 @@ epub:
156156
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
157157

158158
latex:
159+
$(PYTHON) docs/prepare_readme_for_latex.py
159160
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
161+
mv README.rst.bak README.rst
160162
@echo
161163
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
162164
@echo "Run \`make' in that directory to run these through (pdf)latex" \
163165
"(use \`make latexpdf' here to do that automatically)."
164166

165167
# seems to be malfunctioning
166168
latexpdf:
169+
$(PYTHON) docs/prepare_readme_for_latex.py
167170
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
171+
mv README.rst.bak README.rst
168172
@echo "Running LaTeX files through pdflatex..."
169173
$(MAKE) -C $(BUILDDIR)/latex all-pdf
170174
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
171175

172176
# seems to be malfunctioning
173177
latexpdfja:
178+
$(PYTHON) docs/prepare_readme_for_latex.py
174179
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
180+
mv README.rst.bak README.rst
175181
@echo "Running LaTeX files through platex and dvipdfmx..."
176182
$(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
177183
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."

docs/prepare_readme_for_latex.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import shutil
2+
3+
with open("README.rst", "r") as f:
4+
readme_content = f.read()
5+
6+
shutil.copyfile("README.rst", "README.rst.bak")
7+
8+
# turn badge into text only
9+
modified_readme_content = readme_content.replace("|Weblate|", "Weblate", 1)
10+
11+
# remove image link
12+
badge_link_lines = """.. |Weblate| image:: https://hosted.weblate.org/widgets/circuitpython/-/svg-badge.svg
13+
:target: https://hosted.weblate.org/engage/circuitpython/?utm_source=widget"""
14+
15+
modified_readme_content = modified_readme_content.replace(badge_link_lines, "")
16+
17+
with open("README.rst", "w") as f:
18+
f.write(modified_readme_content)

ports/broadcom/supervisor/port.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ uint64_t port_get_raw_ticks(uint8_t *subticks) {
143143
}
144144
COMPLETE_MEMORY_READS;
145145
uint64_t microseconds = hi << 32 | lo;
146-
return 1024 * (microseconds / 1000000) + (microseconds % 1000000) / 977;
146+
int64_t all_subticks = microseconds * 512 / 15625;
147+
if (subticks != NULL) {
148+
*subticks = all_subticks % 32;
149+
}
150+
return all_subticks / 32;
147151
}
148152

149153
void TIMER_1_IRQHandler(void) {

ports/cxd56/supervisor/port.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ void board_timerhook(void) {
124124

125125
uint64_t port_get_raw_ticks(uint8_t *subticks) {
126126
uint64_t count = cxd56_rtc_count();
127-
*subticks = count % 32;
127+
if (subticks != NULL) {
128+
*subticks = count % 32;
129+
}
128130

129131
return count / 32;
130132
}

ports/espressif/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ else ifeq ($(IDF_TARGET),esp32c3)
268268
LDFLAGS += \
269269
-Tesp32c3.rom.newlib.ld \
270270
-Tesp32c3.rom.version.ld \
271+
-Tesp32c3.rom.eco3_bt_funcs.ld \
271272
-Tesp32c3.rom.eco3.ld \
272273
-Tesp32c3.rom.bt_funcs.ld
273274

ports/litex/supervisor/port.c

+3
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ uint64_t port_get_raw_ticks(uint8_t *subticks) {
114114
common_hal_mcu_disable_interrupts();
115115
uint64_t raw_tick_snapshot = raw_ticks;
116116
common_hal_mcu_enable_interrupts();
117+
if (subticks != NULL) {
118+
*subticks = 0;
119+
}
117120
return raw_tick_snapshot;
118121
}
119122

ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pin_names.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
//
77
// SPDX-License-Identifier: MIT
88

9-
#pragma once
10-
9+
// OK to include more than once because FORMAT_PIN may be different.
1110

1211
// define FORMAT_PIN(pin_name) and then include this file.
1312

ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pin_names.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
// SPDX-License-Identifier: MIT
88

9-
#pragma once
9+
// OK to include more than once because FORMAT_PIN may be different.
1010

1111

1212
// define FORMAT_PIN(pin_name) and then include this file.

ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pin_names.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
// SPDX-License-Identifier: MIT
88

9-
#pragma once
9+
// OK to include more than once because FORMAT_PIN may be different.
1010

1111

1212
// define FORMAT_PIN(pin_name) and then include this file.

ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pin_names.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
// SPDX-License-Identifier: MIT
88

9-
#pragma once
9+
// OK to include more than once because FORMAT_PIN may be different.
1010

1111

1212
// define FORMAT_PIN(pin_name) and then include this file.

ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pin_names.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
// SPDX-License-Identifier: MIT
88

9-
#pragma once
9+
// OK to include more than once because FORMAT_PIN may be different.
1010

1111

1212
// define FORMAT_PIN(pin_name) and then include this file.

ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pin_names.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
// SPDX-License-Identifier: MIT
88

9-
#pragma once
9+
// OK to include more than once because FORMAT_PIN may be different.
1010

1111

1212
// define FORMAT_PIN(pin_name) and then include this file.

ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pin_names.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
// SPDX-License-Identifier: MIT
88

9-
#pragma once
9+
// OK to include more than once because FORMAT_PIN may be different.
1010

1111

1212
// define FORMAT_PIN(pin_name) and then include this file.

ports/mimxrt10xx/peripherals/mimxrt10xx/pin_names.h

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
//
66
// SPDX-License-Identifier: MIT
77

8-
#pragma once
9-
108
// OK to include more than once because FORMAT_PIN may be different.
119

1210
#ifdef MIMXRT1011_SERIES

ports/raspberrypi/supervisor/port.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -491,11 +491,11 @@ static volatile bool ticks_enabled;
491491
static volatile bool _woken_up;
492492

493493
uint64_t port_get_raw_ticks(uint8_t *subticks) {
494-
uint64_t microseconds = time_us_64();
494+
int64_t all_subticks = time_us_64() * 512 / 15625;
495495
if (subticks != NULL) {
496-
*subticks = (uint8_t)(((microseconds % 1000000) % 977) / 31);
496+
*subticks = all_subticks % 32;
497497
}
498-
return 1024 * (microseconds / 1000000) + (microseconds % 1000000) / 977;
498+
return all_subticks / 32;
499499
}
500500

501501
static void _tick_callback(uint alarm_num) {

shared-bindings/audiomixer/MixerVoice.c

+14
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ static mp_obj_t audiomixer_mixervoice_obj_stop(size_t n_args, const mp_obj_t *po
8181
}
8282
MP_DEFINE_CONST_FUN_OBJ_KW(audiomixer_mixervoice_stop_obj, 1, audiomixer_mixervoice_obj_stop);
8383

84+
//| def end(self) -> None:
85+
//| """ Sets looping to False if sample is playing. This allows the looped
86+
//| sample to complete its current playback and end further looping """
87+
//| ...
88+
//|
89+
static mp_obj_t audiomixer_mixervoice_obj_end(mp_obj_t self_in) {
90+
audiomixer_mixervoice_obj_t *self = MP_OBJ_TO_PTR(self_in);
91+
common_hal_audiomixer_mixervoice_end(self);
92+
return mp_const_none;
93+
}
94+
MP_DEFINE_CONST_FUN_OBJ_1(audiomixer_mixervoice_end_obj, audiomixer_mixervoice_obj_end);
95+
96+
8497
//| level: synthio.BlockInput
8598
//| """The volume level of a voice, as a floating point number between 0 and 1. If your board
8699
//| does not support synthio, this property will only accept a float value.
@@ -140,6 +153,7 @@ static const mp_rom_map_elem_t audiomixer_mixervoice_locals_dict_table[] = {
140153
// Methods
141154
{ MP_ROM_QSTR(MP_QSTR_play), MP_ROM_PTR(&audiomixer_mixervoice_play_obj) },
142155
{ MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&audiomixer_mixervoice_stop_obj) },
156+
{ MP_ROM_QSTR(MP_QSTR_end), MP_ROM_PTR(&audiomixer_mixervoice_end_obj) },
143157

144158
// Properties
145159
{ MP_ROM_QSTR(MP_QSTR_playing), MP_ROM_PTR(&audiomixer_mixervoice_playing_obj) },

shared-bindings/audiomixer/MixerVoice.h

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ void common_hal_audiomixer_mixervoice_construct(audiomixer_mixervoice_obj_t *sel
1515
void common_hal_audiomixer_mixervoice_set_parent(audiomixer_mixervoice_obj_t *self, audiomixer_mixer_obj_t *parent);
1616
void common_hal_audiomixer_mixervoice_play(audiomixer_mixervoice_obj_t *self, mp_obj_t sample, bool loop);
1717
void common_hal_audiomixer_mixervoice_stop(audiomixer_mixervoice_obj_t *self);
18+
void common_hal_audiomixer_mixervoice_end(audiomixer_mixervoice_obj_t *self);
1819
mp_obj_t common_hal_audiomixer_mixervoice_get_level(audiomixer_mixervoice_obj_t *self);
1920
void common_hal_audiomixer_mixervoice_set_level(audiomixer_mixervoice_obj_t *self, mp_obj_t gain);
2021

shared-module/audiomixer/MixerVoice.c

+6
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,9 @@ bool common_hal_audiomixer_mixervoice_get_playing(audiomixer_mixervoice_obj_t *s
6767
void common_hal_audiomixer_mixervoice_stop(audiomixer_mixervoice_obj_t *self) {
6868
self->sample = NULL;
6969
}
70+
71+
void common_hal_audiomixer_mixervoice_end(audiomixer_mixervoice_obj_t *self) {
72+
if (self->sample != NULL) {
73+
self->loop = false;
74+
}
75+
}

supervisor/shared/tick.c

+24-13
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ void supervisor_tick(void) {
8585
background_callback_add(&tick_callback, supervisor_background_tick, NULL);
8686
}
8787

88+
static uint64_t _get_raw_subticks(void) {
89+
uint64_t ticks;
90+
uint8_t subticks;
91+
ticks = port_get_raw_ticks(&subticks);
92+
return (ticks << 5) | subticks;
93+
}
94+
8895
uint64_t supervisor_ticks_ms64() {
8996
uint64_t result;
9097
result = port_get_raw_ticks(NULL);
@@ -97,26 +104,30 @@ uint32_t supervisor_ticks_ms32() {
97104
}
98105

99106
void mp_hal_delay_ms(mp_uint_t delay_ms) {
100-
uint64_t start_tick = port_get_raw_ticks(NULL);
101-
// Adjust the delay to ticks vs ms.
102-
uint64_t delay_ticks = (delay_ms * (uint64_t)1024) / 1000;
103-
uint64_t end_tick = start_tick + delay_ticks;
104-
int64_t remaining = delay_ticks;
107+
uint64_t start_subtick = _get_raw_subticks();
108+
// Convert delay from ms to subticks
109+
uint64_t delay_subticks = (delay_ms * (uint64_t)32768) / 1000;
110+
uint64_t end_subtick = start_subtick + delay_subticks;
111+
int64_t remaining = delay_subticks;
105112

106113
// Loop until we've waited long enough or we've been CTRL-Ced by autoreload
107114
// or the user.
108115
while (remaining > 0 && !mp_hal_is_interrupted()) {
109116
RUN_BACKGROUND_TASKS;
110-
remaining = end_tick - port_get_raw_ticks(NULL);
111-
// We break a bit early so we don't risk setting the alarm before the time when we call
112-
// sleep.
113-
if (remaining < 1) {
117+
// Exit if interrupted while running background tasks
118+
if (mp_hal_is_interrupted()) {
114119
break;
115120
}
116-
port_interrupt_after_ticks(remaining);
117-
// Idle until an interrupt happens.
118-
port_idle_until_interrupt();
119-
remaining = end_tick - port_get_raw_ticks(NULL);
121+
// Recalculate remaining delay after running background tasks
122+
remaining = end_subtick - _get_raw_subticks();
123+
// If remaining delay is less than 1 tick, idle loop until end of delay
124+
int64_t remaining_ticks = remaining / 32;
125+
if (remaining_ticks > 0) {
126+
port_interrupt_after_ticks(remaining_ticks);
127+
// Idle until an interrupt happens.
128+
port_idle_until_interrupt();
129+
}
130+
remaining = end_subtick - _get_raw_subticks();
120131
}
121132
}
122133

tools/build_board_info.py

+8
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@ def create_pr(changes, updated, git_info, user):
173173
changes["new_release"], boards, languages
174174
)
175175

176+
# Sync main so that the fork has the same commit sha1
177+
sync_main = {"branch": "main"}
178+
response = github.post(
179+
"/repos/{}/circuitpython-org/merge-upstream".format(user), json=sync_main
180+
)
181+
if not response.ok:
182+
raise SystemExit(f"unable to sync main: {response.text}")
183+
176184
create_branch = {"ref": "refs/heads/" + branch_name, "sha": commit_sha}
177185
response = github.post("/repos/{}/circuitpython-org/git/refs".format(user), json=create_branch)
178186
if not response.ok and response.json()["message"] != "Reference already exists":

0 commit comments

Comments
 (0)