Tutorial: PinName Configuration
Pinmap Configuration
Examples
Usage example 1
// GPIO Mode : Input(00), Output(01), AlterFunc(10), Analog(11, reset)
void GPIO_mode(PinNames_t pinName, int mode){
// Separate port-name and pin-number from pinName
GPIO_TypeDef *Port;
unsigned int pin;
ecPinmap(pinName, &Port, &pin);
Port->MODER &= ~(3UL<<(2*pin));
Port->MODER |= mode<<(2*pin);
}
// In MAIN()
GPIO_mode(PA_5, OUTPUT);
GPIO_mode(PC_15, INPUT);
////////////////////////////////////////////////////////////////////////////////////
//
// You can also use PORT name and PIN name separately for the function argument
/*
void GPIO_mode(GPIO_TypeDef *Port, int pin, int mode){
Port->MODER &= ~(3UL<<(2*pin));
Port->MODER |= mode<<(2*pin);
}
*/
/* In MAIN()
GPIO_mode(GPIOA, 5, OUTPUT);
GPIO_mode(GPIOC, 15, INPUT);
*/
Usage example 2
PinName Header File
Last updated