//***************************************************************************** // // Handles notifications from the slider controls. // //***************************************************************************** void OnSliderChange(tWidget *psWidget, int32_t i32Value) { static char pcCanvasText[5]; static char pcSliderText[5]; // // Is this the widget whose value we mirror in the canvas widget and the // locked slider? // if(psWidget == (tWidget *)&g_psSliders[SLIDER_CANVAS_VAL_INDEX]) { // // Yes - update the canvas to show the slider value. // usprintf(pcCanvasText, "%3d%%", i32Value); CanvasTextSet(&g_sSliderValueCanvas, pcCanvasText); WidgetPaint((tWidget *)&g_sSliderValueCanvas); // // Also update the value of the locked slider to reflect this one. // SliderValueSet(&g_psSliders[SLIDER_LOCKED_INDEX], i32Value); WidgetPaint((tWidget *)&g_psSliders[SLIDER_LOCKED_INDEX]); } if(psWidget == (tWidget *)&g_psSliders[SLIDER_TEXT_VAL_INDEX]) { // // Yes - update the canvas to show the slider value. // usprintf(pcSliderText, "%3d%%", i32Value); SliderTextSet(&g_psSliders[SLIDER_TEXT_VAL_INDEX], pcSliderText); WidgetPaint((tWidget *)&g_psSliders[SLIDER_TEXT_VAL_INDEX]); } }
//***************************************************************************** // // A simple demonstration of the features of the Stellaris Graphics Library. // //***************************************************************************** void GraphicsDemoInit(void) { // // Add the title block and the previous and next buttons to the widget // tree. // WidgetAdd((tWidget *)&g_sDemoScreen, (tWidget *)&g_sPrevious); WidgetAdd((tWidget *)&g_sDemoScreen, (tWidget *)&g_sTitle); WidgetAdd((tWidget *)&g_sDemoScreen, (tWidget *)&g_sNext); // // Add the first panel to the widget tree. // g_ulPanel = 0; WidgetAdd((tWidget *)&g_sDemoScreen, (tWidget *)g_psPanels); CanvasTextSet(&g_sTitle, g_pcPanelNames[0]); }
static void DisplayGR(void) { tRectangle sRect; // Fill the top 24 rows of the screen with blue to create the banner. sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&sContext) - 1; sRect.sYMax = 23; GrContextForegroundSet(&sContext, ClrDarkBlue); GrRectFill(&sContext, &sRect); // Put a white box around the banner. GrContextForegroundSet(&sContext, ClrWhite); GrRectDraw(&sContext, &sRect); // Put the application name in the middle of the banner. GrContextFontSet(&sContext, &g_sFontCm20); GrStringDrawCentered(&sContext, "grlib demo", -1, GrContextDpyWidthGet(&sContext) / 2, 8, 0); GrStringDrawCentered(&sContext, "Touch here to proceed ", -1, GrContextDpyWidthGet(&sContext) / 2, 140, 0); // Initialize the sound driver. // Add the title block and the previous and next buttons to the widget tree. WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sPrevious); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sTitle); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sNext); // Add the first panel to the widget tree. g_ulPanel = 0; WidgetAdd(WIDGET_ROOT, (tWidget *)g_psPanels); CanvasTextSet(&g_sTitle, g_pcPanelNames[0]); // Issue the initial paint request to the widgets. //WidgetPaint(WIDGET_ROOT); WidgetMessageQueueAdd(WIDGET_ROOT, WIDGET_MSG_PAINT, 0, 0, 0, 0); }
//***************************************************************************** // // Show the graphics demo // //***************************************************************************** void GraphicsDemoShow(void) { // // Remove the keypad widget tree completely. // WidgetRemove((tWidget *)&g_sBlackBackground); // // Remember that we are showing the graphics demo. // g_ulMode = MODE_DEMO; // // Set the previous and next button text correctly for the first screen. // PushButtonTextSet(&g_sNext, "+"); PushButtonTextSet(&g_sPrevious, "X"); // // Add the title block and the previous and next buttons to the widget // tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sDemoBackground); // // Add the first panel to the widget tree. // g_ulPanel = 0; WidgetAdd((tWidget *)&g_sDemoBackground, (tWidget *)g_psPanels); CanvasTextSet(&g_sTitle, g_pcPanelNames[0]); // // Issue the initial paint request to the widgets. // WidgetPaint(WIDGET_ROOT); }
//***************************************************************************** // // Handles presses of the previous panel button. // //***************************************************************************** void OnPrevious(tWidget *psWidget) { // // There is nothing to be done if the first panel is already being // displayed. // if(g_ui32Panel == 0) { return; } // // Remove the current panel. // WidgetRemove((tWidget *)(g_psPanels + g_ui32Panel)); // // Decrement the panel index. // g_ui32Panel--; // // Add and draw the new panel. // WidgetAdd(WIDGET_ROOT, (tWidget *)(g_psPanels + g_ui32Panel)); WidgetPaint((tWidget *)(g_psPanels + g_ui32Panel)); // // Set the title of this panel. // CanvasTextSet(&g_sTitle, g_pcPanei32Names[g_ui32Panel]); WidgetPaint((tWidget *)&g_sTitle); // // See if this is the first panel. // if(g_ui32Panel == 0) { // // Clear the previous button from the display since the first panel is // being displayed. // PushButtonImageOff(&g_sPrevious); PushButtonTextOff(&g_sPrevious); PushButtonFillOn(&g_sPrevious); WidgetPaint((tWidget *)&g_sPrevious); } // // See if the previous panel was the last panel. // if(g_ui32Panel == (NUM_PANELS - 2)) { // // Display the next button. // PushButtonImageOn(&g_sNext); PushButtonTextOn(&g_sNext); PushButtonFillOff(&g_sNext); WidgetPaint((tWidget *)&g_sNext); } }
//***************************************************************************** // // A simple demonstration of the features of the TivaWare Graphics Library. // //***************************************************************************** int main(void) { tContext sContext; uint32_t ui32SysClock; // // Run from the PLL at 120 MHz. // ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins. // PinoutSet(); // // Initialize the display driver. // Kentec320x240x16_SSD2119Init(ui32SysClock); // // Set graphics library text rendering defaults. // GrLibInit(&GRLIB_INIT_STRUCT); // // Set the string table and the default language. // GrStringTableSet(STRING_TABLE); // // Set the default language. // ChangeLanguage(GrLangEnUS); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&sContext, "lang-demo"); // // Load the static strings from the string table. These strings are // independent of the language in use but we store them in the string // table nonetheless since (a) we may be using codepage remapping in // which case it would be difficult to hardcode them into the app source // anyway (ASCII or ISO8859-1 text would not render properly with the // remapped custom font) and (b) even if we're not using codepage remapping, // we may have generated a custom font from the string table output and // we want to make sure that all glyphs required by the application are // present in that font. If we hardcode some text in the application // source and don't put it in the string table, we run the risk of having // characters missing in the font. // GrStringGet(STR_ENGLISH, g_pcEnglish, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_DEUTSCH, g_pcDeutsch, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_ESPANOL, g_pcEspanol, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_ITALIANO, g_pcItaliano, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_CHINESE, g_pcChinese, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_KOREAN, g_pcKorean, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_JAPANESE, g_pcJapanese, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_PLUS, g_pcPlus, 2); GrStringGet(STR_MINUS, g_pcMinus, 2); // // Initialize the touch screen driver and have it route its messages to the // widget tree. // TouchScreenInit(ui32SysClock); TouchScreenCallbackSet(WidgetPointerMessage); // // Add the title block and the previous and next buttons to the widget // tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sPrevious); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sTitle); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sNext); // // Add the first panel to the widget tree. // g_ui32Panel = 0; WidgetAdd(WIDGET_ROOT, (tWidget *)g_psPanels); // // Set the string for the title. // CanvasTextSet(&g_sTitle, g_pcTitle); // // Issue the initial paint request to the widgets. // WidgetPaint(WIDGET_ROOT); // // Loop forever, processing widget messages. // while(1) { // // Process any messages in the widget message queue. // WidgetMessageQueueProcess(); } }
int main(void) { tContext sContext; tRectangle sRect; // // The FPU should be enabled because some compilers will use floating- // point registers, even for non-floating-point code. If the FPU is not // enabled this will cause a fault. This also ensures that floating- // point operations could be added to this application and would work // correctly and use the hardware floating-point unit. Finally, lazy // stacking is enabled for interrupt handlers. This allows floating- // point instructions to be used within interrupt handlers, but at the // expense of extra stack usage. // FPUEnable(); FPULazyStackingEnable(); // // Set the clock to 40Mhz derived from the PLL and the external oscillator // ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); // // Initialize the display driver. // Adafruit320x240x16_ILI9325Init(); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sAdafruit320x240x16_ILI9325); // // Configure and enable uDMA // SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlDelay(10); uDMAControlBaseSet(&sDMAControlTable[0]); uDMAEnable(); // // Initialize the touch screen driver and have it route its messages to the // widget tree. // TouchScreenInit(); // // Paint touch calibration targets and collect calibration data // GrContextForegroundSet(&sContext, ClrWhite); GrContextBackgroundSet(&sContext, ClrBlack); GrContextFontSet(&sContext, &g_sFontCm20); GrStringDraw(&sContext, "Touch center of circles to calibrate", -1, 0, 0, 1); GrCircleDraw(&sContext, 32, 24, 10); GrFlush(&sContext); TouchScreenCalibrationPoint(32, 24, 0); GrCircleDraw(&sContext, 280, 200, 10); GrFlush(&sContext); TouchScreenCalibrationPoint(280, 200, 1); GrCircleDraw(&sContext, 200, 40, 10); GrFlush(&sContext); TouchScreenCalibrationPoint(200, 40, 2); // // Calculate and set calibration matrix // long* plCalibrationMatrix = TouchScreenCalibrate(); // // Write out calibration data if successful // if(plCalibrationMatrix) { char pcStringBuf[20]; usprintf(pcStringBuf, "A %d", plCalibrationMatrix[0]); GrStringDraw(&sContext, pcStringBuf, -1, 0, 20, 1); usprintf(pcStringBuf, "B %d", plCalibrationMatrix[1]); GrStringDraw(&sContext, pcStringBuf, -1, 0, 40, 1); usprintf(pcStringBuf, "C %d", plCalibrationMatrix[2]); GrStringDraw(&sContext, pcStringBuf, -1, 0, 60, 1); usprintf(pcStringBuf, "D %d", plCalibrationMatrix[3]); GrStringDraw(&sContext, pcStringBuf, -1, 0, 80, 1); usprintf(pcStringBuf, "E %d", plCalibrationMatrix[4]); GrStringDraw(&sContext, pcStringBuf, -1, 0, 100, 1); usprintf(pcStringBuf, "F %d", plCalibrationMatrix[5]); GrStringDraw(&sContext, pcStringBuf, -1, 0, 120, 1); usprintf(pcStringBuf, "Div %d", plCalibrationMatrix[6]); GrStringDraw(&sContext, pcStringBuf, -1, 0, 140, 1); TouchScreenCalibrationPoint(0,0,0); // wait for dummy touch } // // Enable touch screen event handler for grlib widgets // TouchScreenCallbackSet(WidgetPointerMessage); // // Fill the top 24 rows of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&sContext) - 1; sRect.sYMax = 23; GrContextForegroundSet(&sContext, ClrDarkBlue); GrRectFill(&sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&sContext, ClrWhite); GrRectDraw(&sContext, &sRect); // // Put the application name in the middle of the banner. // GrContextFontSet(&sContext, &g_sFontCm20); GrStringDrawCentered(&sContext, "grlib demo", -1, GrContextDpyWidthGet(&sContext) / 2, 8, 0); // // Add the title block and the previous and next buttons to the widget // tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sPrevious); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sTitle); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sNext); // // Add the first panel to the widget tree. // g_ulPanel = 0; WidgetAdd(WIDGET_ROOT, (tWidget *)g_psPanels); CanvasTextSet(&g_sTitle, g_pcPanelNames[0]); // // Issue the initial paint request to the widgets. // WidgetPaint(WIDGET_ROOT); // // Loop forever handling widget messages. // while(1) { // // Process any messages in the widget message queue. // WidgetMessageQueueProcess(); } }
//***************************************************************************** // // Handles presses of the next panel button. // //***************************************************************************** void OnNext(tWidget *pWidget) { // // Play the key click sound. // SoundPlay(g_pusKeyClick, g_ulKeyClickLen); // // If we are on the last panel, return to the main application menu. // if(g_ulPanel == (NUM_PANELS - 1)) { ShowUIScreen(HOME_SCREEN); return; } // // Remove the current panel. // WidgetRemove((tWidget *)(g_psPanels + g_ulPanel)); // // Increment the panel index. // g_ulPanel++; // // Add and draw the new panel. // WidgetAdd((tWidget *)&g_sDemoScreen, (tWidget *)(g_psPanels + g_ulPanel)); WidgetPaint((tWidget *)(g_psPanels + g_ulPanel)); // // Set the title of this panel. // CanvasTextSet(&g_sTitle, g_pcPanelNames[g_ulPanel]); WidgetPaint((tWidget *)&g_sTitle); // // See if the previous panel was the first panel. // if(g_ulPanel == 1) { // // Replace the original text on the "Previous" button. // PushButtonTextSet(&g_sPrevious, "-"); WidgetPaint((tWidget *)&g_sPrevious); } // // See if this is the last panel. // if(g_ulPanel == (NUM_PANELS - 1)) { // // Replace the text on the "Next" button to read "X". // PushButtonTextSet(&g_sNext, "X"); WidgetPaint((tWidget *)&g_sNext); } }
/* * Function name : display_lyric * Description: * display lyric which is suitable with song is playing * Input: * char name **/ void display_lyric(char * name_of_file){ FRESULT fresult; unsigned short usBytesRead = 0; char str[2], time_detect[9], var[20], strDisplay[5][20]; int mm,ss,micro_ss,flag_song_title,i,k,j,time_pointer,flag_time_detect; // error with char * without malloc() str[1] = '\0'; mm = ss = micro_ss = flag_song_title = i = k = j = time_pointer = flag_time_detect = 0; sprintf(var, name_of_file); WidgetPaint((tWidget *)&musicBackground); WidgetMessageQueueProcess(); fresult = f_open(&g_sFileObject1, var, FA_READ); if(fresult != FR_OK) { UARTprintf("\n music 1.c\n"); return; } while(1){ for(j = 0;j < 5; j++) sprintf( strDisplay[j], ""); sprintf(time_detect, ""); flag_time_detect = 0; time_pointer = 0; i = 0; // Read the first title of this song if (flag_song_title == 0){ flag_song_title = 1; do{ fresult = f_read(&g_sFileObject1, str, 1, &usBytesRead); strcat(strDisplay[0],str); }while (str[0] != '\n' && fresult == FR_OK && usBytesRead == 1); sprintf( strDisplay[0], ""); } // Read content of lyric each sentences... do { fresult = f_read(&g_sFileObject1, str, 1, &usBytesRead); if ((flag_time_detect) && (str[0] != ']') && (time_pointer <= 7)){ strcat(time_detect, str); time_pointer++; } if (str[0] == '[') flag_time_detect = 1; // filter content of lyric without time if (time_pointer >= 10){ strcat(strDisplay[i/19], str); i++; } if ((time_pointer >= 8) && (time_pointer < 10)) if (time_pointer >= 8) time_pointer++; }while (str[0] != '\n' && fresult == FR_OK && usBytesRead == 1); if (usBytesRead < 1) break; // check time terminated to display this lyric comment or not? mm = (time_detect[0] - 48)*10 + (time_detect[1] - 48); ss = (time_detect[3] - 48)*10 + (time_detect[4] - 48); micro_ss = (time_detect[6] - 48)*10 +(time_detect[7] - 48); while(!check_time_lyric(mm, ss, micro_ss)); // display lyric one sentence and float on oled for (k = 0;k < 5; k++){ CanvasTextSet(&musicString1, strDisplay[k]); if ((k-1) >= 0) CanvasTextSet(&musicString2, strDisplay[k-1]); if ((k-2) >= 0) CanvasTextSet(&musicString3, strDisplay[k-2]); if ((k-3) >= 0) CanvasTextSet(&musicString4, strDisplay[k-3]); if ((k-4) >= 0) CanvasTextSet(&musicString5, strDisplay[k-4]); WidgetPaint((tWidget *)&musicBackground); WidgetMessageQueueProcess(); delay = delay_help ; while (delay >0); } // clear all thing in olead LCD CanvasTextSet(&musicString1, ""); CanvasTextSet(&musicString2, ""); CanvasTextSet(&musicString3, ""); CanvasTextSet(&musicString4, ""); CanvasTextSet(&musicString5, ""); WidgetPaint((tWidget *)&musicBackground); WidgetMessageQueueProcess(); } }
//***************************************************************************** // // This function monitors the UART-based firmware update and displays the // progress on the screen. // //***************************************************************************** static unsigned long UARTUpdate(void) { unsigned long ulIdx, ulCount; // // Set the progress title to indicate that the firmware is being downloaded // from the PC. // CanvasTextSet(g_psProgressWidgets + PROGRESS_TITLE, "Updating from PC"); // // Add the progress bar widgets to the widget list. // for(ulIdx = 0; ulIdx < NUM_PROGRESS_WIDGETS; ulIdx++) { WidgetAdd(WIDGET_ROOT, (tWidget *)(g_psProgressWidgets + ulIdx)); } // // Gray the non-title widgets in the main panel. // UpdateWidgetsColor(ClrNotPresent); // // Set the progress bar to the beginning. // PROGRESS(0); // // Update the display. // DisplayFlush(); // // Reset the counter of the amount of time since the last serial boot // loader packet was seen. // ulCount = 0; // // Loop while there is still data to be received from the UART. // while(g_ulImageSize) { // // Wait for a tick or a serial boot loader packet. // while((HWREGBITW(&g_ulFlags, FLAG_TICK) == 0) && (HWREGBITW(&g_ulFlags, FLAG_SERIAL_BOOTLOADER) == 0)) { } // // See if a serial boot loader packet was received. // if(HWREGBITW(&g_ulFlags, FLAG_SERIAL_BOOTLOADER) == 1) { // // Reset the timeout counter. // ulCount = 0; // // Clear the serial boot loader packet flag. // HWREGBITW(&g_ulFlags, FLAG_SERIAL_BOOTLOADER) = 0; } // // See if a timer tick has occurred. // if(HWREGBITW(&g_ulFlags, FLAG_TICK) == 1) { // // Increment the timeout counter. // ulCount++; // // Stop waiting if the serial download has timed out. // if(ulCount == SERIAL_UPDATE_TIMEOUT) { break; } // // Clear the timer tick flag. // HWREGBITW(&g_ulFlags, FLAG_TICK) = 0; } // // Update the progress bar and update the screen if the progress bar // has moved. // ulIdx = g_psProgressWidgets[PROGRESS_BAR].sBase.sPosition.sXMax; PROGRESS((g_ulImageOffset * 100) / g_ulImageSize); if(g_psProgressWidgets[PROGRESS_BAR].sBase.sPosition.sXMax != ulIdx) { DisplayFlush(); } } // // Clear the serial boot loader packet flag. // HWREGBITW(&g_ulFlags, FLAG_SERIAL_BOOTLOADER) = 0; // // Remove the progress bar widgets. // for(ulIdx = 0; ulIdx < NUM_PROGRESS_WIDGETS; ulIdx++) { WidgetRemove((tWidget *)(g_psProgressWidgets + ulIdx)); } // // Un-gray the non-title widgets in the main panel. // UpdateWidgetsColor(ClrWhite); // // If the update timed out, set the message to indicate the failure and // return a failure. // if(ulCount == SERIAL_UPDATE_TIMEOUT) { usnprintf(g_pcMessageBuffer, sizeof(g_pcMessageBuffer), "Update from PC failed"); return(1); } // // Return indicating that the serial download was successful. // return(0); }
//***************************************************************************** // // This function performs a CAN-based firmware update of a motor controller, // displaying progress on the screen. // //***************************************************************************** static void CANUpdate(void) { unsigned long ulIdx, ulLoop, *pulData, ulSize; // // Get a pointer to the local firmware image. // pulData = (unsigned long *)IMAGE_BASE; // // Get the size of the firmware image. // ulSize = *pulData++; // // Verify that the firmware image size is valid, the initial stack pointer // is valid, and the reset vector pointer is valid. // if((ulSize > 0x1f000) || ((pulData[0] & 0xffff0003) != 0x20000000) || ((pulData[1] & 0xfff00001) != 0x00000001)) { // // Indicate that the firmware image is not valid and return without // performing a firmware update. // usnprintf(g_pcMessageBuffer, sizeof(g_pcMessageBuffer), "Invalid update image!"); return; } // // Set the progress title to indicate that the motor controller is being // updated. // CanvasTextSet(g_psProgressWidgets + PROGRESS_TITLE, "Updating MDL-BDC"); // // Add the progress bar widgets to the widget list. // for(ulIdx = 0; ulIdx < NUM_PROGRESS_WIDGETS; ulIdx++) { WidgetAdd(WIDGET_ROOT, (tWidget *)(g_psProgressWidgets + ulIdx)); } // // Gray the non-title widgets in the main panel. // UpdateWidgetsColor(ClrNotPresent); // // Set the progress bar to the beginning. // PROGRESS(0); // // Update the display. // DisplayFlush(); // // Set the default message to a failure message. This will be replaced // with a success message if the update is successful. // usnprintf(g_pcMessageBuffer, sizeof(g_pcMessageBuffer), "Update of %d failed!", g_ulCurrentID); // // A simple do/while(0) loop that is executed once (because of the while(0) // at the end) but can be easily exited with a break. This allows a common // cleanup at the end (after the loop) while not having increasingly deep // nesting of the intervening code. // do { // // Tell the motor controller to enter firmware update mode. // CANUpdateStart(); // // Delay for 50 milliseconds to allow it time to shut down and enter // the boot loader. // Delay(50); // // Try to ping the boot loader. // for(ulLoop = 10; (ulLoop != 0) && (g_ulCANUpdateAck == 0); ulLoop--) { // // Send a ping command. // g_ulCANUpdateAck = 0; CANUpdatePing(); // // Delay up to 10 milliseconds waiting for the ACK. // DelayAck(10); } // // Abort the firmware update if the ACK was not received. // if(ulLoop == 0) { break; } // // Delay for 50 milliseconds. If there were some CAN network delays, // it is possible that two pings were sent with the ACK from the first // ping being received right after the second ping was sent. In this // case, this delay will allow time for the second ACK to be received // and processed; failure to do so would cause the remaining actions to // become out of sync. // Delay(50); // // Send the download command, causing the appropriate portion of flash // to be erased. // g_ulCANUpdateAck = 0; CANUpdateDownload(0x800, ulSize); // // Delay for up to 4 seconds waiting for the ACK. Since flash is being // erased, it could take up to ~2.5 seconds (depending on the size of // the firmware image). // if(DelayAck(4000) == 0) { break; } // // Loop over the data in the firmware image. // for(ulLoop = 0; ulLoop < ulSize; ulLoop += 8) { // // Send the next two words of the firmware image. // g_ulCANUpdateAck = 0; CANUpdateSendData(((ulSize - ulLoop) > 8) ? 8 : ulSize - ulLoop, pulData[0], pulData[1]); pulData += 2; // // Delay for up to 10 milliseconds waiting for the ACK. Since // flash is being programming, it could take up to ~44 // microseconds. // if(DelayAck(10) == 0) { break; } // // Update the progress bar and update the screen if the progress // bar has moved. // ulIdx = g_psProgressWidgets[PROGRESS_BAR].sBase.sPosition.sXMax; PROGRESS((ulLoop * 100) / ulSize); if(g_psProgressWidgets[PROGRESS_BAR].sBase.sPosition.sXMax != ulIdx) { DisplayFlush(); } } // // Abort the firmware update if the entire image was not programmed. // if(ulLoop < ulSize) { break; } // // Reset the motor controller. // CANUpdateReset(); // // Delay for 500 milliseconds while the motor controller is being // reset. // Delay(500); // // Indicate that the firmware update was successful. // usnprintf(g_pcMessageBuffer, sizeof(g_pcMessageBuffer), "Device %d updated.", g_ulCurrentID); // // Set the device ID so that any default configuration can be // performed. // CANSetID(g_ulCurrentID); } while(0); // // Remove the progress bar widgets. // for(ulIdx = 0; ulIdx < NUM_PROGRESS_WIDGETS; ulIdx++) { WidgetRemove((tWidget *)(g_psProgressWidgets + ulIdx)); } // // Un-gray the non-title widgets in the main panel. // UpdateWidgetsColor(ClrWhite); }
//***************************************************************************** // // A simple demonstration of the features of the Stellaris Graphics Library. // //***************************************************************************** int main(void) { tContext sContext; tRectangle sRect; // // Set the clocking to run from the PLL. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Set the device pinout appropriately for this board. // PinoutSet(); // // Initialize the display driver. // Kitronix320x240x16_SSD2119Init(); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sKitronix320x240x16_SSD2119); // // Fill the top 24 rows of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&sContext) - 1; sRect.sYMax = 23; GrContextForegroundSet(&sContext, ClrDarkBlue); GrRectFill(&sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&sContext, ClrWhite); GrRectDraw(&sContext, &sRect); // // Put the application name in the middle of the banner. // GrContextFontSet(&sContext, g_pFontCm20); GrStringDrawCentered(&sContext, "grlib demo", -1, GrContextDpyWidthGet(&sContext) / 2, 8, 0); // // Configure and enable uDMA // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlDelay(10); ROM_uDMAControlBaseSet(&sDMAControlTable[0]); ROM_uDMAEnable(); // // Initialize the sound driver. // SoundInit(0); // // Initialize the touch screen driver and have it route its messages to the // widget tree. // TouchScreenInit(); TouchScreenCallbackSet(WidgetPointerMessage); // // Add the title block and the previous and next buttons to the widget // tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sPrevious); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sTitle); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sNext); // // Add the first panel to the widget tree. // g_ulPanel = 0; WidgetAdd(WIDGET_ROOT, (tWidget *)g_psPanels); CanvasTextSet(&g_sTitle, g_pcPanelNames[0]); // // Issue the initial paint request to the widgets. // WidgetPaint(WIDGET_ROOT); // // Loop forever handling widget messages. // while(1) { // // Process any messages in the widget message queue. // WidgetMessageQueueProcess(); } }
//***************************************************************************** // // A simple demonstration of the features of the TivaWare Graphics Library. // //***************************************************************************** int main(void) { tContext sContext; uint32_t ui32SysClock; // // Run from the PLL at 120 MHz. // ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins. // PinoutSet(); // // Initialize the display driver. // Kentec320x240x16_SSD2119Init(ui32SysClock); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&sContext, "grlib-demo"); // // Configure and enable uDMA // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlDelay(10); ROM_uDMAControlBaseSet(&psDMAControlTable[0]); ROM_uDMAEnable(); // // Initialize the sound driver. // SoundInit(ui32SysClock); SoundVolumeSet(128); SoundStart(g_pi16AudioBuffer, AUDIO_SIZE, 64000, SoundCallback); // // Initialize the touch screen driver and have it route its messages to the // widget tree. // TouchScreenInit(ui32SysClock); TouchScreenCallbackSet(WidgetPointerMessage); // // Add the title block and the previous and next buttons to the widget // tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sPrevious); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sTitle); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sNext); // // Add the first panel to the widget tree. // g_ui32Panel = 0; WidgetAdd(WIDGET_ROOT, (tWidget *)g_psPanels); CanvasTextSet(&g_sTitle, g_pcPanelNames[0]); // // Issue the initial paint request to the widgets. // WidgetPaint(WIDGET_ROOT); // // Loop forever handling widget messages. // while(1) { // // Process any messages in the widget message queue. // WidgetMessageQueueProcess(); // // See if the first half of the sound buffer needs to be filled. // if(HWREGBITW(&g_ui32Flags, FLAG_PING) == 1) { // // generate new audio into the first half of the sound buffer. // GenerateAudio(g_pi16AudioBuffer, AUDIO_SIZE / 2); // // Clear the flag for the first half of the sound buffer. // HWREGBITW(&g_ui32Flags, FLAG_PING) = 0; } // // See if the second half of the sound buffer needs to be filled. // if(HWREGBITW(&g_ui32Flags, FLAG_PONG) == 1) { // // generate new audio into the second half of the sound buffer. // GenerateAudio(g_pi16AudioBuffer + (AUDIO_SIZE / 2), AUDIO_SIZE / 2); // // Clear the flag for the second half of the sound buffer. // HWREGBITW(&g_ui32Flags, FLAG_PONG) = 0; } } }
//***************************************************************************** // // Handles presses of the next panel button. // //***************************************************************************** void OnNext(tWidget *pWidget) { // // If this button is pressed when the last panel is displayed, we exit // back to keypad display. // if(g_ulPanel == (NUM_PANELS - 1)) { // // Play the key click sound. // SoundPlay(g_pusKeyClick, sizeof(g_pusKeyClick) / 2); // // Fix up the widget tree to move us back to keypad mode. // GraphicsDemoHide(); return; } // // Remove the current panel. // WidgetRemove((tWidget *)(g_psPanels + g_ulPanel)); // // Increment the panel index. // g_ulPanel++; // // Add and draw the new panel. // WidgetAdd((tWidget *)&g_sDemoBackground, (tWidget *)(g_psPanels + g_ulPanel)); WidgetPaint((tWidget *)(g_psPanels + g_ulPanel)); // // Set the title of this panel. // CanvasTextSet(&g_sTitle, g_pcPanelNames[g_ulPanel]); WidgetPaint((tWidget *)&g_sTitle); // // Set the button text to read "X" (exit) if this is the last panel, // otherwise revert to the usual "+". // PushButtonTextSet(&g_sNext, (g_ulPanel == (NUM_PANELS - 1)) ? "X" : "+"); WidgetPaint((tWidget *)&g_sNext); // // Set the "previous" button text to read "X" if this is the first panel, // otherwise revert to the usual "-". // PushButtonTextSet(&g_sPrevious, (g_ulPanel == 0) ? "X" : "-"); WidgetPaint((tWidget *)&g_sPrevious); // // Play the key click sound. // SoundPlay(g_pusKeyClick, sizeof(g_pusKeyClick) / 2); }
//***************************************************************************** // // Handles when a key is pressed on the keyboard. // //***************************************************************************** void KeyEvent(tWidget *psWidget, uint32_t ui32Key, uint32_t ui32Event) { switch(ui32Key) { // // Look for a backspace key press. // case UNICODE_BACKSPACE: { if(ui32Event == KEYBOARD_EVENT_PRESS) { if(g_ui32StringIdx != 0) { g_ui32StringIdx--; g_pcKeyStr[g_ui32StringIdx] = 0; } WidgetPaint((tWidget *)&g_sKeyboardText); // // Save the pixel width of the current string. // g_i32StringWidth = GrStringWidthGet(&g_sContext, g_pcKeyStr, 40); } break; } // // Look for an enter/return key press. This will exit the keyboard and // return to the current active screen. // case UNICODE_RETURN: { if(ui32Event == KEYBOARD_EVENT_RELEASE) { // // Get rid of the keyboard widget. // WidgetRemove(g_sScreens[g_i32ScreenIdx].psWidget); // // Switch back to the previous screen and add its widget back. // g_i32ScreenIdx = g_i32ScreenIdx; WidgetAdd(WIDGET_ROOT, g_sScreens[g_i32ScreenIdx].psWidget); // // If returning to the main screen then re-draw the frame to // indicate the main screen. // if(g_i32ScreenIdx == SCREEN_DETAILS) { FrameDraw(&g_sContext, "nfc-p2p-demo : Details"); WidgetPaint(g_sScreens[g_i32ScreenIdx].psWidget); } else if(g_i32ScreenIdx == SCREEN_TI) { // // Returning to the settings screen. // FrameDraw(&g_sContext, "nfc-p2p-demo : TI"); WidgetPaint(g_sScreens[g_i32ScreenIdx].psWidget); AnimateButtons(true); WidgetMessageQueueProcess(); } // // Assumed Screen = SCREEN_SUMMARY // else { FrameDraw(&g_sContext, "nfc-p2p-demo : Summary"); WidgetPaint(g_sScreens[g_i32ScreenIdx].psWidget); } // // Enable gestures. // g_sSwipe.bEnable = true; } break; } // // If the key is not special then update the text string. // default: { if(ui32Event == KEYBOARD_EVENT_PRESS) { // // Set the string to the current string to be updated. // if(g_ui32StringIdx == 0) { CanvasTextSet(&g_sKeyboardText, g_pcKeyStr); } g_pcKeyStr[g_ui32StringIdx] = (char)ui32Key; g_ui32StringIdx++; g_pcKeyStr[g_ui32StringIdx] = 0; WidgetPaint((tWidget *)&g_sKeyboardText); // // Save the pixel width of the current string. // g_i32StringWidth = GrStringWidthGet(&g_sContext, g_pcKeyStr, 40); } break; } } }
//***************************************************************************** // // A simple demonstration of the features of the TivaWare Graphics Library. // //***************************************************************************** int main(void) { tContext sContext; tRectangle sRect; // // The FPU should be enabled because some compilers will use floating- // point registers, even for non-floating-point code. If the FPU is not // enabled this will cause a fault. This also ensures that floating- // point operations could be added to this application and would work // correctly and use the hardware floating-point unit. Finally, lazy // stacking is enabled for interrupt handlers. This allows floating- // point instructions to be used within interrupt handlers, but at the // expense of extra stack usage. // FPUEnable(); FPULazyStackingEnable(); // // Run from the PLL at 120 MHz. // g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Initialize the display driver. // Kentec320x240x16_SSD2119Init(g_ui32SysClock); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119); // // Fill the top 24 rows of the screen with blue to create the banner. // sRect.i16XMin = 0; sRect.i16YMin = 0; sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1; sRect.i16YMax = 23; GrContextForegroundSet(&sContext, ClrDarkBlue); GrRectFill(&sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&sContext, ClrWhite); GrRectDraw(&sContext, &sRect); // // Put the application name in the middle of the banner. // GrContextFontSet(&sContext, &g_sFontCm20); GrStringDrawCentered(&sContext, "grlib demo", -1, GrContextDpyWidthGet(&sContext) / 2, 8, 0); // // Configure and enable uDMA // SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlDelay(10); uDMAControlBaseSet(&psDMAControlTable[0]); uDMAEnable(); // // Initialize the touch screen driver and have it route its messages to the // widget tree. // TouchScreenInit(g_ui32SysClock); TouchScreenCallbackSet(WidgetPointerMessage); // // Add the title block and the previous and next buttons to the widget // tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sPrevious); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sTitle); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sNext); // // Add the first panel to the widget tree. // g_ui32Panel = 0; WidgetAdd(WIDGET_ROOT, (tWidget *)g_psPanels); CanvasTextSet(&g_sTitle, g_pcPanei32Names[0]); // // Issue the initial paint request to the widgets. // WidgetPaint(WIDGET_ROOT); // // Loop forever handling widget messages. // while(1) { // // Process any messages in the widget message queue. // WidgetMessageQueueProcess(); } }
//***************************************************************************** // // A simple demonstration of the features of the Stellaris Graphics Library. // //***************************************************************************** int main(void) { tContext sContext; tRectangle sRect; // // If running on Rev A2 silicon, turn the LDO voltage up to 2.75V. This is // a workaround to allow the PLL to operate reliably. // if(REVISION_IS_A2) { SysCtlLDOSet(SYSCTL_LDO_2_75V); } // // Set the clocking to run from the PLL. // SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // // Initialize the display driver. // Kitronix320x240x16_SSD2119Init(); // // Turn on the backlight. // Kitronix320x240x16_SSD2119BacklightOn(255); // // Set graphics library text rendering defaults. // GrLibInit(&GRLIB_INIT_STRUCT); // // Set the string table and the default language. // GrStringTableSet(STRING_TABLE); // // Set the default language. // ChangeLanguage(GrLangEnUS); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sKitronix320x240x16_SSD2119); // // Fill the top 26 rows of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&sContext) - 1; sRect.sYMax = 25; GrContextForegroundSet(&sContext, ClrDarkBlue); GrRectFill(&sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&sContext, ClrWhite); GrRectDraw(&sContext, &sRect); // // Load the static strings from the string table. These strings are // independent of the language in use but we store them in the string // table nonetheless since (a) we may be using codepage remapping in // which case it would be difficult to hardcode them into the app source // anyway (ASCII or ISO8859-1 text would not render properly with the // remapped custom font) and (b) even if we're not using codepage remapping, // we may have generated a custom font from the string table output and // we want to make sure that all glyphs required by the application are // present in that font. If we hardcode some text in the application // source and don't put it in the string table, we run the risk of having // characters missing in the font. // GrStringGet(STR_ENGLISH, g_pcEnglish, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_DEUTSCH, g_pcDeutsch, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_ESPANOL, g_pcEspanol, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_ITALIANO, g_pcItaliano, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_CHINESE, g_pcChinese, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_KOREAN, g_pcKorean, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_JAPANESE, g_pcJapanese, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_PLUS, g_pcPlus, 2); GrStringGet(STR_MINUS, g_pcMinus, 2); // // Put the application name in the middle of the banner. // GrStringGet(STR_APPNAME, g_pcBuffer, SCOMP_MAX_STRLEN); GrContextFontSet(&sContext, FONT_20PT); GrStringDrawCentered(&sContext, g_pcBuffer, -1, GrContextDpyWidthGet(&sContext) / 2, 10, 0); // // Initialize the sound driver. // SoundInit(); // // Initialize the touch screen driver and have it route its messages to the // widget tree. // TouchScreenInit(); TouchScreenCallbackSet(WidgetPointerMessage); // // Add the title block and the previous and next buttons to the widget // tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sPrevious); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sTitle); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sNext); // // Add the first panel to the widget tree. // g_ulPanel = 0; WidgetAdd(WIDGET_ROOT, (tWidget *)g_psPanels); // // Set the string for the title. // CanvasTextSet(&g_sTitle, g_pcTitle); // // Initialize the pointer to the button text. // PushButtonTextSet(&g_sFirmwareUpdateBtn, g_pcUpdateButton); // // Issue the initial paint request to the widgets. // WidgetPaint(WIDGET_ROOT); // // Loop forever unless we receive a signal that a firmware update has been // requested. // while(!g_bFirmwareUpdate) { // // Process any messages in the widget message queue. // WidgetMessageQueueProcess(); } // // If we drop out, a firmware update request has been made. We call // WidgetMessageQueueProcess once more to ensure that any final messages // are processed then jump into the bootloader. // WidgetMessageQueueProcess(); // // Wait a while for the last keyboard click sound to finish. This is about // 500mS since the delay loop is 3 cycles long. // SysCtlDelay(SysCtlClockGet() / 6); // // Pass control to the bootloader. // JumpToBootLoader(); // // The boot loader should take control, so this should never be reached. // Just in case, loop forever. // while(1) { } }
//***************************************************************************** // // Handles presses of the next panel button. // //***************************************************************************** void OnNext(tWidget *pWidget) { // // There is nothing to be done if the last panel is already being // displayed. // if(g_ulPanel == (NUM_PANELS - 1)) { return; } // // Remove the current panel. // WidgetRemove((tWidget *)(g_psPanels + g_ulPanel)); // // Increment the panel index. // g_ulPanel++; // // Add and draw the new panel. // WidgetAdd(WIDGET_ROOT, (tWidget *)(g_psPanels + g_ulPanel)); WidgetPaint((tWidget *)(g_psPanels + g_ulPanel)); // // Set the title of this panel. // CanvasTextSet(&g_sTitle, g_pcPanelNames[g_ulPanel]); WidgetPaint((tWidget *)&g_sTitle); // // See if the previous panel was the first panel. // if(g_ulPanel == 1) { // // Display the previous button. // PushButtonImageOn(&g_sPrevious); PushButtonTextOn(&g_sPrevious); PushButtonFillOff(&g_sPrevious); WidgetPaint((tWidget *)&g_sPrevious); } // // See if this is the last panel. // if(g_ulPanel == (NUM_PANELS - 1)) { // // Clear the next button from the display since the last panel is being // displayed. // PushButtonImageOff(&g_sNext); PushButtonTextOff(&g_sNext); PushButtonFillOn(&g_sNext); WidgetPaint((tWidget *)&g_sNext); } // // Play the key click sound. // //SoundPlay(g_pusKeyClick, sizeof(g_pusKeyClick) / 2); ClickPlay(); }
//***************************************************************************** // // A simple demonstration of the features of the Stellaris Graphics Library. // //***************************************************************************** int main(void) { tContext sContext; tRectangle sRect; // // If running on Rev A2 silicon, turn the LDO voltage up to 2.75V. This is // a workaround to allow the PLL to operate reliably. // if(REVISION_IS_A2) { SysCtlLDOSet(SYSCTL_LDO_2_75V); } // // Set the clocking to run from the PLL. // SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // // Initialize the display driver. // Kitronix320x240x16_SSD2119Init(); // // Turn on the backlight. // Kitronix320x240x16_SSD2119BacklightOn(255); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sKitronix320x240x16_SSD2119); // // Fill the top 24 rows of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&sContext) - 1; sRect.sYMax = 23; GrContextForegroundSet(&sContext, ClrDarkBlue); GrRectFill(&sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&sContext, ClrWhite); GrRectDraw(&sContext, &sRect); // // Put the application name in the middle of the banner. // GrContextFontSet(&sContext, g_pFontCm20); GrStringDrawCentered(&sContext, "grlib demo", -1, GrContextDpyWidthGet(&sContext) / 2, 11, 0); // // Initialize the sound driver. // SoundInit(); // // Initialize the touch screen driver and have it route its messages to the // widget tree. // TouchScreenInit(); TouchScreenCallbackSet(WidgetPointerMessage); // // Add the title block and the previous and next buttons to the widget // tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sPrevious); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sTitle); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sNext); // // Add the first panel to the widget tree. // g_ulPanel = 0; WidgetAdd(WIDGET_ROOT, (tWidget *)g_psPanels); CanvasTextSet(&g_sTitle, g_pcPanelNames[0]); // // Issue the initial paint request to the widgets. // WidgetPaint(WIDGET_ROOT); // // Loop forever unless we receive a signal that a firmware update has been // requested. // while(!g_bFirmwareUpdate) { // // Process any messages in the widget message queue. // WidgetMessageQueueProcess(); } // // If we drop out, a firmware update request has been made. We call // WidgetMessageQueueProcess once more to ensure that any final messages // are processed then jump into the bootloader. // WidgetMessageQueueProcess(); // // Wait a while for the last keyboard click sound to finish. This is about // 500mS since the delay loop is 3 cycles long. // SysCtlDelay(SysCtlClockGet() / 6); // // Pass control to the bootloader. // JumpToBootLoader(); // // The boot loader should take control, so this should never be reached. // Just in case, loop forever. // while(1) { } }