Exemplo n.º 1
0
Arquivo: led.c Projeto: InSoonPark/asf
void LED_Off(U32 leds)
{
  // Use the LED descriptors to get the connections of a given LED to the MCU.
  tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
  volatile avr32_gpio_port_t *led_gpio_port;
  U8 led_shift;

  // Make sure only existing LEDs are specified.
  leds &= (1 << LED_COUNT) - 1;

  // Update the saved state of all LEDs with the requested changes.
  Clr_bits(LED_State, leds);

  // While there are specified LEDs left to manage...
  while (leds)
  {
    // Select the next specified LED and turn it off.
    led_shift = 1 + ctz(leds);
    led_descriptor += led_shift;
    led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
    led_gpio_port->ovrs  = led_descriptor->GPIO.PIN_MASK;
    led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
    led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
    leds >>= led_shift;
  }
}
Exemplo n.º 2
0
/*!
 *  \brief Get the current joystick state.
 *
 *  \param buf char buffer in which the joystick state is stored.
 *
 *  \return true upon success, false if error.
 */
bool b_joystick_get_value( char* buf )
{
    // input is pulled up, if 1 : input is not active
    if ( !is_joystick_up() )  { Clr_bits(x_joystick, JS_EVENT_UP); }
    else                      { Set_bits(x_joystick, JS_EVENT_UP); }

    if ( !is_joystick_down() ) { Clr_bits(x_joystick, JS_EVENT_DOWN); }
    else                       { Set_bits(x_joystick, JS_EVENT_DOWN); }

    if ( !is_joystick_left() )  { Clr_bits(x_joystick, JS_EVENT_LEFT); }
    else                        { Set_bits(x_joystick, JS_EVENT_LEFT); }

    if ( !is_joystick_right() )  { Clr_bits(x_joystick, JS_EVENT_RIGHT); }
    else                         { Set_bits(x_joystick, JS_EVENT_RIGHT); }

    if ( !is_joystick_pressed() ) { Clr_bits(x_joystick, JS_EVENT_PUSH); }
    else                          { Set_bits(x_joystick, JS_EVENT_PUSH); }

   // Build the log string.
   sprintf( buf, "%s\r\n", (portCHAR *)acpc_js_events[x_joystick]);
   return true;
}
Exemplo n.º 3
0
void LED_Off(U32 leds)
{
  tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
  volatile avr32_gpio_port_t *led_gpio_port;
  U8 led_shift;

  leds &= (1 << LED_COUNT) - 1;
  Clr_bits(LED_State, leds);
  while (leds)
  {
    led_shift = 1 + ctz(leds);
    led_descriptor += led_shift;
    led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
    led_gpio_port->ovrs  = led_descriptor->GPIO.PIN_MASK;
    led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
    led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
    leds >>= led_shift;
  }
}
Exemplo n.º 4
0
static portBASE_TYPE prvjoystick_ISR_NonNakedBehaviour( void )
{
  xLogDef *pxLog;
  U32     u32CurrentCountValue = xTaskGetTickCount();


  // Debouncing: ignore joystick events occuring in less than 250ms before the last
  // valid joystick event.
  if((( u32CurrentCountValue >= u32LastCountValue )
        && ( u32CurrentCountValue - u32LastCountValue <= 250))
      ||
       (( u32CurrentCountValue < u32LastCountValue )
        && ( u32CurrentCountValue + (0xFFFFFFFF - u32LastCountValue) <= 250)))
  {
    // Clear all interrupts flag (it's no use checking which event has bouncing).
    gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_PUSH);
    Clr_bits(x_joystick, JS_EVENT_PUSH);
    gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_LEFT);
    Clr_bits(x_joystick, JS_EVENT_LEFT);
    gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_RIGHT);
    Clr_bits(x_joystick, JS_EVENT_RIGHT);
    gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_UP);
    Clr_bits(x_joystick, JS_EVENT_UP);
    gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_DOWN);
    Clr_bits(x_joystick, JS_EVENT_DOWN);
    return(pdFALSE);
  }
  else
  {
    // Update last valid joystick event timestamp.
    u32LastCountValue = u32CurrentCountValue;

    // Check all events.
    if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_UP))
    {
       /* input is pulled up, if 1 : input is not active */
       if (gpio_get_pin_value(GPIO_JOYSTICK_UP))
       {
         /* clear bit UP */
         Clr_bits(x_joystick, JS_EVENT_UP);
       }
       else
       {
         Set_bits(x_joystick, JS_EVENT_UP);
       }
       /* allow new interrupt : clear the IFR flag */
       gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_UP);
     }
     if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_DOWN))
     {
       /* input is pulled up, if 1 : input is not active */
       if (gpio_get_pin_value(GPIO_JOYSTICK_DOWN))
       {
         Clr_bits(x_joystick, JS_EVENT_DOWN);
       }
       else
       {
         Set_bits(x_joystick, JS_EVENT_DOWN);
       }
       /* allow new interrupt : clear the IFR flag */
       gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_DOWN);
     }
     if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_LEFT))
     {
       /* input is pulled up, if 1 : input is not active */
       if (gpio_get_pin_value(GPIO_JOYSTICK_LEFT))
       {
         Clr_bits(x_joystick, JS_EVENT_LEFT);
       }
       else
       {
         Set_bits(x_joystick, JS_EVENT_LEFT);
   #ifdef MMILCD_ENABLE
         vMMI_UserMenuDisplayPreviousItem(pdTRUE);
   #endif
       }
       /* allow new interrupt : clear the IFR flag */
       gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_LEFT);
     }
     if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_RIGHT))
     {
       /* input is pulled up, if 1 : input is not active */
       if (gpio_get_pin_value(GPIO_JOYSTICK_RIGHT))
       {
         Clr_bits(x_joystick, JS_EVENT_RIGHT);
       }
       else
       {
         Set_bits(x_joystick, JS_EVENT_RIGHT);
   #ifdef MMILCD_ENABLE
         vMMI_UserMenuDisplayNextItem(pdTRUE);
   #endif
       }
       /* allow new interrupt : clear the IFR flag */
       gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_RIGHT);
     }
     if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_PUSH))
     {
       /* input is pulled up, if 1 : input is not active */
       if (gpio_get_pin_value(GPIO_JOYSTICK_PUSH))
       {
         Clr_bits(x_joystick, JS_EVENT_PUSH);
       }
       else
       {
         Set_bits(x_joystick, JS_EVENT_PUSH);
         if ( bAlarm == pdTRUE )
         {
           // post alarm to SMTP task
           v_SMTP_PostFromISR("Joystick Alarm", NULL);
         }

   #ifdef MMILCD_ENABLE
         vMMI_UserMenuValidateItem(pdTRUE);
   #endif
       }
       /* allow new interrupt : clear the IFR flag */
       gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_PUSH);
     }
  }
  // Alloc and init a log.
  pxLog = pxdatalog_log_alloc_init_FromISR();
  if( NULL == pxLog )
    return( pdFALSE );
  // Init the id field of the log.
  pxLog->id = DATALOG_ID_JS;
  /* set log event string */
  pxLog->pcStringLog = (portCHAR *)acpc_js_events[x_joystick];
  /* set free function pointer */
  pxLog->pfFreeStringLog = NULL;
  /* add the log entry */
  return( x_datalog_AddLogFromISR( pxLog ) );
}
Exemplo n.º 5
0
//!
//! This function frees a navigator id.
//!
//! @param fd    file descriptor.
//!
void fsaccess_free_nav_id(int fd)
{
    // mark NavId as free
    Clr_bits(pvNavUsed, (1 << fd));
}