e95e921ca1
In #4683, tannewt noticed that uncrustify was not running on some file in common-hal. I investigated and found that it was not being run on a bunch of paths. Rather than make incremental changes, I rewrote list_files to work bsaed on regular expressions; these regular expressions are created from the same git-style glob patterns. I spot-checked some specific filenames after this change, and all looks good: ``` $ python3 tools/codeformat.py -v --dry-run tests/basics/int_small.py ports/raspberrypi/common-hal/pulseio/PulseIn.c extmod/virtpin.c tests/thread/thread_exit1.py ports/raspberrypi/background.h extmod/re1.5/recursiveloop.c tools/codeformat.py -v --dry-run tests/basics/int_small.py ports/raspberrypi/common-hal/pulseio/PulseIn.c extmod/virtpin.c tests/thread/thread_exit1.py ports/raspberrypi/background.h extmod/re1.5/recursiveloop.c uncrustify -c /home/jepler/src/circuitpython/tools/uncrustify.cfg -lC --no-backup extmod/virtpin.c ports/raspberrypi/background.h ports/raspberrypi/common-hal/pulseio/PulseIn.c black --fast --line-length=99 -v tests/thread/thread_exit1.py ``` recursiveloop and int_small are excluded, while PulseIn, virtpin, and background are included. Testing running from a subdirectory (not _specifically_ supported though): ``` (cd ports && python3 ../tools/codeformat.py -v --dry-run raspberrypi/common-hal/pulseio/PulseIn.c ../extmod/virtpin.c) ../tools/codeformat.py -v --dry-run raspberrypi/common-hal/pulseio/PulseIn.c ../extmod/virtpin.c uncrustify -c /home/jepler/src/circuitpython/tools/uncrustify.cfg -lC --no-backup ../extmod/virtpin.c raspberrypi/common-hal/pulseio/PulseIn. ``` As a side-effect, a bunch more files are re-formatted now. :-P
84 lines
2.1 KiB
C
84 lines
2.1 KiB
C
|
|
#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;
|
|
|
|
}
|