Ejemplo n.º 1
0
/**************************************************************************//**
 * @brief
 *   Timeout function for keyboard scan timer.
 *   Scan keyboard to check for key press/release events.
 *   This function is called at a fixed rate.
 *****************************************************************************/
static void ScanTimeout( void )
{
  bool pushedPB0;
  bool pushedPB1;
  HIDKBD_KeyReport_t *report;

  /* Check pushbutton PB0 */
  pushedPB0 = GPIO_PinInGet( BUTTON0_PORT, BUTTON0_PIN ) == 0;

  if ( pushedPB0 != keyPushed )  /* Any change in keyboard status ? */
  {
    if ( pushedPB0 )
    {
      report = (void*)&USBDESC_reportTable[ 0 ];
    }
    else
    {
      report = (void*)&USBDESC_noKeyReport;
    }

    /* Pass keyboard report on to the HID keyboard driver. */
    HIDKBD_KeyboardEvent( report );
  }

  /* Keep track of the new keypush event (if any) */
  if ( pushedPB0 && !keyPushed )
  {
    /* Advance to next position in report table */
    keySeqNo++;
    if ( keySeqNo == (sizeof(USBDESC_reportTable) / sizeof(HIDKBD_KeyReport_t)))
    {
      keySeqNo = 0;
    }
  }
  keyPushed = pushedPB0;

  /* Check pushbutton PB1 */
  pushedPB1 = GPIO_PinInGet( BUTTON1_PORT, BUTTON1_PIN ) == 0;

  if ( pushedPB1 != keyPushed )  /* Any change in keyboard status ? */
  {
    if ( pushedPB1 )
    {
      report = (void*)&USBDESC_reportTable[ 1 ];
    }
    else
    {
      report = (void*)&USBDESC_noKeyReport;
    }

    /* Pass keyboard report on to the HID keyboard driver. */
    HIDKBD_KeyboardEvent( report );
  }
  keyPushed = pushedPB1;

  /* Restart keyboard scan timer */
  USBTIMER_Start( SCAN_TIMER, SCAN_RATE, ScanTimeout );
}
Ejemplo n.º 2
0
/******************************************************************************
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Initialize chip */
  CHIP_Init();
  
  /* Enable code view */
  setupSWO();

  /* Initialize LCD */
  SegmentLCD_Init(false);

  /* Enable the HFPER clock */
  CMU_ClockEnable(cmuClock_HFPER, true);

  /* Configure RTC and GPIO */
  rtc_setup();
  gpio_setup();

  /* Stay in this loop forever */
  while (1)
  {
    /* Wait for Push Button 1 to be pressed */
    while (GPIO_PinInGet(PB0_PORT, PB0_PIN)) ;
    /* and released, so that we do not exit the while loop below immediately */
    while (!GPIO_PinInGet(PB0_PORT, PB0_PIN)) ;

    /* Reset time */
    time = 0;

    /* Disable LCD */
    LCD_Enable(true);

    /* Update time until Push Button 1 is pressed again */
    while (1)
    {
      if (RTC_CounterGet() == 0)
      {
        SegmentLCD_Number(++time);
      }

      if (!GPIO_PinInGet(PB0_PORT, PB0_PIN))
        break;
    }

    /* Delay while showing the result on the LCD */
    for (uint32_t delay = 0; delay < 30; delay++)
    {
      /* Wait for the RTC to overflow once */
      while (RTC_CounterGet() != 0) ;
      while (RTC_CounterGet() == 0) ;
    }

    /* Disable LCD */
    LCD_Enable(false);
  }
}
Ejemplo n.º 3
0
/*****************************************************************************
 * Enters 'bootloader mode' where a new encrypted firmware upgrade can be 
 * sent over UART.
 *****************************************************************************/
void enterBootloaderMode(void)
{
  FLASH_init();

  /* Enable UART */
  BLUART_init();
  
  /* If the current firmware is invalid, but temp storage is
   * enabled and contains a valid firmware, copy this firmware
   * to boot region immediately.  */
  if ( USE_TEMP_STORAGE && !isFirmwareValid() && isTempStorageValid() )
  {
    copyFirmwareFromTempStorage();
    markFirmwareAsVerified();
  }
  
  /* Check if bootloader pin is pulled low. If it is left high
   * enter EM2 to save power. The MCU will wake up when pin is 
   * pulled low. */
  if ( GPIO_PinInGet(BOOTLOADER_PIN) ) {
    enterLowPowerWait();
  }

  /* Wait for commands over UART */
  commandLoop();
}
Ejemplo n.º 4
0
// Function Name: bootloadForceActivation
// Description:   Decides whether to continue launching the bootloader or vector
//                to the application instead. This decision is usually based on
//                some sort of GPIO logic.
//                (ie. a hardware trigger).
// NOTE!!!        This function is called extremely early in the boot process
//                prior to the chip being fully configured and before memory
//                is initialized, so limited functionality is available.
//                If this function returns false any state altered should
//                be returned to its reset state.
// Parameters:    none
// Returns:       false (0) if bootloader should not be launched.
//                (This will try to execute the application if possible.)
//                true (1) if bootloader should be launched.
//
bool bootloadForceActivation( void )
{
  #if defined(USE_BUTTON_RECOVERY)
    uint32_t i;
    bool pressed;
    // this provides an example of an alternative recovery mode activation
    //  method by utilizing one of the breakout board buttons
    CMU_ClockEnable(cmuClock_HFPER, true);
    CMU_ClockEnable(cmuClock_GPIO, true);

    // Since the button may have decoupling caps, they may not be charged
    //  after a power-on and could give a false positive result.  To avoid
    //  this issue, drive the output as an output for a short time to charge
    //  them up as quickly as possible
    GPIO_PinModeSet(BUTTON0_PORT, BUTTON0, gpioModePushPull, 1);
    GPIO_PinOutSet(BUTTON0_PORT, BUTTON0);
    for(i=0; i<100; i++)
      __no_operation();

    // Reconfigure as an input with pullup to read the button state
    GPIO_PinModeSet(BUTTON0_PORT, BUTTON0, gpioModeInputPull, 1);
    // (IO was already set to enable the pullup above)
    // We have to delay again here so that if the button is depressed the
    //  cap has time to discharge again after being charged up
    //  by the above delay
    for(i=0; i<500; i++)
      __no_operation();
    pressed = GPIO_PinInGet(BUTTON0_PORT, BUTTON0) ? BUTTON_RELEASED : BUTTON_PRESSED;

    return pressed;
  #else
    return false;
  #endif
}
Ejemplo n.º 5
0
/***************************************************************************//**
 * @brief
 *   RxTimer, Timer0 IRQHandler.
 ******************************************************************************/
void TIMER0_IRQHandler(void)
{
  uint32_t irqFlags;

  irqFlags = TIMER_IntGet(HIJACK_RX_TIMER);
  TIMER_IntClear(HIJACK_RX_TIMER, irqFlags);

  if (TIMER_IF_CC1 & irqFlags)
  {
	cur_stamp = TIMER_CaptureGet(HIJACK_RX_TIMER, 1);
	TIMER_CounterSet(HIJACK_RX_TIMER, 0);	
	edge_occur = true;
	/* Check what transition it was. */
    if (GPIO_PinInGet(HIJACK_RX_GPIO_PORT, HIJACK_RX_GPIO_PIN))
    {
       	cur_edge = rising;
		BSP_LedSet( 0 );
    }
    else
    {
      	cur_edge = falling;
	 	BSP_LedClear( 0 );
    }
  }
}
Ejemplo n.º 6
0
/**************************************************************************//**
 * @brief  Main function
 * Main is called from __iar_program_start, see assembly startup file
 *****************************************************************************/
int main(void)
{  
  /* Initialize chip */
  CHIP_Init();
  
  /* Enable clock for GPIO module */
  CMU_ClockEnable(cmuClock_GPIO, true);

  /* Configure PD with alternate drive strength of 20mA */
  GPIO_DriveModeSet(gpioPortD, gpioDriveModeHigh);
  
  /* Configure PC12 as input with filter*/
  GPIO_PinModeSet(gpioPortC, 12, gpioModeInput, 0);
  
  /* Configure PD8 as push pull output */
  GPIO_PinModeSet(gpioPortD, 8, gpioModePushPullDrive, 0);
  
  while(1)
  {
    /* If PC12 is high, drive high PD8, else drive low */
    if(GPIO_PinInGet(gpioPortC, 12)) 
      GPIO_PinOutSet(gpioPortD, 8);   /* Drive high PD8 */ 
    else 
      GPIO_PinOutClear(gpioPortD, 8); /* Drive low PD8 */
  }
  
 
}
Ejemplo n.º 7
0
inline uint8_t SX1276ReadDio4( void )
{
#ifdef DIO4_IOPORT
	return GPIO_PinInGet( DIO4_IOPORT, DIO4_PIN );
#else
	return 0;
#endif
}
Ejemplo n.º 8
0
void readGpioY(void)
{
	gpio_data_y[0] = GPIO_PinInGet(gpioPortC, 0);
	gpio_data_y[1] = GPIO_PinInGet(gpioPortC, 1);
	gpio_data_y[2] = GPIO_PinInGet(gpioPortC, 2);
	gpio_data_y[3] = GPIO_PinInGet(gpioPortD, 6);
	gpio_data_y[4] = GPIO_PinInGet(gpioPortD, 7);
	gpio_data_y[5] = GPIO_PinInGet(gpioPortD, 8);
	gpio_data_y[6] = GPIO_PinInGet(gpioPortD, 13);
	gpio_data_y[7] = GPIO_PinInGet(gpioPortD, 14);
}
Ejemplo n.º 9
0
void readGpioX(void)
{
	gpio_data_x[0] = GPIO_PinInGet(gpioPortB, 10);
	gpio_data_x[1] = GPIO_PinInGet(gpioPortB, 9);
	gpio_data_x[2] = GPIO_PinInGet(gpioPortB, 11);
	gpio_data_x[3] = GPIO_PinInGet(gpioPortB, 12);
	gpio_data_x[4] = GPIO_PinInGet(gpioPortD, 15);
	gpio_data_x[5] = GPIO_PinInGet(gpioPortD, 3);
	gpio_data_x[6] = GPIO_PinInGet(gpioPortD, 4);
	gpio_data_x[7] = GPIO_PinInGet(gpioPortD, 5);
}
Ejemplo n.º 10
0
void SysTick_Handler(void)
{

  msTicks++;       /* increment counter necessary in Delay()*/
  if(msTicks%60000==0 )
  {
	  ++curr_time.m;
	  if(curr_time.m==60)
	  {
		  ++curr_time.h;
		  curr_time.m=0;
	  }
  }
  if(curr_time.h==24)
  		  curr_time.h=0;


  if(msTicks%7 ==0)
  {

   	if( op1==1 & GPIO_PinInGet(BTN_PORT, PB1)==0 )
   	{
   		if((1<current && current<6) | current==7 )
   			current--;
   		if(current==1)
   		{
   			oc=choice;

   		  if(choice==1)
   			  choice=2;
   		  else
   			  choice=1;
   		}
   		if(current==6) current=1;
    }

   	   	op1= GPIO_PinInGet(BTN_PORT, PB1);
  }



}
Ejemplo n.º 11
0
static int efm32_uart_hasrx(struct uart *dev) {
#if 1
static unsigned int neg_cnt;
	while (1)
		if (!GPIO_PinInGet(BSP_BCC_RXPORT, BSP_BCC_RXPIN)) {
			LEUART_Tx((void *) dev->base_addr, '0');
			neg_cnt++;
		}
#endif
	return 1;
}
Ejemplo n.º 12
0
rt_uint8_t rt_hw_led_state(rt_uint8_t num)
{
    RT_ASSERT(num < LEDS_MAX_NUMBER);

#if defined(EFM32_G8XX_STK)
    return (rt_uint8_t)GPIO_PinInGet(leds_list[num][0], leds_list[num][1]);
#elif (defined(EFM32_GXXX_DK) || defined(EFM32GG_DK3750))
    return ((DVK_getLEDs() & (rt_uint16_t)(1 << num)) >> num);
#endif

}
Ejemplo n.º 13
0
/**************************************************************************//**
 * @brief  Increments the clock quickly while PB1 is pressed.
 *         A callback is used to update either the analog or the digital clock.
 *
 *****************************************************************************/
void fastForwardTime(void (*drawClock)(struct tm*, bool redraw))
{
  unsigned int i = 0;
  struct tm    *time; 
  
  /* Wait 2 seconds before starting to adjust quickly */
  int waitForPcntIrqCount = pcntIrqCount + 2;

  while (pcntIrqCount != waitForPcntIrqCount)
  {
    /* Return if the button is released */
    if (GPIO_PinInGet(gpioPortC, 9) == 1) {
      timeIsFastForwarding = false;
      return;
    }

    /* Keep updating the second counter while waiting */
    if (updateDisplay)
    {
      time = localtime((time_t const *) &curTime);
      drawClock(time, true);
    }

    EMU_EnterEM2(false);
  }

  /* Keep incrementing the time while the button is held */
  while (GPIO_PinInGet(gpioPortC, 9) == 0)
  {
    if (i % 1000 == 0)
    {
      /* Increase time by 1 minute (60 seconds). */
      curTime += 60;

      time = localtime((time_t const *) &curTime);
      drawClock(time, true);
    }
    i++;
  }
  timeIsFastForwarding = false;
}
Ejemplo n.º 14
0
/*==============================================================================
  hal_pinGet()
 =============================================================================*/
uint8_t    hal_pinGet(void * p_pin)
{
    s_hal_gpio_pin_t* p_gpioPin;

    if(p_pin == NULL) {
        return 0;
    }
    p_gpioPin = (s_hal_gpio_pin_t*)p_pin;
    if( p_gpioPin->mode != gpioModeInput )
        return p_gpioPin->val;
    else
        return GPIO_PinInGet( p_gpioPin->port, p_gpioPin->pin );
} /* hal_pinGet() */
Ejemplo n.º 15
0
/**********************************************************
 * COG init sequence
 **********************************************************/
void cogInit(void)
{
  while ( GPIO_PinInGet(EPD_PIN_BUSY) );
  
  /* Channel select */
  spiSend(0x01, epdConfig.channelSelect, 8);
  
  /* DC/DC frequency setting */
  spiSend1(0x06, 0xFF);
  
  /* High Power Mode Oscillator Setting */
  spiSend1(0x07, 0x9D);
  
  /* Disable ADC */
  spiSend1(0x08, 0x00);
  
  /* Set Vcom Level */
  spiSend2(0x09, 0xD000);
  
  /* Gate and Source Voltage Level*/
  spiSend1(0x04, epdConfig.voltageLevel);
  
  delayMs(5);
  
  /* Driver latch on (cancel register noise) */
  spiSend1(0x03, 0x01);
  
  /* Driver latch off */
  spiSend1(0x03, 0x00);
  
  /* Start chargepump positive voltage. VGH and VDH on */
  spiSend1(0x05, 0x01);
  
  delayMs(30);
  
  /* Stop PWM */
  pwmDisable();
  
  /* Start chargepump on negative voltage. VGL and VDL on */
  spiSend1(0x05, 0x03);
  
  delayMs(30);
  
  /* Set chargepump Vcom driver to ON */
  spiSend1(0x05, 0x0F);
  
  delayMs(30);
  
  /* Output enable to disable */
  spiSend1(0x02, 0x24);
}
Ejemplo n.º 16
0
/***************************************************************************//**
 * @brief
 *   Check status of the touch panel.
 *
 * @return
 *   0 if panel is idle (not touched).
 ******************************************************************************/
int TOUCH_IsBusy(void)
{
  if( (touch_state == TOUCH_INIT) )
  {
    return GPIO_PinInGet(TOUCH_X2);
  }

  if( (touch_state == TOUCH_CHECK_PRESS) )
  {
    return TOUCH_BUSY_CHECK;
  }

  return(TOUCH_BUSY_SCAN);
}
Ejemplo n.º 17
0
/* Measures the length (in microseconds) of a pulse on the pin; state is HIGH
 * or LOW, the type of pulse to measure.  Works on pulses from 2-3 microseconds
 * to 3 minutes in length, but must be called at least a few dozen microseconds
 * before the start of the pulse. */
uint32_t pulseIn( uint32_t pin, uint32_t state, uint32_t timeout )
{
	// cache the port and bit of the pin in order to speed up the
	// pulse width measuring loop and achieve finer resolution.  calling
	// digitalRead() instead yields much coarser resolution.
	int port = dPorts[pin];
    int pinId = dPins[pin];
	uint32_t width = 0; // keep initialization out of time critical area
	
	// convert the timeout from microseconds to a number of times through
	// the initial loop; it takes 22 clock cycles per iteration.
	uint32_t numloops = 0;
	uint32_t maxloops = microsecondsToClockCycles(timeout) / 22;
	
	// wait for any previous pulse to end
	while (GPIO_PinInGet((GPIO_Port_TypeDef)port, pinId) == state)
		if (numloops++ == maxloops)
			return 0;
	
	// wait for the pulse to start
	while (GPIO_PinInGet((GPIO_Port_TypeDef)port, pinId) != state)
		if (numloops++ == maxloops)
			return 0;
	
	// wait for the pulse to stop
	while (GPIO_PinInGet((GPIO_Port_TypeDef)port, pinId) == state) {
		if (numloops++ == maxloops)
			return 0;
		width++;
	}

	// convert the reading to microseconds. The loop has been determined
	// to be 52 clock cycles long and have about 16 clocks between the edge
	// and the start of the loop. There will be some error introduced by
	// the interrupt handlers.
	return clockCyclesToMicroseconds(width * 52 + 16);
}
Ejemplo n.º 18
0
/*****************************************************************************
 * Bootloader entry point. 
 *****************************************************************************/
int main(void)
{
  CHIP_Init();
  
  gpioSetup();

  uint32_t pinTest = GPIO_PinInGet(BOOTLOADER_PIN);
  
  /* The bootloader pin is left high, boot normally */
  if ( pinTest ) 
  {
    
    /* Verify firmware before booting */
    if ( isFirmwareValid() ) 
    {
      BOOT_boot();
    } 
    else 
    {
      
      /* Firmware is invalid. Check temp storage */
      if ( USE_TEMP_STORAGE && isTempStorageValid() )
      {
        FLASH_init();
        copyFirmwareFromTempStorage();
        markFirmwareAsVerified();
        
        /* Application will boot after reset */
        NVIC_SystemReset();
      }
      
      /* No valid application is present. Enter bootloader mode. */
      else 
      {
        enterBootloaderMode();
      }
    }
  } 
  /* The bootloader pin is pulled high, enter bootloader */
  else 
  {
    enterBootloaderMode();
  }
  
  /* Never reached */
  return 0;
}
Ejemplo n.º 19
0
/*****************************************************************************
 * Waits in EM3 until the bootloader pin is pulled low. This saves power
 * while waiting to install firmware. 
 *****************************************************************************/
void enterLowPowerWait(void)
{
  /* Enable interrupt on GPIO pin. Note that 
   * if the pin is changed to an odd pin number
   * the interrupt handler must also be changed */
  GPIO_IntConfig(BOOTLOADER_PIN, true, false, true);
  NVIC_EnableIRQ(GPIO_EVEN_IRQn);
  
  /* Wait in EM3 until the pin is pulled low */
  while ( GPIO_PinInGet(BOOTLOADER_PIN) ) {
    EMU_EnterEM3(false);
  }
  
  /* Disable interrupts again */
  GPIO_IntConfig(BOOTLOADER_PIN, false, false, false);
  NVIC_DisableIRQ(GPIO_EVEN_IRQn);
}
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Chip errata */
  CHIP_Init();

  CMU_ClockEnable(cmuClock_GPIO, true);

  GPIO_PinModeSet(BUTTON_PORT, BUTTON_PIN, gpioModeInput, 0);

  // The initial state of the button is high when not pushed
  bool past_button_state = 1;
  // Start out not blinking
  bool blinking = false;

  while (1)
  {
	  // Grab the state of the button, 1 for high voltage, 0 for low
	  bool live_button_state = GPIO_PinInGet(BUTTON_PORT, BUTTON_PIN);

	  // Invert the blinking mode every time a button is pressed
	  // which generates a low voltage on a pin
	  if (past_button_state == 1 && live_button_state == 0)
	  {
		  past_button_state = 0;

		  // Invert the blinking mode, so that it is buffered and will
		  // keep blinking/not blinking when the button is released
		  blinking = !blinking;
	  }


	  // Reset the past state when the button is released
	  if (live_button_state == 1)
	  {
		  past_button_state = 1;
	  }

	  // Finally decide if there is going to be a blink cycle or not
	  if (blinking)
	  {
		  blink_one_cycle();
      }
    }
}
Ejemplo n.º 21
0
/**************************************************************************//**
 * @brief Get state MCU plugin board VBUS overcurrent flag.
 * @return True if overcurrent situation exist, false otherwise.
 *****************************************************************************/
bool BSP_McuBoard_UsbVbusOcFlagGet( void )
{
#ifdef BSP_MCUBOARD_USB
  bool flag;

  if ( !GPIO_PinInGet( BSP_USB_OCFLAG_PORT, BSP_USB_OCFLAG_PIN ) )
  {
    flag = true;
  }
  else
  {
    flag = false;
  }

  return flag;
#else

  return false;
#endif
}
Ejemplo n.º 22
0
/***************************************************************************//**
 * @brief
 *   Active SO Interrupt handler
 * @param[in] *ref
 *
 ******************************************************************************/
void SO_IRQ(void *ref)
{
	(void) ref;

	int p = GPIO_PinInGet(RX_PORT, RX_PIN);

	if (p != 0)
	{
		// should never happen - we should only get the interrupt when the pin goes low
		GPIO->IFC = 1 << RX_PIN;
		so_spurious_irq_count++;
		return;
	}

	// disable IRQ
	GPIO_IntConfig(RX_PORT, RX_PIN,
			       false,   // risingEdge
			       false,   // fallingEdge
			       false);  // enable

	so_irq_count++;

	if (! so_busy)
	{
		// should never happen
		while (1)
			;
	}

	GPIO_PinOutSet(CS_PORT, CS_PIN);  // deassert CS

	// copy completion fn ptr and ref arg, to avoid race condition
	// if completion fn starts another SPI xfer
	spi_completion_fn_t *completion = so_completion;
	void *completion_ref = so_completion_ref;

	so_busy = false;
	if (completion)
		completion(completion_ref);
}
Ejemplo n.º 23
0
/***************************************************************************//**
 * @brief
 *   Active SO Interrupt handler
 * @note
 * 		Note: may be called synchronously (completion == NULL), in which case
 * 		this function does not return until the SO interrupt occurs, or
 * 		asynchronously (completion != NULL), in which case this function merely
 * 		sets up the interrupt, returns to the caller, and the caller should do
 * 		whatever is desired until the SO interrupt occurs, at which time the
 * 		completion function is called.
 * @param[in] level
 * 		Determines Edge Level Interrupt: Rising/Falling, spiflash_info->so_done_level
 * 		is the variable that is passed into the function and is initialized in the
 * 		Device table found in spiflash.c
 * @param[in] *completion
 * 		Completion State machine callback function
 * @param[in] *completion_ref
 * 		Argument to be passed to completion callback
 *******************************************************************************/
void spi_wait_so(uint8_t level,
                 spi_completion_fn_t *completion,  // completion callback fn
		         void *completion_ref)  // argument to be passed to completion callback
{
	so_completion = completion;
	so_completion_ref = completion_ref;
	so_busy = true;

	INT_Disable();

	// enable IRQ
	// The EFM32 has edge-triggered interrupts, so we'll never get an
	// interrupt if the port pin was already at the desired level.  To
	// avoid deadlock, we check the pin state here, and if it's already
	// at the desired level, simulate an edge interrupt.
	p1 = GPIO_PinInGet(RX_PORT, RX_PIN);
	if (p1 == level)
	{
		so_irq_fake_count++;
		SO_IRQ(NULL);
	}
	else
	{
		// Note that GPIO_IntConfig will clear any pending IRQ for the pin
		GPIO_IntConfig(RX_PORT, RX_PIN,
					   level,  // risingEdge
					   !level, // fallingEdge
					   true);  // enable
	}
	INT_Enable();

	// if called synchronously, actually wait here
	if (!completion)
		while (so_busy)
			enter_low_power_state();
}
Ejemplo n.º 24
0
/** @brief Indicate if device interrupt GPIO is pending
 * @return true if device interrupt is pending, false otherwise
 */
bool halExtDeviceIntPending(void)
{
  return (GPIO_PinInGet((GPIO_Port_TypeDef) RF_INT_PORT, RF_INT_PIN) == false);
}
Ejemplo n.º 25
0
int gpio_read(gpio_t pin)
{
    return GPIO_PinInGet(_port_num(pin), _pin_num(pin));
}
Ejemplo n.º 26
0
inline uint8_t SX1276ReadDio2( void )
{
	return GPIO_PinInGet( DIO2_IOPORT, DIO2_PIN );
}
/**
 * Reads nIRQ pin of the EZRadio device.
 *
 * @return Value of nIRQ pin.
 */
uint8_t ezradio_hal_NirqLevel(void)
{
  return GPIO_PinInGet( (GPIO_Port_TypeDef) RF_INT_PORT, RF_INT_PIN);
}
/**
 * Reads GPIO1 pin of the EZRadio device.
 *
 * @return Value of GPIO1 pin.
 */
uint8_t ezradio_hal_Gpio1Level(void)
{
  return GPIO_PinInGet( (GPIO_Port_TypeDef) RF_GPIO1_PORT, RF_GPIO1_PIN);
}
Ejemplo n.º 29
0
/***************************************************************************//**
 * @brief
 *	Interrupt handler is executed with frequency ~28Hz when panel is not pressed
 *	and with frequency ~140Hz when panel is pressed - this will give ~50 readings per second
 ******************************************************************************/
void ADC0_IRQHandler(void)
{
  switch (touch_state)
  {
  case TOUCH_INIT:   /* enter this state if touch panel is not pressed */
    GPIO_PinModeSet(TOUCH_Y1, gpioModePushPull, 1);
    GPIO_PinModeSet(TOUCH_Y2, gpioModePushPull, 1);
    GPIO_PinModeSet(TOUCH_X1, gpioModeInputPullFilter , 0);
    GPIO_PinModeSet(TOUCH_X2, gpioModeInput, 0);
    sInit.input      = ADC_Y;
    sInit.reference  = adcRefVDD;
    sInit.resolution = adcResOVS;
    sInit.acqTime    = adcAcqTime128;               /* used to slow down */
    if(GPIO_PinInGet(TOUCH_X2))
    {
      touch_state = TOUCH_MEASURE_Y;
      GPIO_PinModeSet(TOUCH_X1, gpioModePushPull, 1);
      GPIO_PinModeSet(TOUCH_X2, gpioModePushPull, 0);
      GPIO_PinModeSet(TOUCH_Y1, gpioModeInput, 0);
      GPIO_PinModeSet(TOUCH_Y2, gpioModeInput, 0);
      sInit.input   = ADC_X;
      sInit.acqTime = adcAcqTime16;                  /* pressed, so speed-up */
    }
    ADC_InitSingle(ADC0, &sInit);
    break;
  case TOUCH_CHECK_PRESS:   /* checks if touch panel is still pressed */
    if( GPIO_PinInGet(TOUCH_X2) )
    {
      touch_state = TOUCH_MEASURE_Y;
      GPIO_PinModeSet(TOUCH_X1, gpioModePushPull, 1);
      GPIO_PinModeSet(TOUCH_X2, gpioModePushPull, 0);
      GPIO_PinModeSet(TOUCH_Y1, gpioModeInput, 0);
      GPIO_PinModeSet(TOUCH_Y2, gpioModeInput, 0);
      sInit.input   = ADC_X;
      sInit.acqTime = adcAcqTime16;                  /* pressed, so speed-up */
      ADC_InitSingle(ADC0, &sInit);
      current_pos.pen = newpos.pen;
      TOUCH_RecalculatePosition(&newpos);
      if (newpos.pen)
      {
        int call_upcall = TOUCH_StateChanged();
        if (call_upcall)
        {
          current_pos.x = newpos.x;
          current_pos.y = newpos.y;
        }
        current_pos.adcx = newpos.adcx;
        current_pos.adcy = newpos.adcy;
        current_pos.pen  = 1;
        if (call_upcall) TOUCH_CallUpcall();
      }
      newpos.pen = 1;
    }
    else
    {
      touch_state     = TOUCH_INIT;
      newpos.pen      = 0;
      current_pos.pen = 0;
      TOUCH_CallUpcall();
    }
    break;
  case TOUCH_MEASURE_Y:                                             /* touch panel pressed, measure Y position */
    newpos.adcy = (ADC_DataSingleGet(ADC0) + 31) >> 6;              /* reduce ADC resolution to 10-bits */
    GPIO_PinModeSet(TOUCH_Y1, gpioModePushPull, 0);                 /* to avoid overflow in calibration routines */
    GPIO_PinModeSet(TOUCH_Y2, gpioModePushPull, 1);
    GPIO_PinModeSet(TOUCH_X1, gpioModeInput, 0);
    GPIO_PinModeSet(TOUCH_X2, gpioModeInput, 0);
    sInit.input = ADC_Y;
    ADC_InitSingle(ADC0, &sInit);
    touch_state = TOUCH_MEASURE_X;
    break;
  case TOUCH_MEASURE_X:   /* touch panel pressed, measure X position */
    newpos.adcx = (ADC_DataSingleGet(ADC0) + 31) >> 6;
    GPIO_PinModeSet(TOUCH_Y1, gpioModePushPull, 1);
    GPIO_PinModeSet(TOUCH_Y2, gpioModePushPull, 1);
    GPIO_PinModeSet(TOUCH_X1, gpioModeInputPullFilter , 0);
    GPIO_PinModeSet(TOUCH_X2, gpioModeInput, 0);
    sInit.input = ADC_Y;
    ADC_InitSingle(ADC0, &sInit);
    touch_state = TOUCH_CHECK_PRESS;
    break;
  default: touch_state = TOUCH_INIT;
  }
  ADC_IntClear(ADC0, ADC_IF_SINGLE);
  ADC_Start(ADC0, adcStartSingle);
}
__LINK_C bool hw_gpio_get_in(pin_id_t pin_id)
{
    return (!!(gpio_pins_configured[pin_id.port] & (1<<pin_id.pin))) 
	&& GPIO_PinInGet(pin_id.port, pin_id.pin);
}