Exemple #1
0
/**************************************************************************//**
 * @brief Initializes the graphics stack.
 * @note This function will /hang/ if errors occur (usually
 *       caused by faulty displays.
 *****************************************************************************/
void GRAPHICS_Init(void)
{
  EMSTATUS status;

  /* Initialize the display module. */
  status = DISPLAY_Init();
  if (DISPLAY_EMSTATUS_OK != status)
    while (1)
      ;

  /* Initialize the DMD module for the DISPLAY device driver. */
  status = DMD_init(0);
  if (DMD_OK != status)
    while (1)
      ;

  status = GLIB_contextInit(&glibContext);
  if (GLIB_OK != status)
    while (1)
      ;

  glibContext.backgroundColor = White;
  glibContext.foregroundColor = Black;

  /* Use Narrow font */
  GLIB_setFont(&glibContext, (GLIB_Font_t *)&GLIB_FontNarrow6x8);
}
Exemple #2
0
/**************************************************************************//**
 * @brief  Main function of clock example.
 *
 *****************************************************************************/
int main(void)
{  
  EMSTATUS status;
  bool redraw;
  ClockMode_t prevClockMode = CLOCK_MODE_DIGITAL;
  
  /* Chip errata */
  CHIP_Init();

  /* Use the 21 MHz band in order to decrease time spent awake.
     Note that 21 MHz is the highest HFRCO band on ZG. */
  CMU_ClockSelectSet( cmuClock_HF, cmuSelect_HFRCO  );
  CMU_HFRCOBandSet( cmuHFRCOBand_21MHz );

  /* Setup GPIO for pushbuttons. */
  gpioSetup();

  /* Initialize display module */    
  status = DISPLAY_Init();
  if (DISPLAY_EMSTATUS_OK != status)
    while (true)
      ;

  /* Initialize the DMD module for the DISPLAY device driver. */
  status = DMD_init(0);
  if (DMD_OK != status)
    while (true)
      ;

  status = GLIB_contextInit(&gc);
  if (GLIB_OK != status)
    while (true)
      ;
  
  /* Set PCNT to generate interrupt every second */
  pcntInit();
  
  /* Pre-compte positions for the analog graphics */
  analogClockInitGraphics();

  /* Enter infinite loop that switches between analog and digitcal clock
   * modes, toggled by pressing the button PB0. */
  while (true)
  {    
    redraw = (prevClockMode != clockMode);
    prevClockMode = clockMode;
    if (CLOCK_MODE_ANALOG == clockMode)
    {
      analogClockShow(redraw);
    }
    else
    {
      digitalClockShow(redraw);
    }
    /* Sleep between each frame update */
    EMU_EnterEM2(false);
  }
}
Exemple #3
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main( void )
{
  /* Chip errata */
  CHIP_Init();

  /* Setup GPIO for pushbuttons. */
  GpioSetup();

  /* Initialize the display module. */
  displayEnabled = true;
  DISPLAY_Init();

  /* Retrieve the properties of the display. */
  if ( DISPLAY_DeviceGet( 0, &displayDevice ) != DISPLAY_EMSTATUS_OK )
  {
    /* Unable to get display handle. */
    while( 1 );
  }

  /* Retarget stdio to the display. */
  if ( TEXTDISPLAY_EMSTATUS_OK != RETARGET_TextDisplayInit() )
  {
    /* Text display initialization failed. */
    while( 1 );
  }

  /* Set PCNT to generate an interrupt every second. */
  PcntInit();

  printf( "\n\n Cycling through"
          "\n energy modes"
          "\n EM0-EM3"
          "\n\n Push PB0 to"
          "\n enter EM4\n\n\n\n" );

  /* Turn on LFXO to be able to see the difference between EM2 and EM3. */
  CMU_OscillatorEnable(cmuOsc_LFXO, true, false );

  for (;;)
  {
    printf( "\r      EM0" );
    EnterEMode( 0, SLEEP_TIME );
    CheckEM4Entry();

    printf( "\r      EM1" );
    EnterEMode( 1, SLEEP_TIME );
    CheckEM4Entry();

    printf( "\r      EM2" );
    EnterEMode( 2, SLEEP_TIME );
    CheckEM4Entry();

    printf( "\r      EM3" );
    EnterEMode( 3, SLEEP_TIME );
    CheckEM4Entry();
  }
}
Exemple #4
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Setup SysTick Timer for 10 msec interrupts  */
  if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000))
  {
    while (1) ;
  }

  /* Initialize the display module. */
  DISPLAY_Init();

  /* Retarget stdio to a text display. */
  if (RETARGET_TextDisplayInit() != TEXTDISPLAY_EMSTATUS_OK)
  {
    while (1) ;
  }

  /* Output text on Memory LCD */
  printf("Hello, EFM32 Zero Gecko world!");
  Delay(2000);

  /* Clear screen */
  printf("\f");

  Setup_MPU6050();
  MPU6050_Test_I2C();
  MPU6050_Check_Registers();
  Calibrate_Gyros();
  Calibrate_Acc();
  /* Update Memory LCD display forever */
  while (1)
  {
	Get_Gyro_Rates();
	Get_Accel_Values();

	Delay(500);
	printf("\f");
  }
}
Exemple #5
0
/**************************************************************************//**
 * @brief main - the entrypoint after reset.
 *****************************************************************************/
int main(void)
{
  /* Initialize LEUSB state variables */
  leusbTogglePushed = false;
  leusbEnabled = false;
  refreshDisplay = false;

  HIDKBD_Init_t hidInitStruct;

  /* Chip errata */
  CHIP_Init();

  /* Go slow to reduce current consumption. */
  CMU_HFRCOBandSet( cmuHFRCOBand_7MHz );

  CMU_ClockEnable( cmuClock_GPIO, true );
  GPIO_PinModeSet( BUTTON0_PORT, BUTTON0_PIN, gpioModeInputPull, 1 );
  GPIO_PinModeSet( BUTTON1_PORT, BUTTON1_PIN, gpioModeInputPull, 1 );

  /* Initialize the display module. */
  DISPLAY_Init();

  /* Retrieve the properties of the display. */
  if ( DISPLAY_DeviceGet( 0, &displayDevice ) != DISPLAY_EMSTATUS_OK )
  {
    /* Unable to get display handle. */
    while( 1 );
  }

  memset( (void*)blank_image, 0xFF, 128*16 );
  displayDevice.pPixelMatrixDraw( &displayDevice, (void*)blank_image,
                                  /* start column, width */
                                  0, displayDevice.geometry.width,
                                  /* start row, height */
                                  0, displayDevice.geometry.height);
  scrollLcd( &displayDevice, scrollLeft, blank_image, gecko_image );

  /* Initialize HID keyboard driver. */
  hidInitStruct.hidDescriptor = (void*)USBDESC_HidDescriptor;
  hidInitStruct.setReportFunc = NULL;
  HIDKBD_Init( &hidInitStruct );

  /* Initialize and start USB device stack. */
  USBD_Init( &usbInitStruct );

  /* Turn off the Low Energy Mode (LEM) features that were enabled in USBD_Init() */
  USB->CTRL &= ~USB_CTRL_LEMIDLEEN;	// LEUSB off to begin demo

  /*
   * When using a debugger it is practical to uncomment the following three
   * lines to force host to re-enumerate the device.
   */
  /* USBD_Disconnect();      */
  /* USBTIMER_DelayMs(1000); */
  /* USBD_Connect();         */

  for (;;)
  {
    if (refreshDisplay)
    {
      refreshDisplay = false; /* Clear the "refresh display" flag */
      if (leusbEnabled)
      {
        /* Update the LCD image to reflect USB Low Energy Mode enabled */
        displayDevice.pPixelMatrixDraw( &displayDevice, (void*)leusb_image,
                                        /* start column, width */
                                        0, displayDevice.geometry.width,
                                        /* start row, height */
                                        0, displayDevice.geometry.height);
      }
      else
      {
        /* Update the LCD image to reflect normal USB HID keyboard demo status */
        displayDevice.pPixelMatrixDraw( &displayDevice, (void*)usb_image,
                                        /* start column, width */
                                        0, displayDevice.geometry.width,
                                        /* start row, height */
                                        0, displayDevice.geometry.height);
      }
    }
    /* Conserve energy ! */
    EMU_EnterEM1();
  }
}
Exemple #6
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  int toggleLED = 0;
  int cnt, x, y;
  bool movedown, moveright;

  /* Use 48MHZ HFXO as core clock frequency */
  CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);

  /* Initialize DK board register access */
  /* This demo currently only works in EBI mode */
  BSP_Init(BSP_INIT_DEFAULT);
  BSP_LedsInit();

  /* Setup SysTick Timer for 10 msec interrupts  */
  if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000))
  {
    while (1) ;
  }

  /* Initialize the display module. */
  DISPLAY_Init();

  /* Retarget stdio to a text display. */
  if (RETARGET_TextDisplayInit() != TEXTDISPLAY_EMSTATUS_OK)
  {
    while (1) ;
  }

  /* Output text on Memory LCD */
  printf("Hello, EFM32 Zero Gecko world!");
  Delay(2000);

  /* Clear screen */
  printf("\f");

  cnt = x = y = 0;
  movedown = moveright = true;

  /* Update Memory LCD display forever */
  while (1)
  {
    printf("%d", cnt );

    if (movedown)
    {
      y++;
      printf( TEXTDISPLAY_ESC_SEQ_CURSOR_DOWN_ONE_LINE );
    }
    else
    {
      y--;
      printf( TEXTDISPLAY_ESC_SEQ_CURSOR_UP_ONE_LINE );
    }

    if (y >= TEXTDISPLAY_DEVICE_0_LINES-1)
      movedown=false;
    if (y == 0)
      movedown=true;
    
    if (moveright)
    {
      x++;
      if (cnt >= 10)
        printf( TEXTDISPLAY_ESC_SEQ_CURSOR_LEFT_ONE_CHAR );
    } 
    else
    {
      x--;
      if (cnt > 10)
      {
        printf( TEXTDISPLAY_ESC_SEQ_CURSOR_LEFT_ONE_CHAR );
        printf( TEXTDISPLAY_ESC_SEQ_CURSOR_LEFT_ONE_CHAR );
        printf( TEXTDISPLAY_ESC_SEQ_CURSOR_LEFT_ONE_CHAR );
      }
      else
      {
        printf( TEXTDISPLAY_ESC_SEQ_CURSOR_LEFT_ONE_CHAR );
        printf( TEXTDISPLAY_ESC_SEQ_CURSOR_LEFT_ONE_CHAR );
      }
    }

    if (x >= TEXTDISPLAY_DEVICE_0_COLUMNS-2)
      moveright=false;
    if (x == 0)
      moveright=true;

    /* Clear screen and reset counter when 100 is reached. */
    if (++cnt == 100)
    {
      printf("\f");
      cnt = x = y = 0;
      movedown = moveright = true;
    }

    /* Toggle led after each Memory LCD_displayUpdate iteration */
    if (toggleLED)
    {
      BSP_LedsSet(0x0000);
      toggleLED = 0;
    }
    else
    {
      BSP_LedsSet(0x000f);
      toggleLED = 1;
    }
    Delay(100);
  }
}