diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index b98e0e2132..d9d5d6e17d 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-08-17 10:10-0400\n" +"POT-Creation-Date: 2020-08-18 11:19-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1334,7 +1334,7 @@ msgstr "" #: ports/stm/common-hal/pulseio/PulseOut.c msgid "" "Port does not accept pins or frequency. " -"Construct and pass a PWM Carrier instead" +"Construct and pass a PWMOut Carrier instead" msgstr "" #: shared-bindings/_bleio/Adapter.c diff --git a/ports/atmel-samd/common-hal/pulseio/PulseOut.c b/ports/atmel-samd/common-hal/pulseio/PulseOut.c index de2f7b8d2a..b53c8da2ba 100644 --- a/ports/atmel-samd/common-hal/pulseio/PulseOut.c +++ b/ports/atmel-samd/common-hal/pulseio/PulseOut.c @@ -102,7 +102,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, uint16_t duty_cycle) { if (!carrier || pin || frequency) { mp_raise_NotImplementedError(translate("Port does not accept pins or frequency. \ - Construct and pass a PWM Carrier instead")); + Construct and pass a PWMOut Carrier instead")); } if (refcount == 0) { diff --git a/ports/cxd56/common-hal/pulseio/PulseOut.c b/ports/cxd56/common-hal/pulseio/PulseOut.c index 2851a04658..08081020f3 100644 --- a/ports/cxd56/common-hal/pulseio/PulseOut.c +++ b/ports/cxd56/common-hal/pulseio/PulseOut.c @@ -65,7 +65,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, uint16_t duty_cycle) { if (!carrier || pin || frequency) { mp_raise_NotImplementedError(translate("Port does not accept pins or frequency. \ - Construct and pass a PWM Carrier instead")); + Construct and pass a PWMOut Carrier instead")); } if (pulse_fd < 0) { diff --git a/ports/esp32s2/common-hal/neopixel_write/__init__.c b/ports/esp32s2/common-hal/neopixel_write/__init__.c index 1fc976ec36..193d754f43 100644 --- a/ports/esp32s2/common-hal/neopixel_write/__init__.c +++ b/ports/esp32s2/common-hal/neopixel_write/__init__.c @@ -93,6 +93,9 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout // Reserve channel uint8_t number = digitalinout->pin->number; rmt_channel_t channel = esp32s2_peripherals_find_and_reserve_rmt(); + if (channel == RMT_CHANNEL_MAX) { + mp_raise_RuntimeError(translate("All timers in use")); + } // Configure Channel rmt_config_t config = RMT_DEFAULT_CONFIG_TX(number, channel); diff --git a/ports/esp32s2/common-hal/pulseio/PulseIn.c b/ports/esp32s2/common-hal/pulseio/PulseIn.c index d741628305..f7429ec12c 100644 --- a/ports/esp32s2/common-hal/pulseio/PulseIn.c +++ b/ports/esp32s2/common-hal/pulseio/PulseIn.c @@ -105,6 +105,9 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, const mcu // Find a free RMT Channel and configure it rmt_channel_t channel = esp32s2_peripherals_find_and_reserve_rmt(); + if (channel == RMT_CHANNEL_MAX) { + mp_raise_RuntimeError(translate("All timers in use")); + } rmt_config_t config = RMT_DEFAULT_CONFIG_RX(pin->number, channel); config.rx_config.filter_en = true; config.rx_config.idle_threshold = 30000; // 30*3=90ms idle required to register a sequence diff --git a/ports/esp32s2/common-hal/pulseio/PulseOut.c b/ports/esp32s2/common-hal/pulseio/PulseOut.c index 463443ef0c..a07ec39dc2 100644 --- a/ports/esp32s2/common-hal/pulseio/PulseOut.c +++ b/ports/esp32s2/common-hal/pulseio/PulseOut.c @@ -42,6 +42,9 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, } rmt_channel_t channel = esp32s2_peripherals_find_and_reserve_rmt(); + if (channel == RMT_CHANNEL_MAX) { + mp_raise_RuntimeError(translate("All timers in use")); + } // Configure Channel rmt_config_t config = RMT_DEFAULT_CONFIG_TX(pin->number, channel); @@ -82,5 +85,7 @@ void common_hal_pulseio_pulseout_send(pulseio_pulseout_obj_t* self, uint16_t* pu } rmt_write_items(self->channel, items, length, true); - rmt_wait_tx_done(self->channel, pdMS_TO_TICKS(100)); + while (rmt_wait_tx_done(self->channel, 0) != ESP_OK) { + RUN_BACKGROUND_TASKS(); + } } diff --git a/ports/esp32s2/peripherals/rmt.c b/ports/esp32s2/peripherals/rmt.c index 16605edf5e..b7629dbd5c 100644 --- a/ports/esp32s2/peripherals/rmt.c +++ b/ports/esp32s2/peripherals/rmt.c @@ -44,8 +44,8 @@ rmt_channel_t esp32s2_peripherals_find_and_reserve_rmt(void) { return i; } } - mp_raise_RuntimeError(translate("All timers in use")); - return false; + // Returning the max indicates a reservation failure. + return RMT_CHANNEL_MAX; } void esp32s2_peripherals_free_rmt(rmt_channel_t chan) { diff --git a/ports/nrf/common-hal/pulseio/PulseOut.c b/ports/nrf/common-hal/pulseio/PulseOut.c index 9f5efcfdc6..bdc5cfbef5 100644 --- a/ports/nrf/common-hal/pulseio/PulseOut.c +++ b/ports/nrf/common-hal/pulseio/PulseOut.c @@ -106,7 +106,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, uint16_t duty_cycle) { if (!carrier || pin || frequency) { mp_raise_NotImplementedError(translate("Port does not accept pins or frequency. \ - Construct and pass a PWM Carrier instead")); + Construct and pass a PWMOut Carrier instead")); } if (refcount == 0) { diff --git a/ports/stm/common-hal/pulseio/PulseOut.c b/ports/stm/common-hal/pulseio/PulseOut.c index 33311fd53d..eec1049dd2 100644 --- a/ports/stm/common-hal/pulseio/PulseOut.c +++ b/ports/stm/common-hal/pulseio/PulseOut.c @@ -119,7 +119,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, uint16_t duty_cycle) { if (!carrier || pin || frequency) { mp_raise_NotImplementedError(translate("Port does not accept pins or frequency. \ - Construct and pass a PWM Carrier instead")); + Construct and pass a PWMOut Carrier instead")); } // Add to active PulseOuts diff --git a/shared-bindings/pulseio/PulseOut.c b/shared-bindings/pulseio/PulseOut.c index 2adbc3cf6a..3fd722558e 100644 --- a/shared-bindings/pulseio/PulseOut.c +++ b/shared-bindings/pulseio/PulseOut.c @@ -71,11 +71,11 @@ STATIC mp_obj_t pulseio_pulseout_make_new(const mp_obj_type_t *type, size_t n_ar mp_obj_t carrier_obj = pos_args[0]; if (MP_OBJ_IS_TYPE(carrier_obj, &pulseio_pwmout_type)) { - // PWM Carrier + // Use a PWMOut Carrier mp_arg_check_num(n_args, kw_args, 1, 1, false); common_hal_pulseio_pulseout_construct(self, (pulseio_pwmout_obj_t *)MP_OBJ_TO_PTR(carrier_obj), NULL, 0, 0); } else { - // Pin and Frequency + // Use a Pin, frequency, and duty cycle enum { ARG_pin, ARG_frequency}; static const mp_arg_t allowed_args[] = { { MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ },