Style changes, reposition runtime errors

This commit is contained in:
Lucian Copeland 2020-08-18 11:42:06 -04:00
parent d0d6a951da
commit da75445cd5
10 changed files with 22 additions and 11 deletions

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \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" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -1334,7 +1334,7 @@ msgstr ""
#: ports/stm/common-hal/pulseio/PulseOut.c #: ports/stm/common-hal/pulseio/PulseOut.c
msgid "" msgid ""
"Port does not accept pins or frequency. " "Port does not accept pins or frequency. "
"Construct and pass a PWM Carrier instead" "Construct and pass a PWMOut Carrier instead"
msgstr "" msgstr ""
#: shared-bindings/_bleio/Adapter.c #: shared-bindings/_bleio/Adapter.c

View File

@ -102,7 +102,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self,
uint16_t duty_cycle) { uint16_t duty_cycle) {
if (!carrier || pin || frequency) { if (!carrier || pin || frequency) {
mp_raise_NotImplementedError(translate("Port does not accept pins or 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) { if (refcount == 0) {

View File

@ -65,7 +65,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self,
uint16_t duty_cycle) { uint16_t duty_cycle) {
if (!carrier || pin || frequency) { if (!carrier || pin || frequency) {
mp_raise_NotImplementedError(translate("Port does not accept pins or 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) { if (pulse_fd < 0) {

View File

@ -93,6 +93,9 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout
// Reserve channel // Reserve channel
uint8_t number = digitalinout->pin->number; uint8_t number = digitalinout->pin->number;
rmt_channel_t channel = esp32s2_peripherals_find_and_reserve_rmt(); 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 // Configure Channel
rmt_config_t config = RMT_DEFAULT_CONFIG_TX(number, channel); rmt_config_t config = RMT_DEFAULT_CONFIG_TX(number, channel);

View File

@ -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 // Find a free RMT Channel and configure it
rmt_channel_t channel = esp32s2_peripherals_find_and_reserve_rmt(); 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); rmt_config_t config = RMT_DEFAULT_CONFIG_RX(pin->number, channel);
config.rx_config.filter_en = true; config.rx_config.filter_en = true;
config.rx_config.idle_threshold = 30000; // 30*3=90ms idle required to register a sequence config.rx_config.idle_threshold = 30000; // 30*3=90ms idle required to register a sequence

View File

@ -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(); 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 // Configure Channel
rmt_config_t config = RMT_DEFAULT_CONFIG_TX(pin->number, 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_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();
}
} }

View File

@ -44,8 +44,8 @@ rmt_channel_t esp32s2_peripherals_find_and_reserve_rmt(void) {
return i; return i;
} }
} }
mp_raise_RuntimeError(translate("All timers in use")); // Returning the max indicates a reservation failure.
return false; return RMT_CHANNEL_MAX;
} }
void esp32s2_peripherals_free_rmt(rmt_channel_t chan) { void esp32s2_peripherals_free_rmt(rmt_channel_t chan) {

View File

@ -106,7 +106,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self,
uint16_t duty_cycle) { uint16_t duty_cycle) {
if (!carrier || pin || frequency) { if (!carrier || pin || frequency) {
mp_raise_NotImplementedError(translate("Port does not accept pins or 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) { if (refcount == 0) {

View File

@ -119,7 +119,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self,
uint16_t duty_cycle) { uint16_t duty_cycle) {
if (!carrier || pin || frequency) { if (!carrier || pin || frequency) {
mp_raise_NotImplementedError(translate("Port does not accept pins or 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 // Add to active PulseOuts

View File

@ -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]; mp_obj_t carrier_obj = pos_args[0];
if (MP_OBJ_IS_TYPE(carrier_obj, &pulseio_pwmout_type)) { 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); 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); common_hal_pulseio_pulseout_construct(self, (pulseio_pwmout_obj_t *)MP_OBJ_TO_PTR(carrier_obj), NULL, 0, 0);
} else { } else {
// Pin and Frequency // Use a Pin, frequency, and duty cycle
enum { ARG_pin, ARG_frequency}; enum { ARG_pin, ARG_frequency};
static const mp_arg_t allowed_args[] = { static const mp_arg_t allowed_args[] = {
{ MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ },