/** * @brief Disables the Display. * @param None * @retval None */ void st7735_DisplayOff(void) { uint8_t data = 0; LCD_IO_WriteReg(LCD_REG_19); LCD_Delay(10); LCD_IO_WriteReg(LCD_REG_40); LCD_Delay(10); LCD_IO_WriteReg(LCD_REG_54); data = 0xC0; LCD_IO_WriteMultipleData(&data, 1); }
/** * @brief Sets Cursor position. * @param Xpos: specifies the X position. * @param Ypos: specifies the Y position. * @retval None */ void st7735_SetCursor(uint16_t Xpos, uint16_t Ypos) { uint8_t data = 0; LCD_IO_WriteReg(LCD_REG_42); data = (Xpos) >> 8; LCD_IO_WriteMultipleData(&data, 1); data = (Xpos) & 0xFF; LCD_IO_WriteMultipleData(&data, 1); LCD_IO_WriteReg(LCD_REG_43); data = (Ypos) >> 8; LCD_IO_WriteMultipleData(&data, 1); data = (Ypos) & 0xFF; LCD_IO_WriteMultipleData(&data, 1); LCD_IO_WriteReg(LCD_REG_44); }
/** * @brief Writes to the selected LCD register. * @param LCDReg: address of the selected register. * @param LCDRegValue: value to write to the selected register. * @retval None */ void spfd5408_WriteReg(uint8_t LCDReg, uint16_t LCDRegValue) { LCD_IO_WriteReg(LCDReg); /* Write 16-bit GRAM Reg */ LCD_IO_WriteData((uint8_t*)&LCDRegValue, 2); }
/** * @brief Displays a bitmap picture. * @param BmpAddress: Bmp picture address. * @param Xpos: Bmp X position in the LCD * @param Ypos: Bmp Y position in the LCD * @retval None */ void ili9325_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp) { uint32_t index = 0, size = 0; /* Read bitmap size */ size = *(volatile uint16_t *) (pbmp + 2); size |= (*(volatile uint16_t *) (pbmp + 4)) << 16; /* Get bitmap data address offset */ index = *(volatile uint16_t *) (pbmp + 10); index |= (*(volatile uint16_t *) (pbmp + 12)) << 16; size = (size - index)/2; pbmp += index; /* Set GRAM write direction and BGR = 1 */ /* I/D=00 (Horizontal : decrement, Vertical : decrement) */ /* AM=1 (address is updated in vertical writing direction) */ ili9325_WriteReg(LCD_REG_3, 0x1008); /* Set Cursor */ ili9325_SetCursor(Xpos, Ypos); /* Prepare to write GRAM */ LCD_IO_WriteReg(LCD_REG_34); for(index = 0; index < size; index++) { /* Write 16-bit GRAM Reg */ LCD_IO_WriteData(*(volatile uint16_t *)pbmp); pbmp += 2; } /* Set GRAM write direction and BGR = 1 */ /* I/D = 01 (Horizontal : increment, Vertical : decrement) */ /* AM = 1 (address is updated in vertical writing direction) */ ili9325_WriteReg(LCD_REG_3, 0x1018); }
/** * @brief Writes to the selected LCD register. * @param LCD_Reg: Address of the selected register. * @param LCD_RegValue: Value to write to the selected register. * @retval None */ void ili9325_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue) { LCD_IO_WriteReg(LCD_Reg); /* Write 16-bit GRAM Reg */ LCD_IO_WriteData(LCD_RegValue); }
/** * @brief Read register value. * @param Reg * @retval None */ uint16_t LCD_IO_ReadData(uint16_t Reg) { uint32_t readvalue = 0; /* Send Reg value to Read */ LCD_IO_WriteReg(Reg); /* Reset LCD control line(/CS) and Send command */ LCD_CS_LOW(); /* Send Start Byte */ SPIx_Write(START_BYTE | LCD_READ_REG); /* Read Upper Byte */ SPIx_Write(0xFF); readvalue = SPIx_Read(); readvalue = readvalue << 8; readvalue |= SPIx_Read(); HAL_Delay(10); /* Deselect : Chip Select high */ LCD_CS_HIGH(); return readvalue; }
/** * @brief Read register value. * @param Reg * @retval None */ uint16_t LCD_IO_ReadData(uint16_t Reg) { uint32_t readvalue = 0; /* Change BaudRate Prescaler 8 for Read */ /* Mean SPI baudrate is set to 72/8 = 9 MHz */ heval_Spi.Instance->CR1 &= 0xFFC7; heval_Spi.Instance->CR1 |= SPI_BAUDRATEPRESCALER_8; /* Send Reg value to Read */ LCD_IO_WriteReg(Reg); /* Reset LCD control line(/CS) and Send command */ LCD_CS_LOW(); /* Send Start Byte */ SPIx_Write(START_BYTE | LCD_READ_REG); /* Read Upper Byte */ SPIx_Write(0xFF); readvalue = SPIx_Read(); readvalue = readvalue << 8; readvalue |= SPIx_Read(); /* Recover Baud Rate initial value */ heval_Spi.Instance->CR1 &= 0xFFC7; heval_Spi.Instance->CR1 |= heval_Spi.Init.BaudRatePrescaler; HAL_Delay(10); /* Deselect : Chip Select high */ LCD_CS_HIGH(); return readvalue; }
/** * @brief Draw vertical line. * @param RGB_Code: Specifies the RGB color * @param Xpos: specifies the X position. * @param Ypos: specifies the Y position. * @param Length: specifies the Line length. * @retval None */ void ili9325_DrawVLine(uint16_t RGB_Code, uint16_t Xpos, uint16_t Ypos, uint16_t Length) { uint16_t i = 0; /* set GRAM write direction and BGR = 1 */ /* I/D=00 (Horizontal : increment, Vertical : decrement) */ /* AM=1 (address is updated in vertical writing direction) */ ili9325_WriteReg(LCD_REG_3, 0x1010); /* Set Cursor */ ili9325_SetCursor(Xpos, Ypos); /* Prepare to write GRAM */ LCD_IO_WriteReg(LCD_REG_34); for(i = 0; i < Length; i++) { /* Write 16-bit GRAM Reg */ LCD_IO_WriteData(RGB_Code); } /* set GRAM write direction and BGR = 1 */ /* I/D=00 (Horizontal : increment, Vertical : decrement) */ /* AM=1 (address is updated in vertical writing direction) */ ili9325_WriteReg(LCD_REG_3, 0x1018); }
/** * @brief Draw vertical line. * @param RGBCode: Specifies the RGB color * @param Xpos: specifies the X position. * @param Ypos: specifies the Y position. * @param Length: specifies the Line length. * @retval None */ void spfd5408_DrawVLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length) { uint16_t counter = 0; /* set GRAM write direction and BGR = 1 */ /* I/D=00 (Horizontal : increment, Vertical : decrement) */ /* AM=1 (address is updated in vertical writing direction) */ spfd5408_WriteReg(LCD_REG_3, 0x1010); /* Set Cursor */ spfd5408_SetCursor(Xpos, Ypos); /* Prepare to write GRAM */ LCD_IO_WriteReg(LCD_REG_34); /* Fill a complete vertical line */ for(counter = 0; counter < Length; counter++) { ArrayRGB[counter] = RGBCode; } /* Write 16-bit GRAM Reg */ LCD_IO_WriteData((uint8_t*)&ArrayRGB[0], Length * 2); /* set GRAM write direction and BGR = 1 */ /* I/D=00 (Horizontal : increment, Vertical : decrement) */ /* AM=1 (address is updated in vertical writing direction) */ spfd5408_WriteReg(LCD_REG_3, 0x1018); }
/** * @brief Reads the selected LCD Register. * @param LCD_Reg: address of the selected register. * @retval LCD Register Value. */ uint16_t ili9325_ReadReg(uint8_t LCD_Reg) { /* Write 16-bit Index (then Read Reg) */ LCD_IO_WriteReg(LCD_Reg); /* Read 16-bit Reg */ return (LCD_IO_ReadData()); }
/** * @brief Write pixel. * @param Xpos: specifies the X position. * @param Ypos: specifies the Y position. * @param RGB_Code: the RGB pixel color * @retval None */ void ili9325_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGB_Code) { /* Set Cursor */ ili9325_SetCursor(Xpos, Ypos); /* Prepare to write GRAM */ LCD_IO_WriteReg(LCD_REG_34); /* Write 16-bit GRAM Reg */ LCD_IO_WriteData(RGB_Code); }
/** * @brief Write pixel. * @param Xpos: specifies the X position. * @param Ypos: specifies the Y position. * @param RGBCode: the RGB pixel color * @retval None */ void spfd5408_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode) { /* Set Cursor */ spfd5408_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 ili9325_ReadPixel(uint16_t Xpos, uint16_t Ypos) { /* Set Cursor */ ili9325_SetCursor(Xpos, Ypos); /* Prepare to write GRAM */ LCD_IO_WriteReg(LCD_REG_34); /* Dummy read */ LCD_IO_ReadData(); /* Read 16-bit Reg */ return (LCD_IO_ReadData()); }
/** * @brief Sets a display window * @param Xpos: specifies the X bottom left position. * @param Ypos: specifies the Y bottom left position. * @param Height: display window height. * @param Width: display window width. * @retval None */ void st7735_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) { uint8_t data = 0; /* Column addr set, 4 args, no delay: XSTART = Xpos, XEND = (Xpos + Width - 1) */ LCD_IO_WriteReg(LCD_REG_42); data = (Xpos) >> 8; LCD_IO_WriteMultipleData(&data, 1); data = (Xpos) & 0xFF; LCD_IO_WriteMultipleData(&data, 1); data = (Xpos + Width - 1) >> 8; LCD_IO_WriteMultipleData(&data, 1); data = (Xpos + Width - 1) & 0xFF; LCD_IO_WriteMultipleData(&data, 1); /* Row addr set, 4 args, no delay: YSTART = Ypos, YEND = (Ypos + Height - 1) */ LCD_IO_WriteReg(LCD_REG_43); data = (Ypos) >> 8; LCD_IO_WriteMultipleData(&data, 1); data = (Ypos) & 0xFF; LCD_IO_WriteMultipleData(&data, 1); data = (Ypos + Height - 1) >> 8; LCD_IO_WriteMultipleData(&data, 1); data = (Ypos + Height - 1) & 0xFF; LCD_IO_WriteMultipleData(&data, 1); }
/** * @brief Draw vertical line. * @param RGB_Code: Specifies the RGB color * @param Xpos: specifies the X position. * @param Ypos: specifies the Y position. * @param Length: specifies the Line length. * @retval None */ void ili9325_DrawHLine(uint16_t RGB_Code, uint16_t Xpos, uint16_t Ypos, uint16_t Length) { uint16_t i = 0; /* Set Cursor */ ili9325_SetCursor(Xpos, Ypos); /* Prepare to write GRAM */ LCD_IO_WriteReg(LCD_REG_34); for(i = 0; i < Length; i++) { /* Write 16-bit GRAM Reg */ LCD_IO_WriteData(RGB_Code); } }
uint8_t u8g_com_stm32duino_fsmc_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { if (msgInitCount) { if (msg == U8G_COM_MSG_INIT) msgInitCount--; if (msgInitCount) return -1; } static uint8_t isCommand; switch (msg) { case U8G_COM_MSG_STOP: break; case U8G_COM_MSG_INIT: u8g_SetPIOutput(u8g, U8G_PI_RESET); LCD_IO_Init(u8g->pin_list[U8G_PI_CS], u8g->pin_list[U8G_PI_A0]); u8g_Delay(100); if (arg_ptr != NULL) *((uint32_t *)arg_ptr) = LCD_IO_ReadData(LCD_READ_ID, 3); isCommand = 0; break; case U8G_COM_MSG_ADDRESS: // define cmd (arg_val = 0) or data mode (arg_val = 1) isCommand = arg_val == 0 ? 1 : 0; break; case U8G_COM_MSG_RESET: u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); break; case U8G_COM_MSG_WRITE_BYTE: if (isCommand) LCD_IO_WriteReg(arg_val); else LCD_IO_WriteData((uint16_t)arg_val); break; case U8G_COM_MSG_WRITE_SEQ: for (uint8_t i = 0; i < arg_val; i += 2) LCD_IO_WriteData(*(uint16_t *)(((uint32_t)arg_ptr) + i)); break; } return 1; }
/** * @brief Displays picture. * @param pdata: picture address. * @param Xpos: Image X position in the LCD * @param Ypos: Image Y position in the LCD * @param Xsize: Image X size in the LCD * @param Ysize: Image Y size in the LCD * @retval None */ void ili9325_DrawRGBImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint8_t *pdata) { uint32_t index = 0, size = 0; size = (Xsize * Ysize); /* Set Cursor */ ili9325_SetCursor(Xpos, Ypos); /* Prepare to write GRAM */ LCD_IO_WriteReg(LCD_REG_34); for(index = 0; index < size; index++) { /* Write 16-bit GRAM Reg */ LCD_IO_WriteData(*(volatile uint16_t *)pdata); pdata += 2; } }
/** * @brief Draw vertical line. * @param RGBCode: Specifies the RGB color * @param Xpos: specifies the X position. * @param Ypos: specifies the Y position. * @param Length: specifies the Line length. * @retval None */ void spfd5408_DrawHLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length) { uint32_t i = 0; /* Set Cursor */ spfd5408_SetCursor(Xpos, Ypos); /* Prepare to write GRAM */ LCD_IO_WriteReg(LCD_REG_34); /* Sent a complete line */ for(i = 0; i < Length; i++) { ArrayRGB[i] = RGBCode; } LCD_IO_WriteData((uint8_t*)&ArrayRGB[0], Length * 2); }
/** * @brief Initialize the ST7735 LCD Component. * @param None * @retval None */ void st7735_Init(void) { uint8_t data = 0; /* Initialize ST7735 low level bus layer -----------------------------------*/ LCD_IO_Init(); /* Out of sleep mode, 0 args, no delay */ st7735_WriteReg(LCD_REG_17, 0x00); /* Frame rate ctrl - normal mode, 3 args:Rate = fosc/(1x2+40) * (LINE+2C+2D)*/ LCD_IO_WriteReg(LCD_REG_177); data = 0x01; LCD_IO_WriteMultipleData(&data, 1); data = 0x2C; LCD_IO_WriteMultipleData(&data, 1); data = 0x2D; LCD_IO_WriteMultipleData(&data, 1); /* Frame rate control - idle mode, 3 args:Rate = fosc/(1x2+40) * (LINE+2C+2D) */ st7735_WriteReg(LCD_REG_178, 0x01); st7735_WriteReg(LCD_REG_178, 0x2C); st7735_WriteReg(LCD_REG_178, 0x2D); /* Frame rate ctrl - partial mode, 6 args: Dot inversion mode, Line inversion mode */ st7735_WriteReg(LCD_REG_179, 0x01); st7735_WriteReg(LCD_REG_179, 0x2C); st7735_WriteReg(LCD_REG_179, 0x2D); st7735_WriteReg(LCD_REG_179, 0x01); st7735_WriteReg(LCD_REG_179, 0x2C); st7735_WriteReg(LCD_REG_179, 0x2D); /* Display inversion ctrl, 1 arg, no delay: No inversion */ st7735_WriteReg(LCD_REG_180, 0x07); /* Power control, 3 args, no delay: -4.6V , AUTO mode */ st7735_WriteReg(LCD_REG_192, 0xA2); st7735_WriteReg(LCD_REG_192, 0x02); st7735_WriteReg(LCD_REG_192, 0x84); /* Power control, 1 arg, no delay: VGH25 = 2.4C VGSEL = -10 VGH = 3 * AVDD */ st7735_WriteReg(LCD_REG_193, 0xC5); /* Power control, 2 args, no delay: Opamp current small, Boost frequency */ st7735_WriteReg(LCD_REG_194, 0x0A); st7735_WriteReg(LCD_REG_194, 0x00); /* Power control, 2 args, no delay: BCLK/2, Opamp current small & Medium low */ st7735_WriteReg(LCD_REG_195, 0x8A); st7735_WriteReg(LCD_REG_195, 0x2A); /* Power control, 2 args, no delay */ st7735_WriteReg(LCD_REG_196, 0x8A); st7735_WriteReg(LCD_REG_196, 0xEE); /* Power control, 1 arg, no delay */ st7735_WriteReg(LCD_REG_197, 0x0E); /* Don't invert display, no args, no delay */ LCD_IO_WriteReg(LCD_REG_32); /* Set color mode, 1 arg, no delay: 16-bit color */ st7735_WriteReg(LCD_REG_58, 0x05); /* Column addr set, 4 args, no delay: XSTART = 0, XEND = 127 */ LCD_IO_WriteReg(LCD_REG_42); data = 0x00; LCD_IO_WriteMultipleData(&data, 1); LCD_IO_WriteMultipleData(&data, 1); LCD_IO_WriteMultipleData(&data, 1); data = 0x7F; LCD_IO_WriteMultipleData(&data, 1); /* Row addr set, 4 args, no delay: YSTART = 0, YEND = 159 */ LCD_IO_WriteReg(LCD_REG_43); data = 0x00; LCD_IO_WriteMultipleData(&data, 1); LCD_IO_WriteMultipleData(&data, 1); LCD_IO_WriteMultipleData(&data, 1); data = 0x9F; LCD_IO_WriteMultipleData(&data, 1); /* Magical unicorn dust, 16 args, no delay */ st7735_WriteReg(LCD_REG_224, 0x02); st7735_WriteReg(LCD_REG_224, 0x1c); st7735_WriteReg(LCD_REG_224, 0x07); st7735_WriteReg(LCD_REG_224, 0x12); st7735_WriteReg(LCD_REG_224, 0x37); st7735_WriteReg(LCD_REG_224, 0x32); st7735_WriteReg(LCD_REG_224, 0x29); st7735_WriteReg(LCD_REG_224, 0x2d); st7735_WriteReg(LCD_REG_224, 0x29); st7735_WriteReg(LCD_REG_224, 0x25); st7735_WriteReg(LCD_REG_224, 0x2B); st7735_WriteReg(LCD_REG_224, 0x39); st7735_WriteReg(LCD_REG_224, 0x00); st7735_WriteReg(LCD_REG_224, 0x01); st7735_WriteReg(LCD_REG_224, 0x03); st7735_WriteReg(LCD_REG_224, 0x10); /* Sparkles and rainbows, 16 args, no delay */ st7735_WriteReg(LCD_REG_225, 0x03); st7735_WriteReg(LCD_REG_225, 0x1d); st7735_WriteReg(LCD_REG_225, 0x07); st7735_WriteReg(LCD_REG_225, 0x06); st7735_WriteReg(LCD_REG_225, 0x2E); st7735_WriteReg(LCD_REG_225, 0x2C); st7735_WriteReg(LCD_REG_225, 0x29); st7735_WriteReg(LCD_REG_225, 0x2D); st7735_WriteReg(LCD_REG_225, 0x2E); st7735_WriteReg(LCD_REG_225, 0x2E); st7735_WriteReg(LCD_REG_225, 0x37); st7735_WriteReg(LCD_REG_225, 0x3F); st7735_WriteReg(LCD_REG_225, 0x00); st7735_WriteReg(LCD_REG_225, 0x00); st7735_WriteReg(LCD_REG_225, 0x02); st7735_WriteReg(LCD_REG_225, 0x10); /* Normal display on, no args, no delay */ st7735_WriteReg(LCD_REG_19, 0x00); /* Main screen turn on, no delay */ st7735_WriteReg(LCD_REG_41, 0x00); st7735_WriteReg(LCD_REG_54, 0xC0); }
/** * @brief Writes to the selected LCD register. * @param LCDReg: Address of the selected register. * @param LCDRegValue: value to write to the selected register. * @retval None */ void st7735_WriteReg(uint8_t LCDReg, uint8_t LCDRegValue) { LCD_IO_WriteReg(LCDReg); LCD_IO_WriteMultipleData(&LCDRegValue, 1); }
/** * @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); }
/******************************************************************** * * LcdWriteReg * * Function description: * Sets display register */ static void LcdWriteReg(U16 Data) { LCD_IO_WriteReg((uint8_t)Data); }
/** * @brief Initialise the SPFD5408 LCD Component. * @param None * @retval None */ void spfd5408_Init(void) { if(Is_spfd5408_Initialized == 0) { Is_spfd5408_Initialized = 1; /* Initialise SPFD5408 low level bus layer --------------------------------*/ LCD_IO_Init(); /* Start Initial Sequence --------------------------------------------------*/ spfd5408_WriteReg(LCD_REG_227, 0x3008); /* Set internal timing */ spfd5408_WriteReg(LCD_REG_231, 0x0012); /* Set internal timing */ spfd5408_WriteReg(LCD_REG_239, 0x1231); /* Set internal timing */ spfd5408_WriteReg(LCD_REG_1, 0x0100); /* Set SS and SM bit */ spfd5408_WriteReg(LCD_REG_2, 0x0700); /* Set 1 line inversion */ spfd5408_WriteReg(LCD_REG_3, 0x1030); /* Set GRAM write direction and BGR=1. */ spfd5408_WriteReg(LCD_REG_4, 0x0000); /* Resize register */ spfd5408_WriteReg(LCD_REG_8, 0x0202); /* Set the back porch and front porch */ spfd5408_WriteReg(LCD_REG_9, 0x0000); /* Set non-display area refresh cycle ISC[3:0] */ spfd5408_WriteReg(LCD_REG_10, 0x0000); /* FMARK function */ spfd5408_WriteReg(LCD_REG_12, 0x0000); /* RGB interface setting */ spfd5408_WriteReg(LCD_REG_13, 0x0000); /* Frame marker Position */ spfd5408_WriteReg(LCD_REG_15, 0x0000); /* RGB interface polarity */ /* Power On sequence -------------------------------------------------------*/ spfd5408_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ spfd5408_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */ spfd5408_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */ spfd5408_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */ LCD_Delay(200); /* Dis-charge capacitor power voltage (200ms) */ spfd5408_WriteReg(LCD_REG_17, 0x0007); /* DC1[2:0], DC0[2:0], VC[2:0] */ LCD_Delay(50); /* Delay 50 ms */ spfd5408_WriteReg(LCD_REG_16, 0x12B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ LCD_Delay(50); /* Delay 50 ms */ spfd5408_WriteReg(LCD_REG_18, 0x01BD); /* External reference voltage= Vci */ LCD_Delay(50); /* Delay 50 ms */ spfd5408_WriteReg(LCD_REG_19, 0x1400); /* VDV[4:0] for VCOM amplitude */ spfd5408_WriteReg(LCD_REG_41, 0x000E); /* VCM[4:0] for VCOMH */ LCD_Delay(50); /* Delay 50 ms */ spfd5408_WriteReg(LCD_REG_32, 0x0000); /* GRAM horizontal Address */ spfd5408_WriteReg(LCD_REG_33, 0x013F); /* GRAM Vertical Address */ /* Adjust the Gamma Curve --------------------------------------------------*/ spfd5408_WriteReg(LCD_REG_48, 0x0007); spfd5408_WriteReg(LCD_REG_49, 0x0302); spfd5408_WriteReg(LCD_REG_50, 0x0105); spfd5408_WriteReg(LCD_REG_53, 0x0206); spfd5408_WriteReg(LCD_REG_54, 0x0808); spfd5408_WriteReg(LCD_REG_55, 0x0206); spfd5408_WriteReg(LCD_REG_56, 0x0504); spfd5408_WriteReg(LCD_REG_57, 0x0007); spfd5408_WriteReg(LCD_REG_60, 0x0105); spfd5408_WriteReg(LCD_REG_61, 0x0808); /* Set GRAM area -----------------------------------------------------------*/ spfd5408_WriteReg(LCD_REG_80, 0x0000); /* Horizontal GRAM Start Address */ spfd5408_WriteReg(LCD_REG_81, 0x00EF); /* Horizontal GRAM End Address */ spfd5408_WriteReg(LCD_REG_82, 0x0000); /* Vertical GRAM Start Address */ spfd5408_WriteReg(LCD_REG_83, 0x013F); /* Vertical GRAM End Address */ spfd5408_WriteReg(LCD_REG_96, 0xA700); /* Gate Scan Line */ spfd5408_WriteReg(LCD_REG_97, 0x0001); /* NDL,VLE, REV */ spfd5408_WriteReg(LCD_REG_106, 0x0000); /* Set scrolling line */ /* Partial Display Control -------------------------------------------------*/ spfd5408_WriteReg(LCD_REG_128, 0x0000); spfd5408_WriteReg(LCD_REG_129, 0x0000); spfd5408_WriteReg(LCD_REG_130, 0x0000); spfd5408_WriteReg(LCD_REG_131, 0x0000); spfd5408_WriteReg(LCD_REG_132, 0x0000); spfd5408_WriteReg(LCD_REG_133, 0x0000); /* Panel Control -----------------------------------------------------------*/ spfd5408_WriteReg(LCD_REG_144, 0x0010); spfd5408_WriteReg(LCD_REG_146, 0x0000); spfd5408_WriteReg(LCD_REG_147, 0x0003); spfd5408_WriteReg(LCD_REG_149, 0x0110); spfd5408_WriteReg(LCD_REG_151, 0x0000); spfd5408_WriteReg(LCD_REG_152, 0x0000); /* Set GRAM write direction and BGR = 1 I/D=01 (Horizontal : increment, Vertical : decrement) AM=1 (address is updated in vertical writing direction) */ spfd5408_WriteReg(LCD_REG_3, 0x1018); spfd5408_WriteReg(LCD_REG_7, 0x0112); /* 262K color and display ON */ } /* Set the Cursor */ spfd5408_SetCursor(0, 0); /* Prepare to write GRAM */ LCD_IO_WriteReg(LCD_REG_34); }
/** * @brief Writes to the selected LCD register. * @param LCD_Reg: address of the selected register. * @retval None */ void st7789v_WriteReg(uint8_t LCD_Reg) { LCD_IO_WriteReg(LCD_Reg); }
/** * @brief Writes to the selected LCD register. * @param LCD_Reg: address of the selected register. * @retval None */ void ili9341_WriteReg(uint8_t LCD_Reg) { LCD_IO_WriteReg(LCD_Reg); }
/** * @brief Initialize the ILI9325 LCD Component. * @param None * @retval None */ void ili9325_Init(void) { /* Initialize ILI9325 low level bus layer ----------------------------------*/ LCD_IO_Init(); /* Start Initial Sequence --------------------------------------------------*/ ili9325_WriteReg(LCD_REG_0, 0x0001); /* Start internal OSC. */ ili9325_WriteReg(LCD_REG_1, 0x0100); /* Set SS and SM bit */ ili9325_WriteReg(LCD_REG_2, 0x0700); /* Set 1 line inversion */ ili9325_WriteReg(LCD_REG_3, 0x1018); /* Set GRAM write direction and BGR=1. */ ili9325_WriteReg(LCD_REG_4, 0x0000); /* Resize register */ ili9325_WriteReg(LCD_REG_8, 0x0202); /* Set the back porch and front porch */ ili9325_WriteReg(LCD_REG_9, 0x0000); /* Set non-display area refresh cycle ISC[3:0] */ ili9325_WriteReg(LCD_REG_10, 0x0000); /* FMARK function */ ili9325_WriteReg(LCD_REG_12, 0x0000); /* RGB interface setting */ ili9325_WriteReg(LCD_REG_13, 0x0000); /* Frame marker Position */ ili9325_WriteReg(LCD_REG_15, 0x0000); /* RGB interface polarity */ /* Power On sequence -------------------------------------------------------*/ ili9325_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ ili9325_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */ ili9325_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */ ili9325_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */ ili9325_WriteReg(LCD_REG_16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ ili9325_WriteReg(LCD_REG_17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */ ili9325_WriteReg(LCD_REG_18, 0x0139); /* VREG1OUT voltage */ ili9325_WriteReg(LCD_REG_19, 0x1d00); /* VDV[4:0] for VCOM amplitude */ ili9325_WriteReg(LCD_REG_41, 0x0013); /* VCM[4:0] for VCOMH */ ili9325_WriteReg(LCD_REG_32, 0x0000); /* GRAM horizontal Address */ ili9325_WriteReg(LCD_REG_33, 0x0000); /* GRAM Vertical Address */ /* Adjust the Gamma Curve (ILI9325) ----------------------------------------*/ ili9325_WriteReg(LCD_REG_48, 0x0007); ili9325_WriteReg(LCD_REG_49, 0x0302); ili9325_WriteReg(LCD_REG_50, 0x0105); ili9325_WriteReg(LCD_REG_53, 0x0206); ili9325_WriteReg(LCD_REG_54, 0x0808); ili9325_WriteReg(LCD_REG_55, 0x0206); ili9325_WriteReg(LCD_REG_56, 0x0504); ili9325_WriteReg(LCD_REG_57, 0x0007); ili9325_WriteReg(LCD_REG_60, 0x0105); ili9325_WriteReg(LCD_REG_61, 0x0808); /* Set GRAM area -----------------------------------------------------------*/ ili9325_WriteReg(LCD_REG_80, 0x0000); /* Horizontal GRAM Start Address */ ili9325_WriteReg(LCD_REG_81, 0x00EF); /* Horizontal GRAM End Address */ ili9325_WriteReg(LCD_REG_82, 0x0000); /* Vertical GRAM Start Address */ ili9325_WriteReg(LCD_REG_83, 0x013F); /* Vertical GRAM End Address */ ili9325_WriteReg(LCD_REG_96, 0xA700); /* Gate Scan Line(GS=1, scan direction is G320~G1) */ ili9325_WriteReg(LCD_REG_97, 0x0001); /* NDL,VLE, REV */ ili9325_WriteReg(LCD_REG_106, 0x0000); /* set scrolling line */ /* Partial Display Control -------------------------------------------------*/ ili9325_WriteReg(LCD_REG_128, 0x0000); ili9325_WriteReg(LCD_REG_129, 0x0000); ili9325_WriteReg(LCD_REG_130, 0x0000); ili9325_WriteReg(LCD_REG_131, 0x0000); ili9325_WriteReg(LCD_REG_132, 0x0000); ili9325_WriteReg(LCD_REG_133, 0x0000); /* Panel Control -----------------------------------------------------------*/ ili9325_WriteReg(LCD_REG_144, 0x0010); ili9325_WriteReg(LCD_REG_146, 0x0000); ili9325_WriteReg(LCD_REG_147, 0x0003); ili9325_WriteReg(LCD_REG_149, 0x0110); ili9325_WriteReg(LCD_REG_151, 0x0000); ili9325_WriteReg(LCD_REG_152, 0x0000); /* set GRAM write direction and BGR = 1 */ /* I/D=00 (Horizontal : increment, Vertical : decrement) */ /* AM=1 (address is updated in vertical writing direction) */ ili9325_WriteReg(LCD_REG_3, 0x1018); /* 262K color and display ON */ ili9325_WriteReg(LCD_REG_7, 0x0173); /* Set the Cursor */ ili9325_SetCursor(0, 0); /* Prepare to write GRAM */ LCD_IO_WriteReg(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; }
void LCD_WriteRegister16(uint16_t LCDReg, uint16_t LCDRegValue) { LCD_IO_WriteReg(LCDReg); LCD_IO_WriteMultipleData(&LCDRegValue, 1); }