/** * @brief Write pixel. * @param Xpos: specifies the X position. * @param Ypos: specifies the Y position. * @param RGBCode: the RGB pixel color * @retval None */ void hx8347d_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode) { /* Set Cursor */ hx8347d_SetCursor(Xpos, Ypos); /* Prepare to write GRAM */ LCD_IO_WriteReg(LCD_REG_34); /* Write 16-bit GRAM Reg */ LCD_IO_WriteData((uint8_t*)&RGBCode, 2); }
/** * @brief Read pixel. * @param None * @retval the RGB pixel color */ uint16_t hx8347d_ReadPixel(uint16_t Xpos, uint16_t Ypos) { /* Set Cursor */ hx8347d_SetCursor(Xpos, Ypos); /* Dummy read */ LCD_IO_ReadData(LCD_REG_34); /* Read 16-bit Reg */ return (LCD_IO_ReadData(LCD_REG_34)); }
/** * @brief Open a file and draw each pixel of the corresponding file * @param xpos: x position for the image * @param xpos: y position for the image * @param BmpName : file name * @retval err: Error status (0=> success, 1=> fail) */ STORAGE_RETURN kStorage_OpenFileDrawPixel(uint16_t xpos, uint16_t ypos, uint8_t *BmpName) { uint32_t index, size, width, height; #if 0 uint32_t x; uint16_t color; #endif uint32_t bmpaddress, bit_pixel; unsigned int BytesRead; FIL file1; uint8_t *kstorage_tmpbuffer = NULL; if(f_open(&file1, (char *)BmpName, FA_READ) != FR_OK) { return KSTORAGE_ERROR_OPEN; } /* Memory allocation for the BMP header */ kstorage_tmpbuffer = malloc(sizeof(uint8_t)*30); if(kstorage_tmpbuffer==NULL) { f_close(&file1); return KSTORAGE_ERROR_MALLOC; } /* Read BMP header */ if(f_read(&file1, (char *)kstorage_tmpbuffer, 30, &BytesRead) != FR_OK) { free(kstorage_tmpbuffer); f_close(&file1); return KSTORAGE_ERROR_READ; } /* get the bmpadress */ bmpaddress = (uint32_t)kstorage_tmpbuffer; /* Read bitmap size */ size = *(uint16_t *) (bmpaddress + 2); size |= (*(uint16_t *) (bmpaddress + 4)) << 16; /* Get bitmap data address offset */ index = *(uint16_t *) (bmpaddress + 10); index |= (*(uint16_t *) (bmpaddress + 12)) << 16; /* Read bitmap width */ width = *(uint16_t *) (bmpaddress + 18); width |= (*(uint16_t *) (bmpaddress + 20)) << 16; /* Read bitmap height */ height = *(uint16_t *) (bmpaddress + 22); height |= (*(uint16_t *) (bmpaddress + 24)) << 16; /* Read bit/pixel */ bit_pixel = (*(uint16_t *) (bmpaddress + 28)) / 8; // bit_pixel = bit_pixel/8; size = (size - index); xpos = xpos + height - 1; /* Synchronize f_read right in front of the image data */ f_close (&file1); /* Memory allocation for the BMP data line */ free(kstorage_tmpbuffer); kstorage_tmpbuffer = malloc(sizeof(uint8_t)*width*bit_pixel); if(kstorage_tmpbuffer==NULL) { return KSTORAGE_ERROR_OPEN; } f_open (&file1, (TCHAR const*)BmpName, FA_READ); f_read(&file1, kstorage_tmpbuffer, index, &BytesRead); do { /* read a line */ f_read(&file1, kstorage_tmpbuffer, width*bit_pixel, &BytesRead); size -= width*bit_pixel; #if 0 /* display each pixel of the line */ for (x = 0; x < width; x++) { color = (kstorage_tmpbuffer[ 2*x+1] << 8) | kstorage_tmpbuffer[ 2 * x]; BSP_LCD_DrawPixel(xpos, ypos + x, color); } #else extern void hx8347d_SetCursor(uint16_t Xpos, uint16_t Ypos); //void LCD_IO_WriteMultipleData(uint8_t *pData, uint32_t Size); //void LCD_IO_WriteReg(uint8_t Reg); // hx8347d_WriteReg(LCD_REG_22, 0xA0); /* Set Cursor */ hx8347d_SetCursor(xpos, ypos); /* Prepare to write GRAM */ LCD_IO_WriteReg(LCD_REG_34); /* Write 16-bit GRAM Reg */ LCD_IO_WriteMultipleData(kstorage_tmpbuffer, width*bit_pixel); #endif xpos--; } while (size != 0); /* Exit : free memory, close the file */ free(kstorage_tmpbuffer); f_close(&file1); return KSTORAGE_NOERROR; }
/** * @brief Initialise the HX8347D LCD Component. * @param None * @retval None */ void hx8347d_Init(void) { if(Is_hx8347d_Initialized == 0) { Is_hx8347d_Initialized = 1; /* Initialise HX8347D low level bus layer --------------------------------*/ LCD_IO_Init(); /* Driving ability setting */ hx8347d_WriteReg(LCD_REG_234, 0x00); hx8347d_WriteReg(LCD_REG_235, 0x20); hx8347d_WriteReg(LCD_REG_236, 0x0C); hx8347d_WriteReg(LCD_REG_237, 0xC4); hx8347d_WriteReg(LCD_REG_232, 0x40); hx8347d_WriteReg(LCD_REG_233, 0x38); hx8347d_WriteReg(LCD_REG_241, 0x01); hx8347d_WriteReg(LCD_REG_242, 0x10); hx8347d_WriteReg(LCD_REG_39, 0xA3); /* Adjust the Gamma Curve */ hx8347d_WriteReg(LCD_REG_64, 0x01); hx8347d_WriteReg(LCD_REG_65, 0x00); hx8347d_WriteReg(LCD_REG_66, 0x00); hx8347d_WriteReg(LCD_REG_67, 0x10); hx8347d_WriteReg(LCD_REG_68, 0x0E); hx8347d_WriteReg(LCD_REG_69, 0x24); hx8347d_WriteReg(LCD_REG_70, 0x04); hx8347d_WriteReg(LCD_REG_71, 0x50); hx8347d_WriteReg(LCD_REG_72, 0x02); hx8347d_WriteReg(LCD_REG_73, 0x13); hx8347d_WriteReg(LCD_REG_74, 0x19); hx8347d_WriteReg(LCD_REG_75, 0x19); hx8347d_WriteReg(LCD_REG_76, 0x16); hx8347d_WriteReg(LCD_REG_80, 0x1B); hx8347d_WriteReg(LCD_REG_81, 0x31); hx8347d_WriteReg(LCD_REG_82, 0x2F); hx8347d_WriteReg(LCD_REG_83, 0x3F); hx8347d_WriteReg(LCD_REG_84, 0x3F); hx8347d_WriteReg(LCD_REG_85, 0x3E); hx8347d_WriteReg(LCD_REG_86, 0x2F); hx8347d_WriteReg(LCD_REG_87, 0x7B); hx8347d_WriteReg(LCD_REG_88, 0x09); hx8347d_WriteReg(LCD_REG_89, 0x06); hx8347d_WriteReg(LCD_REG_90, 0x06); hx8347d_WriteReg(LCD_REG_91, 0x0C); hx8347d_WriteReg(LCD_REG_92, 0x1D); hx8347d_WriteReg(LCD_REG_93, 0xCC); /* Power voltage setting */ hx8347d_WriteReg(LCD_REG_27, 0x1B); hx8347d_WriteReg(LCD_REG_26, 0x01); hx8347d_WriteReg(LCD_REG_36, 0x2F); hx8347d_WriteReg(LCD_REG_37, 0x57); /*****VCOM offset ****/ hx8347d_WriteReg(LCD_REG_35, 0x86); /* Power on setting up flow */ hx8347d_WriteReg(LCD_REG_24, 0x36); /* Display frame rate = 70Hz RADJ = '0110' */ hx8347d_WriteReg(LCD_REG_25, 0x01); /* OSC_EN = 1 */ hx8347d_WriteReg(LCD_REG_28, 0x06); /* AP[2:0] = 111 */ hx8347d_WriteReg(LCD_REG_29, 0x06); /* AP[2:0] = 111 */ hx8347d_WriteReg(LCD_REG_31,0x90); /* GAS=1, VOMG=00, PON=1, DK=0, XDK=0, DVDH_TRI=0, STB=0*/ hx8347d_WriteReg(LCD_REG_39, 1); /* REF = 1 */ LCD_Delay(10); /* 262k/65k color selection */ hx8347d_WriteReg(LCD_REG_23, 0x05); /* default 0x06 262k color, 0x05 65k color */ /* SET PANEL */ hx8347d_WriteReg(LCD_REG_54, 0x09); /* SS_PANEL = 1, GS_PANEL = 0,REV_PANEL = 0, BGR_PANEL = 1 */ /* Display ON flow */ hx8347d_WriteReg(LCD_REG_40, 0x38); /* GON=1, DTE=1, D=10 */ LCD_Delay(60); hx8347d_WriteReg(LCD_REG_40, 0x3C); /* GON=1, DTE=1, D=11 */ /* Set GRAM Area - Partial Display Control */ hx8347d_WriteReg(LCD_REG_1, 0x00); /* DP_STB = 0, DP_STB_S = 0, SCROLL = 0, */ hx8347d_WriteReg(LCD_REG_2, 0x00); /* Column address start 2 */ hx8347d_WriteReg(LCD_REG_3, 0x00); /* Column address start 1 */ hx8347d_WriteReg(LCD_REG_4, 0x01); /* Column address end 2 */ hx8347d_WriteReg(LCD_REG_5, 0x3F); /* Column address end 1 */ hx8347d_WriteReg(LCD_REG_6, 0x00); /* Row address start 2 */ hx8347d_WriteReg(LCD_REG_7, 0x00); /* Row address start 2 */ hx8347d_WriteReg(LCD_REG_8, 0x00); /* Row address end 2 */ hx8347d_WriteReg(LCD_REG_9, 0xEF); /* Row address end 1 */ hx8347d_WriteReg(LCD_REG_22, 0xE0); /* Memory access control: MY = 1, MX = 0, MV = 1, ML = 0 */ } /* Set the Cursor */ hx8347d_SetCursor(0, 0); /* Prepare to write GRAM */ LCD_IO_WriteReg(LCD_REG_34); }