From 62381d8582749dc2672a65cb6e7c5b8a404a3b45 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 6 Nov 2022 19:30:27 -0800 Subject: [PATCH] samd21: Stub out exti code Signed-off-by: Keith Packard --- src/samd21/ao_exti_samd21.c | 163 ++++++++++++++++++++++++++++++++++++ src/samd21/samd21.h | 22 +++++ 2 files changed, 185 insertions(+) create mode 100644 src/samd21/ao_exti_samd21.c diff --git a/src/samd21/ao_exti_samd21.c b/src/samd21/ao_exti_samd21.c new file mode 100644 index 00000000..aa865cc2 --- /dev/null +++ b/src/samd21/ao_exti_samd21.c @@ -0,0 +1,163 @@ +/* + * Copyright © 2022 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include +#include + +struct samd21_exti { + void (*callback)(void); + uint8_t port; + uint8_t pin; +}; + +#if 0 +static struct samd21_exti ao_samd_exti[SAMD21_NUM_EVSYS]; + +static uint32_t ao_exti_inuse; +#endif + +void +samd21_evsys_isr(void) +{ +} + +void +ao_exti_setup (struct samd21_port *port, uint8_t pin, uint8_t mode, void (*callback)(void)) +{ + (void) port; + (void) pin; + (void) mode; + (void) callback; +#if 0 + uint8_t id = pin_id(port,pin); + uint8_t pint; + uint8_t mask; + uint8_t prio; + + for (pint = 0; pint < SAMD21_NUM_EVSYS; pint++) + if ((ao_exti_inuse & (1 << pint)) == 0) + break; + + if (pint == SAMD21_NUM_EVSYS) + ao_panic(AO_PANIC_EXTI); + + if (!(mode & AO_EXTI_PIN_NOCONFIGURE)) + ao_enable_input(port, pin, mode); + + ao_arch_block_interrupts(); + mask = (1 << pint); + ao_exti_inuse |= mask; + ao_pint_enabled &= (uint8_t) ~mask; + + ao_pint_map[id] = pint; + ao_exti_callback[pint] = callback; + + /* configure gpio to interrupt routing */ + lpc_scb.pintsel[pint] = id; + + /* Set edge triggered */ + lpc_gpio_pin.isel &= ~mask; + + ao_pint_enabled &= (uint8_t) ~mask; + ao_pint_mode[pint] = mode; + _ao_exti_set_enable(pint); + + /* Set interrupt mask and rising/falling mode */ + + prio = AO_LPC_NVIC_MED_PRIORITY; + if (mode & AO_EXTI_PRIORITY_LOW) + prio = AO_LPC_NVIC_LOW_PRIORITY; + else if (mode & AO_EXTI_PRIORITY_HIGH) + prio = AO_LPC_NVIC_HIGH_PRIORITY; + + /* Set priority and enable */ + lpc_nvic_set_priority(LPC_ISR_PIN_INT0_POS + pint, prio); + lpc_nvic_set_enable(LPC_ISR_PIN_INT0_POS + pint); + ao_arch_release_interrupts(); +#endif +} + +void +ao_exti_set_mode(struct samd21_port *port, uint8_t pin, uint8_t mode) +{ + (void) port; + (void) pin; + (void) mode; +#if 0 + uint8_t id = pin_id(port,pin); + uint8_t pint = ao_pint_map[id]; + + ao_arch_block_interrupts(); + ao_pint_mode[pint] = mode; + _ao_exti_set_enable(pint); + ao_arch_release_interrupts(); +#endif +} + +void +ao_exti_set_callback(struct samd21_port *port, uint8_t pin, void (*callback)(void)) +{ + (void) port; + (void) pin; + (void) callback; +#if 0 + uint8_t id = pin_id(port,pin); + uint8_t pint = ao_pint_map[id]; + + ao_exti_callback[pint] = callback; +#endif +} + +void +ao_exti_enable(struct samd21_port *port, uint8_t pin) +{ + (void) port; + (void) pin; +#if 0 + uint8_t id = pin_id(port,pin); + uint8_t pint = ao_pint_map[id]; + uint8_t mask = 1 << pint; + + ao_arch_block_interrupts(); + ao_pint_enabled |= mask; + _ao_exti_set_enable(pint); + ao_arch_release_interrupts(); +#endif +} + +void +ao_exti_disable(struct samd21_port *port, uint8_t pin) +{ + (void) port; + (void) pin; +#if 0 + uint8_t id = pin_id(port,pin); + uint8_t pint = ao_pint_map[id]; + uint8_t mask = 1 << pint; + + ao_arch_block_interrupts(); + ao_pint_enabled &= (uint8_t) ~mask; + _ao_exti_set_enable(pint); + ao_arch_release_interrupts(); +#endif +} + +void +ao_exti_init(void) +{ +} diff --git a/src/samd21/samd21.h b/src/samd21/samd21.h index cd9d2d34..331fb723 100644 --- a/src/samd21/samd21.h +++ b/src/samd21/samd21.h @@ -1373,6 +1373,28 @@ samd21_usb_ep_curbk(uint8_t ep) return (samd21_usb.ep[ep].epstatus >> SAMD21_USB_EP_EPSTATUS_CURBK) & 1; } +/* evsys */ + +struct samd21_evsys { + vuint8_t ctrl; + vuint8_t reserved_01; + vuint16_t reserved_02; + vuint32_t channel; + vuint16_t user; + vuint16_t reserved_0a; + vuint32_t chstatus; + + vuint32_t intenclr; + vuint32_t intenset; + vuint32_t intflag; +}; + +extern struct samd21_evsys samd21_evsys; + +#define SAMD21_NUM_EVSYS 16 + +#define samd21_evsys (*(struct samd21_evsys *) 0x42000400) + /* sercom */ struct samd21_sercom { -- 2.30.2