コード例 #1
0
ファイル: gpio.cpp プロジェクト: RichardHabeeb/ksurct
/*****************************************************************************
* Function: Init
*
* Description:
*****************************************************************************/
void OutputPin::Init
    (
        pin_level_t pin_level // Starting level (high/low) of pin.
    )
{
    assert_param(IS_GPIO_ALL_PERIPH(this->port));
    assert_param(IS_GET_GPIO_PIN(this->pin));
    assert_param(IS_RCC_AHB1_CLOCK_PERIPH(this->clock));

    // Peripheral clock enable.
    RCC_AHB1PeriphClockCmd(this->clock, ENABLE);

    // Configure pin in output pushpull mode.
    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_InitStructure.GPIO_Pin = this->pin;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(this->port, &GPIO_InitStructure);

    // Initialize pin level and field.
    if (pin_level == HIGH)
    {
        WriteHigh();
    }
    else
    {
        WriteLow();
    }

} // OutputPin::Init()
コード例 #2
0
ファイル: stm32w108xx_gpio.c プロジェクト: ndpr43/CpE5170
/**
  * @brief  Sets or clears the selected data port bit.
  * @param  GPIOx: where x can be (A, B or C) to select the GPIO peripheral.
  * @param  GPIO_Pin: specifies the port bit to be written.
  *   This parameter can be one of GPIO_Pin_x where x can be (0..7).
  * @param  BitVal: specifies the value to be written to the selected bit.
  *   This parameter can be one of the BitAction enum values:
  *     @arg Bit_RESET: to clear the port pin
  *     @arg Bit_SET: to set the port pin
  * @retval None
  */
void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, BitAction BitVal)
{
  /* Check the parameters */
  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
  assert_param(IS_GPIO_BIT_ACTION(BitVal));
  
  if (BitVal != Bit_RESET)
  {
    GPIOx->BSR = GPIO_Pin;
  }
  else
  {
    GPIOx->BRR = GPIO_Pin ;
  }
}
コード例 #3
0
ファイル: stm32w108xx_gpio.c プロジェクト: ndpr43/CpE5170
/**
  * @brief  Reads the specified input port pin.
  * @param  GPIOx: where x can be (A, B or C) to select the GPIO peripheral.
  * @param  GPIO_Pin: specifies the port bit to read.
  *   This parameter can be GPIO_Pin_x where x can be (0..7).
  * @retval The input port pin value.
  */
uint32_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin)
{
  uint32_t bitstatus = 0x00;
  /* Check the parameters */
  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
  
  if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)Bit_RESET)
  {
    bitstatus = (uint32_t)Bit_SET;
  }
  else
  {
    bitstatus = (uint32_t)Bit_RESET;
  }
  return bitstatus;
}
コード例 #4
0
ファイル: gpio.cpp プロジェクト: RichardHabeeb/ksurct
/*****************************************************************************
* Function: Init
*
* Description:
*****************************************************************************/
void InputPin::Init(void)
{
    assert_param(IS_GPIO_ALL_PERIPH(this->port));
    assert_param(IS_GET_GPIO_PIN(this->pin));
    assert_param(IS_RCC_AHB1_CLOCK_PERIPH(this->clock));

    // Peripheral clock enable.
    RCC_AHB1PeriphClockCmd(this->clock, ENABLE);

    // Configure pin in input pushpull mode.
    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_InitStructure.GPIO_Pin = this->pin;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(this->port, &GPIO_InitStructure);

} // InputPin::Init()
コード例 #5
0
ファイル: gpio.cpp プロジェクト: RichardHabeeb/ksurct
/*****************************************************************************
* Function: Init
*
* Description:
*****************************************************************************/
void AlternateFunctionPin::Init(void)
{
    assert_param(IS_GPIO_ALL_PERIPH(this->port));
    assert_param(IS_GET_GPIO_PIN(this->pin));
    assert_param(IS_GPIO_PIN_SOURCE(this->pin_source));
    assert_param(IS_GPIO_AF(this->alternate_function));
    assert_param(IS_RCC_AHB1_CLOCK_PERIPH(this->clock));

    // Peripheral clock enable.
    RCC_AHB1PeriphClockCmd(this->clock, ENABLE);

    // Configure pin in alternate function mode.
    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_InitStructure.GPIO_Pin = this->pin;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(this->port, &GPIO_InitStructure);

    GPIO_PinAFConfig(this->port, this->pin_source, this->alternate_function);

} // AlternateFunctionPin::Init()