stm3210c_eval_lcd.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm3210c_eval_lcd.c
00004   * @author  MCD Application Team
00005   * @version V4.3.0
00006   * @date    10/15/2010
00007   * @brief   This file includes the LCD driver for AM-240320L8TNQW00H (LCD_ILI9320)
00008   *          Liquid Crystal Display Module of STM3210C-EVAL board.
00009   ******************************************************************************
00010   * @copy
00011   *
00012   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00013   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00014   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00015   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00016   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00017   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00018   *
00019   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00020   */ 
00021 
00022 /* Includes ------------------------------------------------------------------*/
00023 #include "stm3210c_eval_lcd.h"
00024 #include "../Common/fonts.c"
00025 
00026 /** @addtogroup Utilities
00027   * @{
00028   */
00029 
00030 /** @addtogroup STM32_EVAL
00031   * @{
00032   */ 
00033 
00034 /** @addtogroup STM3210C_EVAL
00035   * @{
00036   */
00037     
00038 /** @defgroup STM3210C_EVAL_LCD 
00039   * @brief This file includes the LCD driver for AM-240320L8TNQW00H (LCD_ILI9320)
00040   *        Liquid Crystal Display Module of STM3210C-EVAL board.
00041   * @{
00042   */ 
00043 
00044 /** @defgroup STM3210C_EVAL_LCD_Private_TypesDefinitions
00045   * @{
00046   */ 
00047 /**
00048   * @}
00049   */ 
00050 
00051 
00052 /** @defgroup STM3210C_EVAL_LCD_Private_Defines
00053   * @{
00054   */ 
00055 #define START_BYTE         0x70
00056 #define SET_INDEX          0x00
00057 #define READ_STATUS        0x01
00058 #define LCD_WRITE_REG      0x02
00059 #define LCD_READ_REG       0x03
00060 #define MAX_POLY_CORNERS   200
00061 #define POLY_Y(Z)          ((int32_t)((Points + Z)->X))
00062 #define POLY_X(Z)          ((int32_t)((Points + Z)->Y))
00063 /**
00064   * @}
00065   */ 
00066 
00067 
00068 /** @defgroup STM3210C_EVAL_LCD_Private_Macros
00069   * @{
00070   */
00071 #define ABS(X)  ((X) > 0 ? (X) : -(X))    
00072 /**
00073   * @}
00074   */ 
00075 
00076 
00077 /** @defgroup STM3210C_EVAL_LCD_Private_Variables
00078   * @{
00079   */ 
00080 static sFONT *LCD_Currentfonts;
00081 /* Global variables to set the written text color */
00082 static  __IO uint16_t TextColor = 0x0000, BackColor = 0xFFFF;
00083 /**
00084   * @}
00085   */ 
00086 
00087 
00088 /** @defgroup STM3210C_EVAL_LCD_Private_FunctionPrototypes
00089   * @{
00090   */ 
00091 #ifndef USE_Delay
00092 static void delay(__IO uint32_t nCount);
00093 #endif /* USE_Delay*/
00094 static void PutPixel(int16_t x, int16_t y);
00095 static void LCD_PolyLineRelativeClosed(pPoint Points, uint16_t PointCount, uint16_t Closed);
00096 /**
00097   * @}
00098   */ 
00099 
00100 
00101 /** @defgroup STM3210C_EVAL_LCD_Private_Functions
00102   * @{
00103   */ 
00104 
00105 /**
00106   * @brief  DeInitializes the LCD.
00107   * @param  None
00108   * @retval None
00109   */
00110 void LCD_DeInit(void)
00111 {
00112   GPIO_InitTypeDef GPIO_InitStructure;
00113 
00114   /*!< LCD Display Off */
00115   LCD_DisplayOff();
00116 
00117   /*!< LCD_SPI disable */
00118   SPI_Cmd(LCD_SPI, DISABLE);
00119   
00120   /*!< LCD_SPI DeInit */
00121   SPI_I2S_DeInit(LCD_SPI);
00122    
00123   /*!< Disable SPI clock  */
00124   RCC_APB1PeriphClockCmd(LCD_SPI_CLK, DISABLE);
00125   GPIO_PinRemapConfig(GPIO_Remap_SPI3, DISABLE);
00126     
00127   /* Configure NCS in Output Push-Pull mode */
00128   GPIO_InitStructure.GPIO_Pin = LCD_NCS_PIN;
00129   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00130   GPIO_Init(LCD_NCS_GPIO_PORT, &GPIO_InitStructure);
00131    
00132   /* Configure SPI pins: SCK, MISO and MOSI */
00133   GPIO_InitStructure.GPIO_Pin = LCD_SPI_SCK_PIN;
00134   GPIO_Init(LCD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
00135 
00136   GPIO_InitStructure.GPIO_Pin = LCD_SPI_MISO_PIN;
00137   GPIO_Init(LCD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
00138   
00139   GPIO_InitStructure.GPIO_Pin = LCD_SPI_MOSI_PIN;
00140   GPIO_Init(LCD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
00141 }
00142 
00143 /**
00144   * @brief  Setups the LCD.
00145   * @param  None
00146   * @retval None
00147   */
00148 void LCD_Setup(void)
00149 { 
00150 /* Configure the LCD Control pins --------------------------------------------*/
00151   LCD_CtrlLinesConfig();
00152   
00153 /* Configure the LCD_SPI interface ----------------------------------------------*/
00154   LCD_SPIConfig();
00155   _delay_(5); /* Delay 50 ms */
00156   /* Start Initial Sequence ------------------------------------------------*/
00157   LCD_WriteReg(LCD_REG_229, 0x8000); /* Set the internal vcore voltage */
00158   LCD_WriteReg(LCD_REG_0,  0x0001); /* Start internal OSC. */
00159   LCD_WriteReg(LCD_REG_1,  0x0100); /* set SS and SM bit */
00160   LCD_WriteReg(LCD_REG_2,  0x0700); /* set 1 line inversion */
00161   LCD_WriteReg(LCD_REG_3,  0x1030); /* set GRAM write direction and BGR=1. */
00162   LCD_WriteReg(LCD_REG_4,  0x0000); /* Resize register */
00163   LCD_WriteReg(LCD_REG_8,  0x0202); /* set the back porch and front porch */
00164   LCD_WriteReg(LCD_REG_9,  0x0000); /* set non-display area refresh cycle ISC[3:0] */
00165   LCD_WriteReg(LCD_REG_10, 0x0000); /* FMARK function */
00166   LCD_WriteReg(LCD_REG_12, 0x0000); /* RGB interface setting */
00167   LCD_WriteReg(LCD_REG_13, 0x0000); /* Frame marker Position */
00168   LCD_WriteReg(LCD_REG_15, 0x0000); /* RGB interface polarity */
00169   /* Power On sequence -----------------------------------------------------*/
00170   LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
00171   LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
00172   LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */
00173   LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */
00174   _delay_(20);                 /* Dis-charge capacitor power voltage (200ms) */
00175   LCD_WriteReg(LCD_REG_16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
00176   LCD_WriteReg(LCD_REG_17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
00177   _delay_(5);                  /* Delay 50 ms */
00178   LCD_WriteReg(LCD_REG_18, 0x0139); /* VREG1OUT voltage */
00179   _delay_(5);                  /* Delay 50 ms */
00180   LCD_WriteReg(LCD_REG_19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
00181   LCD_WriteReg(LCD_REG_41, 0x0013); /* VCM[4:0] for VCOMH */
00182   _delay_(5);                  /* Delay 50 ms */
00183   LCD_WriteReg(LCD_REG_32, 0x0000); /* GRAM horizontal Address */
00184   LCD_WriteReg(LCD_REG_33, 0x0000); /* GRAM Vertical Address */
00185   /* Adjust the Gamma Curve ------------------------------------------------*/
00186   LCD_WriteReg(LCD_REG_48, 0x0006);
00187   LCD_WriteReg(LCD_REG_49, 0x0101);
00188   LCD_WriteReg(LCD_REG_50, 0x0003);
00189   LCD_WriteReg(LCD_REG_53, 0x0106);
00190   LCD_WriteReg(LCD_REG_54, 0x0b02);
00191   LCD_WriteReg(LCD_REG_55, 0x0302);
00192   LCD_WriteReg(LCD_REG_56, 0x0707);
00193   LCD_WriteReg(LCD_REG_57, 0x0007);
00194   LCD_WriteReg(LCD_REG_60, 0x0600);
00195   LCD_WriteReg(LCD_REG_61, 0x020b);
00196   
00197   /* Set GRAM area ---------------------------------------------------------*/
00198   LCD_WriteReg(LCD_REG_80, 0x0000); /* Horizontal GRAM Start Address */
00199   LCD_WriteReg(LCD_REG_81, 0x00EF); /* Horizontal GRAM End Address */
00200   LCD_WriteReg(LCD_REG_82, 0x0000); /* Vertical GRAM Start Address */
00201   LCD_WriteReg(LCD_REG_83, 0x013F); /* Vertical GRAM End Address */
00202   LCD_WriteReg(LCD_REG_96,  0x2700); /* Gate Scan Line */
00203   LCD_WriteReg(LCD_REG_97,  0x0001); /* NDL,VLE, REV */
00204   LCD_WriteReg(LCD_REG_106, 0x0000); /* set scrolling line */
00205   /* Partial Display Control -----------------------------------------------*/
00206   LCD_WriteReg(LCD_REG_128, 0x0000);
00207   LCD_WriteReg(LCD_REG_129, 0x0000);
00208   LCD_WriteReg(LCD_REG_130, 0x0000);
00209   LCD_WriteReg(LCD_REG_131, 0x0000);
00210   LCD_WriteReg(LCD_REG_132, 0x0000);
00211   LCD_WriteReg(LCD_REG_133, 0x0000);
00212   /* Panel Control ---------------------------------------------------------*/
00213   LCD_WriteReg(LCD_REG_144, 0x0010);
00214   LCD_WriteReg(LCD_REG_146, 0x0000);
00215   LCD_WriteReg(LCD_REG_147, 0x0003);
00216   LCD_WriteReg(LCD_REG_149, 0x0110);
00217   LCD_WriteReg(LCD_REG_151, 0x0000);
00218   LCD_WriteReg(LCD_REG_152, 0x0000);
00219   /* Set GRAM write direction and BGR = 1 */
00220   /* I/D=01 (Horizontal : increment, Vertical : decrement) */
00221   /* AM=1 (address is updated in vertical writing direction) */
00222   LCD_WriteReg(LCD_REG_3, 0x1018);
00223   LCD_WriteReg(LCD_REG_7, 0x0173); /* 262K color and display ON */
00224 }
00225 
00226 
00227 /**
00228   * @brief  Initializes the LCD.
00229   * @param  None
00230   * @retval None
00231   */
00232 void STM3210C_LCD_Init(void)
00233 {
00234   /* Setups the LCD */
00235   LCD_Setup();
00236   LCD_SetFont(&LCD_DEFAULT_FONT);
00237 }
00238 
00239 /**
00240   * @brief  Sets the LCD Text and Background colors.
00241   * @param  _TextColor: specifies the Text Color.
00242   * @param  _BackColor: specifies the Background Color.
00243   * @retval None
00244   */
00245 void LCD_SetColors(__IO uint16_t _TextColor, __IO uint16_t _BackColor)
00246 {
00247   TextColor = _TextColor; 
00248   BackColor = _BackColor;
00249 }
00250 
00251 /**
00252   * @brief  Gets the LCD Text and Background colors.
00253   * @param  _TextColor: pointer to the variable that will contain the Text 
00254             Color.
00255   * @param  _BackColor: pointer to the variable that will contain the Background 
00256             Color.
00257   * @retval None
00258   */
00259 void LCD_GetColors(__IO uint16_t *_TextColor, __IO uint16_t *_BackColor)
00260 {
00261   *_TextColor = TextColor; *_BackColor = BackColor;
00262 }
00263 
00264 /**
00265   * @brief  Sets the Text color.
00266   * @param  Color: specifies the Text color code RGB(5-6-5).
00267   * @retval None
00268   */
00269 void LCD_SetTextColor(__IO uint16_t Color)
00270 {
00271   TextColor = Color;
00272 }
00273 
00274 
00275 /**
00276   * @brief  Sets the Background color.
00277   * @param  Color: specifies the Background color code RGB(5-6-5).
00278   * @retval None
00279   */
00280 void LCD_SetBackColor(__IO uint16_t Color)
00281 {
00282   BackColor = Color;
00283 }
00284 
00285 /**
00286   * @brief  Sets the Text Font.
00287   * @param  fonts: specifies the font to be used.
00288   * @retval None
00289   */
00290 void LCD_SetFont(sFONT *fonts)
00291 {
00292   LCD_Currentfonts = fonts;
00293 }
00294 
00295 /**
00296   * @brief  Gets the Text Font.
00297   * @param  None.
00298   * @retval the used font.
00299   */
00300 sFONT *LCD_GetFont(void)
00301 {
00302   return LCD_Currentfonts;
00303 }
00304 
00305 /**
00306   * @brief  Clears the selected line.
00307   * @param  Line: the Line to be cleared.
00308   *   This parameter can be one of the following values:
00309   *     @arg Linex: where x can be 0..n
00310   * @retval None
00311   */
00312 void LCD_ClearLine(uint8_t Line)
00313 {
00314   uint16_t refcolumn = LCD_PIXEL_WIDTH - 1;
00315   /* Send the string character by character on lCD */
00316   while (((refcolumn + 1)& 0xFFFF) >= LCD_Currentfonts->Width)
00317   {
00318     /* Display one character on LCD */
00319     LCD_DisplayChar(Line, refcolumn, ' ');
00320     /* Decrement the column position by 16 */
00321     refcolumn -= LCD_Currentfonts->Width;
00322   }
00323 }
00324 
00325 
00326 /**
00327   * @brief  Clears the hole LCD.
00328   * @param  Color: the color of the background.
00329   * @retval None
00330   */
00331 void LCD_Clear(uint16_t Color)
00332 {
00333   uint32_t index = 0;
00334   
00335   LCD_SetCursor(0x00, 0x013F); 
00336   LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
00337   for(index = 0; index < 76800; index++)
00338   {
00339     LCD_WriteRAM(Color);
00340   }
00341   LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET); 
00342   
00343 }
00344 
00345 
00346 /**
00347   * @brief  Sets the cursor position.
00348   * @param  Xpos: specifies the X position.
00349   * @param  Ypos: specifies the Y position. 
00350   * @retval None
00351   */
00352 void LCD_SetCursor(uint8_t Xpos, uint16_t Ypos)
00353 {
00354  LCD_WriteReg(LCD_REG_32, Xpos);
00355  LCD_WriteReg(LCD_REG_33, Ypos);
00356 }
00357 
00358 
00359 /**
00360   * @brief  Draws a character on LCD.
00361   * @param  Xpos: the Line where to display the character shape.
00362   * @param  Ypos: start column address.
00363   * @param  c: pointer to the character data.
00364   * @retval None
00365   */
00366 void LCD_DrawChar(uint8_t Xpos, uint16_t Ypos, const uint16_t *c)
00367 {
00368   uint32_t index = 0, i = 0;
00369   uint8_t Xaddress = 0;
00370    
00371   Xaddress = Xpos;
00372   
00373   LCD_SetCursor(Xaddress, Ypos);
00374   
00375   for(index = 0; index < LCD_Currentfonts->Height; index++)
00376   {
00377     LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
00378     for(i = 0; i < LCD_Currentfonts->Width; i++)
00379     {
00380       if((((c[index] & ((0x80 << ((LCD_Currentfonts->Width / 12 ) * 8 ) ) >> i)) == 0x00) &&(LCD_Currentfonts->Width <= 12))||
00381         (((c[index] & (0x1 << i)) == 0x00)&&(LCD_Currentfonts->Width > 12 )))
00382 
00383       {
00384         LCD_WriteRAM(BackColor);
00385       }
00386       else
00387       {
00388         LCD_WriteRAM(TextColor);
00389       }
00390     }   
00391     LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET); 
00392     Xaddress++;
00393     LCD_SetCursor(Xaddress, Ypos);
00394   }
00395 }
00396 
00397 
00398 /**
00399   * @brief  Displays one character (16dots width, 24dots height).
00400   * @param  Line: the Line where to display the character shape .
00401   *   This parameter can be one of the following values:
00402   *     @arg Linex: where x can be 0..9
00403   * @param  Column: start column address.
00404   * @param  Ascii: character ascii code, must be between 0x20 and 0x7E.
00405   * @retval None
00406   */
00407 void LCD_DisplayChar(uint8_t Line, uint16_t Column, uint8_t Ascii)
00408 {
00409   Ascii -= 32;
00410   LCD_DrawChar(Line, Column, &LCD_Currentfonts->table[Ascii * LCD_Currentfonts->Height]);
00411 }
00412 
00413 
00414 /**
00415   * @brief  Displays a maximum of 20 char on the LCD.
00416   * @param  Line: the Line where to display the character shape .
00417   *   This parameter can be one of the following values:
00418   *     @arg Linex: where x can be 0..9
00419   * @param  *ptr: pointer to string to display on LCD.
00420   * @retval None
00421   */
00422 void LCD_DisplayStringLine(uint8_t Line, uint8_t *ptr)
00423 {
00424   uint16_t refcolumn = LCD_PIXEL_WIDTH - 1;
00425 
00426   /* Send the string character by character on lCD */
00427   while ((*ptr != 0) & (((refcolumn + 1) & 0xFFFF) >= LCD_Currentfonts->Width))
00428   {
00429     /* Display one character on LCD */
00430     LCD_DisplayChar(Line, refcolumn, *ptr);
00431     /* Decrement the column position by 16 */
00432     refcolumn -= LCD_Currentfonts->Width;
00433     /* Point on the next character */
00434     ptr++;
00435   }
00436 }
00437 
00438 
00439 /**
00440   * @brief  Sets a display window
00441   * @param  Xpos: specifies the X buttom left position.
00442   * @param  Ypos: specifies the Y buttom left position.
00443   * @param  Height: display window height.
00444   * @param  Width: display window width.
00445   * @retval None
00446   */
00447 void LCD_SetDisplayWindow(uint8_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width)
00448 { 
00449   /* Horizontal GRAM Start Address */
00450   if(Xpos >= Height)
00451   {
00452     LCD_WriteReg(LCD_REG_80, (Xpos - Height + 1));
00453   }
00454   else
00455   {
00456     LCD_WriteReg(LCD_REG_80, 0);
00457   }
00458   /* Horizontal GRAM End Address */
00459   LCD_WriteReg(LCD_REG_81, Xpos);
00460   /* Vertical GRAM Start Address */
00461   if(Ypos >= Width)
00462   {
00463     LCD_WriteReg(LCD_REG_82, (Ypos - Width + 1));
00464   }  
00465   else
00466   {
00467     LCD_WriteReg(LCD_REG_82, 0);
00468   }
00469   /* Vertical GRAM End Address */
00470   LCD_WriteReg(LCD_REG_83, Ypos);
00471   LCD_SetCursor(Xpos, Ypos);
00472 }
00473 
00474 
00475 /**
00476   * @brief  Disables LCD Window mode.
00477   * @param  None
00478   * @retval None
00479   */
00480 void LCD_WindowModeDisable(void)
00481 {
00482   LCD_SetDisplayWindow(239, 0x13F, 240, 320);
00483   LCD_WriteReg(LCD_REG_3, 0x1018);    
00484 }
00485 
00486 
00487 /**
00488   * @brief  Displays a line.
00489   * @param  Xpos: specifies the X position.
00490   * @param  Ypos: specifies the Y position.
00491   * @param  Length: line length.
00492   * @param  Direction: line direction.
00493   *   This parameter can be one of the following values: Vertical or Horizontal.
00494   * @retval None
00495   */
00496 void LCD_DrawLine(uint8_t Xpos, uint16_t Ypos, uint16_t Length, uint8_t Direction)
00497 {
00498   uint32_t i = 0;
00499   
00500   LCD_SetCursor(Xpos, Ypos);
00501   if(Direction == LCD_DIR_HORIZONTAL)
00502   { 
00503     LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
00504     for(i = 0; i < Length; i++)
00505     {
00506       LCD_WriteRAM(TextColor);
00507     }
00508     LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
00509   }
00510   else
00511   {
00512     for(i = 0; i < Length; i++)
00513     {
00514       LCD_WriteRAMWord(TextColor);
00515       Xpos++;
00516       LCD_SetCursor(Xpos, Ypos);
00517     }
00518   }
00519 }
00520 
00521 
00522 /**
00523   * @brief  Displays a rectangle.
00524   * @param  Xpos: specifies the X position.
00525   * @param  Ypos: specifies the Y position.
00526   * @param  Height: display rectangle height.
00527   * @param  Width: display rectangle width.
00528   * @retval None
00529   */
00530 void LCD_DrawRect(uint8_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width)
00531 {
00532   LCD_DrawLine(Xpos, Ypos, Width, LCD_DIR_HORIZONTAL);
00533   LCD_DrawLine((Xpos + Height), Ypos, Width, LCD_DIR_HORIZONTAL);
00534   
00535   LCD_DrawLine(Xpos, Ypos, Height, LCD_DIR_VERTICAL);
00536   LCD_DrawLine(Xpos, (Ypos - Width + 1), Height, LCD_DIR_VERTICAL);
00537 }
00538 
00539 
00540 /**
00541   * @brief  Displays a circle.
00542   * @param  Xpos: specifies the X position.
00543   * @param  Ypos: specifies the Y position.
00544   * @param  Radius
00545   * @retval None
00546   */
00547 void LCD_DrawCircle(uint8_t Xpos, uint16_t Ypos, uint16_t Radius)
00548 {
00549   s32  D;/* Decision Variable */ 
00550   uint32_t  CurX;/* Current X Value */
00551   uint32_t  CurY;/* Current Y Value */ 
00552   
00553   D = 3 - (Radius << 1);
00554   CurX = 0;
00555   CurY = Radius;
00556   
00557   while (CurX <= CurY)
00558   {
00559     LCD_SetCursor(Xpos + CurX, Ypos + CurY);
00560     LCD_WriteRAMWord(TextColor);
00561     LCD_SetCursor(Xpos + CurX, Ypos - CurY);
00562     LCD_WriteRAMWord(TextColor);
00563     LCD_SetCursor(Xpos - CurX, Ypos + CurY);
00564     LCD_WriteRAMWord(TextColor);
00565     LCD_SetCursor(Xpos - CurX, Ypos - CurY);
00566     LCD_WriteRAMWord(TextColor);
00567     LCD_SetCursor(Xpos + CurY, Ypos + CurX);
00568     LCD_WriteRAMWord(TextColor);
00569     LCD_SetCursor(Xpos + CurY, Ypos - CurX);
00570     LCD_WriteRAMWord(TextColor);
00571     LCD_SetCursor(Xpos - CurY, Ypos + CurX);
00572     LCD_WriteRAMWord(TextColor);
00573     LCD_SetCursor(Xpos - CurY, Ypos - CurX);
00574     LCD_WriteRAMWord(TextColor);
00575     if (D < 0)
00576     { 
00577       D += (CurX << 2) + 6;
00578     }
00579     else
00580     {
00581       D += ((CurX - CurY) << 2) + 10;
00582       CurY--;
00583     }
00584     CurX++;
00585   }
00586 }
00587 
00588 /**
00589   * @brief  Displays a monocolor picture.
00590   * @param  Pict: pointer to the picture array.
00591   * @retval None
00592   */
00593 void LCD_DrawMonoPict(const uint32_t *Pict)
00594 {
00595   uint32_t index = 0, i = 0;
00596   LCD_SetCursor(0, (LCD_PIXEL_WIDTH - 1)); 
00597   LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
00598   for(index = 0; index < 2400; index++)
00599   {
00600     for(i = 0; i < 32; i++)
00601     {
00602       if((Pict[index] & (1 << i)) == 0x00)
00603       {
00604         LCD_WriteRAM(BackColor);
00605       }
00606       else
00607       {
00608         LCD_WriteRAM(TextColor);
00609       }
00610     }
00611   }
00612   LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
00613 }
00614 
00615 #ifdef USE_LCD_DrawBMP
00616 /**
00617   * @brief  Displays a bitmap picture loaded in the SPI Flash.
00618   * @param  BmpAddress: Bmp picture address in the SPI Flash.
00619   * @retval None
00620   */
00621 //void LCD_DrawBMP(uint32_t BmpAddress)
00622 //{
00623 //  uint32_t i = 0, size = 0;
00624 //
00625 //  /* Read bitmap size */
00626 //  sFLASH_ReadBuffer((uint8_t*)&size, BmpAddress + 2, 4);
00627 //
00628 //  /* get bitmap data address offset */
00629 //  sFLASH_ReadBuffer((uint8_t*)&i, BmpAddress + 10, 4);
00630 //  
00631 //  size = (size - i)/2;
00632 //
00633 //  sFLASH_StartReadSequence(BmpAddress + i);
00634 //
00635 //  /* Disable LCD_SPI  */
00636 //  SPI_Cmd(LCD_SPI, DISABLE);
00637 //  /* SPI in 16-bit mode */
00638 //  SPI_DataSizeConfig(LCD_SPI, SPI_DataSize_16b);
00639 //
00640 //  /* Enable LCD_SPI  */
00641 //  SPI_Cmd(LCD_SPI, ENABLE);
00642 //  
00643 //  /* Set GRAM write direction and BGR = 1 */
00644 //  /* I/D=00 (Horizontal : decrement, Vertical : decrement) */
00645 //  /* AM=1 (address is updated in vertical writing direction) */
00646 //  LCD_WriteReg(LCD_REG_3, 0x1008);
00647 //
00648 //  LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
00649 //
00650 //  /* Read bitmap data from SPI Flash and send them to LCD */
00651 //  for(i = 0; i < size; i++)
00652 //  {
00653 //    LCD_WriteRAM(__REV_HalfWord(sFLASH_SendHalfWord(0xA5A5)));
00654 //  }
00655 //
00656 //  LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
00657 //
00658 //  /* Deselect the FLASH: Chip Select high */
00659 //  sFLASH_CS_HIGH();
00660 //
00661 //  /* Disable LCD_SPI  */
00662 //  SPI_Cmd(LCD_SPI, DISABLE);
00663 //  /* SPI in 8-bit mode */
00664 //  SPI_DataSizeConfig(LCD_SPI, SPI_DataSize_8b);
00665 //
00666 //  /* Enable LCD_SPI  */
00667 //  SPI_Cmd(LCD_SPI, ENABLE);
00668 //
00669 //  /* Set GRAM write direction and BGR = 1 */
00670 //  /* I/D = 01 (Horizontal : increment, Vertical : decrement) */
00671 //  /* AM = 1 (address is updated in vertical writing direction) */
00672 //  LCD_WriteReg(LCD_REG_3, 0x1018);
00673 //}
00674 
00675 
00676 /**
00677   * @brief  Displays a bitmap picture loaded in the Internal FLASH.
00678   * @param  BmpAddress: Bmp picture address in the Internal FLASH.
00679   * @retval None
00680   */
00681 void LCD_DrawBMP(const uint16_t *BmpAddress)
00682 {
00683   uint32_t i = 0, size = 0;
00684   /* Read bitmap size */
00685   size = BmpAddress[1] | (BmpAddress[2] << 16);
00686   /* get bitmap data address offset */
00687   i = BmpAddress[5] | (BmpAddress[6] << 16);
00688   size = (size - i)/2;
00689   BmpAddress += i/2;
00690   /* Set GRAM write direction and BGR = 1 */
00691   /* I/D=00 (Horizontal : decrement, Vertical : decrement) */
00692   /* AM=1 (address is updated in vertical writing direction) */
00693   LCD_WriteReg(LCD_REG_3, 0x1008);
00694   LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
00695   /* Read bitmap data from SPI Flash and send them to LCD */
00696   for(i = 0; i < size; i++)
00697   {
00698     LCD_WriteRAM(BmpAddress[i]);
00699   }
00700   LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
00701   /* Set GRAM write direction and BGR = 1 */
00702   /* I/D = 01 (Horizontal : increment, Vertical : decrement) */
00703   /* AM = 1 (address is updated in vertical writing direction) */
00704   LCD_WriteReg(LCD_REG_3, 0x1018);
00705 }
00706 #endif
00707 
00708 /**
00709   * @brief  Displays a full rectangle.
00710   * @param  Xpos: specifies the X position.
00711   * @param  Ypos: specifies the Y position.
00712   * @param  Height: rectangle height.
00713   * @param  Width: rectangle width.
00714   * @retval None
00715   */
00716 void LCD_DrawFullRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
00717 {
00718   LCD_SetTextColor(TextColor);
00719 
00720   LCD_DrawLine(Xpos, Ypos, Width, LCD_DIR_HORIZONTAL);
00721   LCD_DrawLine((Xpos + Height), Ypos, Width, LCD_DIR_HORIZONTAL);
00722   
00723   LCD_DrawLine(Xpos, Ypos, Height, LCD_DIR_VERTICAL);
00724   LCD_DrawLine(Xpos, (Ypos - Width + 1), Height, LCD_DIR_VERTICAL);
00725 
00726   Width -= 2;
00727   Height--;
00728   Ypos--;
00729 
00730   LCD_SetTextColor(BackColor);
00731 
00732   while(Height--)
00733   {
00734     LCD_DrawLine(++Xpos, Ypos, Width, LCD_DIR_HORIZONTAL);    
00735   }
00736 
00737   LCD_SetTextColor(TextColor);
00738 }
00739 
00740 /**
00741   * @brief  Displays a full circle.
00742   * @param  Xpos: specifies the X position.
00743   * @param  Ypos: specifies the Y position.
00744   * @param  Radius
00745   * @retval None
00746   */
00747 void LCD_DrawFullCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
00748 {
00749   int32_t  D;    /* Decision Variable */ 
00750   uint32_t  CurX;/* Current X Value */
00751   uint32_t  CurY;/* Current Y Value */ 
00752   
00753   D = 3 - (Radius << 1);
00754 
00755   CurX = 0;
00756   CurY = Radius;
00757   
00758   LCD_SetTextColor(BackColor);
00759 
00760   while (CurX <= CurY)
00761   {
00762     if(CurY > 0) 
00763     {
00764       LCD_DrawLine(Xpos - CurX, Ypos + CurY, 2*CurY, LCD_DIR_HORIZONTAL);
00765       LCD_DrawLine(Xpos + CurX, Ypos + CurY, 2*CurY, LCD_DIR_HORIZONTAL);
00766     }
00767 
00768     if(CurX > 0) 
00769     {
00770       LCD_DrawLine(Xpos - CurY, Ypos + CurX, 2*CurX, LCD_DIR_HORIZONTAL);
00771       LCD_DrawLine(Xpos + CurY, Ypos + CurX, 2*CurX, LCD_DIR_HORIZONTAL);
00772     }
00773     if (D < 0)
00774     { 
00775       D += (CurX << 2) + 6;
00776     }
00777     else
00778     {
00779       D += ((CurX - CurY) << 2) + 10;
00780       CurY--;
00781     }
00782     CurX++;
00783   }
00784 
00785   LCD_SetTextColor(TextColor);
00786   LCD_DrawCircle(Xpos, Ypos, Radius);
00787 }
00788 
00789 /**
00790   * @brief  Displays an uni line (between two points).
00791   * @param  x1: specifies the point 1 x position.
00792   * @param  y1: specifies the point 1 y position.
00793   * @param  x2: specifies the point 2 x position.
00794   * @param  y2: specifies the point 2 y position.
00795   * @retval None
00796   */
00797 void LCD_DrawUniLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
00798 {
00799   int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0, 
00800   yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0, 
00801   curpixel = 0;
00802   
00803   deltax = ABS(x2 - x1);        /* The difference between the x's */
00804   deltay = ABS(y2 - y1);        /* The difference between the y's */
00805   x = x1;                       /* Start x off at the first pixel */
00806   y = y1;                       /* Start y off at the first pixel */
00807   
00808   if (x2 >= x1)                 /* The x-values are increasing */
00809   {
00810     xinc1 = 1;
00811     xinc2 = 1;
00812   }
00813   else                          /* The x-values are decreasing */
00814   {
00815     xinc1 = -1;
00816     xinc2 = -1;
00817   }
00818   
00819   if (y2 >= y1)                 /* The y-values are increasing */
00820   {
00821     yinc1 = 1;
00822     yinc2 = 1;
00823   }
00824   else                          /* The y-values are decreasing */
00825   {
00826     yinc1 = -1;
00827     yinc2 = -1;
00828   }
00829   
00830   if (deltax >= deltay)         /* There is at least one x-value for every y-value */
00831   {
00832     xinc1 = 0;                  /* Don't change the x when numerator >= denominator */
00833     yinc2 = 0;                  /* Don't change the y for every iteration */
00834     den = deltax;
00835     num = deltax / 2;
00836     numadd = deltay;
00837     numpixels = deltax;         /* There are more x-values than y-values */
00838   }
00839   else                          /* There is at least one y-value for every x-value */
00840   {
00841     xinc2 = 0;                  /* Don't change the x for every iteration */
00842     yinc1 = 0;                  /* Don't change the y when numerator >= denominator */
00843     den = deltay;
00844     num = deltay / 2;
00845     numadd = deltax;
00846     numpixels = deltay;         /* There are more y-values than x-values */
00847   }
00848   
00849   for (curpixel = 0; curpixel <= numpixels; curpixel++)
00850   {
00851     PutPixel(x, y);             /* Draw the current pixel */
00852     num += numadd;              /* Increase the numerator by the top of the fraction */
00853     if (num >= den)             /* Check if numerator >= denominator */
00854     {
00855       num -= den;               /* Calculate the new numerator value */
00856       x += xinc1;               /* Change the x as appropriate */
00857       y += yinc1;               /* Change the y as appropriate */
00858     }
00859     x += xinc2;                 /* Change the x as appropriate */
00860     y += yinc2;                 /* Change the y as appropriate */
00861   }
00862 }
00863 
00864 /**
00865   * @brief  Displays an polyline (between many points).
00866   * @param  Points: pointer to the points array.
00867   * @param  PointCount: Number of points.
00868   * @retval None
00869   */
00870 void LCD_PolyLine(pPoint Points, uint16_t PointCount)
00871 {
00872   int16_t X = 0, Y = 0;
00873 
00874   if(PointCount < 2)
00875   {
00876     return;
00877   }
00878 
00879   while(--PointCount)
00880   {
00881     X = Points->X;
00882     Y = Points->Y;
00883     Points++;
00884     LCD_DrawUniLine(X, Y, Points->X, Points->Y);
00885   }
00886 }
00887 
00888 /**
00889   * @brief  Displays an relative polyline (between many points).
00890   * @param  Points: pointer to the points array.
00891   * @param  PointCount: Number of points.
00892   * @param  Closed: specifies if the draw is closed or not.
00893   *           1: closed, 0 : not closed.
00894   * @retval None
00895   */
00896 static void LCD_PolyLineRelativeClosed(pPoint Points, uint16_t PointCount, uint16_t Closed)
00897 {
00898   int16_t X = 0, Y = 0;
00899   pPoint First = Points;
00900 
00901   if(PointCount < 2)
00902   {
00903     return;
00904   }  
00905   X = Points->X;
00906   Y = Points->Y;
00907   while(--PointCount)
00908   {
00909     Points++;
00910     LCD_DrawUniLine(X, Y, X + Points->X, Y + Points->Y);
00911     X = X + Points->X;
00912     Y = Y + Points->Y;
00913   }
00914   if(Closed)
00915   {
00916     LCD_DrawUniLine(First->X, First->Y, X, Y);
00917   }  
00918 }
00919 
00920 /**
00921   * @brief  Displays a closed polyline (between many points).
00922   * @param  Points: pointer to the points array.
00923   * @param  PointCount: Number of points.
00924   * @retval None
00925   */
00926 void LCD_ClosedPolyLine(pPoint Points, uint16_t PointCount)
00927 {
00928   LCD_PolyLine(Points, PointCount);
00929   LCD_DrawUniLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y);
00930 }
00931 
00932 /**
00933   * @brief  Displays a relative polyline (between many points).
00934   * @param  Points: pointer to the points array.
00935   * @param  PointCount: Number of points.
00936   * @retval None
00937   */
00938 void LCD_PolyLineRelative(pPoint Points, uint16_t PointCount)
00939 {
00940   LCD_PolyLineRelativeClosed(Points, PointCount, 0);
00941 }
00942 
00943 /**
00944   * @brief  Displays a closed relative polyline (between many points).
00945   * @param  Points: pointer to the points array.
00946   * @param  PointCount: Number of points.
00947   * @retval None
00948   */
00949 void LCD_ClosedPolyLineRelative(pPoint Points, uint16_t PointCount)
00950 {
00951   LCD_PolyLineRelativeClosed(Points, PointCount, 1);
00952 }
00953 
00954 
00955 /**
00956   * @brief  Displays a  full polyline (between many points).
00957   * @param  Points: pointer to the points array.
00958   * @param  PointCount: Number of points.
00959   * @retval None
00960   */
00961 void LCD_FillPolyLine(pPoint Points, uint16_t PointCount)
00962 {
00963   /*  public-domain code by Darel Rex Finley, 2007 */
00964   uint16_t  nodes = 0, nodeX[MAX_POLY_CORNERS], pixelX = 0, pixelY = 0, i = 0,
00965   j = 0, swap = 0;
00966   uint16_t  IMAGE_LEFT = 0, IMAGE_RIGHT = 0, IMAGE_TOP = 0, IMAGE_BOTTOM = 0;
00967 
00968   IMAGE_LEFT = IMAGE_RIGHT = Points->X;
00969   IMAGE_TOP= IMAGE_BOTTOM = Points->Y;
00970 
00971   for(i = 1; i < PointCount; i++)
00972   {
00973     pixelX = POLY_X(i);
00974     if(pixelX < IMAGE_LEFT)
00975     {
00976       IMAGE_LEFT = pixelX;
00977     }
00978     if(pixelX > IMAGE_RIGHT)
00979     {
00980       IMAGE_RIGHT = pixelX;
00981     }
00982     
00983     pixelY = POLY_Y(i);
00984     if(pixelY < IMAGE_TOP)
00985     { 
00986       IMAGE_TOP = pixelY;
00987     }
00988     if(pixelY > IMAGE_BOTTOM)
00989     {
00990       IMAGE_BOTTOM = pixelY;
00991     }
00992   }
00993   
00994   LCD_SetTextColor(BackColor);  
00995 
00996   /*  Loop through the rows of the image. */
00997   for (pixelY = IMAGE_TOP; pixelY < IMAGE_BOTTOM; pixelY++) 
00998   {  
00999     /* Build a list of nodes. */
01000     nodes = 0; j = PointCount-1;
01001 
01002     for (i = 0; i < PointCount; i++) 
01003     {
01004       if (POLY_Y(i)<(double) pixelY && POLY_Y(j)>=(double) pixelY || POLY_Y(j)<(double) pixelY && POLY_Y(i)>=(double) pixelY) 
01005       {
01006         nodeX[nodes++]=(int) (POLY_X(i)+((pixelY-POLY_Y(i))*(POLY_X(j)-POLY_X(i)))/(POLY_Y(j)-POLY_Y(i))); 
01007       }
01008       j = i; 
01009     }
01010   
01011     /* Sort the nodes, via a simple “Bubble” sort. */
01012     i = 0;
01013     while (i < nodes-1) 
01014     {
01015       if (nodeX[i]>nodeX[i+1]) 
01016       {
01017         swap = nodeX[i]; 
01018         nodeX[i] = nodeX[i+1]; 
01019         nodeX[i+1] = swap; 
01020         if(i)
01021         {
01022           i--; 
01023         }
01024       }
01025       else 
01026       {
01027         i++;
01028       }
01029     }
01030   
01031     /*  Fill the pixels between node pairs. */
01032     for (i = 0; i < nodes; i+=2) 
01033     {
01034       if(nodeX[i] >= IMAGE_RIGHT) 
01035       {
01036         break;
01037       }
01038       if(nodeX[i+1] > IMAGE_LEFT) 
01039       {
01040         if (nodeX[i] < IMAGE_LEFT)
01041         {
01042           nodeX[i]=IMAGE_LEFT;
01043         }
01044         if(nodeX[i+1] > IMAGE_RIGHT)
01045         {
01046           nodeX[i+1] = IMAGE_RIGHT;
01047         }
01048         LCD_SetTextColor(BackColor);
01049         LCD_DrawLine(pixelY, nodeX[i+1], nodeX[i+1] - nodeX[i], LCD_DIR_HORIZONTAL);
01050         LCD_SetTextColor(TextColor);
01051         PutPixel(pixelY, nodeX[i+1]);
01052         PutPixel(pixelY, nodeX[i]);
01053         /* for (j=nodeX[i]; j<nodeX[i+1]; j++) PutPixel(j,pixelY); */
01054       }
01055     }
01056   } 
01057 
01058   /* draw the edges */
01059   LCD_SetTextColor(TextColor);
01060 }
01061 
01062 /**
01063   * @brief  Reset LCD control line(/CS) and Send Start-Byte
01064   * @param  Start_Byte: the Start-Byte to be sent
01065   * @retval None
01066   */
01067 void LCD_nCS_StartByte(uint8_t Start_Byte)
01068 {
01069   LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_RESET);
01070   SPI_I2S_SendData(LCD_SPI, Start_Byte);
01071   while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
01072   {
01073   }
01074 }
01075 
01076 /**
01077   * @brief  Writes index to select the LCD register.
01078   * @param  LCD_Reg: address of the selected register.
01079   * @retval None
01080   */
01081 void LCD_WriteRegIndex(uint8_t LCD_Reg)
01082 {
01083   /* Reset LCD control line(/CS) and Send Start-Byte */
01084   LCD_nCS_StartByte(START_BYTE | SET_INDEX);
01085   /* Write 16-bit Reg Index (High Byte is 0) */
01086   SPI_I2S_SendData(LCD_SPI, 0x00);
01087   while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
01088   {
01089   }
01090   SPI_I2S_SendData(LCD_SPI, LCD_Reg);
01091   while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
01092   {
01093   }
01094   LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
01095 }
01096 
01097 
01098 /**
01099   * @brief  Reads the selected LCD Register.
01100   * @param  None
01101   * @retval LCD Register Value.
01102   */
01103 uint16_t LCD_ReadReg(uint8_t LCD_Reg)
01104 {
01105   uint16_t tmp = 0;
01106   uint8_t i = 0;
01107   
01108   /* LCD_SPI prescaler: 4 */
01109   LCD_SPI->CR1 &= 0xFFC7;
01110   LCD_SPI->CR1 |= 0x0008;
01111   /* Write 16-bit Index (then Read Reg) */
01112   LCD_WriteRegIndex(LCD_Reg);
01113   /* Read 16-bit Reg */
01114   /* Reset LCD control line(/CS) and Send Start-Byte */
01115   LCD_nCS_StartByte(START_BYTE | LCD_READ_REG);
01116   
01117   for(i = 0; i < 5; i++)
01118   {
01119     SPI_I2S_SendData(LCD_SPI, 0xFF);
01120     while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
01121     {
01122     }
01123     /* One byte of invalid dummy data read after the start byte */
01124     while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_RXNE) == RESET)
01125     {    
01126     }
01127     SPI_I2S_ReceiveData(LCD_SPI); 
01128   }
01129   SPI_I2S_SendData(LCD_SPI, 0xFF);
01130   /* Read upper byte */
01131   while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
01132   {
01133   }
01134   /* Read lower byte */
01135   while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_RXNE) == RESET)
01136   {
01137   }
01138   tmp = SPI_I2S_ReceiveData(LCD_SPI);
01139   
01140   
01141   SPI_I2S_SendData(LCD_SPI, 0xFF);
01142   while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
01143   {
01144   }
01145   /* Read lower byte */
01146   while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_RXNE) == RESET)
01147   {
01148   }
01149   tmp = ((tmp & 0xFF) << 8) | SPI_I2S_ReceiveData(LCD_SPI);
01150   LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
01151   /* LCD_SPI prescaler: 2 */
01152   LCD_SPI->CR1 &= 0xFFC7;
01153   return tmp;
01154 }
01155 
01156 
01157 /**
01158   * @brief  Prepare to write to the LCD RAM.
01159   * @param  None
01160   * @retval None
01161   */
01162 void LCD_WriteRAM_Prepare(void)
01163 {
01164   LCD_WriteRegIndex(LCD_REG_34); /* Select GRAM Reg */
01165   /* Reset LCD control line(/CS) and Send Start-Byte */
01166   LCD_nCS_StartByte(START_BYTE | LCD_WRITE_REG);
01167 }
01168 
01169 
01170 /**
01171   * @brief  Writes 1 word to the LCD RAM.
01172   * @param  RGB_Code: the pixel color in RGB mode (5-6-5).
01173   * @retval None
01174   */
01175 void LCD_WriteRAMWord(uint16_t RGB_Code)
01176 {
01177   LCD_WriteRAM_Prepare();
01178   LCD_WriteRAM(RGB_Code);
01179   LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
01180 }
01181 
01182 
01183 /**
01184   * @brief  Writes to the selected LCD register.
01185   * @param  LCD_Reg: address of the selected register.
01186   * @param  LCD_RegValue: value to write to the selected register.
01187   * @retval None
01188   */
01189 void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue)
01190 {
01191   /* Write 16-bit Index (then Write Reg) */
01192   LCD_WriteRegIndex(LCD_Reg);
01193   /* Write 16-bit Reg */
01194   /* Reset LCD control line(/CS) and Send Start-Byte */
01195   LCD_nCS_StartByte(START_BYTE | LCD_WRITE_REG);
01196   SPI_I2S_SendData(LCD_SPI, LCD_RegValue>>8);
01197   while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
01198   {
01199   }
01200   SPI_I2S_SendData(LCD_SPI, (LCD_RegValue & 0xFF));
01201   while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
01202   {
01203   }
01204   LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
01205 }
01206 
01207 
01208 /**
01209   * @brief  Writes to the LCD RAM.
01210   * @param  RGB_Code: the pixel color in RGB mode (5-6-5).
01211   * @retval None
01212   */
01213 void LCD_WriteRAM(uint16_t RGB_Code)
01214 {
01215   SPI_I2S_SendData(LCD_SPI, RGB_Code >> 8);
01216   while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
01217   {
01218   }
01219   SPI_I2S_SendData(LCD_SPI, RGB_Code & 0xFF);
01220   while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
01221   {
01222   }
01223 }
01224 
01225 
01226 /**
01227   * @brief  Power on the LCD.
01228   * @param  None
01229   * @retval None
01230   */
01231 void LCD_PowerOn(void)
01232 { 
01233   /* Power On sequence ---------------------------------------------------------*/
01234   LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
01235   LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
01236   LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */
01237   LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */
01238   _delay_(20);                 /* Dis-charge capacitor power voltage (200ms) */
01239   LCD_WriteReg(LCD_REG_16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
01240   LCD_WriteReg(LCD_REG_17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
01241   _delay_(5);                  /* Delay 50 ms */
01242   LCD_WriteReg(LCD_REG_18, 0x0139); /* VREG1OUT voltage */
01243   _delay_(5);                  /* delay 50 ms */
01244   LCD_WriteReg(LCD_REG_19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
01245   LCD_WriteReg(LCD_REG_41, 0x0013); /* VCM[4:0] for VCOMH */
01246   _delay_(5);                  /* delay 50 ms */
01247   LCD_WriteReg(LCD_REG_7, 0x0173);  /* 262K color and display ON */
01248 }
01249 
01250 /**
01251   * @brief  Enables the Display.
01252   * @param  None
01253   * @retval None
01254   */
01255 void LCD_DisplayOn(void)
01256 {
01257   /* Display On */
01258   LCD_WriteReg(LCD_REG_7, 0x0173); /* 262K color and display ON */
01259  
01260 }
01261 
01262 /**
01263   * @brief  Disables the Display.
01264   * @param  None
01265   * @retval None
01266   */
01267 void LCD_DisplayOff(void)
01268 {
01269   /* Display Off */
01270   LCD_WriteReg(LCD_REG_7, 0x0);
01271 }
01272 
01273 /**
01274   * @brief  Configures LCD control lines in Output Push-Pull mode.
01275   * @param  None
01276   * @retval None
01277   */
01278 void LCD_CtrlLinesConfig(void)
01279 {
01280   GPIO_InitTypeDef GPIO_InitStructure;
01281 
01282   /* Enable GPIO clock */
01283   RCC_APB2PeriphClockCmd(LCD_NCS_GPIO_CLK, ENABLE);
01284 
01285   /* Configure NCS in Output Push-Pull mode */
01286   GPIO_InitStructure.GPIO_Pin = LCD_NCS_PIN;
01287   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
01288   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
01289   GPIO_Init(LCD_NCS_GPIO_PORT, &GPIO_InitStructure);  
01290 }
01291 
01292 /**
01293   * @brief  Sets or reset LCD control lines.
01294   * @param  GPIOx: where x can be B or D to select the GPIO peripheral.
01295   * @param  CtrlPins: the Control line. This parameter can be:
01296   *     @arg LCD_NCS_PIN: Chip Select pin
01297   * @param  BitVal: specifies the value to be written to the selected bit.
01298   *   This parameter can be:
01299   *     @arg Bit_RESET: to clear the port pin
01300   *     @arg Bit_SET: to set the port pin
01301   * @retval None
01302   */
01303 void LCD_CtrlLinesWrite(GPIO_TypeDef* GPIOx, uint16_t CtrlPins, BitAction BitVal)
01304 {
01305   /* Set or Reset the control line */
01306   GPIO_WriteBit(GPIOx, CtrlPins, BitVal);
01307 }
01308 
01309 
01310 /**
01311   * @brief  Configures the LCD_SPI interface.
01312   * @param  None
01313   * @retval None
01314   */
01315 void LCD_SPIConfig(void)
01316 {
01317   SPI_InitTypeDef    SPI_InitStructure;
01318   GPIO_InitTypeDef   GPIO_InitStructure;
01319 
01320   /* Enable GPIO clock */
01321   RCC_APB2PeriphClockCmd(LCD_SPI_SCK_GPIO_CLK | LCD_SPI_MISO_GPIO_CLK | LCD_SPI_MOSI_GPIO_CLK
01322                          | RCC_APB2Periph_AFIO, ENABLE);
01323   GPIO_PinRemapConfig(GPIO_Remap_SPI3, ENABLE);
01324 
01325   /* Enable SPI clock  */
01326   RCC_APB1PeriphClockCmd(LCD_SPI_CLK, ENABLE);
01327   
01328   /* Configure SPI pins: SCK, MISO and MOSI */
01329   GPIO_InitStructure.GPIO_Pin = LCD_SPI_SCK_PIN;
01330   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
01331   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
01332   GPIO_Init(LCD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
01333 
01334   GPIO_InitStructure.GPIO_Pin = LCD_SPI_MISO_PIN;
01335   GPIO_Init(LCD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
01336   
01337   GPIO_InitStructure.GPIO_Pin = LCD_SPI_MOSI_PIN;
01338   GPIO_Init(LCD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
01339   
01340   SPI_I2S_DeInit(LCD_SPI);
01341   
01342   /* SPI Config */
01343   SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
01344   SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
01345   SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
01346   SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
01347   SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
01348   SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
01349   SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
01350   SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
01351   SPI_Init(LCD_SPI, &SPI_InitStructure);
01352 
01353   /* SPI enable */
01354   SPI_Cmd(LCD_SPI, ENABLE);
01355 }
01356 
01357 /**
01358   * @brief  Displays a pixel.
01359   * @param  x: pixel x.
01360   * @param  y: pixel y.  
01361   * @retval None
01362   */
01363 static void PutPixel(int16_t x, int16_t y)
01364 { 
01365   if(x < 0 || x > 239 || y < 0 || y > 319)
01366   {
01367     return;  
01368   }
01369   LCD_DrawLine(x, y, 1, LCD_DIR_HORIZONTAL);
01370 }
01371 
01372 #ifndef USE_Delay
01373 /**
01374   * @brief  Inserts a delay time.
01375   * @param  nCount: specifies the delay time length.
01376   * @retval None
01377   */
01378 static void delay(__IO uint32_t nCount)
01379 {
01380   __IO uint32_t index = 0; 
01381   for(index = (100000 * nCount); index != 0; index--)
01382   {
01383   }
01384 }
01385 #endif /* USE_Delay*/
01386 /**
01387   * @}
01388   */ 
01389 
01390 /**
01391   * @}
01392   */ 
01393 
01394 /**
01395   * @}
01396   */
01397   
01398 /**
01399   * @}
01400   */ 
01401   
01402 /**
01403   * @}
01404   */  
01405   
01406 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
STM32F10x Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit  www.st.com/STM32