Implement afio's control functions
This commit is contained in:
parent
9052aac1b3
commit
3906a79315
63
drivers/afio.c
Normal file
63
drivers/afio.c
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/** @file afio.c
|
||||||
|
* Module handling Alternate Functions for Inputs/Outputs
|
||||||
|
*
|
||||||
|
* The module provides functions to remap ios to diverse peripherals
|
||||||
|
*/
|
||||||
|
|
||||||
|
//--includes--------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "afio.h"
|
||||||
|
#include "afio_regs.h"
|
||||||
|
|
||||||
|
#include "rcc.h"
|
||||||
|
|
||||||
|
|
||||||
|
//--local definitions-----------------------------------------------------------
|
||||||
|
|
||||||
|
//--local variables-------------------------------------------------------------
|
||||||
|
|
||||||
|
static volatile struct AFIO* regs = (struct AFIO*)AFIO_BASE_ADDRESS;
|
||||||
|
|
||||||
|
|
||||||
|
//--public functions------------------------------------------------------------
|
||||||
|
|
||||||
|
void afio_map_exti(enum ExtiLine line_mask, enum GpioPort port)
|
||||||
|
{
|
||||||
|
//ensure afio peripheral is enabled
|
||||||
|
rcc_enable(RCC_AHB_NONE, RCC_APB1_NONE, RCC_APB2_AFIO);
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < 4; ++i) {
|
||||||
|
if (line_mask & (0x1 << i)) {
|
||||||
|
regs->EXTICR1.word &= ~(0xF << (4 * i));
|
||||||
|
regs->EXTICR1.word |= (port << (4 * i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
line_mask = line_mask >> 4;
|
||||||
|
for (uint8_t i = 0; i < 4; ++i) {
|
||||||
|
if (line_mask & (0x1 << i)) {
|
||||||
|
regs->EXTICR2.word &= ~(0xF << (4 * i));
|
||||||
|
regs->EXTICR2.word |= (port << (4 * i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
line_mask = line_mask >> 4;
|
||||||
|
for (uint8_t i = 0; i < 4; ++i) {
|
||||||
|
if (line_mask & (0x1 << i)) {
|
||||||
|
regs->EXTICR3.word &= ~(0xF << (4 * i));
|
||||||
|
regs->EXTICR3.word |= (port << (4 * i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
line_mask = line_mask >> 4;
|
||||||
|
for (uint8_t i = 0; i < 4; ++i) {
|
||||||
|
if (line_mask & (0x1 << i)) {
|
||||||
|
regs->EXTICR4.word &= ~(0xF << (4 * i));
|
||||||
|
regs->EXTICR4.word |= (port << (4 * i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--local functions-------------------------------------------------------------
|
||||||
|
|
||||||
26
drivers/afio.h
Normal file
26
drivers/afio.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/** @file afio.h
|
||||||
|
* Module handling Alternate Functions for Inputs/Outputs
|
||||||
|
*
|
||||||
|
* The module provides functions to remap ios to diverse peripherals
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _AFIO_H_
|
||||||
|
#define _AFIO_H_
|
||||||
|
|
||||||
|
//--includes--------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "stdint.h"
|
||||||
|
#include "stdbool.h"
|
||||||
|
|
||||||
|
#include "exti.h"
|
||||||
|
|
||||||
|
|
||||||
|
//--type definitions------------------------------------------------------------
|
||||||
|
|
||||||
|
//--functions-------------------------------------------------------------------
|
||||||
|
|
||||||
|
void afio_map_exti(enum ExtiLine line_mask, enum GpioPort port);
|
||||||
|
|
||||||
|
|
||||||
|
#endif //_AFIO_H_
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user