void bmp_drawTest(char * bmp_name, unsigned int x, unsigned int y) { unsigned int i=0; // unsigned char * lookup_table = &bmp_lookup_table[0]; unsigned long bmp_loc=0; unsigned int index; uint8_t nameLength; //uint8_t bmpNameLen = strlen(bmp_name); COLOR black = {0,0,0}; COLOR white = {255,255,255}; cli(); //disable interrupts bmp_loc = bmp_find(bmp_name); /* Bitmap not found error handling here */ #if 0 if (bmp_loc == 0) { /* Display the not found placeholder */ dispPutS(bmp_name,x,y,white,black); return; } #endif unsigned char bmp_buff[DATAFLASH_PAGESIZE]; /* Get the width and height */ dataflash_read_block(bmp_buff,bmp_loc,4); uint16_t width = (uint16_t)(bmp_buff[0]<<8) + bmp_buff[1]; uint16_t height = (uint16_t)(bmp_buff[2]<<8) + bmp_buff[3]; uint32_t length = (uint32_t)width * (uint32_t)height; uint16_t byteCnt=0; dispSetWindow(x,y,width-1,height); /* Incremement the bmp pointer passed the width/height */ bmp_loc+=4; dataflash_read_block(bmp_buff, bmp_loc, DATAFLASH_PAGESIZE); while (length--) { GraphicsColor.blue = bmp_buff[byteCnt]; GraphicsColor.green = bmp_buff[byteCnt+1]; GraphicsColor.red = bmp_buff[byteCnt+2]; dispPix(); byteCnt+=3; if (byteCnt>=528) { bmp_loc+=528; dataflash_read_block(bmp_buff, bmp_loc, DATAFLASH_PAGESIZE); byteCnt=0; } } sei(); //enable interrupts }
//******************************************************************************* //* This is where we get the chunks of data //* to program to the dataflash //******************************************************************************* void image_interface_begin(void) { unsigned int page_count = 0; unsigned char command = 0; unsigned char *buff; unsigned int page_num = 0; boolean keepGoing; #ifdef _TOUCH_STEALTH_ COLOR black = {0,0,0}; COLOR white = {255,255,255}; #endif /* order of operations: 1.) purge usart buffers 2.) recv mode byte 3.) if mode == STORE, recv page_count recv all pages else mode == READ send page_count send pages */ #ifdef _USE_DBBUG_RECT_STATUS_ DebugRectPrintText("image_interface_begin()"); #endif arduinoReset(); usart_init(115200); // usart_init(57600); #ifdef _USE_DBBUG_RECT_STATUS_ DebugRectPrintText("usart_init 115200"); #endif #ifdef _USE_DBBUG_RECT_STATUS_ DebugRectPrintText("arduino in reset"); #endif cli(); buff = usart_getBuff_ptr(); //enough setup, lets begin keepGoing = TRUE; while(keepGoing) { usart_read_bytes(1); // Wait for us to read a byte command = buff[0]; // store or read command #ifdef _TOUCH_STEALTH_ if (command == IMAGE_INTERFACE_ERASE) { dispPutS("Erasing",0,0,white,black); dataflash_erase(); usart_putc(IMAGE_INTERFACE_PAGE_DONE); //ok dispPutS("Erasing Done",0,10,white,black); } else #endif if (command == IMAGE_INTERFACE_STORE) { unsigned int x; unsigned int ii,wait,wait2; unsigned char out_data[DATAFLASH_PAGESIZE],in_data[DATAFLASH_PAGESIZE]; #ifdef _USE_DBBUG_RECT_STATUS_ DebugRectPrintText("IMAGE_INTERFACE_STORE"); #endif buff = usart_getBuff_ptr(); dataflash_erase(); usart_putc(IMAGE_INTERFACE_PAGE_DONE); //done erasing #ifdef _USE_DBBUG_RECT_STATUS_ DebugRectPrintText("done erasing "); #endif //give us the number of pages you're sending usart_read_bytes(2); page_count = (buff[0] << 8) + buff[1]; //number of pages for (ii=0; ii< page_count; ii++) { unsigned int buffer_count = 0; #ifdef _USE_DBBUG_RECT_STATUS_ // DebugRectPrintText("Page"); #endif usart_read_bytes(DATAFLASH_PAGESIZE); //read the whole page buffer_count = usart_getBuff_size(); //program the whole page for(x=0;x<DATAFLASH_PAGESIZE;x++) { out_data[x] = buff[x]; } dataflash_program_page(&out_data[0], ii); //program the page for(x=0;x<DATAFLASH_PAGESIZE;x++) in_data[x] = 0x00; dataflash_cont_read(&in_data[0], ii, DATAFLASH_PAGESIZE); for (x=0;x<DATAFLASH_PAGESIZE;x++) { if (x==256) { for (wait = 0; wait < 254; wait++) { for (wait2 = 0; wait2 < 254; wait2++) { asm("nop"); } } } usart_putc(in_data[x]); asm("nop"); } } } else if (command == IMAGE_INTERFACE_READ) { unsigned int x; unsigned char out[DATAFLASH_PAGESIZE]; #ifdef _USE_DBBUG_RECT_STATUS_ DebugRectPrintText("IMAGE_INTERFACE_READ"); #endif page_num=0; //give us the number of pages you're sending usart_read_bytes(2); page_num = (buff[0] << 8) + buff[1]; //number of pages dataflash_cont_read(&out[0], page_num, DATAFLASH_PAGESIZE); for (x=0; x<DATAFLASH_PAGESIZE; x++) { usart_putc(out[x]); } asm("nop"); } else if (command == IMAGE_INTERFACE_INFO) { short ii; char validImage; short bmpWidth; short bmpHeight; char displayLine[64]; usart_puts("\nTouch Shield | ver 002\n"); usart_putc(0); ii = 0; validImage = TRUE; while (validImage && (ii < BMP_MAXBMP_COUNT)) { bmp_get_entryname(ii, displayLine, &bmpWidth, &bmpHeight); usart_puts(displayLine); usart_puts("\n"); ii++; } } else if (command == IMAGE_INTERFACE_EXIT) { usart_puts("Exit Command\n"); sei(); //enable interrupts bmp_init(); usart_putc(IMAGE_INTERFACE_PAGE_DONE); //ok arduinoRun(); keepGoing = FALSE; // break; } }//end while } //end function
//******************************************************************************* void DisplaySplashScreen(void) { COLOR bgColor; COLOR fontColor; int ii; int yTextLoc; #ifdef _STARTUPSCREEN_VERSION_ char startupMsg[128]; #endif #ifdef _STARTUPSCREEN_VERSION_ bgColor.red = 0; bgColor.green = 0; bgColor.blue = 0; fontColor.red = 0; fontColor.green = 255; fontColor.blue = 0; //* display the overall library version yTextLoc = 10; strcpy(startupMsg, kDisplayHardwareString); strcat(startupMsg, " "); strcat(startupMsg, kDisplayHardwareVersion); dispPutS(startupMsg, 5, yTextLoc, fontColor, bgColor); yTextLoc += kLinrSpacing; //* display the SubProcessing library version strcpy(startupMsg, "Arduino Procssing Library "); strcat(startupMsg, kSubP_VersionString); strcat(startupMsg, " "); #ifdef _SUBP_OPTION_GAMES_ strcat(startupMsg, "+G"); #endif #ifdef _SUBP_OPTION_KEYBOARD_ strcat(startupMsg, "+K"); #endif dispPutS(startupMsg, 5, yTextLoc, fontColor, bgColor); yTextLoc += kLinrSpacing; #endif #ifdef _DEBUG_RECTS_ dispColor(bgColor); ii = kSCREEN_Y_size / 2; ii -= 25; ii = kSCREEN_Y_size / 3; while (ii > 30) { fill(random(255), random(255), random(255)); stroke(random(255), random(255), random(255)); drawrect((kSCREEN_X_size / 2) - ii, (kSCREEN_Y_size / 2) - ii, (ii * 2), (ii * 2)); ii -= 10; } fill(0); stroke(255); #endif #ifdef _STARTUPSCREEN_LIQUIDWARE_ for (ii=0; ii<190; ii+=10) { //* this is the FADE color, how much to subtract from the actual colors //* 0 means none. bgColor.red = ii; bgColor.green = ii; bgColor.blue = ii; DisplayRLE_RGB(gLiquidWareLogo, &bgColor, false, kMatixTopOffset); #ifdef _STARTUPSCREEN_MATRIX_ if (ii > 100) { MatrixDisplay(kMatixTopOffset, 3); } #endif } #endif #ifdef _STARTUPSCREEN_MATRIX_ ii = 0; while(!serialAvailable() && (ii < 2000)) { MatrixDisplay(kMatixTopOffset, 2); ii++; gettouch(); if ((mouseX > 200) && (mouseY < 100)) { break; } } #endif #ifdef _SUBP_OPTION_7_SEGMENT_dontDisplay int xx, yy; // dispClearScreen(); xx = 10; yy = 50; for (ii=5; ii<30; ii += 4) { Display7SegmentString(xx, yy, "0123456789ABCDEF", ii); yy += (ii * 2); yy += 8; if (ii > 230) { break; } } while (true) { //* do nothing } #endif bgColor.red = 0; bgColor.green = 0; bgColor.blue = 0; dispColor(bgColor); // drawrect(0, yTextLoc, 320, 240); }
//******************************************************************************* //* This is where we get the chunks of data //* to program to the dataflash //******************************************************************************* void image_interface_begin(void) { //unsigned int page_count = 0; unsigned char command = 0; unsigned char *buff; unsigned int page_num = 0; boolean keepGoing; COLOR black = {0,0,0}; COLOR white = {255,255,255}; /* order of operations: 1.) purge usart buffers 2.) recv mode byte 3.) if mode == STORE, recv page_count recv all pages else mode == READ send page_count send pages */ arduinoReset(); usart_init(115200); cli(); buff = usart_getBuff_ptr(); //enough setup, lets begin keepGoing = TRUE; while(keepGoing) { usart_read_bytes(1); //Wait for us to read a byte command = buff[0]; //store or read command if (command == IMAGE_INTERFACE_ERASE) { dispPutS("Erasing",0,0,white,black); dataflash_erase(); usart_putc(IMAGE_INTERFACE_PAGE_DONE); //ok dispPutS("Erasing Done",0,10,white,black); } else if (command == IMAGE_INTERFACE_STORE) { uint16_t x; unsigned char out_data[DATAFLASH_PAGESIZE],in_data[DATAFLASH_PAGESIZE]; char out[10]; uint8_t checksum = 0; buff = usart_getBuff_ptr(); dispPutS("Store",0,20,white,black); usart_putc(IMAGE_INTERFACE_PAGE_DONE); //ok //give us the page number to write usart_read_bytes(2); usart_putc(IMAGE_INTERFACE_PAGE_DONE); //ok page_num = (buff[1] << 8) + buff[0]; dtostrf(page_num,4,0,out); dispPutS("Page Number:",0,30,white,black); dispPutS(out,100,30,white,black); //read the whole page usart_read_bytes(DATAFLASH_PAGESIZE); usart_putc(IMAGE_INTERFACE_PAGE_DONE); //ok dispPutS("Page recved",0,40,white,black); //program the whole page for(x=0;x<DATAFLASH_PAGESIZE;x++) { out_data[x] = buff[x]; } //copy the page to the outbound page buffer dataflash_program_page(&out_data[0], page_num); //program the page for(x=0;x<DATAFLASH_PAGESIZE;x++) { in_data[x] = 0x00; } //clear the inbound page buffer //wait for checksum command usart_read_bytes(1); dispPutS("Checksum",0,50,white,black); dataflash_cont_read(&in_data[0], page_num, DATAFLASH_PAGESIZE); //read the page out of the chip for(x=0;x<DATAFLASH_PAGESIZE;x++) { checksum += in_data[x]; } // build checksum checksum = (checksum ^ 0xFF ) + 1; //two's complement usart_putc(checksum); //send checksum dispPutS("Sent",0,60,white,black); } else if (command == IMAGE_INTERFACE_READ) { unsigned int x; unsigned char out[DATAFLASH_PAGESIZE]; page_num=0; //give us the number of pages you're sending usart_read_bytes(2); page_num = (buff[0] << 8) + buff[1]; //number of pages dataflash_cont_read(&out[0], page_num, DATAFLASH_PAGESIZE); for (x=0; x<DATAFLASH_PAGESIZE; x++) { usart_putc(out[x]); } asm("nop"); } else if (command == IMAGE_INTERFACE_INFO) { usart_puts("Flasher | ver 001"); usart_putc(0); } else if (command == IMAGE_INTERFACE_EXIT) { usart_putc(IMAGE_INTERFACE_PAGE_DONE); //ok bmp_init(); arduinoRun(); sei(); //enable interrupts keepGoing = FALSE; break; } }//end while } //end function