void LCD_FillRect(int x0, int y0, int x1, int y1, int color) { int h = y1 - y0 + 1; int w = x1 - x0 + 1; int pixels = h * w; //unsigned int dma_count; LCD_Window(x0,y0,w,h); LCD_Cmd(0x2C); // send pixel SSP0_16(1); // Use 16 bit transfers // Write to LCD using DMA SSP0_WriteLcdDMA(color, pixels); #if 0 LPC_GPDMACH0->DMACCSrcAddr = (uint32_t)&color; LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP0->DR; // we send to SSP0 LPC_SSP0->DMACR = 0x2; // start DMA do { if (pixel > 4095) { dma_count = 4095; pixel = pixel - 4095; } else { dma_count = pixel; pixel = 0; } LPC_GPDMA->DMACIntTCClear = 0x1; LPC_GPDMA->DMACIntErrClr = 0x1; // Configure DMA to use 16bit transfers // no address increment, interrupt LPC_GPDMACH0->DMACCControl = dma_count | (1UL << 18) | (1UL << 21) | (1UL << 31) ; LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | DMA_DEST_SSP0_TX; LPC_GPDMA->DMACSoftSReq = 0x1; // DMA request do { } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running } while (pixel > 0); #endif SSP0_WaitBusy(); // wait for end of transfer SSP0_16(0); LCD_CS(1); LCD_WindowMax(); return; }
void LCD_Hline(int x0, int x1, int y, int color) { int w,j; w = x1 - x0 + 1; LCD_Window(x0,y,w,1); LCD_DC(0); LCD_CS(0); SSP0_Write(0x2C); // send pixel SSP0_WaitBusy(); LCD_DC(1); SSP0_16(1); for (j=0; j<w; j++) { SSP0_Write(color); } SSP0_WaitBusy(); SSP0_16(0); LCD_CS(1); LCD_WindowMax(); return; }
void LCD_Vline(int x, int y0, int y1, int color) { int h,y; h = y1 - y0 + 1; LCD_Window(x,y0,1,h); LCD_DC(0); LCD_CS(0); SSP0_Write(0x2C); // send pixel SSP0_WaitBusy(); LCD_DC(1); SSP0_16(1); // switch to 16 bit Mode 3 for (y=0; y<h; y++) { SSP0_Write(color); } SSP0_WaitBusy(); SSP0_16(0); LCD_CS(1); LCD_WindowMax(); return; }
/* main work function */ void work(void) { unsigned short i, j; unsigned char mailbox_num = 0; volatile ProtoIOMBox * mbox; /* setup status */ status_setup(); /* setup serial console */ usart1_setup(); /* setup proto */ proto_setup(); mbox = proto_srv_dat.mailboxes[mailbox_num]; /* setup button */ buttons_setup(); /* lcd setup */ LCD_Setup(); LCD_Clear(BLACK); for (i = 0; i < 10; i++) { for (j = 0; j < 10; j++) { LCD_Pixel(j + 10, i + 10, test.data[i * 10 + j]); } } LCD_Window(0, 0, 9, 9); LCD_RS_LOW; LCD_SELECT; for (i = 0; i < 100; i++) { LCD_Send(test.data[i] >> 8); LCD_Send(test.data[i] & 0x00ff); } LCD_Cursor(0, 0); LCD_DESEL; /* check status */ check_status(); /* send ping */ mbox->outbox->header = 'C'; /* Command */ mbox->outbox->size = 0x00; /* 0 for ping request */ mbox->outbox_s = PROTO_IO_MBOX_READY; /* Box ready */ mbox->inbox->size = 64; /* buffer len for control */ mbox->inbox_s = PROTO_IO_MBOX_READY; /* Box ready */ /* wait connection estabilished */ while (status == 0); /* send ping message */ proto_send_msg(mailbox_num); /* wait to send message */ while (mbox->outbox_s <= PROTO_IO_MBOX_SEND); if (mbox->outbox_s == PROTO_IO_MBOX_COMPLETE) LCD_String("Con", 36, 6, 1, WHITE, GLASSY); else LCD_String("Un", 36, 6, 1, RED, GLASSY); /* get ping message */ /* FIXME wtf? this not work or work parity */ //proto_get_msg(mailbox_num); /* wait to get message */ while (mbox->inbox_s <= PROTO_IO_MBOX_SEND); if (mbox->inbox_s == PROTO_IO_MBOX_COMPLETE) { LCD_String("OK", 36 + 3 * 7, 6, 1, GREEN, GLASSY); for (i = 0; i < mbox->inbox->size; i++) LCD_Char(mbox->inbox->message[i], 70 + i * 6, 6, 1, WHITE, GLASSY); } else LCD_String("ERR", 36 + 3 * 7, 6, 1, RED, GLASSY); /* infinity loop */ while (1) { if (button_state.state[B_LGHT] == B_CLICK) { sender('+'); button_state.state[B_LGHT] = B_RELEASE; } if (button_state.state[B_MOD] == B_CLICK) { sender('m'); button_state.state[B_MOD] = B_RELEASE; } if (button_state.state[B_SET] == B_CLICK) { sender('-'); button_state.state[B_SET] = B_RELEASE; } if (button_state.state[B_UP] == B_CLICK) { sender('<'); button_state.state[B_UP] = B_RELEASE; } if (button_state.state[B_SU] == B_CLICK) { sender('p'); button_state.state[B_SU] = B_RELEASE; } if (button_state.state[B_DWN] == B_CLICK) { sender('>'); button_state.state[B_DWN] = B_RELEASE; } } }
void TFT_DrawPoint( u16 CoordiX, u16 CoordiY, u32 Color ) { LCD_Window(CoordiY,320-CoordiX,1,1); LCD_REG=0x2C;//WriteRAM_Prepare LCD_RAM=Color; }
void GUI_SetPoint(u16 xpos, u16 ypos,u16 color) { LCD_Window(240-ypos,320-xpos,1,1); LCD_REG=0x2C;//WriteRAM_Prepare LCD_RAM=color; }
void LCD_Character(int x, int y, int c) { unsigned int hor,vert,offset,bpl,j,i,b; unsigned char* charbit; unsigned char z,w; #ifdef use_ram unsigned int pixel; unsigned int p; unsigned int dma_count,dma_off; uint16_t *buffer; #endif // Position characters LCD_Locate(x, y); if ((c < 31) || (c > 127)) return; // test char range // read font parameter from start of array offset = font[0]; // bytes / char hor = font[1]; // get hor size of font vert = font[2]; // get vert size of font bpl = font[3]; // bytes per line if (((int) (char_x + hor)) > LCD_Width()) { char_x = 0; char_y = char_y + vert; if (((int) char_y) >= LCD_Height() - font[2]) { char_y = 0; } } LCD_Window(char_x, char_y,hor,vert); // setup char box LCD_Cmd(0x2C); SSP0_16(1); // switch to 16 bit Mode #ifdef LCD_USE_RAM pixel = hor * vert; // calculate buffer size buffer = (uint16_t *) malloc (2*pixel); // we need a buffer for the font if(buffer != NULL) { // there is memory space -> use dma charbit = &font[((c -32) * offset) + 4]; // start of char bitmap w = charbit[0]; // width of actual char p = 0; // construct the font into the buffer for (j=0; j<vert; j++) { // vert line for (i=0; i<hor; i++) { // horz line z = charbit[bpl * i + ((j & 0xF8) >> 3)+1]; b = 1 << (j & 0x07); if (( z & b ) == 0x00) { buffer[p] = background; } else { buffer[p] = foreground; } p++; } } // copy the buffer with DMA SPI to display dma_off = 0; // offset for DMA transfer LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP0->DR; // we send to SSP0 LPC_SSP0->DMACR = 0x2; // start DMA do { if (pixel > 4095) { // this is a giant font ! dma_count = 4095; pixel = pixel - 4095; } else { dma_count = pixel; pixel = 0; } LPC_GPDMA->DMACIntTCClear = 0x1; LPC_GPDMA->DMACIntErrClr = 0x1; LPC_GPDMACH0->DMACCSrcAddr = (uint32_t) (buffer + dma_off); LPC_GPDMACH0->DMACCControl = dma_count | (1UL << 18) | (1UL << 21) | (1UL << 31) | DMA_CHANNEL_SRC_INC ; // 16 bit transfer , address increment, interrupt LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | DMA_DEST_SSP0_TX); LPC_GPDMA->DMACSoftSReq = 0x1; do { } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running dma_off = dma_off + dma_count; } while (pixel > 0); SSP0_WaitBusy(); free ((uint16_t *) buffer); SSP0_16(0); }
void LCD_WindowMax (void) { LCD_Window (0, 0, LCD_Width(), LCD_Height()); }