From ea9200a042e4a0c5fe0e773498d7697a5ea1c07f Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sat, 16 Feb 2019 19:26:24 -0600 Subject: [PATCH 01/13] starting again; initial addition of 'frequencyio.FrequencyIn' --- .../common-hal/frequencyio/FrequencyIn.c | 545 ++++++++++++++++++ .../common-hal/frequencyio/FrequencyIn.h | 60 ++ shared-bindings/frequencyio/FrequencyIn.c | 238 ++++++++ shared-bindings/frequencyio/FrequencyIn.h | 46 ++ shared-bindings/frequencyio/__init__.c | 88 +++ 5 files changed, 977 insertions(+) create mode 100644 ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c create mode 100644 ports/atmel-samd/common-hal/frequencyio/FrequencyIn.h create mode 100644 shared-bindings/frequencyio/FrequencyIn.c create mode 100644 shared-bindings/frequencyio/FrequencyIn.h create mode 100644 shared-bindings/frequencyio/__init__.c diff --git a/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c b/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c new file mode 100644 index 0000000000..e499684288 --- /dev/null +++ b/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c @@ -0,0 +1,545 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Michael Schroeder + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "hal/include/hal_gpio.h" +#include "atmel_start_pins.h" +#include "supervisor/shared/translate.h" + +#include "mpconfigport.h" +#include "py/runtime.h" +#include "timer_handler.h" +#include "background.h" + +#include "samd/clocks.h" +#include "samd/timers.h" +#include "samd/events.h" +#include "samd/pins.h" +#include "samd/external_interrupts.h" + +#include "shared-bindings/frequencyio/FrequencyIn.h" +#include "peripheral_clk_config.h" +#include "hpl_gclk_config.h" + +#include "tick.h" + +#ifdef SAMD21 +#include "hpl/gclk/hpl_gclk_base.h" +#endif + +static frequencyio_frequencyin_obj_t *active_frequencyins[TC_INST_NUM]; +volatile uint8_t reference_tc = 0xff; +#ifdef SAMD51 +static uint8_t dpll_gclk; +#endif + +void frequencyin_emergency_cancel_capture(uint8_t index) { + frequencyio_frequencyin_obj_t* self = active_frequencyins[index]; + + NVIC_DisableIRQ(self->TC_IRQ); + NVIC_ClearPendingIRQ(self->TC_IRQ); + #ifdef SAMD21 + NVIC_DisableIRQ(EIC_IRQn); + NVIC_ClearPendingIRQ(EIC_IRQn); + #endif + #ifdef SAMD51 + NVIC_DisableIRQ(EIC_0_IRQn + self->channel); + NVIC_ClearPendingIRQ(EIC_0_IRQn + self->channel); + #endif + + common_hal_frequencyio_frequencyin_pause(self); // pause any further captures + + NVIC_EnableIRQ(self->TC_IRQ); + #ifdef SAMD21 + NVIC_EnableIRQ(EIC_IRQn); + #endif + #ifdef SAMD51 + NVIC_EnableIRQ(EIC_0_IRQn + self->channel); + #endif + mp_raise_RuntimeError(translate("Frequency captured is above capability. Capture Paused.")); +} + +void frequencyin_interrupt_handler(uint8_t index) { + Tc* ref_tc = tc_insts[reference_tc]; + + if (!ref_tc->COUNT16.INTFLAG.bit.OVF) return; // false trigger + + uint32_t current_us; + uint64_t current_ms; + current_tick(¤t_ms, ¤t_us); + + for (uint8_t i = 0; i <= (TC_INST_NUM - 1); i++) { + if (active_frequencyins[i] != NULL) { + frequencyio_frequencyin_obj_t* self = active_frequencyins[i]; + Tc* tc = tc_insts[self->tc_index]; + + uint32_t mask = 1 << self->channel; + if ((EIC->INTFLAG.reg & mask) == mask) { + // Make sure capture_period has elapsed before we + // record a new event count. + if (current_ms - self->last_ms >= self->capture_period) { + float new_factor = self->last_us + (1000 - current_us); + self->factor = (current_ms - self->last_ms) + (new_factor / 1000); + self->last_ms = current_ms; + self->last_us = current_us; + + #ifdef SAMD51 + tc->COUNT16.CTRLBSET.bit.CMD = TC_CTRLBSET_CMD_READSYNC_Val; + while ((tc->COUNT16.SYNCBUSY.bit.COUNT == 1) || + (tc->COUNT16.CTRLBSET.bit.CMD == TC_CTRLBSET_CMD_READSYNC_Val)) { + } + #endif + + uint16_t new_freq = tc->COUNT16.COUNT.reg; + if ((tc->COUNT16.INTFLAG.reg & TC_INTFLAG_OVF) == 1) { + new_freq += 65535; + tc->COUNT16.INTFLAG.reg |= TC_INTFLAG_OVF; + } + self->frequency = new_freq; + + #ifdef SAMD51 + tc->COUNT16.CTRLBSET.bit.CMD = TC_CTRLBSET_CMD_RETRIGGER_Val; + while ((tc->COUNT16.SYNCBUSY.bit.COUNT == 1) || + (tc->COUNT16.CTRLBSET.bit.CMD == TC_CTRLBSET_CMD_RETRIGGER_Val)) { + } + #endif + } + EIC->INTFLAG.reg |= mask; + } + + // Check if we've reached the upper limit of detection + if (!background_tasks_ok() || self->errored_too_fast) { + self->errored_too_fast = true; + frequencyin_emergency_cancel_capture(i); + } + } + } + ref_tc->COUNT16.INTFLAG.reg |= TC_INTFLAG_OVF; +} + +void frequencyin_reference_tc_init() { + if (reference_tc == 0xff) { + return; + } + #ifdef SAMD21 + turn_on_clocks(true, reference_tc, 0, TC_HANDLER_FREQUENCYIN); + #endif + // use the DPLL we setup so that the reference_tc and freqin_tc(s) + // are using the same clock frequency. + #ifdef SAMD51 + if (dpll_gclk == 0xff) { + frequencyin_samd51_start_dpll(); + } + turn_on_clocks(true, reference_tc, dpll_gclk, TC_HANDLER_FREQUENCYIN); + #endif + + Tc *tc = tc_insts[reference_tc]; + tc_set_enable(tc, false); + tc_reset(tc); + + #ifdef SAMD21 + tc->COUNT16.CTRLA.reg = TC_CTRLA_MODE_COUNT16 | TC_CTRLA_PRESCALER_DIV1; + tc->COUNT16.INTENSET.bit.OVF = 1; + NVIC_EnableIRQ(TC3_IRQn + reference_tc); + #endif + #ifdef SAMD51 + tc->COUNT16.CTRLA.reg = TC_CTRLA_MODE_COUNT16 | + TC_CTRLA_PRESCALER_DIV1; + tc->COUNT16.INTENSET.bit.OVF = 1; + NVIC_EnableIRQ(TC0_IRQn + reference_tc); + #endif +} + +bool frequencyin_reference_tc_enabled() { + if (reference_tc == 0xff) { + return false; + } + Tc *tc = tc_insts[reference_tc]; + return tc->COUNT16.CTRLA.bit.ENABLE; +} + +void frequencyin_reference_tc_enable(bool enable) { + if (reference_tc == 0xff) { + return; + } + Tc *tc = tc_insts[reference_tc]; + tc_set_enable(tc, enable); +} + +#ifdef SAMD51 +void frequencyin_samd51_start_dpll() { + if (clock_get_enabled(0, GCLK_SOURCE_DPLL1)) { + return; + } + + uint8_t free_gclk = find_free_gclk(1); + if (free_gclk == 0xff) { + dpll_gclk = 0xff; + return; + } + + GCLK->PCHCTRL[OSCCTRL_GCLK_ID_FDPLL1].reg = GCLK_PCHCTRL_CHEN | GCLK_PCHCTRL_GEN(free_gclk); + // TC4-7 can only have a max of 100MHz source + // DPLL1 frequency equation with [X]OSC32K as source: 98.304MHz = 32768(2999 + 1 + 0/32) + // Will also enable the Lock Bypass due to low-frequency sources causing DPLL unlocks + // as outlined in the Errata (1.12.1) + OSCCTRL->Dpll[1].DPLLRATIO.reg = OSCCTRL_DPLLRATIO_LDRFRAC(0) | OSCCTRL_DPLLRATIO_LDR(2999); + if (board_has_crystal()) { // we can use XOSC32K directly as the source + OSC32KCTRL->XOSC32K.bit.EN32K = 1; + OSCCTRL->Dpll[1].DPLLCTRLB.reg = OSCCTRL_DPLLCTRLB_REFCLK(1) | + OSCCTRL_DPLLCTRLB_LBYPASS; + } else { + // can't use OSCULP32K directly; need to setup a GCLK as a reference, + // which must be done in samd/clocks.c to avoid waiting for sync + return; + //OSC32KCTRL->OSCULP32K.bit.EN32K = 1; + //OSCCTRL->Dpll[1].DPLLCTRLB.reg = OSCCTRL_DPLLCTRLB_REFCLK(0); + } + OSCCTRL->Dpll[1].DPLLCTRLA.reg = OSCCTRL_DPLLCTRLA_ENABLE; + + while (!(OSCCTRL->Dpll[1].DPLLSTATUS.bit.LOCK || OSCCTRL->Dpll[1].DPLLSTATUS.bit.CLKRDY)) {} + enable_clock_generator(free_gclk, GCLK_GENCTRL_SRC_DPLL1_Val, 1); + dpll_gclk = free_gclk; +} + +void frequencyin_samd51_stop_dpll() { + if (!clock_get_enabled(0, GCLK_SOURCE_DPLL1)) { + return; + } + + disable_clock_generator(dpll_gclk); + + GCLK->PCHCTRL[OSCCTRL_GCLK_ID_FDPLL1].reg = 0; + OSCCTRL->Dpll[1].DPLLCTRLA.reg = 0; + OSCCTRL->Dpll[1].DPLLRATIO.reg = 0; + OSCCTRL->Dpll[1].DPLLCTRLB.reg = 0; + + while (OSCCTRL->Dpll[1].DPLLSYNCBUSY.bit.ENABLE) { + } + dpll_gclk = 0xff; +} +#endif + +void common_hal_frequencyio_frequencyin_construct(frequencyio_frequencyin_obj_t* self, const mcu_pin_obj_t* pin, const uint16_t capture_period) { + + if (!pin->has_extint) { + mp_raise_RuntimeError(translate("No hardware support on pin")); + } + if ((capture_period == 0) || (capture_period > 500)) { + // TODO: find a sutiable message that is already translated + mp_raise_ValueError(translate("Invalid something")); + } + uint32_t mask = 1 << pin->extint_channel; + if (eic_get_enable() == 1 && + #ifdef SAMD21 + ((EIC->INTENSET.vec.EXTINT & mask) != 0 || (EIC->EVCTRL.vec.EXTINTEO & mask) != 0)) { + #endif + #ifdef SAMD51 + ((EIC->INTENSET.bit.EXTINT & mask) != 0 || (EIC->EVCTRL.bit.EXTINTEO & mask) != 0)) { + #endif + mp_raise_RuntimeError(translate("EXTINT channel already in use")); + } + + uint8_t timer_index = find_free_timer(); + if (timer_index == 0xff) { + mp_raise_RuntimeError(translate("All timers in use")); + } + Tc *tc = tc_insts[timer_index]; + + self->tc_index = timer_index; + self->pin = pin->number; + self->channel = pin->extint_channel; + self->errored_too_fast = false; + self->last_ms = 0; + self->last_us = 1000; + self->capture_period = capture_period; + #ifdef SAMD21 + self->TC_IRQ = TC3_IRQn + timer_index; + #endif + #ifdef SAMD51 + self->TC_IRQ = TC0_IRQn + timer_index; + #endif + + active_frequencyins[timer_index] = self; + + // SAMD21: We use GCLK0 generated from DFLL running at 48mhz + // SAMD51: We use a GCLK generated from DPLL1 running at <100mhz + #ifdef SAMD21 + turn_on_clocks(true, timer_index, 0, TC_HANDLER_NO_INTERRUPT); + #endif + #ifdef SAMD51 + frequencyin_samd51_start_dpll(); + if (dpll_gclk == 0xff && !clock_get_enabled(0, GCLK_SOURCE_DPLL1)) { + common_hal_frequencyio_frequencyin_deinit(self); + mp_raise_RuntimeError(translate("No available clocks")); + } + turn_on_clocks(true, timer_index, dpll_gclk, TC_HANDLER_NO_INTERRUPT); + #endif + + // Ensure EIC is on + if (eic_get_enable() == 0) { + turn_on_external_interrupt_controller(); // enables EIC, so disable it after + } + eic_set_enable(false); + + uint8_t sense_setting = EIC_CONFIG_SENSE0_HIGH_Val; + uint8_t config_index = self->channel / 8; + uint8_t position = (self->channel % 8) * 4; + uint32_t masked_value = EIC->CONFIG[config_index].reg & ~(0xf << position); + EIC->CONFIG[config_index].reg = masked_value | (sense_setting << position); + + #ifdef SAMD21 + masked_value = EIC->EVCTRL.vec.EXTINTEO; + EIC->EVCTRL.vec.EXTINTEO = masked_value | (1 << self->channel); + #endif + #ifdef SAMD51 + masked_value = EIC->EVCTRL.bit.EXTINTEO; + EIC->EVCTRL.bit.EXTINTEO = masked_value | (1 << self->channel); + EIC->ASYNCH.bit.ASYNCH = 1; + #endif + + turn_on_cpu_interrupt(self->channel); + + eic_set_enable(true); + + // Turn on EVSYS + turn_on_event_system(); + uint8_t evsys_channel = find_async_event_channel(); + #ifdef SAMD21 + connect_event_user_to_channel((EVSYS_ID_USER_TC3_EVU + timer_index), evsys_channel); + #endif + #ifdef SAMD51 + connect_event_user_to_channel((EVSYS_ID_USER_TC0_EVU + timer_index), evsys_channel); + #endif + init_async_event_channel(evsys_channel, (EVSYS_ID_GEN_EIC_EXTINT_0 + self->channel)); + self->event_channel = evsys_channel; + + tc_set_enable(tc, false); + tc_reset(tc); + #ifdef SAMD21 + tc->COUNT16.CTRLA.reg = TC_CTRLA_MODE_COUNT16 | + TC_CTRLA_PRESCALER_DIV1; + tc->COUNT16.EVCTRL.bit.TCEI = 1; + tc->COUNT16.EVCTRL.bit.EVACT = TC_EVCTRL_EVACT_COUNT_Val; + #endif + + #ifdef SAMD51 + tc->COUNT16.EVCTRL.reg = TC_EVCTRL_EVACT(TC_EVCTRL_EVACT_COUNT_Val) | TC_EVCTRL_TCEI; + tc->COUNT16.CTRLA.reg = TC_CTRLA_MODE_COUNT16 | + TC_CTRLA_PRESCALER_DIV1; + #endif + + NVIC_EnableIRQ(self->TC_IRQ); + + gpio_set_pin_function(pin->number, GPIO_PIN_FUNCTION_A); + + tc_set_enable(tc, true); + + // setup reference TC if not already + if (reference_tc == 0xff) { + reference_tc = find_free_timer(); + if (reference_tc == 0xff) { + common_hal_frequencyio_frequencyin_deinit(self); + mp_raise_RuntimeError(translate("All timers in use")); + } + frequencyin_reference_tc_init(); + } + if (!frequencyin_reference_tc_enabled()) { + frequencyin_reference_tc_enable(true); + } +} + +bool common_hal_frequencyio_frequencyin_deinited(frequencyio_frequencyin_obj_t* self) { + return self->pin == NO_PIN; +} + +void common_hal_frequencyio_frequencyin_deinit(frequencyio_frequencyin_obj_t* self) { + if (common_hal_frequencyio_frequencyin_deinited(self)) { + return; + } + reset_pin(self->pin); + + // turn off EIC & EVSYS utilized by this TC + disable_event_channel(self->event_channel); + eic_set_enable(false); + #ifdef SAMD21 + disable_event_user(EVSYS_ID_USER_TC3_EVU + self->tc_index); + uint32_t masked_value = EIC->EVCTRL.vec.EXTINTEO; + EIC->EVCTRL.vec.EXTINTEO = masked_value ^ (1 << self->channel); + #endif + #ifdef SAMD51 + disable_event_user(EVSYS_ID_USER_TC0_EVU + self->tc_index); + uint32_t masked_value = EIC->EVCTRL.bit.EXTINTEO; + EIC->EVCTRL.bit.EXTINTEO = masked_value ^ (1 << self->channel); + NVIC_DisableIRQ(EIC_0_IRQn + self->channel); + NVIC_ClearPendingIRQ(EIC_0_IRQn + self->channel); + #endif + eic_set_enable(true); + // check if any other objects are using the EIC; if not, turn it off + if (EIC->EVCTRL.reg == 0 && EIC->INTENSET.reg == 0) { + eic_reset(); + turn_off_external_interrupt_controller(); + } + + // turn off the TC we were using + Tc *tc = tc_insts[self->tc_index]; + tc_set_enable(tc, false); + tc_reset(tc); + NVIC_DisableIRQ(self->TC_IRQ); + NVIC_ClearPendingIRQ(self->TC_IRQ); + + active_frequencyins[self->tc_index] = NULL; + self->tc_index = 0xff; + self->pin = NO_PIN; + + bool check_active = false; + for (uint8_t i = 0; i <= (TC_INST_NUM - 1); i++) { + if (active_frequencyins[i] != NULL) { + check_active = true; + } + } + if (!check_active) { + frequencyin_reference_tc_enable(false); + reference_tc = 0xff; + #ifdef SAMD51 + frequencyin_samd51_stop_dpll(); + #endif + } +} + +uint32_t common_hal_frequencyio_frequencyin_get_item(frequencyio_frequencyin_obj_t* self) { + NVIC_DisableIRQ(self->TC_IRQ); + #ifdef SAMD21 + NVIC_DisableIRQ(EIC_IRQn); + #endif + #ifdef SAMD51 + NVIC_DisableIRQ(EIC_0_IRQn + self->channel); + #endif + + // adjust for actual capture period vs base `capture_period` + float frequency_adjustment = 0.0; + if (self->factor > self->capture_period) { + float time_each_event = self->factor / self->frequency; // get the time for each event during actual period + float capture_diff = self->factor - self->capture_period; // get the difference of actual and base periods + // we only need to adjust if the capture_diff can contain 1 or more events + // if so, we add how many events could have occured during the diff time + if (time_each_event > capture_diff) { + frequency_adjustment = capture_diff / time_each_event; + } + } + + float value = 1000 / (self->capture_period / (self->frequency + frequency_adjustment)); + + NVIC_ClearPendingIRQ(self->TC_IRQ); + NVIC_EnableIRQ(self->TC_IRQ); + #ifdef SAMD21 + NVIC_ClearPendingIRQ(EIC_IRQn); + NVIC_EnableIRQ(EIC_IRQn); + #endif + #ifdef SAMD51 + NVIC_ClearPendingIRQ(EIC_0_IRQn + self->channel); + NVIC_EnableIRQ(EIC_0_IRQn + self->channel); + #endif + + return value; +} + +void common_hal_frequencyio_frequencyin_pause(frequencyio_frequencyin_obj_t* self) { + Tc *tc = tc_insts[self->tc_index]; + if (!tc->COUNT16.EVCTRL.bit.TCEI) { + return; + } + tc->COUNT16.EVCTRL.bit.TCEI = 0; + + #ifdef SAMD21 + uint32_t masked_value = EIC->EVCTRL.vec.EXTINTEO; + EIC->EVCTRL.vec.EXTINTEO = masked_value | (0 << self->channel); + #endif + #ifdef SAMD51 + uint32_t masked_value = EIC->EVCTRL.bit.EXTINTEO; + EIC->EVCTRL.bit.EXTINTEO = masked_value | (0 << self->channel); + #endif + return; +} + +void common_hal_frequencyio_frequencyin_resume(frequencyio_frequencyin_obj_t* self) { + Tc *tc = tc_insts[self->tc_index]; + if (tc->COUNT16.EVCTRL.bit.TCEI) { + return; + } + tc->COUNT16.EVCTRL.bit.TCEI = 1; + + #ifdef SAMD21 + uint32_t masked_value = EIC->EVCTRL.vec.EXTINTEO; + EIC->EVCTRL.vec.EXTINTEO = masked_value | (1 << self->channel); + #endif + #ifdef SAMD51 + uint32_t masked_value = EIC->EVCTRL.bit.EXTINTEO; + EIC->EVCTRL.bit.EXTINTEO = masked_value | (1 << self->channel); + #endif + self->errored_too_fast = false; + return; +} + +void common_hal_frequencyio_frequencyin_clear(frequencyio_frequencyin_obj_t* self) { + NVIC_DisableIRQ(self->TC_IRQ); + #ifdef SAMD21 + NVIC_DisableIRQ(EIC_IRQn); + #endif + #ifdef SAMD51 + NVIC_DisableIRQ(EIC_0_IRQn + self->channel); + #endif + + self->frequency = 0; + + NVIC_ClearPendingIRQ(self->TC_IRQ); + NVIC_EnableIRQ(self->TC_IRQ); + #ifdef SAMD21 + NVIC_ClearPendingIRQ(EIC_IRQn); + NVIC_EnableIRQ(EIC_IRQn); + #endif + #ifdef SAMD51 + NVIC_ClearPendingIRQ(EIC_0_IRQn + self->channel); + NVIC_EnableIRQ(EIC_0_IRQn + self->channel); + #endif + return; +} + +uint16_t common_hal_frequencyio_frequencyin_get_capture_period(frequencyio_frequencyin_obj_t *self) { + return self->capture_period; +} + +void common_hal_frequencyio_frequencyin_set_capture_period(frequencyio_frequencyin_obj_t *self, uint16_t capture_period) { + if ((capture_period == 0) || (capture_period > 500)) { + // TODO: find a sutiable message that is already translated + mp_raise_ValueError(translate("Invalid something")); + } + + self->capture_period = capture_period; + + common_hal_frequencyio_frequencyin_clear(self); +} diff --git a/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.h b/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.h new file mode 100644 index 0000000000..abd63cc86d --- /dev/null +++ b/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.h @@ -0,0 +1,60 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Michael Schroeder + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_FREQUENCYIO_FREQUENCYIN_H +#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_FREQUENCYIO_FREQUENCYIN_H + +#include "common-hal/microcontroller/Pin.h" + +#include "py/obj.h" + +typedef struct { + mp_obj_base_t base; + uint8_t tc_index; + uint8_t pin; + uint8_t channel; + uint8_t event_channel; + uint32_t frequency; + volatile uint64_t last_ms; + volatile uint32_t last_us; + float factor; + uint32_t capture_period; + uint8_t TC_IRQ; + volatile bool errored_too_fast; +} frequencyio_frequencyin_obj_t; + +void frequencyin_interrupt_handler(uint8_t index); +void frequencyin_emergency_cancel_capture(uint8_t index); +void frequencyin_reference_tc_init(void); +void frequencyin_reference_tc_enable(bool enable); +bool frequencyin_reference_tc_enabled(void); +#ifdef SAMD51 +void frequencyin_samd51_start_dpll(void); +void frequencyin_samd51_stop_dpll(void); +#endif + + +#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_FREQUENCYIO_FREQUENCYIN_H diff --git a/shared-bindings/frequencyio/FrequencyIn.c b/shared-bindings/frequencyio/FrequencyIn.c new file mode 100644 index 0000000000..0e666d718e --- /dev/null +++ b/shared-bindings/frequencyio/FrequencyIn.c @@ -0,0 +1,238 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Michael Schroeder + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "lib/utils/context_manager_helpers.h" +#include "py/objproperty.h" +#include "py/runtime.h" +#include "py/runtime0.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/frequencyio/FrequencyIn.h" +#include "shared-bindings/util.h" +#include "supervisor/shared/translate.h" + +//| .. currentmodule:: frequencyio +//| +//| :class:`FrequencyIn` -- Read a frequency signal +//| ======================================================== +//| +//| FrequencyIn is used to measure the frequency, in hertz, of a digital signal +//| on an incoming pin. Accuracy has shown to be within 1kHz, if not better. +//| Current maximum detectable frequency is ~512kHz. +//| It will not determine pulse width (use ``PulseIn``). +//| +//| .. class:: FrequencyIn(pin, capture_period=10) +//| +//| Create a FrequencyIn object associated with the given pin. +//| +//| :param ~microcontroller.Pin pin: Pin to read frequency from. +//| :param int capture_period: Keyword argument to set the measurement period, in +//| milliseconds. Default is 10ms; maximum is 500ms. +//| +//| Read the incoming frequency from a pin:: +//| +//| import frequencyio +//| import board +//| +//| frequency = frequencyio.FrequencyIn(board.D11) +//| +//| # Loop while printing the detected frequency +//| while True: +//| print(frequency.value) +//| +//| # Optional clear() will reset the value +//| # to zero. Without this, if the incoming +//| # signal stops, the last reading will remain +//| # as the value. +//| frequency.clear() +//| +STATIC mp_obj_t frequencyio_frequencyin_make_new(const mp_obj_type_t *type, size_t n_args, + size_t n_kw, const mp_obj_t *pos_args) { + mp_arg_check_num(n_args, n_kw, 1, 2, true); + + frequencyio_frequencyin_obj_t *self = m_new_obj(frequencyio_frequencyin_obj_t); + self->base.type = &frequencyio_frequencyin_type; + mp_map_t kw_args; + mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args); + enum { ARG_pin, ARG_capture_period }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_capture_period, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 10} }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + assert_pin(args[ARG_pin].u_obj, false); + mcu_pin_obj_t* pin = MP_OBJ_TO_PTR(args[ARG_pin].u_obj); + assert_pin_free(pin); + + const uint16_t capture_period = args[ARG_capture_period].u_int; + + common_hal_frequencyio_frequencyin_construct(self, pin, capture_period); + + return MP_OBJ_FROM_PTR(self); +} + +//| .. method:: deinit() +//| +//| Deinitialises the FrequencyIn and releases any hardware resources for reuse. +//| +STATIC mp_obj_t frequencyio_frequencyin_deinit(mp_obj_t self_in) { + frequencyio_frequencyin_obj_t *self = MP_OBJ_TO_PTR(self_in); + common_hal_frequencyio_frequencyin_deinit(self); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(frequencyio_frequencyin_deinit_obj, frequencyio_frequencyin_deinit); + +//| .. method:: __enter__() +//| +//| No-op used by Context Managers. +//| +// Provided by context manager helper. + +//| .. method:: __exit__() +//| +//| Automatically deinitializes the hardware when exiting a context. See +//| :ref:`lifetime-and-contextmanagers` for more info. +//| +STATIC mp_obj_t frequencyio_frequencyin_obj___exit__(size_t n_args, const mp_obj_t *args) { + (void)n_args; + common_hal_frequencyio_frequencyin_deinit(args[0]); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(frequencyio_frequencyin___exit___obj, 4, 4, frequencyio_frequencyin_obj___exit__); + +//| .. method:: pause() +//| +//| Pause frequency capture. +//| +STATIC mp_obj_t frequencyio_frequencyin_obj_pause(mp_obj_t self_in) { + frequencyio_frequencyin_obj_t *self = MP_OBJ_TO_PTR(self_in); + raise_error_if_deinited(common_hal_frequencyio_frequencyin_deinited(self)); + + common_hal_frequencyio_frequencyin_pause(self); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(frequencyio_frequencyin_pause_obj, frequencyio_frequencyin_obj_pause); + +//| .. method:: resume() +//| +//| Resumes frequency capture. +//| +STATIC mp_obj_t frequencyio_frequencyin_obj_resume(mp_obj_t self_in) { + frequencyio_frequencyin_obj_t *self = MP_OBJ_TO_PTR(self_in); + raise_error_if_deinited(common_hal_frequencyio_frequencyin_deinited(self)); + + common_hal_frequencyio_frequencyin_resume(self); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(frequencyio_frequencyin_resume_obj, frequencyio_frequencyin_obj_resume); + +//| .. method:: clear() +//| +//| Clears the last detected frequency capture value. +//| + +STATIC mp_obj_t frequencyio_frequencyin_obj_clear(mp_obj_t self_in) { + frequencyio_frequencyin_obj_t *self = MP_OBJ_TO_PTR(self_in); + raise_error_if_deinited(common_hal_frequencyio_frequencyin_deinited(self)); + + common_hal_frequencyio_frequencyin_clear(self); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(frequencyio_frequencyin_clear_obj, frequencyio_frequencyin_obj_clear); + +//| .. attribute:: capture_period +//| +//| The capture measurement period. +//| +//| .. note:: When setting a new ``capture_period``, all previous capture information is +//| cleared with a call to ``clear()``. +//| +STATIC mp_obj_t frequencyio_frequencyin_obj_get_capture_period(mp_obj_t self_in) { + frequencyio_frequencyin_obj_t *self = MP_OBJ_TO_PTR(self_in); + raise_error_if_deinited(common_hal_frequencyio_frequencyin_deinited(self)); + + return MP_OBJ_NEW_SMALL_INT(common_hal_frequencyio_frequencyin_get_capture_period(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(frequencyio_frequency_get_capture_period_obj, frequencyio_frequencyin_obj_get_capture_period); + +STATIC mp_obj_t frequencyio_frequencyin_obj_set_capture_period(mp_obj_t self_in, mp_obj_t capture_period) { + frequencyio_frequencyin_obj_t *self = MP_OBJ_TO_PTR(self_in); + raise_error_if_deinited(common_hal_frequencyio_frequencyin_deinited(self)); + + common_hal_frequencyio_frequencyin_set_capture_period(self, mp_obj_get_int(capture_period)); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(frequencyio_frequency_set_capture_period_obj, frequencyio_frequencyin_obj_set_capture_period); + +const mp_obj_property_t frequencyio_frequencyin_capture_period_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&frequencyio_frequency_get_capture_period_obj, + (mp_obj_t)&frequencyio_frequency_set_capture_period_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + +//| .. method:: __get__(index) +//| +//| Returns the value of the last frequency captured. +//| +STATIC mp_obj_t frequencyio_frequencyin_obj_get_value(mp_obj_t self_in) { + frequencyio_frequencyin_obj_t *self = MP_OBJ_TO_PTR(self_in); + raise_error_if_deinited(common_hal_frequencyio_frequencyin_deinited(self)); + + //return MP_OBJ_NEW_SMALL_INT(common_hal_frequencyio_frequencyin_get_item(self)); + return mp_obj_new_int_from_float(common_hal_frequencyio_frequencyin_get_item(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(frequencyio_frequencyin_get_value_obj, frequencyio_frequencyin_obj_get_value); + +const mp_obj_property_t frequencyio_frequencyin_value_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&frequencyio_frequencyin_get_value_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + +STATIC const mp_rom_map_elem_t frequencyio_frequencyin_locals_dict_table[] = { + // Methods + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&frequencyio_frequencyin_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&frequencyio_frequencyin___exit___obj) }, + { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&frequencyio_frequencyin_value_obj) }, + { MP_ROM_QSTR(MP_QSTR_pause), MP_ROM_PTR(&frequencyio_frequencyin_pause_obj) }, + { MP_ROM_QSTR(MP_QSTR_resume), MP_ROM_PTR(&frequencyio_frequencyin_resume_obj) }, + { MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&frequencyio_frequencyin_clear_obj) }, + { MP_ROM_QSTR(MP_QSTR_capture_period), MP_ROM_PTR(&frequencyio_frequencyin_capture_period_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(frequencyio_frequencyin_locals_dict, frequencyio_frequencyin_locals_dict_table); + +const mp_obj_type_t frequencyio_frequencyin_type = { + { &mp_type_type }, + .name = MP_QSTR_frequencyin, + .make_new = frequencyio_frequencyin_make_new, + .locals_dict = (mp_obj_dict_t*)&frequencyio_frequencyin_locals_dict, +}; diff --git a/shared-bindings/frequencyio/FrequencyIn.h b/shared-bindings/frequencyio/FrequencyIn.h new file mode 100644 index 0000000000..4718075ece --- /dev/null +++ b/shared-bindings/frequencyio/FrequencyIn.h @@ -0,0 +1,46 @@ +frequencyio/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Michael Schroeder + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_FREQUENCYIO_FREQUENCYIN_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_FREQUENCYIO_FREQUENCYIN_H + +#include "common-hal/microcontroller/Pin.h" +#include "common-hal/frequencyio/FrequencyIn.h" + +extern const mp_obj_type_t frequencyio_frequencyin_type; + +extern void common_hal_frequencyio_frequencyin_construct(frequencyio_frequencyin_obj_t *self, + const mcu_pin_obj_t *pin, uint16_t capture_period); +extern void common_hal_frequencyio_frequencyin_deinit(frequencyio_frequencyin_obj_t *self); +extern bool common_hal_frequencyio_frequencyin_deinited(frequencyio_frequencyin_obj_t *self); +extern void common_hal_frequencyio_frequencyin_pause(frequencyio_frequencyin_obj_t *self); +extern void common_hal_frequencyio_frequencyin_resume(frequencyio_frequencyin_obj_t *self); +extern void common_hal_frequencyio_frequencyin_clear(frequencyio_frequencyin_obj_t *self); +extern uint32_t common_hal_frequencyio_frequencyin_get_item(frequencyio_frequencyin_obj_t *self); +extern uint16_t common_hal_frequencyio_frequencyin_get_capture_period(frequencyio_frequencyin_obj_t *self); +extern void common_hal_frequencyio_frequencyin_set_capture_period(frequencyio_frequencyin_obj_t *self, uint16_t capture_period); + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_FREQUENCYIO_FREQUENCYIN_H diff --git a/shared-bindings/frequencyio/__init__.c b/shared-bindings/frequencyio/__init__.c new file mode 100644 index 0000000000..8e794eac4a --- /dev/null +++ b/shared-bindings/frequencyio/__init__.c @@ -0,0 +1,88 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "py/obj.h" +#include "py/runtime.h" + +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/frequencyio/FrequencyIn.h" + +//| :mod:`frequencyio` --- Support for frequency based protocols +//| ============================================================= +//| +//| .. module:: frequencyio +//| :synopsis: Support for frequency based protocols +//| :platform: SAMD51 +//| +//| The `frequencyio` module contains classes to provide access to basic frequency IO. +//| +//| Libraries +//| +//| .. toctree:: +//| :maxdepth: 3 +//| +//| FrequencyIn +//| + +//| .. warning:: This module is not available in SAMD21 builds. See the +//| :ref:`module-support-matrix` for more info. +//| + +//| All classes change hardware state and should be deinitialized when they +//| are no longer needed if the program continues after use. To do so, either +//| call :py:meth:`!deinit` or use a context manager. See +//| :ref:`lifetime-and-contextmanagers` for more info. +//| +//| For example:: +//| +//| import frequencyio +//| import time +//| from board import * +//| +//| frequency = frequencyio.FrequencyIn(D13) +//| frequency.capture_period = 15 +//| time.sleep(0.1) +//| +//| This example will initialize the the device, set +//| :py:data:`~frequencyio.FrequencyIn.capture_period`, and then sleep 0.1 seconds. +//| CircuitPython will automatically turn off FrequencyIn capture when it resets all +//| hardware after program completion. Use ``deinit()`` or a ``with`` statement +//| to do it yourself. +//| + +STATIC const mp_rom_map_elem_t frequencyio_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_frequencyio) }, + { MP_ROM_QSTR(MP_QSTR_FrequencyIn), MP_ROM_PTR(&pulseio_frequencyin_type) }, +}; + +STATIC MP_DEFINE_CONST_DICT(frequencyio_module_globals, frequencyio_module_globals_table); + +const mp_obj_module_t frequencyio_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t*)&frequencyio_module_globals, +}; From 2437ab9605ba7587a26819a1c60a5a7d8a84b6ae Mon Sep 17 00:00:00 2001 From: sommersoft Date: Fri, 22 Feb 2019 17:19:09 -0600 Subject: [PATCH 02/13] update frequencyin interrupt handler --- ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c | 9 ++++++--- ports/atmel-samd/timer_handler.c | 2 ++ ports/atmel-samd/timer_handler.h | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c b/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c index e499684288..6b67e014a3 100644 --- a/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +++ b/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c @@ -154,7 +154,8 @@ void frequencyin_reference_tc_init() { if (dpll_gclk == 0xff) { frequencyin_samd51_start_dpll(); } - turn_on_clocks(true, reference_tc, dpll_gclk, TC_HANDLER_FREQUENCYIN); + set_timer_handler(reference_tc, dpll_gclk, TC_HANDLER_FREQUENCYIN); + turn_on_clocks(true, reference_tc, dpll_gclk); #endif Tc *tc = tc_insts[reference_tc]; @@ -289,7 +290,8 @@ void common_hal_frequencyio_frequencyin_construct(frequencyio_frequencyin_obj_t* // SAMD21: We use GCLK0 generated from DFLL running at 48mhz // SAMD51: We use a GCLK generated from DPLL1 running at <100mhz #ifdef SAMD21 - turn_on_clocks(true, timer_index, 0, TC_HANDLER_NO_INTERRUPT); + set_timer_handler(timer_index, 0, TC_HANDLER_NO_INTERRUPT); + turn_on_clocks(true, timer_index, 0); #endif #ifdef SAMD51 frequencyin_samd51_start_dpll(); @@ -297,7 +299,8 @@ void common_hal_frequencyio_frequencyin_construct(frequencyio_frequencyin_obj_t* common_hal_frequencyio_frequencyin_deinit(self); mp_raise_RuntimeError(translate("No available clocks")); } - turn_on_clocks(true, timer_index, dpll_gclk, TC_HANDLER_NO_INTERRUPT); + set_timer_handler(timer_index, dpll_gclk, TC_HANDLER_NO_INTERRUPT); + turn_on_clocks(true, timer_index, dpll_gclk); #endif // Ensure EIC is on diff --git a/ports/atmel-samd/timer_handler.c b/ports/atmel-samd/timer_handler.c index 26f984d964..cc777cc3b1 100644 --- a/ports/atmel-samd/timer_handler.c +++ b/ports/atmel-samd/timer_handler.c @@ -46,6 +46,8 @@ void shared_timer_handler(bool is_tc, uint8_t index) { uint8_t handler = tc_handler[index]; if (handler == TC_HANDLER_PULSEOUT) { pulseout_interrupt_handler(index); + } else if (handler == TC_HANDLER_FREQUENCYIN) { + frequencyin_interrupt_handler(index); } } } diff --git a/ports/atmel-samd/timer_handler.h b/ports/atmel-samd/timer_handler.h index f7a6e6e0ed..a495e21f2a 100644 --- a/ports/atmel-samd/timer_handler.h +++ b/ports/atmel-samd/timer_handler.h @@ -28,6 +28,7 @@ #define TC_HANDLER_NO_INTERRUPT 0x0 #define TC_HANDLER_PULSEOUT 0x1 +#define TC_HANDLER_FREQUENCYIN 0x2 void set_timer_handler(bool is_tc, uint8_t index, uint8_t timer_handler); void shared_timer_handler(bool is_tc, uint8_t index); From 9d3fcf9a0d549bbe2329e4b9d1db31194f4b18df Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sun, 24 Feb 2019 18:05:51 -0600 Subject: [PATCH 03/13] add frequencyio to circuipy_ configs --- py/circuitpy_defns.mk | 5 +++++ py/circuitpy_mpconfig.h | 8 ++++++++ py/circuitpy_mpconfig.mk | 5 +++++ 3 files changed, 18 insertions(+) diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 2fa2e78e2a..9bda124fc5 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -126,6 +126,9 @@ endif ifeq ($(CIRCUITPY_DISPLAYIO),1) SRC_PATTERNS += displayio/% terminalio/% endif +ifeq ($(CIRCUITPY_FREQUENCYIO),1) +SRC_PATTERNS += frequencyio/% +endif ifeq ($(CIRCUITPY_GAMEPAD),1) SRC_PATTERNS += gamepad/% endif @@ -228,6 +231,8 @@ $(filter $(SRC_PATTERNS), \ digitalio/DigitalInOut.c \ digitalio/__init__.c \ displayio/ParallelBus.c \ + frequencyio/__init__.c \ + frequencyio/FrequencyIn.c \ i2cslave/I2CSlave.c \ i2cslave/__init__.c \ microcontroller/Pin.c \ diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 6f97054854..218fc3d050 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -281,6 +281,13 @@ extern const struct _mp_obj_module_t terminalio_module; #define CIRCUITPY_DISPLAY_LIMIT (0) #endif +#if CIRCUITPY_FREQUENCYIO +extern const struct _mp_obj_module_t frequencyio_module; +#define FREQUENCYIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_frequencyio), (mp_obj_t)&frequencyio_module }, +#else +#define FREQUENCYIO_MODULE +#endif + #if CIRCUITPY_GAMEPAD extern const struct _mp_obj_module_t gamepad_module; // Scan gamepad every 32ms @@ -512,6 +519,7 @@ extern const struct _mp_obj_module_t ustack_module; TERMINALIO_MODULE \ DISPLAYIO_MODULE \ ERRNO_MODULE \ + FREQUENCYIO_MODULE \ GAMEPAD_MODULE \ I2CSLAVE_MODULE \ JSON_MODULE \ diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index a4a59170f0..e10c7f66eb 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -92,6 +92,11 @@ CIRCUITPY_DISPLAYIO = $(CIRCUITPY_FULL_BUILD) endif CFLAGS += -DCIRCUITPY_DISPLAYIO=$(CIRCUITPY_DISPLAYIO) +ifndef CIRCUITPY_FREQUENCYIO +CIRCUITPY_FREQUENCYIO = $(CIRCUITPY_FULL_BUILD) +endif +CFLAGS += -DCIRCUITPY_FREQUENCYIO=$(CIRCUITPY_FREQUENCYIO) + ifndef CIRCUITPY_GAMEPAD CIRCUITPY_GAMEPAD = $(CIRCUITPY_FULL_BUILD) endif From f602fa3d9f56056e3fd808586c59cb49cc28043d Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sun, 24 Feb 2019 18:07:26 -0600 Subject: [PATCH 04/13] fix init deps --- .../common-hal/frequencyio/__init__.c | 1 + shared-bindings/frequencyio/__init__.c | 5 +-- shared-bindings/frequencyio/__init__.h | 34 +++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 ports/atmel-samd/common-hal/frequencyio/__init__.c create mode 100644 shared-bindings/frequencyio/__init__.h diff --git a/ports/atmel-samd/common-hal/frequencyio/__init__.c b/ports/atmel-samd/common-hal/frequencyio/__init__.c new file mode 100644 index 0000000000..487814bd07 --- /dev/null +++ b/ports/atmel-samd/common-hal/frequencyio/__init__.c @@ -0,0 +1 @@ +// No ferquencyio module functions. diff --git a/shared-bindings/frequencyio/__init__.c b/shared-bindings/frequencyio/__init__.c index 8e794eac4a..48a0268249 100644 --- a/shared-bindings/frequencyio/__init__.c +++ b/shared-bindings/frequencyio/__init__.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Scott Shawcroft for Adafruit Industries + * Copyright (c) 2019 Michael Schroeder * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,6 +30,7 @@ #include "py/runtime.h" #include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/frequencyio/__init__.h" #include "shared-bindings/frequencyio/FrequencyIn.h" //| :mod:`frequencyio` --- Support for frequency based protocols @@ -77,7 +78,7 @@ STATIC const mp_rom_map_elem_t frequencyio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_frequencyio) }, - { MP_ROM_QSTR(MP_QSTR_FrequencyIn), MP_ROM_PTR(&pulseio_frequencyin_type) }, + { MP_ROM_QSTR(MP_QSTR_FrequencyIn), MP_ROM_PTR(&frequencyio_frequencyin_type) }, }; STATIC MP_DEFINE_CONST_DICT(frequencyio_module_globals, frequencyio_module_globals_table); diff --git a/shared-bindings/frequencyio/__init__.h b/shared-bindings/frequencyio/__init__.h new file mode 100644 index 0000000000..3915765944 --- /dev/null +++ b/shared-bindings/frequencyio/__init__.h @@ -0,0 +1,34 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Michael Schroeder + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_FREQUENCYIO___INIT___H +#define MICROPY_INCLUDED_SHARED_BINDINGS_FREQUENCYIO___INIT___H + +#include "py/obj.h" + +// Nothing now. + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_FREQUENCYIO___INIT___H From a8204f1bf9b607ec13f581722b4c2e036f8c34b7 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sun, 24 Feb 2019 18:07:55 -0600 Subject: [PATCH 05/13] touchup adding frequencyin interrupt handling --- ports/atmel-samd/timer_handler.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/atmel-samd/timer_handler.c b/ports/atmel-samd/timer_handler.c index cc777cc3b1..7f68e4a920 100644 --- a/ports/atmel-samd/timer_handler.c +++ b/ports/atmel-samd/timer_handler.c @@ -30,6 +30,7 @@ #include "timer_handler.h" #include "common-hal/pulseio/PulseOut.h" +#include "common-hal/frequencyio/FrequencyIn.h" static uint8_t tc_handler[TC_INST_NUM]; From 4a9f05a44f18615a1adeacfcae329d3090188550 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Mon, 25 Feb 2019 21:22:52 -0600 Subject: [PATCH 06/13] final re-glue; compiles now. --- ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c | 9 +++++---- shared-bindings/frequencyio/FrequencyIn.c | 8 +++----- shared-bindings/frequencyio/FrequencyIn.h | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c b/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c index 6b67e014a3..2119605878 100644 --- a/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +++ b/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c @@ -146,7 +146,8 @@ void frequencyin_reference_tc_init() { return; } #ifdef SAMD21 - turn_on_clocks(true, reference_tc, 0, TC_HANDLER_FREQUENCYIN); + set_timer_handler(reference_tc, dpll_gclk, TC_HANDLER_FREQUENCYIN); + turn_on_clocks(true, reference_tc, 0); #endif // use the DPLL we setup so that the reference_tc and freqin_tc(s) // are using the same clock frequency. @@ -384,7 +385,7 @@ void common_hal_frequencyio_frequencyin_deinit(frequencyio_frequencyin_obj_t* se if (common_hal_frequencyio_frequencyin_deinited(self)) { return; } - reset_pin(self->pin); + reset_pin_number(self->pin); // turn off EIC & EVSYS utilized by this TC disable_event_channel(self->event_channel); @@ -480,11 +481,11 @@ void common_hal_frequencyio_frequencyin_pause(frequencyio_frequencyin_obj_t* sel #ifdef SAMD21 uint32_t masked_value = EIC->EVCTRL.vec.EXTINTEO; - EIC->EVCTRL.vec.EXTINTEO = masked_value | (0 << self->channel); + EIC->EVCTRL.vec.EXTINTEO = masked_value ^ (1 << self->channel); #endif #ifdef SAMD51 uint32_t masked_value = EIC->EVCTRL.bit.EXTINTEO; - EIC->EVCTRL.bit.EXTINTEO = masked_value | (0 << self->channel); + EIC->EVCTRL.bit.EXTINTEO = masked_value ^ (1 << self->channel); #endif return; } diff --git a/shared-bindings/frequencyio/FrequencyIn.c b/shared-bindings/frequencyio/FrequencyIn.c index 0e666d718e..fb1698fa2e 100644 --- a/shared-bindings/frequencyio/FrequencyIn.c +++ b/shared-bindings/frequencyio/FrequencyIn.c @@ -71,20 +71,18 @@ //| frequency.clear() //| STATIC mp_obj_t frequencyio_frequencyin_make_new(const mp_obj_type_t *type, size_t n_args, - size_t n_kw, const mp_obj_t *pos_args) { - mp_arg_check_num(n_args, n_kw, 1, 2, true); + const mp_obj_t *pos_args, mp_map_t *kw_args) { + mp_arg_check_num(n_args, kw_args, 1, 1, true); frequencyio_frequencyin_obj_t *self = m_new_obj(frequencyio_frequencyin_obj_t); self->base.type = &frequencyio_frequencyin_type; - mp_map_t kw_args; - mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args); enum { ARG_pin, ARG_capture_period }; static const mp_arg_t allowed_args[] = { { MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_capture_period, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 10} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); assert_pin(args[ARG_pin].u_obj, false); mcu_pin_obj_t* pin = MP_OBJ_TO_PTR(args[ARG_pin].u_obj); diff --git a/shared-bindings/frequencyio/FrequencyIn.h b/shared-bindings/frequencyio/FrequencyIn.h index 4718075ece..dba6c3a661 100644 --- a/shared-bindings/frequencyio/FrequencyIn.h +++ b/shared-bindings/frequencyio/FrequencyIn.h @@ -1,4 +1,4 @@ -frequencyio/* +/* * This file is part of the Micro Python project, http://micropython.org/ * * The MIT License (MIT) From 4d47ce5c60d5e024b9a95f58372bfbb27772ef1a Mon Sep 17 00:00:00 2001 From: sommersoft Date: Wed, 27 Feb 2019 19:28:59 -0600 Subject: [PATCH 07/13] fixes set_timer_handler call --- ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c b/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c index 2119605878..30fc438277 100644 --- a/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +++ b/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c @@ -146,7 +146,7 @@ void frequencyin_reference_tc_init() { return; } #ifdef SAMD21 - set_timer_handler(reference_tc, dpll_gclk, TC_HANDLER_FREQUENCYIN); + set_timer_handler(true, reference_tc, TC_HANDLER_FREQUENCYIN); turn_on_clocks(true, reference_tc, 0); #endif // use the DPLL we setup so that the reference_tc and freqin_tc(s) @@ -155,7 +155,7 @@ void frequencyin_reference_tc_init() { if (dpll_gclk == 0xff) { frequencyin_samd51_start_dpll(); } - set_timer_handler(reference_tc, dpll_gclk, TC_HANDLER_FREQUENCYIN); + set_timer_handler(true, reference_tc, TC_HANDLER_FREQUENCYIN); turn_on_clocks(true, reference_tc, dpll_gclk); #endif From 438eadd63acb25a43e008dec9335ac4ebb779f96 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Fri, 1 Mar 2019 21:47:23 -0600 Subject: [PATCH 08/13] re-add frequencyin to 'timer_handler' after upstream merge --- ports/atmel-samd/timer_handler.c | 4 ++++ ports/atmel-samd/timer_handler.h | 1 + 2 files changed, 5 insertions(+) diff --git a/ports/atmel-samd/timer_handler.c b/ports/atmel-samd/timer_handler.c index 059d4330ed..6fb25db4f0 100644 --- a/ports/atmel-samd/timer_handler.c +++ b/ports/atmel-samd/timer_handler.c @@ -31,6 +31,7 @@ #include "common-hal/pulseio/PulseOut.h" #include "shared-module/_pew/PewPew.h" +#include "common-hal/frequencyio/FrequencyIn.h" static uint8_t tc_handler[TC_INST_NUM]; @@ -54,6 +55,9 @@ void shared_timer_handler(bool is_tc, uint8_t index) { pewpew_interrupt_handler(index); #endif break; + case TC_HANDLER_FREQUENCYIN: + frequencyin_interrupt_handler(index); + break; default: break; } diff --git a/ports/atmel-samd/timer_handler.h b/ports/atmel-samd/timer_handler.h index e249fca363..4a7adb58c3 100644 --- a/ports/atmel-samd/timer_handler.h +++ b/ports/atmel-samd/timer_handler.h @@ -29,6 +29,7 @@ #define TC_HANDLER_NO_INTERRUPT 0x0 #define TC_HANDLER_PULSEOUT 0x1 #define TC_HANDLER_PEW 0x2 +#define TC_HANDLER_FREQUENCYIN 0x3 void set_timer_handler(bool is_tc, uint8_t index, uint8_t timer_handler); void shared_timer_handler(bool is_tc, uint8_t index); From 2cd6a7901683e32832f42a531485783aa599169a Mon Sep 17 00:00:00 2001 From: sommersoft Date: Fri, 1 Mar 2019 22:46:57 -0600 Subject: [PATCH 09/13] better handle frequencyio inclusion --- ports/atmel-samd/boards/arduino_mkr1300/mpconfigboard.mk | 2 ++ ports/atmel-samd/boards/arduino_mkrzero/mpconfigboard.mk | 2 ++ ports/atmel-samd/boards/arduino_zero/mpconfigboard.mk | 2 ++ .../boards/circuitplayground_express/mpconfigboard.mk | 1 + .../boards/circuitplayground_express_crickit/mpconfigboard.mk | 1 + ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.mk | 2 ++ ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.mk | 2 ++ ports/atmel-samd/boards/feather_m0_express/mpconfigboard.mk | 2 ++ .../boards/feather_m0_express_crickit/mpconfigboard.mk | 1 + ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.mk | 2 ++ ports/atmel-samd/boards/feather_m0_rfm9x/mpconfigboard.mk | 2 ++ ports/atmel-samd/boards/gemma_m0/mpconfigboard.mk | 2 ++ ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk | 1 + ports/atmel-samd/boards/meowmeow/mpconfigboard.mk | 2 ++ ports/atmel-samd/boards/metro_m0_express/mpconfigboard.mk | 2 ++ ports/atmel-samd/boards/pewpew10/mpconfigboard.mk | 1 + ports/atmel-samd/boards/pirkey_m0/mpconfigboard.mk | 1 + ports/atmel-samd/boards/sparkfun_samd21_dev/mpconfigboard.mk | 2 ++ ports/atmel-samd/boards/sparkfun_samd21_mini/mpconfigboard.mk | 2 ++ ports/atmel-samd/boards/trinket_m0/mpconfigboard.mk | 2 ++ ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.mk | 2 ++ ports/nrf/mpconfigport.mk | 3 +++ py/circuitpy_mpconfig.mk | 2 +- 23 files changed, 40 insertions(+), 1 deletion(-) diff --git a/ports/atmel-samd/boards/arduino_mkr1300/mpconfigboard.mk b/ports/atmel-samd/boards/arduino_mkr1300/mpconfigboard.mk index bafb8a96ca..b1b127ced6 100644 --- a/ports/atmel-samd/boards/arduino_mkr1300/mpconfigboard.mk +++ b/ports/atmel-samd/boards/arduino_mkr1300/mpconfigboard.mk @@ -10,3 +10,5 @@ CIRCUITPY_SMALL_BUILD = 1 CHIP_VARIANT = SAMD21G18A CHIP_FAMILY = samd21 + +CIRCUITPY_FREQUENCYIO = 0 diff --git a/ports/atmel-samd/boards/arduino_mkrzero/mpconfigboard.mk b/ports/atmel-samd/boards/arduino_mkrzero/mpconfigboard.mk index b6df8d6e22..0e6fb612eb 100644 --- a/ports/atmel-samd/boards/arduino_mkrzero/mpconfigboard.mk +++ b/ports/atmel-samd/boards/arduino_mkrzero/mpconfigboard.mk @@ -10,3 +10,5 @@ CIRCUITPY_SMALL_BUILD = 1 CHIP_VARIANT = SAMD21G18A CHIP_FAMILY = samd21 + +CIRCUITPY_FREQUENCYIO = 0 diff --git a/ports/atmel-samd/boards/arduino_zero/mpconfigboard.mk b/ports/atmel-samd/boards/arduino_zero/mpconfigboard.mk index af953e8c2d..26f771b502 100644 --- a/ports/atmel-samd/boards/arduino_zero/mpconfigboard.mk +++ b/ports/atmel-samd/boards/arduino_zero/mpconfigboard.mk @@ -10,3 +10,5 @@ CIRCUITPY_SMALL_BUILD = 1 CHIP_VARIANT = SAMD21G18A CHIP_FAMILY = samd21 + +CIRCUITPY_FREQUENCYIO = 0 diff --git a/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.mk b/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.mk index aacffffe09..e1fba0d00c 100644 --- a/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.mk @@ -11,6 +11,7 @@ LONGINT_IMPL = MPZ # Make room for frozen libs. CIRCUITPY_DISPLAYIO = 0 +CIRCUITPY_FREQUENCYIO = 0 CHIP_VARIANT = SAMD21G18A CHIP_FAMILY = samd21 diff --git a/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.mk b/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.mk index eed40f9024..b450f1d555 100644 --- a/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.mk +++ b/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.mk @@ -12,6 +12,7 @@ LONGINT_IMPL = NONE CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_PIXELBUF = 0 +CIRCUITPY_FREQUENCYIO = 0 CHIP_VARIANT = SAMD21G18A CHIP_FAMILY = samd21 diff --git a/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.mk b/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.mk index 26e3b7d4d0..0b99955833 100644 --- a/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.mk +++ b/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.mk @@ -10,3 +10,5 @@ CIRCUITPY_SMALL_BUILD = 1 CHIP_VARIANT = SAMD21G18A CHIP_FAMILY = samd21 + +CIRCUITPY_FREQUENCYIO = 0 diff --git a/ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.mk b/ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.mk index 102cb656f2..a469dcf1dc 100644 --- a/ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.mk +++ b/ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.mk @@ -10,3 +10,5 @@ CIRCUITPY_SMALL_BUILD = 1 CHIP_VARIANT = SAMD21G18A CHIP_FAMILY = samd21 + +CIRCUITPY_FREQUENCYIO = 0 diff --git a/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.mk b/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.mk index 989a676a5b..efd45d0491 100644 --- a/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.mk @@ -14,3 +14,5 @@ CHIP_FAMILY = samd21 CIRCUITPY_NETWORK = 1 MICROPY_PY_WIZNET5K = 5500 + +CIRCUITPY_FREQUENCYIO = 0 diff --git a/ports/atmel-samd/boards/feather_m0_express_crickit/mpconfigboard.mk b/ports/atmel-samd/boards/feather_m0_express_crickit/mpconfigboard.mk index c6dc73d390..7d349193b7 100644 --- a/ports/atmel-samd/boards/feather_m0_express_crickit/mpconfigboard.mk +++ b/ports/atmel-samd/boards/feather_m0_express_crickit/mpconfigboard.mk @@ -11,6 +11,7 @@ LONGINT_IMPL = MPZ # Make space for frozen libs CIRCUITPY_DISPLAYIO = 0 +CIRCUITPY_FREQUENCYIO = 0 CHIP_VARIANT = SAMD21G18A CHIP_FAMILY = samd21 diff --git a/ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.mk b/ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.mk index ce3f8668c7..16696297db 100644 --- a/ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.mk +++ b/ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.mk @@ -10,3 +10,5 @@ CIRCUITPY_SMALL_BUILD = 1 CHIP_VARIANT = SAMD21G18A CHIP_FAMILY = samd21 + +CIRCUITPY_FREQUENCYIO = 0 diff --git a/ports/atmel-samd/boards/feather_m0_rfm9x/mpconfigboard.mk b/ports/atmel-samd/boards/feather_m0_rfm9x/mpconfigboard.mk index 282977338c..39fdc591dc 100644 --- a/ports/atmel-samd/boards/feather_m0_rfm9x/mpconfigboard.mk +++ b/ports/atmel-samd/boards/feather_m0_rfm9x/mpconfigboard.mk @@ -10,3 +10,5 @@ CIRCUITPY_SMALL_BUILD = 1 CHIP_VARIANT = SAMD21G18A CHIP_FAMILY = samd21 + +CIRCUITPY_FREQUENCYIO = 0 diff --git a/ports/atmel-samd/boards/gemma_m0/mpconfigboard.mk b/ports/atmel-samd/boards/gemma_m0/mpconfigboard.mk index 9f4a9fe835..d44f2feb93 100644 --- a/ports/atmel-samd/boards/gemma_m0/mpconfigboard.mk +++ b/ports/atmel-samd/boards/gemma_m0/mpconfigboard.mk @@ -10,3 +10,5 @@ CIRCUITPY_SMALL_BUILD = 1 CHIP_VARIANT = SAMD21E18A CHIP_FAMILY = samd21 + +CIRCUITPY_FREQUENCYIO = 0 diff --git a/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk b/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk index 222a217b30..36cb67ea57 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk @@ -19,3 +19,4 @@ FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel # To keep the build small CIRCUITPY_I2CSLAVE = 0 +CIRCUITPY_FREQUENCYIO = 0 diff --git a/ports/atmel-samd/boards/meowmeow/mpconfigboard.mk b/ports/atmel-samd/boards/meowmeow/mpconfigboard.mk index a620f2919c..3547235dd1 100644 --- a/ports/atmel-samd/boards/meowmeow/mpconfigboard.mk +++ b/ports/atmel-samd/boards/meowmeow/mpconfigboard.mk @@ -10,3 +10,5 @@ CIRCUITPY_SMALL_BUILD = 1 CHIP_VARIANT = SAMD21G18A CHIP_FAMILY = samd21 + +CIRCUITPY_FREQUENCYIO = 0 diff --git a/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.mk b/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.mk index 1c5f4ff7dd..ce46d7000a 100644 --- a/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.mk @@ -15,3 +15,5 @@ CHIP_FAMILY = samd21 CIRCUITPY_NETWORK = 1 MICROPY_PY_WIZNET5K = 5500 + +CIRCUITPY_FREQUENCYIO = 0 diff --git a/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk b/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk index 983e48e21c..92f8cff527 100644 --- a/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk +++ b/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk @@ -20,3 +20,4 @@ CIRCUITPY_RTC = 0 CIRCUITPY_SAMD = 0 CIRCUITPY_USB_MIDI = 0 CIRCUITPY_SMALL_BUILD = 1 +CIRCUITPY_FREQUENCYIO = 0 diff --git a/ports/atmel-samd/boards/pirkey_m0/mpconfigboard.mk b/ports/atmel-samd/boards/pirkey_m0/mpconfigboard.mk index 8bac356049..418f70d92a 100644 --- a/ports/atmel-samd/boards/pirkey_m0/mpconfigboard.mk +++ b/ports/atmel-samd/boards/pirkey_m0/mpconfigboard.mk @@ -17,6 +17,7 @@ CIRCUITPY_RTC = 0 CIRCUITPY_SAMD = 0 CIRCUITPY_USB_MIDI = 0 CIRCUITPY_SMALL_BUILD = 1 +CIRCUITPY_FREQUENCYIO = 0 CHIP_VARIANT = SAMD21E18A CHIP_FAMILY = samd21 diff --git a/ports/atmel-samd/boards/sparkfun_samd21_dev/mpconfigboard.mk b/ports/atmel-samd/boards/sparkfun_samd21_dev/mpconfigboard.mk index c0238ce80e..ec627b523f 100644 --- a/ports/atmel-samd/boards/sparkfun_samd21_dev/mpconfigboard.mk +++ b/ports/atmel-samd/boards/sparkfun_samd21_dev/mpconfigboard.mk @@ -10,3 +10,5 @@ CIRCUITPY_SMALL_BUILD = 1 CHIP_VARIANT = SAMD21G18A CHIP_FAMILY = samd21 + +CIRCUITPY_FREQUENCYIO = 0 diff --git a/ports/atmel-samd/boards/sparkfun_samd21_mini/mpconfigboard.mk b/ports/atmel-samd/boards/sparkfun_samd21_mini/mpconfigboard.mk index 462e3e2caf..8d2f35a69d 100644 --- a/ports/atmel-samd/boards/sparkfun_samd21_mini/mpconfigboard.mk +++ b/ports/atmel-samd/boards/sparkfun_samd21_mini/mpconfigboard.mk @@ -10,3 +10,5 @@ CIRCUITPY_SMALL_BUILD = 1 CHIP_VARIANT = SAMD21G18A CHIP_FAMILY = samd21 + +CIRCUITPY_FREQUENCYIO = 0 diff --git a/ports/atmel-samd/boards/trinket_m0/mpconfigboard.mk b/ports/atmel-samd/boards/trinket_m0/mpconfigboard.mk index 1c6f6db05d..b3448cf49d 100644 --- a/ports/atmel-samd/boards/trinket_m0/mpconfigboard.mk +++ b/ports/atmel-samd/boards/trinket_m0/mpconfigboard.mk @@ -10,3 +10,5 @@ CIRCUITPY_SMALL_BUILD = 1 CHIP_VARIANT = SAMD21E18A CHIP_FAMILY = samd21 + +CIRCUITPY_FREQUENCYIO = 0 diff --git a/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.mk b/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.mk index c9c196da7b..5975ad1bae 100644 --- a/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.mk +++ b/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.mk @@ -11,3 +11,5 @@ LONGINT_IMPL = MPZ CHIP_VARIANT = SAMD21E18A CHIP_FAMILY = samd21 + +CIRCUITPY_FREQUENCYIO = 0 diff --git a/ports/nrf/mpconfigport.mk b/ports/nrf/mpconfigport.mk index c90734c633..55c1734b93 100644 --- a/ports/nrf/mpconfigport.mk +++ b/ports/nrf/mpconfigport.mk @@ -24,3 +24,6 @@ CIRCUITPY_NVM = 0 # rtc not yet implemented CIRCUITPY_RTC = 0 + +# frequencyio not yet implemented +CIRCUITPY_FREQUENCYIO = 0 diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 8ea72f0bfb..0df6fff063 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -93,7 +93,7 @@ endif CFLAGS += -DCIRCUITPY_DISPLAYIO=$(CIRCUITPY_DISPLAYIO) ifndef CIRCUITPY_FREQUENCYIO -CIRCUITPY_FREQUENCYIO = $(CIRCUITPY_FULL_BUILD) +CIRCUITPY_FREQUENCYIO = 1 endif CFLAGS += -DCIRCUITPY_FREQUENCYIO=$(CIRCUITPY_FREQUENCYIO) From c9eb02d9d29aa7a3ae9091b08a11377e4d1ae4d6 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sat, 2 Mar 2019 10:05:32 -0600 Subject: [PATCH 10/13] shore-up inclusion --- ports/atmel-samd/timer_handler.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ports/atmel-samd/timer_handler.c b/ports/atmel-samd/timer_handler.c index 6fb25db4f0..498294acfc 100644 --- a/ports/atmel-samd/timer_handler.c +++ b/ports/atmel-samd/timer_handler.c @@ -31,7 +31,9 @@ #include "common-hal/pulseio/PulseOut.h" #include "shared-module/_pew/PewPew.h" +#if CIRCUITPY_FREQUENCYIN #include "common-hal/frequencyio/FrequencyIn.h" +#endif static uint8_t tc_handler[TC_INST_NUM]; @@ -51,12 +53,14 @@ void shared_timer_handler(bool is_tc, uint8_t index) { pulseout_interrupt_handler(index); break; case TC_HANDLER_PEW: -#if CIRCUITPY_PEW + #if CIRCUITPY_PEW pewpew_interrupt_handler(index); -#endif + #endif break; case TC_HANDLER_FREQUENCYIN: + #if CIRCUITPY_FREQUENCYIN frequencyin_interrupt_handler(index); + #endif break; default: break; From b2520f3147d839852141e6ade061661acd0b1141 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sat, 2 Mar 2019 16:17:23 -0600 Subject: [PATCH 11/13] using the correct name for things is important... --- ports/atmel-samd/timer_handler.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ports/atmel-samd/timer_handler.c b/ports/atmel-samd/timer_handler.c index 498294acfc..61ab3e6d76 100644 --- a/ports/atmel-samd/timer_handler.c +++ b/ports/atmel-samd/timer_handler.c @@ -31,9 +31,7 @@ #include "common-hal/pulseio/PulseOut.h" #include "shared-module/_pew/PewPew.h" -#if CIRCUITPY_FREQUENCYIN #include "common-hal/frequencyio/FrequencyIn.h" -#endif static uint8_t tc_handler[TC_INST_NUM]; @@ -58,7 +56,7 @@ void shared_timer_handler(bool is_tc, uint8_t index) { #endif break; case TC_HANDLER_FREQUENCYIN: - #if CIRCUITPY_FREQUENCYIN + #if CIRCUITPY_FREQUENCYIO frequencyin_interrupt_handler(index); #endif break; From b7b74d1f78dfd2f9c9a294e45fcf5663f54c6ff4 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sat, 2 Mar 2019 18:17:58 -0600 Subject: [PATCH 12/13] update translations --- locale/ID.po | 11 ++++++++++- locale/circuitpython.pot | 11 ++++++++++- locale/de_DE.po | 11 ++++++++++- locale/en_US.po | 11 ++++++++++- locale/es.po | 11 ++++++++++- locale/fil.po | 11 ++++++++++- locale/fr.po | 11 ++++++++++- locale/it_IT.po | 11 ++++++++++- locale/pt_BR.po | 11 ++++++++++- ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c | 6 ++---- 10 files changed, 92 insertions(+), 13 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index f5fadce49f..2d86f7e996 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-01 07:16-0800\n" +"POT-Creation-Date: 2019-03-03 00:16+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -557,6 +557,9 @@ msgstr "Gagal untuk menulis nilai gatts, status: 0x%08lX" msgid "File exists" msgstr "" +msgid "Frequency captured is above capability. Capture Paused." +msgstr "" + msgid "Function requires lock" msgstr "" @@ -598,6 +601,9 @@ msgstr "Bit clock pada pin tidak valid" msgid "Invalid buffer size" msgstr "Ukuran buffer tidak valid" +msgid "Invalid capture period. Valid range: 1 - 500" +msgstr "" + msgid "Invalid channel count" msgstr "" @@ -712,6 +718,9 @@ msgstr "Tidak pin RX" msgid "No TX pin" msgstr "Tidak ada pin TX" +msgid "No available clocks" +msgstr "" + msgid "No default I2C bus" msgstr "Tidak ada standar bus I2C" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 0808ae43e5..2426b37fa7 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: 2019-03-01 07:16-0800\n" +"POT-Creation-Date: 2019-03-03 00:16+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -532,6 +532,9 @@ msgstr "" msgid "File exists" msgstr "" +msgid "Frequency captured is above capability. Capture Paused." +msgstr "" + msgid "Function requires lock" msgstr "" @@ -573,6 +576,9 @@ msgstr "" msgid "Invalid buffer size" msgstr "" +msgid "Invalid capture period. Valid range: 1 - 500" +msgstr "" + msgid "Invalid channel count" msgstr "" @@ -687,6 +693,9 @@ msgstr "" msgid "No TX pin" msgstr "" +msgid "No available clocks" +msgstr "" + msgid "No default I2C bus" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index 941a5d5d16..e681c2630c 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-01 07:16-0800\n" +"POT-Creation-Date: 2019-03-03 00:16+0000\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -537,6 +537,9 @@ msgstr "gatts value konnte nicht geschrieben werden. Status: 0x%04x" msgid "File exists" msgstr "Datei existiert" +msgid "Frequency captured is above capability. Capture Paused." +msgstr "" + msgid "Function requires lock" msgstr "Die Funktion erwartet, dass der 'lock'-Befehl zuvor ausgeführt wurde" @@ -580,6 +583,9 @@ msgstr "Ungültiges bit clock pin" msgid "Invalid buffer size" msgstr "Ungültige Puffergröße" +msgid "Invalid capture period. Valid range: 1 - 500" +msgstr "" + msgid "Invalid channel count" msgstr "Ungültige Anzahl von Kanälen" @@ -703,6 +709,9 @@ msgstr "Kein RX Pin" msgid "No TX pin" msgstr "Kein TX Pin" +msgid "No available clocks" +msgstr "" + msgid "No default I2C bus" msgstr "Kein Standard I2C Bus" diff --git a/locale/en_US.po b/locale/en_US.po index 01cbaeb510..e1f80398b7 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-01 07:16-0800\n" +"POT-Creation-Date: 2019-03-03 00:16+0000\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -532,6 +532,9 @@ msgstr "" msgid "File exists" msgstr "" +msgid "Frequency captured is above capability. Capture Paused." +msgstr "" + msgid "Function requires lock" msgstr "" @@ -573,6 +576,9 @@ msgstr "" msgid "Invalid buffer size" msgstr "" +msgid "Invalid capture period. Valid range: 1 - 500" +msgstr "" + msgid "Invalid channel count" msgstr "" @@ -687,6 +693,9 @@ msgstr "" msgid "No TX pin" msgstr "" +msgid "No available clocks" +msgstr "" + msgid "No default I2C bus" msgstr "" diff --git a/locale/es.po b/locale/es.po index a4eceb1fb8..c230ee4ef0 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-01 07:16-0800\n" +"POT-Creation-Date: 2019-03-03 00:16+0000\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -562,6 +562,9 @@ msgstr "No se puede escribir el valor del atributo. status: 0x%02x" msgid "File exists" msgstr "El archivo ya existe" +msgid "Frequency captured is above capability. Capture Paused." +msgstr "" + msgid "Function requires lock" msgstr "La función requiere lock" @@ -605,6 +608,9 @@ msgstr "Pin bit clock inválido" msgid "Invalid buffer size" msgstr "Tamaño de buffer inválido" +msgid "Invalid capture period. Valid range: 1 - 500" +msgstr "" + msgid "Invalid channel count" msgstr "Cuenta de canales inválida" @@ -724,6 +730,9 @@ msgstr "Sin pin RX" msgid "No TX pin" msgstr "Sin pin TX" +msgid "No available clocks" +msgstr "" + msgid "No default I2C bus" msgstr "Sin bus I2C por defecto" diff --git a/locale/fil.po b/locale/fil.po index fb6002a574..974488f32c 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-01 07:16-0800\n" +"POT-Creation-Date: 2019-03-03 00:16+0000\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -560,6 +560,9 @@ msgstr "Hindi maisulat ang gatts value, status: 0x%08lX" msgid "File exists" msgstr "Mayroong file" +msgid "Frequency captured is above capability. Capture Paused." +msgstr "" + msgid "Function requires lock" msgstr "Function nangangailangan ng lock" @@ -603,6 +606,9 @@ msgstr "Mali ang bit clock pin" msgid "Invalid buffer size" msgstr "Mali ang buffer size" +msgid "Invalid capture period. Valid range: 1 - 500" +msgstr "" + msgid "Invalid channel count" msgstr "Maling bilang ng channel" @@ -722,6 +728,9 @@ msgstr "Walang RX pin" msgid "No TX pin" msgstr "Walang TX pin" +msgid "No available clocks" +msgstr "" + msgid "No default I2C bus" msgstr "Walang default na I2C bus" diff --git a/locale/fr.po b/locale/fr.po index c937a4b5ba..21c21f0336 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-01 07:16-0800\n" +"POT-Creation-Date: 2019-03-03 00:16+0000\n" "PO-Revision-Date: 2018-12-23 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -559,6 +559,9 @@ msgstr "Impossible d'écrire la valeur de gatts. status: 0x%08lX" msgid "File exists" msgstr "Le fichier existe" +msgid "Frequency captured is above capability. Capture Paused." +msgstr "" + msgid "Function requires lock" msgstr "La fonction nécessite un verrou" @@ -604,6 +607,9 @@ msgstr "Broche invalide pour 'bit clock'" msgid "Invalid buffer size" msgstr "longueur de tampon invalide" +msgid "Invalid capture period. Valid range: 1 - 500" +msgstr "" + #, fuzzy msgid "Invalid channel count" msgstr "Argument invalide" @@ -725,6 +731,9 @@ msgstr "Pas de broche RX" msgid "No TX pin" msgstr "Pas de broche TX" +msgid "No available clocks" +msgstr "" + msgid "No default I2C bus" msgstr "Pas de bus I2C par défaut" diff --git a/locale/it_IT.po b/locale/it_IT.po index 64fb22128f..a3032db9da 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-01 07:16-0800\n" +"POT-Creation-Date: 2019-03-03 00:16+0000\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -559,6 +559,9 @@ msgstr "Impossibile scrivere valore dell'attributo. status: 0x%02x" msgid "File exists" msgstr "File esistente" +msgid "Frequency captured is above capability. Capture Paused." +msgstr "" + msgid "Function requires lock" msgstr "" @@ -603,6 +606,9 @@ msgstr "Pin del clock di bit non valido" msgid "Invalid buffer size" msgstr "lunghezza del buffer non valida" +msgid "Invalid capture period. Valid range: 1 - 500" +msgstr "" + #, fuzzy msgid "Invalid channel count" msgstr "Argomento non valido" @@ -720,6 +726,9 @@ msgstr "Nessun pin RX" msgid "No TX pin" msgstr "Nessun pin TX" +msgid "No available clocks" +msgstr "" + msgid "No default I2C bus" msgstr "Nessun bus I2C predefinito" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index cf46dfbc58..a55de1994f 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-01 07:16-0800\n" +"POT-Creation-Date: 2019-03-03 00:16+0000\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -552,6 +552,9 @@ msgstr "Não é possível gravar o valor do atributo. status: 0x%02x" msgid "File exists" msgstr "Arquivo já existe" +msgid "Frequency captured is above capability. Capture Paused." +msgstr "" + msgid "Function requires lock" msgstr "" @@ -594,6 +597,9 @@ msgstr "Pino de bit clock inválido" msgid "Invalid buffer size" msgstr "Arquivo inválido" +msgid "Invalid capture period. Valid range: 1 - 500" +msgstr "" + #, fuzzy msgid "Invalid channel count" msgstr "certificado inválido" @@ -710,6 +716,9 @@ msgstr "Nenhum pino RX" msgid "No TX pin" msgstr "Nenhum pino TX" +msgid "No available clocks" +msgstr "" + msgid "No default I2C bus" msgstr "Nenhum barramento I2C padrão" diff --git a/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c b/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c index 30fc438277..fa5d08a3ff 100644 --- a/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +++ b/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c @@ -252,8 +252,7 @@ void common_hal_frequencyio_frequencyin_construct(frequencyio_frequencyin_obj_t* mp_raise_RuntimeError(translate("No hardware support on pin")); } if ((capture_period == 0) || (capture_period > 500)) { - // TODO: find a sutiable message that is already translated - mp_raise_ValueError(translate("Invalid something")); + mp_raise_ValueError(translate("Invalid capture period. Valid range: 1 - 500")); } uint32_t mask = 1 << pin->extint_channel; if (eic_get_enable() == 1 && @@ -539,8 +538,7 @@ uint16_t common_hal_frequencyio_frequencyin_get_capture_period(frequencyio_frequ void common_hal_frequencyio_frequencyin_set_capture_period(frequencyio_frequencyin_obj_t *self, uint16_t capture_period) { if ((capture_period == 0) || (capture_period > 500)) { - // TODO: find a sutiable message that is already translated - mp_raise_ValueError(translate("Invalid something")); + mp_raise_ValueError(translate("Invalid capture period. Valid range: 1 - 500")); } self->capture_period = capture_period; From 8de4cf6b10b48c982ec67dcc60e4eb96f394409f Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sat, 2 Mar 2019 18:33:37 -0600 Subject: [PATCH 13/13] update RTD documentation --- shared-bindings/frequencyio/FrequencyIn.c | 15 ++++++++++----- shared-bindings/index.rst | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/shared-bindings/frequencyio/FrequencyIn.c b/shared-bindings/frequencyio/FrequencyIn.c index fb1698fa2e..908cb307dd 100644 --- a/shared-bindings/frequencyio/FrequencyIn.c +++ b/shared-bindings/frequencyio/FrequencyIn.c @@ -41,9 +41,12 @@ //| ======================================================== //| //| FrequencyIn is used to measure the frequency, in hertz, of a digital signal -//| on an incoming pin. Accuracy has shown to be within 1kHz, if not better. -//| Current maximum detectable frequency is ~512kHz. -//| It will not determine pulse width (use ``PulseIn``). +//| on an incoming pin. Accuracy has shown to be within 10%, if not better. It +//| is recommended to utilize an average of multiple samples to smooth out readings. +//| +//| Frequencies below 1KHz are not currently detectable. +//| +//| FrequencyIn will not determine pulse width (use ``PulseIn``). //| //| .. class:: FrequencyIn(pin, capture_period=10) //| @@ -51,7 +54,7 @@ //| //| :param ~microcontroller.Pin pin: Pin to read frequency from. //| :param int capture_period: Keyword argument to set the measurement period, in -//| milliseconds. Default is 10ms; maximum is 500ms. +//| milliseconds. Default is 10ms; range is 1ms - 500ms. //| //| Read the incoming frequency from a pin:: //| @@ -166,7 +169,9 @@ MP_DEFINE_CONST_FUN_OBJ_1(frequencyio_frequencyin_clear_obj, frequencyio_frequen //| .. attribute:: capture_period //| -//| The capture measurement period. +//| The capture measurement period. Lower incoming frequencies will be measured +//| more accurately with longer capture periods. Higher frequencies are more +//| accurate with shorter capture periods. //| //| .. note:: When setting a new ``capture_period``, all previous capture information is //| cleared with a call to ``clear()``. diff --git a/shared-bindings/index.rst b/shared-bindings/index.rst index 9641d73d14..4f2e28702b 100644 --- a/shared-bindings/index.rst +++ b/shared-bindings/index.rst @@ -42,6 +42,7 @@ Module Supported Ports `bleio` **nRF** `busio` **All Supported** `digitalio` **All Supported** +`frequencyio` **SAMD51** `gamepad` **SAMD Express, nRF** `hashlib` **ESP8266** `i2cslave` **SAMD Express**