예제 #1
0
/**
  * @brief  Clears the selected data port bits.
  * @param  GPIOx: where x can be (A, B or C) to select the GPIO peripheral.
  * @param  GPIO_Pin: specifies the port bits to be written.
  *   This parameter can be any combination of GPIO_Pin_x where x can be (0..7).
  * @note  This functions uses GPIOx_CLR register to allow atomic read/modify 
  *        accesses. In this way, there is no risk of an IRQ occurring between
  *        the read and the modify access.
  * @retval None
  */
void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin)
{
  /* Check the parameters */
  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  assert_param(IS_GPIO_PIN(GPIO_Pin));
  
  GPIOx->BRR = GPIO_Pin;
}
예제 #2
0
void GPIO_Init(GPIO_TypeDef* GPIOx, uint8_t GPIO_Pin, GPIO_Mode_TypeDef GPIO_Mode)
{
  /*----------------------*/
  /* Check the parameters */
  /*----------------------*/

  assert_param(IS_GPIO_MODE(GPIO_Mode));
  assert_param(IS_GPIO_PIN(GPIO_Pin));

  /* Reset corresponding bit to GPIO_Pin in CR2 register */
  GPIOx->CR2 &= (uint8_t)(~(GPIO_Pin));

  /*-----------------------------*/
  /* Input/Output mode selection */
  /*-----------------------------*/

  if ((((uint8_t)(GPIO_Mode)) & (uint8_t)0x80) != (uint8_t)0x00) /* Output mode */
  {
    if ((((uint8_t)(GPIO_Mode)) & (uint8_t)0x10) != (uint8_t)0x00) /* High level */
    {
      GPIOx->ODR |= GPIO_Pin;
    } else /* Low level */
    {
      GPIOx->ODR &= (uint8_t)(~(GPIO_Pin));
    }
    /* Set Output mode */
    GPIOx->DDR |= GPIO_Pin;
  } else /* Input mode */
  {
    /* Set Input mode */
    GPIOx->DDR &= (uint8_t)(~(GPIO_Pin));
  }

  /*------------------------------------------------------------------------*/
  /* Pull-Up/Float (Input) or Push-Pull/Open-Drain (Output) modes selection */
  /*------------------------------------------------------------------------*/

  if ((((uint8_t)(GPIO_Mode)) & (uint8_t)0x40) != (uint8_t)0x00) /* Pull-Up or Push-Pull */
  {
    GPIOx->CR1 |= GPIO_Pin;
  } else /* Float or Open-Drain */
  {
    GPIOx->CR1 &= (uint8_t)(~(GPIO_Pin));
  }

  /*-----------------------------------------------------*/
  /* Interrupt (Input) or Slope (Output) modes selection */
  /*-----------------------------------------------------*/

  if ((((uint8_t)(GPIO_Mode)) & (uint8_t)0x20) != (uint8_t)0x00) /* Interrupt or Slow slope */
  {
    GPIOx->CR2 |= GPIO_Pin;
  } else /* No external interrupt or No slope control */
  {
    GPIOx->CR2 &= (uint8_t)(~(GPIO_Pin));
  }

}
예제 #3
0
/**
  * @brief  Initializes the GPIOx peripheral according to the specified 
  *         parameters in the GPIO_InitStruct.
  * @param  GPIOx: where x can be (A, B or C) to select the GPIO peripheral.
  * @param  GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure that 
  *         contains the configuration information for the specified GPIO
  *         peripheral.
  *         GPIO_Pin: selects the pin to be configured: GPIO_Pin_0 -> GPIO_Pin_7
  *         GPIO_Mode: selects the mode of the pin: 
  *                          - GPIO Analog Mode: GPIO_Mode_AN 
  *                          - GPIO Output Mode PP: GPIO_Mode_OUT_PP
  *                          - GPIO Input Mode NOPULL: GPIO_Mode_IN
  *                          - GPIO Output Mode OD: GPIO_Mode_OUT_OD
  *                          - GPIO Input Mode PuPd: GPIO_Mode_IN_PUD 
  *                          - GPIO Alternate function Mode PP: GPIO_Mode_AF_PP
  *                          - GPIO Alternate function Mode SPI SCLK PP: GPIO_Mode_AF_PP_SPI
  *                          - GPIO Alternate function Mode OD: GPIO_Mode_AF_OD
  * @retval None
  */
void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
{
  uint32_t currentmode = 0x00, currentpin = 0x00, pinpos = 0x00, pos = 0x00;
  uint32_t tmpreg = 0x00, pinmask = 0x00;
  /* Check the parameters */
  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));
  assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin));
  
  /*---------------------------- GPIO Mode Configuration -----------------------*/
  currentmode = ((uint32_t)GPIO_InitStruct->GPIO_Mode) & ((uint32_t)0x0F);
  
  /*---------------------------- GPIO CRL Configuration ------------------------*/
  /* Configure the four low port pins */
  if (((uint32_t)GPIO_InitStruct->GPIO_Pin & ((uint32_t)0x0F)) != 0x00)
  {
    tmpreg = GPIOx->CRL;
    for (pinpos = 0x00; pinpos < 0x04; pinpos++)
    {
      pos = ((uint32_t)0x01) << pinpos;
      /* Get the port pins position */
      currentpin = (GPIO_InitStruct->GPIO_Pin) & pos;
      if (currentpin == pos)
      {
        pos = pinpos << 2;
        /* Clear the corresponding low control register bits */
        pinmask = ((uint32_t)0x0F) << pos;
        tmpreg &= ~pinmask;
        /* Write the mode configuration in the corresponding bits */
        tmpreg |= (currentmode << pos);
      }
    }
    GPIOx->CRL = tmpreg;
  }
  /*---------------------------- GPIO CRH Configuration ------------------------*/
  /* Configure the four high port pins */
  if (GPIO_InitStruct->GPIO_Pin > 0x0F)
  {
    tmpreg = GPIOx->CRH;
    for (pinpos = 0x00; pinpos < 0x04; pinpos++)
    {
      pos = (((uint32_t)0x01) << (pinpos + 0x04));
      /* Get the port pins position */
      currentpin = ((GPIO_InitStruct->GPIO_Pin) & pos);
      if (currentpin == pos)
      {
        pos = pinpos << 2;
        /* Clear the corresponding high control register bits */
        pinmask = ((uint32_t)0x0F) << pos;
        tmpreg &= ~pinmask;
        /* Write the mode configuration in the corresponding bits */
        tmpreg |= (currentmode << pos);
      } 
    }
    GPIOx->CRH = tmpreg;
  }
}
예제 #4
0
/**
  * @brief  Configures the external pull-up on GPIOx pins.
  * @param  GPIOx : Select the GPIO peripheral number (x = A to I).
  * @param  GPIO_Pin : Specifies the pin number
  *           This parameter can be one of the following values:
  *            @arg GPIO_Pin_0: Pin 0
  *            @arg GPIO_Pin_1: Pin 1
  *            @arg GPIO_Pin_2: Pin 2
  *            @arg GPIO_Pin_3: Pin 3
  *            @arg GPIO_Pin_4: Pin 4
  *            @arg GPIO_Pin_5: Pin 5
  *            @arg GPIO_Pin_6: Pin 6
  *            @arg GPIO_Pin_7: Pin 7
  * @param  NewState : The new state of the pull up pin.
  *           Can be ENABLE or DISABLE
  * @retval None
  */
void GPIO_ExternalPullUpConfig(GPIO_TypeDef* GPIOx, uint8_t GPIO_Pin, FunctionalState NewState)
{
    /* Check the parameters */
    assert_param(IS_GPIO_PIN(GPIO_Pin));
    assert_param(IS_FUNCTIONAL_STATE(NewState));

    if (NewState != DISABLE) { /* External Pull-Up Set*/
        GPIOx->CR1 |= GPIO_Pin;
    } else { /* External Pull-Up Reset*/
        GPIOx->CR1 &= (uint8_t)(~(GPIO_Pin));
    }
}
예제 #5
0
uint8_t GPIO_ReadInputDataBit(uint32_t GPIO_Pin)
{
    int reg_val;

    /* Check the parameters */
    assert_param(IS_GPIO_PIN(GPIO_Pin)); 
	    	
    reg_val = NST_RD_GPIO_REG(EXT_PORTA); 
    reg_val &= GPIO_Pin;

    return (reg_val?1:0);
}
예제 #6
0
uint32_t GPIO_ReadInputData(void)
{
    int reg_val;

    /* Check the parameters */
    assert_param(IS_GPIO_PIN(GPIO_Pin));
	     	
    reg_val = NST_RD_GPIO_REG(EXT_PORTA); 
    reg_val &= GPIO_Pin_All;

    return reg_val;
}
예제 #7
0
void GPIO_ResetBits(uint32_t GPIO_Pin)
{
	int reg_val;

    /* Check the parameters */
    assert_param(IS_GPIO_PIN(GPIO_Pin));
  
    reg_val = NST_RD_GPIO_REG(SWPORTA_DR);
    reg_val &= ~GPIO_Pin; 

    NST_WR_GPIO_REG(SWPORTA_DR, reg_val); 
}
예제 #8
0
/**
  * @brief  Sets or clears the selected data port bit.
  * @param  GPIOx : Select the GPIO peripheral number (x = A to I).
  * @param  GPIO_Pin: Specifies the port bit to be written.
  *           This parameter can be one of the following values:
  *            @arg GPIO_Pin_0: Pin 0
  *            @arg GPIO_Pin_1: Pin 1
  *            @arg GPIO_Pin_2: Pin 2
  *            @arg GPIO_Pin_3: Pin 3
  *            @arg GPIO_Pin_4: Pin 4
  *            @arg GPIO_Pin_5: Pin 5
  *            @arg GPIO_Pin_6: Pin 6
  *            @arg GPIO_Pin_7: Pin 7
  * @param  GPIO_BitVal: specifies the desired status to be written.
  *         This parameter can be SET or RESET
  * @retval None
  */
void GPIO_WriteBit(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin, BitAction GPIO_BitVal)
{
    /* Check the parameters */
    assert_param(IS_GPIO_PIN(GPIO_Pin));
    assert_param(IS_STATE_VALUE(GPIO_BitVal));

    if (GPIO_BitVal != RESET) {
        GPIOx->ODR |= GPIO_Pin;

    } else {
        GPIOx->ODR &= (uint8_t)(~GPIO_Pin);
    }
}
예제 #9
0
static u8 GetGpioPortNumber(GPIO_TypeDef* gpio_port)
{	 
	u8 i = 0;
	//参数检查
	assert_param(IS_GPIO_PIN(gpio_port)); 
	for(i = 0; i < 6; i ++)
	{											
		if(gpio_port == GPIO_PORT[i])
		{
			return i;	
		}								
	}
	return 0;									//不会执行到这里
}
예제 #10
0
void POLOLU_MOTOR_Init(MOTOR_InitTypeDef *motor)
{
	assert_param(IS_GPIO_PIN(motor->PinIn1));
	assert_param(IS_GPIO_PIN(motor->PinIn2));

	if (motor->htimIn1 != NULL)
	{
		HAL_TIM_Base_Start(motor->htimIn1);
	}
	if (motor->htimIn2 != NULL)
	{
		HAL_TIM_Base_Start(motor->htimIn2);
	}
	GPIO_InitTypeDef GPIO_InitStruct;
	GPIO_InitStruct.Pin = motor->PinIn1 ;
	GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
	GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
	HAL_GPIO_Init(motor->GPIOxIn1, &GPIO_InitStruct);

	GPIO_InitStruct.Pin = motor->PinIn2;
	GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
	GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
	HAL_GPIO_Init(motor->GPIOxIn2, &GPIO_InitStruct);
}
예제 #11
0
/**
  * @brief  Initializes the GPIOx peripheral according to the specified 
  *         parameters in the GPIO_InitStruct.
            ��ʼ��GPIOx ����ͨ������GPIOx(����mode\speed\PuPd\otype)
  * @param  GPIOx: where x can be (A, B, C, D, E or H) to select the GPIO peripheral.
    ����    GPIOx(A, B, C, D, E or H)
  * @param  GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure that 
  *         contains the configuration information for the specified GPIO
  *         peripheral.
  *         GPIO_Pin: selects the pin to be configured: GPIO_Pin_0 -> GPIO_Pin_15
  *         GPIO_Mode: selects the mode of the pin: 
  *                      - Input mode: GPIO_Mode_IN
  *                      - Output mode: GPIO_Mode_OUT
  *                      - Alternate Function mode: GPIO_Mode_AF
  *                      - Analog mode: GPIO_Mode_AN
  *         GPIO_Speed: selects the speed of the pin if configured in Output:
  *                      - Very Low: GPIO_Speed_400KHz
  *                      - Low: GPIO_Speed_2MHz
  *                      - Medium: GPIO_Speed_10MHz
  *                      - High: GPIO_Speed_40MHz
  *         GPIO_OType: selects the Output type (if the selected mode is output):
  *                      - Push-pull: GPIO_OType_PP
  *                      - Open Drain: GPIO_OType_OD
  *         GPIO_PuPd: configures the Pull-up/Pull-down resistor on the pin:
  *                      - pull-up: GPIO_PuPd_UP
  *                      - pull-down: GPIO_PuPd_DOWN
  *                      - Neither pull-up nor Pull-down: GPIO_PuPd_NOPULL
  ����Ϊ1��GPIO_TypeDef* GPIOx������GPIOx)�������������ļĴ�����
        2��GPIO_InitTypeDef* GPIO_InitStruct ������д�û���Ҫ�����͡��ٶȡ����ģʽ�����������ȣ�
  * @retval None
  */
void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
{
  uint32_t pinpos = 0x00, pos = 0x00 , currentpin = 0x00;
  
  /* Check the parameters */
  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin));
  assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));
  assert_param(IS_GPIO_PUPD(GPIO_InitStruct->GPIO_PuPd));

  /* -------------------------Configure the port pins---------------- */
  /*-- GPIO Mode Configuration --*/
  for (pinpos = 0x00; pinpos < 0x10; pinpos++)
  {
    pos = ((uint32_t)0x01) << pinpos;

    /* Get the port pins position */
    currentpin = (GPIO_InitStruct->GPIO_Pin) & pos;

    if (currentpin == pos)
    {
      GPIOx->MODER  &= ~(GPIO_MODER_MODER0 << (pinpos * 2));/*һ��pinռ2λ����˱����ƶ�pinpos * 2,�����*/

      GPIOx->MODER |= (((uint32_t)GPIO_InitStruct->GPIO_Mode) << (pinpos * 2));/*һ��pinռ2λ����˱����ƶ�pinpos * 2,�ٸ�ֵ*/

      if ((GPIO_InitStruct->GPIO_Mode == GPIO_Mode_OUT) || (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_AF))
      {  /*��ѡ�����ģʽ����AFģʽ,�����ٶȡ�������͡�*/
        /* Check Speed mode parameters */
        assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed));

        /* Speed mode configuration */
        GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (pinpos * 2));/*һ��pinռ2λ����˱����ƶ�pinpos * 2,�����*/
        GPIOx->OSPEEDR |= ((uint32_t)(GPIO_InitStruct->GPIO_Speed) << (pinpos * 2));/*һ��pinռ2λ����˱����ƶ�pinpos * 2,�ٸ�ֵ*/

        /*Check Output mode parameters */
        assert_param(IS_GPIO_OTYPE(GPIO_InitStruct->GPIO_OType));

        /* Output mode configuration */
        GPIOx->OTYPER  &= ~((GPIO_OTYPER_OT_0) << ((uint16_t)pinpos)) ;/*һ��pinռ1λ����˱����ƶ�pinpos ,�����*/
        GPIOx->OTYPER |= (uint16_t)(((uint16_t)GPIO_InitStruct->GPIO_OType) << ((uint16_t)pinpos));/*һ��pinռ1λ����˱����ƶ�pinpos ,�ٸ�ֵ*/
      }
       /*������*/
      /* Pull-up Pull down resistor configuration */
      GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << ((uint16_t)pinpos * 2));/*һ��pinռ2λ����˱����ƶ�pinpos * 2,�����*/
      GPIOx->PUPDR |= (((uint32_t)GPIO_InitStruct->GPIO_PuPd) << (pinpos * 2));/*һ��pinռ2λ����˱����ƶ�pinpos*2 ,�ٸ�ֵ*/
      }
    }
  }
예제 #12
0
/**
  * @brief  Sets or clears the selected data port bit.
  * @param  GPIOx       Select the GPIO peripheral number (x = A to D).
  * @param  GPIO_Pin: Specifies the port bit to be written.
  *           This parameter can be one of the following values:
  *            @arg GPIO_Pin_0: Pin 0
  *            @arg GPIO_Pin_1: Pin 1
  *            @arg GPIO_Pin_2: Pin 2
  *            @arg GPIO_Pin_3: Pin 3
  *            @arg GPIO_Pin_4: Pin 4
  *            @arg GPIO_Pin_5: Pin 5
  *            @arg GPIO_Pin_6: Pin 6
  *            @arg GPIO_Pin_7: Pin 7   
  * @param  GPIO_BitVal: specifies the desired status to be written.
  *         This parameter can be SET or RESET
  * @retval None
  */
void GPIO_WriteBit(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin, BitAction GPIO_BitVal)
{
  /* Check the parameters */
  assert_param(IS_GPIO_PIN(GPIO_Pin));
  assert_param(IS_STATE_VALUE(GPIO_BitVal));

  if (GPIO_BitVal != RESET)
  {
    SetBit(GPIOx->ODR, GPIO_Pin);

  }
  else
  {
    ClrBit(GPIOx->ODR, GPIO_Pin);
  }
}
예제 #13
0
void GPIO_EXTILineConfig(uint32_t GPIO_Pin, FunctionalState Cmd)
{
    int reg_val;
    
    /* Check the parameters */
    assert_param(IS_GPIO_PIN(GPIO_Pin));
			 
     //Mask or unmask interrupt
    reg_val = NST_RD_GPIO_REG(G_INT_MASK);
    if(Cmd){
	   reg_val &= ~(GPIO_Pin);    
    } else {
	   reg_val |= GPIO_Pin;
    }
    NST_WR_GPIO_REG(G_INT_MASK, reg_val);  
}
예제 #14
0
void GPIO_Init(GPIO_InitTypeDef* GPIO_InitStruct)
{
    int pin_reg = 0,mode_reg;

    /* Check the parameters */
    assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));
    assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin)); 

	/* set ADDR_GPIO_PIN_MUX_CTRL Register*/
    pin_reg = NST_RD_PWM_REG(ADDR_GPIO_PIN_MUX_CTRL);
    pin_reg |= GPIO_InitStruct->GPIO_Pin; 

	/* set SWPORTA_DDR Register*/
    mode_reg = NST_RD_GPIO_REG(SWPORTA_DDR);
    if(GPIO_InitStruct->GPIO_Mode){
        mode_reg |= GPIO_InitStruct->GPIO_Pin;
    } else {
        mode_reg &= ~GPIO_InitStruct->GPIO_Pin; 
    }

    NST_WR_PWM_REG(ADDR_GPIO_PIN_MUX_CTRL, pin_reg); 
    NST_WR_GPIO_REG(SWPORTA_DDR, mode_reg);   
}
예제 #15
0
void POLOLU_DRIVER_Init(DRIVER_InitTypeDef *driver)
{
	assert_param(IS_GPIO_PIN(driver->ModePin));
}
예제 #16
0
void LCD_Init(
    uint8_t fourBitMode, GPIO_TypeDef* gpio,
    uint16_t rs, uint16_t rw, uint16_t enable,
    uint16_t d0, uint16_t d1, uint16_t d2, uint16_t d3,
    uint16_t d4, uint16_t d5, uint16_t d6, uint16_t d7)
{
    uint32_t periph;

    assert_param(IS_GPIO_ALL_PERIPH(gpio));
    assert_param(IS_GPIO_PIN(rs));
    assert_param(IS_GPIO_PIN(rw));
    assert_param(IS_GPIO_PIN(enable));
    assert_param(IS_GPIO_PIN(d0));
    assert_param(IS_GPIO_PIN(d1));
    assert_param(IS_GPIO_PIN(d2));
    assert_param(IS_GPIO_PIN(d3));

    if(!fourBitMode) {
        assert_param(IS_GPIO_PIN(d4));
        assert_param(IS_GPIO_PIN(d5));
        assert_param(IS_GPIO_PIN(d6));
        assert_param(IS_GPIO_PIN(d7));
    }

    Lcd_Conf.gpio = gpio;
    Lcd_Conf.rs = rs;
    Lcd_Conf.rw = rw;
    Lcd_Conf.enable = enable;
    Lcd_Conf.data[0] = d0;
    Lcd_Conf.data[1] = d1;
    Lcd_Conf.data[2] = d2;
    Lcd_Conf.data[3] = d3;
    Lcd_Conf.data[4] = d4;
    Lcd_Conf.data[5] = d5;
    Lcd_Conf.data[6] = d6;
    Lcd_Conf.data[7] = d7;

    if (gpio == GPIOA)
        periph = RCC_AHB1Periph_GPIOA;
    else if (gpio == GPIOB)
        periph = RCC_AHB1Periph_GPIOB;
    else if (gpio == GPIOC)
        periph = RCC_AHB1Periph_GPIOC;
    else if (gpio == GPIOD)
        periph = RCC_AHB1Periph_GPIOD;
    else if (gpio == GPIOE)
        periph = RCC_AHB1Periph_GPIOE;
    else
        return;

    RCC_AHB1PeriphClockCmd(periph, ENABLE);

    set_output(1);

    if(fourBitMode)
        Lcd_Conf.dispFunc = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
    else
        Lcd_Conf.dispFunc = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS;
}