Skip to content

Commit cdd77b5

Browse files
committed
remove CPy-specific EIC handlers from samd-peripherals
1 parent c9571fe commit cdd77b5

File tree

6 files changed

+108
-4
lines changed

6 files changed

+108
-4
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/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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
case EIC_HANDLER_PULSEIN:
44+
pulsein_interrupt_handler(channel);
45+
break;
46+
47+
case EIC_HANDLER_INCREMENTAL_ENCODER:
48+
incrementalencoder_interrupt_handler(channel);
49+
break;
50+
51+
default:
52+
break;
53+
}
54+
}

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

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