Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb5bc8b3

Browse files
authored
Merge pull requestadafruit#1745 from dhalbert/rotaryio-typo-eic-refactor
ROTARYIO_MODULE typo; EIC interrupt handler refactor
2 parents35cfc61 +682e83a commitb5bc8b3

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
voidpulsein_interrupt_handler(uint8_tchannel) {
@@ -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
boolcommon_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+
staticuint8_teic_channel_handler[EIC_EXTINT_NUM];
35+
36+
voidset_eic_handler(uint8_tchannel,uint8_teic_handler) {
37+
eic_channel_handler[channel]=eic_handler;
38+
}
39+
40+
voidshared_eic_handler(uint8_tchannel) {
41+
uint8_thandler=eic_channel_handler[channel];
42+
switch (handler) {
43+
#ifCIRCUITPY_PULSEIO
44+
caseEIC_HANDLER_PULSEIN:
45+
pulsein_interrupt_handler(channel);
46+
break;
47+
#endif
48+
49+
#ifCIRCUITPY_ROTARYIO
50+
caseEIC_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+
#ifndefMICROPY_INCLUDED_ATMEL_SAMD_EIC_HANDLER_H
27+
#defineMICROPY_INCLUDED_ATMEL_SAMD_EIC_HANDLER_H
28+
29+
#defineEIC_HANDLER_NO_INTERRUPT 0x0
30+
#defineEIC_HANDLER_PULSEIN 0x1
31+
#defineEIC_HANDLER_INCREMENTAL_ENCODER 0x2
32+
33+
voidset_eic_handler(uint8_tchannel,uint8_teic_handler);
34+
voidshared_eic_handler(uint8_tchannel);
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
#defineOS_MODULE_ALT_NAME
361361
#endif
362362

363+
#ifCIRCUITPY_PEW
364+
externconststruct_mp_obj_module_tpew_module;
365+
#definePEW_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR__pew),(mp_obj_t)&pew_module },
366+
#else
367+
#definePEW_MODULE
368+
#endif
369+
363370
#ifCIRCUITPY_PIXELBUF
364371
externconststruct_mp_obj_module_tpixelbuf_module;
365372
#definePIXELBUF_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
#defineUSTACK_MODULE
475482
#endif
476483

477-
#ifCIRCUITPY_PEW
478-
externconststruct_mp_obj_module_tpew_module;
479-
#definePEW_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR__pew),(mp_obj_t)&pew_module },
480-
#else
481-
#definePEW_MODULE
482-
#endif
483-
484484
// These modules are not yet in shared-bindings, but we prefer the non-uxxx names.
485485
#ifMICROPY_PY_UERRNO
486486
#defineERRNO_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)

[8]ページ先頭

©2009-2025 Movatter.jp