Exemplo n.º 1
0
/*!
    \brief      set GPIO output type and speed
    \param[in]  port
      \arg        GPIOx(x = A,B,C,D,F)
    \param[in]  mode
      \arg        GPIO_OTYPE_PP: push pull mode
      \arg        GPIO_OTYPE_OD: open drain mode
    \param[in]  speed
      \arg        GPIO_OSPEED_2MHZ: output max speed 2M 
      \arg        GPIO_OSPEED_10MHZ: output max speed 10M 
      \arg        GPIO_OSPEED_50MHZ: output max speed 50M 
    \param[in]  pin
      \arg        GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
    \param[out] none
    \retval     none
*/
void gpio_output_options_set(uint32_t port, uint8_t otype, uint8_t speed,uint16_t pin)
{
    uint16_t i;
    uint32_t ospeedr;

    if(0x1 == otype){
        GPIO_OMODE(port) |= pin;
    }else{
        GPIO_OMODE(port) &= ~pin;
    }

    /* get the specified pin output speed bits value */
    ospeedr = GPIO_OSPD(port);

    for (i = 0; i < 16; i++){
        if (!((1 << i) & pin)){
            continue;
        }
        /* clear the specified pin output speed bits */
        ospeedr &= ~GPIO_OSPEED_MASK(i);
        ospeedr |= GPIO_OSPEED_SET(i, speed);
    }
    GPIO_OSPD(port) = ospeedr;
}
Exemplo n.º 2
0
/*!
    \brief      set GPIO output type and speed
    \param[in]  gpio_periph: GPIOx(x = A,B,C,F) 
                only one parameter can be selected which is shown as below:
      \arg        GPIOx(x = A,B,C,F) 
    \param[in]  otype: gpio pin output mode
      \arg        GPIO_OTYPE_PP: push pull mode
      \arg        GPIO_OTYPE_OD: open drain mode
    \param[in]  speed: gpio pin output max speed
      \arg        GPIO_OSPEED_2MHZ: output max speed 2MHz 
      \arg        GPIO_OSPEED_10MHZ: output max speed 10MHz 
      \arg        GPIO_OSPEED_50MHZ: output max speed 50MHz
    \param[in]  pin: GPIO pin
                one or more parameters can be selected which are shown as below:
      \arg        GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
    \param[out] none
    \retval     none
*/
void gpio_output_options_set(uint32_t gpio_periph, uint8_t otype, uint32_t speed, uint32_t pin)
{
    uint16_t i;
    uint32_t ospeed;

    if(GPIO_OTYPE_OD == otype){
        GPIO_OMODE(gpio_periph) |= (uint32_t)pin;
    }else{
        GPIO_OMODE(gpio_periph) &= (uint32_t)(~pin);
    }

    /* get the specified pin output speed bits value */
    ospeed = GPIO_OSPD(gpio_periph);

    for(i = 0U;i < 16U;i++){
        if((1U << i) & pin){
            /* clear the specified pin output speed bits */
            ospeed &= ~GPIO_OSPEED_MASK(i);
            /* set the specified pin output speed bits */
            ospeed |= GPIO_OSPEED_SET(i,speed);
        }
    }
    GPIO_OSPD(gpio_periph) = ospeed;
}