//***************************************************************************** // // Provide a simple function so other parts of the application can update // a status display. // //***************************************************************************** void SetStatusText(const char *pcTitle, const char *pcLine1, const char *pcLine2, const char *pcLine3) { static const char pcBlankLine[] = " "; // // Check to see if each parameter was passed, and if so then update its // text field on the status dislay. // pcTitle = pcTitle ? pcTitle : pcBlankLine; MenuUpdateText(TEXT_ITEM_STATUS_TITLE, pcTitle); pcLine1 = pcLine1 ? pcLine1 : pcBlankLine; MenuUpdateText(TEXT_ITEM_STATUS1, pcLine1); pcLine2 = pcLine2 ? pcLine2 : pcBlankLine; MenuUpdateText(TEXT_ITEM_STATUS2, pcLine2); pcLine3 = pcLine3 ? pcLine3 : pcBlankLine; MenuUpdateText(TEXT_ITEM_STATUS3, pcLine3); // // Force a repaint after all the status text fields have been updated. // WidgetPaint(WIDGET_ROOT); WidgetMessageQueueProcess(); }
//***************************************************************************** // // Draw one of the LED widgets in a particular state. // //***************************************************************************** void UpdateLEDWidget(unsigned long ulLED, tBoolean bOn) { tPushButtonWidget *pButton; // // Which widget are we dealing with? // pButton = (ulLED == 1) ? &g_sLED1 : &g_sLED2; // // Turn the LED on or off by setting the background fill color // appropriately. // PushButtonFillColorSet(pButton, g_ulLEDColors[ulLED - 1][bOn]); PushButtonFillColorPressedSet(pButton, g_ulLEDColors[ulLED - 1][bOn]); // // Ensure that the LED is repainted. This will occur on the next call to // WidgetMessageQueueProcess(). // WidgetPaint((tWidget *)pButton); // // Process the messages in the widget message queue. // WidgetMessageQueueProcess(); }
//***************************************************************************** // // This function listens for a link request from another SimpliciTI device. // //***************************************************************************** tBoolean LinkFrom(void) { smplStatus_t eRetcode; unsigned long ulCount; // // Tell SimpliciTI to try to link to an access point. // for(ulCount = 1; ulCount <= 10; ulCount++) { // // Update the displayed count. Note that we must process the widget // message queue here to ensure that the change makes it onto the // display. // UpdateStatus(false, "Listening %d (%s)", ulCount, (ulCount > 1) ? MapSMPLStatus(eRetcode) : "Waiting"); WidgetMessageQueueProcess(); // // Try to link to the access point. // eRetcode = SMPL_LinkListen(&sLinkID); if(eRetcode == SMPL_SUCCESS) { break; } } // // Did we manage to link to the access point? // if(eRetcode == SMPL_SUCCESS) { UpdateStatus(false, "Listen successful."); // // Turn on RX. Default is off. // SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RXON, 0); // // Tell the main loop that we established communication successfully. // return(true); } else { UpdateStatus(false, "No link request received."); // // Tell the main loop that we failed to establish communication. // return(false); } }
//**************************************************************************** // // Application should periodically call this function. // //**************************************************************************** void UIMain(void) { WidgetMessageQueueProcess(); if(g_sUIState.ui32Indicators & UI_STATUS_KEYBOARD) { } else { USBMouseMain(); } }
void vGraphicTask(void* pvParameters) { vInitDisplay(); vShowBootText("booting ..."); while (1) { // // Process any messages in the widget message queue. // WidgetMessageQueueProcess(); vTaskDelay(1); } }
//***************************************************************************** // // This function causes the display to be redrawn. // //***************************************************************************** void DisplayFlush(void) { // // Send a paint message to the entire widget tree. // WidgetPaint(WIDGET_ROOT); // // Process any widget messages in the message queue. // WidgetMessageQueueProcess(); // // Flush the drawing operations to the screen. // DpyFlush(&g_sRIT128x96x4Display); }
int main(void) { // // Set the system clock to run at 80MHz (max freq) from the PLL. // SysCtlClockSet( SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Configure SysTick for a 100Hz interrupt. // SysTickPeriodSet(SysCtlClockGet() / TICKS_PER_SECOND); SysTickEnable(); /// Init RTC rtc_init(); // Init LCD ssd1289_init(); // // Initialize the display context // GrContextInit(&sContext, pDisplay); initClock(pDisplay); // Init touch xpt2046_init(); xpt2046_setTouchScreenCallback(WidgetPointerMessage); xpt2046_enableTouchIRQ(); SysTickIntEnable(); startMainMenuApplication(); while (true) { // // Process any messages in the widget message queue. // WidgetMessageQueueProcess(); } }
int main(void) { ui32SysClkFreq = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1); GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1, 0x00); Kentec320x240x16_SSD2119Init(ui32SysClkFreq); TouchScreenInit(ui32SysClkFreq); TouchScreenCallbackSet(WidgetPointerMessage); WidgetAdd(WIDGET_ROOT, (tWidget *) &g_sBackground); WidgetPaint(WIDGET_ROOT); while (1) { WidgetMessageQueueProcess(); } }
//***************************************************************************** // // Periodic Functions that need to be called. Should go in main loop // //***************************************************************************** void ScreenPeriodic(void) { // // Handle screen movements. // HandleMovement(); // // Handle button animation. // AnimateButtons(true); // // Handle keyboard entry if it is open. // HandleKeyboard(); // // If nothing has happened for awhile, then move to a new city. // if(g_ui32ScreenSaver == 0) { // // Reset the timeout for 10s to update the screen more often. // g_ui32ScreenSaver = 10 * SYSTEM_TICK_S; // // Trigger a left swipe. // g_sSwipe.eMovement = iSwipeLeft; } WidgetMessageQueueProcess(); }
//***************************************************************************** // // A simple delay function which will wait for a particular number of // milliseconds before returning. During this time, the application message // queue is serviced. The delay granularity here is the system tick period. // //***************************************************************************** void ApplicationDelay(unsigned long ulDelaymS) { unsigned long ulTarget; // // What will the system tick counter be when we are finished this delay? // ulTarget = g_ulSysTickCount + ((ulDelaymS * TICKS_PER_SECOND) / 1000); // // Hang around waiting until this time. This doesn't take into account the // system tick counter wrapping but, since this takes about 13 and a half // years, it's probably not too much of a problem. // while(g_ulSysTickCount < ulTarget) { // // Process the message queue in case there are any new messages to // handle. // WidgetMessageQueueProcess(); } }
//***************************************************************************** // // Handle the animation when switching between screens. // //***************************************************************************** void AnimatePanel(uint32_t ui32Color) { int32_t i32Idx; GrContextForegroundSet(&g_sContext, ui32Color); if(g_i32ScreenIdx == SCREEN_DETAILS) { for(i32Idx = BG_MAX_Y; i32Idx >= BG_MIN_Y; i32Idx--) { GrLineDrawH(&g_sContext, BG_MIN_X, BG_MAX_X, i32Idx); if(i32Idx == 40) { WidgetPaint((tWidget *)&g_sHeaderTitle); WidgetMessageQueueProcess(); } else if(i32Idx == 70) { WidgetPaint((tWidget *)&g_sHeaderLine1); WidgetMessageQueueProcess(); } else if(i32Idx == 100) { WidgetPaint((tWidget *)&g_sHeaderLine2); WidgetMessageQueueProcess(); } else if(i32Idx == 130) { WidgetPaint((tWidget *)&g_sHeaderLine3); WidgetMessageQueueProcess(); } else if(i32Idx == 160) { WidgetPaint((tWidget *)&g_sHeaderLine4); WidgetMessageQueueProcess(); } else if(i32Idx == 190) { WidgetPaint((tWidget *)&g_sHeaderLine5); WidgetMessageQueueProcess(); } SysCtlDelay(SCREEN_ANIMATE_DELAY); } } else if(g_i32ScreenIdx == SCREEN_SUMMARY) { for(i32Idx = BG_MAX_Y; i32Idx >= BG_MIN_Y; i32Idx--) { GrLineDrawH(&g_sContext, BG_MIN_X, BG_MAX_X, i32Idx); if(i32Idx == 210) { WidgetPaint((tWidget *)&g_sPayloadLine8); WidgetMessageQueueProcess(); } else if(i32Idx == 195) { WidgetPaint((tWidget *)&g_sPayloadLine7); WidgetMessageQueueProcess(); } else if(i32Idx == 180) { WidgetPaint((tWidget *)&g_sPayloadLine6); WidgetMessageQueueProcess(); } else if(i32Idx == 165) { WidgetPaint((tWidget *)&g_sPayloadLine5); WidgetMessageQueueProcess(); } else if(i32Idx == 150) { WidgetPaint((tWidget *)&g_sPayloadLine4); WidgetMessageQueueProcess(); } else if(i32Idx == 135) { WidgetPaint((tWidget *)&g_sPayloadLine3); WidgetMessageQueueProcess(); } else if(i32Idx == 120) { WidgetPaint((tWidget *)&g_sPayloadLine2); WidgetMessageQueueProcess(); } else if(i32Idx == 105) { WidgetPaint((tWidget *)&g_sPayloadLine1); WidgetMessageQueueProcess(); } else if(i32Idx == 75) { WidgetPaint((tWidget *)&g_sPayloadTitle); WidgetMessageQueueProcess(); } else if(i32Idx == 40) { WidgetPaint((tWidget *)&g_sTag); WidgetMessageQueueProcess(); WidgetPaint((tWidget *)&g_sTagTitle); WidgetMessageQueueProcess(); } SysCtlDelay(SCREEN_ANIMATE_DELAY); } } else if(g_i32ScreenIdx == SCREEN_TI) { for(i32Idx = BG_MIN_Y; i32Idx < BG_MAX_Y; i32Idx++) { GrLineDrawH(&g_sContext, BG_MIN_X, BG_MAX_X, i32Idx); if (i32Idx == 100) { GrImageDraw(&g_sContext, g_pui8TILogo, BG_MIN_X, BG_MIN_Y); } else if(i32Idx == 140) { WidgetPaint((tWidget *)&g_sStatusLine1); WidgetMessageQueueProcess(); GrContextForegroundSet(&g_sContext, ui32Color); } else if(i32Idx == 170) { //DrawToggle(&sProxyToggle, g_sConfig.bProxyEnabled); WidgetPaint((tWidget *)&g_sStatusLine2); GrContextForegroundSet(&g_sContext, ui32Color); WidgetMessageQueueProcess(); } else if(i32Idx == 230) { WidgetPaint((tWidget *)&g_sTINFCButton); WidgetPaint((tWidget *)&g_sEchoNFCButton); GrContextForegroundSet(&g_sContext, ui32Color); WidgetMessageQueueProcess(); } SysCtlDelay(SCREEN_ANIMATE_DELAY); } } }
//***************************************************************************** // // Main application entry function. // //***************************************************************************** int main(void) { tBoolean bRetcode; bspIState_t intState; uint8_t ucLastChannel; // // Set the system clock to run at 50MHz from the PLL // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // NB: We don't call PinoutSet() in this testcase since the EM header // expansion board doesn't currently have an I2C ID EEPROM. If we did // call PinoutSet() this would configure all the EPI pins for SDRAM and // we don't want to do this. // g_eDaughterType = DAUGHTER_NONE; // // Enable peripherals required to drive the LCD. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH); // // Configure SysTick for a 10Hz interrupt. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Initialize the display driver. // Kitronix320x240x16_SSD2119Init(); // // Initialize the touch screen driver. // TouchScreenInit(); // // Set the touch screen event handler. // TouchScreenCallbackSet(WidgetPointerMessage); // // Add the compile-time defined widgets to the widget tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sHeading); // // Initialize the status string. // UpdateStatus(true, "Initializing..."); // // Paint the widget tree to make sure they all appear on the display. // WidgetPaint(WIDGET_ROOT); // // Initialize the SimpliciTI BSP. // BSP_Init(); // // Set the SimpliciTI device address using the current Ethernet MAC address // to ensure something like uniqueness. // bRetcode = SetSimpliciTIAddress(); // // Did we have a problem with the address? // if(!bRetcode) { // // Yes - make sure the display is updated then hang the app. // WidgetMessageQueueProcess(); while(1) { // // MAC address is not set so hang the app. // } } // // Turn on both our LEDs // SetLED(1, true); SetLED(2, true); UpdateStatus(true, "Waiting for a device..."); // // Initialize the SimpliciTI stack and register our receive callback. // SMPL_Init(ReceiveCallback); // // Tell the user what's up. // UpdateStatus(true, "Access point active."); // // Do nothing after this - the SimpliciTI stack code handles all the // access point function required. // while(1) { // // Wait for the Join semaphore to be set by the receipt of a Join // frame from a device that supports an end device. // // An external method could be used as well. A button press could be // connected to an ISR and the ISR could set a semaphore that is // checked by a function call here, or a command shell running in // support of a serial connection could set a semaphore that is // checked by a function call. // if (g_ucJoinSem && (g_ucNumCurrentPeers < NUM_CONNECTIONS)) { // // Listen for a new incoming connection. // while (1) { if (SMPL_SUCCESS == SMPL_LinkListen(&g_sLID[g_ucNumCurrentPeers])) { // // The connection attempt succeeded so break out of the // loop. // break; } // // Process our widget message queue. // WidgetMessageQueueProcess(); // // A "real" application would implement its fail-to-link // policy here. We go back and listen again. // } // // Increment our peer counter. // g_ucNumCurrentPeers++; // // Decrement the join semaphore. // BSP_ENTER_CRITICAL_SECTION(intState); g_ucJoinSem--; BSP_EXIT_CRITICAL_SECTION(intState); // // Tell the user how many devices we are now connected to. // UpdateStatus(false, "%d devices connected.", g_ucNumCurrentPeers); } // // Have we received a frame on one of the ED connections? We don't use // a critical section here since it doesn't really matter much if we // miss a poll. // if (g_ucPeerFrameSem) { uint8_t pucMsg[MAX_APP_PAYLOAD], ucLen, ucLoop; /* process all frames waiting */ for (ucLoop = 0; ucLoop < g_ucNumCurrentPeers; ucLoop++) { // // Receive the message. // if (SMPL_SUCCESS == SMPL_Receive(g_sLID[ucLoop], pucMsg, &ucLen)) { // // ...and pass it to the function that processes it. // ProcessMessage(g_sLID[ucLoop], pucMsg, ucLen); // // Decrement our frame semaphore. // BSP_ENTER_CRITICAL_SECTION(intState); g_ucPeerFrameSem--; BSP_EXIT_CRITICAL_SECTION(intState); } } } // // Have we been asked to change channel? // ucLastChannel = g_ucChannel; if (g_bChangeChannel) { // // Yes - go ahead and change to the next radio channel. // g_bChangeChannel = false; ChangeChannel(); } else { // // No - check to see if we need to automatically change channel // due to interference on the current one. // CheckChangeChannel(); } // // If the channel changed, update the display. // if(g_ucChannel != ucLastChannel) { UpdateStatus(false, "Changed to channel %d.", g_ucChannel); } // // If required, blink the "LEDs" to indicate we are waiting for a // message following a channel change. // BSP_ENTER_CRITICAL_SECTION(intState); if (g_ulBlinky) { if (++g_ulBlinky >= 0xF) { g_ulBlinky = 1; ToggleLED(1); ToggleLED(2); } } BSP_EXIT_CRITICAL_SECTION(intState); // // Process our widget message queue. // WidgetMessageQueueProcess(); } }
//***************************************************************************** // // Main application entry function. // //***************************************************************************** int main(void) { tBoolean bRetcode; smplStatus_t eRetcode; // // Set the system clock to run at 50MHz from the PLL // MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // NB: We don't call PinoutSet() in this testcase since the EM header // expansion board doesn't currently have an I2C ID EEPROM. If we did // call PinoutSet() this would configure all the EPI pins for SDRAM and // we don't want to do this. // g_eDaughterType = DAUGHTER_NONE; // // Enable peripherals required to drive the LCD. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH); // // Configure SysTick for a 10Hz interrupt. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Initialize the display driver. // Kitronix320x240x16_SSD2119Init(); // // Initialize the touch screen driver. // TouchScreenInit(); // // Set the touch screen event handler. // TouchScreenCallbackSet(WidgetPointerMessage); // // Add the compile-time defined widgets to the widget tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sHeading); // // Initialize the status string. // UpdateStatus("Initializing..."); // // Paint the widget tree to make sure they all appear on the display. // WidgetPaint(WIDGET_ROOT); // // Initialize the SimpliciTI BSP. // BSP_Init(); // // Set the SimpliciTI device address using the current Ethernet MAC address // to ensure something like uniqueness. // bRetcode = SetSimpliciTIAddress(); // // Did we have a problem with the address? // if(!bRetcode) { // // Yes - make sure the display is updated then hang the app. // WidgetMessageQueueProcess(); while(1) { // // MAC address is not set so hang the app. // } } // // Turn on both our LEDs // SetLED(1, true); SetLED(2, true); UpdateStatus("Waiting..."); // // Initialize the SimpliciTI stack but don't set any receive callback. // while(1) { eRetcode = SMPL_Init((uint8_t (*)(linkID_t))0); if(eRetcode == SMPL_SUCCESS) { break; } ToggleLED(1); ToggleLED(2); SPIN_ABOUT_A_SECOND; } // // Tell the user what's up. // UpdateStatus("Range Extender active."); // // Do nothing after this - the SimpliciTI stack code handles all the // access point function required. // while(1) { // // Process the widget message queue. // WidgetMessageQueueProcess(); } }
//***************************************************************************** // // 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 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(); } }
//***************************************************************************** // // Main application entry function. // //***************************************************************************** int main(void) { tBoolean bRetcode; smplStatus_t eRetcode; ioctlToken_t eToken; // // Set the system clock to run at 50MHz from the PLL // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // NB: We don't call PinoutSet() in this testcase since the EM header // expansion board doesn't currently have an I2C ID EEPROM. If we did // call PinoutSet() this would configure all the EPI pins for SDRAM and // we don't want to do this. // g_eDaughterType = DAUGHTER_NONE; // // Enable peripherals required to drive the LCD. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH); // // Configure SysTick for a 10Hz interrupt. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Initialize the display driver. // Kitronix320x240x16_SSD2119Init(); // // Initialize the touch screen driver. // TouchScreenInit(); // // Set the touch screen event handler. // TouchScreenCallbackSet(WidgetPointerMessage); // // Add the compile-time defined widgets to the widget tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sHeading); // // Initialize the status string. // UpdateStatus("Initializing..."); // // Paint the widget tree to make sure they all appear on the display. // WidgetPaint(WIDGET_ROOT); // // Initialize the SimpliciTI BSP. // BSP_Init(); // // Set the SimpliciTI device address using the current Ethernet MAC address // to ensure something like uniqueness. // bRetcode = SetSimpliciTIAddress(); // // Did we have a problem with the address? // if(!bRetcode) { // // Yes - make sure the display is updated then hang the app. // WidgetMessageQueueProcess(); while(1) { // // MAC address is not set so hang the app. // } } // // Turn on both our LEDs // SetLED(1, true); SetLED(2, true); UpdateStatus("Waiting..."); // // Initialize the SimpliciTI stack but don't set any receive callback. // while(1) { eRetcode = SMPL_Init((uint8_t (*)(linkID_t))0); if(eRetcode == SMPL_SUCCESS) { break; } ToggleLED(1); ToggleLED(2); SPIN_ABOUT_A_SECOND; } // This code example changes the Link token to be distributed to those who // Join. For the example here this should be done before anyone joins so // the Join context is defaulted to OFF for this scenario. See the // smpl_config.dat file. After the link token is set the Join context must // be enabled. // // NOTE that this is done after initialization. For APs the init sequence // consists of a step in which a link token is generated. The sequence here // overrides that setting. It can be used to distribute different link // tokens to different devices. The sequence here is a simple example of // how to use the IOCTL interface to set the Link token for subsequent // Joiners. // // You might want to be careful about following this particular example if // you are restoring from NV unless you are setting a fixed value as is // done here. Unconditionally setting a random value will make it // essentially impossible for newly joining devices to link to devices that // joined before the AP was reset since they will have different link // tokens. // eToken.tokenType = TT_LINK; eToken.token.linkToken = 0x78563412; SMPL_Ioctl(IOCTL_OBJ_TOKEN, IOCTL_ACT_SET, &eToken); // // Enable join context. // SMPL_Ioctl(IOCTL_OBJ_AP_JOIN, IOCTL_ACT_ON, 0); // // Tell the user what's up. // UpdateStatus("Access point active."); // // Do nothing after this - the SimpliciTI stack code handles all the // access point function required. // while(1) { // // Process the widget message queue. // WidgetMessageQueueProcess(); } }
int main(void) { int xCoOd = 0, yCoOd = 0; char pressure = 0, touched = 0; unsigned int i = 0; unsigned char *dest; unsigned char *src; SetupIntc(); SetUpLCD(); /* configuring the base ceiling */ RasterDMAFBConfig(SOC_LCDC_0_REGS, (unsigned int)(g_pucBuffer+PALETTE_OFFSET), (unsigned int)(g_pucBuffer+PALETTE_OFFSET) + sizeof(g_pucBuffer) - 2 - PALETTE_OFFSET, FRAME_BUFFER_0); RasterDMAFBConfig(SOC_LCDC_0_REGS, (unsigned int)(g_pucBuffer+PALETTE_OFFSET), (unsigned int)(g_pucBuffer+PALETTE_OFFSET) + sizeof(g_pucBuffer) - 2 - PALETTE_OFFSET, FRAME_BUFFER_1); src = (unsigned char *) palette_32b; dest = (unsigned char *) (g_pucBuffer+PALETTE_OFFSET); // Copy palette info into buffer for( i = PALETTE_OFFSET; i < (PALETTE_SIZE+PALETTE_OFFSET); i++) { *dest++ = *src++; } // copy splash screen /*src = (unsigned char *)&splash[40]; for(; i < LCD_SIZE; i++) { *dest++ = *src++; }*/ GrOffScreen16BPPInit(&g_sSHARP480x272x16Display, g_pucBuffer, LCD_WIDTH, LCD_HEIGHT); // Initialize a drawing context. GrContextInit(&sContext, &g_sSHARP480x272x16Display); /* enable End of frame interrupt */ RasterEndOfFrameIntEnable(SOC_LCDC_0_REGS); /* enable raster */ RasterEnable(SOC_LCDC_0_REGS); /* Enable display panel backlight and power */ ConfigRasterDisplayEnable(); DisplayGR(); SoundInit(); // TS init PeripheralsSetup(); InitTouchScreen(); // Loop forever handling widget messages. while(1) { while(!touched) { ReadAxis(2, &pressure, &touched); } /* Resolving the coordinates of the touched location.*/ ResolveCoordinates(&xCoOd, &yCoOd); do { WidgetPointerMessage(WIDGET_MSG_PTR_DOWN, xCoOd, yCoOd); // Process any messages in the widget message queue. WidgetMessageQueueProcess(); ResolveCoordinates(&xCoOd, &yCoOd); ReadAxis(2, &pressure, &touched); }while(touched); WidgetPointerMessage(WIDGET_MSG_PTR_UP, xCoOd, yCoOd); WidgetMessageQueueProcess(); } }
//***************************************************************************** // // This function attempts to link to another SimpliciTI device by sending a // link request. // //***************************************************************************** tBoolean LinkTo(void) { smplStatus_t eRetcode; unsigned long ulCount; // // Turn both "LEDs" on. // SetLED(1, true); SetLED(2, true); // // Tell SimpliciTI to try to link to an access point. // for(ulCount = 1; ulCount <= 10; ulCount++) { // // Update the displayed count. Note that we must process the widget // message queue here to ensure that the change makes it onto the // display. // UpdateStatus(false, "Link request %d (%s)", ulCount, (ulCount > 1) ? MapSMPLStatus(eRetcode) : "Waiting"); WidgetMessageQueueProcess(); // // Try to link to the access point. // eRetcode = SMPL_Link(&sLinkID); if(eRetcode == SMPL_SUCCESS) { break; } // // Wait a bit before trying again. // NWK_DELAY(1000); // // Toggle both the LEDs // ToggleLED(1); ToggleLED(2); } // // Did we manage to link to the access point? // if(eRetcode == SMPL_SUCCESS) { // // Tell the user how we got on. // UpdateStatus(false, "Link successful."); SetLED(2, false); // // Turn on RX. Default is off. // SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RXON, 0); // // Set the time at which we have to send the next packet to our peer to // one second in the future. // g_ulNextPacketTick = g_ulSysTickCount + TICKS_PER_SECOND; // // Tell the main loop that we established communication successfully. // return(true); } else { UpdateStatus(false, "Failed to link."); // // Tell the main loop that we failed to establish communication. // return(false); } }
//***************************************************************************** // // Compute and display a sine wave. // //***************************************************************************** int main(void) { uint_fast16_t ui16ItemCount = 0; uint32_t ui32LastTickCount = 0; // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPULazyStackingEnable(); // // Set the clocking to run directly at 50 MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); // // Configure SysTick to generate a periodic time tick interrupt. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Initialize the display driver. // CFAL96x64x16Init(); // // Initialize an offscreen display and assign the palette. This offscreen // buffer is needed by the strip chart widget. // GrOffScreen4BPPInit(&g_sOffscreenDisplay, g_pui8OffscreenBuf, 96, 64); GrOffScreen4BPPPaletteSet(&g_sOffscreenDisplay, g_pui32Palette, 0, NUM_PALETTE_ENTRIES); // // Set the data series buffer pointer to point at the storage where the // series data points will be stored. // g_sSeries.pvData = g_i8SeriesData; // // Add the series to the strip chart // StripChartSeriesAdd(&g_sStripChart, &g_sSeries); // // Add the strip chart to the widget tree. // WidgetAdd(WIDGET_ROOT, &g_sStripChart.sBase); // // Enter a loop to continuously calculate a sine wave. // while(1) { float fElapsedTime; float fRadians; float fSine; // // Wait for the next timer tick. // while(ui32LastTickCount == g_ui32TickCount) { } ui32LastTickCount = g_ui32TickCount; // // Preparing to add a new data point to the strip chart ... // If the number count of items in the strip chart has reached the // maximum value, then the data points need to "slide down" in the // buffer so new data can be added at the end. // if(ui16ItemCount == SERIES_LENGTH) { memmove(&g_i8SeriesData[0], &g_i8SeriesData[1], SERIES_LENGTH - 1); } // // Otherwise, the series data buffer is less than full so just // increment the count of data points. // else { // // Increment the number of items that have been added to the strip // chart series data buffer. // ui16ItemCount++; // // Since the count of data items has changed, it must be updated in // the data series. // g_sSeries.ui16NumItems = ui16ItemCount; } // // Compute the elapsed time in decimal seconds, in floating point // format. // fElapsedTime = (float)g_ui32TickCount * FSECONDS_PER_TICK; // // Convert the time to radians. // fRadians = fElapsedTime * 2.0 * M_PI; // // Adjust the period of the wave. This will give us a wave period // of 4 seconds, or 0.25 Hz. This number was chosen arbitrarily to // provide a nice looking wave on the display. // fRadians /= 4.0; // // Compute the sine. Multiply by 0.5 to reduce the amplitude. // fSine = sinf(fRadians) * 0.5; // // Finally, save the sine value into the last location in the series // data point buffer. Convert the sine amplitude to display pixels. // (Amplitude 1 = 32 pixels) // g_i8SeriesData[ui16ItemCount - 1] = (int8_t)(fSine * 32.0); // // Now that a new data point has been added to the series, advance // the strip chart. // StripChartAdvance(&g_sStripChart, 1); // // Request a repaint and run the widget processing queue. // WidgetPaint(WIDGET_ROOT); WidgetMessageQueueProcess(); } }
//***************************************************************************** // // Main application entry function. // //***************************************************************************** int main(void) { tBoolean bSuccess, bRetcode, bInitialized; // // Set the system clock to run at 50MHz from the PLL // MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // NB: We don't call PinoutSet() in this testcase since the EM header // expansion board doesn't currently have an I2C ID EEPROM. If we did // call PinoutSet() this would configure all the EPI pins for SDRAM and // we don't want to do this. // g_eDaughterType = DAUGHTER_NONE; // // Enable peripherals required to drive the LCD. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH); // // Configure SysTick for a 10Hz interrupt. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Initialize the display driver. // Kitronix320x240x16_SSD2119Init(); // // Initialize the touch screen driver. // TouchScreenInit(); // // Set the touch screen event handler. // TouchScreenCallbackSet(WidgetPointerMessage); // // Add the compile-time defined widgets to the widget tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sHeading); // // Paint the widget tree to make sure they all appear on the display. // WidgetPaint(WIDGET_ROOT); // // Initialize the SimpliciTI BSP. // BSP_Init(); // // Set the SimpliciTI device address using the current Ethernet MAC address // to ensure something like uniqueness. // bRetcode = SetSimpliciTIAddress(); if(!bRetcode) { // // The Ethernet MAC address can't have been set so hang here since we // don't have an address to use for SimpliciTI. // WidgetMessageQueueProcess(); while(1) { // // MAC address is not set so hang the app. // } } // // First time through, we need to initialize the SimpliciTI stack. // bInitialized = false; // // The main loop starts here now that we have joined the network. // while(1) { // // Tell the user what to do. // UpdateStatus(true, "Please choose the operating mode."); // // Now wait until the user selects whether we should run as the sender // or the receiver. // while(g_ulMode == MODE_UNDEFINED) { // // Just spin, processing UI messages and waiting for someone to // press one of the mode buttons. // WidgetMessageQueueProcess(); } // // At this point, the mode is set so remove the buttons from the // display and replace them with the LEDs. // WidgetRemove((tWidget *)&g_sBtnContainer); WidgetAdd((tWidget *)&g_sBackground, (tWidget *)&g_sLEDContainer); WidgetPaint((tWidget *)&g_sBackground); // // Tell the user what we're doing now. // UpdateStatus(false, "Joining network..."); if(!bInitialized) { // // Initialize the SimpliciTI stack We keep trying to initialize until // we get a success return code. This indicates that we have also // successfully joined the network. // while(SMPL_SUCCESS != SMPL_Init((uint8_t (*)(linkID_t))0)) { ToggleLED(1); ToggleLED(2); SPIN_ABOUT_A_SECOND; } // // Now that we are initialized, remember not to call this again. // bInitialized = true; } // // Once we have joined, turn both LEDs on and tell the user what we want // them to do. // SetLED(1, true); SetLED(2, true); // // Now call the function that initiates communication in // the desired mode. Note that these functions will not return // until communication is established or an error occurs. // if(g_ulMode == MODE_SENDER) { bSuccess = LinkTo(); } else { bSuccess = LinkFrom(); } // // If we were unsuccessfull, go back to the mode selection // display. // if(!bSuccess) { // // Remove the LEDs and show the buttons again. // WidgetRemove((tWidget *)&g_sLEDContainer); WidgetAdd((tWidget *)&g_sBackground, (tWidget *)&g_sBtnContainer); WidgetPaint((tWidget *)&g_sBackground); // // Tell the user what happened. // UpdateStatus(false, "Error establishing communication!"); // // Remember that we don't have an operating mode chosen. // g_ulMode = MODE_UNDEFINED; } } }
//***************************************************************************** // // This function listens for a link request from another SimpliciTI device. // //***************************************************************************** tBoolean LinkFrom(void) { linkID_t linkID1; uint8_t pucMsg[MAX_APP_PAYLOAD], ucLen, ucLtid; unsigned long ulCount; smplStatus_t eRetcode; // // Tell the user what we're doing. // UpdateStatus(false, "Listening for link..."); // // Keep the compiler happy. // eRetcode = SMPL_TIMEOUT; // // Turn on LED 1 to indicate that we are listening. // SetLED(1, true); // // Listen for link for 10 seconds or so. This logic may fail if you // happen to have sat around for about 13.6 years between starting the // example and pressing the mode selection button. I suspect I will be // forgiven for this. // ulCount = g_ulSysTickCount + (LINK_TIMEOUT_SECONDS * TICKS_PER_SECOND); while (ulCount > g_ulSysTickCount) { // // Process our message queue to keep the widget library happy. // WidgetMessageQueueProcess(); // // Listen for a link. This call takes quite some time to return. // eRetcode = SMPL_LinkListen(&linkID1); // // Was the link successful? // if (SMPL_SUCCESS == eRetcode) { // // Yes - drop out of the loop. // break; } } // // Did we link successfully? // if(eRetcode != SMPL_SUCCESS) { // // No - Tell the user what happened and return an error. // UpdateStatus(false, "Failed to link!"); return(false); } // // Turn off LED 1 to indicate that our listen succeeded. // UpdateStatus(false, "Link succeeded."); SetLED(1, false); // // Clear our message counter. // ulCount = 0; // // Enter an infinite loop polling for messages. // while (1) { // // Turn the radio off and pretend to sleep for a second or so. // SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SLEEP, 0); SPIN_ABOUT_A_SECOND; /* emulate MCU sleeping */ // // Turn the radio back on again. // SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, 0); // // Were any messages "received"? // // The receive call results in polling the Access Point. The success // case occurs when a payload is actually returned. When there is no // frame waiting for the device a frame with no payload is returned by // the Access Point. Note that this loop will retrieve any and all // frames that are waiting for this device on the specified link ID. // This call will also return frames that were received directly. It // is possible to get frames that were repeated either from the initial // transmission from the peer or via a Range Extender. This is why we // implement the TID check. // do { // // Receive whatever the AP has for us. // eRetcode = SMPL_Receive(linkID1, pucMsg, &ucLen); // // Did we get a real frame? // if((eRetcode == SMPL_SUCCESS) && ucLen) { // // Tell the user what's going on. // UpdateStatus(false, "Received msg %d", ++ulCount); // // Process our message queue to keep the widget library happy. // WidgetMessageQueueProcess(); // // Check the application sequence number to detect late or missing // frames. // ucLtid = *(pucMsg+1); if (ucLtid) { // // If the current TID is non-zero and the last one we saw was // less than this one assume we've received the 'next' one. // if (g_ucTid < ucLtid) { // // 'Next' frame. We may have missed some but we don't // care. // if ((*pucMsg == 1) || (*pucMsg == 2)) { // // We're good. Toggle the requested LED. // ToggleLED(*pucMsg); } // // Remember the last TID. // g_ucTid = ucLtid; } // // If current TID is non-zero and less than or equal to the last // one we saw assume we received a duplicate. Just ignore it. // } else { // // Current TID is zero so the count wrapped or we just started. // Let's just accept it and start over. // if ((*pucMsg == 1) || (*pucMsg == 2)) { // // We're good. Toggle the requested LED. // ToggleLED(*pucMsg); } // // Remember the last TID. // g_ucTid = ucLtid; } } } while ((eRetcode == SMPL_SUCCESS) & ucLen); } }
//***************************************************************************** // // Read the ulIndex-th JPEG image and pass it to the JPEG canvas widget for // decompression. If bPaint is true, repaint the widget to show the new image // or the error information string. // //***************************************************************************** static tBoolean ImageViewerGetImage(unsigned long ulIndex, tBoolean bPaint) { tBoolean bRetcode; unsigned long ulLen, ulError; char *pcName; unsigned char *pucData; // // Get a pointer to the file data and its length. // bRetcode = FileGetJPEGFileInfo(ulIndex, &pcName, &ulLen, &pucData); // // Did we get the file information successfully? // if(bRetcode) { // // If we have been asked to paint the image, display text on top of // the existing image indicating that decompression is going on. // if(bPaint) { JPEGWidgetTextSet(&g_sMainImage, "Decompressing..."); WidgetPaint((tWidget *)&g_sMainImage); WidgetMessageQueueProcess(); } // // We got the file information so now pass it to the JPEG canvas // widget to have it decompressed. // ulError = JPEGWidgetImageSet((tWidget *)&g_sMainImage, pucData, ulLen); // // Did the decompression go as planned? // if(ulError) { // // No - something went wrong. Set an error message. // JPEGWidgetTextSet(&g_sMainImage, "Decompression Error!"); bRetcode = false; } else { // // The image was decompressed successfully so remove any error // string that the control may have been displaying. // JPEGWidgetTextSet(&g_sMainImage, ""); } } // // If we have been asked to repaint the widget, do so. // if(bPaint) { WidgetPaint((tWidget *)&g_sMainImage); } // // Tell the caller how things went. // return(bRetcode); }
//***************************************************************************** // // Main application entry function. // //***************************************************************************** int main(void) { tBoolean bSuccess, bRetcode; unsigned char pucMsg[2]; unsigned char ucTid; unsigned char ucDelay; unsigned long ulLastRxCount, ulLastTxCount; smplStatus_t eRetcode; // // Set the system clock to run at 50MHz from the PLL // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // NB: We don't call PinoutSet() in this testcase since the EM header // expansion board doesn't currently have an I2C ID EEPROM. If we did // call PinoutSet() this would configure all the EPI pins for SDRAM and // we don't want to do this. // g_eDaughterType = DAUGHTER_NONE; // // Enable peripherals required to drive the LCD. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH); // // Configure SysTick for a 10Hz interrupt. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Initialize the display driver. // Kitronix320x240x16_SSD2119Init(); // // Initialize the touch screen driver. // TouchScreenInit(); // // Set the touch screen event handler. // TouchScreenCallbackSet(WidgetPointerMessage); // // Add the compile-time defined widgets to the widget tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sHeading); // // Initialize the status string. // UpdateStatus(true, "Please choose the operating mode."); // // Paint the widget tree to make sure they all appear on the display. // WidgetPaint(WIDGET_ROOT); // // Initialize the SimpliciTI BSP. // BSP_Init(); // // Set the SimpliciTI device address using the current Ethernet MAC address // to ensure something like uniqueness. // bRetcode = SetSimpliciTIAddress(); if(!bRetcode) { // // The board does not have a MAC address configured so we can't set // the SimpliciTI device address (which we derive from the MAC address). // while(1); } // // Initialize the SimpliciTI stack and supply our receive callback // function pointer. // SMPL_Init(RxCallback); // // Initialize our message ID, initial inter-message delay and packet // counters. // ucTid = 0; ucDelay = 0; ulLastRxCount = 0; ulLastTxCount = 0; // // Fall into the command line processing loop. // while (1) { // // Process any messages from or for the widgets. // WidgetMessageQueueProcess(); // // Check to see if we've been told to do anything. // if(g_ulCommandFlags) { // // Has the mode been set? If so, set up the display to show the // "LEDs" and then start communication. // if(HWREGBITW(&g_ulCommandFlags, COMMAND_MODE_SET)) { // // Clear the bit now that we have seen it. // HWREGBITW(&g_ulCommandFlags, COMMAND_MODE_SET) = 0; // // Remove the buttons and replace them with the LEDs then // repaint the display. // WidgetRemove((tWidget *)&g_sBtnContainer); WidgetAdd((tWidget *)&g_sBackground, (tWidget *)&g_sLEDContainer); WidgetPaint((tWidget *)&g_sBackground); // // Now call the function that initiates communication in // the desired mode. Note that these functions will not return // until communication is established or an error occurs. // if(g_ulMode == MODE_TALKER) { bSuccess = LinkTo(); } else { bSuccess = LinkFrom(); } // // If we were unsuccessfull, go back to the mode selection // display. // if(!bSuccess) { // // Remove the LEDs and show the buttons again. // WidgetRemove((tWidget *)&g_sLEDContainer); WidgetAdd((tWidget *)&g_sBackground, (tWidget *)&g_sBtnContainer); WidgetPaint((tWidget *)&g_sBackground); // // Tell the user what happened. // UpdateStatus(false, "Error establishing communication!"); UpdateStatus(true, "Please choose the operating mode."); // // Remember that we don't have an operating mode chosen. // g_ulMode = MODE_UNDEFINED; } } // // Have we been asked to toggle the first "LED"? // if(HWREGBITW(&g_ulCommandFlags, COMMAND_LED1_TOGGLE)) { // // Clear the bit now that we have seen it. // HWREGBITW(&g_ulCommandFlags, COMMAND_LED1_TOGGLE) = 0; // // Toggle the LED. // ToggleLED(1); } // // Have we been asked to toggle the second "LED"? // if(HWREGBITW(&g_ulCommandFlags, COMMAND_LED2_TOGGLE)) { // // Clear the bit now that we have seen it. // HWREGBITW(&g_ulCommandFlags, COMMAND_LED2_TOGGLE) = 0; // // Toggle the LED. // ToggleLED(2); } // // Have we been asked to send a packet back to our peer? This // command is only ever sent to the main loop when we are running // in listener mode (LinkListen). // if(HWREGBITW(&g_ulCommandFlags, COMMAND_SEND_REPLY)) { // // Clear the bit now that we have seen it. // HWREGBITW(&g_ulCommandFlags, COMMAND_SEND_REPLY) = 0; // // Create the message. The first byte tells the receiver to // toggle LED1 and the second is a sequence counter. // pucMsg[0] = 1; pucMsg[1] = ++ucTid; eRetcode = SMPL_Send(sLinkID, pucMsg, 2); // // Update our transmit counter if we transmitted the packet // successfully. // if(eRetcode == SMPL_SUCCESS) { g_ulTxCount++; } else { UpdateStatus(false, "TX error %s (%d)", MapSMPLStatus(eRetcode), eRetcode); } } } // // If we are the talker (LinkTo mode), check to see if it's time to // send another packet to our peer. // if((g_ulMode == MODE_TALKER) && (g_ulSysTickCount >= g_ulNextPacketTick)) { // // Create the message. The first byte tells the receiver to // toggle LED1 and the second is a sequence counter. // pucMsg[0] = 1; pucMsg[1] = ++ucTid; eRetcode = SMPL_Send(sLinkID, pucMsg, 2); // // Update our transmit counter if we transmitted the packet // correctly. // if(eRetcode == SMPL_SUCCESS) { g_ulTxCount++; } else { UpdateStatus(false, "TX error %s (%d)", MapSMPLStatus(eRetcode), eRetcode); } // // Set the delay before the next message. // #ifndef USE_2_SECOND_DELAY // // Set the delay before the next message. We increase this from 1 // second to 4 seconds then cycle back to 1. // ucDelay = (ucDelay == 4) ? 1 : (ucDelay + 1); #else // // Wait 2 seconds before sending the next message. // ucDelay = 2; #endif // // Calculate the system tick count when our delay has completed. // This algorithm will generate a spurious packet every 13.7 years // since I don't handle the rollover case in the comparison above // but I'm pretty sure you will forgive me for this oversight. // g_ulNextPacketTick = g_ulSysTickCount + (TICKS_PER_SECOND * ucDelay); } // // If either the transmit or receive packet count changed, update // the status on the display. // if((g_ulRxCount != ulLastRxCount) || (g_ulTxCount != ulLastTxCount)) { ulLastTxCount = g_ulTxCount; ulLastRxCount = g_ulRxCount; UpdateStatus(false, "Received %d pkts, sent %d (%d)", ulLastRxCount, ulLastTxCount); } } }
//***************************************************************************** // // 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; } } }
//***************************************************************************** // // Main application entry function. // //***************************************************************************** int main(void) { tBoolean bRetcode; smplStatus_t eRetcode; ioctlScanChan_t sScan; freqEntry_t pFreq[NWK_FREQ_TBL_SIZE]; tBoolean bFirstTimeThrough; unsigned long ulLoop; uint8_t ucLast; // // Set the system clock to run at 50MHz from the PLL // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // NB: We don't call PinoutSet() in this testcase since the EM header // expansion board doesn't currently have an I2C ID EEPROM. If we did // call PinoutSet() this would configure all the EPI pins for SDRAM and // we don't want to do this. // g_eDaughterType = DAUGHTER_NONE; // // Enable peripherals required to drive the LCD. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH); // // Configure SysTick for a 10Hz interrupt. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Initialize the display driver. // Kitronix320x240x16_SSD2119Init(); // // Initialize the touch screen driver. // TouchScreenInit(); // // Set the touch screen event handler. // TouchScreenCallbackSet(WidgetPointerMessage); // // Add the compile-time defined widgets to the widget tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sHeading); // // Initialize the status string. // UpdateStatus("Initializing..."); // // Paint the widget tree to make sure they all appear on the display. // WidgetPaint(WIDGET_ROOT); // // Initialize the SimpliciTI BSP. // BSP_Init(); // // Set the SimpliciTI device address using the current Ethernet MAC address // to ensure something like uniqueness. // bRetcode = SetSimpliciTIAddress(); // // Did we have a problem with the address? // if(!bRetcode) { // // Yes - make sure the display is updated then hang the app. // WidgetMessageQueueProcess(); while(1) { // // MAC address is not set so hang the app. // } } // // Turn on both our LEDs // SetLED(1, true); SetLED(2, true); UpdateStatus("Joining network..."); // // Initialize the SimpliciTI stack but don't set any receive callback. // while(1) { eRetcode = SMPL_Init((uint8_t (*)(linkID_t))0); if(eRetcode == SMPL_SUCCESS) { break; } ToggleLED(1); ToggleLED(2); SPIN_ABOUT_A_SECOND; } // // Tell the user what's up. // UpdateStatus("Sniffing..."); // // Set up for our first sniff. // sScan.freq = pFreq; bFirstTimeThrough = true; ucLast = 0xFF; // // Keep sniffing forever. // while (1) { // // Wait a while. // SPIN_ABOUT_A_QUARTER_SECOND; // // Scan for the active channel. // SMPL_Ioctl(IOCTL_OBJ_FREQ, IOCTL_ACT_SCAN, &sScan); // // Did we find a signal? // if (1 == sScan.numChan) { if (bFirstTimeThrough) { // // Set the initial LED state. // SetLED(1, false); SetLED(2, true); // // Wait a while. // for(ulLoop = 0; ulLoop < 15; ulLoop--) { // // Toggle both LEDs and wait a bit. // ToggleLED(1); ToggleLED(2); SPIN_ABOUT_A_QUARTER_SECOND; } bFirstTimeThrough = false; } // // Has the channel changed since the last time we updated the // display? // if(pFreq[0].logicalChan != ucLast) { // // Remember the channel we just detected. // ucLast = pFreq[0].logicalChan; // // Tell the user which channel we found to be active. // UpdateStatus("Active channel is %d.", pFreq[0].logicalChan); // // Set the "LEDs" to mimic the behavior of the MSP430 versions // of this application. // switch(pFreq[0].logicalChan) { case 0: { /* GREEN OFF */ /* RED OFF */ SetLED(1, false); SetLED(2, false); break; } case 1: { /* GREEN OFF */ /* RED ON */ SetLED(1, false); SetLED(2, true); break; } case 2: { /* GREEN ON */ /* RED OFF */ SetLED(1, true); SetLED(2, false); break; } case 3: { /* GREEN ON */ /* RED ON */ SetLED(1, true); SetLED(2, true); break; } case 4: { /* blink them both... */ SetLED(1, false); SetLED(2, false); SPIN_ABOUT_A_QUARTER_SECOND; SetLED(1, true); SetLED(2, true); SPIN_ABOUT_A_QUARTER_SECOND; SetLED(1, false); SetLED(2, false); } } } } } }
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(); } }
//***************************************************************************** // // Main application entry function. // //***************************************************************************** int main(void) { tBoolean bRetcode; // // Set the system clock to run at 50MHz from the PLL // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // NB: We don't call PinoutSet() in this testcase since the EM header // expansion board doesn't currently have an I2C ID EEPROM. If we did // call PinoutSet() this would configure all the EPI pins for SDRAM and // we don't want to do this. // g_eDaughterType = DAUGHTER_NONE; // // Enable peripherals required to drive the LCD. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH); // // Configure SysTick for a 10Hz interrupt. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Initialize the display driver. // Kitronix320x240x16_SSD2119Init(); // // Initialize the touch screen driver. // TouchScreenInit(); // // Set the touch screen event handler. // TouchScreenCallbackSet(WidgetPointerMessage); // // Add the compile-time defined widgets to the widget tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sHeading); // // Initialize the status string. // UpdateStatus(true, "Monitoring..."); // // Paint the widget tree to make sure they all appear on the display. // WidgetPaint(WIDGET_ROOT); // // Initialize the SimpliciTI BSP. // BSP_Init(); // // Set the SimpliciTI device address using the current Ethernet MAC address // to ensure something like uniqueness. // bRetcode = SetSimpliciTIAddress(); // // Did we have a problem with the address? // if(!bRetcode) { // // Yes - make sure the display is updated then hang the app. // WidgetMessageQueueProcess(); while(1) { // // MAC address is not set so hang the app. // } } // // Initialize the SimpliciTI stack but don't set any receive callback. // SMPL_Init(0); // // Start monitoring for alert messages from other devices. This function // doesn't return. // MonitorForBadNews(); }
//***************************************************************************** // // 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) { } }
//***************************************************************************** // // Initialize and operate the data logger. // //***************************************************************************** int main(void) { tContext sDisplayContext, sBufferContext; uint32_t ui32HibIntStatus, ui32SysClock, ui32LastTickCount; bool bSkipSplash; uint8_t ui8ButtonState, ui8ButtonChanged; uint_fast8_t ui8X, ui8Y; // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // MAP_FPULazyStackingEnable(); // // Set the clocking to run at 50 MHz. // MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); ui32SysClock = MAP_SysCtlClockGet(); // // Initialize locals. // bSkipSplash = false; ui32LastTickCount = 0; // // Initialize the data acquisition module. This initializes the ADC // hardware. // AcquireInit(); // // Enable access to the hibernate peripheral. If the hibernate peripheral // was already running then this will have no effect. // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE); // // Check to see if the hiberate module is already active and if so then // read the saved configuration state. If both are okay, then proceed // to check and see if we are logging data using sleep mode. // if(HibernateIsActive() && !GetSavedState(&g_sConfigState)) { // // Read the status of the hibernate module. // ui32HibIntStatus = HibernateIntStatus(1); // // If this is a pin wake, that means the user pressed the select // button and we should terminate the sleep logging. In this case // we will fall out of this conditional section, and go through the // normal startup below, but skipping the splash screen so the user // gets immediate response. // if(ui32HibIntStatus & HIBERNATE_INT_PIN_WAKE) { // // Clear the interrupt flag so it is not seen again until another // wake. // HibernateIntClear(HIBERNATE_INT_PIN_WAKE); bSkipSplash = true; } // // Otherwise if we are waking from hibernate and it was not a pin // wake, then it must be from RTC match. Check to see if we are // sleep logging and if so then go through an abbreviated startup // in order to collect the data and go back to sleep. // else if(g_sConfigState.ui32SleepLogging && (ui32HibIntStatus & HIBERNATE_INT_RTC_MATCH_0)) { // // Start logger and pass the configuration. The logger should // configure itself to take one sample. // AcquireStart(&g_sConfigState); g_iLoggerState = eSTATE_LOGGING; // // Enter a forever loop to run the acquisition. This will run // until a new sample has been taken and stored. // while(!AcquireRun()) { } // // Getting here means that a data acquisition was performed and we // can now go back to sleep. Save the configuration and then // activate the hibernate. // SetSavedState(&g_sConfigState); // // Set wake condition on pin-wake or RTC match. Then put the // processor in hibernation. // HibernateWakeSet(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC); HibernateRequest(); // // Hibernating takes a finite amount of time to occur, so wait // here forever until hibernate activates and the processor // power is removed. // for(;;) { } } // // Otherwise, this was not a pin wake, and we were not sleep logging, // so just fall out of this conditional and go through the normal // startup below. // } else { // // In this case, either the hibernate module was not already active, or // the saved configuration was not valid. Initialize the configuration // to the default state and then go through the normal startup below. // GetDefaultState(&g_sConfigState); } // // Enable the Hibernate module to run. // HibernateEnableExpClk(SysCtlClockGet()); // // The hibernate peripheral trim register must be set per silicon // erratum 2.1 // HibernateRTCTrimSet(0x7FFF); // // Start the RTC running. If it was already running then this will have // no effect. // HibernateRTCEnable(); // // In case we were sleep logging and are now finished (due to user // pressing select button), then disable sleep logging so it doesnt // try to start up again. // g_sConfigState.ui32SleepLogging = 0; SetSavedState(&g_sConfigState); // // Initialize the display driver. // CFAL96x64x16Init(); // // Initialize the buttons driver. // ButtonsInit(); // // Pass the restored state to the menu system. // MenuSetState(&g_sConfigState); // // Enable the USB peripheral // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); // // Configure the required pins for USB operation. // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); MAP_GPIOPinConfigure(GPIO_PG4_USB0EPEN); MAP_GPIOPinTypeUSBDigital(GPIO_PORTG_BASE, GPIO_PIN_4); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL); MAP_GPIOPinTypeUSBAnalog(GPIO_PORTL_BASE, GPIO_PIN_6 | GPIO_PIN_7); MAP_GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Erratum workaround for silicon revision A1. VBUS must have pull-down. // if(CLASS_IS_BLIZZARD && REVISION_IS_A1) { HWREG(GPIO_PORTB_BASE + GPIO_O_PDR) |= GPIO_PIN_1; } // // Initialize the USB stack mode and pass in a mode callback. // USBStackModeSet(0, eUSBModeOTG, ModeCallback); // // Initialize the stack to be used with USB stick. // USBStickInit(); // // Initialize the stack to be used as a serial device. // USBSerialInit(); // // Initialize the USB controller for dual mode operation with a 2ms polling // rate. // USBOTGModeInit(0, 2000, g_pui8HCDPool, HCD_MEMORY_SIZE); // // Initialize the menus module. This module will control the user // interface menuing system. // MenuInit(WidgetActivated); // // Configure SysTick to periodically interrupt. // g_ui32TickCount = 0; MAP_SysTickPeriodSet(ui32SysClock / CLOCK_RATE); MAP_SysTickIntEnable(); MAP_SysTickEnable(); // // Initialize the display context and another context that is used // as an offscreen drawing buffer for display animation effect // GrContextInit(&sDisplayContext, &g_sCFAL96x64x16); GrContextInit(&sBufferContext, &g_sOffscreenDisplayA); // // Show the splash screen if we are not skipping it. The only reason to // skip it is if the application was in sleep-logging mode and the user // just waked it up with the select button. // if(!bSkipSplash) { const uint8_t *pui8SplashLogo = g_pui8Image_TI_Black; // // Draw the TI logo on the display. Use an animation effect where the // logo will "slide" onto the screen. Allow select button to break // out of animation. // for(ui8X = 0; ui8X < 96; ui8X++) { if(ButtonsPoll(0, 0) & SELECT_BUTTON) { break; } GrImageDraw(&sDisplayContext, pui8SplashLogo, 95 - ui8X, 0); } // // Leave the logo on the screen for a long duration. Monitor the // buttons so that if the user presses the select button, the logo // display is terminated and the application starts immediately. // while(g_ui32TickCount < 400) { if(ButtonsPoll(0, 0) & SELECT_BUTTON) { break; } } // // Extended splash sequence // if(ButtonsPoll(0, 0) & UP_BUTTON) { for(ui8X = 0; ui8X < 96; ui8X += 4) { GrImageDraw(&sDisplayContext, g_ppui8Image_Splash[(ui8X / 4) & 3], (int32_t)ui8X - 96L, 0); GrImageDraw(&sDisplayContext, pui8SplashLogo, ui8X, 0); MAP_SysCtlDelay(ui32SysClock / 12); } MAP_SysCtlDelay(ui32SysClock / 3); pui8SplashLogo = g_ppui8Image_Splash[4]; GrImageDraw(&sDisplayContext, pui8SplashLogo, 0, 0); MAP_SysCtlDelay(ui32SysClock / 12); } // // Draw the initial menu into the offscreen buffer. // SlideMenuDraw(&g_sMenuWidget, &sBufferContext, 0); // // Now, draw both the TI logo splash screen (from above) and the initial // menu on the screen at the same time, moving the coordinates so that // the logo "slides" off the display and the menu "slides" onto the // display. // for(ui8Y = 0; ui8Y < 64; ui8Y++) { GrImageDraw(&sDisplayContext, pui8SplashLogo, 0, -ui8Y); GrImageDraw(&sDisplayContext, g_pui8OffscreenBufA, 0, 63 - ui8Y); } } // // Add the menu widget to the widget tree and send an initial paint // request. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sMenuWidget); WidgetPaint(WIDGET_ROOT); // // Set the focus handle to the menu widget. Any button events will be // sent to this widget // g_ui32KeyFocusWidgetHandle = (uint32_t)&g_sMenuWidget; // // Forever loop to run the application // while(1) { // // Each time the timer tick occurs, process any button events. // if(g_ui32TickCount != ui32LastTickCount) { // // Remember last tick count // ui32LastTickCount = g_ui32TickCount; // // Read the debounced state of the buttons. // ui8ButtonState = ButtonsPoll(&ui8ButtonChanged, 0); // // Pass any button presses through to the widget message // processing mechanism. The widget that has the button event // focus (probably the menu widget) will catch these button events. // if(BUTTON_PRESSED(SELECT_BUTTON, ui8ButtonState, ui8ButtonChanged)) { SendWidgetKeyMessage(WIDGET_MSG_KEY_SELECT); } if(BUTTON_PRESSED(UP_BUTTON, ui8ButtonState, ui8ButtonChanged)) { SendWidgetKeyMessage(WIDGET_MSG_KEY_UP); } if(BUTTON_PRESSED(DOWN_BUTTON, ui8ButtonState, ui8ButtonChanged)) { SendWidgetKeyMessage(WIDGET_MSG_KEY_DOWN); } if(BUTTON_PRESSED(LEFT_BUTTON, ui8ButtonState, ui8ButtonChanged)) { SendWidgetKeyMessage(WIDGET_MSG_KEY_LEFT); } if(BUTTON_PRESSED(RIGHT_BUTTON, ui8ButtonState, ui8ButtonChanged)) { SendWidgetKeyMessage(WIDGET_MSG_KEY_RIGHT); } } // // Tell the OTG library code how much time has passed in milliseconds // since the last call. // USBOTGMain(GetTickms()); // // Call functions as needed to keep the host or device mode running. // if(g_iCurrentUSBMode == eUSBModeDevice) { USBSerialRun(); } else if(g_iCurrentUSBMode == eUSBModeHost) { USBStickRun(); } // // If in the logging state, then call the logger run function. This // keeps the data acquisition running. // if((g_iLoggerState == eSTATE_LOGGING) || (g_iLoggerState == eSTATE_VIEWING)) { if(AcquireRun() && g_sConfigState.ui32SleepLogging) { // // If sleep logging is enabled, then at this point we have // stored the first data item, now save the state and start // hibernation. Wait for the power to be cut. // SetSavedState(&g_sConfigState); HibernateWakeSet(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC); HibernateRequest(); for(;;) { } } // // If viewing instead of logging then request a repaint to keep // the viewing window updated. // if(g_iLoggerState == eSTATE_VIEWING) { WidgetPaint(WIDGET_ROOT); } } // // If in the saving state, then save data from flash storage to // USB stick. // if(g_iLoggerState == eSTATE_SAVING) { // // Save data from flash to USB // FlashStoreSave(); // // Return to idle state // g_iLoggerState = eSTATE_IDLE; } // // If in the erasing state, then erase the data stored in flash. // if(g_iLoggerState == eSTATE_ERASING) { // // Save data from flash to USB // FlashStoreErase(); // // Return to idle state // g_iLoggerState = eSTATE_IDLE; } // // If in the flash reporting state, then show the report of the amount // of used and free flash memory. // if(g_iLoggerState == eSTATE_FREEFLASH) { // // Report free flash space // FlashStoreReport(); // // Return to idle state // g_iLoggerState = eSTATE_IDLE; } // // If we are exiting the clock setting widget, that means that control // needs to be given back to the menu system. // if(g_iLoggerState == eSTATE_CLOCKEXIT) { // // Give the button event focus back to the menu system // g_ui32KeyFocusWidgetHandle = (uint32_t)&g_sMenuWidget; // // Send a button event to the menu widget that means the left // key was pressed. This signals the menu widget to deactivate // the current child widget (which was the clock setting wigdet). // This will cause the menu widget to slide the clock set widget // off the screen and resume control of the display. // SendWidgetKeyMessage(WIDGET_MSG_KEY_LEFT); g_iLoggerState = eSTATE_IDLE; } // // Process any new messages that are in the widget queue. This keeps // the user interface running. // WidgetMessageQueueProcess(); } }
//***************************************************************************** // // The program main function. It performs initialization, then runs a loop to // process USB activities and operate the user interface. // //***************************************************************************** int main(void) { uint32_t ui32DriveTimeout; // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPULazyStackingEnable(); // // Set the system clock to run at 50MHz from the PLL. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Configure the required pins for USB operation. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); ROM_GPIOPinConfigure(GPIO_PG4_USB0EPEN); ROM_GPIOPinTypeUSBDigital(GPIO_PORTG_BASE, GPIO_PIN_4); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTL_BASE, GPIO_PIN_6 | GPIO_PIN_7); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Configure SysTick for a 100Hz interrupt. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Enable the uDMA controller and set up the control table base. // The uDMA controller is used by the USB library. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); ROM_uDMAEnable(); ROM_uDMAControlBaseSet(g_psDMAControlTable); // // Enable Interrupts // ROM_IntMasterEnable(); // // Initialize the display driver. // CFAL96x64x16Init(); // // Initialize the buttons driver. // ButtonsInit(); // // Initialize two offscreen displays and assign the palette. These // buffers are used by the slide menu widget to allow animation effects. // GrOffScreen4BPPInit(&g_sOffscreenDisplayA, g_pui8OffscreenBufA, 96, 64); GrOffScreen4BPPPaletteSet(&g_sOffscreenDisplayA, g_pui32Palette, 0, NUM_PALETTE_ENTRIES); GrOffScreen4BPPInit(&g_sOffscreenDisplayB, g_pui8OffscreenBufB, 96, 64); GrOffScreen4BPPPaletteSet(&g_sOffscreenDisplayB, g_pui32Palette, 0, NUM_PALETTE_ENTRIES); // // Show an initial status screen // g_pcStatusLines[0] = "Waiting"; g_pcStatusLines[1] = "for device"; ShowStatusScreen(g_pcStatusLines, 2); // // Add the compile-time defined widgets to the widget tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sFileMenuWidget); // // Initially wait for device connection. // g_eState = STATE_NO_DEVICE; // // Initialize the USB stack for host mode. // USBStackModeSet(0, eUSBModeHost, 0); // // Register the host class drivers. // USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ui32NumHostClassDrivers); // // Open an instance of the mass storage class driver. // g_psMSCInstance = USBHMSCDriveOpen(0, MSCCallback); // // Initialize the drive timeout. // ui32DriveTimeout = USBMSC_DRIVE_RETRY; // // Initialize the power configuration. This sets the power enable signal // to be active high and does not enable the power fault. // USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER); // // Initialize the USB controller for host operation. // USBHCDInit(0, g_pui8HCDPool, HCD_MEMORY_SIZE); // // Initialize the file system. // FileInit(); // // Enter an infinite loop to run the user interface and process USB // events. // while(1) { uint32_t ui32LastTickCount = 0; // // Call the USB stack to keep it running. // USBHCDMain(); // // Process any messages in the widget message queue. This keeps the // display UI running. // WidgetMessageQueueProcess(); // // Take action based on the application state. // switch(g_eState) { // // A device has enumerated. // case STATE_DEVICE_ENUM: { // // Check to see if the device is ready. If not then stay // in this state and we will check it again on the next pass. // if(USBHMSCDriveReady(g_psMSCInstance) != 0) { // // Wait about 500ms before attempting to check if the // device is ready again. // ROM_SysCtlDelay(ROM_SysCtlClockGet()/(3)); // // Decrement the retry count. // ui32DriveTimeout--; // // If the timeout is hit then go to the // STATE_TIMEOUT_DEVICE state. // if(ui32DriveTimeout == 0) { g_eState = STATE_TIMEOUT_DEVICE; } break; } // // Getting here means the device is ready. // Reset the CWD to the root directory. // g_pcCwdBuf[0] = '/'; g_pcCwdBuf[1] = 0; // // Set the initial directory level to the root // g_ui32Level = 0; // // We need to reset the indexes of the root menu to 0, so that // it will start at the top of the file list, and reset the // slide menu widget to start with the root menu. // g_psFileMenus[g_ui32Level].ui32CenterIndex = 0; g_psFileMenus[g_ui32Level].ui32FocusIndex = 0; SlideMenuMenuSet(&g_sFileMenuWidget, &g_psFileMenus[g_ui32Level]); // // Initiate a directory change to the root. This will // populate a menu structure representing the root directory. // if(ProcessDirChange("/", g_ui32Level)) { // // If there were no errors reported, we are ready for // MSC operation. // g_eState = STATE_DEVICE_READY; // // Set the Device Present flag. // g_ui32Flags = FLAGS_DEVICE_PRESENT; // // Request a repaint so the file menu will be shown // WidgetPaint(WIDGET_ROOT); } break; } // // If there is no device then just wait for one. // case STATE_NO_DEVICE: { if(g_ui32Flags == FLAGS_DEVICE_PRESENT) { // // Show waiting message on screen // g_pcStatusLines[0] = "Waiting"; g_pcStatusLines[1] = "for device"; ShowStatusScreen(g_pcStatusLines, 2); // // Clear the Device Present flag. // g_ui32Flags &= ~FLAGS_DEVICE_PRESENT; } break; } // // An unknown device was connected. // case STATE_UNKNOWN_DEVICE: { // // If this is a new device then change the status. // if((g_ui32Flags & FLAGS_DEVICE_PRESENT) == 0) { // // Clear the screen and indicate that an unknown device // is present. // g_pcStatusLines[0] = "Unknown"; g_pcStatusLines[1] = "device"; ShowStatusScreen(g_pcStatusLines, 2); } // // Set the Device Present flag. // g_ui32Flags = FLAGS_DEVICE_PRESENT; break; } // // The connected mass storage device is not reporting ready. // case STATE_TIMEOUT_DEVICE: { // // If this is the first time in this state then print a // message. // if((g_ui32Flags & FLAGS_DEVICE_PRESENT) == 0) { // // // Clear the screen and indicate that an unknown device // is present. // g_pcStatusLines[0] = "Device"; g_pcStatusLines[1] = "Timeout"; ShowStatusScreen(g_pcStatusLines, 2); } // // Set the Device Present flag. // g_ui32Flags = FLAGS_DEVICE_PRESENT; break; } // // The device is ready and in use. // case STATE_DEVICE_READY: { // // Process occurrence of timer tick. Check for user input // once each tick. // if(g_ui32SysTickCount != ui32LastTickCount) { uint8_t ui8ButtonState; uint8_t ui8ButtonChanged; ui32LastTickCount = g_ui32SysTickCount; // // Get the current debounced state of the buttons. // ui8ButtonState = ButtonsPoll(&ui8ButtonChanged, 0); // // If select button or right button is pressed, then we // are trying to descend into another directory // if(BUTTON_PRESSED(SELECT_BUTTON, ui8ButtonState, ui8ButtonChanged) || BUTTON_PRESSED(RIGHT_BUTTON, ui8ButtonState, ui8ButtonChanged)) { uint32_t ui32NewLevel; uint32_t ui32ItemIdx; char *pcItemName; // // Get a pointer to the current menu for this CWD. // tSlideMenu *psMenu = &g_psFileMenus[g_ui32Level]; // // Get the highlighted index in the current file list. // This is the currently highlighted file or dir // on the display. Then get the name of the file at // this index. // ui32ItemIdx = SlideMenuFocusItemGet(psMenu); pcItemName = psMenu->psSlideMenuItems[ui32ItemIdx].pcText; // // Make sure we are not yet past the maximum tree // depth. // if(g_ui32Level < MAX_SUBDIR_DEPTH) { // // Potential new level is one greater than the // current level. // ui32NewLevel = g_ui32Level + 1; // // Process the directory change to the new // directory. This function will populate a menu // structure with the files and subdirs in the new // directory. // if(ProcessDirChange(pcItemName, ui32NewLevel)) { // // If the change was successful, then update // the level. // g_ui32Level = ui32NewLevel; // // Now that all the prep is done, send the // KEY_RIGHT message to the widget and it will // "slide" from the previous file list to the // new file list of the CWD. // SendWidgetKeyMessage(WIDGET_MSG_KEY_RIGHT); } } } // // If the UP button is pressed, just pass it to the widget // which will handle scrolling the list of files. // if(BUTTON_PRESSED(UP_BUTTON, ui8ButtonState, ui8ButtonChanged)) { SendWidgetKeyMessage(WIDGET_MSG_KEY_UP); } // // If the DOWN button is pressed, just pass it to the widget // which will handle scrolling the list of files. // if(BUTTON_PRESSED(DOWN_BUTTON, ui8ButtonState, ui8ButtonChanged)) { SendWidgetKeyMessage(WIDGET_MSG_KEY_DOWN); } // // If the LEFT button is pressed, then we are attempting // to go up a level in the file system. // if(BUTTON_PRESSED(LEFT_BUTTON, ui8ButtonState, ui8ButtonChanged)) { uint32_t ui32NewLevel; // // Make sure we are not already at the top of the // directory tree (at root). // if(g_ui32Level) { // // Potential new level is one less than the // current level. // ui32NewLevel = g_ui32Level - 1; // // Process the directory change to the new // directory. This function will populate a menu // structure with the files and subdirs in the new // directory. // if(ProcessDirChange("..", ui32NewLevel)) { // // If the change was successful, then update // the level. // g_ui32Level = ui32NewLevel; // // Now that all the prep is done, send the // KEY_LEFT message to the widget and it will // "slide" from the previous file list to the // new file list of the CWD. // SendWidgetKeyMessage(WIDGET_MSG_KEY_LEFT); } } } } break; } // // Something has caused a power fault. // case STATE_POWER_FAULT: { // // Clear the screen and show a power fault indication. // g_pcStatusLines[0] = "Power"; g_pcStatusLines[1] = "fault"; ShowStatusScreen(g_pcStatusLines, 2); break; } default: { break; } } } }