1 /********************* (C) COPYRIGHT 2007 RAISONANCE S.A.S. *******************/
5 * @brief General header for the CircleOS project.
10 * It contains the list of the utilities functions organized by sections
11 * (MEMS, LCD, POINTER, ...)
14 * @version 1.5 types of OutX_F64 and OutX_F256 changed to u32 (same for Y and Z)
16 /******************************************************************************/
18 #include "scheduler.h"
20 /* Define to prevent recursive inclusion -------------------------------------*/
24 //-------------------------------- General -------------------------------------
25 /* Defines ------------------------------------------------------------------*/
26 #define VDD_VOLTAGE_MV 3300 //Voltage (mV) of the STM32
27 #define FA_TABLE 0x8006000
28 #define TIM2 ((TIM_TypeDef *) TIM2_BASE)
29 #define CIRCLEOS_RAM_BASE 0x20004000
31 /* Variables ----------------------------------------------------------------*/
32 extern GPIO_InitTypeDef GPIO_InitStructure;
34 /* Utilities -----------------------------------------------------------------*/
35 void UTIL_uint2str( char *ptr , u32 X, u16 digit, int fillwithzero );
36 void UTIL_int2str( char *ptr , s32 X, u16 digit, int fillwithzero );
37 u16 UTIL_ReadBackupRegister( u16 BKP_DR );
38 void UTIL_WriteBackupRegister( u16 BKP_DR, u16 Data );
39 u16 UTIL_GetBat( void );
40 u8 UTIL_GetUsb( void );
41 u16 UTIL_GetTemp ( void ) ;
42 void UTIL_SetTempMode ( int mode );
43 //typedef void (*tHandler) ( void );
44 void UTIL_SetIrqHandler ( int , tHandler );
45 tHandler UTIL_GetIrqHandler ( int );
46 extern u16 ADC_ConvertedValue[17];
64 POINTER_SCHHDL_ID = 4,
69 UNUSED0_SCHHDL_ID = 8,
70 UNUSED1_SCHHDL_ID = 9,
71 UNUSED2_SCHHDL_ID = 10,
72 UNUSED3_SCHHDL_ID = 11,
73 UNUSED4_SCHHDL_ID = 12,
74 UNUSED5_SCHHDL_ID = 13,
75 UNUSED6_SCHHDL_ID = 14,
76 UNUSED7_SCHHDL_ID = 15
77 } dummy_var ; //for doxygen
79 void UTIL_SetSchHandler ( enum eSchHandler , tHandler );
80 tHandler UTIL_GetSchHandler ( enum eSchHandler );
81 #define NULL_SCHHDL (0)
82 #define LAST_SCHHDL ((tHandler)(-1))
85 void UTIL_SetPll( enum eSpeed speed );
86 const char* UTIL_GetVersion( void );
87 enum eSpeed UTIL_GetPll( void );
88 extern RCC_ClocksTypeDef RCC_ClockFreq;
89 extern u8 fTemperatureInFahrenheit; /*!< 1 : Fahrenheit, 0 : Celcius (default). */
92 //--------------------------------- MEMS ------------------------------------
94 /* Exported types ------------------------------------------------------------*/
101 } Rotate_H12_V_Match_TypeDef;
126 extern tMEMS_Info MEMS_Info;
128 /* Exported functions --------------------------------------------------------*/
129 void MEMS_Init(void);
130 void MEMS_Handler(void);
131 void MEMS_GetPosition(s16 * pX, s16* pY);
132 void MEMS_SetNeutral( void );
133 void MEMS_GetRotation(Rotate_H12_V_Match_TypeDef * H12);
134 tMEMS_Info* MEMS_GetInfo (void);
135 u8 MEMS_ReadID(void);
137 //---------------------------------- LED -------------------------------------
139 /* Exported types ------------------------------------------------------------*/
140 enum LED_mode { LED_UNDEF = -1, LED_OFF = 0, LED_ON = 1, LED_BLINKING_LF = 2, LED_BLINKING_HF = 3 };
141 enum LED_id { LED_GREEN = 0, LED_RED = 1};
143 /* Exported functions --------------------------------------------------------*/
144 void LED_Init (void);
145 void LED_Handler_hw ( enum LED_id id );
146 void LED_Handler ( void );
147 void LED_Set ( enum LED_id id, enum LED_mode mode );
149 //-------------------------------- ADC --------------------------------------
151 /* Exported functions --------------------------------------------------------*/
152 void ADConverter_Init (void);
155 //==============================================================================
156 //-------------------------------- SHUTDOWN ---------------------------------
157 /* Exported functions --------------------------------------------------------*/
158 void SHUTDOWN_Action (void);
160 //-------------------------------- BUTTON -----------------------------------
161 /* Exported types ------------------------------------------------------------*/
162 enum BUTTON_mode { BUTTON_DISABLED = -1, BUTTON_ONOFF = 0,
163 BUTTON_ONOFF_FORMAIN = 1, BUTTON_WITHCLICK = 2 };
164 enum BUTTON_state { BUTTON_UNDEF = -1, BUTTON_RELEASED = 0, BUTTON_PUSHED = 1,
165 BUTTON_PUSHED_FORMAIN = 2 , BUTTON_CLICK = 3, BUTTON_DBLCLICK = 4 };
167 /* Exported functions -------------------------------------------------------*/
168 void BUTTON_Init (void);
169 void BUTTON_Handler(void);
170 enum BUTTON_state BUTTON_GetState();
171 void BUTTON_SetMode( enum BUTTON_mode mode);
172 enum BUTTON_mode BUTTON_GetMode ( void ) ;
173 void BUTTON_WaitForRelease();
175 //-------------------------------- POINTER ----------------------------------
177 /* Exported types ------------------------------------------------------------*/
178 enum POINTER_mode { POINTER_UNDEF = -1, POINTER_OFF = 0, POINTER_ON = 1, POINTER_MENU = 2, POINTER_APPLICATION = 3, POINTER_RESTORE_LESS = 4 };
179 enum POINTER_state { POINTER_S_UNDEF = -1, POINTER_S_DISABLED = 0, POINTER_S_ENABLED = 1 };
181 /* Exported defines ----------------------------------------------------------*/
182 #define POINTER_WIDTH 7
196 extern tPointer_Info POINTER_Info ;
198 /* Exported vars -------------------------------------------------------------*/
199 extern unsigned char *BallPointerBmpSize;
200 extern unsigned char BallPointerBmp [POINTER_WIDTH], *CurrentPointerBmp,*CurrentPointerSize;
201 extern u16 CurrentPointerColor;
202 extern u16 BallColor;
203 extern s16 POINTER_X_PosMin;
204 extern s16 POINTER_Y_PosMin;
205 extern s16 POINTER_X_PosMax;
206 extern s16 POINTER_Y_PosMax;
207 extern unsigned char PointerAreaStore [2*POINTER_WIDTH*POINTER_WIDTH];
209 /* Exported functions --------------------------------------------------------*/
210 extern void POINTER_Init ( void ) ;
211 void POINTER_Handler(void);
212 u16 POINTER_GetCurrentAngleStart ( void );
213 void POINTER_SetCurrentAngleStart ( u16 );
214 u16 POINTER_GetCurrentSpeedOnAngle ( void );
215 void POINTER_SetCurrentSpeedOnAngle ( u16 newspeed );
216 void POINTER_SetMode( enum POINTER_mode mode);
217 void POINTER_SetCurrentPointer( unsigned char width, unsigned char height, unsigned char *bmp);
218 enum POINTER_state POINTER_GetState(void);
219 void POINTER_Draw (u8 Line, u8 Column, u8 Width, u8 Height, u8 *Bmp);
220 void POINTER_SetRect ( s16 x, s16 y, s16 width, s16 height ); //Restrict the move of the pointer to a rectangle
221 void POINTER_SetRectScreen ( void ); //Remove any space restriction for the pointer moves.
222 void POINTER_Save (u8 Line, u8 Column, u8 Width, u8 Height);
223 void POINTER_Restore (u8 Line, u8 Column, u8 Width, u8 Height);
224 u16 POINTER_GetPos(void); //Return the poistion of the cursor (x=lower byte, y = upperbyte)
225 void POINTER_SetPos ( u16 x, u16 y );
226 typedef void (*tAppPtrMgr) ( int , int );
227 void POINTER_SetApplication_Pointer_Mgr( tAppPtrMgr mgr );
228 tPointer_Info* POINTER_GetInfo ( void );
229 u16 POINTER_GetColor ( void ) ;
230 void POINTER_SetColor ( u16 color );
231 enum POINTER_mode POINTER_GetMode( void );
232 void POINTER_SetCurrentAreaStore ( u8 *ptr );
233 void LCD_SetRotateScreen ( u8 RotateScreen);
234 u8 LCD_GetRotateScreen ();
235 void LCD_SetScreenOrientation (Rotate_H12_V_Match_TypeDef ScreenOrientation);
236 Rotate_H12_V_Match_TypeDef LCD_GetScreenOrientation ();
238 //---------------------------------- LCD -----------------------------------
240 /* Exported defines ----------------------------------------------------------*/
241 //RGB is 16-bit coded as G2G1G0B4 B3B2B1B0 R4R3R2R1 R0G5G4G3
242 #define RGB_MAKE(xR,xG,xB) ( ( (xG&0x07)<<13 ) + ( (xG)>>5 ) + \
243 ( ((xB)>>3) << 8 ) + \
245 #define RGB_RED 0x00F8
246 #define RGB_BLACK 0x0000
247 #define RGB_WHITE 0xffff
248 #define RGB_BLUE 0x1F00
249 #define RGB_GREEN 0xE007
250 #define RGB_YELLOW (RGB_GREEN|RGB_RED)
251 #define RGB_MAGENTA (RGB_BLUE|RGB_RED)
252 #define RGB_LIGHTBLUE (RGB_BLUE|RGB_GREEN)
253 #define RGB_ORANGE (RGB_RED | 0xE001) //green/2 + red
254 #define RGB_PINK (RGB_MAGENTA | 0xE001) //green/2 + magenta
257 #define SCREEN_WIDTH 128
258 #define SCREEN_HEIGHT 128
259 #define CHIP_SCREEN_WIDTH 132
260 #define CHIP_SCREEN_HEIGHT 132
264 #define CHAR_HEIGHT 14
267 #define BACKLIGHTMIN 0x1000 /*!< Minimal PWM rate. */
268 #define DEFAULT_CCR_BACKLIGHTSTART 0x8000 /*!< Default PWM rate. */
270 /* Exported vars -------------------------------------------------------------*/
271 extern Rotate_H12_V_Match_TypeDef Screen_Orientation;
272 extern int rotate_screen;
274 /* Exported functions --------------------------------------------------------*/
276 void LCD_Handler(void);
277 void LCD_SetRect_For_Cmd( s16 x, s16 y, s16 width, s16 height );
278 u16 LCD_GetPixel( u8 x, u8 y );
279 void LCD_DrawPixel( u8 x, u8 y, u16 Pixel );
280 void LCD_SendLCDCmd( u8 Cmd );
281 void LCD_SendLCDData( u8 Data );
282 u32 LCD_ReadLCDData( void );
283 void LCD_FillRect( u16 x, u16 y, u16 width, u16 height, u16 color );
284 void LCD_DrawRect( u16 x, u16 y, u16 width, u16 height, u16 color );
285 void LCD_DisplayChar( u8 x, u8 y, u8 Ascii, u16 TextColor, u16 BGndColor, u16 CharMagniCoeff );
286 void LCD_RectRead( u16 x, u16 y, u16 width, u16 height, u8* bmp );
287 void LCD_SetBackLight (u32 newBacklightStart);
288 u32 LCD_GetBackLight ( void );
289 void LCD_SetBackLightOff( void );
290 void LCD_SetBackLightOn( void );
294 //---------------------------------- DRAW ----------------------------------
296 /* Exported functions --------------------------------------------------------*/
297 void DRAW_Init(void);
298 void DRAW_Clear(void);
299 void DRAW_Handler(void);
300 void DRAW_SetDefaultColor (void);
301 void DRAW_SetImage(const u16 *imageptr, u8 x, u8 y, u8 width, u8 height);
302 void DRAW_SetImageBW(const u8 *imageptr, u8 x, u8 y, u8 width, u8 height);
303 void DRAW_SetLogoBW(void);
304 void DRAW_DisplayVbat(u8 x, u8 y);
305 void DRAW_DisplayTime(u8 x, u8 y);
306 void DRAW_DisplayTemp(u8 x, u8 y);
307 void DRAW_DisplayString( u8 x, u8 y, const u8 *ptr, u8 len );
308 void DRAW_DisplayStringInverted( u8 x, u8 y, const u8 *ptr, u8 len );
309 u16 DRAW_GetCharMagniCoeff(void);
310 void DRAW_SetCharMagniCoeff(u16 Coeff);
311 u16 DRAW_GetTextColor(void);
312 void DRAW_SetTextColor(u16 Color);
313 u16 DRAW_GetBGndColor(void);
314 void DRAW_SetBGndColor(u16 Color);
315 void DRAW_Batt( void );
316 void DRAW_Line (s16 x1, s16 y1, s16 x2, s16 y2, u16 color );
318 /* Exported vars -------------------------------------------------------------*/
319 extern int fDisplayTime;
322 //-------------------------------- BUZZER -----------------------------------
324 /* Exported defines ----------------------------------------------------------*/
325 #define BUZZER_BEEP BUZZER_SHORTBEEP
327 /* Exported type def ---------------------------------------------------------*/
328 enum BUZZER_mode { BUZZER_UNDEF = -1, BUZZER_OFF = 0, BUZZER_ON = 1,
329 BUZZER_SHORTBEEP = 2, BUZZER_LONGBEEP = 3, BUZZER_PLAYMUSIC = 4 };
331 /* Exported type functions ---------------------------------------------------*/
332 void BUZZER_Init(void);
333 void BUZZER_Handler(void);
334 void BUZZER_SetMode( enum BUZZER_mode mode);
335 enum BUZZER_mode BUZZER_GetMode( void );
336 void BUZZER_PlayMusic (const u8 *melody );
338 //--------------------------------- MENU -----------------------------------
340 /* Exported defines ----------------------------------------------------------*/
341 #define MENU_MAXITEM 6
342 #define APP_VOID ((tMenuItem *)(-1))
343 #define MAX_APP_MENU_SIZE 10
345 #define MAX_MENUAPP_SIZE 3
346 #define REMOVE_MENU 0x01
347 #define APP_MENU 0x02
349 enum MENU_code { MENU_LEAVE = 0, MENU_CONTINUE = 1, MENU_REFRESH = 2,
350 MENU_CHANGE = 3, MENU_CONTINUE_COMMAND = 4};
352 /* Exported type def ---------------------------------------------------------*/
356 enum MENU_code (*Fct_Init) ( void );
357 enum MENU_code (*Fct_Manage)( void );
363 unsigned fdispTitle : 1;
369 unsigned int SelectedItem;
370 tMenuItem Items[MENU_MAXITEM];
373 /* Exported vars -------------------------------------------------------------*/
374 extern tMenu MainMenu, *CurrentMenu;
375 extern tMenuItem *CurrentCommand;
376 extern int BGndColor_Menu;
377 extern int TextColor_Menu;
379 /* Exported type functions ---------------------------------------------------*/
380 enum MENU_code fColor ( void ) ;
381 void MENU_Set ( tMenu *mptr );
382 void MENU_Handler ( void ) ;
383 extern enum MENU_code MENU_Quit ( void );
384 void MENU_Remove ( void ) ;
385 void MENU_Question ( char *str, int *answer );
386 void MENU_Print ( char *str );
387 enum MENU_code MENU_SetLevel_Ini( void );
388 enum MENU_code MENU_SetLevel_Mgr( u32 *value, u32 value_range [] ) ;
389 void MENU_ClearCurrentCommand( void );
390 void MENU_SetLevelTitle(u8* title);
391 void MENU_SetTextColor ( int TextColor );
392 int MENU_GetTextColor ( void );
393 void MENU_SetBGndColor ( int BGndColor );
394 int MENU_GetBGndColor ( void );
395 extern enum MENU_code fQuit ( void ) ;
396 void MENU_ClearCurrentMenu(void);
398 //-------------------------------- BACKLIGHT --------------------------------
400 /* Exported type functions ---------------------------------------------------*/
401 void BackLight_Configuration (void);
402 void ManageBackLight (void);
403 void BackLight_Change (void);
405 //-------------------------------- RTC --------------------------------------
407 /* Exported type functions ---------------------------------------------------*/
409 void RTC_SetTime (u32 THH, u32 TMM, u32 TSS);
410 void RTC_GetTime (u32 * THH, u32 * TMM, u32 * TSS);
411 void RTC_DisplayTime ( void );
425 #define BKP_PLL (BKP_SYS2)
426 #define BKP_BKLIGHT (BKP_SYS3)
428 //--------------------------------- Application --------------------------------
429 void (*Application_Pointer_Mgr) ( int sposX, int sposY);
431 #endif /*__CIRCLE_H */