libmaple/stm32f2-f4/gpio.c
void gpio_set_modef(gpio_dev *dev,
                    uint8 bit,
                    gpio_pin_mode mode,
                    unsigned flags) {
    gpio_reg_map *regs = dev->regs;
    unsigned shift = bit * 2;
    uint32 tmp;

    /* Mode */
    tmp = regs->MODER;
    tmp &= ~(0x3 << shift);
    tmp |= mode << shift;
    regs->MODER = tmp;

    /* Output type */
    bb_peri_set_bit(&regs->OTYPER, bit, flags & 0x1);

    /* Speed */
    tmp = regs->OSPEEDR;
    tmp &= ~(0x3 << shift);
    tmp |= ((flags >> 1) & 0x3) << shift;
    regs->OSPEEDR = tmp;

    /* Pull-up/pull-down */
    tmp = regs->PUPDR;
    tmp &= ~(0x3 << shift);
    tmp |= ((flags >> 3) & 0x3) << shift;
    regs->PUPDR = tmp;
}
/**
 * @brief Set the mode of a GPIO pin.
 * @param dev GPIO device.
 * @param bit Bit on dev whose mode to set, 0--15.
 * @param mode Mode to set the pin to.
 * @param flags Flags to modify basic mode configuration
 */
@brief Set the mode of a GPIO pin.
@param dev GPIO device.
@param bit Bit on dev whose mode to set, 0--15.
@param mode Mode to set the pin to.
@param flags Flags to modify basic mode configuration
@brief Set the mode of a GPIO pin . @param dev GPIO device . @param bit Bit on dev whose mode to set 0 -- 15 . @param mode Mode to set the pin to . @param flags Flags to modify basic mode configuration
void gpio_set_modef(gpio_dev *dev,
                    uint8 bit,
                    gpio_pin_mode mode,
                    unsigned flags) {
    gpio_reg_map *regs = dev->regs;
    unsigned shift = bit * 2;
    uint32 tmp;
    tmp = regs->MODER;
    tmp &= ~(0x3 << shift);
    tmp |= mode << shift;
    regs->MODER = tmp;
    bb_peri_set_bit(&regs->OTYPER, bit, flags & 0x1);
    tmp = regs->OSPEEDR;
    tmp &= ~(0x3 << shift);
    tmp |= ((flags >> 1) & 0x3) << shift;
    regs->OSPEEDR = tmp;
    tmp = regs->PUPDR;
    tmp &= ~(0x3 << shift);
    tmp |= ((flags >> 3) & 0x3) << shift;
    regs->PUPDR = tmp;
}
void gpio_set_modef ( gpio_dev * dev , uint8 bit , gpio_pin_mode mode , unsigned flags ) { gpio_reg_map * regs = dev -> regs ; unsigned shift = bit * 2 ; uint32 tmp ; tmp = regs -> MODER ; tmp &= ~ ( 0x3 << shift ) ; tmp |= mode << shift ; regs -> MODER = tmp ; bb_peri_set_bit ( & regs -> OTYPER , bit , flags & 0x1 ) ; tmp = regs -> OSPEEDR ; tmp &= ~ ( 0x3 << shift ) ; tmp |= ( ( flags >> 1 ) & 0x3 ) << shift ; regs -> OSPEEDR = tmp ; tmp = regs -> PUPDR ; tmp &= ~ ( 0x3 << shift ) ; tmp |= ( ( flags >> 3 ) & 0x3 ) << shift ; regs -> PUPDR = tmp ; }
@brief Set the mode of a GPIO pin.
@brief Set the mode of a GPIO pin .
/* Mode */ /* Output type */ /* Speed */ /* Pull-up/pull-down */