1 /********************* (C) COPYRIGHT 2007 RAISONANCE S.A.S. *******************/
5 * @brief Various utilities for drawings (characters, ..)
11 /******************************************************************************/
13 /* Includes ------------------------------------------------------------------*/
18 /* Private define ------------------------------------------------------------*/
19 #define V9_MADCTRVAL 0x90
20 #define V12_MADCTRVAL 0x30
21 #define V3_MADCTRVAL 0x50
22 #define V6_MADCTRVAL 0xF0
24 #define ROTATE_DIVISER 500
26 /* Private variables ---------------------------------------------------------*/
28 static u16 CharMagniCoeff = 1; /*!< Current character magnify coefficient. */
29 static u16 BGndColor; /*!< Current background color. */
30 static u16 TextColor; /*!< Current text color. */
38 u32 OldTemp; //FL071107
43 u8 UsbState,OldUsbState;
44 static int divider_coord = 0;
46 // Screen orientation management
47 int rotate_counter = 0;
48 Rotate_H12_V_Match_TypeDef previous_H12 = V9;
49 Rotate_H12_V_Match_TypeDef previous_previous_H12 = V9;
50 Rotate_H12_V_Match_TypeDef H12;
51 Rotate_H12_V_Match_TypeDef CurrentScreenOrientation;
52 int CurrentRotateScreen = 1;
57 /* Private functions ---------------------------------------------------------*/
59 /*******************************************************************************
63 *******************************************************************************/
66 * This function convert an u16 in ascii radix 10
68 * @param[out] ptr A pointer to a string where the converted value will be put.
69 * @param[in] X The value to convert.
71 * @see DRAW_DisplayVbat
74 /******************************************************************************/
75 static void vbattoa( char* ptr, u16 X )
103 /*******************************************************************************
105 * DRAW_DisplayStringWithMode
107 *******************************************************************************/
110 * This function is used to display a 17char max string of
111 * characters on the LCD display on the selected line.
113 * this function is the user interface to use the LCD driver.
115 * @param[in] x The horizontal screen coordinate where to draw the string.
116 * @param[in] y The vertical screen coordinate where to draw the string.
117 * @param[in] ptr Pointer to string to display.
118 * @param[in] len String size.
119 * @param[in] mode Display mode: 0 normal, 1 inverted colors.
121 * @warning The (0x0) point in on the low left corner.
123 * @see DRAW_DisplayString
124 * @see DRAW_DisplayStringInverted
127 /******************************************************************************/
128 static void DRAW_DisplayStringWithMode( u8 x, u8 y, const u8* ptr, u8 len, int mode )
132 /* Send the string character by character on LCD */
133 while ((*ptr!=0)&&(i<18))
135 /* Display one character on LCD */
136 LCD_DisplayChar( ref_x, y, *ptr, mode ? BGndColor : TextColor, mode ? TextColor : BGndColor, CharMagniCoeff );
138 /* Increment the column position by 7 */
139 ref_x+= (7*CharMagniCoeff);
141 /* Point on the next character */
144 /* Increment the character counter */
146 /* If we reach the maximum Line character */
151 /* Display one character on LCD */
152 LCD_DisplayChar( ref_x, y, ' ', mode ? BGndColor : TextColor, mode ? TextColor : BGndColor, CharMagniCoeff );
154 /* Increment the column position by 7 */
155 ref_x += ( 7 * CharMagniCoeff );
157 /* Increment the character counter */
162 /* Public functions for CircleOS ---------------------------------------------*/
164 /*******************************************************************************
168 *******************************************************************************/
171 * Initialize GUI drawing. Called at CircleOS startup.
173 * @attention This function must <b>NOT</b> be called by the user.
176 /******************************************************************************/
177 void DRAW_Init( void )
181 MEMS_GetRotation( &CurrentScreenOrientation );
183 LCD_SetScreenOrientation( CurrentScreenOrientation );
193 // Clear LCD and draw black and white logo
194 DRAW_SetDefaultColor();
195 LCD_FillRect( 0, 0, CHIP_SCREEN_WIDTH, CHIP_SCREEN_HEIGHT, BGndColor );
202 /* Public functions ----------------------------------------------------------*/
204 /*******************************************************************************
206 * DRAW_SetCharMagniCoeff
208 *******************************************************************************/
211 * Set the magnifying value for the characters (should be 1 or 2)
213 * @param[in] Coeff The new magnifying coefficent.
216 /******************************************************************************/
217 void DRAW_SetCharMagniCoeff( u16 Coeff )
219 CharMagniCoeff = Coeff;
222 /******************************************************************************
224 * DRAW_GetCharMagniCoeff
226 *******************************************************************************/
229 * Return the current magnifying value for the characters
231 * @return Current magnifying value.
234 /******************************************************************************/
235 u16 DRAW_GetCharMagniCoeff( void )
237 return CharMagniCoeff;
240 /******************************************************************************
244 *******************************************************************************/
247 * Return current text color.
249 * @return The current RGB color used to draw text.
252 /******************************************************************************/
253 u16 DRAW_GetTextColor( void )
258 /*******************************************************************************
262 *******************************************************************************/
265 * Set current text color.
267 * @param[in] Color The new RGB color used when drawing text.
270 /******************************************************************************/
271 void DRAW_SetTextColor( u16 Color )
276 /*******************************************************************************
280 *******************************************************************************/
283 * Return current background color.
285 * @return The current RGB color used for the background.
288 /******************************************************************************/
289 u16 DRAW_GetBGndColor( void )
294 /*******************************************************************************
298 *******************************************************************************/
301 * Set current background color
303 * @param[in] Color The new RGB color for background.
306 /******************************************************************************/
307 void DRAW_SetBGndColor(u16 Color)
313 /*******************************************************************************
317 *******************************************************************************/
320 * The provided bitmap is made width * height 2 byte words. Each 2 byte word contains
321 * the RGB color of a pixel.
323 * @brief Draw a color bitmap at the provided coordinates.
324 * @param[in] imageptr A pointer to an array of width * height 2 byte words.
325 * @param[in] x The horizontal coordinate of the low left corner of the bitmap.
326 * @param[in] y The vertical coordinate of the low left corner of the bitmap.
327 * @param[in] width The bitmap width.
328 * @param[in] height The bitmap height.
330 * @warning The (0x0) point in on the low left corner.
333 /******************************************************************************/
334 void DRAW_SetImage( const u16* imageptr, u8 x, u8 y, u8 width, u8 height )
338 // Select screen area to access.
339 LCD_SetRect_For_Cmd( x, y, width, height );
341 // Send command to write data on the LCD screen.
342 LCD_SendLCDCmd(ST7637_RAMWR);
344 for( i = 0; i < ( width * height ); i++ )
346 LCD_SendLCDData( imageptr[ i ] & 0xff );
347 LCD_SendLCDData( ( imageptr[ i ] >> 8 ) & 0xff );
353 /*******************************************************************************
357 *******************************************************************************/
360 * This function is used to display a 17 character max string of
361 * characters on the LCD display at the provided coordinates.
363 * @param[in] x The horizontal coordinate of the displayed string.
364 * @param[in] y The vertical coordinate of the display string.
365 * @param[in] *ptr Pointer to the string to display on LCD.
366 * @param[in] len String length.
368 * @warning The (0x0) point in on the low left corner.
371 /******************************************************************************/
372 void DRAW_DisplayString( u8 x, u8 y, const u8* ptr, u8 len )
374 DRAW_DisplayStringWithMode( x, y, ptr, len, 0 );
377 /*******************************************************************************
379 * DRAW_DisplayStringInverted
381 *******************************************************************************/
384 * This function is used to display a 17 character max string of
385 * characters on the LCD display at the provided coordinates with inverted colors.
387 * @param[in] x The horizontal coordinate of the displayed string.
388 * @param[in] y The vertical coordinate of the display string.
389 * @param[in] *ptr Pointer to the string to display on LCD.
390 * @param[in] len String length.
392 * @warning The (0x0) point in on the low left corner.
395 /******************************************************************************/
396 void DRAW_DisplayStringInverted( u8 x, u8 y, const u8* ptr, u8 len )
398 //BackGround and Text Colors are inverted
399 DRAW_DisplayStringWithMode( x, y, ptr, len, 1 );
402 /*******************************************************************************
404 * DRAW_SetDefaultColor
406 *******************************************************************************/
409 * Reset text and background colors to their default values.
412 /******************************************************************************/
413 void DRAW_SetDefaultColor (void)
415 BGndColor = RGB_WHITE;
416 TextColor = RGB_BLACK;
419 /*******************************************************************************
423 *******************************************************************************/
426 * This function is used to display the current temperature in ascii.
427 * The choice between Celcius and Fahrenheit is fixed by UTIL_SetModeTemp()
429 * @param[in] x The horizontal coordinate of the displayed string.
430 * @param[in] y The vertical coordinate of the display string.
432 * @warning The (0x0) point in on the low left corner.
435 /******************************************************************************/
436 void DRAW_DisplayTemp( u8 x, u8 y )
439 u8 TextBuffer[5] = { 0,0,0,0,0};
442 Temp = UTIL_GetTemp() ;
444 if( Temp != OldTemp )
446 // Display C (if modified).
447 UTIL_uint2str( TextBuffer, Temp/10, 2, 1 );
448 TextBuffer[ 2 ] = '.';
449 DRAW_DisplayString( x + ( 0 * CharMagniCoeff * 7 ), y, TextBuffer, 3 );
451 // Display C/10 (if modified).
452 UTIL_uint2str( TextBuffer, Temp%10, 1, 1 );
453 TextBuffer[ 1 ] = fTemperatureInFahrenheit ? 'F' : 'C'; TextBuffer[ 2 ] = 0;
454 DRAW_DisplayString( x + ( 3 * CharMagniCoeff * 7 ), y, TextBuffer, 2 );
459 /*******************************************************************************
463 *******************************************************************************/
465 * Draw a line on the LCD screen. Optimized for horizontal/vertical lines,
466 * and use the Bresenham algorithm for other cases.
468 * @param[in] x1 The x-coordinate of the first line endpoint.
469 * @param[in] x2 The x-coordinate of the second line endpoint.
470 * @param[in] y1 The y-coordinate of the first line endpoint.
471 * @param[in] y2 The y-coordinate of the second line endpoint.
472 * @param[in] color The line color.
475 void DRAW_Line (s16 x1, s16 y1, s16 x2, s16 y2, u16 color )
477 int i,dx,dy,sdx,sdy,dxabs,dyabs,x,y,px,py;
479 #define abs(X) ( ( (X) < 0 ) ? -(X) : (X) )
480 #define sgn(X) ( ( (X) < 0 ) ? -1 : 1 )
482 if ( x1==x2 ) //Vertical Line
484 if ( y1 > y2 ) //We assume y2>y1 and invert if not
490 LCD_FillRect( x1, y1, 1, y2-y1+1, color );
493 else if ( y1==y2 ) //Horizontal Line
495 if ( x1 > x2 ) //We assume x2>x1 and we swap them if not
501 LCD_FillRect( x1, y1, x2-x1+1, 1, color );
505 dx=x2-x1; /* the horizontal distance of the line */
506 dy=y2-y1; /* the vertical distance of the line */
516 if (dxabs>=dyabs) /* the line is more horizontal than vertical */
527 LCD_DrawPixel(px,py,color);
530 else /* the line is more vertical than horizontal */
541 LCD_DrawPixel(px,py,color);