__inline void destroy_left(){ double ticks; GLCD_SetTextColor(LightGrey); GLCD_Bargraph (current_block.x_offset, current_block.y_offset, abs(diff), HEIGHT, 1024); ticks = os_time_get(); while(os_time_get() - ticks < ERASE_TIME); GLCD_SetTextColor(White); GLCD_Bargraph (current_block.x_offset, current_block.y_offset, abs(diff), HEIGHT, 1024); }
void Drawbasket(int X0,int Y0){ int j , k ; GLCD_SetTextColor(Olive); Draw_lineX(X0-12,Y0,X0+13); Draw_lineX(X0-12,Y0+1,X0+11); Draw_lineX(X0-10,Y0+2,X0+11); Draw_lineX(X0-10,Y0+3,X0+11); Draw_lineX(X0-10,Y0+4,X0+11); Draw_lineX(X0-10,Y0+5,X0+11); Draw_lineX(X0-10,Y0+6,X0+11); Draw_lineX(X0-10,Y0+7,X0+11); Draw_lineX(X0-10,Y0+8,X0+11); Draw_lineX(X0-10,Y0+9,X0+11); Draw_lineX(X0-10,Y0+10,X0+11); Draw_lineX(X0-10,Y0+11,X0+11); Draw_lineX(X0-9,Y0+12,X0+10); Draw_lineX(X0-9,Y0+13,X0+10); Draw_lineX(X0-9,Y0+14,X0+10); Draw_lineX(X0-8,Y0+15,X0+9); Draw_lineX(X0-8,Y0+16,X0+9); Draw_lineX(X0-8,Y0+17,X0+9); GLCD_SetTextColor(Black); k = 0; j = 0; while( k < 3){ while( j < 6){ Draw_lineX(X0-10+(4*j),Y0+2+(4*k),X0-9+(4*j)); Draw_lineX(X0-10+(4*j),Y0+3+(4*k),X0-9+(4*j)); j++; } j=0; k++; } }
/*--------------------------------------------------------------------------- Set Lights function controls LEDs and LCD display *---------------------------------------------------------------------------*/ void SetLights (uint32_t light, uint32_t on) { osMutexWait(mut_GLCD, osWaitForever); GLCD_SetBackColor(White); if (light == RED) { GLCD_SetTextColor(Red); if (on == 0) { GLCD_DisplayChar(4, 15, __FI, 0x80+0); } else { GLCD_DisplayChar(4, 15, __FI, 0x80+1); } } if (light == YELLOW) { GLCD_SetTextColor(Yellow); if (on == 0) { GLCD_DisplayChar(5, 15, __FI, 0x80+0); } else { GLCD_DisplayChar(5, 15, __FI, 0x80+1); } } if (light == GREEN) { GLCD_SetTextColor(Green); if (on == 0) { GLCD_DisplayChar(6, 15, __FI, 0x80+0); } else { GLCD_DisplayChar(6, 15, __FI, 0x80+1); } } if (light == STOP) { GLCD_SetTextColor(Red); if (on == 0) { GLCD_DisplayChar(5, 13, __FI, 0x80+12); } else { GLCD_DisplayChar(5, 13, __FI, 0x80+13); } } if (light == WALK) { GLCD_SetTextColor(Green); if (on == 0) { GLCD_DisplayChar(6, 13, __FI, 0x80+14); } else { GLCD_DisplayChar(6, 13, __FI, 0x80+15); } } osMutexRelease(mut_GLCD); if (on == 0) { LED_Off (light); } else { LED_On (light); } }
void DisplayInstructions(void){ GLCD_SetBackColor(Blue); GLCD_SetTextColor(Red); GLCD_DisplayString(0, 0, __FI, " BrainMINSA "); GLCD_SetTextColor(White); updateScoreAndDifficulty(currentScore, currentDifficulty, nextDifficulty); GLCD_DisplayString(2,0,__FI,"Use POTENTIOMETER -"); GLCD_DisplayString(2,0,__FI,"to change difficulty"); GLCD_DisplayString(9,0,__FI,"User button = finish"); }
__inline void destroy_right(){ double ticks; GLCD_SetTextColor(LightGrey); GLCD_Bargraph (x_offsets[count - 1] + widths[count - 1], current_block.y_offset, diff, HEIGHT, 1024); ticks = os_time_get(); while(os_time_get() - ticks < ERASE_TIME); GLCD_SetTextColor(White); GLCD_Bargraph (x_offsets[count - 1] + widths[count - 1], current_block.y_offset, diff, HEIGHT, 1024); }
/*---------------------------------------------------------------------------- * switch LED off *---------------------------------------------------------------------------*/ void LED_Off (unsigned char led) { LED_off(led); os_mut_wait(mut_GLCD, 0xffff); GLCD_SetBackColor(White); /* Set the Back Color */ GLCD_SetTextColor(Green); /* Set the Text Color */ GLCD_DisplayChar(4, 5+led, 1, 0x80+0); /* Circle Empty */ os_mut_release(mut_GLCD); }
/*---------------------------------------------------------------------------- switch LED off *---------------------------------------------------------------------------*/ void LED_off (unsigned char led) { LED_Off(led); osMutexWait(mut_GLCD, osWaitForever); GLCD_SetBackColor(White); GLCD_SetTextColor(Green); GLCD_DisplayChar(4, 5+led, __FI, 0x80+0); /* Circle Empty */ osMutexRelease(mut_GLCD); }
/*---------------------------------------------------------------------------- * Initialize On Board LCD Module *---------------------------------------------------------------------------*/ static void init_display (void) { /* LCD Module init */ GLCD_Init (); GLCD_Clear (White); GLCD_SetTextColor (Blue); GLCD_DisplayString (1, 2, " RL-ARM"); GLCD_DisplayString (2, 2, "SD_File example"); }
/*---------------------------------------------------------------------------- Thread 6 'lcd': LCD Control task *---------------------------------------------------------------------------*/ void lcd (void const *argument) { for (;;) { osMutexWait(mut_GLCD, osWaitForever); GLCD_SetBackColor(Blue); GLCD_SetTextColor(White); GLCD_DisplayString(0, 0, __FI, " MCB1700 Demo "); GLCD_DisplayString(1, 0, __FI, " RTX Blinky "); GLCD_DisplayString(2, 0, __FI, " www.keil.com "); osMutexRelease(mut_GLCD); osDelay(4000); /* delay 4s */ osMutexWait(mut_GLCD, osWaitForever); GLCD_SetBackColor(Blue); GLCD_SetTextColor(Red); GLCD_DisplayString(0, 0, __FI, " MCB1700 Demo "); GLCD_DisplayString(1, 0, __FI, " RTX Blinky "); GLCD_DisplayString(2, 0, __FI, " www.keil.com "); osMutexRelease(mut_GLCD); osDelay(4000); /* delay 4s */ } }
/*---------------------------------------------------------------------------- * Task 6 'lcd': LCD Control task *---------------------------------------------------------------------------*/ __task void lcd (void) { for (;;) { os_mut_wait(mut_GLCD, 0xffff); GLCD_SetBackColor(Blue); /* Set the Text Color */ GLCD_SetTextColor(White); /* Set the Text Color */ GLCD_DisplayString(0, 0, 1, " MCB1700 RL-ARM "); GLCD_DisplayString(1, 0, 1, " RTX Blinky "); GLCD_DisplayString(2, 0, 1, " www.keil.com "); os_mut_release(mut_GLCD); os_dly_wait (400); os_mut_wait(mut_GLCD, 0xffff); GLCD_SetBackColor(Blue); /* Set the Text Color */ GLCD_SetTextColor(Red); /* Set the Text Color */ GLCD_DisplayString(0, 0, 1, " MCB1700 RL-ARM "); GLCD_DisplayString(1, 0, 1, " RTX Blinky "); GLCD_DisplayString(2, 0, 1, " www.keil.com "); os_mut_release(mut_GLCD); os_dly_wait (400); } }
void init_scroll( void ) { GLCD_Init(); GLCD_Clear(BGC); GLCD_SetBackColor(BGC); GLCD_SetTextColor(TXC); cache_start = 0; cache_size = 0; last_col_cahche = 0; window_start = 0; window_size = 0; }
/*---------------------------------------------------------------------------- Thread 6 'lcd': LCD Control Thread *---------------------------------------------------------------------------*/ void lcd (void const *argument) { GLCD_Clear(White); /* Clear the LCD */ for (;;) { osMutexWait(mut_GLCD, osWaitForever); GLCD_SetBackColor(Blue); /* Set the Back Color */ GLCD_SetTextColor(White); /* Set the Text Color */ GLCD_DisplayString(0, 0, __FI, " MCB1700 Demo "); GLCD_DisplayString(1, 0, __FI, " RTX Traffic "); GLCD_DisplayString(2, 0, __FI, " www.keil.com "); osMutexRelease(mut_GLCD); osDelay(4000); osMutexWait(mut_GLCD, osWaitForever); GLCD_SetBackColor(Blue); /* Set the Back Color */ GLCD_SetTextColor(Red); /* Set the Text Color */ GLCD_DisplayString(0, 0, __FI, " MCB1700 Demo "); GLCD_DisplayString(1, 0, __FI, " RTX Traffic "); GLCD_DisplayString(2, 0, __FI, " www.keil.com "); osMutexRelease(mut_GLCD); osDelay(4000); } }
int main(void) { SystemInit(); GLCD_Init(); GLCD_Clear(Black); GLCD_SetTextColor(Red); GLCD_SetBackColor(Black); __enable_irq(); GLCD_DisplayString(1, 1, 1, "Status: "); GLCD_DisplayString(1, 9, 1, "START"); GLCD_DisplayString(4, 5, 1, "TIMER"); BoardInit(); hwInterrupt(min_to_run * ms_in_min); GLCD_DisplayString(1, 9, 1, "END "); return 0; }
void DrawBarGraph(uint32_t x, uint32_t y, uint32_t w, uint32_t h, int32_t val){ GLCD_SetBackColor(White); GLCD_SetTextColor(Black); GLCD_DisplayString(6,0,__FI,"Difficulty "); switch(w) { case 20: GLCD_SetBackColor(Green); GLCD_Bargraph(x,y,w,h,val); GLCD_SetBackColor(White); break; case 40: GLCD_SetBackColor(Blue); GLCD_Bargraph(x,y,w,h,val); GLCD_SetBackColor(White); break; case 60: GLCD_SetBackColor(Magenta); GLCD_Bargraph(x,y,w,h,val); GLCD_SetBackColor(White); break; case 80: GLCD_SetBackColor(Cyan); GLCD_Bargraph(x,y,w,h,val); GLCD_SetBackColor(White); break; case 100: GLCD_SetBackColor(Red); GLCD_Bargraph(x,y,w,h,val); GLCD_SetBackColor(White); break; default: break; } }
/*---------------------------------------------------------------------------- * Initialize a Flash Memory Card *---------------------------------------------------------------------------*/ static void init_card (void) { U32 retv; MMCFG SDCardCfg; char outBuf[26]; GLCD_SetBackColor (White); GLCD_SetTextColor (Blue); GLCD_ClearLn (5); GLCD_ClearLn (6); GLCD_ClearLn (7); GLCD_ClearLn (8); while ((retv = finit ()) != 0) { /* Wait until the Card is ready*/ if (retv == 1) { printf ("\nSD/MMC Init Failed"); printf ("\nInsert Memory card and press key...\n"); getkey (); } else { printf ("\nSD/MMC Card is Unformatted"); strcpy (&in_line[0], "KEIL\r\n"); cmd_format (&in_line[0]); } } mmc_read_config (&SDCardCfg); outBuf[0] = 0; sprintf (&outBuf[0], " SerNr: 0x%08X", SDCardCfg.sernum); GLCD_DisplayString (5, 0, (unsigned char *)outBuf); sprintf (&outBuf[0], " BlockNr:0x%08X", SDCardCfg.blocknr); GLCD_DisplayString (6, 0, (unsigned char *)outBuf); sprintf (&outBuf[0], " RdLen: 0x%04X", SDCardCfg.read_blen); GLCD_DisplayString (7, 0, (unsigned char *)outBuf); sprintf(&outBuf[0], " WrLen: 0x%04X", SDCardCfg.write_blen); GLCD_DisplayString (8, 0, (unsigned char *)outBuf); }
// This is the actual task that is run static portTASK_FUNCTION( vLCDUpdateTask, pvParameters ) { #if LCD_EXAMPLE_OP==0 unsigned short screenColor = 0; unsigned short tscr; unsigned char curLine; unsigned timerCount = 0; int xoffset = 0, yoffset = 0; unsigned int xmin=0, xmax=0, ymin=0, ymax=0; unsigned int x, y; int i, j; float hue=0, sat=0.2, light=0.2; #elif LCD_EXAMPLE_OP==1 unsigned char picIndex = 0; #else Bad definition #endif vtLCDMsg msgBuffer; vtLCDStruct *lcdPtr = (vtLCDStruct *) pvParameters; #ifdef INSPECT_STACK // This is meant as an example that you can re-use in your own tasks // Inspect to the stack remaining to see how much room is remaining // 1. I'll check it here before anything really gets started // 2. I'll check during the run to see if it drops below 10% // 3. You could use break points or logging to check on this, but // you really don't want to print it out because printf() can // result in significant stack usage. // 4. Note that this checking is not perfect -- in fact, it will not // be able to tell how much the stack grows on a printf() call and // that growth can be *large* if version 1 of printf() is used. unsigned portBASE_TYPE InitialStackLeft = uxTaskGetStackHighWaterMark(NULL); unsigned portBASE_TYPE CurrentStackLeft; float remainingStack = InitialStackLeft; remainingStack /= lcdSTACK_SIZE; if (remainingStack < 0.10) { // If the stack is really low, stop everything because we don't want it to run out // The 0.10 is just leaving a cushion, in theory, you could use exactly all of it VT_HANDLE_FATAL_ERROR(0); } #endif /* Initialize the LCD and set the initial colors */ GLCD_Init(); tscr = Red; // may be reset in the LCDMsgTypeTimer code below screenColor = White; // may be reset in the LCDMsgTypeTimer code below GLCD_SetTextColor(tscr); GLCD_SetBackColor(screenColor); GLCD_Clear(screenColor); // Added by Matthew Ibarra 2/2/2013 int xPos = 0; // Note that srand() & rand() require the use of malloc() and should not be used unless you are using // MALLOC_VERSION==1 #if MALLOC_VERSION==1 srand((unsigned) 55); // initialize the random number generator to the same seed for repeatability #endif curLine = 5; // This task should never exit for(;;) { #ifdef INSPECT_STACK CurrentStackLeft = uxTaskGetStackHighWaterMark(NULL); float remainingStack = CurrentStackLeft; remainingStack /= lcdSTACK_SIZE; if (remainingStack < 0.10) { // If the stack is really low, stop everything because we don't want it to run out VT_HANDLE_FATAL_ERROR(0); } #endif #if LCD_EXAMPLE_OP==0 // Wait for a message if (xQueueReceive(lcdPtr->inQ,(void *) &msgBuffer,portMAX_DELAY) != pdTRUE) { VT_HANDLE_FATAL_ERROR(0); } #if EXAMPLE_COLOR_CHANGE==1 //Log that we are processing a message -- more explanation of logging is given later on vtITMu8(vtITMPortLCDMsg,getMsgType(&msgBuffer)); vtITMu8(vtITMPortLCDMsg,getMsgLength(&msgBuffer)); // Take a different action depending on the type of the message that we received switch(getMsgType(&msgBuffer)) { case LCDMsgTypePrint: { // This will result in the text printing in the last five lines of the screen char lineBuffer[lcdCHAR_IN_LINE+1]; copyMsgString(lineBuffer,&msgBuffer,lcdCHAR_IN_LINE); // clear the line GLCD_ClearLn(curLine,1); // show the text GLCD_DisplayString(curLine,0,1,(unsigned char *)lineBuffer); curLine++; if (curLine == lcdNUM_LINES) { curLine = 5; } break; } case LCDMsgTypeTimer: { // Note: if I cared how long the timer update was I would call my routine // unpackTimerMsg() which would unpack the message and get that value // Each timer update will cause a circle to be drawn on the top half of the screen // as explained below if (timerCount == 0) { /* ************************************************** */ // Find a new color for the screen by randomly (within limits) selecting HSL values // This can be ignored unless you care about the color map #if MALLOC_VERSION==1 hue = rand() % 360; sat = (rand() % 1024) / 1023.0; sat = sat * 0.5; sat += 0.5; light = (rand() % 1024) / 1023.0; light = light * 0.8; light += 0.10; #else hue = (hue + 1); if (hue >= 360) hue = 0; sat+=0.01; if (sat > 1.0) sat = 0.20; light+=0.03; if (light > 1.0) light = 0.20; #endif screenColor = hsl2rgb(hue,sat,light); // Now choose a complementary value for the text color hue += 180; if (hue >= 360) hue -= 360; tscr = hsl2rgb(hue,sat,light); GLCD_SetTextColor(tscr); GLCD_SetBackColor(screenColor); // End of playing around with figuring out a random color /* ************************************************** */ // clear the top half of the screen GLCD_ClearWindow(0,0,320,120,screenColor); // Now we are going to draw a circle in the upper left corner of the screen int count = 200; float radius; float inc, val, offset = MAX_RADIUS; unsigned short circleColor; inc = 2*M_PI/count; xmax = 0; ymax = 0; xmin = 50000; ymin = 50000; val = 0.0; for (i=0;i<count;i++) { // Make the circle a little thicker // by actually drawing three circles w/ different radii float cv = cos(val), sv=sin(val); circleColor = (val*0xFFFF)/(2*M_PI); GLCD_SetTextColor(circleColor); for (radius=MAX_RADIUS-2.0;radius<=MAX_RADIUS;radius+=1.0) { x = round(cv*radius+offset); y = round(sv*radius+offset); if (x > xmax) xmax = x; if (y > ymax) ymax = y; if (x < xmin) xmin = x; if (y < ymin) ymin = y; GLCD_PutPixel(x,y); } val += inc; } // Now we are going to read the upper left square of the LCD's // memory (see its data sheet for details on that) and save // that into a buffer for fast re-drawing later if (((xmax+1-xmin)*(ymax+1-ymin)) > BUF_LEN) { // Make sure we have room for the data VT_HANDLE_FATAL_ERROR(0); } unsigned short int *tbuffer = buffer; unsigned int width = (xmax+1-xmin); for (j=ymin;j<=ymax;j++) { GLCD_GetPixelRow (xmin,j,width,tbuffer); tbuffer += width; } // end of reading in the buffer xoffset = xmin; yoffset = ymin; } else { // We are going to write out the data read into the buffer // back onto the screen at a new location // This is *very* fast // First, clear out where we were GLCD_ClearWindow(xoffset,yoffset,xmax+1-xmin,ymax+1-ymin,screenColor); // Pick the new location #if MALLOC_VERSION==1 xoffset = rand() % (320-(xmax+1-xmin)); yoffset = rand() % (120-(ymax+1-ymin)); #else xoffset = (xoffset + 10) % (320-(xmax+1-xmin)); yoffset = (yoffset + 10) % (120-(ymax+1-ymin)); #endif // Draw the bitmap GLCD_Bitmap(xoffset,yoffset,xmax+1-xmin,ymax-1-ymin,(unsigned char *)buffer); } timerCount++; if (timerCount >= 40) { // every so often, we reset timer count and start again // This isn't for any important reason, it is just to for this example code to do "stuff" timerCount = 0; } break; } default: { // In this configuration, we are only expecting to receive timer messages VT_HANDLE_FATAL_ERROR(getMsgType(&msgBuffer)); break; } } // end of switch() #endif #if MILESTONE_1==1 // Added by Matthew Ibarra 2/2/2013 if(timerCount==0) { GLCD_Clear(screenColor); // Draw the vertical gridlines onto the LCD int i; for(i = 320/6; i < 315; i = i + 320/6) { GLCD_ClearWindow(i, 0, 1, 240, Red); } // Draw the vertical gridlines onto the LCD for(i = 240/4; i < 235; i = i + 240/4) { GLCD_ClearWindow(0, i, 320, 1, Red); } //Output Scale on LCD GLCD_DisplayString(29, 0, 0, (unsigned char*) "V/div=2.5 s/div=3"); timerCount++; } int adcValue; getMsgValue(&adcValue, &msgBuffer); int displayValue; displayValue = 120 - (adcValue * 120)/(0x100); GLCD_ClearWindow(xPos, displayValue, 2, 2, Black); xPos += 2; if(xPos > 320) { timerCount = 0; xPos = 0; } #endif // Here is a way to do debugging output via the built-in hardware -- it requires the ULINK cable and the // debugger in the Keil tools to be connected. You can view PORT0 output in the "Debug(printf) Viewer" // under "View->Serial Windows". You have to enable "Trace" and "Port0" in the Debug setup options. This // should not be used if you are using Port0 for printf() // There are 31 other ports and their output (and port 0's) can be seen in the "View->Trace->Records" // windows. You have to enable the prots in the Debug setup options. Note that unlike ITM_SendChar() // this "raw" port write is not blocking. That means it can overrun the capability of the system to record // the trace events if you go too quickly; that won't hurt anything or change the program execution and // you can tell if it happens because the "View->Trace->Records" window will show there was an overrun. //vtITMu16(vtITMPortLCD,screenColor); #elif LCD_EXAMPLE_OP==1 // In this alternate version, we just keep redrawing a series of bitmaps as // we receive timer messages // Wait for a message if (xQueueReceive(lcdPtr->inQ,(void *) &msgBuffer,portMAX_DELAY) != pdTRUE) { VT_HANDLE_FATAL_ERROR(0); } if (getMsgType(&msgBuffer) != LCDMsgTypeTimer) { // In this configuration, we are only expecting to receive timer messages VT_HANDLE_FATAL_ERROR(getMsgType(&msgBuffer)); } /* go through a bitmap that is really a series of bitmaps */ picIndex = (picIndex + 1) % 9; GLCD_Bmp(99,99,120,45,(unsigned char *) &ARM_Ani_16bpp[picIndex*(120*45*2)]); #else Bad setting #endif } }
// This is the actual task that is run static portTASK_FUNCTION( vLCDUpdateTask, pvParameters ) { portTickType xUpdateRate, xLastUpdateTime; int pixel_buffer[80]; float max = 0; float min = 990; unsigned short screenColor; #if LCD_EXAMPLE_OP==0 unsigned short tscr; static char scrString[40]; unsigned char curLine = 0; float hue=0, sat=0.2, light=0.2; #elif LCD_EXAMPLE_OP==1 unsigned char picIndex = 0; #elif LCD_EXAMPLE_OP==2 vtLCDMsg msgBuffer; unsigned char curLine = 0; #endif vtLCDStruct *lcdPtr = (vtLCDStruct *) pvParameters; /* Initialize the LCD */ GLCD_Init(); GLCD_Clear(Yellow); // Scale the update rate to ensure it really is in ms xUpdateRate = lcdWRITE_RATE_BASE / portTICK_RATE_MS; /* We need to initialise xLastUpdateTime prior to the first call to vTaskDelayUntil(). */ xLastUpdateTime = xTaskGetTickCount(); // Note that srand() & rand() require the use of malloc() and should not be used unless you are using // MALLOC_VERSION==1 #if MALLOC_VERSION==1 srand((unsigned) 55); // initialize the random number generator to the same seed for repeatability #endif // Like all good tasks, this should never exit int i = 0; GLCD_SetTextColor(Black); GLCD_SetBackColor(Yellow); for(;;) { #if LCD_EXAMPLE_OP==0 /* Ask the RTOS to delay reschduling this task for the specified time */ vTaskDelayUntil( &xLastUpdateTime, xUpdateRate ); // Find a new color for the screen by randomly (within limits) selecting HSL values #if MALLOC_VERSION==1 hue = rand() % 360; sat = (rand() % 1024) / 1023.0; sat = sat * 0.5; sat += 0.5; light = (rand() % 1024) / 1023.0; light = light * 0.8; light += 0.10; #else hue = (hue + 1); if (hue >= 360) hue = 0; sat+=0.01; if (sat > 1.0) sat = 0.20; light+=0.03; if (light > 1.0) light = 0.20; #endif screenColor = hsl2rgb(hue,sat,light); // Now choose a complementary value for the text color hue += 180; if (hue >= 360) hue -= 360; tscr = hsl2rgb(hue,sat,light); GLCD_SetTextColor(tscr); GLCD_SetBackColor(screenColor); /* create a string for printing to the LCD */ sprintf(scrString,"LCD: %d %d %d",screenColor,(int)xUpdateRate,(int)xLastUpdateTime); GLCD_ClearLn(curLine,1); GLCD_DisplayString(curLine,0,1,(unsigned char *)scrString); curLine++; if (curLine == 10) { /* clear the LCD at the end of the screen */ GLCD_Clear(screenColor); curLine = 0; } printf("BackColor (RGB): %d %d %d - (HSL) %3.0f %3.2f %3.2f \n", (screenColor & 0xF800) >> 11,(screenColor & 0x07E0) >> 5,screenColor & 0x001F, hue,sat,light); printf("TextColor (RGB): %d %d %d\n", (tscr & 0xF800) >> 11,(tscr & 0x07E0) >> 5,tscr & 0x001F); // Here is a way to do debugging output via the built-in hardware -- it requires the ULINK cable and the // debugger in the Keil tools to be connected. You can view PORT0 output in the "Debug(printf) Viewer" // under "View->Serial Windows". You have to enable "Trace" and "Port0" in the Debug setup options. This // should not be used if you are using Port0 for printf() // There are 31 other ports and their output (and port 0's) can be seen in the "View->Trace->Records" // windows. You have to enable the prots in the Debug setup options. Note that unlike ITM_SendChar() // this "raw" port write is not blocking. That means it can overrun the capability of the system to record // the trace events if you go too quickly; that won't hurt anything or change the program execution and // you can tell if it happens because the "View->Trace->Records" window will show there was an overrun. vtITMu16(vtITMPortLCD,screenColor); #elif LCD_EXAMPLE_OP==1 /* Ask the RTOS to delay reschduling this task for the specified time */ vTaskDelayUntil( &xLastUpdateTime, xUpdateRate ); /* go through a bitmap that is really a series of bitmaps */ picIndex = (picIndex + 1) % 9; GLCD_Bmp(99,99,120,45,(unsigned char *) &ARM_Ani_16bpp[picIndex*(120*45*2)]); #elif LCD_EXAMPLE_OP==2 // wait for a message from another task telling us to send/recv over i2c if (xQueueReceive(lcdPtr->inQ,(void *) &msgBuffer,portMAX_DELAY) != pdTRUE) { VT_HANDLE_FATAL_ERROR(0); } //get the data from the message queue and reconvert it into a 10-bit value int pixel = msgBuffer.buf[1]<<8; pixel = pixel + msgBuffer.buf[0]; //set minimum and maximum values should they change across the 80 data points in buffer if (pixel > max) max = pixel; if (pixel < min) min = pixel; //trim pixel data value to fit it on screen pixel = pixel / 5; //add pixel to a data buffer so we can clear the screen and keep accurate data pixel_buffer[i] = pixel; //increment for next position in the buffer i++; //once we have a filled buffer of data points, print the screen if (i > 79) { GLCD_Clear(Yellow); //each data point is 4 pixels by 4 pixels for (i = 0; i < 80; i++) { GLCD_PutPixel(i*4, 240-pixel_buffer[i]); GLCD_PutPixel(i*4, 240-pixel_buffer[i]+1); GLCD_PutPixel(i*4, 240-pixel_buffer[i]+2); GLCD_PutPixel(i*4, 240-pixel_buffer[i]+3); GLCD_PutPixel(i*4+1, 240-pixel_buffer[i]); GLCD_PutPixel(i*4+1, 240-pixel_buffer[i]+1); GLCD_PutPixel(i*4+1, 240-pixel_buffer[i]+2); GLCD_PutPixel(i*4+1, 240-pixel_buffer[i]+3); GLCD_PutPixel(i*4+2, 240-pixel_buffer[i]); GLCD_PutPixel(i*4+2, 240-pixel_buffer[i]+1); GLCD_PutPixel(i*4+2, 240-pixel_buffer[i]+2); GLCD_PutPixel(i*4+2, 240-pixel_buffer[i]+3); GLCD_PutPixel(i*4+3, 240-pixel_buffer[i]); GLCD_PutPixel(i*4+3, 240-pixel_buffer[i]+1); GLCD_PutPixel(i*4+3, 240-pixel_buffer[i]+2); GLCD_PutPixel(i*4+3, 240-pixel_buffer[i]+3); } //convert max and mins to voltages max = max / 300; min = min / 300; //display the max and min voltages on the screen uint8_t toprint[4]; sprintf((char *)toprint, "%1.1fV", max); GLCD_DisplayString(0,9,1, (unsigned char*)&toprint); sprintf((char *)toprint, "%1.1fV", min); GLCD_DisplayString(9,9,1, (unsigned char*)&toprint); //display the scalar on the screen GLCD_DisplayString(9,0,1, (unsigned char *)"0V"); GLCD_DisplayString(7,0,1, (unsigned char *)"1V"); GLCD_DisplayString(5,0,1, (unsigned char *)"2V"); GLCD_DisplayString(3,0,1, (unsigned char *)"3V"); //reset values for the next buffer screen i = 0; max = 0; min = 990; } #else Bad setting #endif } }
int_t main(void) { error_t error; NetInterface *interface; OsTask *task; static DhcpClientSettings dhcpClientSettings; static DhcpClientCtx dhcpClientContext; //Update system core clock SystemCoreClockUpdate(); //Configure debug UART debugInit(115200); //Start-up message TRACE_INFO("\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("*** CycloneTCP FTP Client Demo ***\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("Copyright: 2010-2013 Oryx Embedded\r\n"); TRACE_INFO("Compiled: %s %s\r\n", __DATE__, __TIME__); TRACE_INFO("Target: SAM4E\r\n"); TRACE_INFO("\r\n"); //IO configuration ioInit(); //Initialize LCD display GLCD_Init(); GLCD_SetBackColor(Blue); GLCD_SetTextColor(White); GLCD_Clear(Blue); //Welcome message lcdSetCursor(0, 0); printf("FTP Client Demo\r\n"); //TCP/IP stack initialization error = tcpIpStackInit(); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize TCP/IP stack!\r\n"); } //Configure the first Ethernet interface interface = &netInterface[0]; //Select the relevant network adapter interface->nicDriver = &sam4eEthDriver; interface->phyDriver = &ksz8051PhyDriver; //Interface name strcpy(interface->name, "eth0"); //Set host MAC address macStringToAddr("00-AB-CD-EF-04-16", &interface->macAddr); #if (IPV6_SUPPORT == ENABLED) //Set link-local IPv6 address ipv6StringToAddr("fe80::00ab:cdef:0416", &interface->ipv6Config.linkLocalAddr); #endif //Initialize network interface error = tcpIpStackConfigInterface(interface); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to configure interface %s!\r\n", interface->name); } #if 1 //Set the network interface to be configured by DHCP dhcpClientSettings.interface = &netInterface[0]; //Disable rapid commit option dhcpClientSettings.rapidCommit = FALSE; //Start DHCP client error = dhcpClientStart(&dhcpClientContext, &dhcpClientSettings); //Failed to start DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to start DHCP client!\r\n"); } #else //Manual configuration interface = &netInterface[0]; //IPv4 address ipv4StringToAddr("192.168.0.20", &interface->ipv4Config.addr); //Subnet mask ipv4StringToAddr("255.255.255.0", &interface->ipv4Config.subnetMask); //Default gateway ipv4StringToAddr("192.168.0.254", &interface->ipv4Config.defaultGateway); //Primary and secondary DNS servers interface->ipv4Config.dnsServerCount = 2; ipv4StringToAddr("212.27.40.240", &interface->ipv4Config.dnsServer[0]); ipv4StringToAddr ("212.27.40.241", &interface->ipv4Config.dnsServer[1]); #endif //Create user task task = osTaskCreate("User Task", userTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Create a task to blink the LED task = osTaskCreate("Blink", blinkTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Start the execution of tasks osStart(); //This function should never return return 0; }
/******************************************************************************* * Function Name : main * Description : Main program * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) { /* NVIC configuration */ NVIC_Configuration(); initialisation(); /* Initialisation of SD Card and creation of File */ SD_Init(); /* Blinkmuster laden */ if( SD_Start("muster.txt", FA_OPEN_EXISTING | FA_READ) ) { SD_Read(&muster,1); } SD_Close(); /* LCD Initialisieren */ GLCD_Init(); GLCD_Clear(White); GLCD_SetTextColor(Red); GLCD_DisplayString(1, 1, 1, "Write to SD-Card"); GLCD_DisplayString(8, 1, 1, "Press User to stop"); GLCD_DisplayString(4, 1, 1, "Fit Card into Slot"); /* Wait until SD Card is in Slot */ while(!(SD_Start("time.txt", FA_CREATE_ALWAYS | FA_WRITE))) { } length=sprintf (buffer, "runtime: %d:%d:%d ", hour, min, sek); GLCD_DisplayString(4, 1, 1, buffer); /***************************** * ENDE INITIALISIERUNG * ******************************/ GPIO_ResetBits(GPIOE,GPIO_Pin_All); // LED off all pins while(1) { // BFH_GLCD_UDP(); /* Alle 10ms wird das tickFlag gesetzt */ if(tickFlag) { tickFlag=0; // reset tickFlag if(write > 1) { /* Jede Sekunde einen Stamp ins File schreiben */ if((write%1000) == 0) { /* Zeit hochzählen */ sek++; if(sek==60) { sek=0; min++; } if(min==60) { min=0; hour++; } if(hour==24) { hour=0; } /* write time to Diaplay */ length=sprintf (buffer, "runtime: %d:%d:%d ", hour, min, sek); GLCD_DisplayString(4, 1, 1, buffer); /* write time to card */ length=sprintf (buffer, "runtime: %d:%d:%d\ttext\r\n", hour, min, sek); SD_Write(buffer,length); /* switch LED */ GPIOE->ODR ^= muster << 8; } write += 10; } /* Close SD Card */ else if (write == 1) { SD_Close(); write--; } /* Schreiben beendet -> LED löschen */ else { GPIOE->ODR |= muster << 8; GLCD_DisplayString(8, 1, 1, "Application stopped"); } } /* Wenn Taste gedrückt wird, schreiben beenden */ if((GPIOB->IDR&0x0080) == 0) { write = 1; } } }
// This is the actual task that is run static portTASK_FUNCTION(vLCDUpdateTask, pvParameters) { #if LCD_EXAMPLE_OP == 0 unsigned short screenColor = 0; unsigned short tscr; unsigned char curLine; unsigned timerCount = 0; int xoffset = 0, yoffset = 0; unsigned int xmin = 0, xmax = 0, ymin = 0, ymax = 0; unsigned int x, y; int i; float hue = 0, sat = 0.2, light = 0.2; #else // if LCD_EXAMPLE_OP==1 unsigned char picIndex = 0; #endif vtLCDMsg msgBuffer; vtLCDStruct *lcdPtr = (vtLCDStruct *)pvParameters; #ifdef INSPECT_STACK // This is meant as an example that you can re-use in your own tasks // Inspect to the stack remaining to see how much room is remaining // 1. I'll check it here before anything really gets started // 2. I'll check during the run to see if it drops below 10% // 3. You could use break points or logging to check on this, but // you really don't want to print it out because printf() can // result in significant stack usage. // 4. Note that this checking is not perfect -- in fact, it will not // be able to tell how much the stack grows on a printf() call and // that growth can be *large* if version 1 of printf() is used. unsigned portBASE_TYPE InitialStackLeft = uxTaskGetStackHighWaterMark(NULL); unsigned portBASE_TYPE CurrentStackLeft; float remainingStack = InitialStackLeft; remainingStack /= lcdSTACK_SIZE; if (remainingStack < 0.10) { // If the stack is really low, stop everything because we don't want it to // run out // The 0.10 is just leaving a cushion, in theory, you could use exactly all // of it VT_HANDLE_FATAL_ERROR(0); } #endif // Graph initialization const unsigned graphXoff = 30; const unsigned graphYoff = 10; const unsigned graphWidth = 260; const unsigned graphHeight = 160; uint8_t graphVals[graphWidth]; for (i = 0; i < graphWidth; i++) { graphVals[i] = 0; } uint8_t graphStart = 0; /* Initialize the LCD and set the initial colors */ GLCD_Init(); tscr = White; // may be reset in the LCDMsgTypeTimer code below screenColor = Black; // may be reset in the LCDMsgTypeTimer code below GLCD_SetTextColor(tscr); GLCD_SetBackColor(screenColor); GLCD_Clear(screenColor); GLCD_ClearWindow(graphXoff - 1, graphYoff - 1, 1, graphHeight + 1, Blue); GLCD_ClearWindow( graphXoff - 1, graphYoff + graphHeight + 1, graphWidth + 1, 1, Blue); GLCD_DisplayString(22, 47, 0, (unsigned char *)"0min"); GLCD_DisplayString(22, 37, 0, (unsigned char *)"-1min"); GLCD_DisplayString(22, 27, 0, (unsigned char *)"-2min"); GLCD_DisplayString(22, 17, 0, (unsigned char *)"-3min"); GLCD_DisplayString(22, 7, 0, (unsigned char *)"-4min"); GLCD_DisplayString(22, 0, 0, (unsigned char *)"0.0m"); GLCD_DisplayString(14, 0, 0, (unsigned char *)"0.5m"); GLCD_DisplayString(8, 0, 0, (unsigned char *)"1.0m"); GLCD_DisplayString(2, 0, 0, (unsigned char *)"1.5m"); // Note that srand() & rand() require the use of malloc() and should not be used // unless you are using // MALLOC_VERSION==1 #if MALLOC_VERSION == 1 srand((unsigned)55); // initialize the random number generator to the same // seed for repeatability #endif curLine = lcdNUM_SMALL_LINES - 1; // This task should never exit for (;;) { #ifdef INSPECT_STACK CurrentStackLeft = uxTaskGetStackHighWaterMark(NULL); float remainingStack = CurrentStackLeft; remainingStack /= lcdSTACK_SIZE; if (remainingStack < 0.10) { // If the stack is really low, stop everything because we don't want it to // run out VT_HANDLE_FATAL_ERROR(0); } #endif #if LCD_EXAMPLE_OP == 0 // Wait for a message if (xQueueReceive(lcdPtr->inQ, (void *)&msgBuffer, portMAX_DELAY) != pdTRUE) { VT_HANDLE_FATAL_ERROR(0); } // Log that we are processing a message -- more explanation of logging is // given later on vtITMu8(vtITMPortLCDMsg, getMsgType(&msgBuffer)); vtITMu8(vtITMPortLCDMsg, getMsgLength(&msgBuffer)); // Take a different action depending on the type of the message that we // received switch (getMsgType(&msgBuffer)) { case LCDMsgTypePrint: { // This will result in the text printing in the last five lines of the // screen char lineBuffer[lcdCHAR_IN_LINE + 1]; copyMsgString(lineBuffer, &msgBuffer, lcdCHAR_IN_LINE); // clear the line GLCD_ClearLn(curLine, 1); // show the text GLCD_DisplayString(curLine, 0, 0, (unsigned char *)lineBuffer); curLine++; if (curLine == lcdNUM_SMALL_LINES) { curLine = lcdNUM_SMALL_LINES - 1; } break; } case LCDMsgTypePoint: { graphVals[graphStart] = getMsgPoint(&msgBuffer); break; } case LCDMsgTypeTimer: { // Note: if I cared how long the timer update was I would call my // routine // unpackTimerMsg() which would unpack the message and get that value // Each timer update will cause a circle to be drawn on the top half of // the screen // as explained below if (timerCount % 2 == 0) { /* ************************************************** */ // Find a new color for the screen by randomly (within limits) // selecting // HSL values // This can be ignored unless you care about the color map /* #if MALLOC_VERSION==1 hue = rand() % 360; sat = (rand() % 1024) / 1023.0; sat = sat * 0.5; sat += 0.5; light = (rand() % 1024) / 1023.0; light = light * 0.8; light += 0.10; #else hue = (hue + 1); if (hue >= 360) hue = 0; sat+=0.01; if (sat > 1.0) sat = 0.20; light+=0.03; if (light > 1.0) light = 0.20; #endif screenColor = hsl2rgb(hue,sat,light); // Now choose a complementary value for the text color hue += 180; if (hue >= 360) hue -= 360; tscr = hsl2rgb(hue,sat,light); GLCD_SetTextColor(tscr); GLCD_SetBackColor(screenColor); unsigned short int *tbuffer = buffer; //int i; for(i = BUF_LEN; i--;) { tbuffer[i] = screenColor; } */ // End of playing around with figuring out a random color /* ************************************************** */ // clear the top half of the screen // GLCD_ClearWindow(0,0,320,120,screenColor); /* // Now we are going to draw a circle in the buffer // count is how many pixels are in the circle int count = 50; float radius; float inc, val, offset = MAX_RADIUS; unsigned short circleColor; inc = 2*M_PI/count; xmax = 0; ymax = 0; xmin = 50000; ymin = 50000; val = 0.0; for (i=0;i<count;i++) { // Make the circle a little thicker // by actually drawing three circles w/ different radii float cv = cos(val), sv=sin(val); circleColor = (val*0xFFFF)/(2*M_PI); GLCD_SetTextColor(circleColor); for (radius=MAX_RADIUS-2.0;radius<=MAX_RADIUS;radius+=1.0) { x = round(cv*radius+offset); y = round(sv*radius+offset); if (x > xmax) xmax = x; if (y > ymax) ymax = y; if (x < xmin) xmin = x; if (y < ymin) ymin = y; //tbuffer[(y*((MAX_RADIUS*2)+1)) + x] = circleColor; } val += inc; } */ // GLCD_ClearWindow(graphXoff, graphYoff, graphWidth, graphHeight, // screenColor); graphStart = (graphStart + 1) % graphWidth; DEBUG_OUT(0xf); for (i = 0; i < graphWidth; i++) { unsigned index = (i + graphStart) % graphWidth; unsigned y = graphHeight - graphVals[index] + graphYoff; unsigned x = i + graphXoff; GLCD_ClearWindow(x, graphYoff, 1, graphHeight, screenColor); GLCD_PutPixel(x, y); } DEBUG_OUT(0x0); } // else { // We are going to write out the buffer // back onto the screen at a new location // This is *very* fast /* // First, clear out where we were GLCD_ClearWindow(xoffset,yoffset,xmax+1-xmin,ymax+1-ymin,screenColor); // Pick the new location #if MALLOC_VERSION==1 xoffset = rand() % (320-(xmax+1-xmin)); yoffset = rand() % (120-(ymax+1-ymin)); #else xoffset = (xoffset + 10) % (320-(xmax+1-xmin)); yoffset = (yoffset + 10) % (120-(ymax+1-ymin)); #endif // Draw the bitmap GLCD_Bitmap(xoffset,yoffset,xmax+1-xmin,ymax-1-ymin,(unsigned char*)buffer); */ //} timerCount++; if (timerCount >= 100) { // every so often, we reset timer count and start again // This isn't for any important reason, it is just to for this example // code to do "stuff" timerCount = 0; } break; } default: { // In this configuration, we are only expecting to receive timer // messages VT_HANDLE_FATAL_ERROR(getMsgType(&msgBuffer)); break; } } // end of switch() // Here is a way to do debugging output via the built-in hardware -- it requires // the ULINK cable and the debugger in the Keil tools to be connected. You can // view PORT0 output in the "Debug(printf) Viewer" under "View->Serial Windows". // You have to enable "Trace" and "Port0" in the Debug setup options. This // should not be used if you are using Port0 for printf(). There are 31 other // ports and their output (and port 0's) can be seen in the // "View->Trace->Records" windows. You have to enable the ports in the Debug // setup options. Note that unlike ITM_SendChar() this "raw" port write is not // blocking. That means it can overrun the capability of the system to record // the trace events if you go too quickly; that won't hurt anything or change // the program execution and you can tell if it happens because the // "View->Trace->Records" window will show there was an overrun. // vtITMu16(vtITMPortLCD,screenColor); #elif LCD_EXAMPLE_OP == 1 // In this alternate version, we just keep redrawing a series of bitmaps as // we receive timer messages // Wait for a message if (xQueueReceive(lcdPtr->inQ, (void *)&msgBuffer, portMAX_DELAY) != pdTRUE) { VT_HANDLE_FATAL_ERROR(0); } if (getMsgType(&msgBuffer) != LCDMsgTypeTimer) { // In this configuration, we are only expecting to receive timer messages VT_HANDLE_FATAL_ERROR(getMsgType(&msgBuffer)); } /* go through a bitmap that is really a series of bitmaps */ picIndex = (picIndex + 1) % 9; GLCD_Bmp(99, 99, 120, 45, (unsigned char *)&ARM_Ani_16bpp[picIndex * (120 * 45 * 2)]); #else Bad setting #endif } }
void Draw_CHICKEN2(int y0 ){ GLCD_SetTextColor(Red); GLCD_PutPixel(319-21,y0); GLCD_PutPixel(319-17,y0+1); GLCD_PutPixel(319-18,y0+1); Draw_lineX2( 319-20, y0+1, 319-22); Draw_lineX2(319-17, y0+2, 319-23); Draw_lineX2(319-16, y0+3, 319-23); Draw_lineX2(319-17, y0+4, 319-22); GLCD_PutPixel(319-18, y0+5); GLCD_SetTextColor(Orange); Draw_lineX2(319-25, y0+7, 319-28); Draw_lineX2(319-25, y0+8, 319-26); Draw_lineX2(319-25, y0+9, 319-28); Draw_lineX2(319-25, y0+10, 319-26); GLCD_SetTextColor(Black); GLCD_PutPixel(319-19, y0+9); GLCD_PutPixel(319-20, y0+9); GLCD_SetTextColor(Yellow); Draw_lineX2(319-19,y0+5,319-22); Draw_lineX2(319-17,y0+6,319-23); Draw_lineX2(319-17,y0+7,319-24); Draw_lineX2(319-16,y0+8,319-24); Draw_lineX2(319-15,y0+9,319-24); Draw_lineX2(319-14,y0+10,319-24); Draw_lineX2(319-14,y0+11,319-24); Draw_lineX2(319-13,y0+12,319-24); Draw_lineX2(319-12,y0+13,319-22); Draw_lineX2(319-11,y0+14,319-22); Draw_lineX2(319-10,y0+15,319-22); Draw_lineX2(319-2,y0+16,319-22); Draw_lineX2(319-0,y0+17,319-22); Draw_lineX2(319-0,y0+18,319-22); Draw_lineX2(319-0,y0+19,319-22); Draw_lineX2(319-2,y0+20,319-21); Draw_lineX2(319-4,y0+21,319-21); Draw_lineX2(319-2,y0+22,319-21); Draw_lineX2(319-0,y0+23,319-20); Draw_lineX2(319-1,y0+24,319-20); Draw_lineX2(319-1,y0+25,319-20); Draw_lineX2(319-2,y0+26,319-19); Draw_lineX2(319-3,y0+27,319-18); Draw_lineX2(319-3,y0+28,319-17); Draw_lineX2(319-4,y0+29,319-16); Draw_lineX2(319-5,y0+30,319-15); Draw_lineX2(319-6,y0+31,319-14); //Tail GLCD_PutPixel(319-0, y0+10); Draw_lineX2(319-0, y0+9, 319-1); Draw_lineX2(319-0, y0+10, 319-2); Draw_lineX2(319-0, y0+11, 319-3); Draw_lineX2(319-1, y0+12, 319-4); Draw_lineX2(319-1, y0+13, 319-5); Draw_lineX2(319-2, y0+14, 319-6); Draw_lineX2(319-3, y0+15, 319-7); GLCD_SetTextColor(Black); GLCD_PutPixel(319-20, y0+8); GLCD_PutPixel(319-21, y0+8); GLCD_PutPixel(319-19, y0+9); GLCD_PutPixel(319-20, y0+9); }
void Draw_CHICKEN1(int y0 ){ GLCD_SetTextColor(Red); GLCD_PutPixel(21,y0); GLCD_PutPixel(17,y0+1); GLCD_PutPixel(18,y0+1); Draw_lineX( 20, y0+1, 22); Draw_lineX(17, y0+2, 23); Draw_lineX(16, y0+3, 23); Draw_lineX(17, y0+4, 22); GLCD_PutPixel(18, y0+5); GLCD_SetTextColor(Orange); Draw_lineX(25, y0+7, 28); Draw_lineX(25, y0+8, 26); Draw_lineX(25, y0+9, 28); Draw_lineX(25, y0+10, 26); GLCD_SetTextColor(Black); GLCD_PutPixel(19, y0+9); GLCD_PutPixel(20, y0+9); GLCD_SetTextColor(Yellow); Draw_lineX(19,y0+5,22); Draw_lineX(17,y0+6,23); Draw_lineX(17,y0+7,24); Draw_lineX(16,y0+8,24); Draw_lineX(15,y0+9,24); Draw_lineX(14,y0+10,24); Draw_lineX(14,y0+11,24); Draw_lineX(13,y0+12,24); Draw_lineX(12,y0+13,22); Draw_lineX(11,y0+14,22); Draw_lineX(10,y0+15,22); Draw_lineX(2,y0+16,22); Draw_lineX(0,y0+17,22); Draw_lineX(0,y0+18,22); Draw_lineX(0,y0+19,22); Draw_lineX(2,y0+20,21); Draw_lineX(4,y0+21,21); Draw_lineX(2,y0+22,21); Draw_lineX(0,y0+23,20); Draw_lineX(1,y0+24,20); Draw_lineX(1,y0+25,20); Draw_lineX(2,y0+26,19); Draw_lineX(3,y0+27,18); Draw_lineX(3,y0+28,17); Draw_lineX(4,y0+29,16); Draw_lineX(5,y0+30,15); Draw_lineX(6,y0+31,14); //Tail GLCD_PutPixel(0, y0+10); Draw_lineX(0, y0+9, 1); Draw_lineX(0, y0+10, 2); Draw_lineX(0, y0+11, 3); Draw_lineX(1, y0+12, 4); Draw_lineX(1, y0+13, 5); Draw_lineX(2, y0+14, 6); Draw_lineX(3, y0+15, 7); GLCD_SetTextColor(Black); GLCD_PutPixel(20, y0+8); GLCD_PutPixel(21, y0+8); GLCD_PutPixel(19, y0+9); GLCD_PutPixel(20, y0+9); }
/*---------------------------------------------------------------------------- MAIN function *----------------------------------------------------------------------------*/ int main (void) { /* Main Program */ //************************************************************************************************************ /* this is contiki-code */ watchdog_init(); /* Initialize hardware. */ clock_init(); /* UART4 Initialization */ // uart4_init(115200); USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb); // Led initialization leds_init(); leds_on(LEDS_BLUE); PRINTF("\r\nStarting "); PRINTF(CONTIKI_VERSION_STRING); PRINTF(" on %s \r\n", PLATFORM_NAME); #ifdef __USE_LCD GLCD_Init(); /* Initialize graphical LCD display */ GLCD_Clear(White); /* Clear graphical LCD display */ GLCD_SetBackColor(DarkGreen); GLCD_SetTextColor(White); GLCD_DisplayString(0, 0, __FI, " KUSZ - TU Dortmund "); GLCD_DisplayString(1, 0, __FI, " contiki "); GLCD_DisplayString(2, 0, __FI, " www.tu-dortmund.de "); GLCD_SetBackColor(White); GLCD_SetTextColor(Blue); watchdog_periodic(); #endif // __USE_LCD /* * Initialize Contiki and our processes. */ #ifdef WITH_SERIAL_LINE_INPUT // uart1_set_input(serial_line_input_byte); // serial_line_init(); #endif /* rtimer and ctimer should be initialized before radio duty cycling layers*/ rtimer_init(); process_init(); process_start(&sensors_process, NULL); /* etimers must be started before ctimer_init */ process_start(&etimer_process, NULL); ctimer_init(); /* Start radio and radio receive process */ NETSTACK_RADIO.init(); /* makes use of cpu-specific RNG peripheral - no seed needed */ random_init(0); /* Set addresses BEFORE starting tcpip process */ addr.u8[0] = 0x02; addr.u8[1] = *((uint8_t*)0x1FFF7A10); addr.u8[2] = *((uint8_t*)0x1FFF7A10+1); addr.u8[3] = 0xFF; addr.u8[4] = 0xFE; addr.u8[5] = *((uint8_t*)0x1FFF7A10+2); addr.u8[6] = *((uint8_t*)0x1FFF7A10+3); addr.u8[7] = *((uint8_t*)0x1FFF7A10+4); memcpy(&uip_lladdr.addr, &addr.u8, sizeof(rimeaddr_t)); rimeaddr_set_node_addr(&addr); rf230_set_pan_addr(0xabcd,0xbabe,(uint8_t *)&addr.u8); rf230_set_channel(CHANNEL_802_15_4); rf230_set_txpower(0); /* max */ PRINTF("EUI-64 MAC: %x-%x-%x-%x-%x-%x-%x-%x\n",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]); /* Initialize stack protocols */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); #define ANNOUNCE_BOOT 1 #if ANNOUNCE_BOOT PRINTF("%s %s, channel %u , check rate %u Hz tx power %u\n",NETSTACK_MAC.name, NETSTACK_RDC.name, rf230_get_channel(), CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:NETSTACK_RDC.channel_check_interval()), rf230_get_txpower()); #if UIP_CONF_IPV6_RPL PRINTF("RPL Enabled\n"); #endif #if UIP_CONF_ROUTER PRINTF("Routing Enabled\n"); #endif #endif /* ANNOUNCE_BOOT */ process_start(&tcpip_process, NULL); /* Autostart other processes */ autostart_start(autostart_processes); #if ANNOUNCE_BOOT PRINTF("Online\n"); #endif /* ANNOUNCE_BOOT */ energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); watchdog_start(); while (1) { /* Loop forever */ watchdog_periodic(); process_run(); } }
int_t main(void) { error_t error; NetInterface *interface; OsTask *task; MacAddr macAddr; #if (APP_USE_DHCP == DISABLED) Ipv4Addr ipv4Addr; #endif #if (APP_USE_SLAAC == DISABLED) Ipv6Addr ipv6Addr; #endif //Initialize kernel osInitKernel(); //Configure debug UART debugInit(115200); //Start-up message TRACE_INFO("\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("*** CycloneTCP Web Server Demo ***\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("Copyright: 2010-2014 Oryx Embedded\r\n"); TRACE_INFO("Compiled: %s %s\r\n", __DATE__, __TIME__); TRACE_INFO("Target: SAM3X\r\n"); TRACE_INFO("\r\n"); //Configure I/Os ioInit(); //ADC initialization adcInit(); //Initialize LCD display GLCD_Init(); GLCD_SetBackColor(Blue); GLCD_SetTextColor(White); GLCD_Clear(Blue); //Welcome message lcdSetCursor(0, 0); printf("Web Server Demo\r\n"); //Generate a random seed //PRNG initialization error = yarrowInit(&yarrowContext); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize PRNG!\r\n"); } //Properly seed the PRNG error = yarrowSeed(&yarrowContext, seed, sizeof(seed)); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to seed PRNG!\r\n"); } //TCP/IP stack initialization error = tcpIpStackInit(); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize TCP/IP stack!\r\n"); } //Configure the first Ethernet interface interface = &netInterface[0]; //Set interface name tcpIpStackSetInterfaceName(interface, "eth0"); //Set host name tcpIpStackSetHostname(interface, "WebServerDemo"); //Select the relevant network adapter tcpIpStackSetDriver(interface, &sam3xEthDriver); tcpIpStackSetPhyDriver(interface, &dm9161PhyDriver); //Set external interrupt line driver tcpIpStackSetExtIntDriver(interface, &extIntDriver); //Set host MAC address macStringToAddr(APP_MAC_ADDR, &macAddr); tcpIpStackSetMacAddr(interface, &macAddr); //Initialize network interface error = tcpIpStackConfigInterface(interface); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to configure interface %s!\r\n", interface->name); } #if (IPV4_SUPPORT == ENABLED) #if (APP_USE_DHCP == ENABLED) //Get default settings dhcpClientGetDefaultSettings(&dhcpClientSettings); //Set the network interface to be configured by DHCP dhcpClientSettings.interface = interface; //Disable rapid commit option dhcpClientSettings.rapidCommit = FALSE; //DHCP client initialization error = dhcpClientInit(&dhcpClientContext, &dhcpClientSettings); //Failed to initialize DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to initialize DHCP client!\r\n"); } //Start DHCP client error = dhcpClientStart(&dhcpClientContext); //Failed to start DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to start DHCP client!\r\n"); } #else //Set IPv4 host address ipv4StringToAddr(APP_IPV4_HOST_ADDR, &ipv4Addr); ipv4SetHostAddr(interface, ipv4Addr); //Set subnet mask ipv4StringToAddr(APP_IPV4_SUBNET_MASK, &ipv4Addr); ipv4SetSubnetMask(interface, ipv4Addr); //Set default gateway ipv4StringToAddr(APP_IPV4_DEFAULT_GATEWAY, &ipv4Addr); ipv4SetDefaultGateway(interface, ipv4Addr); //Set primary and secondary DNS servers ipv4StringToAddr(APP_IPV4_PRIMARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 0, ipv4Addr); ipv4StringToAddr(APP_IPV4_SECONDARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 1, ipv4Addr); #endif #endif #if (IPV6_SUPPORT == ENABLED) #if (APP_USE_SLAAC == ENABLED) //Get default settings slaacGetDefaultSettings(&slaacSettings); //Set the network interface to be configured slaacSettings.interface = interface; //SLAAC initialization error = slaacInit(&slaacContext, &slaacSettings); //Failed to initialize SLAAC? if(error) { //Debug message TRACE_ERROR("Failed to initialize SLAAC!\r\n"); } //Start IPv6 address autoconfiguration process error = slaacStart(&slaacContext); //Failed to start SLAAC process? if(error) { //Debug message TRACE_ERROR("Failed to start SLAAC!\r\n"); } #else //Set link-local address ipv6StringToAddr(APP_IPV6_LINK_LOCAL_ADDR, &ipv6Addr); ipv6SetLinkLocalAddr(interface, &ipv6Addr, IPV6_ADDR_STATE_VALID); //Set IPv6 prefix ipv6StringToAddr(APP_IPV6_PREFIX, &ipv6Addr); ipv6SetPrefix(interface, &ipv6Addr, APP_IPV6_PREFIX_LENGTH); //Set global address ipv6StringToAddr(APP_IPV6_GLOBAL_ADDR, &ipv6Addr); ipv6SetGlobalAddr(interface, &ipv6Addr, IPV6_ADDR_STATE_VALID); //Set router ipv6StringToAddr(APP_IPV6_ROUTER, &ipv6Addr); ipv6SetRouter(interface, &ipv6Addr); //Set primary and secondary DNS servers ipv6StringToAddr(APP_IPV6_PRIMARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 0, &ipv6Addr); ipv6StringToAddr(APP_IPV6_SECONDARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 1, &ipv6Addr); #endif #endif //Get default settings httpServerGetDefaultSettings(&httpServerSettings); //Bind HTTP server to the desired interface httpServerSettings.interface = &netInterface[0]; //Listen to port 80 httpServerSettings.port = HTTP_PORT; //Specify the server's root directory strcpy(httpServerSettings.rootDirectory, "/www/"); //Set default home page strcpy(httpServerSettings.defaultDocument, "index.shtm"); //Callback functions httpServerSettings.authCallback = httpServerAuthCallback; httpServerSettings.cgiCallback = httpServerCgiCallback; httpServerSettings.uriNotFoundCallback = httpServerUriNotFoundCallback; //HTTP server initialization error = httpServerInit(&httpServerContext, &httpServerSettings); //Failed to initialize HTTP server? if(error) { //Debug message TRACE_ERROR("Failed to initialize HTTP server!\r\n"); } //Start HTTP server error = httpServerStart(&httpServerContext); //Failed to start HTTP server? if(error) { //Debug message TRACE_ERROR("Failed to start HTTP server!\r\n"); } //Start TCP echo service error = tcpEchoStart(); //Failed to TCP echo service? if(error) { //Debug message TRACE_ERROR("Failed to start TCP echo service!\r\n"); } //Start UDP echo service error = udpEchoStart(); //Failed to TCP echo service? if(error) { //Debug message TRACE_ERROR("Failed to start UDP echo service!\r\n"); } //Start TCP discard service error = tcpDiscardStart(); //Failed to TCP echo service? if(error) { //Debug message TRACE_ERROR("Failed to start TCP discard service!\r\n"); } //Start UDP discard service error = udpDiscardStart(); //Failed to TCP echo service? if(error) { //Debug message TRACE_ERROR("Failed to start UDP discard service!\r\n"); } //Start TCP chargen service error = tcpChargenStart(); //Failed to TCP echo service? if(error) { //Debug message TRACE_ERROR("Failed to start TCP chargen service!\r\n"); } //Start UDP chargen service error = udpChargenStart(); //Failed to TCP echo service? if(error) { //Debug message TRACE_ERROR("Failed to start UDP chargen service!\r\n"); } //Create user task task = osCreateTask("User Task", userTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Create a task to blink the LED task = osCreateTask("Blink", blinkTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Start the execution of tasks osStartKernel(); //This function should never return return 0; }
void Vectored_Interrupt(int button){ char cString[4], currDiffString[4]; //GLCD_Clear(White); /* Clear graphical LCD display */ GLCD_SetBackColor(Blue); GLCD_SetTextColor(White); switch(button){ case USER_BUTTON: //GLCD_DisplayString(0, 0, __FI, "< --User Button -- >"); switch(currentState) { case WELCOME_SCREEN: // If on the welcome screen, set up difficulty screen GLCD_Clear(White); if(currentDifficulty == 0){ currentDifficulty = 1; } updateNextDifficulty(nextDifficulty); DisplayInstructions(); DrawBarGraph(BAR_X,BAR_Y,currentDifficulty * 20,BAR_HEIGHT,BAR_VALUE); currentState = DIFFICULTY_SCREEN; break; case DIFFICULTY_SCREEN: // Transition to Question Screen updateScoreAndDifficulty(currentScore, currentDifficulty, nextDifficulty); currentDifficulty = nextDifficulty; // Set the difficulty currentState = QUESTION_SCREEN; questionScreen(); // Display the question screen break; case QUESTION_SCREEN: // Question Screen uses countdown timer - no inputs break; case ANSWER_SCREEN: //answerScreen(); currentState = MARKING_SCREEN; // Mark the users answer break; case MARKING_SCREEN: // Mark the users answer attempt markAnswer(); currentDifficulty = nextDifficulty; // Set the difficulty currentState = NEXT_QUESTION; break; case NEXT_QUESTION: // Move on to next question currentDifficulty = nextDifficulty; // Set the difficulty currentState = QUESTION_SCREEN; questionScreen(); // Display the question screen break; }; //GLCD_DisplayString(6, 0, __FI, GenerateRandomString(5)); //doTone = ~doTone; break; case JOYSTICK_SELECT: //GLCD_DisplayString(0, 0, __FI, "< --JSTK Select -->"); // Left available for future program improvements break; case JOYSTICK_UP: //GLCD_DisplayString(0, 0, __FI, "< --JSTK UP -- >"); inputAnswer(JOYSTICK_UP); break; case JOYSTICK_DOWN: //GLCD_DisplayString(0, 0, __FI, "< --JSTK DOWN -- >"); inputAnswer(JOYSTICK_DOWN); break; case JOYSTICK_RIGHT: //GLCD_DisplayString(0, 0, __FI, "< --JSTK RIGHT-- >"); inputAnswer(JOYSTICK_RIGHT); break; case JOYSTICK_LEFT: //GLCD_DisplayString(0, 0, __FI, "< --JSTK LEFT -- >"); inputAnswer(JOYSTICK_LEFT); break; case POTENTIOMETER_TURNED: //sprintf(cString, "%02d", c); switch(currentState) { case DIFFICULTY_SCREEN: nextDifficulty = (c / 3) + 1; nextDifficulty = nextDifficulty > 5 ? 5 : nextDifficulty; sprintf(currDiffString, "%1d", nextDifficulty); //updateScoreAndDifficulty(currentScore, currDifficulty, nextDifficulty); updateNextDifficulty(nextDifficulty); DrawBarGraph(BAR_X,BAR_Y,nextDifficulty * 20,BAR_HEIGHT,BAR_VALUE); //GLCD_SetBackColor(Red); break; case WELCOME_SCREEN: break; default: nextDifficulty = (c / 3) + 1; nextDifficulty = nextDifficulty > 5 ? 5 : nextDifficulty; sprintf(currDiffString, "%1d", nextDifficulty); updateScoreAndDifficulty(currentScore, currentDifficulty, nextDifficulty); break; } break; default: break; } }
// This is the actual task that is run static portTASK_FUNCTION( vLCDUpdateTask, pvParameters ) { portTickType xUpdateRate, xLastUpdateTime; vtLCDMsg msgBuffer; vtLCDStruct *lcdPtr = (vtLCDStruct *) pvParameters; //counter for line display //uint8_t counter = 0; /* Initialize the LCD */ GLCD_Init(); GLCD_Clear(White); const char line_0[] = "Calc. Position"; const char line_2[] = "Bearing from #0"; const char line_4[] = "GPS"; const char line_6[] = "Bearing from GPS"; const char line_8[] = "RSSI [0, 1, 2]"; int initial = 0; // Scale the update rate to ensure it really is in ms xUpdateRate = lcdWRITE_RATE_BASE / portTICK_RATE_MS; /* We need to initialise xLastUpdateTime prior to the first call to vTaskDelayUntil(). */ xLastUpdateTime = xTaskGetTickCount(); // Note that srand() & rand() require the use of malloc() and should not be used unless you are using // MALLOC_VERSION==1 #if MALLOC_VERSION==1 srand((unsigned) 55); // initialize the random number generator to the same seed for repeatability #endif // Like all good tasks, this should never exit for(;;) { if (LCD_STATE == 2){ /* Ask the RTOS to delay reschduling this task for the specified time */ vTaskDelayUntil( &xLastUpdateTime, xUpdateRate ); // wait for a message from another task telling us to send/recv over i2c if (xQueueReceive(lcdPtr->inQ,(void *) &msgBuffer,portMAX_DELAY) != pdTRUE) { VT_HANDLE_FATAL_ERROR(0); } //Log that we are processing a message vtITMu8(vtITMPortLCDMsg,msgBuffer.length); if (msgBuffer.buf[0] == 0xDE && msgBuffer.buf[1] == 0xAD && msgBuffer.buf[2] == 0xBE){ GLCD_Clear(White); LCD_STATE = 3; } else { char buf[21]; sprintf(buf, "%4.6f, %4.6f", msgBuffer.tlat, msgBuffer.tlon); GLCD_DisplayString(0,0,1,(unsigned char *)msgBuffer.buf); GLCD_DisplayString(1,0,1,(unsigned char *) buf); } } else if (LCD_STATE == 3){ /* Ask the RTOS to delay reschduling this task for the specified time */ //vTaskDelayUntil( &xLastUpdateTime, xUpdateRate ); // wait for a message from another task telling us to send/recv over i2c if (xQueueReceive(lcdPtr->inQ,(void *) &msgBuffer,portMAX_DELAY) != pdTRUE) { VT_HANDLE_FATAL_ERROR(0); } #if USE_GPIO == 1 GPIO_SetValue(1, 0x20000000); #endif //Log that we are processing a message vtITMu8(vtITMPortLCDMsg,msgBuffer.length); // Decide what color and then clear the line GLCD_SetTextColor(Black); GLCD_SetBackColor(White); if(!initial){ GLCD_DisplayString(0, 0, 1, (unsigned char *)line_0); GLCD_DisplayString(2, 0, 1, (unsigned char *)line_2); GLCD_DisplayString(4, 0, 1, (unsigned char *)line_4); GLCD_DisplayString(6, 0, 1, (unsigned char *)line_6); GLCD_DisplayString(8, 0, 1, (unsigned char *)line_8); initial++; } GLCD_DisplayString(msgBuffer.line_num + 1, 0, 1, (unsigned char *)msgBuffer.buf); #if USE_GPIO == 1 GPIO_ClearValue(1, 0x20000000); #endif } else{ // Bad setting } } }