예제 #1
0
void NEC_ReceiveInterrupt(NEC_FRAME f) {
	GPIO_ToggleBits(GPIOD, GPIO_Pin_7);
	char buf[12];
	USART_WriteString("NEC Frame was received : \r\nAddress : ");
	Int2Str(buf, f.Address);
	USART_WriteString(buf);
	USART_WriteString("\r\nCommand : ");
	Int2Str(buf, f.Command);
	USART_WriteString(buf);
	USART_WriteString("\r\n");

	switch (f.Command) {
	case 1:
		GPIO_ToggleBits(GPIOD, GPIO_Pin_12);
		break;
	case 2:
		GPIO_ToggleBits(GPIOD, GPIO_Pin_13);
		break;
	case 3:
		GPIO_ToggleBits(GPIOD, GPIO_Pin_14);
		break;
	case 4:
		GPIO_ToggleBits(GPIOD, GPIO_Pin_15);
		break;
	}
}
예제 #2
0
int main(void) {
///////// Initial Portion /////////////////////////
  init_USART1(9600); // initialize USART1 @ 9600 baud
	SystemCoreClockUpdate();                      /* Get Core Clock Frequency   */
  if (SysTick_Config(SystemCoreClock / 1000)) { /* SysTick 1 msec interrupts  */
    while (1);                                  /* Capture error              */
  }
  USART_puts(USART1, "Init 1 complete! Hello World!rn"); // just send a message to indicate that it works

		//Init GPIO for Leds on board and button input
	init_GPIO();
	
	/////////////////- Loop - ////////////////////////////////////
  while (1){
    
     // You can do whatever you want in here
		USART_puts(USART1, "Init 2 complete! Hello World! \r \n"); // just send a message to indicate that it works
				
		//GPIO_ToggleBits(GPIOD, GPIO_Pin_15 | GPIO_Pin_14 | GPIO_Pin_13| GPIO_Pin_12 );
		GPIO_ToggleBits(GPIOD, GPIO_Pin_12 ); //Test Leds on board
		Delay(200);
		GPIO_ToggleBits(GPIOD, GPIO_Pin_13 ); //Test Leds on board
		Delay(200);
		GPIO_ToggleBits(GPIOD, GPIO_Pin_14 ); //Test Leds on board
		Delay(1000);
     
  }
//////////////////////////////////////////////////////////	
}
예제 #3
0
/*******************************************************************************
* Function Name  : gpio_toggle
* Description    : Toggle the value of a specified GPIO
* Input          : - Gpio: Select the GPIO to be toggled
* Output         : None
* Return         : None
*******************************************************************************/
void gpio_toggle(const _Gpio_Descriptor *Gpio)
{
  if (!Gpio) return;
  #ifdef _GPIO_I2CIO_SUPPORT
    if (gpio_is_i2c(Gpio)) i2cio_toggle_output(Gpio->Port, Gpio->GPIO_Pin);
    else GPIO_ToggleBits((GPIO_TypeDef *)Gpio->Port, Gpio->GPIO_Pin);
  #else
    GPIO_ToggleBits((GPIO_TypeDef *)Gpio->Port, Gpio->GPIO_Pin);
  #endif
}
예제 #4
0
파일: main.c 프로젝트: apkbox/lpc_testbed
void TIMER32_0_IRQHandler()
{
    static unsigned int duty_counter_r = 0;
    static unsigned int duty_counter_g = 0;
    static unsigned int duty_counter_b = 0;
    static unsigned int bl_duty_counter = 0;

    static unsigned int period_counter = 0;
    static int activity_counter = 0;

    CoEnterISR();

    TIM_ClearIntPending(LPC_TMR32B0, TIM_MR0_INT);

    // 39.0625us activity indicator (for calibration)
    GPIO_ToggleBits(TIMER_ACTIVITY_PORT, TIMER_ACTIVITY_PIN);

    if( period_counter -- > 0 ) {
        if( duty_counter_r -- == 0 )
            GPIO_ResetBits(RED_PORT, RED_PIN);
        if( duty_counter_g -- == 0 )
            GPIO_ResetBits(GREEN_PORT, GREEN_PIN);
        if( duty_counter_b -- == 0 )
            GPIO_ResetBits(BLUE_PORT, BLUE_PIN);

        if (bl_duty_counter-- == 0)
            GPIO_ResetBits(LCD_BACKLITE_PORT, LCD_BACKLITE_PIN);
    }
    else {
        if( activity_counter ++ >= TICKS_PER_SECOND ) {
            activity_counter = 0;
            GPIO_ToggleBits(TIMER_ACTIVITY_PORT, TIMER_ACTIVITY_PIN);

            //if( device_mode == AMBIENT_TEMPERATURE )
            //    PLUGIN_Temperature_Update();
        }

        SEQ_Tick();
        duty_counter_r = SEQ_CurrentRed();
        duty_counter_r == 0 ? GPIO_ResetBits(RED_PORT, RED_PIN) : GPIO_SetBits(RED_PORT, RED_PIN);

        duty_counter_g = SEQ_CurrentGreen();
        duty_counter_g == 0 ? GPIO_ResetBits(GREEN_PORT, GREEN_PIN ) : GPIO_SetBits(GREEN_PORT, GREEN_PIN );

        duty_counter_b = SEQ_CurrentBlue();
        duty_counter_b == 0 ? GPIO_ResetBits(BLUE_PORT, BLUE_PIN ) : GPIO_SetBits(BLUE_PORT, BLUE_PIN );

        bl_duty_counter = backlite_power;
        bl_duty_counter == 0 ? GPIO_ResetBits(LCD_BACKLITE_PORT, LCD_BACKLITE_PIN) : GPIO_SetBits(LCD_BACKLITE_PORT, LCD_BACKLITE_PIN);

        period_counter = 255;
    }

    CoExitISR();
}
예제 #5
0
int main(void) {
    uint8_t c;
    /* System Init */
    SystemInit();

    /* Initialize LED's. Make sure to check settings for your board in tm_stm32f4_disco.h file */
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE); //
    GPIO_InitTypeDef GPIO_InitDef;

    GPIO_InitDef.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14; // we gaan pin 13 en 14 gebruiken

    GPIO_InitDef.GPIO_OType = GPIO_OType_PP;		// init push-pull
    GPIO_InitDef.GPIO_Mode = GPIO_Mode_OUT; 		// init output
    GPIO_InitDef.GPIO_PuPd = GPIO_PuPd_NOPULL;	// init no pullup
    GPIO_InitDef.GPIO_Speed = GPIO_Speed_100MHz;	// init 100 MHZ

    //Initialize pins
    GPIO_Init(GPIOG, &GPIO_InitDef);
    GPIO_ToggleBits(GPIOG, GPIO_Pin_13);


    /* Initialize USB VCP */
    TM_USB_VCP_Init();

    while (1) {
        /* USB configured OK, drivers OK */
        if (TM_USB_VCP_GetStatus() == TM_USB_VCP_CONNECTED) {
            /* Turn on GREEN led */
            //TM_DISCO_LedOn(LED_GREEN);
            //TM_DISCO_LedOff(LED_RED);
            /* If something arrived at VCP */
            if (TM_USB_VCP_Getc(&c) == TM_USB_VCP_DATA_OK) {
                /* Return data back */
                TM_USB_VCP_Putc('0' + (c /100) % 10);
                TM_USB_VCP_Putc('0' + (c /10) % 10);
                TM_USB_VCP_Putc('0' + c % 10);
                TM_USB_VCP_Putc(',');
                TM_USB_VCP_Putc(' ');
                GPIO_ToggleBits(GPIOG, GPIO_Pin_13 | GPIO_Pin_14);
            }
            else
            {
                //TM_USB_VCP_Putc(' ');
            }
        } else {
            /* USB not OK */
            //TM_DISCO_LedOff(LED_GREEN);
            //TM_DISCO_LedOn(LED_RED);
        }
    }
}
예제 #6
0
파일: main.c 프로젝트: ahmedjafri/EE478
void flipBuffers()
{
        char *tempBuffer = currentReadBuffer;
        currentReadBuffer = currentWriteBuffer;
        currentWriteBuffer = tempBuffer;
        read_ptr = currentReadBuffer;
        
        rxIndex = 0;
        countFlips += 1;
        
        GPIO_ToggleBits(GPIOD,  GPIO_Pin_11);
        GPIO_ToggleBits(GPIOD,  GPIO_Pin_11);
        
}
예제 #7
0
//Rotina para exibir, visualmente, que os dispostivios foram iniciados
void blinkDebugLeds() {

	GPIO_ToggleBits(GPIOD, GPIO_Pin_12);

	delay(2500);

	GPIO_ToggleBits(GPIOD, GPIO_Pin_12);

	delay(2500);
	
	GPIO_ToggleBits(GPIOD, GPIO_Pin_13);

	delay(2500);

	GPIO_ToggleBits(GPIOD, GPIO_Pin_13);

	delay(2500);

	GPIO_ToggleBits(GPIOD, GPIO_Pin_14);

	delay(2500);

	GPIO_ToggleBits(GPIOD, GPIO_Pin_14);

	delay(2500);

	GPIO_ToggleBits(GPIOD, GPIO_Pin_15);

	delay(2500);

	GPIO_ToggleBits(GPIOD, GPIO_Pin_15);

	delay(2500);
}
예제 #8
0
파일: LogA_LEDs.c 프로젝트: useger/src
void LogA_ToggleActiveLED(void)
{
	switch (LEDCurrentlyBlinking)
	{
		case LEDBlinking_Red_Slowly :
		case LEDBlinking_Red_Quickly :
			{
				GPIO_ToggleBits(LEDRED);
				GPIO_ResetBits(LEDORANGE);
				GPIO_ResetBits(LEDGREEN);
				GPIO_ResetBits(LEDBLUE);
			}
			break;
		case LEDBlinking_Orange_Slowly :
		case LEDBlinking_Orange_Quickly :
			{
				GPIO_ResetBits(LEDRED);
				GPIO_ToggleBits(LEDORANGE);
				GPIO_ResetBits(LEDGREEN);
				GPIO_ResetBits(LEDBLUE);
			}
			break;
		case LEDBlinking_Green_Slowly :
		case LEDBlinking_Green_Quickly :
			{
				GPIO_ResetBits(LEDRED);
				GPIO_ResetBits(LEDORANGE);
				GPIO_ToggleBits(LEDGREEN);
				GPIO_ResetBits(LEDBLUE);
			}
			break;
		case LEDBlinking_Blue_Slowly :
		case LEDBlinking_Blue_Quickly :
			{
				GPIO_ResetBits(LEDRED);
				GPIO_ResetBits(LEDORANGE);
				GPIO_ResetBits(LEDGREEN);
				GPIO_ToggleBits(LEDBLUE);
			}
			break;
		case LEDBlinking_ToggleAllFour :
		{
			GPIO_ToggleBits(LEDRED);
			GPIO_ToggleBits(LEDORANGE);
			GPIO_ToggleBits(LEDGREEN);
			GPIO_ToggleBits(LEDBLUE);
		}
		break;
		// Covers LEDBlinking_None
		default:
			{
				GPIO_ResetBits(LEDRED);
				GPIO_ResetBits(LEDORANGE);
				GPIO_ResetBits(LEDGREEN);
				GPIO_ResetBits(LEDBLUE);
			}
			break;
	}
}
예제 #9
0
void RxPacket(void const *argument){
	uint8_t mode_filter, transmit_mode;
   //uint8_t buf;
	uint8_t buf;
	Packet pkt;
   GPIO_ResetBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
   mode_filter = 0x70;
   transmit_mode = 0x20;
	printf("Thread_started. waitig for signal\n");
   // put reciever in RX mode
	CC2500_Strobe(CC2500_STROBE_SRX, 0x00);
   
	while(1){
		int i;
		osSignalWait(RX_PKT, osWaitForever);
		
      //turn on LED on packet RX
		GPIO_ToggleBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
		CC2500_Read(&buf ,CC2500_FIFO_ADDR, 1); 
		//CC2500_RxPackets((uint8_t*)&pkt, CC2500_SETTING_PKTLEN + 2);
		printf("buf is %d \n", buf);

		if(pkt.Src_addr == 0x01){
			i++;
			 // put the measured RSSI in  byte 3 for main board
      pkt.Aux_rssi = pkt.Rssi;
      printf("%d Packet received from user beacon\n", i);
      printf("SRC: 0x%02x\t\t", pkt.Src_addr);
      printf("SEQ: 0x%02x\t\t", pkt.Seq_num);
      printf("RAW_RSSI: 0x%02x\n", pkt.Rssi);
			
			buf = CC2500_Strobe(CC2500_STROBE_SRX, 0x3F);
			printf("Buffer : 0x%02x\n", buf); 
		}
      
		
      // change the source address on the packet
      pkt.Src_addr = CC2500_SETTING_ADDR;
      
		// transmit this packet for main board
      osDelay(100);
      CC2500_TxPacket((uint8_t*)&pkt, CC2500_SETTING_PKTLEN);
		
      // turn off LED on successful Tx
      GPIO_ToggleBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
      // put device back to rx mode
      osDelay(100);
	}
}
예제 #10
0
// this is the interrupt request handler (IRQ) for ALL USART3 interrupts
void USART3_IRQHandler(void){

	// check if the USART3 receive interrupt flag was set
	if( USART_GetITStatus(USART3, USART_IT_RXNE) ){

		/*check the uart RX have accept the char*/
		GPIO_ToggleBits(GPIOD,GPIO_Pin_14);


		static uint8_t cnt = 0; // this counter is used to determine the uart receive string length

		//Receive_data = USART3->DR; // the character from the USART3 data register is saved in t
		Receive_data = USART_ReceiveData(USART3);;

		/* check if the received character is not the LF character (used to determine end of string) 
		 * or the if the maximum string length has been been reached 
		 */

		if( cnt < MAX_STRLEN){ 
			received_string[cnt] = Receive_data;
            if(Receive_data=='0') GPIO_ToggleBits(GPIOD,GPIO_Pin_15);

            /*start determine the period of command.*/
            if(received_string[cnt]=='\r'){
                Receive_String_Ready = 1; /*Ready to parse the command */
                cnt=0; /*restart to accept next stream message.*/
            }
            else{
                cnt++;
            }
		}
		else{ // over the max string length, cnt return to zero.
			Receive_String_Ready=1;
			cnt = 0;  
		}
		if(Receive_String_Ready){
			//print the content of the received string
			USART_puts(USART3, received_string);
			USART_puts(USART3,"\r\n");
			//receive_task();
			/*clear the received string and the flag*/
			Receive_String_Ready = 0;
			int i;
			for( i = 0 ; i< MAX_STRLEN ; i++){
				received_string[i]= 0;
			}
		}
	}
}
예제 #11
0
void tcp_rx_handler(void)
{
  if(crc32((uint8_t*)&rx_tcp_msg+4,rx_tcp_msg.msg_len + TCP_HEADER_SIZE - 4) == rx_tcp_msg.msg_crc)
  {
    switch(rx_tcp_msg.msg_id)
    {
      case CHECK_CONNECT: 
           tcp_write(pout_pcb," соединение установлено",23,1);
           tcp_output(pout_pcb);
           tcp_sent(pout_pcb,NULL); 
      break;
      
      case SEND_FILE: 
        {
           int adr  = rx_tcp_msg.data[0];
           int size = rx_tcp_msg.msg_len - 1;
           memcpy(&buffer[adr][0],&rx_tcp_msg.data[1],size);
        }
      break;
      
      case SET_DATA_DAC: 
        {
           unsigned short data_temp = *((unsigned short*)&rx_tcp_msg.data[0]);
           for (int i = 0; i < 8192; i++) *(uint16_t *) (sram_bank4 + 0) =  data_temp;
           GPIO_ToggleBits(GPIOI, GPIO_Pin_0); 
        }
      break;
      

      case SEND_FILE_DONE: 
        {
          int adr,size;
          unsigned short *pbuffer = (unsigned short*)&buffer[0][0];
 
          adr  = rx_tcp_msg.data[0];
          size = rx_tcp_msg.msg_len - 1;
          memcpy(&buffer[adr][0],&rx_tcp_msg.data[1],size);
           
          for (int i = 0; i < 8192; i++) *(uint16_t *) (sram_bank4 + 0) = *(pbuffer++);
             
          GPIO_ToggleBits(GPIOI, GPIO_Pin_0); 
          
        } 
     
      break;
    }
  }
}
예제 #12
0
int main(void)
{
  Timer_init();

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  GPIO_InitTypeDef  GPIO_InitStructure;
  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);

  static uint32_t timerValue;
  uint32_t lastTime = TIM2->CNT;
  while (1)
  {
    timerValue = TIM2->CNT;

    if( timerValue - lastTime > 1000000 )
    {
      GPIO_ToggleBits(GPIOD, GPIO_Pin_12 |GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
      lastTime = timerValue;
    }

  }
}
예제 #13
0
int main(void)
{
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

  /* 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);

  uint8_t rec;
  spi_init();

  while (1)
  {
    GPIO_ToggleBits( GPIOD, GPIO_Pin_15 );
    GPIOC->BSRRH |= GPIO_Pin_4;
    rec = spi_send( 0xaa );

    GPIOC->BSRRL |= GPIO_Pin_4;
    Delay( 0xffff );
  }
}
예제 #14
0
int main(void)
{
  uint8_t colorR =0 ,colorG =0 ,colorB =0 ;
  uint8_t colorR_dir =0 ,colorG_dir =0 ,colorB_dir =0 ;
  char lcd_text_buff[100];

  float GyX =0.0f, GyY =0.0f, GyZ =0.0f;
  float X_offset =0.0f,Y_offset =0.0f,Z_offset =0.0f;
  uint32_t i=0;
  float delay_count=1000.0f;

  GPIO_Configuration();
  USART1_Configuration();
  CANx_Config();
  CANx_NVIC_Config();
  lcd_init();
  lcd_drawBackground(20,60,250);
  lcd_drawBGPersimmon(20, 60, 250);


    LCD_SetColors(LCD_COLOR_WHITE-1,LCD_COLOR_WHITE);
    LCD_SetFont(&Font16x24);
    LCD_DisplayStringLine(LINE(1), (uint8_t*)" CAN Bus DEMO  ");
    DrawNeedle(120,120,60,300.0f,0.0f,200.0f);
  while (1)
  {
    CANx_Transmit();
    GPIO_ToggleBits(LED4);

    Delay_1us(1000);
  }
  
}
예제 #15
0
void vLEDTask( void *pvParameters ) {
	const portTickType xDelay = 1000;
	while(1) {
		GPIO_ToggleBits(GPIOD, GPIO_Pin_12);
	    vTaskDelay(xDelay);
	}
}
예제 #16
0
int main(void)
{
	// Set clock to 168MHz
	CLOCK_SetClockTo168MHz();
	// Delay initialization
	DELAY_Init();

	// Enable clock for GPIOD
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
	// Initialize PD13 and PD15 as output for orange and blue LED
	GPIO_InitTypeDef GPIO_InitStruct;
	GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStruct.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_15;
	GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
	GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
	GPIO_Init(GPIOD, &GPIO_InitStruct);

	// External interrupt initialization
	EXTI0_Init();

	while (1)
	{
		// Toggle blue LED (PD15) every 5s
		GPIO_ToggleBits(GPIOD, GPIO_Pin_15);
		DELAY_Ms(5000);
	}
}
예제 #17
0
int main()
{
  while(true){
    Reset();
    systickInit();
    gpioInit();
    adcInit();
    lcdInit();
    tsInit();
    welcomeScreen();
    #ifdef DEBUG
      ledInit();
    #endif
    spiInit();
    while(!IsRebootRequired()){
      if(IsSynchronizationRequired()){
        AssertGoBusIRQ();
      }
      #ifdef DEBUG
        GPIO_ToggleBits(GPIOC, GPIO_Pin_13);
        delay(5);
      #endif
    }
  }
}
예제 #18
0
int main(void)
{
    GPIO_InitTypeDef  GPIO_InitStructure;

    /* Enable GPIOG clock */
    LED_RCC_CLKCMD(LED_RCC_PERIPH, ENABLE);

    /* Configure LED pin in output mode */
    GPIO_InitStructure.GPIO_Pin   = LED_GPIO_PIN;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;

    GPIO_Init(LED_GPIO_PORT, &GPIO_InitStructure);
    GPIO_SetBits(LED_GPIO_PORT, LED_GPIO_PIN);

    /* configure systick to interrupt every 1ms */
    if (SysTick_Config(SystemCoreClock / 1000)) {
        while(1);
    }

    /* Do nothing */
    while (1) {
        /* wait 500ms */
        systick_sleep(500);

        /* Toggle LED */
        GPIO_ToggleBits(LED_GPIO_PORT, LED_GPIO_PIN);
    }
}
예제 #19
0
 */
static uint16_t VCP_DataTx(uint8_t* Buf, uint32_t Len) {
	uint32_t i = 0;

	GPIO_ToggleBits(LED3_GPIO_PORT, LED3_PIN);

	//If no buffer, we're supposed to receive USART, send USB
//   if (Buf==NULL) {
//      if (g_lc.datatype == 7)
//         APP_Rx_Buffer[APP_Rx_ptr_in] = USART_ReceiveData(DISCOVERY_COM) & 0x7F;
//      else if (g_lc.datatype == 8)
//         APP_Rx_Buffer[APP_Rx_ptr_in] = USART_ReceiveData(DISCOVERY_COM);
//
//      APP_Rx_ptr_in++;
//
//      /* To avoid buffer overflow */
//      if(APP_Rx_ptr_in == APP_RX_DATA_SIZE)
//         APP_Rx_ptr_in = 0;
//   }
//   else

	if (Buf) {      //If we were passed a buffer, transmit that
		while (i < Len) {
			APP_Rx_Buffer[APP_Rx_ptr_in] = *(Buf + i);
			APP_Rx_ptr_in++;
			i++;

			/* To avoid buffer overflow */
			if (APP_Rx_ptr_in == APP_RX_DATA_SIZE)
				APP_Rx_ptr_in = 0;
		}
	}

	return USBD_OK;
예제 #20
0
void GPIO< port, pin >::toggle()
{
    constexpr auto m_port = pick_port(port);
    constexpr auto m_pin  = pick_pin(pin);

    GPIO_ToggleBits(m_port, m_pin);
}
예제 #21
0
파일: main.c 프로젝트: sayden/stm32f407vg
int main(void) {
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
    GPIO_InitTypeDef GPIO_InitDefLed;
 
    GPIO_InitDefLed.GPIO_Pin = GPIO_Pin_13;
    GPIO_InitDefLed.GPIO_OType = GPIO_OType_PP;
    GPIO_InitDefLed.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitDefLed.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_InitDefLed.GPIO_Speed = GPIO_Speed_100MHz;

    //Initialize pins
    GPIO_Init(GPIOD, &GPIO_InitDefLed);


    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
    GPIO_InitTypeDef GPIO_InitDefBtn;
    GPIO_InitDefBtn.GPIO_Pin = GPIO_Pin_0;
    GPIO_InitDefBtn.GPIO_Mode = GPIO_Mode_IN;
    GPIO_InitDefBtn.GPIO_PuPd = GPIO_PuPd_DOWN;

    GPIO_Init(GPIOA, &GPIO_InitDefBtn);
 
    volatile int i;
    while (1) {
        // Toggle leds
        if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)){
            GPIO_ToggleBits(GPIOD, GPIO_Pin_13);
        }
        // Waste some tome
        for (i = 0; i < 500000; i++);
    }
}
예제 #22
0
void iniciarMPU6050Imu() {
    MPU6050_InitStruct initialConfig;

    //Configurações dos sensores.
    initialConfig.accelFullScale = AFS_8G;              //Fundo de escala de 8G.
    initialConfig.gyroFullScale = FS_2000DPS;             //Fundo de escala de 500 graus por segundo.
    initialConfig.clockSource = MPU6050_CLK_GYRO_X_PLL; //Fonte de clock no oscilador do eixo X do giroscópio.
    initialConfig.fifoEnabled = 0;                      //Fifo desligada;
    initialConfig.sampleRateDivider = 0;                //Frequência do Accel é igual à do Gyro //Taxa de saída de 500 Hz
    initialConfig.temperatureSensorDisabled = 0;        //Sensor de temperatura ligado.
    initialConfig.interruptsConfig = 0x01;              //Ativa a interrupção de Data Ready;
    initialConfig.intPinConfig = 0x20;                  //Ativa o pino de interrupção com o modo que o "liga" quando há uma interrupção.

    initialConfig.digitalLowPassConfig = 0x01;            //Sem filtro passa baixa
    //initialConfig.digitalLowPassConfig = 0x02;            //Frequências de corte em 90Hz e Aquisição em 1Khz. (Delay de aprox 10ms)
    //initialConfig.digitalLowPassConfig = 0x03;            //Frequências de corte em 40Hz e Aquisição em 1Khz. (Delay de aprox 5ms)
    //initialConfig.digitalLowPassConfig = 0x04;            //Frequências de corte em 20Hz e Aquisição em 1Khz. (Delay de aprox 8,5ms)
    //initialConfig.digitalLowPassConfig = 0x00;            //Frequências de corte em 260Hz e Aquisição em 8Khz. (Delay de aprox 0.98ms)


    MPU6050_Init(I2C3, &initialConfig);

    float offset_accel[3] = {0,0,0};
    float offset_gyro[3] = {0,0,0};
    float temp_accel[3];
    float temp_gyro[3];  

    delay(10000);

    MPU6050_configIntPin(RCC_AHB1Periph_GPIOD, GPIOD, GPIO_Pin_0);

    //Carregar valores de "parado" (Offsets).
    uint16_t counterOffsetAquisition = 10000;
    while(counterOffsetAquisition--) {
        while(MPU6050_checkDataReadyIntPin() == Bit_RESET);

        MPU6050_readData(I2C3, temp_accel, temp_gyro);
        GPIO_ToggleBits(GPIOD, GPIO_Pin_12);

        offset_accel[0] += temp_accel[0];
        offset_accel[1] += temp_accel[1];
        offset_accel[2] += (1-temp_accel[2]);

        offset_gyro[0] += temp_gyro[0];
        offset_gyro[1] += temp_gyro[1];
        offset_gyro[2] += temp_gyro[2];
    }

    offset_accel[0] = offset_accel[0]/((float)(10000));
    offset_accel[1] = offset_accel[1]/((float)(10000));
    offset_accel[2] = offset_accel[2]/((float)(10000));

    offset_gyro[0] = offset_gyro[0]/((float)(10000));
    offset_gyro[1] = offset_gyro[1]/((float)(10000));
    offset_gyro[2] = offset_gyro[2]/((float)(10000));

    setar_offset_acel(offset_accel);
    setar_offset_gyro(offset_gyro);
}
예제 #23
0
static void prvQueueReceiveTask( void *pvParameters )
{
uint32_t ulReceivedValue;

	for( ;; )
	{
		/* Espere hasta que algo llega a la cola */
		xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );

		if( ulReceivedValue == 0x31 ) /* Recibe el No 1 */
			{
			/* Incrementa el contador */
			ulCountOfItemsReceivedOnQueue++;

			/*Cambia el estado del led */
			GPIO_ToggleBits(PORTD, LED_GREENP);
			}

		if( ulReceivedValue == 0x32 ) /* Recibe el No 2 */
			{
			/* Incrementa el contador */
			ulCountOfItemsReceivedOnQueue++;

			/*Cambia el estado del led */
			GPIO_ToggleBits(PORTD, LED_ORANGEP);
			}

		if( ulReceivedValue == 0x33 ) /* Recibe el No 3 */
			{
			/* Incrementa el contador */
			ulCountOfItemsReceivedOnQueue++;

			/*Cambia el estado del led */
			GPIO_ToggleBits(PORTD, LED_REDP);
			}

		if( ulReceivedValue == 0x34 ) /* Recibe el No 4 */
			{
			/* Incrementa el contador */
			ulCountOfItemsReceivedOnQueue++;

			/*Cambia el estado del led */
			GPIO_ToggleBits(PORTD, LED_BLUEP);
			}
	}
}
예제 #24
0
void vTaskPB( void ) {
	xSemaphoreTake( xTestSemaphore, 0 );
	for( ;; )
	{
		xSemaphoreTake( xTestSemaphore, portMAX_DELAY );
		GPIO_ToggleBits(GPIOD, GPIO_Pin_15);
	}
}
예제 #25
0
void TIM2_IRQHandler(void)
{
  if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET) {
    TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
      TIM_ITConfig(TIM2, TIM_IT_Update, DISABLE);
    GPIO_ToggleBits(GPIOB, GPIO_Pin_6);
  }
}
예제 #26
0
void TIM2_IRQHandler()
{
    if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
    {
        TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
        GPIO_ToggleBits(GPIOD, GPIO_Pin_12);
    }
}
예제 #27
0
파일: app.c 프로젝트: eagle860/stm32f207
static void led_toggle(void *p_arg)
{
    for (;;)
    {
        GPIO_ToggleBits(GPIOF, GPIO_Pin_8);
        OSTimeDly(500);
    }
}
예제 #28
0
/* Handle PD0 interrupt */
void EXTI0_IRQHandler(void) {
    /* Make sure that interrupt flag is set */
    if (EXTI_GetITStatus(EXTI_Line0) != RESET) {
    	while(GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_0));
		GPIO_ToggleBits(GPIOB, GPIO_Pin_0);

        EXTI_ClearITPendingBit(EXTI_Line0);
    }
}
예제 #29
0
void TIM4_IRQHandler(void)     
{
if(TIM4->SR & TIM_SR_UIF) // if UIF flag is set
  {
    TIM4->SR &= ~TIM_SR_UIF; // clear UIF flag                                   
		GPIO_ToggleBits(GPIOC, GPIO_Pin_5);
		switching();
  }
}
예제 #30
0
void AJS_TargetIO_PinToggle(void* pinCtx)
{
    GPIO* gpio = (GPIO*)pinCtx;
    if (gpio->pwm.dutyCycle) {
        ReleasePWM(gpio);
    }
    GPIO_ToggleBits(gpio->GPIOx, gpio->gpioPin);
    return;
}