Various cosmetic and coding style fixes.

This commit is contained in:
Uwe Hermann 2010-06-29 23:01:44 +02:00
parent 47b31246ca
commit 6ba179b361
5 changed files with 125 additions and 116 deletions

View File

@ -244,7 +244,8 @@ void clock_setup(void)
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM3EN);
/* Enable GPIOC, Alternate Function clocks. */
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN | RCC_APB2ENR_AFIOEN);
rcc_peripheral_enable_clock(&RCC_APB2ENR,
RCC_APB2ENR_IOPCEN | RCC_APB2ENR_AFIOEN);
}
void gpio_setup(void)

View File

@ -23,11 +23,12 @@
#include <libopenstm32/memorymap.h>
#include <libopenstm32/common.h>
/*Define EXTI Registers */
/* --- EXTI registers ------------------------------------------------------ */
#define EXTI_IMR MMIO32(EXTI_BASE + 0x00)
#define EXTI_EMR MMIO32(EXTI_BASE + 0x04)
#define EXTI_RTSR MMIO32(EXTI_BASE + 0x08)
#define EXTI_FTSR MMIO32(EXTI_BASE + 0x0C)
#define EXTI_FTSR MMIO32(EXTI_BASE + 0x0c)
#define EXTI_SWIER MMIO32(EXTI_BASE + 0x10)
#define EXTI_PR MMIO32(EXTI_BASE + 0x14)
@ -53,19 +54,17 @@
#define EXTI18 (1 << 18)
#define EXTI19 (1 << 19)
/*Define trigger types*/
/* Trigger types */
typedef enum trigger_e {
EXTI_TRIGGER_RISING,
EXTI_TRIGGER_FALLING,
EXTI_TRIGGER_BOTH,
} exti_trigger_type;
/*Function Prototypes */
void exti_set_trigger(u32 extis, exti_trigger_type trig);
void exti_enable_request(u32 extis);
void exti_disable_request(u32 extis);
void exti_reset_request(u32 extis);
void exti_select_source(u32 exti, u32 gpioport);
#endif

View File

@ -56,7 +56,7 @@
#define IWDG_PR_DIV64 0x4
#define IWDG_PR_DIV128 0x5
#define IWDG_PR_DIV256 0x6
/* double definition */
/* Double definition: 0x06 and 0x07 both mean DIV256 as per datasheet. */
/* #define IWDG_PR_DIV256 0x7 */
/* --- IWDG_RLR values ----------------------------------------------------- */

View File

@ -22,8 +22,7 @@
void exti_set_trigger(u32 extis, exti_trigger_type trig)
{
switch(trig)
{
switch (trig) {
case EXTI_TRIGGER_RISING:
EXTI_RTSR |= extis;
EXTI_FTSR &= ~extis;
@ -41,38 +40,44 @@ void exti_set_trigger(u32 extis, exti_trigger_type trig)
void exti_enable_request(u32 extis)
{
//enable interrupts
/* Enable interrupts. */
EXTI_IMR |= extis;
//enable events
/* Enable events. */
EXTI_EMR |= extis;
}
void exti_disable_request(u32 extis)
{
//disable interrupts
/* Disable interrupts. */
EXTI_IMR &= ~extis;
//disable events
/* Disable events. */
EXTI_EMR &= ~extis;
}
/*
Reset the interrupt request by writing a 1 to the corresponding
pending bit register
* Reset the interrupt request by writing a 1 to the corresponding
* pending bit register.
*/
void exti_reset_request(u32 extis)
{
EXTI_PR |= extis;
}
/*Remap an external interrupt line to the corresponding
pin on the specified GPIO port TODO: this could be rewritten in less lines of code */
/*
* Remap an external interrupt line to the corresponding pin on the
* specified GPIO port.
*
* TODO: This could be rewritten in less lines of code.
*/
void exti_select_source(u32 exti, u32 gpioport)
{
u8 shift =0;
u8 bits = 0;
switch (exti)
{
u8 shift, bits;
shift = bits = 0;
switch (exti) {
case EXTI0:
case EXTI4:
case EXTI8:
@ -99,33 +104,37 @@ void exti_select_source(u32 exti, u32 gpioport)
break;
}
switch (gpioport)
{
switch (gpioport) {
case GPIOA:
bits = 0xF;
bits = 0xf;
break;
case GPIOB:
bits = 0xE;
bits = 0xe;
break;
case GPIOC:
bits = 0xD;
bits = 0xd;
break;
case GPIOD:
bits = 0xC;
bits = 0xc;
break;
case GPIOE:
bits = 0xB;
bits = 0xb;
break;
case GPIOF:
bits = 0xA;
bits = 0xa;
break;
case GPIOG:
bits = 0x9;
break;
}
if(exti < EXTI4) AFIO_EXTICR1 &=~ ( bits << shift );
else if (exti < EXTI8) AFIO_EXTICR2 &=~ ( bits << shift );
else if (exti < EXTI12) AFIO_EXTICR3 &=~ ( bits << shift );
else if (exti < EXTI16) AFIO_EXTICR4 &=~ ( bits << shift ); //ensure that only valid EXTI lines are used
/* Ensure that only valid EXTI lines are used. */
if (exti < EXTI4)
AFIO_EXTICR1 &= ~(bits << shift);
else if (exti < EXTI8)
AFIO_EXTICR2 &= ~(bits << shift);
else if (exti < EXTI12)
AFIO_EXTICR3 &= ~(bits << shift);
else if (exti < EXTI16)
AFIO_EXTICR4 &= ~(bits << shift);
}