|
1. 实验平台使用百为的STM32F103开发板 2. 例程目录\百为stm32开发板光盘\stm32_gui_lib\Project\Embedded_GUI_Example\EWARM 3. 直接编译遇到一个问题 - Error[Pe147]: declaration is incompatible with "__nounwind __interwork __softfp unsigned int __iar_builtin_REV16(unsigned int)" 9 ?7 B+ I' p/ r9 f% K7 w
- (declared at line 197 of "D:\IAR Systems\ E:\MCU\STM32\百为stm32开发板光盘\stm32_gui_lib\Libraries\CMSIS\CM3\CoreSupport\core_cm3.h 1124
复制代码
) S K; z+ T' b* C2 @ Z4. 解决办法如下,勾选Use CMSIS - ^+ Z' ]" T& a/ L8 z! h- ^8 ^
+ ?: k8 ]- P6 @. O$ r( E6 D* N
5. 去掉 $PROJ_DIR$\..\..\..\Libraries\CMSIS\CM3\CoreSupport,编译通过。
) k- o) d6 t* T. l3 P% |2 e
" e- S( M4 i% @
6. 打开工程,分为GUI_HAL和底层有关的,GUI_Library是上层的鼠标,文字,图像等处理,其实看起来蛮简单的。 JoyHal.c是处理板子上面的一个方向按键,
# w% E) q& C% m, ^: H
2 ~$ [6 Q( ]6 x9 L# r) F
7. 看下主函数 - int main(void)" z; C, @* c; p4 ]7 x# L
- {
4 M% s$ m( N% `2 U - RCC_ClocksTypeDef RCC_Clocks;
Z, [9 @* o/ t" V3 }
7 {* f% K6 b2 Z& C' K0 a- /* Set the Vector Table base location at 0x08000000 */
0 f4 y! I* \& L7 Z* A - NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0000);
& L, j; ~8 O* x* s" P% z - NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);' x+ }8 p1 H; D! Q0 \# X9 m+ a
- ; s: L0 T* @; D' Z# y2 q( P% W' H4 r
- /* Setup SysTick Timer for 10 msec interrupts */1 }* `6 T5 N# K8 `
- RCC_GetClocksFreq(&RCC_Clocks);- W' k( R7 @# U7 A$ n2 h$ N
- if (SysTick_Config(RCC_Clocks.SYSCLK_Frequency / 100))
& r A7 D0 O+ e+ y - {
- j3 V M& ]0 u, T - /* Capture error */
: i8 z7 N7 z% x% g* H& O- y- L - while (1);8 r1 V3 y" q+ v' v* c! r
- }
. U9 r- v3 v6 I - /* configure Systick priority */
1 p; r9 t) E' t# |" R$ Z - NVIC_SetPriority(SysTick_IRQn, 0x0B);' U1 n$ }# T0 h1 K
- ' W2 G2 z- Q7 Z
- /* Set HW structure parameters */
& L+ k/ H1 V, W1 J( y4 F9 Z - HWConfig_SetHardwareParams();# ~" J" m, }3 I
( n+ q( [9 i' V" a/ Y6 v" ~" M" j* K- * d& f3 B. ~% G4 |4 }6 O
- /* If the LCD Panel has a resolution of 320x240 this command is not needed, it's set by default */& u6 {# c8 U- ^9 f
- /* Set_LCD_Resolution( 320, 240 ); */8 ~' j: l$ v, W
. w/ Y6 O" @- P- /* Initialize the LCD */
& q1 E; o) [9 n, ~# k- H - GL_LCD_Init();& J/ Q+ Z6 G. p1 H1 h
& G9 P- h, i( p# K0 A6 w- m& m- GL_Clear(GL_White);# D% ?5 V" D0 P3 Y
- 4 M! A/ @5 g; Q
- InputInterface_Init();
/ I4 t2 M8 v6 X
+ o" {7 { t# I- | ]6 U3 O- ShowLoadingLogo();; Q/ Z% m2 r1 B$ ?- E
- 3 P, V$ T4 R+ b. d$ L
- #if TOUCH_SCREEN_CAPABILITY
+ D, w: W$ q6 [2 X5 F - /* Check if Calibration has been done*/# j. [! C% d$ o, L
- TS_CheckCalibration();
; `2 x% P1 ?2 @: H4 R, K - #endif
6 E/ i, L1 Q, L e, F! f - , j* X, s- \: P
- /*Initialize cursor*/3 E, H7 ^8 M$ Y# e- H- W& ]- o* H
- GL_Clear(White);
) M. d% X' @( f+ E - CursorInit(GL_NULL);
5 z6 k L7 u" `' s( Y- @/ B - 6 o+ L9 m8 z' M
- /* Menu Initialisation*/
# X5 x( N& x9 p/ N4 q4 v6 n h - Show_HomeScreen();
9 I b2 k6 |( o' e0 @; v1 b - CursorShow(195, 80);
% W, A* j- K" x- s8 O( l1 A
1 n+ v! z, ]5 d) f' u) e- /* Infinite main loop ------------------------------------------------------*/* e- t% `3 Q$ J5 T; I4 Y
- while (1)
/ I( s. M) w! R# V - {
6 n/ W! x7 b) Q
* |5 t3 _7 W I- #if defined(USE_STM3210C_EVAL) || defined(USE_STM32100E_EVAL)) t5 m) X! r2 z& d4 c- Z
- /* Catching touch events */3 l* |' c* Y! B, T# {; {
- if ( TS_IsCalibrationDone() == SET )( f" H$ k. V8 A4 S
- #endif5 y+ s6 Y& x5 P* y
- {
+ x ^" ~# q/ t% T4 C- ~1 t# a - ProcessInputData();/ R/ J* k7 A4 E6 d9 H. _1 D
- }5 T0 G% c* J6 o# M% _0 P
- - T L. k% f1 z9 D
- /* Time out calculate for power saving mode */
0 D& P9 P+ G! ~" |+ r. O; A* I - TimeOutCalculate();5 R! f% J z: e( ^ L1 E
- 9 x1 E$ D4 k( Y2 O8 S4 x! y
- CatchInputEvents();
" [/ ?! [9 ]3 g3 G: \ - }8 i; ]0 {! C2 u8 j8 J
- }
复制代码
% a2 Z+ \& Z# q& r, j: E( ?8. 方向按键的原理图,程序对应的就是JoyHal.c,joystick翻译成中文就是操纵杆。 / _/ R) P; ~* \. \% h! w3 n
9 A" h, i9 ]* |$ R4 w/ J2 C! Y
9. 看下实际效果,主要用操纵杆移动鼠标,不知道为啥触摸屏没用。可能是板子跳线帽不对。看了一下cursor.c这个文件,里面只有读操纵杆的函数,估计触摸屏本来就没用。
- W4 I/ _5 d7 k8 S
1 o" D, T( ^# t# G
10. LCD接口是FSMC接口,FSMC本来是存储器的接口,也可以用来驱动LCD。 + u" d q7 V5 J9 U
! V! u3 p: C& N" I$ ~, |- B2 K8 t
11. LCD引脚配置 - void LCD_CtrlLinesConfig(void)
1 o7 b: |; G! e- T- n - {7 ?7 z% b: }0 w9 x) o
- GPIO_InitTypeDef GPIO_InitStructure;' W0 \% i" w: T. o$ P5 X' q& |
- /* Enable FSMC, GPIOD, GPIOE, GPIOF, GPIOG and AFIO clocks */
* Q3 C8 G7 H) Z( _' N! B/ K0 [ - RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);5 J; N2 H4 D; e. U/ @; w) ^5 S
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
( H) e) A p% O, h - RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG |; S r3 X& h$ C2 j; ?' g
- RCC_APB2Periph_AFIO, ENABLE);
" M6 r0 f. V$ _ - /* Set PD.00(D2), PD.01(D3), PD.04(NOE), PD.05(NWE), PD.08(D13), PD.09(D14),
+ b* W, ~& B4 l/ r - PD.10(D15), PD.14(D0), PD.15(D1) as alternate function push pull */
, f+ L8 a/ R5 W8 }: O& b% b9 K - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 |& s6 y/ E& {% F% L( F* P
- GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_14 |3 B0 f/ q9 F' b6 w) y
- GPIO_Pin_15;
d8 L0 j1 T, ^ L7 X1 r - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;6 n* ~8 s, s" G2 m
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
1 F0 T7 A6 x% P/ e) b - GPIO_Init(GPIOD, &GPIO_InitStructure);
& s+ H; y* ]9 O; s* J - /* Set PE.07(D4), PE.08(D5), PE.09(D6), PE.10(D7), PE.11(D8), PE.12(D9), PE.13(D10),
) _( q B. R& \" F! {$ V - PE.14(D11), PE.15(D12) as alternate function push pull */
1 `1 e# ]& U! L - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
# s* O* \' B& W. d - GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 |
0 M0 _6 Z5 m1 R# ], z* { - GPIO_Pin_15;
$ b% S; ~ r! I- ?9 `9 I/ D4 J - GPIO_Init(GPIOE, &GPIO_InitStructure);
' r) X5 q: g2 u* r# r% W - /* Set PF.00(A0 (RS)) as alternate function push pull */( m8 e" h& {! v4 D
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
/ v9 z5 i) y4 S0 {1 Y7 P# o/ { H - GPIO_Init(GPIOF, &GPIO_InitStructure);. ]3 J) Y( Q, l7 U6 F
- /* Set PG.12(NE4 (LCD/CS)) as alternate function push pull - CE3(LCD /CS) */1 L5 Z8 L6 X5 X( r
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
7 O! f% \6 Y) w - GPIO_Init(GPIOG, &GPIO_InitStructure);! V* e! x% J2 k" o
- }
复制代码
$ W4 [/ ^; I# z4 r3 V9 ?8 @12. FSMC配置 - void LCD_FSMCConfig(void)+ ?% i: E# n5 j2 ]
- {6 m" i! G/ m, P4 R" a) F* G
- FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
/ X5 n& H. k0 e - FSMC_NORSRAMTimingInitTypeDef p;8 k k$ }! N3 ^/ n; U
- /*-- FSMC Configuration ------------------------------------------------------*/
3 _. \% h6 H/ c; m - /*----------------------- SRAM Bank 4 ----------------------------------------*/
- ^/ d2 m Z5 _8 B' K' D$ L - /* FSMC_Bank1_NORSRAM4 configuration */' B( m* e" G+ |/ M) w7 V, T& G
- p.FSMC_AddressSetupTime = 1;
E7 F. w/ N$ `( i( \( o - p.FSMC_AddressHoldTime = 0;
8 s! _1 D& B! n# K" Q/ w - p.FSMC_DataSetupTime = 2;
2 {3 g D% }0 b# ^: _6 b$ w: i - p.FSMC_BusTurnAroundDuration = 0;
9 r5 Q0 \6 v: s: {9 d* \8 O - p.FSMC_CLKDivision = 0;. _" s0 Q6 s) {- `& W
- p.FSMC_DataLatency = 0;
* f+ O. Y0 K- _$ f4 [1 r+ t- {# @ - p.FSMC_AccessMode = FSMC_AccessMode_A;
& K( O% {$ G+ X, @; w! |" n+ u, { - /* Color LCD configuration ------------------------------------# S9 x7 \2 m4 q9 f3 B
- LCD configured as follow:
3 {/ r6 o" g5 o& y - - Data/Address MUX = Disable0 N9 R2 W) { B; r t. K; V
- - Memory Type = SRAM) t2 a9 A ]2 n$ X) `4 M
- - Data Width = 16bit& h% h% x3 G/ z, S; }# _; i
- - Write Operation = Enable( ^' D" h: a) K, k; z
- - Extended Mode = Enable
y0 D" ]: m) T' z' _) ~3 V" L - - Asynchronous Wait = Disable */
& E2 I1 s. [7 P" K, M' ? - FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM4;; x9 U7 M" J+ W& N
- FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
9 }1 Q& V& O/ N6 W) l ? - FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;0 {1 B! t2 k% t! Z- a2 f
- FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
, |+ x6 s% W; d7 i B ]! P - FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
3 ]' V4 B5 m- b/ J - FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
" e/ e% s6 Y p- C - FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
) j- o. m. R0 D - FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
. @# {; b1 G9 w7 }! z - FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;5 ~/ K. } a. }& r \4 |
- FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;* m' y# f8 J1 _" |' X( o
- FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
q& x* _, w* j/ } _, f0 r - FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
. l3 F* f' e) x/ ~2 C5 N) _* e - FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
. `4 l$ ~& L' B. [( `$ J% P9 ^ - FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;7 U7 l/ y' j/ S
- FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;: Z3 K& i( ]% t
- FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
8 P. r+ W" j& K$ {' W6 x# ~7 P - /* BANK 4 (of NOR/SRAM Bank 1~4) is enabled */6 N* O3 [6 V8 ~+ q: @% @
- FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE);4 d0 J" ?' W2 @/ c# J. ~$ d
- }
复制代码
/ E0 I0 a6 i3 I1 N- N13. 画按钮的函数 - void GL_DrawButtonBMP(uint16_t maxX, uint16_t minX, uint16_t maxY, uint16_t minY, uint8_t* ptrBitmap)
5 h) h" Z2 r" l [. K( V; N - {, [" q2 |5 H# f: U" M9 D$ ~1 Z. e
- GL_SetDisplayWindow(maxY, maxX, maxY - minY, maxX - minX);
( h' S1 N) |9 l, \. i" x - GL_DrawBMP(ptrBitmap);3 _* B- R: }1 \' |3 b. {
- GL_SetDisplayWindow(LCD_Height - 1, LCD_Width - 1, LCD_Height, LCD_Width);( j$ a1 c0 r5 d0 E5 x2 V2 H3 f9 B
- }
复制代码 4 u: o' d# z0 c+ u0 }
14. 总结起来,这个库其实功能简单,用起来也不复杂的。
0 n! j. c* _7 S; Y0 ?; p# ~* { |