/**************************************************************************//** * @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); }
/**************************************************************************//** * @brief Initialize viewer *****************************************************************************/ void SLIDES_init(void) { EMSTATUS status; GLIB_Rectangle rect = { .xMin = 0, .yMin = 0, .xMax = 319, .yMax = 239, }; /* Initialize graphics - abort on failure */ status = DMD_init(BC_SSD2119_BASE, BC_SSD2119_BASE + 2); if ((status != DMD_OK) && (status != DMD_ERROR_DRIVER_ALREADY_INITIALIZED)) while (1) ; /* Make sure display is configured with correct rotation */ if ((status == DMD_OK)) DMD_flipDisplay(1,1); /* Init graphics context - abort on failure */ status = GLIB_contextInit(&gc); if (status != GLIB_OK) while (1) ; /* Clear framebuffer */ gc.foregroundColor = GLIB_rgbColor(20, 40, 20); GLIB_drawRectFilled(&gc, &rect); /* Update drawing regions of picture */ gc.foregroundColor = GLIB_rgbColor(200, 200, 200); }
/**************************************************************************//** * @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); } }
/**************************************************************************//** * @brief Main function *****************************************************************************/ int main(void) { bool redraw = false; bool prevRedraw = false; EMSTATUS status; volatile int i; /* Initialize DK board register access */ /* This demo currently only works in EBI mode */ BSP_Init(BSP_INIT_DEFAULT); /* If first word of user data page is zero, enable eA Profiler trace */ BSP_TraceProfilerSetup(); /* Initialize DK interrupt enable */ DK_IRQInit(); /* Initialize GPIO interrupt */ GPIO_IRQInit(); /* Clear LEDs */ BSP_LedsSet(0x0000); /* Wait until we have control over display */ while(!redraw) { redraw = TFT_AddressMappedInit(); } /* Init graphics context - abort on failure */ status = GLIB_contextInit(&gc); if (status != GLIB_OK) while (1) ; /* Update TFT display forever */ while (1) { /* Check if we should control TFT display instead of AEM/board controller */ redraw = TFT_AddressMappedInit(); if(redraw) { /* This indicated a BC -> EFM control transfer */ if(prevRedraw != redraw) { /* Update information message */ gc.foregroundColor = GLIB_rgbColor(200, 200, 200); gc.backgroundColor = GLIB_rgbColor(0, 0, 0); GLIB_drawString(&gc, description[0], strlen(description[0]), 0, 0, 1); GLIB_drawString(&gc, description[1], strlen(description[1]), 0, 8, 1); GLIB_drawString(&gc, description[2], strlen(description[2]), 0, 24, 1); GLIB_drawString(&gc, description[3], strlen(description[3]), 0, 40, 1); GLIB_drawString(&gc, description[4], strlen(description[4]), 0, 48, 1); GLIB_drawString(&gc, description[5], strlen(description[5]), 0, 64, 1); GLIB_drawString(&gc, description[6], strlen(description[6]), 0, 72, 1); gc.foregroundColor = GLIB_rgbColor(200, 200, 100); GLIB_drawString(&gc, description[7], strlen(description[7]), 0, 88, 1); GLIB_drawString(&gc, description[8], strlen(description[8]), 0, 104, 1); } /* Update selected demo */ gc.foregroundColor = GLIB_rgbColor(100, 200, 100); gc.backgroundColor = GLIB_rgbColor(50, 50, 50); GLIB_drawString(&gc, eModeDesc[eModeDemo], strlen(eModeDesc[eModeDemo]), 40, 150, 1); } else { /* No need to refresh display when BC is active */ } prevRedraw = redraw; if(runDemo) { gc.foregroundColor = GLIB_rgbColor(50, 50, 50); gc.backgroundColor = GLIB_rgbColor(100, 200, 100); GLIB_drawString(&gc, eModeDesc[eModeDemo], strlen(eModeDesc[eModeDemo]), 40, 150, 1); for(i=0; i<14000; i++) ; break; } } /* Run demo */ switch(eModeDemo) { case 0: Demo_Primes(cmuSelect_HFXO, (CMU_HFRCOBand_TypeDef) 0); break; case 1: Demo_EM1(cmuSelect_HFXO, (CMU_HFRCOBand_TypeDef) 0); break; case 2: Demo_Primes(cmuSelect_HFRCO, cmuHFRCOBand_14MHz); break; case 3: Demo_EM1(cmuSelect_HFRCO, cmuHFRCOBand_14MHz); break; case 4: Demo_EM2(); break; case 5: Demo_EM2_RTC(); break; case 6: Demo_EM3(); break; case 7: Demo_EM3_GPIO(); break; case 8: Demo_EM4(); break; default: while(1); } return 0; }
/**************************************************************************//** * @brief Main function *****************************************************************************/ int main(void) { int toggleLED = 0; bool redraw = false; EMSTATUS status; GLIB_Rectangle rect = { .xMin = 0, .yMin = 0, .xMax = 319, .yMax = 239, }; /* 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); /* If first word of user data page is non-zero, enable eA Profiler trace */ BSP_TraceProfilerSetup(); /* Setup SysTick Timer for 1 msec interrupts */ if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) { while (1) ; } /* Wait until we have control over display */ while(!redraw) { redraw = TFT_AddressMappedInit(); } /* Init graphics context - abort on failure */ status = GLIB_contextInit(&gc); if (status != GLIB_OK) while (1) ; /* Clear framebuffer */ gc.foregroundColor = GLIB_rgbColor(20, 40, 20); GLIB_drawRectFilled(&gc, &rect); /* Update TFT display forever */ while (1) { /* Check if we should control TFT display instead of AEM/board controller */ redraw = TFT_AddressMappedInit(); if(redraw) { /* Update display */ TFT_displayUpdate(&gc); } else { /* No need to refresh display when BC is active */ Delay(200); } /* Toggle led after each TFT_displayUpdate iteration */ if (toggleLED) { BSP_LedsSet(0x0000); toggleLED = 0; } else { BSP_LedsSet(0x000f); toggleLED = 1; } } }
/***************************************************************************//** * @brief * Main function. Setup ADC, FFT, clocks, PRS, DMA, Timer, * and process FFT forever. *******************************************************************************/ int main(void) { arm_status status; char buf[20]; bool redraw = false; int glibStatus; DMA_Init_TypeDef dmaInit; TIMER_Init_TypeDef timerInit = TIMER_INIT_DEFAULT; /* Initialize DVK board register access */ BSP_Init(BSP_INIT_DEFAULT); /* If first word of user data page is non-zero, enable eA Profiler trace */ BSP_TraceEtmSetup(); /* Connect audio in to ADC */ BSP_PeripheralAccess(BSP_AUDIO_IN, true); /* Wait a while in order to let signal from audio-in stabilize after */ /* enabling audio-in peripheral. */ RTCDRV_Trigger(1000, NULL); EMU_EnterEM2(true); /* Initialize the CFFT/CIFFT module */ status = arm_rfft_init_f32(&rfft_instance, &cfft_instance, GUITAR_AUDIO_BUFFER_SAMPLES, 0, /* forward transform */ 1); /* normal, not bitreversed, order */ if (status != ARM_MATH_SUCCESS) { /* Error initializing RFFT module. */ while (1) ; } dataReadyForFFT = false; processingFFT = false; /* Use the HFXO. We still only manage to process about * a third the buffers through FFT */ CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO); /* Setup SysTick Timer for 1 msec interrupts */ if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) { while (1) ; } /* Enable clocks required */ CMU_ClockEnable(cmuClock_HFPER, true); CMU_ClockEnable(cmuClock_ADC0, true); CMU_ClockEnable(cmuClock_PRS, true); CMU_ClockEnable(cmuClock_DMA, true); CMU_ClockEnable(cmuClock_TIMER0, true); NVIC_SetPriority(DMA_IRQn, 0); /* Highest priority */ /* Configure peripheral reflex system used by TIMER to trigger ADC/DAC */ guitarPRSConfig(GUITAR_PRS_CHANNEL); /* Configure general DMA issues */ dmaInit.hprot = 0; dmaInit.controlBlock = dmaControlBlock; DMA_Init(&dmaInit); /* Configure ADC used for audio-in */ guitarADCConfig(); /* Trigger sampling according to configured sample rate */ TIMER_TopSet(TIMER0, CMU_ClockFreqGet(cmuClock_HFPER) / GUITAR_AUDIO_SAMPLE_RATE); TIMER_Init(TIMER0, &timerInit); /* Wait until we have control over display */ while(!redraw) { redraw = TFT_AddressMappedInit(); } /* Init graphics context - abort on failure */ glibStatus = GLIB_contextInit(&gc); if (glibStatus != GLIB_OK) while (1) ; /* Clear the screen */ gc.backgroundColor = GLIB_rgbColor(0, 0, 0); GLIB_clear(&gc); while (1) { while (dataReadyForFFT) { float32_t freq; processingFFT = true; processFFT(); dataReadyForFFT = false; processingFFT = false; /* Get frequency and make string with one decimal accuracy */ freq = getFreq(); sprintf(buf, "%6.1f", freq); /* Check if we should control TFT display instead of AEM/board controller */ redraw = TFT_AddressMappedInit(); if (redraw) { gc.foregroundColor = GLIB_rgbColor(220, 220, 220); gc.backgroundColor = GLIB_rgbColor(0, 0, 0); /* Print the frequency somewhere in the middle of the screen */ GLIB_drawString(&gc, buf, strlen(buf), 100, 120, 1); } } EMU_EnterEM1(); } }