refactor countio based on feedback
This commit is contained in:
parent
54eb6d39e4
commit
bfa5cd9c13
@ -8,7 +8,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2020-04-27 18:34-0700\n"
|
||||
"POT-Creation-Date: 2020-05-05 14:57+1000\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
@ -245,6 +245,7 @@ msgstr ""
|
||||
msgid "3-arg pow() not supported"
|
||||
msgstr ""
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
#: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c
|
||||
msgid "A hardware interrupt channel is already in use"
|
||||
msgstr "Sebuah channel hardware interrupt sedang digunakan"
|
||||
@ -1209,6 +1210,10 @@ msgstr ""
|
||||
msgid "Pin does not have ADC capabilities"
|
||||
msgstr "Pin tidak mempunya kemampuan untuk ADC (Analog Digital Converter)"
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
msgid "Pin must support hardware interrupts"
|
||||
msgstr ""
|
||||
|
||||
#: ports/stm/common-hal/pulseio/PulseIn.c
|
||||
msgid "Pin number already reserved by EXTI"
|
||||
msgstr ""
|
||||
|
@ -8,7 +8,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2020-04-27 18:34-0700\n"
|
||||
"POT-Creation-Date: 2020-05-05 14:57+1000\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
@ -244,6 +244,7 @@ msgstr ""
|
||||
msgid "3-arg pow() not supported"
|
||||
msgstr ""
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
#: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c
|
||||
msgid "A hardware interrupt channel is already in use"
|
||||
msgstr ""
|
||||
@ -1197,6 +1198,10 @@ msgstr ""
|
||||
msgid "Pin does not have ADC capabilities"
|
||||
msgstr ""
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
msgid "Pin must support hardware interrupts"
|
||||
msgstr ""
|
||||
|
||||
#: ports/stm/common-hal/pulseio/PulseIn.c
|
||||
msgid "Pin number already reserved by EXTI"
|
||||
msgstr ""
|
||||
|
@ -7,7 +7,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2020-04-27 18:34-0700\n"
|
||||
"POT-Creation-Date: 2020-05-05 14:57+1000\n"
|
||||
"PO-Revision-Date: 2018-07-27 11:55-0700\n"
|
||||
"Last-Translator: Pascal Deneaux\n"
|
||||
"Language-Team: Sebastian Plamauer, Pascal Deneaux\n"
|
||||
@ -246,6 +246,7 @@ msgstr ""
|
||||
msgid "3-arg pow() not supported"
|
||||
msgstr "3-arg pow() wird nicht unterstützt"
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
#: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c
|
||||
msgid "A hardware interrupt channel is already in use"
|
||||
msgstr "Ein Hardware Interrupt Kanal wird schon benutzt"
|
||||
@ -1212,6 +1213,10 @@ msgstr "Zugang verweigert"
|
||||
msgid "Pin does not have ADC capabilities"
|
||||
msgstr "Pin hat keine ADC Funktionalität"
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
msgid "Pin must support hardware interrupts"
|
||||
msgstr ""
|
||||
|
||||
#: ports/stm/common-hal/pulseio/PulseIn.c
|
||||
msgid "Pin number already reserved by EXTI"
|
||||
msgstr ""
|
||||
|
@ -7,7 +7,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2020-04-27 18:34-0700\n"
|
||||
"POT-Creation-Date: 2020-05-05 14:57+1000\n"
|
||||
"PO-Revision-Date: 2018-07-27 11:55-0700\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
@ -244,6 +244,7 @@ msgstr ""
|
||||
msgid "3-arg pow() not supported"
|
||||
msgstr ""
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
#: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c
|
||||
msgid "A hardware interrupt channel is already in use"
|
||||
msgstr ""
|
||||
@ -1197,6 +1198,10 @@ msgstr ""
|
||||
msgid "Pin does not have ADC capabilities"
|
||||
msgstr ""
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
msgid "Pin must support hardware interrupts"
|
||||
msgstr ""
|
||||
|
||||
#: ports/stm/common-hal/pulseio/PulseIn.c
|
||||
msgid "Pin number already reserved by EXTI"
|
||||
msgstr ""
|
||||
|
@ -7,7 +7,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2020-04-27 18:34-0700\n"
|
||||
"POT-Creation-Date: 2020-05-05 14:57+1000\n"
|
||||
"PO-Revision-Date: 2018-07-27 11:55-0700\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: @sommersoft, @MrCertainly\n"
|
||||
@ -246,6 +246,7 @@ msgstr ""
|
||||
msgid "3-arg pow() not supported"
|
||||
msgstr ""
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
#: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c
|
||||
msgid "A hardware interrupt channel is already in use"
|
||||
msgstr "Avast! A hardware interrupt channel be used already"
|
||||
@ -1201,6 +1202,10 @@ msgstr ""
|
||||
msgid "Pin does not have ADC capabilities"
|
||||
msgstr "Belay that! Th' Pin be not ADC capable"
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
msgid "Pin must support hardware interrupts"
|
||||
msgstr ""
|
||||
|
||||
#: ports/stm/common-hal/pulseio/PulseIn.c
|
||||
msgid "Pin number already reserved by EXTI"
|
||||
msgstr ""
|
||||
|
@ -7,7 +7,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2020-04-27 18:34-0700\n"
|
||||
"POT-Creation-Date: 2020-05-05 14:57+1000\n"
|
||||
"PO-Revision-Date: 2018-08-24 22:56-0500\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
@ -246,6 +246,7 @@ msgstr "0.0 a una potencia compleja"
|
||||
msgid "3-arg pow() not supported"
|
||||
msgstr "pow() con 3 argumentos no soportado"
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
#: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c
|
||||
msgid "A hardware interrupt channel is already in use"
|
||||
msgstr "El canal EXTINT ya está siendo utilizado"
|
||||
@ -1211,6 +1212,10 @@ msgstr "Permiso denegado"
|
||||
msgid "Pin does not have ADC capabilities"
|
||||
msgstr "Pin no tiene capacidad ADC"
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
msgid "Pin must support hardware interrupts"
|
||||
msgstr ""
|
||||
|
||||
#: ports/stm/common-hal/pulseio/PulseIn.c
|
||||
msgid "Pin number already reserved by EXTI"
|
||||
msgstr ""
|
||||
|
@ -7,7 +7,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2020-04-27 18:34-0700\n"
|
||||
"POT-Creation-Date: 2020-05-05 14:57+1000\n"
|
||||
"PO-Revision-Date: 2018-12-20 22:15-0800\n"
|
||||
"Last-Translator: Timothy <me@timothygarcia.ca>\n"
|
||||
"Language-Team: fil\n"
|
||||
@ -247,6 +247,7 @@ msgstr "0.0 para sa complex power"
|
||||
msgid "3-arg pow() not supported"
|
||||
msgstr "3-arg pow() hindi suportado"
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
#: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c
|
||||
msgid "A hardware interrupt channel is already in use"
|
||||
msgstr "Isang channel ng hardware interrupt ay ginagamit na"
|
||||
@ -1217,6 +1218,10 @@ msgstr "Walang pahintulot"
|
||||
msgid "Pin does not have ADC capabilities"
|
||||
msgstr "Ang pin ay walang kakayahan sa ADC"
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
msgid "Pin must support hardware interrupts"
|
||||
msgstr ""
|
||||
|
||||
#: ports/stm/common-hal/pulseio/PulseIn.c
|
||||
msgid "Pin number already reserved by EXTI"
|
||||
msgstr ""
|
||||
|
@ -8,7 +8,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: 0.1\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2020-04-27 18:34-0700\n"
|
||||
"POT-Creation-Date: 2020-05-05 14:57+1000\n"
|
||||
"PO-Revision-Date: 2019-04-14 20:05+0100\n"
|
||||
"Last-Translator: Pierrick Couturier <arofarn@arofarn.info>\n"
|
||||
"Language-Team: fr\n"
|
||||
@ -248,6 +248,7 @@ msgstr "0.0 à une puissance complexe"
|
||||
msgid "3-arg pow() not supported"
|
||||
msgstr "pow() non supporté avec 3 arguments"
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
#: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c
|
||||
msgid "A hardware interrupt channel is already in use"
|
||||
msgstr "Un canal d'interruptions matérielles est déjà utilisé"
|
||||
@ -1231,6 +1232,10 @@ msgstr "Permission refusée"
|
||||
msgid "Pin does not have ADC capabilities"
|
||||
msgstr "La broche ne peut être utilisée pour l'ADC"
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
msgid "Pin must support hardware interrupts"
|
||||
msgstr ""
|
||||
|
||||
#: ports/stm/common-hal/pulseio/PulseIn.c
|
||||
msgid "Pin number already reserved by EXTI"
|
||||
msgstr ""
|
||||
|
@ -8,7 +8,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2020-04-27 18:34-0700\n"
|
||||
"POT-Creation-Date: 2020-05-05 14:57+1000\n"
|
||||
"PO-Revision-Date: 2018-10-02 16:27+0200\n"
|
||||
"Last-Translator: Enrico Paganin <enrico.paganin@mail.com>\n"
|
||||
"Language-Team: \n"
|
||||
@ -246,6 +246,7 @@ msgstr "0.0 elevato alla potenza di un numero complesso"
|
||||
msgid "3-arg pow() not supported"
|
||||
msgstr "pow() con tre argmomenti non supportata"
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
#: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c
|
||||
msgid "A hardware interrupt channel is already in use"
|
||||
msgstr "Un canale di interrupt hardware è già in uso"
|
||||
@ -1226,6 +1227,10 @@ msgstr "Permesso negato"
|
||||
msgid "Pin does not have ADC capabilities"
|
||||
msgstr "Il pin non ha capacità di ADC"
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
msgid "Pin must support hardware interrupts"
|
||||
msgstr ""
|
||||
|
||||
#: ports/stm/common-hal/pulseio/PulseIn.c
|
||||
msgid "Pin number already reserved by EXTI"
|
||||
msgstr ""
|
||||
|
@ -8,7 +8,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2020-04-27 18:34-0700\n"
|
||||
"POT-Creation-Date: 2020-05-05 14:57+1000\n"
|
||||
"PO-Revision-Date: 2019-05-06 14:22-0700\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
@ -246,6 +246,7 @@ msgstr ""
|
||||
msgid "3-arg pow() not supported"
|
||||
msgstr ""
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
#: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c
|
||||
msgid "A hardware interrupt channel is already in use"
|
||||
msgstr ""
|
||||
@ -1201,6 +1202,10 @@ msgstr ""
|
||||
msgid "Pin does not have ADC capabilities"
|
||||
msgstr ""
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
msgid "Pin must support hardware interrupts"
|
||||
msgstr ""
|
||||
|
||||
#: ports/stm/common-hal/pulseio/PulseIn.c
|
||||
msgid "Pin number already reserved by EXTI"
|
||||
msgstr ""
|
||||
|
@ -7,7 +7,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2020-04-27 18:34-0700\n"
|
||||
"POT-Creation-Date: 2020-05-05 14:57+1000\n"
|
||||
"PO-Revision-Date: 2019-03-19 18:37-0700\n"
|
||||
"Last-Translator: Radomir Dopieralski <circuitpython@sheep.art.pl>\n"
|
||||
"Language-Team: pl\n"
|
||||
@ -245,6 +245,7 @@ msgstr "0.0 do potęgi zespolonej"
|
||||
msgid "3-arg pow() not supported"
|
||||
msgstr "3-argumentowy pow() jest niewspierany"
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
#: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c
|
||||
msgid "A hardware interrupt channel is already in use"
|
||||
msgstr "Kanał przerwań sprzętowych w użyciu"
|
||||
@ -1202,6 +1203,10 @@ msgstr "Odmowa dostępu"
|
||||
msgid "Pin does not have ADC capabilities"
|
||||
msgstr "Nóżka nie obsługuje ADC"
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
msgid "Pin must support hardware interrupts"
|
||||
msgstr ""
|
||||
|
||||
#: ports/stm/common-hal/pulseio/PulseIn.c
|
||||
msgid "Pin number already reserved by EXTI"
|
||||
msgstr ""
|
||||
|
@ -8,7 +8,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2020-04-27 18:34-0700\n"
|
||||
"POT-Creation-Date: 2020-05-05 14:57+1000\n"
|
||||
"PO-Revision-Date: 2018-10-02 21:14-0000\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
@ -246,6 +246,7 @@ msgstr ""
|
||||
msgid "3-arg pow() not supported"
|
||||
msgstr ""
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
#: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c
|
||||
msgid "A hardware interrupt channel is already in use"
|
||||
msgstr "Um canal de interrupção de hardware já está em uso"
|
||||
@ -1212,6 +1213,10 @@ msgstr "Permissão negada"
|
||||
msgid "Pin does not have ADC capabilities"
|
||||
msgstr "O pino não tem recursos de ADC"
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
msgid "Pin must support hardware interrupts"
|
||||
msgstr ""
|
||||
|
||||
#: ports/stm/common-hal/pulseio/PulseIn.c
|
||||
msgid "Pin number already reserved by EXTI"
|
||||
msgstr ""
|
||||
|
@ -7,7 +7,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: circuitpython-cn\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2020-04-27 18:34-0700\n"
|
||||
"POT-Creation-Date: 2020-05-05 14:57+1000\n"
|
||||
"PO-Revision-Date: 2019-04-13 10:10-0700\n"
|
||||
"Last-Translator: hexthat\n"
|
||||
"Language-Team: Chinese Hanyu Pinyin\n"
|
||||
@ -251,6 +251,7 @@ msgstr "0.0 dào fùzá diànyuán"
|
||||
msgid "3-arg pow() not supported"
|
||||
msgstr "bù zhīchí 3-arg pow ()"
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
#: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c
|
||||
msgid "A hardware interrupt channel is already in use"
|
||||
msgstr "Yìngjiàn zhōngduàn tōngdào yǐ zài shǐyòng zhōng"
|
||||
@ -1216,6 +1217,10 @@ msgstr "Quánxiàn bèi jùjué"
|
||||
msgid "Pin does not have ADC capabilities"
|
||||
msgstr "Pin méiyǒu ADC nénglì"
|
||||
|
||||
#: ports/atmel-samd/common-hal/countio/Counter.c
|
||||
msgid "Pin must support hardware interrupts"
|
||||
msgstr ""
|
||||
|
||||
#: ports/stm/common-hal/pulseio/PulseIn.c
|
||||
msgid "Pin number already reserved by EXTI"
|
||||
msgstr ""
|
||||
|
83
ports/atmel-samd/common-hal/countio/Counter.c
Normal file
83
ports/atmel-samd/common-hal/countio/Counter.c
Normal file
@ -0,0 +1,83 @@
|
||||
|
||||
#include "common-hal/countio/Counter.h"
|
||||
|
||||
#include "atmel_start_pins.h"
|
||||
|
||||
#include "eic_handler.h"
|
||||
#include "samd/external_interrupts.h"
|
||||
#include "py/runtime.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
void common_hal_countio_counter_construct(countio_counter_obj_t* self,
|
||||
const mcu_pin_obj_t* pin_a) {
|
||||
if (!pin_a->has_extint) {
|
||||
mp_raise_RuntimeError(translate("Pin must support hardware interrupts"));
|
||||
}
|
||||
|
||||
|
||||
if (eic_get_enable()) {
|
||||
if (!eic_channel_free(pin_a->extint_channel)) {
|
||||
mp_raise_RuntimeError(translate("A hardware interrupt channel is already in use"));
|
||||
}
|
||||
} else {
|
||||
turn_on_external_interrupt_controller();
|
||||
}
|
||||
|
||||
// These default settings apply when the EIC isn't yet enabled.
|
||||
self->eic_channel_a = pin_a->extint_channel;
|
||||
|
||||
self->pin_a = pin_a->number;
|
||||
|
||||
gpio_set_pin_function(self->pin_a, GPIO_PIN_FUNCTION_A);
|
||||
gpio_set_pin_pull_mode(self->pin_a, GPIO_PULL_UP);
|
||||
|
||||
set_eic_channel_data(self->eic_channel_a, (void*) self);
|
||||
|
||||
self->count = 0;
|
||||
|
||||
|
||||
claim_pin(pin_a);
|
||||
|
||||
|
||||
set_eic_handler(self->eic_channel_a, EIC_HANDLER_COUNTER);
|
||||
turn_on_eic_channel(self->eic_channel_a, EIC_CONFIG_SENSE0_FALL_Val);
|
||||
|
||||
}
|
||||
|
||||
bool common_hal_countio_counter_deinited(countio_counter_obj_t* self) {
|
||||
return self->pin_a == NO_PIN;
|
||||
}
|
||||
|
||||
void common_hal_countio_counter_deinit(countio_counter_obj_t* self) {
|
||||
if (common_hal_countio_counter_deinited(self)) {
|
||||
return;
|
||||
}
|
||||
|
||||
set_eic_handler(self->eic_channel_a, EIC_HANDLER_NO_INTERRUPT);
|
||||
turn_off_eic_channel(self->eic_channel_a);
|
||||
|
||||
|
||||
reset_pin_number(self->pin_a);
|
||||
self->pin_a = NO_PIN;
|
||||
|
||||
}
|
||||
|
||||
mp_int_t common_hal_countio_counter_get_count(countio_counter_obj_t* self) {
|
||||
return self->count;
|
||||
}
|
||||
|
||||
void common_hal_countio_counter_set_count(countio_counter_obj_t* self,
|
||||
mp_int_t new_count) {
|
||||
self->count = new_count;
|
||||
}
|
||||
|
||||
void common_hal_countio_counter_reset(countio_counter_obj_t* self){
|
||||
self->count = 0;
|
||||
}
|
||||
|
||||
void counter_interrupt_handler(uint8_t channel) {
|
||||
countio_counter_obj_t* self = get_eic_channel_data(channel);
|
||||
|
||||
self->count += 1;
|
||||
|
||||
}
|
19
ports/atmel-samd/common-hal/countio/Counter.h
Normal file
19
ports/atmel-samd/common-hal/countio/Counter.h
Normal file
@ -0,0 +1,19 @@
|
||||
|
||||
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_COUNTIO_COUNTER_H
|
||||
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_COUNTIO_COUNTER_H
|
||||
|
||||
#include "common-hal/microcontroller/Pin.h"
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
uint8_t pin_a;
|
||||
uint8_t eic_channel_a:4;
|
||||
mp_int_t count;
|
||||
} countio_counter_obj_t;
|
||||
|
||||
|
||||
void counter_interrupt_handler(uint8_t channel);
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_COUNTIO_COUNT_H
|
1
ports/atmel-samd/common-hal/countio/__init__.c
Normal file
1
ports/atmel-samd/common-hal/countio/__init__.c
Normal file
@ -0,0 +1 @@
|
||||
//No countio module functions
|
@ -27,6 +27,7 @@
|
||||
#include "common-hal/pulseio/PulseIn.h"
|
||||
#include "common-hal/ps2io/Ps2.h"
|
||||
#include "common-hal/rotaryio/IncrementalEncoder.h"
|
||||
#include "common-hal/countio/Counter.h"
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
//#include "samd/external_interrupts.h"
|
||||
#include "eic_handler.h"
|
||||
@ -59,6 +60,12 @@ void shared_eic_handler(uint8_t channel) {
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_COUNTIO
|
||||
case EIC_HANDLER_COUNTER:
|
||||
counter_interrupt_handler(channel);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -30,6 +30,7 @@
|
||||
#define EIC_HANDLER_PULSEIN 0x1
|
||||
#define EIC_HANDLER_INCREMENTAL_ENCODER 0x2
|
||||
#define EIC_HANDLER_PS2 0x3
|
||||
#define EIC_HANDLER_COUNTER 0x04
|
||||
|
||||
void set_eic_handler(uint8_t channel, uint8_t eic_handler);
|
||||
void shared_eic_handler(uint8_t channel);
|
||||
|
@ -18,5 +18,5 @@ CIRCUITPY_NEOPIXEL_WRITE = 0
|
||||
CIRCUITPY_NVM = 0
|
||||
CIRCUITPY_DISPLAYIO = 0
|
||||
CIRCUITPY_FREQUENCYIO = 0
|
||||
|
||||
CIRCUITPY_COUNTIO = 0
|
||||
INTERNAL_LIBM = 1
|
||||
|
@ -25,7 +25,7 @@ CIRCUITPY_NVM = 0
|
||||
CIRCUITPY_PULSEIO = 0
|
||||
CIRCUITPY_ROTARYIO = 0
|
||||
CIRCUITPY_RTC = 0
|
||||
|
||||
CIRCUITPY_COUNTIO = 0
|
||||
# Enable USB support
|
||||
CIRCUITPY_USB_HID = 1
|
||||
CIRCUITPY_USB_MIDI = 1
|
||||
|
@ -26,5 +26,5 @@ CIRCUITPY_FREQUENCYIO = 0
|
||||
CIRCUITPY_I2CSLAVE = 0
|
||||
CIRCUITPY_NVM = 0
|
||||
CIRCUITPY_ROTARYIO = 0
|
||||
|
||||
CIRCUITPY_COUNTIO = 0
|
||||
LONGINT_IMPL = MPZ
|
||||
|
@ -54,6 +54,8 @@ CIRCUITPY_FREQUENCYIO = 0
|
||||
CIRCUITPY_RGBMATRIX ?= 1
|
||||
CIRCUITPY_FRAMEBUFFERIO ?= 1
|
||||
|
||||
CIRCUITPY_COUNTIO = 0
|
||||
|
||||
# nRF52840-specific
|
||||
|
||||
ifeq ($(MCU_CHIP),nrf52840)
|
||||
|
@ -8,6 +8,7 @@ ifeq ($(MCU_SERIES),F4)
|
||||
CIRCUITPY_AUDIOBUSIO = 0
|
||||
CIRCUITPY_AUDIOIO = 0
|
||||
CIRCUITPY_ROTARYIO = 0
|
||||
CIRCUITPY_COUNTIO = 0
|
||||
CIRCUITPY_RTC = 0
|
||||
CIRCUITPY_FREQUENCYIO = 0
|
||||
CIRCUITPY_I2CSLAVE = 0
|
||||
@ -26,6 +27,7 @@ ifeq ($(MCU_SERIES),H7)
|
||||
CIRCUITPY_NVM = 0
|
||||
CIRCUITPY_AUDIOBUSIO = 0
|
||||
CIRCUITPY_AUDIOIO = 0
|
||||
CIRCUITPY_COUNTIO = 0
|
||||
CIRCUITPY_ROTARYIO = 0
|
||||
CIRCUITPY_RTC = 0
|
||||
CIRCUITPY_FREQUENCYIO = 0
|
||||
@ -46,6 +48,7 @@ ifeq ($(MCU_SERIES),F7)
|
||||
CIRCUITPY_AUDIOBUSIO = 0
|
||||
CIRCUITPY_AUDIOIO = 0
|
||||
CIRCUITPY_ROTARYIO = 0
|
||||
CIRCUITPY_COUNTIO = 0
|
||||
CIRCUITPY_RTC = 0
|
||||
CIRCUITPY_FREQUENCYIO = 0
|
||||
CIRCUITPY_I2CSLAVE = 0
|
||||
|
@ -136,6 +136,9 @@ endif
|
||||
ifeq ($(CIRCUITPY_BUSIO),1)
|
||||
SRC_PATTERNS += busio/% bitbangio/OneWire.%
|
||||
endif
|
||||
ifeq ($(CIRCUITPY_COUNTIO),1)
|
||||
SRC_PATTERNS += countio/%
|
||||
endif
|
||||
ifeq ($(CIRCUITPY_DIGITALIO),1)
|
||||
SRC_PATTERNS += digitalio/%
|
||||
endif
|
||||
@ -263,6 +266,8 @@ SRC_COMMON_HAL_ALL = \
|
||||
busio/SPI.c \
|
||||
busio/UART.c \
|
||||
busio/__init__.c \
|
||||
countio/Counter.c \
|
||||
countio/__init__.c \
|
||||
digitalio/DigitalInOut.c \
|
||||
digitalio/__init__.c \
|
||||
displayio/ParallelBus.c \
|
||||
|
@ -314,6 +314,13 @@ extern const struct _mp_obj_module_t busio_module;
|
||||
#define BUSIO_MODULE
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_COUNTIO
|
||||
extern const struct _mp_obj_module_t countio_module;
|
||||
#define COUNTIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_countio), (mp_obj_t)&countio_module },
|
||||
#else
|
||||
#define COUNTIO_MODULE
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_DIGITALIO
|
||||
extern const struct _mp_obj_module_t digitalio_module;
|
||||
#define DIGITALIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_digitalio), (mp_obj_t)&digitalio_module },
|
||||
@ -630,6 +637,7 @@ extern const struct _mp_obj_module_t ustack_module;
|
||||
BLEIO_MODULE \
|
||||
BOARD_MODULE \
|
||||
BUSIO_MODULE \
|
||||
COUNTIO_MODULE \
|
||||
DIGITALIO_MODULE \
|
||||
DISPLAYIO_MODULE \
|
||||
FONTIO_MODULE \
|
||||
|
@ -109,6 +109,12 @@ CIRCUITPY_DIGITALIO = 1
|
||||
endif
|
||||
CFLAGS += -DCIRCUITPY_DIGITALIO=$(CIRCUITPY_DIGITALIO)
|
||||
|
||||
ifndef CIRCUITPY_COUNTIO
|
||||
CIRCUITPY_COUNTIO = 1
|
||||
endif
|
||||
CFLAGS += -DCIRCUITPY_COUNTIO=$(CIRCUITPY_COUNTIO)
|
||||
|
||||
|
||||
ifndef CIRCUITPY_DISPLAYIO
|
||||
CIRCUITPY_DISPLAYIO = $(CIRCUITPY_FULL_BUILD)
|
||||
endif
|
||||
@ -207,6 +213,11 @@ CIRCUITPY_ROTARYIO = 1
|
||||
endif
|
||||
CFLAGS += -DCIRCUITPY_ROTARYIO=$(CIRCUITPY_ROTARYIO)
|
||||
|
||||
ifndef CIRCUITPY_COUNTIO
|
||||
CIRCUITPY_COUNTIO = 1
|
||||
endif
|
||||
CFLAGS += -DCIRCUITPY_COUNTIO=$(CIRCUITPY_COUNTIO)
|
||||
|
||||
ifndef CIRCUITPY_RTC
|
||||
CIRCUITPY_RTC = 1
|
||||
endif
|
||||
|
152
shared-bindings/countio/Counter.c
Normal file
152
shared-bindings/countio/Counter.c
Normal file
@ -0,0 +1,152 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#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/countio/Counter.h"
|
||||
#include "shared-bindings/util.h"
|
||||
|
||||
//| .. currentmodule:: countio
|
||||
//|
|
||||
//| :class:`Counter` -- Track the count of edge transistions (pulses) on a given pin
|
||||
//| ====================================================================================
|
||||
//|
|
||||
//| Counter will keep track of the number of edge transistions (pulses) on a given pin
|
||||
//|
|
||||
//| .. class:: Counter(pin_a)
|
||||
//|
|
||||
//| Create an Counter object associated with the given pin. It tracks the number of
|
||||
//| pulses relative when the object is contructed.
|
||||
//|
|
||||
//| :param ~microcontroller.Pin pin_a: Pin to read pulses from.
|
||||
//|
|
||||
//|
|
||||
//| For example::
|
||||
//|
|
||||
//| import countio
|
||||
//| import time
|
||||
//| from board import *
|
||||
//|
|
||||
//| pin_counter = countio.Counter(board.D1)
|
||||
//|
|
||||
//| while True:
|
||||
//| count = pin_counter.count
|
||||
//| if count == None 10:
|
||||
//| pin_counter.reset()
|
||||
//| print(pin_counter.count)
|
||||
//|
|
||||
STATIC mp_obj_t countio_counter_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_pin_a };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_pin_a, MP_ARG_REQUIRED | MP_ARG_OBJ }
|
||||
|
||||
};
|
||||
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);
|
||||
|
||||
const mcu_pin_obj_t* pin_a = validate_obj_is_free_pin(args[ARG_pin_a].u_obj);
|
||||
|
||||
|
||||
countio_counter_obj_t *self = m_new_obj(countio_counter_obj_t);
|
||||
self->base.type = &countio_counter_type;
|
||||
|
||||
common_hal_countio_counter_construct(self, pin_a);
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Deinitializes the Counter and releases any hardware resources for reuse.
|
||||
//|
|
||||
STATIC mp_obj_t countio_counter_deinit(mp_obj_t self_in) {
|
||||
countio_counter_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
common_hal_countio_counter_deinit(self);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(countio_counter_deinit_obj, countio_counter_deinit);
|
||||
|
||||
STATIC void check_for_deinit(countio_counter_obj_t *self) {
|
||||
if (common_hal_countio_counter_deinited(self)) {
|
||||
raise_deinited_error();
|
||||
}
|
||||
}
|
||||
|
||||
//| .. 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 countio_counter_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
common_hal_countio_counter_deinit(args[0]);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(countio_counter___exit___obj, 4, 4, countio_counter_obj___exit__);
|
||||
|
||||
|
||||
//| .. attribute:: count
|
||||
//|
|
||||
//| The current count in terms of pulses.
|
||||
//|
|
||||
//|
|
||||
STATIC mp_obj_t countio_counter_obj_get_count(mp_obj_t self_in) {
|
||||
countio_counter_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
|
||||
return mp_obj_new_int(common_hal_countio_counter_get_count(self));
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(countio_counter_get_count_obj, countio_counter_obj_get_count);
|
||||
|
||||
STATIC mp_obj_t countio_counter_obj_set_count(mp_obj_t self_in, mp_obj_t new_count) {
|
||||
countio_counter_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
|
||||
common_hal_countio_counter_set_count(self, mp_obj_get_int(new_count));
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(countio_counter_set_count_obj, countio_counter_obj_set_count);
|
||||
|
||||
const mp_obj_property_t countio_counter_count_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = {(mp_obj_t)&countio_counter_get_count_obj,
|
||||
(mp_obj_t)&countio_counter_set_count_obj,
|
||||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
STATIC mp_obj_t countio_counter_reset(mp_obj_t self_in){
|
||||
countio_counter_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
//set the position to zero for reset
|
||||
common_hal_countio_counter_reset(self);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(countio_counter_reset_obj, countio_counter_reset);
|
||||
|
||||
STATIC const mp_rom_map_elem_t countio_counter_locals_dict_table[] = {
|
||||
// Methods
|
||||
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&countio_counter_deinit_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&countio_counter___exit___obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_count), MP_ROM_PTR(&countio_counter_count_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&countio_counter_reset_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(countio_counter_locals_dict, countio_counter_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t countio_counter_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_Counter,
|
||||
.make_new = countio_counter_make_new,
|
||||
.locals_dict = (mp_obj_dict_t*)&countio_counter_locals_dict,
|
||||
};
|
18
shared-bindings/countio/Counter.h
Normal file
18
shared-bindings/countio/Counter.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_COUNTIO_COUNTER_H
|
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_COUNTIO_COUNTER_H
|
||||
|
||||
#include "common-hal/microcontroller/Pin.h"
|
||||
#include "common-hal/countio/Counter.h"
|
||||
|
||||
extern const mp_obj_type_t countio_counter_type;
|
||||
|
||||
extern void common_hal_countio_counter_construct(countio_counter_obj_t* self,
|
||||
const mcu_pin_obj_t* pin_a);
|
||||
extern void common_hal_countio_counter_deinit(countio_counter_obj_t* self);
|
||||
extern bool common_hal_countio_counter_deinited(countio_counter_obj_t* self);
|
||||
extern mp_int_t common_hal_countio_counter_get_count(countio_counter_obj_t* self);
|
||||
extern void common_hal_countio_counter_set_count(countio_counter_obj_t* self,
|
||||
mp_int_t new_count);
|
||||
extern void common_hal_countio_counter_reset(countio_counter_obj_t* self);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_COUNTIO_COUNTER_H
|
48
shared-bindings/countio/__init__.c
Normal file
48
shared-bindings/countio/__init__.c
Normal file
@ -0,0 +1,48 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-bindings/countio/__init__.h"
|
||||
#include "shared-bindings/countio/Counter.h"
|
||||
|
||||
//| :mod:`countio` --- Support for edge counting
|
||||
//| ========================================================
|
||||
//|
|
||||
//| .. module:: countio
|
||||
//| :synopsis: Support for edge counting
|
||||
//| :platform: SAMD
|
||||
//|
|
||||
//| The `countio` module contains logic to read and count edge transistions
|
||||
//|
|
||||
//| Libraries
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| Counter
|
||||
//|
|
||||
|
||||
//| .. warning:: This module is not available in some SAMD21 (aka M0) 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.
|
||||
//|
|
||||
|
||||
STATIC const mp_rom_map_elem_t countio_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_countio) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_Counter), MP_ROM_PTR(&countio_counter_type) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(countio_module_globals, countio_module_globals_table);
|
||||
|
||||
const mp_obj_module_t countio_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&countio_module_globals,
|
||||
};
|
9
shared-bindings/countio/__init__.h
Normal file
9
shared-bindings/countio/__init__.h
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_COUNTIO___INIT___H
|
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_COUNTIO___INIT___H
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
// Nothing now.
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_COUNTIO___INIT___H
|
Loading…
Reference in New Issue
Block a user