Skip to content

Commit

Permalink
PiOS:EXTI: Add EXTI DeInit function
Browse files Browse the repository at this point in the history
  • Loading branch information
tracernz authored and mlyle committed Apr 28, 2016
1 parent 16db23a commit 06692b3
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
26 changes: 26 additions & 0 deletions flight/PiOS/STM32F10x/pios_exti.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,32 @@ int32_t PIOS_EXTI_Init(const struct pios_exti_cfg * cfg)
return -1;
}

void PIOS_EXTI_DeInit(const struct pios_exti_cfg *cfg)
{
PIOS_Assert(cfg);
PIOS_Assert(&__start__exti);
PIOS_Assert(cfg >= &__start__exti);
PIOS_Assert(cfg < &__stop__exti);

/* Disconnect this config from the requested vector */
uint8_t line_index = PIOS_EXTI_line_to_index(cfg->line);
pios_exti_line_to_cfg_map[line_index] = PIOS_EXTI_INVALID;

/* Disconnect EXTI */
uint8_t exti_source_pin = PIOS_EXTI_gpio_pin_to_exti_source_pin(cfg->pin.init.GPIO_Pin);
// sadly std-periph doesn't provide a way to disable the exti line
uint32_t tmp = ((uint32_t)0x0F) << (0x04 * (exti_source_pin & (uint8_t)0x03));
AFIO->EXTICR[exti_source_pin >> 0x02] &= ~tmp;

/* Disable EXTI */
EXTI_InitTypeDef init = {
.EXTI_LineCmd = DISABLE,
.EXTI_Mode = cfg->exti.init.EXTI_Mode,
.EXTI_Line = cfg->exti.init.EXTI_Line,
};
EXTI_Init(&init);
}

static bool PIOS_EXTI_generic_irq_handler(uint8_t line_index)
{
uint8_t cfg_index = pios_exti_line_to_cfg_map[line_index];
Expand Down
26 changes: 26 additions & 0 deletions flight/PiOS/STM32F30x/pios_exti.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,32 @@ int32_t PIOS_EXTI_Init(const struct pios_exti_cfg * cfg)
return -1;
}

void PIOS_EXTI_DeInit(const struct pios_exti_cfg *cfg)
{
PIOS_Assert(cfg);
PIOS_Assert(&__start__exti);
PIOS_Assert(cfg >= &__start__exti);
PIOS_Assert(cfg < &__stop__exti);

/* Disconnect this config from the requested vector */
uint8_t line_index = PIOS_EXTI_line_to_index(cfg->line);
pios_exti_line_to_cfg_map[line_index] = PIOS_EXTI_INVALID;

/* Disconnect EXTI */
uint8_t exti_source_pin = PIOS_EXTI_gpio_pin_to_exti_source_pin(cfg->pin.init.GPIO_Pin);
// sadly std-periph doesn't provide a way to disable the exti line
uint32_t tmp = ((uint32_t)0x0F) << (0x04 * (exti_source_pin & (uint8_t)0x03));
SYSCFG->EXTICR[exti_source_pin >> 0x02] &= ~tmp;

/* Disable EXTI */
EXTI_InitTypeDef init = {
.EXTI_LineCmd = DISABLE,
.EXTI_Mode = cfg->exti.init.EXTI_Mode,
.EXTI_Line = cfg->exti.init.EXTI_Line,
};
EXTI_Init(&init);
}

static bool PIOS_EXTI_generic_irq_handler(uint8_t line_index)
{
uint8_t cfg_index = pios_exti_line_to_cfg_map[line_index];
Expand Down
26 changes: 26 additions & 0 deletions flight/PiOS/STM32F4xx/pios_exti.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,32 @@ int32_t PIOS_EXTI_Init(const struct pios_exti_cfg * cfg)
return -1;
}

void PIOS_EXTI_DeInit(const struct pios_exti_cfg *cfg)
{
PIOS_Assert(cfg);
PIOS_Assert(&__start__exti);
PIOS_Assert(cfg >= &__start__exti);
PIOS_Assert(cfg < &__stop__exti);

/* Disconnect this config from the requested vector */
uint8_t line_index = PIOS_EXTI_line_to_index(cfg->line);
pios_exti_line_to_cfg_map[line_index] = PIOS_EXTI_INVALID;

/* Disconnect EXTI */
uint8_t exti_source_pin = PIOS_EXTI_gpio_pin_to_exti_source_pin(cfg->pin.init.GPIO_Pin);
// sadly std-periph doesn't provide a way to disable the exti line
uint32_t tmp = ((uint32_t)0x0F) << (0x04 * (exti_source_pin & (uint8_t)0x03));
SYSCFG->EXTICR[exti_source_pin >> 0x02] &= ~tmp;

/* Disable EXTI */
EXTI_InitTypeDef init = {
.EXTI_LineCmd = DISABLE,
.EXTI_Mode = cfg->exti.init.EXTI_Mode,
.EXTI_Line = cfg->exti.init.EXTI_Line,
};
EXTI_Init(&init);
}

static bool PIOS_EXTI_generic_irq_handler(uint8_t line_index)
{
uint8_t cfg_index = pios_exti_line_to_cfg_map[line_index];
Expand Down
3 changes: 2 additions & 1 deletion flight/PiOS/inc/pios_exti.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ struct pios_exti_cfg {
/* must be added to any pios_exti_cfg definition for it to be valid */
#define __exti_config __attribute__((section("_exti")))

extern int32_t PIOS_EXTI_Init(const struct pios_exti_cfg * cfg);
extern int32_t PIOS_EXTI_Init(const struct pios_exti_cfg *cfg);
extern void PIOS_EXTI_DeInit(const struct pios_exti_cfg *cfg);

#endif /* PIOS_EXTI_H */

Expand Down

0 comments on commit 06692b3

Please sign in to comment.