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
67 lines
1.7 KiB
C
67 lines
1.7 KiB
C
|
|
#include "common-hal/countio/Counter.h"
|
|
#include "nrfx_gpiote.h"
|
|
|
|
// obj array to map pin number -> self since nrfx hide the mapping
|
|
static countio_counter_obj_t *_countio_objs[NUMBER_OF_PINS];
|
|
|
|
static void _intr_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
|
|
countio_counter_obj_t *self = _countio_objs[pin];
|
|
if (!self) {
|
|
return;
|
|
}
|
|
self->count += 1;
|
|
}
|
|
|
|
void common_hal_countio_counter_construct(countio_counter_obj_t *self,
|
|
const mcu_pin_obj_t *pin_a) {
|
|
|
|
self->pin_a = pin_a->number;
|
|
_countio_objs[self->pin_a] = self;
|
|
|
|
self->count = 0;
|
|
|
|
nrfx_gpiote_in_config_t cfg = {
|
|
.sense = NRF_GPIOTE_POLARITY_HITOLO,
|
|
.pull = NRF_GPIO_PIN_PULLUP,
|
|
.is_watcher = false,
|
|
.hi_accuracy = true,
|
|
.skip_gpio_setup = false
|
|
};
|
|
|
|
nrfx_gpiote_in_init(self->pin_a, &cfg, _intr_handler);
|
|
nrfx_gpiote_in_event_enable(self->pin_a, true);
|
|
|
|
claim_pin(pin_a);
|
|
|
|
}
|
|
|
|
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;
|
|
}
|
|
_countio_objs[self->pin_a] = NULL;
|
|
|
|
nrfx_gpiote_in_event_disable(self->pin_a);
|
|
nrfx_gpiote_in_uninit(self->pin_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;
|
|
}
|