Skip to content

Commit b14672c

Browse files
committed
Reset the I2S DAC. Tweak exception behavior when heap not available
1 parent 7ea83dc commit b14672c

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

ports/raspberrypi/boards/adafruit_fruit_jam/board.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
#include "common-hal/microcontroller/Pin.h"
88
#include "hardware/gpio.h"
9+
#include "py/mphal.h"
910
#include "shared-bindings/usb_host/Port.h"
1011
#include "supervisor/board.h"
1112

1213
#include "common-hal/picodvi/__init__.h"
1314

1415
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
1516

17+
#define I2S_RESET_PIN_NUMBER 22
1618

1719
#if defined(DEFAULT_USB_HOST_5V_POWER)
1820
bool board_reset_pin_number(uint8_t pin_number) {
@@ -28,7 +30,7 @@ bool board_reset_pin_number(uint8_t pin_number) {
2830
return true;
2931
}
3032
// Set I2S out of reset.
31-
if (pin_number == 22) {
33+
if (pin_number == I2S_RESET_PIN_NUMBER) {
3234
gpio_put(pin_number, 1);
3335
gpio_set_dir(pin_number, GPIO_OUT);
3436
gpio_set_function(pin_number, GPIO_FUNC_SIO);
@@ -40,6 +42,13 @@ bool board_reset_pin_number(uint8_t pin_number) {
4042
#endif
4143

4244
void board_init(void) {
45+
// Reset the DAC to put it in a known state.
46+
gpio_put(I2S_RESET_PIN_NUMBER, 0);
47+
gpio_set_dir(I2S_RESET_PIN_NUMBER, GPIO_OUT);
48+
gpio_set_function(I2S_RESET_PIN_NUMBER, GPIO_FUNC_SIO);
49+
mp_hal_delay_us(1);
50+
board_reset_pin_number(I2S_RESET_PIN_NUMBER);
51+
4352
#if defined(DEFAULT_USB_HOST_DATA_PLUS)
4453
common_hal_usb_host_port_construct(DEFAULT_USB_HOST_DATA_PLUS, DEFAULT_USB_HOST_DATA_MINUS);
4554
#endif

py/objexcept.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,10 +539,14 @@ mp_obj_t mp_obj_new_exception_msg_vlist(const mp_obj_type_t *exc_type, mp_rom_er
539539
assert(MP_OBJ_TYPE_GET_SLOT_OR_NULL(exc_type, make_new) == mp_obj_exception_make_new);
540540

541541
// Try to allocate memory for the message
542-
mp_obj_str_t *o_str = m_new_obj_maybe(mp_obj_str_t);
542+
mp_obj_str_t *o_str = NULL;
543+
byte *o_str_buf = NULL;
543544
// CIRCUITPY-CHANGE: here and more below
544545
size_t o_str_alloc = decompress_length(fmt);
545-
byte *o_str_buf = m_new_maybe(byte, o_str_alloc);
546+
if (gc_alloc_possible()) {
547+
o_str = m_new_obj_maybe(mp_obj_str_t);
548+
o_str_buf = m_new_maybe(byte, o_str_alloc);
549+
}
546550

547551
bool used_emg_buf = false;
548552
#if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF

0 commit comments

Comments
 (0)