Skip to content

Commit b5bc8b3

Browse files
authored
Merge pull request adafruit#1745 from dhalbert/rotaryio-typo-eic-refactor
ROTARYIO_MODULE typo; EIC interrupt handler refactor
2 parents 35cfc61 + 682e83a commit b5bc8b3

File tree

9 files changed

+122
-11
lines changed

9 files changed

+122
-11
lines changed

ports/atmel-samd/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ SRC_C = \
212212
bindings/samd/__init__.c \
213213
boards/$(BOARD)/board.c \
214214
boards/$(BOARD)/pins.c \
215+
eic_handler.c \
215216
fatfs_port.c \
216217
freetouch/adafruit_ptc.c \
217218
lib/libc/string0.c \

ports/atmel-samd/boards/pewpew10/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ CIRCUITPY_PEW = 1
1616
CIRCUITPY_ANALOGIO = 1
1717
CIRCUITPY_MATH = 1
1818
CIRCUITPY_NEOPIXEL_WRITE = 1
19+
CIRCUITPY_ROTARYIO = 0
1920
CIRCUITPY_RTC = 0
2021
CIRCUITPY_SAMD = 0
2122
CIRCUITPY_USB_MIDI = 0

ports/atmel-samd/boards/pirkey_m0/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ LONGINT_IMPL = NONE
1313
CIRCUITPY_ANALOGIO = 0
1414
CIRCUITPY_MATH = 0
1515
CIRCUITPY_NEOPIXEL_WRITE = 0
16+
CIRCUITPY_ROTARYIO = 0
1617
CIRCUITPY_RTC = 0
1718
CIRCUITPY_SAMD = 0
1819
CIRCUITPY_USB_MIDI = 0

ports/atmel-samd/common-hal/pulseio/PulseIn.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "hal/include/hal_gpio.h"
3333

3434
#include "background.h"
35+
#include "eic_handler.h"
3536
#include "mpconfigport.h"
3637
#include "py/gc.h"
3738
#include "py/runtime.h"
@@ -54,7 +55,8 @@ static void pulsein_set_config(pulseio_pulsein_obj_t* self, bool first_edge) {
5455
} else {
5556
sense_setting = EIC_CONFIG_SENSE0_RISE_Val;
5657
}
57-
turn_on_eic_channel(self->channel, sense_setting, EIC_HANDLER_PULSEIN);
58+
set_eic_handler(self->channel, EIC_HANDLER_PULSEIN);
59+
turn_on_eic_channel(self->channel, sense_setting);
5860
}
5961

6062
void pulsein_interrupt_handler(uint8_t channel) {
@@ -153,6 +155,7 @@ void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t* self) {
153155
if (common_hal_pulseio_pulsein_deinited(self)) {
154156
return;
155157
}
158+
set_eic_handler(self->channel, EIC_HANDLER_NO_INTERRUPT);
156159
turn_off_eic_channel(self->channel);
157160
reset_pin_number(self->pin);
158161
self->pin = NO_PIN;

ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "atmel_start_pins.h"
3030

31+
#include "eic_handler.h"
3132
#include "samd/external_interrupts.h"
3233
#include "py/runtime.h"
3334
#include "supervisor/shared/translate.h"
@@ -76,8 +77,11 @@ void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencode
7677
claim_pin(pin_a);
7778
claim_pin(pin_b);
7879

79-
turn_on_eic_channel(self->eic_channel_a, EIC_CONFIG_SENSE0_BOTH_Val, EIC_HANDLER_INCREMENTAL_ENCODER);
80-
turn_on_eic_channel(self->eic_channel_b, EIC_CONFIG_SENSE0_BOTH_Val, EIC_HANDLER_INCREMENTAL_ENCODER);
80+
set_eic_handler(self->eic_channel_a, EIC_HANDLER_INCREMENTAL_ENCODER);
81+
turn_on_eic_channel(self->eic_channel_a, EIC_CONFIG_SENSE0_BOTH_Val);
82+
83+
set_eic_handler(self->eic_channel_b, EIC_HANDLER_INCREMENTAL_ENCODER);
84+
turn_on_eic_channel(self->eic_channel_b, EIC_CONFIG_SENSE0_BOTH_Val);
8185
}
8286

8387
bool common_hal_rotaryio_incrementalencoder_deinited(rotaryio_incrementalencoder_obj_t* self) {
@@ -88,10 +92,16 @@ void common_hal_rotaryio_incrementalencoder_deinit(rotaryio_incrementalencoder_o
8892
if (common_hal_rotaryio_incrementalencoder_deinited(self)) {
8993
return;
9094
}
95+
96+
set_eic_handler(self->eic_channel_a, EIC_HANDLER_NO_INTERRUPT);
9197
turn_off_eic_channel(self->eic_channel_a);
98+
99+
set_eic_handler(self->eic_channel_b, EIC_HANDLER_NO_INTERRUPT);
92100
turn_off_eic_channel(self->eic_channel_b);
101+
93102
reset_pin_number(self->pin_a);
94103
self->pin_a = NO_PIN;
104+
95105
reset_pin_number(self->pin_b);
96106
self->pin_b = NO_PIN;
97107
}

ports/atmel-samd/eic_handler.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 Dan Halbert for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "common-hal/pulseio/PulseIn.h"
28+
#include "common-hal/rotaryio/IncrementalEncoder.h"
29+
#include "shared-bindings/microcontroller/__init__.h"
30+
//#include "samd/external_interrupts.h"
31+
#include "eic_handler.h"
32+
33+
// Which handler should be called for a particular channel?
34+
static uint8_t eic_channel_handler[EIC_EXTINT_NUM];
35+
36+
void set_eic_handler(uint8_t channel, uint8_t eic_handler) {
37+
eic_channel_handler[channel] = eic_handler;
38+
}
39+
40+
void shared_eic_handler(uint8_t channel) {
41+
uint8_t handler = eic_channel_handler[channel];
42+
switch (handler) {
43+
#if CIRCUITPY_PULSEIO
44+
case EIC_HANDLER_PULSEIN:
45+
pulsein_interrupt_handler(channel);
46+
break;
47+
#endif
48+
49+
#if CIRCUITPY_ROTARYIO
50+
case EIC_HANDLER_INCREMENTAL_ENCODER:
51+
incrementalencoder_interrupt_handler(channel);
52+
break;
53+
#endif
54+
55+
default:
56+
break;
57+
}
58+
}

ports/atmel-samd/eic_handler.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 Dan Halbert for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_EIC_HANDLER_H
27+
#define MICROPY_INCLUDED_ATMEL_SAMD_EIC_HANDLER_H
28+
29+
#define EIC_HANDLER_NO_INTERRUPT 0x0
30+
#define EIC_HANDLER_PULSEIN 0x1
31+
#define EIC_HANDLER_INCREMENTAL_ENCODER 0x2
32+
33+
void set_eic_handler(uint8_t channel, uint8_t eic_handler);
34+
void shared_eic_handler(uint8_t channel);
35+
36+
#endif // MICROPY_INCLUDED_ATMEL_SAMD_EIC_HANDLER_H

py/circuitpy_mpconfig.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,13 @@ extern const struct _mp_obj_module_t os_module;
360360
#define OS_MODULE_ALT_NAME
361361
#endif
362362

363+
#if CIRCUITPY_PEW
364+
extern const struct _mp_obj_module_t pew_module;
365+
#define PEW_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR__pew),(mp_obj_t)&pew_module },
366+
#else
367+
#define PEW_MODULE
368+
#endif
369+
363370
#if CIRCUITPY_PIXELBUF
364371
extern const struct _mp_obj_module_t pixelbuf_module;
365372
#define PIXELBUF_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR__pixelbuf),(mp_obj_t)&pixelbuf_module },
@@ -474,13 +481,6 @@ extern const struct _mp_obj_module_t ustack_module;
474481
#define USTACK_MODULE
475482
#endif
476483

477-
#if CIRCUITPY_PEW
478-
extern const struct _mp_obj_module_t pew_module;
479-
#define PEW_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR__pew),(mp_obj_t)&pew_module },
480-
#else
481-
#define PEW_MODULE
482-
#endif
483-
484484
// These modules are not yet in shared-bindings, but we prefer the non-uxxx names.
485485
#if MICROPY_PY_UERRNO
486486
#define ERRNO_MODULE { MP_ROM_QSTR(MP_QSTR_errno), MP_ROM_PTR(&mp_module_uerrno) },
@@ -546,6 +546,7 @@ extern const struct _mp_obj_module_t pew_module;
546546
PULSEIO_MODULE \
547547
RANDOM_MODULE \
548548
RE_MODULE \
549+
ROTARYIO_MODULE \
549550
RTC_MODULE \
550551
SAMD_MODULE \
551552
STAGE_MODULE \

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy