/*================================< DEMO.c >==================================*/ // // Title: DEMO 1 PROGRAM // Written by: JAG // Project: RIZE RMS102 MICROCOMPUTER // Target : Freescale i.MXL // Platform : RMS102 Rev A // Copyright: Subject to the Revely Source Code License (see license.txt) // // DEMO demonstrates the capabilities of the RIZE RMS102 Microcomputer // Text commands can be entered to evaluate various hardware and software // capabilities. // // Configured builds: // - ARM RAM/Flash Debug/Release // /*============================================================================*/ #include "stddefs.h" #include "rlib.h" #include "rgraph.h" #include "targets/MC9328MXL.h" #include /*----------------------------------< Defines >-------------------------------*/ #define CMD_END 255 // Create a 'pointer to command function' type typedef void (*CMDFUNCPTR)(void); /*--------------------------------< Prototypes >------------------------------*/ // Command functions void TestSound(void); void ShowAbout(void); void ShowHelp(void); void ClearMainWindow(void); void LedTest(void); void Sketch(void); void TestSDCard(void); void TestTV(void); void CompactFlashTest(void); void SerialPortTest(void); void CircleEffect(void); void EmptyFunction(void); // Other functions CMDFUNCPTR ParseCommand(char *pS); void ShowStatus(char *str); void GetTextString(INT32U wMaxLen, INT32U wFont, INT32U wTCol, INT32U wBCol); void WriteText(char *txt, INT16U color, INT16U font); /*-----------------------------< Global Variables >---------------------------*/ char str[100]; // GP string INT8U FBuff[512]; // Temporary File buffer char tstr[100]; // Another GP string char bVidMode; // Video Mode char gotMouse; // TRUE if mouse detected char gotKeyboard; // TRUE if keyboard detected INT8U txtLine; // Which line of text is being written to in main window /*-----------------------------< Global Constants >---------------------------*/ // Create an array of structures of command information struct cmd { char text[10]; // command text int tok; // token CMDFUNCPTR pfunc; // pointer to function to call for this command char desc[26]; // command description }; const struct cmd Command[] = { {"SOUND", 0, TestSound, "plays notes"}, {"CLS", 1, ClearMainWindow, "clears main window"}, {"ABOUT", 2, ShowAbout, "to find out more"}, {"HELP", 3, ShowHelp, "show command help"}, {"LED", 4, LedTest, "flashes LEDs A-C"}, {"SKETCH", 5, Sketch, "draw pictures with mouse"}, {"SDCARD", 6, TestSDCard, "runs a quick SDcard test"}, {"TV", 7, TestTV, "displays TV out video"}, {"CF", 8, CompactFlashTest,"read CompactFlash info"}, {"SERIAL", 9, SerialPortTest, "echoes RS232 @115K,8,n,1"}, {"CIRCLES",10, CircleEffect, "meaningless circle effect"}, {"", CMD_END, EmptyFunction, ""} /* mark end of table */ }; /*-----------------------------------< Main >---------------------------------*/ int main(void) { INT32U i; CMDFUNCPTR DoCmd; InitEverything(); // Frame GraphRectangle(0, 0, 639, 450, GREY, 0); GraphRectangle(0, 452, 639, 479, GREY, 0); GraphTextXY("RIZE MICROCOMPUTER DEMO 1.0", 8, 4, WHITE, 1); GraphTextXY("By Revely Microsystems", 8, 16, WHITE, 0); // 15 Color bars (skip black) for (i=0; i<15; i++) { GraphRectangle(i*40+20, 100, (i*40)+59, 350, i+1, TRUE); } if (gotKeyboard) ShowStatus("This program demonstrates RIZE features. Type 'help' for more information."); else ShowStatus("Can't find a PS/2 keyboard!!"); // Main program loop while (1) { // Get text command GraphRectangle(72, 465, 638, 477, BLACK, 1); GraphTextXY("Command >", 8, 465, GREEN, BLACK); GetTextString(40, 0, GREEN, BLACK); DoCmd = ParseCommand(str); sprintf(tstr,"Ready"); // Action it if (DoCmd) DoCmd(); else sprintf(tstr,"Unknown command %10s",str); ShowStatus(tstr); GraphTextXY(tstr, 8, 453, YELLOW, 1); } } /*------------------------------< InitEverything >----------------------------*/ int InitEverything(void) { VIDEOCONFIG vidCfg; SysConfigureClocks(SYS_CLK_125MHZ); InitSysDrivers(); CFInitPort(); RS232Init(115200, 42000000); // Set up UART first so printf is working IoDriverInit(); PS2DriverInit(); // Setup Video Controller vidCfg.mode = VMODE_VGA8; vidCfg.pvmem = (void*)0x08F00000; VideoInit(&vidCfg); GraphInit(&vidCfg); GraphInit8bitPalette(); GraphClrScr(BLACK); // Check for optional hardware Delay(100); // Some mice need a little time to boot up if (PS2MouseInit(1)) // Mouse on Port 2 (logical port 1)? gotMouse=TRUE; if (PS2KeyboardInit(0)) // Keyboard on Port 1 (logical port 0)? gotKeyboard=TRUE; } /*-----------------------------< ParseCommand >-------------------------------*/ CMDFUNCPTR ParseCommand(char *pS) { int i=0; while (Command[i].tok != CMD_END) { if (strcmp(pS, Command[i].text)==0) { return Command[i].pfunc; } i++; } return 0; } /*-------------------------------< TestSound >-------------------------------*/ void TestSound(void) { char c; for (c=0; c < 12; c++) { SoundOn(c * 10 + 600); Delay(100); } for (c=12; c ; c--) { SoundOn(c * 10 + 600); Delay(100); } SoundOff(); } /*-------------------------------< ShowAbout >--------------------------------*/ void ShowAbout(void) { ClearMainWindow(); WriteText("The RIZE Model RMS102 uses Freescale's i.MXL CPU", WHITE, FBOLD); WriteText("Visit www.revely.com for more info",WHITE, FBOLD); // System Info if (gotMouse) WriteText("PS/2 Mouse Detected : TRUE", WHITE, FNORMAL); else WriteText("PS/2 Mouse Detected : FALSE", WHITE, FNORMAL); } /*------------------------------< LedTest >-----------------------------------*/ void LedTest(void) { INT32U i; for (i=30; i; i--) { // Flash Leds A through C CFLedOn(0); CFLedOn(1); CFLedOn(2); Delay(50); CFLedOff(0); CFLedOff(1);CFLedOff(2); Delay(50); } } /*------------------------------< Sketch >-----------------------------*/ void Sketch(void) { INT16U x,y; INT16S mx, my; INT8U b=0,pcolor=WHITE, bcolor=BLACK; ShowStatus("SKETCH P=pen color B=background color E=erase Q=quit"); VideoSetRGB(16, 0, 0, 0); // use color 16 for background GraphRectangle(1, 1, 638, 449, 16, 1); PS2MouseResetPosition(); while (1) { // Get mouse position and update pointer position PS2MouseGetPosition(&mx, &my); if (mx < 0) mx=0; if (my < 0) my=0; if (++mx > 637) mx = 637; if (++my > 448) my = 448; // If left mouse then draw a point if (PS2MouseButtonState() & MOUSE_LEFT) { y = 450 - my; x = mx+1; GraphRectangle(x-1, y-1, x+1, y+1, pcolor, TRUE); } else { // Erase old pointer GraphRectangle(x-1, y-1, x+1, y+1, 16, FALSE); // Draw a new one y = 449 - my; x = mx; GraphRectangle(x-1, y-1, x+1, y+1, pcolor, FALSE); } // Check for keyboard activity if (kbhit()) { switch (toupper(getch())) { case 'P': if (++pcolor > 15) pcolor=0; break; case 'B': if (++bcolor > 15) { bcolor=0; VideoSetRGB(16, 0, 0, 0); } else VideoCopyRGB(16, bcolor); break; case 'E': ClearMainWindow(); break; case 'Q': return; } } } } /*----------------------------------< TestSDCard >----------------------------*/ void TestSDCard(void) { INT32U ad; INT8U seed = (INT8U)RTC_SECONDS; // Get time directly from i.MX register ClearMainWindow(); WriteText("SD Card Test", WHITE, FBOLD); SDCardSlotInit(FALSE); if (SDCardDetect()) WriteText("Card Detected", WHITE, FNORMAL); else { WriteText("No Card Detected", RED, FNORMAL); return; } if (SDCardInit()) WriteText("Card CMD0 Successful", WHITE, FNORMAL); else { WriteText("Card CMD0 Failed", RED, FNORMAL); return; } // Display CID info SDCardGetCIDString(str); WriteText("Card CID Info :", WHITE, FNORMAL); WriteText(str, WHITE, FNORMAL); // Do read speed test 1MB RTC_SECONDS = 0; for (ad=0; ad<0x100000; ad+=512) { if (!CardReadBlock(ad, FBuff)) { WriteText("SD Card Speed Read Failed!", RED, FNORMAL); break; } } sprintf(str, "Read 1MB from SD Card in %u seconds", RTC_SECONDS); WriteText(str, WHITE, FNORMAL); } /*--------------------------------< TestTV >----------------------------------*/ void TestTV(void) { INT16U i; if (VideoInitInTVMode(0)==TV_CLK_IS_NTSC) { txtLine=2; WriteText("Now In NTSC TV Mode", WHITE, FBOLD); } else { txtLine=2; WriteText("Now In PAL TV Mode", WHITE, FBOLD); } WriteText("RMS102 SBC DEMO1 APPLICATION", PURPLE, FBOLD); WriteText("Revely Microsystems", CYAN, FBOLD); WriteText("www.revely.com", YELLOW, FBOLD); // 15 Color bars (skip black) for (i=0; i<15; i++) GraphRectangle(i*40+20, 120, (i*40)+49, 199, i+1, TRUE); getch(); // Back to VGA mode VideoInit(VMODE_VGA8); } /*-----------------------------< CompactFlashTest >---------------------------*/ void CompactFlashTest(void) { ClearMainWindow(); WriteText("Compact Flash Memory Card Test", WHITE, FBOLD); if (CFInitCard()) WriteText("CF Card Detected", WHITE, FNORMAL); else { WriteText("No CF Card Detected", RED, FNORMAL); return; } CFGetMfgString(FBuff); sprintf(str,"Card Mfg Info : %s", FBuff); WriteText(str, WHITE, FNORMAL); if (CFReadBlock(0, FBuff)) WriteText("First Block Read Successfully", WHITE, FNORMAL); else WriteText("First Block Read Failed", RED, FNORMAL); } /*-----------------------------< SerialPortTest >-----------------------------*/ void SerialPortTest(void) { char c; ClearMainWindow(); WriteText("Echoing Serial Port Data - Press any key to quit", WHITE, FBOLD); printf("RIZE RMS102 Serial Port Test\r\n"); while (!kbhit()) { if (RS232CharReady()) { c=RS232GetChar(); putchar(c); sprintf(str,"Got '%c'", c); WriteText(str, GREY, FNORMAL); } } getch(); } /*-------------------------------< ShowHelp >---------------------------------*/ void ShowHelp(void) { INT32U i=0; ClearMainWindow(); WriteText("Available commands:",WHITE, FBOLD); while (Command[i].tok != CMD_END) { sprintf(str,"%s %s", Command[i].text, Command[i].desc); WriteText(str, CYAN, FNORMAL); i++; } } /*-----------------------------< CircleEffect >-------------------------------*/ void CircleEffect(void) { INT16U i,c; for (i=0; i<500 ; i++) { for (c=111; c; c--) GraphCircle(320, 223, c<<1, 0x0f & (c+i)); } for (c=111; c; c--) { GraphCircle(320, 223, c<<1, BLACK); Delay(2); } } /*-----------------------------< EmptyFunction >------------------------------*/ void EmptyFunction(void) { } /*-----------------------------< ClearMainWindow >----------------------------*/ void ClearMainWindow(void) { GraphRectangle(1, 1, 638, 449, BLACK, 1); txtLine=0; } /*-------------------------------< ShowStatus >-------------------------------*/ void ShowStatus(char *str) { GraphRectangle(1, 453, 638, 465, BLACK, 1); GraphTextXY(str, 8, 453, YELLOW, 0); } /*-----------------------------< GetTextString >-----------------------------*/ void GetTextString(INT32U wMaxLen, INT32U wFont, INT32U wTCol, INT32U wBCol) { INT8U bDone=FALSE; INT32U wPos=0, x; INT8U bChar; INT32U wCSize,i; INT32U wXpos = 84, wYpos = 465; INT8U TStr[2]; TStr[1]=NULL; if (wFont == 2) wCSize=8; else wCSize=12; while (!bDone) { x = wXpos + wPos*8; while (!kbhit()) { // Flash cursor GraphRectangle(x-1, wYpos, x+7, wYpos+wCSize, wTCol, TRUE); for (bChar=0; (bChar<10) && (!kbhit()); bChar++) Delay(20); if (kbhit()) break; GraphRectangle(x-1, wYpos, x+7, wYpos+wCSize, wBCol, TRUE); for (bChar=0; (bChar<10) && (!kbhit()); bChar++) Delay(20); if (kbhit()) break; } GraphRectangle(x-1, wYpos, x+7, wYpos+wCSize, wBCol, TRUE); bChar = getch(); // get a keypress // Action keypress switch(bChar) { case 0x0d: str[wPos]=0; // Enter so null terminate bDone=TRUE; break; case 0x08: TStr[0]=' '; // Backspace GraphTextXY(TStr, wXpos+8*wPos,wYpos, wBCol, wFont); if (wPos) wPos--; break; case 0x04: break; // Right arrow (ignore) default: TStr[0] = bChar; // Normal character GraphTextXY(TStr, wXpos+8*wPos, wYpos, wTCol, wFont); str[wPos] = toupper(bChar); if (wPos < wMaxLen-1) wPos++; else { str[wPos+1] = NULL; bDone = TRUE; } } } } /*---------------------------------< WriteText >-------------------------------*/ // Writes a line of text to main window. Automatically moves to next line. // Call ClearMainWindow to clear window and reset line position. void WriteText(char *txt, INT16U color, INT16U font) { if (txtLine > 30) ClearMainWindow(); GraphTextXY(txt, 4, txtLine++ * 14 + 3, color, font); } // end of demo1.c