Skip to content

Commit 5099271

Browse files
authored
Merge pull request #5686 from tannewt/merge_7.1
Merge 7.1 fixes back into main
2 parents 8eee16c + 89ce4d6 commit 5099271

File tree

20 files changed

+160
-102
lines changed

20 files changed

+160
-102
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
with:
3636
python-version: 3.8
3737
- name: Get CP deps
38-
run: python tools/ci_fetch_deps.py test ${{ github.ref }}
38+
run: python tools/ci_fetch_deps.py test ${{ github.sha }}
3939
- name: CircuitPython version
4040
run: |
4141
git describe --dirty --tags || git log --parents HEAD~4..
@@ -141,7 +141,7 @@ jobs:
141141
with:
142142
python-version: 3.8
143143
- name: Get CP deps
144-
run: python tools/ci_fetch_deps.py mpy-cross-mac ${{ github.ref }}
144+
run: python tools/ci_fetch_deps.py mpy-cross-mac ${{ github.sha }}
145145
- name: CircuitPython version
146146
run: |
147147
git describe --dirty --tags
@@ -197,7 +197,7 @@ jobs:
197197
submodules: false
198198
fetch-depth: 1
199199
- name: Get CP deps
200-
run: python tools/ci_fetch_deps.py docs ${{ github.ref }}
200+
run: python tools/ci_fetch_deps.py docs ${{ github.sha }}
201201
- name: CircuitPython version
202202
run: |
203203
git describe --dirty --tags
@@ -269,7 +269,7 @@ jobs:
269269
submodules: false
270270
fetch-depth: 1
271271
- name: Get CP deps
272-
run: python tools/ci_fetch_deps.py ${{ matrix.board }} ${{ github.ref }}
272+
run: python tools/ci_fetch_deps.py ${{ matrix.board }} ${{ github.sha }}
273273
- name: Install dependencies
274274
run: |
275275
sudo apt-get install -y gettext
@@ -321,7 +321,7 @@ jobs:
321321
submodules: false
322322
fetch-depth: 1
323323
- name: Get CP deps
324-
run: python tools/ci_fetch_deps.py ${{ matrix.board }} ${{ github.ref }}
324+
run: python tools/ci_fetch_deps.py ${{ matrix.board }} ${{ github.sha }}
325325
- name: Install dependencies
326326
run: |
327327
sudo apt-get install -y gettext
@@ -373,7 +373,7 @@ jobs:
373373
submodules: false
374374
fetch-depth: 1
375375
- name: Get CP deps
376-
run: python tools/ci_fetch_deps.py ${{ matrix.board }} ${{ github.ref }}
376+
run: python tools/ci_fetch_deps.py ${{ matrix.board }} ${{ github.sha }}
377377
- name: CircuitPython version
378378
run: git describe --dirty --tags
379379
- uses: actions/cache@v2
@@ -460,7 +460,7 @@ jobs:
460460
submodules: false
461461
fetch-depth: 1
462462
- name: Get CP deps
463-
run: python tools/ci_fetch_deps.py ${{ matrix.board }} ${{ github.ref }}
463+
run: python tools/ci_fetch_deps.py ${{ matrix.board }} ${{ github.sha }}
464464
- name: Install dependencies
465465
run: |
466466
sudo apt-get install -y gettext mtools

.github/workflows/create_website_pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
with:
2626
python-version: 3.8
2727
- name: Get CP deps
28-
run: python tools/ci_fetch_deps.py website ${{ github.ref }}
28+
run: python tools/ci_fetch_deps.py website ${{ github.sha }}
2929
- name: Install deps
3030
run: |
3131
pip install -r requirements-dev.txt

.github/workflows/ports_windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
submodules: false
7171
fetch-depth: 1
7272
- name: Get CP deps
73-
run: python tools/ci_fetch_deps.py windows ${{ github.ref }}
73+
run: python tools/ci_fetch_deps.py windows ${{ github.sha }}
7474
- name: CircuitPython version
7575
run: |
7676
git describe --dirty --tags

devices/ble_hci/common-hal/_bleio/__init__.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,6 @@ void common_hal_bleio_gc_collect(void) {
107107
}
108108

109109

110-
void bleio_background(void) {
110+
void bleio_hci_background(void) {
111111
bleio_adapter_background(&common_hal_bleio_adapter_obj);
112112
}

devices/ble_hci/common-hal/_bleio/__init__.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include "att.h"
3535
#include "hci.h"
3636

37-
void bleio_background(void);
37+
void bleio_hci_background(void);
3838
void bleio_reset(void);
3939

4040
typedef struct {

ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c

Lines changed: 63 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,33 @@
5454
#endif
5555

5656
static frequencyio_frequencyin_obj_t *active_frequencyins[TC_INST_NUM];
57-
volatile uint8_t reference_tc = 0xff;
57+
volatile uint8_t reference_tc;
5858
#ifdef SAM_D5X_E5X
5959
static uint8_t dpll_gclk;
60+
61+
#if !BOARD_HAS_CRYSTAL
62+
static uint8_t osculp32k_gclk;
63+
#endif
64+
6065
#endif
6166

62-
void frequencyin_emergency_cancel_capture(uint8_t index) {
67+
void frequencyin_reset(void) {
68+
for (uint8_t i = 0; i < TC_INST_NUM; i++) {
69+
active_frequencyins[i] = NULL;
70+
}
71+
72+
reference_tc = 0xff;
73+
#ifdef SAM_D5X_E5X
74+
dpll_gclk = 0xff;
75+
76+
#if !BOARD_HAS_CRYSTAL
77+
osculp32k_gclk = 0xff;
78+
#endif
79+
80+
#endif
81+
}
82+
83+
static void frequencyin_emergency_cancel_capture(uint8_t index) {
6384
frequencyio_frequencyin_obj_t* self = active_frequencyins[index];
6485

6586
NVIC_DisableIRQ(self->TC_IRQ);
@@ -93,7 +114,7 @@ void frequencyin_interrupt_handler(uint8_t index) {
93114

94115
uint64_t current_ns = common_hal_time_monotonic_ns();
95116

96-
for (uint8_t i = 0; i <= (TC_INST_NUM - 1); i++) {
117+
for (uint8_t i = 0; i < TC_INST_NUM; i++) {
97118
if (active_frequencyins[i] != NULL) {
98119
frequencyio_frequencyin_obj_t* self = active_frequencyins[i];
99120
Tc* tc = tc_insts[self->tc_index];
@@ -143,7 +164,7 @@ void frequencyin_interrupt_handler(uint8_t index) {
143164
ref_tc->COUNT16.INTFLAG.reg |= TC_INTFLAG_OVF;
144165
}
145166

146-
void frequencyin_reference_tc_init() {
167+
static void frequencyin_reference_tc_init(void) {
147168
if (reference_tc == 0xff) {
148169
return;
149170
}
@@ -154,9 +175,6 @@ void frequencyin_reference_tc_init() {
154175
// use the DPLL we setup so that the reference_tc and freqin_tc(s)
155176
// are using the same clock frequency.
156177
#ifdef SAM_D5X_E5X
157-
if (dpll_gclk == 0xff) {
158-
frequencyin_samd51_start_dpll();
159-
}
160178
set_timer_handler(true, reference_tc, TC_HANDLER_FREQUENCYIN);
161179
turn_on_clocks(true, reference_tc, dpll_gclk);
162180
#endif
@@ -178,15 +196,15 @@ void frequencyin_reference_tc_init() {
178196
#endif
179197
}
180198

181-
bool frequencyin_reference_tc_enabled() {
199+
static bool frequencyin_reference_tc_enabled(void) {
182200
if (reference_tc == 0xff) {
183201
return false;
184202
}
185203
Tc *tc = tc_insts[reference_tc];
186204
return tc->COUNT16.CTRLA.bit.ENABLE;
187205
}
188206

189-
void frequencyin_reference_tc_enable(bool enable) {
207+
static void frequencyin_reference_tc_enable(bool enable) {
190208
if (reference_tc == 0xff) {
191209
return;
192210
}
@@ -195,56 +213,69 @@ void frequencyin_reference_tc_enable(bool enable) {
195213
}
196214

197215
#ifdef SAM_D5X_E5X
198-
void frequencyin_samd51_start_dpll() {
216+
static bool frequencyin_samd51_start_dpll(void) {
199217
if (clock_get_enabled(0, GCLK_SOURCE_DPLL1)) {
200-
return;
218+
return true;
201219
}
202220

203-
uint8_t free_gclk = find_free_gclk(1);
204-
if (free_gclk == 0xff) {
205-
dpll_gclk = 0xff;
206-
return;
221+
dpll_gclk = find_free_gclk(1);
222+
if (dpll_gclk == 0xff) {
223+
return false;
207224
}
208225

209-
GCLK->PCHCTRL[OSCCTRL_GCLK_ID_FDPLL1].reg = GCLK_PCHCTRL_CHEN | GCLK_PCHCTRL_GEN(free_gclk);
210226
// TC4-7 can only have a max of 100MHz source
211227
// DPLL1 frequency equation with [X]OSC32K as source: 98.304MHz = 32768(2999 + 1 + 0/32)
212228
// Will also enable the Lock Bypass due to low-frequency sources causing DPLL unlocks
213229
// as outlined in the Errata (1.12.1)
214230
OSCCTRL->Dpll[1].DPLLRATIO.reg = OSCCTRL_DPLLRATIO_LDRFRAC(0) | OSCCTRL_DPLLRATIO_LDR(2999);
231+
215232
#if BOARD_HAS_CRYSTAL
216-
// we can use XOSC32K directly as the source
217-
OSC32KCTRL->XOSC32K.bit.EN32K = 1;
218-
OSCCTRL->Dpll[1].DPLLCTRLB.reg = OSCCTRL_DPLLCTRLB_REFCLK(1) | OSCCTRL_DPLLCTRLB_LBYPASS;
233+
// we can use XOSC32K directly as the source. It has already been initialized in clocks.c
234+
OSCCTRL->Dpll[1].DPLLCTRLB.reg =
235+
OSCCTRL_DPLLCTRLB_REFCLK(OSCCTRL_DPLLCTRLB_REFCLK_XOSC32_Val) | OSCCTRL_DPLLCTRLB_LBYPASS;
219236
#else
220-
// can't use OSCULP32K directly; need to setup a GCLK as a reference,
221-
// which must be done in samd/clocks.c to avoid waiting for sync
222-
return;
223-
//OSC32KCTRL->OSCULP32K.bit.EN32K = 1;
224-
//OSCCTRL->Dpll[1].DPLLCTRLB.reg = OSCCTRL_DPLLCTRLB_REFCLK(0);
237+
// We can't use OSCULP32K directly. Set up a GCLK controlled by it
238+
// Then use that GCLK as the reference oscillator for the DPLL.
239+
osculp32k_gclk = find_free_gclk(1);
240+
if (osculp32k_gclk == 0xff) {
241+
return false;
242+
}
243+
enable_clock_generator(osculp32k_gclk, GCLK_GENCTRL_SRC_OSCULP32K_Val, 1);
244+
GCLK->PCHCTRL[OSCCTRL_GCLK_ID_FDPLL1].reg = GCLK_PCHCTRL_CHEN | GCLK_PCHCTRL_GEN(OSCCTRL_GCLK_ID_FDPLL1);
245+
OSCCTRL->Dpll[1].DPLLCTRLB.reg =
246+
OSCCTRL_DPLLCTRLB_REFCLK(OSCCTRL_DPLLCTRLB_REFCLK_GCLK_Val) | OSCCTRL_DPLLCTRLB_LBYPASS;
225247
#endif
226-
OSCCTRL->Dpll[1].DPLLCTRLA.reg = OSCCTRL_DPLLCTRLA_ENABLE;
227248

249+
OSCCTRL->Dpll[1].DPLLCTRLA.reg = OSCCTRL_DPLLCTRLA_ENABLE;
228250
while (!(OSCCTRL->Dpll[1].DPLLSTATUS.bit.LOCK || OSCCTRL->Dpll[1].DPLLSTATUS.bit.CLKRDY)) {}
229-
enable_clock_generator(free_gclk, GCLK_GENCTRL_SRC_DPLL1_Val, 1);
230-
dpll_gclk = free_gclk;
251+
252+
enable_clock_generator(dpll_gclk, GCLK_GENCTRL_SRC_DPLL1_Val, 1);
253+
return true;
231254
}
232255

233-
void frequencyin_samd51_stop_dpll() {
256+
static void frequencyin_samd51_stop_dpll(void) {
234257
if (!clock_get_enabled(0, GCLK_SOURCE_DPLL1)) {
235258
return;
236259
}
237260

238-
disable_clock_generator(dpll_gclk);
261+
if (dpll_gclk != 0xff) {
262+
disable_clock_generator(dpll_gclk);
263+
dpll_gclk = 0xff;
264+
}
265+
266+
#if !BOARD_HAS_CRYSTAL
267+
if (osculp32k_gclk != 0xff) {
268+
disable_clock_generator(osculp32k_gclk);
269+
osculp32k_gclk = 0xff;
270+
}
271+
#endif
239272

240273
GCLK->PCHCTRL[OSCCTRL_GCLK_ID_FDPLL1].reg = 0;
241274
OSCCTRL->Dpll[1].DPLLCTRLA.reg = 0;
242275
OSCCTRL->Dpll[1].DPLLRATIO.reg = 0;
243276
OSCCTRL->Dpll[1].DPLLCTRLB.reg = 0;
244-
245277
while (OSCCTRL->Dpll[1].DPLLSYNCBUSY.bit.ENABLE) {
246278
}
247-
dpll_gclk = 0xff;
248279
}
249280
#endif
250281

@@ -421,7 +452,7 @@ void common_hal_frequencyio_frequencyin_deinit(frequencyio_frequencyin_obj_t* se
421452
self->pin = NO_PIN;
422453

423454
bool check_active = false;
424-
for (uint8_t i = 0; i <= (TC_INST_NUM - 1); i++) {
455+
for (uint8_t i = 0; i < TC_INST_NUM; i++) {
425456
if (active_frequencyins[i] != NULL) {
426457
check_active = true;
427458
}

ports/atmel-samd/common-hal/frequencyio/FrequencyIn.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,7 @@ typedef struct {
4646
} frequencyio_frequencyin_obj_t;
4747

4848
void frequencyin_interrupt_handler(uint8_t index);
49-
void frequencyin_emergency_cancel_capture(uint8_t index);
50-
void frequencyin_reference_tc_init(void);
51-
void frequencyin_reference_tc_enable(bool enable);
52-
bool frequencyin_reference_tc_enabled(void);
53-
#ifdef SAM_D5X_E5X
54-
void frequencyin_samd51_start_dpll(void);
55-
void frequencyin_samd51_stop_dpll(void);
56-
#endif
49+
void frequencyin_reset(void);
5750

5851

5952
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_FREQUENCYIO_FREQUENCYIN_H

ports/atmel-samd/supervisor/port.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@
7171
#include "common-hal/busio/__init__.h"
7272
#endif
7373

74+
#if CIRCUITPY_FREQUENCYIO
75+
#include "common-hal/frequencyio/FrequencyIn.h"
76+
#endif
77+
7478
#include "common-hal/microcontroller/Pin.h"
7579

7680
#if CIRCUITPY_PULSEIO
@@ -388,6 +392,10 @@ void reset_port(void) {
388392
i2sout_reset();
389393
#endif
390394

395+
#if CIRCUITPY_FREQUENCYIO
396+
frequencyin_reset();
397+
#endif
398+
391399
#if CIRCUITPY_TOUCHIO && CIRCUITPY_TOUCHIO_USE_NATIVE
392400
touchin_reset();
393401
#endif
@@ -399,7 +407,7 @@ void reset_port(void) {
399407
#if CIRCUITPY_PWMIO
400408
pwmout_reset();
401409
#endif
402-
#if CIRCUITPY_PWMIO || CIRCUITPY_AUDIOIO
410+
#if CIRCUITPY_PWMIO || CIRCUITPY_AUDIOIO || CIRCUITPY_FREQUENCYIO
403411
reset_timers();
404412
#endif
405413

ports/broadcom/qstrdefsport.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
// qstrs specific to this port, only needed if they aren't auto-generated
2828

29+
// Prevent uncrustify from modifying these lines.
30+
// *FORMAT-OFF*
31+
2932
// Entries for sys.path
3033
Q(/sd)
3134
Q(/sd/lib)

ports/espressif/boards/adafruit_feather_esp32s2_tft/board.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void board_init(void) {
8686

8787
common_hal_busio_spi_never_reset(spi);
8888

89-
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
89+
displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus;
9090
bus->base.type = &displayio_fourwire_type;
9191

9292
common_hal_displayio_fourwire_construct(
@@ -99,7 +99,7 @@ void board_init(void) {
9999
0, // polarity
100100
0 // phase
101101
);
102-
displayio_display_obj_t* display = &displays[0].display;
102+
displayio_display_obj_t *display = &displays[0].display;
103103
display->base.type = &displayio_display_type;
104104

105105
// workaround as board_init() is called before reset_port() in main.c

ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ void common_hal_audiopwmio_pwmaudioout_play(audiopwmio_pwmaudioout_obj_t *self,
207207
uint32_t tx_register = (uint32_t)&pwm_hw->slice[self->left_pwm.slice].cc;
208208
if (self->stereo) {
209209
// Shift the destination if we are outputting to both PWM channels.
210-
tx_register += self->left_pwm.channel * sizeof(uint16_t);
210+
tx_register += self->left_pwm.ab_channel * sizeof(uint16_t);
211211
}
212212

213213
self->pacing_timer = pacing_timer;

ports/raspberrypi/common-hal/busio/I2C.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,11 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
109109
// set up as GPIO by the bitbangio.I2C object.
110110
//
111111
// Sets pins to open drain, high, and input.
112+
//
113+
// Do not use the default supplied clock stretching timeout here.
114+
// It is too short for some devices. Use the busio timeout instead.
112115
shared_module_bitbangio_i2c_construct(&self->bitbangio_i2c, scl, sda,
113-
frequency, timeout);
116+
frequency, BUS_TIMEOUT_US);
114117

115118
self->baudrate = i2c_init(self->peripheral, frequency);
116119

0 commit comments

Comments
 (0)