コード例 #1
0
ファイル: encoder.c プロジェクト: eLimones/Irrigation_control
void encoder_init(void){
	//ECH_A PB6, ECH_B PB7 
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB,ENABLE);
	
	GPIO_InitTypeDef myGPIO;
	GPIO_StructInit(&myGPIO);
	myGPIO.GPIO_Mode=GPIO_Mode_IN;
	myGPIO.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_7;
	myGPIO.GPIO_PuPd=GPIO_PuPd_UP;
	GPIO_Init(GPIOB,&myGPIO);
	
	RCC_APB2PeriphClockCmd(RCC_APB2ENR_SYSCFGEN,ENABLE);//Turn on SYSCFG since it's disabled by default
	EXTI_InitTypeDef myEXTI;
	EXTI_StructInit(&myEXTI);
	myEXTI.EXTI_Line=EXTI_Line6|EXTI_Line7;
	myEXTI.EXTI_LineCmd=ENABLE;
	myEXTI.EXTI_Mode=EXTI_Mode_Interrupt;
	myEXTI.EXTI_Trigger=EXTI_Trigger_Rising_Falling;
	EXTI_Init(&myEXTI);
	
	SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB,EXTI_PinSource6);//Reamp Line 6 to Port B
	SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB,EXTI_PinSource7);//Reamp Line 7 to Port B
	
	
	last_encoderA=GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_6);
	last_encoderB=GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_7);
	
	EXTI_ClearITPendingBit(EXTI_Line6);//Clear pening interrupts
	EXTI_ClearITPendingBit(EXTI_Line7);//Clear pening interrupts
	
	NVIC_EnableIRQ(EXTI4_15_IRQn);//Enable EXTI0  interrupts
}
コード例 #2
0
ファイル: menu.c プロジェクト: ptLong/IAR-STM32F407ZG-SK
/*******************************************************************************
* Function Name  : IntExtOnOffConfig
* Description    : Enables or disables EXTI for the menu navigation keys :
*                  EXTI lines 14, 15 and 13 which correpond respectively
*                  to "UP", "SEL" and "DOWN".
* Input          : NewState: New state of the navigation keys. This parameter
*                  can be: ENABLE or DISABLE.
* Output         : None
* Return         : None
*******************************************************************************/
void IntExtOnOffConfig(FunctionalState NewState)
{
    EXTI_InitTypeDef EXTI_InitStructure;

    /* Initializes the EXTI_InitStructure */
    EXTI_StructInit(&EXTI_InitStructure);

    /* Disable the EXTI line 15, 8 and 7 on falling edge */
    if(NewState == DISABLE)
    {
        EXTI_InitStructure.EXTI_Line = EXTI_Line15 | EXTI_Line8 | EXTI_Line7;
        EXTI_InitStructure.EXTI_LineCmd = DISABLE;
        EXTI_Init(&EXTI_InitStructure);
    }
    /* Enable the EXTI line 15, 8 and 7 on falling edge */
    else
    {
        /* Clear the the EXTI line 15, 8 and 7 interrupt pending bit */
        EXTI_ClearITPendingBit(EXTI_Line15 | EXTI_Line8 | EXTI_Line7);

        EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
        EXTI_InitStructure.EXTI_Line = EXTI_Line15 | EXTI_Line8 | EXTI_Line7;
        EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
        EXTI_InitStructure.EXTI_LineCmd = ENABLE;
        EXTI_Init(&EXTI_InitStructure);
    }
}
コード例 #3
0
ファイル: Button.cpp プロジェクト: Bigboy20769/TCode
void button_init()
{
	// Enable clock for SYSCFG */
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
	// Push Button 2 Port C Pin 13
	GPIO_InitTypeDef GPIO_InitStructure;
	GPIO_StructInit(&GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOC, &GPIO_InitStructure);
	// Tell system that you will use PC13 for EXTI_Line13
	SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource13);

	//Configure Button EXT1 line
	EXTI_InitTypeDef EXTI_InitStructure;
	EXTI_StructInit(&EXTI_InitStructure);
	EXTI_InitStructure.EXTI_Line = EXTI_Line13;
	EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
	EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
	EXTI_InitStructure.EXTI_LineCmd = ENABLE;
	EXTI_Init(&EXTI_InitStructure);
	//Set Priority to the lowest
	NVIC_InitTypeDef NVIC_InitStructure;
	NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);
}
コード例 #4
0
void EINT_Config(void)
{

	GPIO_StructInit(&GPIO_InitStructure1);
	GPIO_InitStructure1.GPIO_Pin = GPIO_Pin_0;
	GPIO_InitStructure1.GPIO_Mode = GPIO_Mode_IPU;
	GPIO_InitStructure1.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOG, &GPIO_InitStructure1);


	//SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);

	EXTI_InitTypeDef EXTI_InitStructure;
	EXTI_StructInit(&EXTI_InitStructure);
	EXTI_InitStructure.EXTI_Line = EXTI_Line0;
	EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
	EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
	EXTI_InitStructure.EXTI_LineCmd = ENABLE;
	EXTI_Init(&EXTI_InitStructure);

	NVIC_InitTypeDef NVIC_InitStructure1;
	NVIC_InitStructure1.NVIC_IRQChannel = EXTI0_IRQn;
	NVIC_InitStructure1.NVIC_IRQChannelPreemptionPriority = 0x01;
	NVIC_InitStructure1.NVIC_IRQChannelSubPriority = 0x01;
	NVIC_InitStructure1.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure1);
}
コード例 #5
0
ファイル: owlcontrol.c プロジェクト: pingdynasty/OwlWare
/** 
 * Configure EXTI callback
 */
void setupSwitchB(void (*f)()){
  externalInterruptCallbackB = f;

  EXTI_InitTypeDef EXTI_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;

  /* Enable the clocks */
  RCC_AHB1PeriphClockCmd(SWITCH_B_CLOCK, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

  /* Configure switch pin */
  configureDigitalInput(SWITCH_B_PORT, SWITCH_B_PIN, GPIO_PuPd_UP);

  /* Connect EXTI Line to GPIO Pin */
  SYSCFG_EXTILineConfig(SWITCH_B_PORT_SOURCE, SWITCH_B_PIN_SOURCE);

  /* Configure EXTI line */
  EXTI_StructInit(&EXTI_InitStructure);
  EXTI_InitStructure.EXTI_Line = SWITCH_B_PIN_LINE;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);

  /* Enable and set EXTI Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = SWITCH_B_IRQ;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = SWITCH_B_PRIORITY;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = SWITCH_B_SUBPRIORITY;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}
コード例 #6
0
ファイル: stm32f10x_sensor.c プロジェクト: kuling729/USB_JKJ
void SENSOR_Init(Sensor_TypeDef SensorIndex, Sensor_Mode_TypeDef Sensor_Mode)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	EXTI_InitTypeDef EXTI_InitStructure;
  	NVIC_InitTypeDef NVIC_InitStructure;

	RCC_APB2PeriphClockCmd(SENSOR_GPIO_CLK[SensorIndex],ENABLE);
	GPIO_InitStructure.GPIO_Pin=SENSOR_GPIO_PIN[SensorIndex];
	GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
	GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
	GPIO_Init(SENSOR_GPIO_PORT[SensorIndex],&GPIO_InitStructure);
	
	if (Sensor_Mode==Mode_EXTI)
	{
		//
		RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
		GPIO_EXTILineConfig(SENSOR_GPIO_PORT_SOURCE[SensorIndex], SENSOR_GPIO_PIN_SOURCE[SensorIndex]);
		EXTI_StructInit(&EXTI_InitStructure);
		EXTI_InitStructure.EXTI_Line=SENSOR_GPIO_EXTI_LINE[SensorIndex];
		EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;
		EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Rising;//EXTI_Trigger_Falling;
		EXTI_InitStructure.EXTI_LineCmd=ENABLE;
		EXTI_Init(&EXTI_InitStructure);

		NVIC_InitStructure.NVIC_IRQChannel=SENSOR_GPIO_IRQn[SensorIndex];
		NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0x0F;
		NVIC_InitStructure.NVIC_IRQChannelSubPriority=0x0F;
		NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
		NVIC_Init(&NVIC_InitStructure);
	}		
}
コード例 #7
0
ファイル: main.c プロジェクト: Czaper/STM32_basics
int main(void) {

	GPIO_InitTypeDef gpio;
	EXTI_InitTypeDef exti;
	NVIC_InitTypeDef nvic;

	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

	GPIO_StructInit(&gpio);
	gpio.GPIO_Pin = GPIO_Pin_5;
	gpio.GPIO_Mode = GPIO_Mode_OUT;
	gpio.GPIO_OType = GPIO_OType_PP;
	GPIO_Init(GPIOA, &gpio);

	gpio.GPIO_Pin = GPIO_Pin_13;
	gpio.GPIO_Mode = GPIO_Mode_IN;
	gpio.GPIO_PuPd = GPIO_PuPd_UP;
	gpio.GPIO_Speed = GPIO_Speed_2MHz;
	GPIO_Init(GPIOC, &gpio);

	GPIO_StructInit(&gpio);
	gpio.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
	GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 |
	GPIO_Pin_8 | GPIO_Pin_9;
	gpio.GPIO_Mode = GPIO_Mode_OUT;
	gpio.GPIO_OType = GPIO_OType_PP;
	GPIO_Init(GPIOC, &gpio);

	SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource13); //via DM00073522 faq file, onboard button as trigger

	EXTI_StructInit(&exti);
	exti.EXTI_Line = EXTI_Line13; //GPIO can use lines 0-15
	exti.EXTI_Mode = EXTI_Mode_Interrupt;
	exti.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
	exti.EXTI_LineCmd = ENABLE;
	EXTI_Init(&exti);

	nvic.NVIC_IRQChannel = EXTI15_10_IRQn; //to be found in stm32f30x.h, search 'external line'
	nvic.NVIC_IRQChannelPreemptionPriority = 0x00; //highest priority
	nvic.NVIC_IRQChannelSubPriority = 0x00; //-||-
	nvic.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&nvic);

	//SysTick_Config(SystemCoreClock / 1000); //tick every 1ms

	//uint32_t led = 0;

	/*while (1) {
		GPIO_SetBits(GPIOC, 1 << led); //set bit
		delay_ms(150);
		GPIO_ResetBits(GPIOC, 1 << led); //reset bit
		if (++led >= 10) {
			led = 0;
		}
	}*/
}
コード例 #8
0
ファイル: gpio_irq_api.c プロジェクト: AsamQi/mbed
void gpio_irq_free(gpio_irq_t *obj) {
    channel_ids[obj->irq_index] = 0;
    channel_gpio[obj->irq_index] = 0;
    channel_pin[obj->irq_index] = 0;
    // Disable EXTI line
    EXTI_InitTypeDef EXTI_InitStructure;
    EXTI_StructInit(&EXTI_InitStructure);
    EXTI_Init(&EXTI_InitStructure);  
    obj->event = EDGE_NONE;
}
コード例 #9
0
ファイル: nRF24L01P.c プロジェクト: thuSkywalker/t10cgrmt_fw
/**
  * @brief  External interrupt channel configuration for IRQ pin
	* @note   None
  * @param  Pointer to nRF24L01P_Object
  * @retval None
  */
void NRF_EXTI_Config(nRF24L01P_Object* nrf)
{
	EXTI_InitTypeDef EXTI_InitStructure;
	EXTI_StructInit(&EXTI_InitStructure);
	
	/* EXTI Line Config */
	GPIO_EXTILineConfig(nrf->IRQ_GPIO_PORT_SOURCE, nrf->IRQ_GPIO_PIN_SOURCE); 
	
  EXTI_InitStructure.EXTI_Line = nrf->EXTI_LINE;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure); 	
}
コード例 #10
0
ファイル: nrf2.c プロジェクト: thuSkywalker/t10cgrmt_fw
void NRF2_EXTI_Init(void)
{
	EXTI_InitTypeDef EXTI_InitStructure;
	EXTI_StructInit(&EXTI_InitStructure);
	
	/* IMPORTANT: Do Not Forget to Configure NVIC */
	
	/* EXTI Line Mode Config */
	GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource10); 
  EXTI_InitStructure.EXTI_Line = EXTI_Line10;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure); 	
}
コード例 #11
0
// init exti line 0 (PA0 - user button)
//==============================================================================
static void init( void )
{
  GPIO_InitTypeDef gpio_init;
  EXTI_InitTypeDef exti_init;
  NVIC_InitTypeDef nvic_init;

  // create semaphore to implement delayed interrupt service
  vSemaphoreCreateBinary( exti_0_semaphor );
  if( !exti_0_semaphor )
    hardware_fail();

  // reset the EXTI peripheral registers to their default reset values
  EXTI_DeInit();

  // fills each gpio_init fields with its default value
  GPIO_StructInit( &gpio_init );

  // fills each exti_init fields with its reset value
  EXTI_StructInit( &exti_init );

  // enable GPIOA and AFIO clock
  RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE );

  // configure PA0 as input floating
  gpio_init.GPIO_Pin = GPIO_Pin_0;
  gpio_init.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init( GPIOA, &gpio_init );

  // connect PA0 to EXTI line 0
  GPIO_EXTILineConfig( GPIO_PortSourceGPIOA, GPIO_PinSource0 );

  // configure EXTI line 0
  exti_init.EXTI_Line = EXTI_Line0;
  exti_init.EXTI_Mode = EXTI_Mode_Interrupt;
  exti_init.EXTI_Trigger = EXTI_Trigger_Rising;
  exti_init.EXTI_LineCmd = ENABLE;
  EXTI_Init( &exti_init );

  // enable EXTI line 0 interrupt
  // preemption priority: 12 or 0xcf > configMAX_SYSCALL_INTERRUPT_PRIORITY,
  // so we can use FreeRTOS API inside interrupt handler
  // sub priority: we don't use sub priority, look to main.c
  nvic_init.NVIC_IRQChannel = EXTI0_IRQn;
  nvic_init.NVIC_IRQChannelPreemptionPriority = 12;
  nvic_init.NVIC_IRQChannelSubPriority = 0;
  nvic_init.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init( &nvic_init );
}
コード例 #12
0
ファイル: main.c プロジェクト: DerekTan/STM32F107_ucosIII
/**
  * @brief  Configures the External Interrupts controller.
  * @param  None
  * @retval None
  */
void EXTI_Configuration(void)
{
  EXTI_InitTypeDef EXTI_InitStructure;

  /* Smartcard OFF */
  GPIO_EXTILineConfig(SC_PortSource, SC_PinSource);

  EXTI_StructInit(&EXTI_InitStructure);
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  EXTI_InitStructure.EXTI_Line = SC_EXTI;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);

  /* Clear SC EXTI Line Pending Bit */
  EXTI_ClearITPendingBit(SC_EXTI);
}
コード例 #13
0
/**
  * @brief  LPTIM GPIO,NVIC Configuration and EXTI LINE 23 configuration
  * @param  None
  * @retval None
  */
void LPTIM_Config(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;
  EXTI_InitTypeDef EXTI_InitStructure;
  
  /* Enable LPTIM Peripheral */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_LPTIM1, ENABLE);
  /* Enable GPIO for LPTIM Pins */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB , ENABLE);
  
  /* Configure Pin PB5 for Input 1 */
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_LPTIM);
  GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
  /* Configure External Trigger Pins (PC3,PB6) */
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource3, GPIO_AF_LPTIM);
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_LPTIM);
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_DOWN;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  
  /* Enable the LPTIM global Interrupt */
  /* Configure the Priority Group to 1 bit */                
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  /* Configure the SPI interrupt priority */
  NVIC_InitStructure.NVIC_IRQChannel = LPTIM1_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  
  /* EXTI Line 23 Configuration */
  EXTI_StructInit(&EXTI_InitStructure);
  EXTI_InitStructure.EXTI_Line = EXTI_Line23;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE; 
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  EXTI_Init(&EXTI_InitStructure);
}
コード例 #14
0
ファイル: cnc_joystick.c プロジェクト: Ivan47/CNC
void cnc_joystick_init(){
	GPIO_InitTypeDef GPIO_InitStructure; 
 	EXTI_InitTypeDef EXTI_InitStructure;
  	NVIC_InitTypeDef NVIC_InitStructure;   
  	uint8_t i;

  	GPIO_StructInit(&GPIO_InitStructure);
  	for( i = 0; i < 8; i++){
  		/* Enable the BUTTON Clock */
 		RCC_AHB1PeriphClockCmd(JOYSTICK_BUTTON_CLK[i], ENABLE);
  		/* Configure Button pin as input */
  		GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  		GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  		GPIO_InitStructure.GPIO_Pin = JOYSTICK_BUTTON_PIN[i];
  		GPIO_Init(JOYSTICK_BUTTON_PORT[i], &GPIO_InitStructure);
	}
	#if INTERRUPT_MODE
	RCC_AHB1PeriphClockCmd(JOYSTICK_INTERRUPT_CLK, ENABLE);
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Pin = JOYSTICK_INTERRUPT_PIN;
  GPIO_Init(JOYSTICK_INTERRUPT_PORT, &GPIO_InitStructure);

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  SYSCFG_EXTILineConfig(JOYSTICK_EXTI_PORT, JOYSTICK_EXTI_PIN);	

  EXTI_DeInit();
  EXTI_StructInit(&EXTI_InitStructure);
  EXTI_InitStructure.EXTI_Line = JOYSTICK_EXTI_LINE;	
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  EXTI_Init(&EXTI_InitStructure);

  NVIC_InitStructure.NVIC_IRQChannel = JOYSTICK_EXTI_IRQ;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 7;			//Because of FreeRTOS
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);
	#endif
}
コード例 #15
0
ファイル: platform_int.c プロジェクト: Shengliang/elua
static int gpioh_set_int_status( elua_int_id id, elua_int_resnum resnum, int status )
{
  int prev = gpioh_get_int_status( id, resnum );
  u32 mask = 1 << exint_gpio_to_src( resnum );
  EXTI_InitTypeDef exti_init_struct;
  
  if( status == PLATFORM_CPU_ENABLE )
  {
    // Configure port for interrupt line
    //GPIO_EXTILineConfig( PLATFORM_IO_GET_PORT( resnum ), PLATFORM_IO_GET_PIN( resnum ) );

    EXTI_StructInit(&exti_init_struct);
    exti_init_struct.EXTI_Line = exti_line[ exint_gpio_to_src( resnum ) ];
    exti_init_struct.EXTI_Mode = EXTI_Mode_Interrupt;
    if( ( ( ( EXTI->RTSR & mask ) != 0 ) && ( id == INT_GPIO_NEGEDGE ) ) ||
        ( ( ( EXTI->FTSR & mask ) != 0 ) && ( id == INT_GPIO_POSEDGE ) ) )
      exti_init_struct.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
    else
      exti_init_struct.EXTI_Trigger = id == INT_GPIO_POSEDGE ? EXTI_Trigger_Rising : EXTI_Trigger_Falling;
    exti_init_struct.EXTI_LineCmd = ENABLE;
    EXTI_Init(&exti_init_struct);

    EXTI_ClearITPendingBit( exti_line[ exint_gpio_to_src( resnum ) ] );
  }
  else
  {
    //Disable edge
    if( id == INT_GPIO_POSEDGE )
      EXTI->RTSR &= ~mask;
    else
      EXTI->FTSR &= ~mask;
    
    //If no edges enabled, disable line interrupt
    if( ( ( EXTI->RTSR | EXTI->FTSR ) & mask ) == 0 )
      EXTI->IMR &= ~mask;
  }
  return prev;
}
コード例 #16
0
ファイル: main.c プロジェクト: synweap15/PUT_PTM13_keyboard
void GPIOInit(void)
{
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); // led
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); // PS2 in
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); // timer

	/* LED */
	GPIO_InitTypeDef  GPIO_InitStructure;
	/* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15;
	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(GPIOD, &GPIO_InitStructure);

	/* PA1 & PA2 - PS2 clock i data */
	GPIO_InitTypeDef  GPIO_InitStructure_keyboard;
	GPIO_InitStructure_keyboard.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2;
	GPIO_InitStructure_keyboard.GPIO_PuPd = GPIO_PuPd_NOPULL;
	GPIO_InitStructure_keyboard.GPIO_Speed = GPIO_Speed_100MHz;
	GPIO_InitStructure_keyboard.GPIO_Mode = GPIO_Mode_IN;
	GPIO_Init(GPIOA, &GPIO_InitStructure_keyboard);

	EXTI_InitTypeDef EXTI_InitStructure;
	EXTI_StructInit(&EXTI_InitStructure);
	EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
	EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
	EXTI_InitStructure.EXTI_Line = EXTI_Line1;
	EXTI_InitStructure.EXTI_LineCmd = ENABLE;
	EXTI_Init(&EXTI_InitStructure);

	EXTI_ClearITPendingBit(EXTI1_IRQn);

	NVIC_InitTypeDef NVIC_InitStructure;
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
	NVIC_ClearPendingIRQ(EXTI1_IRQn);

	NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);

	NVIC_InitTypeDef NVIC_InitStructure_TIM;
	NVIC_InitStructure_TIM.NVIC_IRQChannel = TIM3_IRQn;
	NVIC_InitStructure_TIM.NVIC_IRQChannelPreemptionPriority = 0x00;
	NVIC_InitStructure_TIM.NVIC_IRQChannelSubPriority = 0x00;
	NVIC_InitStructure_TIM.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure_TIM);

	TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
	TIM_TimeBaseStructure.TIM_Prescaler = 42000-1;
	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
	TIM_TimeBaseStructure.TIM_Period = 500;
	TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
	TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
	TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);

	TIM_SetCounter(TIM3, 0);
	//na razie nie wlaczamy: TIM_Cmd(TIM3, ENABLE);

	TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
	TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
}
コード例 #17
0
ファイル: main.c プロジェクト: timmy00274672/STM32-Learning
/*******************************************************************************
* Function Name  : RCC_Configuration
* Description    : Configures the different system clocks.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void RCC_Configuration(void)
{
  /* RCC system reset(for debug purpose) */
  RCC_DeInit();

  /* Enable HSE */
  RCC_HSEConfig(RCC_HSE_ON);

  /* Wait till HSE is ready */
  HSEStartUpStatus = RCC_WaitForHSEStartUp();

  if(HSEStartUpStatus == SUCCESS)
  {
    /* Enable Prefetch Buffer */
    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

    /* Flash 2 wait state */
    FLASH_SetLatency(FLASH_Latency_2);
 
    /* HCLK = SYSCLK */
    RCC_HCLKConfig(RCC_SYSCLK_Div1); 
  
    /* PCLK2 = HCLK */
    RCC_PCLK2Config(RCC_HCLK_Div1); 

    /* PCLK1 = HCLK/2 */
    RCC_PCLK1Config(RCC_HCLK_Div2);

    /* PLLCLK = 8MHz * 9 = 72 MHz */
    RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);

    /* Enable PLL */ 
    RCC_PLLCmd(ENABLE);

    /* Wait till PLL is ready */
    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
    {
    }

    /* Select PLL as system clock source */
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

    /* Wait till PLL is used as system clock source */
    while(RCC_GetSYSCLKSource() != 0x08)
    {
    }
  }  
  
  /* GPIOA, GPIOC, GPIO KEY Button, GPIO_LED and AFIO clocks enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIO_KEY_BUTTON | 
                         RCC_APB2Periph_GPIO_LED | RCC_APB2Periph_GPIOC |
                         RCC_APB2Periph_AFIO, ENABLE);
   
#ifdef RTC_Alarm_WFEWakeUp
  /* Enable the PWR and BKP Clocks */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

  /* Configure the EXTI Line 17 as Event */
  EXTI_StructInit(&EXTI_InitStructure);
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Event;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  EXTI_InitStructure.EXTI_Line = EXTI_Line17;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);
  
  /* Allow access to BKP Domain */
  PWR_BackupAccessCmd(ENABLE);

  /* Reset Backup Domain */
  BKP_DeInit();
  /* Enable LSE */
  RCC_LSEConfig(RCC_LSE_ON);
  /* Wait till LSE is ready */
  while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
  {
  }

  /* Select LSE as RTC Clock Source */
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);

  /* Enable the RTC Clock */
  RCC_RTCCLKCmd(ENABLE);
  /* Wait for APB registers synchronisation */
  RTC_WaitForSynchro();
  
  /* Wait until last write operation on RTC registers has finished */
  RTC_WaitForLastTask();
  /* Set the RTC time base to 1s */
  RTC_SetPrescaler(32767);
    /* Wait until last write operation on RTC registers has finished */
  RTC_WaitForLastTask();
#endif 

}
コード例 #18
0
ファイル: ui.c プロジェクト: equinoxorg/standalone_v2
/**
  * @brief  Initialises the hardware required for the keypad. Also sets up interrupts for keypad events.
  * @param  None
  * @retval None
  */
void keypad_init (void) 
{
	//Output Pins: PA15, PB6, PB5, PB4
		
	EXTI_InitTypeDef   EXTI_InitStructure;
  GPIO_InitTypeDef   GPIO_InitStructure;
  NVIC_InitTypeDef   NVIC_InitStructure;
 
	// GPIOA Clocks enable 
  RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOA, ENABLE);
  
  // GPIOA Configuration 
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
	
	GPIO_ResetBits(GPIOA, GPIO_Pin_15);
	
	// GPIOB Clocks enable 
  RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOB, ENABLE);
  
	GPIO_StructInit(&GPIO_InitStructure);
	
  // GPIOB Configuration 
  GPIO_InitStructure.GPIO_Pin = ( GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 );
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
	
	GPIO_ResetBits(GPIOB, ( GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 ));
	
	//Input Pins with pull-ups and interrupt: PB7, PB8, PB9
	
	// GPIOB Clocks enable 
  RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOB, ENABLE);
  
	GPIO_StructInit(&GPIO_InitStructure);
	
  // GPIOB Configuration
  GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9);
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  // Enable SYSCFG clock 
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  
  // Connect External Line x to PBx pin 
  SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource7);
	SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource8);
	SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource9);
  
	// Configure External Interrupts on Lines
	EXTI_StructInit(&EXTI_InitStructure);
  EXTI_InitStructure.EXTI_Line = (EXTI_Line7 | EXTI_Line8 | EXTI_Line9);
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);

  // Enable and set EXTI4_15 Interrupt 
  NVIC_InitStructure.NVIC_IRQChannel = EXTI4_15_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
	
}