[STM32] Removed exti.c from f1 and made global exti.c usable.
Because most changes are internal to a function in exti.c I am leaving the macro checks in there, otherwise we would end up with a bunch of code duplication if we used the dispatch system used otherwise throughout the stm32 part of the library. I bet it could be split up into more granular functions resulting in more generic code that we could run through the dispatch system. But I am leaving that as an excersize for later.
This commit is contained in:
parent
74eb5ab84a
commit
201c2706b5
@ -22,18 +22,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <libopencm3/stm32/exti.h>
|
#include <libopencm3/stm32/exti.h>
|
||||||
|
#if defined(STM32L1) || defined(STM32F2) || defined(STM32F3) || defined(STM32F4)
|
||||||
#include <libopencm3/stm32/syscfg.h>
|
#include <libopencm3/stm32/syscfg.h>
|
||||||
#if defined(STM32F2)
|
|
||||||
#include <libopencm3/stm32/f2/gpio.h>
|
|
||||||
#elif defined(STM32F3)
|
|
||||||
#include <libopencm3/stm32/f3/gpio.h>
|
|
||||||
#elif defined(STM32F4)
|
|
||||||
#include <libopencm3/stm32/f4/gpio.h>
|
|
||||||
#elif defined(STM32L1)
|
|
||||||
#include <libopencm3/stm32/l1/gpio.h>
|
|
||||||
#else
|
|
||||||
#error "invalid/unknown stm32 family for this code"
|
|
||||||
#endif
|
#endif
|
||||||
|
#include <libopencm3/stm32/gpio.h>
|
||||||
|
|
||||||
void exti_set_trigger(uint32_t extis, exti_trigger_type trig)
|
void exti_set_trigger(uint32_t extis, exti_trigger_type trig)
|
||||||
{
|
{
|
||||||
@ -143,28 +135,44 @@ void exti_select_source(uint32_t exti, uint32_t gpioport)
|
|||||||
case GPIOE:
|
case GPIOE:
|
||||||
bits = 0xb;
|
bits = 0xb;
|
||||||
break;
|
break;
|
||||||
#if !defined(STM32L1)
|
#if defined(STM32F1) || defined(STM32F2) || defined(STM32F3) || defined(STM32F4)
|
||||||
case GPIOF:
|
case GPIOF:
|
||||||
bits = 0xa;
|
bits = 0xa;
|
||||||
break;
|
break;
|
||||||
#if !defined(STM32F3)
|
#endif
|
||||||
|
#if defined(STM32F1) || defined(STM32F2) || defined(STM32F4)
|
||||||
case GPIOG:
|
case GPIOG:
|
||||||
bits = 0x9;
|
bits = 0x9;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#if defined(STM32L1) || defined(STM32F2) || defined(STM32F4)
|
||||||
#if !defined(STM32F3)
|
|
||||||
case GPIOH:
|
case GPIOH:
|
||||||
bits = 0x8;
|
bits = 0x8;
|
||||||
break;
|
break;
|
||||||
#if !defined(STM32L1)
|
#endif
|
||||||
|
#if defined(STM32F2) || defined(STM32F4)
|
||||||
case GPIOI:
|
case GPIOI:
|
||||||
bits = 0x7;
|
bits = 0x7;
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(STM32F1)
|
||||||
|
/* Ensure that only valid EXTI lines are used. */
|
||||||
|
if (exti < EXTI4) {
|
||||||
|
AFIO_EXTICR1 &= ~(0x000F << shift);
|
||||||
|
AFIO_EXTICR1 |= (~bits << shift);
|
||||||
|
} else if (exti < EXTI8) {
|
||||||
|
AFIO_EXTICR2 &= ~(0x000F << shift);
|
||||||
|
AFIO_EXTICR2 |= (~bits << shift);
|
||||||
|
} else if (exti < EXTI12) {
|
||||||
|
AFIO_EXTICR3 &= ~(0x000F << shift);
|
||||||
|
AFIO_EXTICR3 |= (~bits << shift);
|
||||||
|
} else if (exti < EXTI16) {
|
||||||
|
AFIO_EXTICR4 &= ~(0x000F << shift);
|
||||||
|
AFIO_EXTICR4 |= (~bits << shift);
|
||||||
|
}
|
||||||
|
#else
|
||||||
/* Ensure that only valid EXTI lines are used. */
|
/* Ensure that only valid EXTI lines are used. */
|
||||||
if (exti < EXTI4) {
|
if (exti < EXTI4) {
|
||||||
SYSCFG_EXTICR1 &= ~(0x000F << shift);
|
SYSCFG_EXTICR1 &= ~(0x000F << shift);
|
||||||
@ -179,4 +187,5 @@ void exti_select_source(uint32_t exti, uint32_t gpioport)
|
|||||||
SYSCFG_EXTICR4 &= ~(0x000F << shift);
|
SYSCFG_EXTICR4 &= ~(0x000F << shift);
|
||||||
SYSCFG_EXTICR4 |= (~bits << shift);
|
SYSCFG_EXTICR4 |= (~bits << shift);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
@ -1,153 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of the libopencm3 project.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2010 Mark Butler <mbutler@physics.otago.ac.nz>
|
|
||||||
*
|
|
||||||
* This library is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library 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 Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <libopencm3/stm32/exti.h>
|
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
|
||||||
|
|
||||||
void exti_set_trigger(uint32_t extis, exti_trigger_type trig)
|
|
||||||
{
|
|
||||||
switch (trig) {
|
|
||||||
case EXTI_TRIGGER_RISING:
|
|
||||||
EXTI_RTSR |= extis;
|
|
||||||
EXTI_FTSR &= ~extis;
|
|
||||||
break;
|
|
||||||
case EXTI_TRIGGER_FALLING:
|
|
||||||
EXTI_RTSR &= ~extis;
|
|
||||||
EXTI_FTSR |= extis;
|
|
||||||
break;
|
|
||||||
case EXTI_TRIGGER_BOTH:
|
|
||||||
EXTI_RTSR |= extis;
|
|
||||||
EXTI_FTSR |= extis;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void exti_enable_request(uint32_t extis)
|
|
||||||
{
|
|
||||||
/* Enable interrupts. */
|
|
||||||
EXTI_IMR |= extis;
|
|
||||||
|
|
||||||
/* Enable events. */
|
|
||||||
EXTI_EMR |= extis;
|
|
||||||
}
|
|
||||||
|
|
||||||
void exti_disable_request(uint32_t extis)
|
|
||||||
{
|
|
||||||
/* Disable interrupts. */
|
|
||||||
EXTI_IMR &= ~extis;
|
|
||||||
|
|
||||||
/* Disable events. */
|
|
||||||
EXTI_EMR &= ~extis;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Reset the interrupt request by writing a 1 to the corresponding
|
|
||||||
* pending bit register.
|
|
||||||
*/
|
|
||||||
void exti_reset_request(uint32_t extis)
|
|
||||||
{
|
|
||||||
EXTI_PR |= extis;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Check the flag of a given EXTI interrupt.
|
|
||||||
* */
|
|
||||||
uint32_t exti_get_flag_status(uint32_t exti)
|
|
||||||
{
|
|
||||||
return EXTI_PR & exti;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Remap an external interrupt line to the corresponding pin on the
|
|
||||||
* specified GPIO port.
|
|
||||||
*
|
|
||||||
* TODO: This could be rewritten in fewer lines of code.
|
|
||||||
*/
|
|
||||||
void exti_select_source(uint32_t exti, uint32_t gpioport)
|
|
||||||
{
|
|
||||||
uint8_t shift, bits;
|
|
||||||
|
|
||||||
shift = bits = 0;
|
|
||||||
|
|
||||||
switch (exti) {
|
|
||||||
case EXTI0:
|
|
||||||
case EXTI4:
|
|
||||||
case EXTI8:
|
|
||||||
case EXTI12:
|
|
||||||
shift = 0;
|
|
||||||
break;
|
|
||||||
case EXTI1:
|
|
||||||
case EXTI5:
|
|
||||||
case EXTI9:
|
|
||||||
case EXTI13:
|
|
||||||
shift = 4;
|
|
||||||
break;
|
|
||||||
case EXTI2:
|
|
||||||
case EXTI6:
|
|
||||||
case EXTI10:
|
|
||||||
case EXTI14:
|
|
||||||
shift = 8;
|
|
||||||
break;
|
|
||||||
case EXTI3:
|
|
||||||
case EXTI7:
|
|
||||||
case EXTI11:
|
|
||||||
case EXTI15:
|
|
||||||
shift = 12;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (gpioport) {
|
|
||||||
case GPIOA:
|
|
||||||
bits = 0xf;
|
|
||||||
break;
|
|
||||||
case GPIOB:
|
|
||||||
bits = 0xe;
|
|
||||||
break;
|
|
||||||
case GPIOC:
|
|
||||||
bits = 0xd;
|
|
||||||
break;
|
|
||||||
case GPIOD:
|
|
||||||
bits = 0xc;
|
|
||||||
break;
|
|
||||||
case GPIOE:
|
|
||||||
bits = 0xb;
|
|
||||||
break;
|
|
||||||
case GPIOF:
|
|
||||||
bits = 0xa;
|
|
||||||
break;
|
|
||||||
case GPIOG:
|
|
||||||
bits = 0x9;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Ensure that only valid EXTI lines are used. */
|
|
||||||
if (exti < EXTI4) {
|
|
||||||
AFIO_EXTICR1 &= ~(0x000F << shift);
|
|
||||||
AFIO_EXTICR1 |= (~bits << shift);
|
|
||||||
} else if (exti < EXTI8) {
|
|
||||||
AFIO_EXTICR2 &= ~(0x000F << shift);
|
|
||||||
AFIO_EXTICR2 |= (~bits << shift);
|
|
||||||
} else if (exti < EXTI12) {
|
|
||||||
AFIO_EXTICR3 &= ~(0x000F << shift);
|
|
||||||
AFIO_EXTICR3 |= (~bits << shift);
|
|
||||||
} else if (exti < EXTI16) {
|
|
||||||
AFIO_EXTICR4 &= ~(0x000F << shift);
|
|
||||||
AFIO_EXTICR4 |= (~bits << shift);
|
|
||||||
}
|
|
||||||
}
|
|
@ -33,7 +33,7 @@ CFLAGS = -Os -g \
|
|||||||
# ARFLAGS = rcsv
|
# ARFLAGS = rcsv
|
||||||
ARFLAGS = rcs
|
ARFLAGS = rcs
|
||||||
|
|
||||||
OBJS = gpio.o exti2.o rcc.o
|
OBJS = gpio.o exti.o rcc.o
|
||||||
|
|
||||||
OBJS += crc_common_all.o dac_common_all.o dma_common_f24.o \
|
OBJS += crc_common_all.o dac_common_all.o dma_common_f24.o \
|
||||||
gpio_common_all.o gpio_common_f234.o i2c_common_all.o \
|
gpio_common_all.o gpio_common_f234.o i2c_common_all.o \
|
||||||
|
@ -34,7 +34,7 @@ CFLAGS = -Os -g \
|
|||||||
# ARFLAGS = rcsv
|
# ARFLAGS = rcsv
|
||||||
ARFLAGS = rcs
|
ARFLAGS = rcs
|
||||||
|
|
||||||
OBJS = rcc.o gpio.o adc.o exti2.o i2c.o spi.o usart.o
|
OBJS = rcc.o gpio.o adc.o exti.o i2c.o spi.o usart.o
|
||||||
|
|
||||||
OBJS += gpio_common_all.o gpio_common_f234.o \
|
OBJS += gpio_common_all.o gpio_common_f234.o \
|
||||||
dac_common_all.o usart_common_all.o crc_common_all.o\
|
dac_common_all.o usart_common_all.o crc_common_all.o\
|
||||||
|
@ -34,7 +34,7 @@ CFLAGS = -Os -g \
|
|||||||
# ARFLAGS = rcsv
|
# ARFLAGS = rcsv
|
||||||
ARFLAGS = rcs
|
ARFLAGS = rcs
|
||||||
|
|
||||||
OBJS = adc.o can.o gpio.o exti2.o pwr.o rcc.o rtc.o crypto.o
|
OBJS = adc.o can.o gpio.o exti.o pwr.o rcc.o rtc.o crypto.o
|
||||||
|
|
||||||
OBJS += crc_common_all.o dac_common_all.o dma_common_f24.o \
|
OBJS += crc_common_all.o dac_common_all.o dma_common_f24.o \
|
||||||
gpio_common_all.o gpio_common_f234.o i2c_common_all.o \
|
gpio_common_all.o gpio_common_f234.o i2c_common_all.o \
|
||||||
|
@ -32,7 +32,7 @@ CFLAGS = -Os -g \
|
|||||||
-ffunction-sections -fdata-sections -MD -DSTM32L1
|
-ffunction-sections -fdata-sections -MD -DSTM32L1
|
||||||
# ARFLAGS = rcsv
|
# ARFLAGS = rcsv
|
||||||
ARFLAGS = rcs
|
ARFLAGS = rcs
|
||||||
OBJS = crc.o desig.o exti2.o flash.o rcc.o usart.o
|
OBJS = crc.o desig.o exti.o flash.o rcc.o usart.o
|
||||||
OBJS += crc_common_all.o dac_common_all.o
|
OBJS += crc_common_all.o dac_common_all.o
|
||||||
OBJS += dma_common_f13.o
|
OBJS += dma_common_f13.o
|
||||||
OBJS += gpio_common_all.o gpio_common_f234.o
|
OBJS += gpio_common_all.o gpio_common_f234.o
|
||||||
|
Loading…
x
Reference in New Issue
Block a user