Skip to content

Commit dafc370

Browse files
committed
moves 'shared_timer_handler' back to atmel-samd from samd-peripherals
1 parent 90bc09a commit dafc370

5 files changed

Lines changed: 95 additions & 4 deletions

File tree

ports/atmel-samd/common-hal/audioio/AudioOut.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#endif
4848

4949
#include "audio_dma.h"
50+
#include "timer_handler.h"
5051

5152
#include "samd/dma.h"
5253
#include "samd/events.h"
@@ -251,7 +252,7 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self,
251252
tc_gclk = 1;
252253
#endif
253254

254-
turn_on_clocks(true, tc_index, tc_gclk);
255+
turn_on_clocks(true, tc_index, tc_gclk, TC_HANDLER_NO_INTERRUPT);
255256

256257
// Don't bother setting the period. We set it before you playback anything.
257258
tc_set_enable(t, false);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "common-hal/pulseio/PWMOut.h"
3232
#include "shared-bindings/pulseio/PWMOut.h"
3333
#include "shared-bindings/microcontroller/Processor.h"
34+
#include "timer_handler.h"
3435

3536
#include "atmel_start_pins.h"
3637
#include "hal/utils/include/utils_repeat_macro.h"
@@ -235,7 +236,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
235236
}
236237

237238
// We use the zeroeth clock on either port to go full speed.
238-
turn_on_clocks(timer->is_tc, timer->index, 0);
239+
turn_on_clocks(timer->is_tc, timer->index, 0, TC_HANDLER_NO_INTERRUPT);
239240

240241
if (timer->is_tc) {
241242
tc_periods[timer->index] = top;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "py/runtime.h"
3838
#include "shared-bindings/pulseio/PulseOut.h"
3939
#include "supervisor/shared/translate.h"
40+
#include "timer_handler.h"
4041

4142
// This timer is shared amongst all PulseOut objects under the assumption that
4243
// the code is single threaded.
@@ -115,10 +116,10 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self,
115116
// We use GCLK0 for SAMD21 and GCLK1 for SAMD51 because they both run at 48mhz making our
116117
// math the same across the boards.
117118
#ifdef SAMD21
118-
turn_on_clocks(true, index, 0);
119+
turn_on_clocks(true, index, 0, TC_HANDLER_PULSEOUT);
119120
#endif
120121
#ifdef SAMD51
121-
turn_on_clocks(true, index, 1);
122+
turn_on_clocks(true, index, 1, TC_HANDLER_PULSEOUT);
122123
#endif
123124

124125

ports/atmel-samd/timer_handler.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2017 Scott Shawcroft 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 <stdbool.h>
28+
#include <stdint.h>
29+
30+
#include "timer_handler.h"
31+
32+
#include "common-hal/pulseio/PulseOut.h"
33+
#include "common-hal/pulseio/FrequencyIn.h"
34+
35+
static uint8_t tc_handler[TC_INST_NUM];
36+
37+
void set_timer_handler(uint8_t index, uint8_t timer_handler) {
38+
tc_handler[index] = timer_handler;
39+
}
40+
41+
void shared_timer_handler(bool is_tc, uint8_t index) {
42+
// Add calls to interrupt handlers for specific functionality here.
43+
// Make sure to add the handler #define to timer_handler.h
44+
if (is_tc) {
45+
uint8_t handler = tc_handler[index];
46+
if (handler == TC_HANDLER_PULSEOUT) {
47+
pulseout_interrupt_handler(index);
48+
} else if (handler == TC_HANDLER_FREQUENCYIN) {
49+
frequencyin_interrupt_handler(index);
50+
}
51+
}
52+
}

ports/atmel-samd/timer_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) 2018 Scott Shawcroft 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_TIMER_HANDLER_H
27+
#define MICROPY_INCLUDED_ATMEL_SAMD_TIMER_HANDLER_H
28+
29+
#define TC_HANDLER_NO_INTERRUPT 0x0
30+
#define TC_HANDLER_PULSEOUT 0x1
31+
#define TC_HANDLER_FREQUENCYIN 0x2
32+
33+
void set_timer_handler(uint8_t index, uint8_t timer_handler);
34+
void shared_timer_handler(bool is_tc, uint8_t index);
35+
36+
#endif // MICROPY_INCLUDED_ATMEL_SAMD_TIMER_HANDLER_H

0 commit comments

Comments
 (0)