Skip to content

Switch SAMD21 ticks to PER event #5100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/utils/pyexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
mp_hal_stdout_tx_strn("\x04", 1);
}
// check for SystemExit
if (mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(((mp_obj_base_t *)nlr.ret_val)->type), MP_OBJ_FROM_PTR(&mp_type_SystemExit))) {
if (mp_obj_is_subclass_fast(mp_obj_get_type((mp_obj_t)nlr.ret_val), MP_OBJ_FROM_PTR(&mp_type_SystemExit))) {
// at the moment, the value of SystemExit is unused
ret = pyexec_system_exit;
#if CIRCUITPY_ALARM
Expand Down
30 changes: 4 additions & 26 deletions ports/atmel-samd/audio_dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,13 @@ audio_dma_result audio_dma_setup_playback(audio_dma_t *dma,

#ifdef SAM_D5X_E5X
int irq = dma->event_channel < 4 ? EVSYS_0_IRQn + dma->event_channel : EVSYS_4_IRQn;
// Only disable and clear on SAMD51 because the SAMD21 shares EVSYS with ticks.
NVIC_DisableIRQ(irq);
NVIC_ClearPendingIRQ(irq);
#else
int irq = EVSYS_IRQn;
#endif

NVIC_DisableIRQ(irq);
NVIC_ClearPendingIRQ(irq);

DmacDescriptor *first_descriptor = dma_descriptor(dma_channel);
setup_audio_descriptor(first_descriptor, dma->beat_size, output_spacing, output_register_address);
if (single_buffer) {
Expand Down Expand Up @@ -374,7 +374,7 @@ STATIC void dma_callback_fun(void *arg) {
audio_dma_load_next_block(dma);
}

void evsyshandler_common(void) {
void audio_evsys_handler(void) {
for (uint8_t i = 0; i < AUDIO_DMA_CHANNEL_COUNT; i++) {
audio_dma_t *dma = audio_dma_state[i];
if (dma == NULL) {
Expand All @@ -388,26 +388,4 @@ void evsyshandler_common(void) {
}
}

#ifdef SAM_D5X_E5X
void EVSYS_0_Handler(void) {
evsyshandler_common();
}
void EVSYS_1_Handler(void) {
evsyshandler_common();
}
void EVSYS_2_Handler(void) {
evsyshandler_common();
}
void EVSYS_3_Handler(void) {
evsyshandler_common();
}
void EVSYS_4_Handler(void) {
evsyshandler_common();
}
#else
void EVSYS_Handler(void) {
evsyshandler_common();
}
#endif

#endif
2 changes: 2 additions & 0 deletions ports/atmel-samd/audio_dma.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,6 @@ void audio_dma_background(void);

uint8_t find_sync_event_channel_raise(void);

void audio_evsys_handler(void);

#endif // MICROPY_INCLUDED_ATMEL_SAMD_AUDIO_DMA_H
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define MICROPY_HW_MCU_NAME "samd21e18"

#define MICROPY_HW_NEOPIXEL (&pin_PA15)
#define MICROPY_HW_NEOPIXEL_COUNT (2)

#define IGNORE_PIN_PA01 1
#define IGNORE_PIN_PA02 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ CIRCUITPY_FULL_BUILD = 0
CIRCUITPY_ANALOGIO = 0
CIRCUITPY_AUDIOCORE = 0
CIRCUITPY_BUSIO_SPI = 0
CIRCUITPY_BUSIO_UART = 0
CIRCUITPY_PULSEIO = 0
CIRCUITPY_PWMIO = 0
CIRCUITPY_ROTARYIO = 0
Expand Down
13 changes: 13 additions & 0 deletions ports/atmel-samd/boards/arduino_mkr1300/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,16 @@
// USB is always used internally so skip the pin objects for it.
#define IGNORE_PIN_PA24 1
#define IGNORE_PIN_PA25 1
// USD ID
#define IGNORE_PIN_PA18 1

// Hooked to the external crystal
#define IGNORE_PIN_PA00 1
#define IGNORE_PIN_PA01 1

// SWD only
#define IGNORE_PIN_PA30 1
#define IGNORE_PIN_PA31 1

// Not connected
#define IGNORE_PIN_PA28 1
8 changes: 8 additions & 0 deletions ports/atmel-samd/boards/arduino_nano_33_iot/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@
// USB is always used internally so skip the pin objects for it.
#define IGNORE_PIN_PA24 1
#define IGNORE_PIN_PA25 1

// Not connected
#define IGNORE_PIN_PA00 1
#define IGNORE_PIN_PA01 1

// SWD only
#define IGNORE_PIN_PA30 1
#define IGNORE_PIN_PA31 1
6 changes: 6 additions & 0 deletions ports/atmel-samd/common-hal/pulseio/PulseIn.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t *self) {
void common_hal_pulseio_pulsein_pause(pulseio_pulsein_obj_t *self) {
uint32_t mask = 1 << self->channel;
EIC->INTENCLR.reg = mask << EIC_INTENSET_EXTINT_Pos;
#ifdef SAMD21
rtc_end_pulse();
#endif
}

void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t *self,
Expand Down Expand Up @@ -299,6 +302,9 @@ void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t *self,
EIC->INTFLAG.reg = mask << EIC_INTFLAG_EXTINT_Pos;
EIC->INTENSET.reg = mask << EIC_INTENSET_EXTINT_Pos;

#ifdef SAMD21
rtc_start_pulse();
#endif
pulsein_set_config(self, true);
}

Expand Down
Loading