HomiKetalys commited on
Commit
052e04a
·
1 Parent(s): 4cba0c9

update modelzoo

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. deployment/GD32F470I_BluePill_ARMCC/ARM/NVIC/NVIC.c +73 -0
  2. deployment/GD32F470I_BluePill_ARMCC/ARM/NVIC/NVIC.h +37 -0
  3. deployment/GD32F470I_BluePill_ARMCC/ARM/SysTick/SysTick.c +150 -0
  4. deployment/GD32F470I_BluePill_ARMCC/ARM/SysTick/SysTick.h +41 -0
  5. deployment/GD32F470I_BluePill_ARMCC/ARM/System/gd32f470x_conf.h +51 -0
  6. deployment/GD32F470I_BluePill_ARMCC/ARM/System/gd32f4xx.h +368 -0
  7. deployment/GD32F470I_BluePill_ARMCC/ARM/System/gd32f4xx_it.c +143 -0
  8. deployment/GD32F470I_BluePill_ARMCC/ARM/System/gd32f4xx_it.h +63 -0
  9. deployment/GD32F470I_BluePill_ARMCC/ARM/System/gd32f4xx_libopt.h +81 -0
  10. deployment/GD32F470I_BluePill_ARMCC/ARM/System/startup_gd32f450_470.s +470 -0
  11. deployment/GD32F470I_BluePill_ARMCC/ARM/System/system_gd32f4xx.c +1149 -0
  12. deployment/GD32F470I_BluePill_ARMCC/ARM/System/system_gd32f4xx.h +58 -0
  13. deployment/GD32F470I_BluePill_ARMCC/App/Beep/Beep.c +113 -0
  14. deployment/GD32F470I_BluePill_ARMCC/App/Beep/Beep.h +44 -0
  15. deployment/GD32F470I_BluePill_ARMCC/App/Camera/Camera.c +163 -0
  16. deployment/GD32F470I_BluePill_ARMCC/App/Camera/Camera.h +40 -0
  17. deployment/GD32F470I_BluePill_ARMCC/App/Camera/DCI.c +341 -0
  18. deployment/GD32F470I_BluePill_ARMCC/App/Camera/DCI.h +48 -0
  19. deployment/GD32F470I_BluePill_ARMCC/App/Camera/OV2640.c +611 -0
  20. deployment/GD32F470I_BluePill_ARMCC/App/Camera/OV2640.h +137 -0
  21. deployment/GD32F470I_BluePill_ARMCC/App/Camera/OV2640Cfg.h +463 -0
  22. deployment/GD32F470I_BluePill_ARMCC/App/Camera/SCCB.c +236 -0
  23. deployment/GD32F470I_BluePill_ARMCC/App/Camera/SCCB.h +40 -0
  24. deployment/GD32F470I_BluePill_ARMCC/App/DataType/DataType.h +67 -0
  25. deployment/GD32F470I_BluePill_ARMCC/App/DbgMCU/CheckLineFeed.c +144 -0
  26. deployment/GD32F470I_BluePill_ARMCC/App/DbgMCU/CheckLineFeed.h +41 -0
  27. deployment/GD32F470I_BluePill_ARMCC/App/DbgMCU/DbgMCU.c +387 -0
  28. deployment/GD32F470I_BluePill_ARMCC/App/DbgMCU/DbgMCU.h +40 -0
  29. deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/BookByteRead.c +256 -0
  30. deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/BookByteRead.h +40 -0
  31. deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/Canvas.c +361 -0
  32. deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/Canvas.h +38 -0
  33. deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUIBreathLED.c +134 -0
  34. deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUIBreathLED.h +39 -0
  35. deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUICAN.c +659 -0
  36. deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUICAN.h +39 -0
  37. deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUICamera.c +630 -0
  38. deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUICamera.h +39 -0
  39. deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUICanvas.c +192 -0
  40. deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUICanvas.h +39 -0
  41. deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUIClock.c +250 -0
  42. deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUIClock.h +39 -0
  43. deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUIEthernet.c +594 -0
  44. deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUIEthernet.h +39 -0
  45. deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUIFileSys.c +899 -0
  46. deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUIFileSys.h +39 -0
  47. deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUIHome.c +335 -0
  48. deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUIHome.h +39 -0
  49. deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUIKeyBoard.c +504 -0
  50. deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUIKeyBoard.h +40 -0
deployment/GD32F470I_BluePill_ARMCC/ARM/NVIC/NVIC.c ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�NVIC.c
3
+ * ժ Ҫ��NVICģ�飬����NVIC�жϷ�������
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�SZLY(COPYRIGHT 2018 - 2020 SZLY. All rights reserved.)
6
+ * ������ڣ�2020��01��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+
17
+ /*********************************************************************************************************
18
+ * ����ͷ�ļ�
19
+ *********************************************************************************************************/
20
+ #include "NVIC.h"
21
+ #include "gd32f470x_conf.h"
22
+
23
+ /*********************************************************************************************************
24
+ * �궨��
25
+ *********************************************************************************************************/
26
+
27
+ /*********************************************************************************************************
28
+ * ö�ٽṹ��
29
+ *********************************************************************************************************/
30
+
31
+ /*********************************************************************************************************
32
+ * �ڲ�����
33
+ *********************************************************************************************************/
34
+
35
+ /*********************************************************************************************************
36
+ * �ڲ���������
37
+ *********************************************************************************************************/
38
+ static void ConfigNVIC(void); //����NVIC
39
+
40
+ /*********************************************************************************************************
41
+ * �ڲ�����ʵ��
42
+ *********************************************************************************************************/
43
+
44
+ /*********************************************************************************************************
45
+ * �������ƣ�ConfigNVIC
46
+ * �������ܣ�����NVIC
47
+ * ���������void
48
+ * ���������void
49
+ * �� �� ֵ��void
50
+ * �������ڣ�2018��01��01��
51
+ * ע �⣺
52
+ *********************************************************************************************************/
53
+ static void ConfigNVIC(void)
54
+ {
55
+ nvic_priority_group_set(NVIC_PRIGROUP_PRE2_SUB2);
56
+ }
57
+
58
+ /*********************************************************************************************************
59
+ * API����ʵ��
60
+ *********************************************************************************************************/
61
+ /*********************************************************************************************************
62
+ * �������ƣ�InitNVIC
63
+ * �������ܣ���ʼ��NVICģ��
64
+ * ���������void
65
+ * ���������void
66
+ * �� �� ֵ��void
67
+ * �������ڣ�2018��01��01��
68
+ * ע �⣺
69
+ *********************************************************************************************************/
70
+ void InitNVIC(void)
71
+ {
72
+ ConfigNVIC(); //����NVIC
73
+ }
deployment/GD32F470I_BluePill_ARMCC/ARM/NVIC/NVIC.h ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�NVIC.h
3
+ * ժ Ҫ��NVICģ�飬����NVIC�жϷ�������
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�SZLY(COPYRIGHT 2018 - 2020 SZLY. All rights reserved.)
6
+ * ������ڣ�2020��01��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+ #ifndef _NVIC_H_
17
+ #define _NVIC_H_
18
+
19
+ /*********************************************************************************************************
20
+ * ����ͷ�ļ�
21
+ *********************************************************************************************************/
22
+ #include "DataType.h"
23
+
24
+ /*********************************************************************************************************
25
+ * �궨��
26
+ *********************************************************************************************************/
27
+
28
+ /*********************************************************************************************************
29
+ * ö�ٽṹ��
30
+ *********************************************************************************************************/
31
+
32
+ /*********************************************************************************************************
33
+ * API��������
34
+ *********************************************************************************************************/
35
+ void InitNVIC(void); //��ʼ��NVICģ��
36
+
37
+ #endif
deployment/GD32F470I_BluePill_ARMCC/ARM/SysTick/SysTick.c ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�SysTick.c
3
+ * ժ Ҫ��SysTickģ�飬����SysTickģ���ʼ���Լ�΢��ͺ��뼶��ʱ����
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�SZLY(COPYRIGHT 2018 - 2020 SZLY. All rights reserved.)
6
+ * ������ڣ�2020��01��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+
17
+ /*********************************************************************************************************
18
+ * ����ͷ�ļ�
19
+ *********************************************************************************************************/
20
+ #include "SysTick.h"
21
+ #include "gd32f470x_conf.h"
22
+
23
+ /*********************************************************************************************************
24
+ * �궨��
25
+ *********************************************************************************************************/
26
+
27
+ /*********************************************************************************************************
28
+ * ö�ٽṹ��
29
+ *********************************************************************************************************/
30
+
31
+ /*********************************************************************************************************
32
+ * �ڲ�����
33
+ *********************************************************************************************************/
34
+ static __IO u32 s_iTimDelayCnt = 0;
35
+
36
+ /*********************************************************************************************************
37
+ * �ڲ���������
38
+ *********************************************************************************************************/
39
+ static void TimDelayDec(void); //��ʱ����
40
+
41
+ /*********************************************************************************************************
42
+ * �ڲ�����ʵ��
43
+ *********************************************************************************************************/
44
+ /*********************************************************************************************************
45
+ * �������ƣ�TimDelayDec
46
+ * �������ܣ���ʱ����
47
+ * ���������void
48
+ * ���������void
49
+ * �� �� ֵ��void
50
+ * �������ڣ�2018��01��01��
51
+ * ע �⣺��SysTick�жϷ�����SysTick_Handler�е���
52
+ *********************************************************************************************************/
53
+ static void TimDelayDec(void)
54
+ {
55
+ if(s_iTimDelayCnt != 0) //��ʱ����������ֵ��Ϊ0
56
+ {
57
+ s_iTimDelayCnt--; //��ʱ����������ֵ��1
58
+ }
59
+ }
60
+
61
+ /*********************************************************************************************************
62
+ * �������ƣ�SysTick_Handler
63
+ * �������ܣ�SysTick�жϷ�����
64
+ * ���������void
65
+ * ���������void
66
+ * �� �� ֵ��void
67
+ * �������ڣ�2018��01��01��
68
+ * ע �⣺
69
+ *********************************************************************************************************/
70
+ void SysTick_Handler(void)
71
+ {
72
+ TimDelayDec(); //��ʱ��������
73
+ }
74
+
75
+ /*********************************************************************************************************
76
+ * API����ʵ��
77
+ *********************************************************************************************************/
78
+ /*********************************************************************************************************
79
+ * �������ƣ�InitSysTick
80
+ * �������ܣ���ʼ��SysTickģ��
81
+ * ���������void
82
+ * ���������void
83
+ * �� �� ֵ��void
84
+ * �������ڣ�2018��01��01��
85
+ * ע �⣺SystemCoreClock / 1000 1ms�ж�һ�Σ�����1000��Ϊ1s��ÿ��һ��λ1/1000s=1ms��
86
+ * SystemCoreClock / 4000 0.25ms�ж�һ�Σ�����4000��Ϊ1s��ÿ��һ��λ1/4000s=0.25ms��
87
+ * SystemCoreClock / 100000 10us�ж�һ�Σ�����100000��Ϊ1s��ÿ��һ��λ1/100000s=10us��
88
+ * SystemCoreClock / 1000000 1us�ж�һ�Σ�����1000000��Ϊ1s��ÿ��һ��λ1/1000000s=1us��
89
+ *********************************************************************************************************/
90
+ void InitSysTick( void )
91
+ {
92
+ if (SysTick_Config(SystemCoreClock / 1000U)) //����ϵͳ�δ�ʱ��1ms�ж�һ��
93
+ // if (SysTick_Config(240000000 / 1000U)) //����ϵͳ�δ�ʱ��1ms�ж�һ��
94
+ {
95
+ while(1) //������������£�������ѭ��
96
+ {
97
+
98
+ }
99
+ }
100
+ NVIC_SetPriority(SysTick_IRQn, 0x00U); //�������ȼ�
101
+ }
102
+
103
+ /*********************************************************************************************************
104
+ * �������ƣ�DelayNms
105
+ * �������ܣ����뼶��ʱ����
106
+ * ���������nms
107
+ * ���������void
108
+ * �� �� ֵ��void
109
+ * �������ڣ�2018��01��01��
110
+ * ע �⣺
111
+ *********************************************************************************************************/
112
+ void DelayNms(__IO u32 nms)
113
+ {
114
+ s_iTimDelayCnt = nms; //����ʱ������s_iTimDelayCnt����ֵ��Ϊnms
115
+ SysTick->VAL = SysTick->LOAD; //�����һ��ms��׼��bug
116
+
117
+ while(s_iTimDelayCnt != 0) //��ʱ����������ֵΪ0ʱ����ʾ��ʱ��nms������while���
118
+ {
119
+
120
+ }
121
+ // u32 i=2400;
122
+ // while(i--)
123
+ // {
124
+ // }
125
+ }
126
+
127
+ /*********************************************************************************************************
128
+ * �������ƣ�DelayNus
129
+ * �������ܣ�΢�뼶��ʱ����
130
+ * ���������nus
131
+ * ���������void
132
+ * �� �� ֵ��void
133
+ * �������ڣ�2018��01��01��
134
+ * ע �⣺
135
+ *********************************************************************************************************/
136
+ void DelayNus(__IO u32 nus)
137
+ {
138
+ u32 s_iTimCnt = nus; //����һ������s_iTimCnt��Ϊ��ʱ����������ֵΪnus
139
+ u16 i; //����һ��������Ϊѭ��������
140
+
141
+ while(s_iTimCnt != 0) //��ʱ������s_iTimCnt��ֵ��Ϊ0
142
+ {
143
+ for(i = 0; i < 38*2; i++) //��ѭ����������ʱ����
144
+ {
145
+
146
+ }
147
+
148
+ s_iTimCnt--; //�ɹ���ʱ1us������s_iTimCnt��1
149
+ }
150
+ }
deployment/GD32F470I_BluePill_ARMCC/ARM/SysTick/SysTick.h ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�SysTick.h
3
+ * ժ Ҫ��SysTickģ�飬����SysTickģ���ʼ���Լ�΢��ͺ��뼶��ʱ����
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�SZLY(COPYRIGHT 2018 - 2020 SZLY. All rights reserved.)
6
+ * ������ڣ�2020��01��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+ #ifndef _SYS_TICK_H_
17
+ #define _SYS_TICK_H_
18
+
19
+ /*********************************************************************************************************
20
+ * ����ͷ�ļ�
21
+ *********************************************************************************************************/
22
+ #include "DataType.h"
23
+ #include "gd32f4xx.h"
24
+ #include "gd32f470x_conf.h"
25
+
26
+ /*********************************************************************************************************
27
+ * �궨��
28
+ *********************************************************************************************************/
29
+
30
+ /*********************************************************************************************************
31
+ * ö�ٽṹ��
32
+ *********************************************************************************************************/
33
+
34
+ /*********************************************************************************************************
35
+ * API��������
36
+ *********************************************************************************************************/
37
+ void InitSysTick(void); //��ʼ��SysTickģ��
38
+ void DelayNus(__IO u32 nus); //΢�뼶��ʱ����
39
+ void DelayNms(__IO u32 nms); //���뼶��ʱ����
40
+
41
+ #endif
deployment/GD32F470I_BluePill_ARMCC/ARM/System/gd32f470x_conf.h ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * 模块名称:gd32f470x_conf.h
3
+ * 摘 要:gd32f4xx头文件包含
4
+ * 当前版本:1.0.0
5
+ * 作 者:SZLY(COPYRIGHT 2018 - 2020 SZLY. All rights reserved.)
6
+ * 完成日期:2020年01月01日
7
+ * 内 容:
8
+ * 注 意:
9
+ **********************************************************************************************************
10
+ * 取代版本:
11
+ * 作 者:
12
+ * 完成日期:
13
+ * 修改内容:
14
+ * 修改文件:
15
+ *********************************************************************************************************/
16
+ #ifndef _GD32F470_H_
17
+ #define _GD32F470_H_
18
+ /*********************************************************************************************************
19
+ * 包含头文件
20
+ *********************************************************************************************************/
21
+ #include "gd32f4xx_rcu.h"
22
+ #include "gd32f4xx_adc.h"
23
+ #include "gd32f4xx_can.h"
24
+ #include "gd32f4xx_crc.h"
25
+ #include "gd32f4xx_ctc.h"
26
+ #include "gd32f4xx_dac.h"
27
+ #include "gd32f4xx_dbg.h"
28
+ #include "gd32f4xx_dci.h"
29
+ #include "gd32f4xx_dma.h"
30
+ #include "gd32f4xx_exti.h"
31
+ #include "gd32f4xx_fmc.h"
32
+ #include "gd32f4xx_fwdgt.h"
33
+ #include "gd32f4xx_gpio.h"
34
+ #include "gd32f4xx_syscfg.h"
35
+ #include "gd32f4xx_i2c.h"
36
+ #include "gd32f4xx_iref.h"
37
+ #include "gd32f4xx_pmu.h"
38
+ #include "gd32f4xx_rtc.h"
39
+ #include "gd32f4xx_sdio.h"
40
+ #include "gd32f4xx_spi.h"
41
+ #include "gd32f4xx_timer.h"
42
+ #include "gd32f4xx_trng.h"
43
+ #include "gd32f4xx_usart.h"
44
+ #include "gd32f4xx_wwdgt.h"
45
+ #include "gd32f4xx_misc.h"
46
+ #include "gd32f4xx_enet.h"
47
+ #include "gd32f4xx_exmc.h"
48
+ #include "gd32f4xx_ipa.h"
49
+ #include "gd32f4xx_tli.h"
50
+
51
+ #endif
deployment/GD32F470I_BluePill_ARMCC/ARM/System/gd32f4xx.h ADDED
@@ -0,0 +1,368 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ \file gd32f4xx.h
3
+ \brief general definitions for GD32F4xx
4
+
5
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
6
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
7
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
8
+ */
9
+
10
+ /*
11
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
12
+
13
+ Redistribution and use in source and binary forms, with or without modification,
14
+ are permitted provided that the following conditions are met:
15
+
16
+ 1. Redistributions of source code must retain the above copyright notice, this
17
+ list of conditions and the following disclaimer.
18
+ 2. Redistributions in binary form must reproduce the above copyright notice,
19
+ this list of conditions and the following disclaimer in the documentation
20
+ and/or other materials provided with the distribution.
21
+ 3. Neither the name of the copyright holder nor the names of its contributors
22
+ may be used to endorse or promote products derived from this software without
23
+ specific prior written permission.
24
+
25
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
34
+ OF SUCH DAMAGE.
35
+ */
36
+
37
+ #ifndef GD32F4XX_H
38
+ #define GD32F4XX_H
39
+
40
+ #ifdef __cplusplus
41
+ extern "C" {
42
+ #endif
43
+
44
+ /* define GD32F4xx */
45
+ #if !defined (GD32F450) && !defined (GD32F405) && !defined (GD32F407) && !defined (GD32F470) && !defined (GD32F425) && !defined (GD32F427)
46
+ /* #define GD32F450 */
47
+ /* #define GD32F405 */
48
+ /* #define GD32F407 */
49
+ /* #define GD32F470 */
50
+ /* #define GD32F425 */
51
+ /* #define GD32F427 */
52
+ #endif /* define GD32F4xx */
53
+
54
+ #if !defined (GD32F450) && !defined (GD32F405) && !defined (GD32F407) && !defined (GD32F470) && !defined (GD32F425) && !defined (GD32F427)
55
+ #error "Please select the target GD32F4xx device in gd32f4xx.h file"
56
+ #endif /* undefine GD32F4xx tip */
57
+
58
+ /* define value of high speed crystal oscillator (HXTAL) in Hz */
59
+ #if !defined (HXTAL_VALUE)
60
+ #define HXTAL_VALUE ((uint32_t)25000000)
61
+ #endif /* high speed crystal oscillator value */
62
+
63
+ /* define startup timeout value of high speed crystal oscillator (HXTAL) */
64
+ #if !defined (HXTAL_STARTUP_TIMEOUT)
65
+ #define HXTAL_STARTUP_TIMEOUT ((uint16_t)0xFFFF)
66
+ #endif /* high speed crystal oscillator startup timeout */
67
+
68
+ /* define value of internal 16MHz RC oscillator (IRC16M) in Hz */
69
+ #if !defined (IRC16M_VALUE)
70
+ #define IRC16M_VALUE ((uint32_t)16000000)
71
+ #endif /* internal 16MHz RC oscillator value */
72
+
73
+ /* define startup timeout value of internal 16MHz RC oscillator (IRC16M) */
74
+ #if !defined (IRC16M_STARTUP_TIMEOUT)
75
+ #define IRC16M_STARTUP_TIMEOUT ((uint16_t)0x0500)
76
+ #endif /* internal 16MHz RC oscillator startup timeout */
77
+
78
+ /* define value of internal 32KHz RC oscillator(IRC32K) in Hz */
79
+ #if !defined (IRC32K_VALUE)
80
+ #define IRC32K_VALUE ((uint32_t)32000)
81
+ #endif /* internal 32KHz RC oscillator value */
82
+
83
+ /* define value of low speed crystal oscillator (LXTAL)in Hz */
84
+ #if !defined (LXTAL_VALUE)
85
+ #define LXTAL_VALUE ((uint32_t)32768)
86
+ #endif /* low speed crystal oscillator value */
87
+
88
+ /* I2S external clock in selection */
89
+ //#define I2S_EXTERNAL_CLOCK_IN (uint32_t)12288000U
90
+
91
+ /* GD32F4xx firmware library version number V1.0 */
92
+ #define __GD32F4xx_STDPERIPH_VERSION_MAIN (0x03) /*!< [31:24] main version */
93
+ #define __GD32F4xx_STDPERIPH_VERSION_SUB1 (0x00) /*!< [23:16] sub1 version */
94
+ #define __GD32F4xx_STDPERIPH_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */
95
+ #define __GD32F4xx_STDPERIPH_VERSION_RC (0x00) /*!< [7:0] release candidate */
96
+ #define __GD32F4xx_STDPERIPH_VERSION ((__GD32F4xx_STDPERIPH_VERSION_MAIN << 24)\
97
+ |(__GD32F4xx_STDPERIPH_VERSION_SUB1 << 16)\
98
+ |(__GD32F4xx_STDPERIPH_VERSION_SUB2 << 8)\
99
+ |(__GD32F4xx_STDPERIPH_VERSION_RC))
100
+
101
+ /* configuration of the cortex-M4 processor and core peripherals */
102
+ #define __CM4_REV 0x0001 /*!< core revision r0p1 */
103
+ #define __MPU_PRESENT 1 /*!< GD32F4xx provide MPU */
104
+ #define __NVIC_PRIO_BITS 4 /*!< GD32F4xx uses 4 bits for the priority levels */
105
+ #define __Vendor_SysTickConfig 0 /*!< set to 1 if different sysTick config is used */
106
+ #define __FPU_PRESENT 1 /*!< FPU present */
107
+ /* define interrupt number */
108
+ typedef enum IRQn
109
+ {
110
+ /* cortex-M4 processor exceptions numbers */
111
+ NonMaskableInt_IRQn = -14, /*!< 2 non maskable interrupt */
112
+ MemoryManagement_IRQn = -12, /*!< 4 cortex-M4 memory management interrupt */
113
+ BusFault_IRQn = -11, /*!< 5 cortex-M4 bus fault interrupt */
114
+ UsageFault_IRQn = -10, /*!< 6 cortex-M4 usage fault interrupt */
115
+ SVCall_IRQn = -5, /*!< 11 cortex-M4 SV call interrupt */
116
+ DebugMonitor_IRQn = -4, /*!< 12 cortex-M4 debug monitor interrupt */
117
+ PendSV_IRQn = -2, /*!< 14 cortex-M4 pend SV interrupt */
118
+ SysTick_IRQn = -1, /*!< 15 cortex-M4 system tick interrupt */
119
+ /* interruput numbers */
120
+ WWDGT_IRQn = 0, /*!< window watchdog timer interrupt */
121
+ LVD_IRQn = 1, /*!< LVD through EXTI line detect interrupt */
122
+ TAMPER_STAMP_IRQn = 2, /*!< tamper and timestamp through EXTI line detect */
123
+ RTC_WKUP_IRQn = 3, /*!< RTC wakeup through EXTI line interrupt */
124
+ FMC_IRQn = 4, /*!< FMC interrupt */
125
+ RCU_CTC_IRQn = 5, /*!< RCU and CTC interrupt */
126
+ EXTI0_IRQn = 6, /*!< EXTI line 0 interrupts */
127
+ EXTI1_IRQn = 7, /*!< EXTI line 1 interrupts */
128
+ EXTI2_IRQn = 8, /*!< EXTI line 2 interrupts */
129
+ EXTI3_IRQn = 9, /*!< EXTI line 3 interrupts */
130
+ EXTI4_IRQn = 10, /*!< EXTI line 4 interrupts */
131
+ DMA0_Channel0_IRQn = 11, /*!< DMA0 channel0 Interrupt */
132
+ DMA0_Channel1_IRQn = 12, /*!< DMA0 channel1 Interrupt */
133
+ DMA0_Channel2_IRQn = 13, /*!< DMA0 channel2 interrupt */
134
+ DMA0_Channel3_IRQn = 14, /*!< DMA0 channel3 interrupt */
135
+ DMA0_Channel4_IRQn = 15, /*!< DMA0 channel4 interrupt */
136
+ DMA0_Channel5_IRQn = 16, /*!< DMA0 channel5 interrupt */
137
+ DMA0_Channel6_IRQn = 17, /*!< DMA0 channel6 interrupt */
138
+ ADC_IRQn = 18, /*!< ADC interrupt */
139
+ CAN0_TX_IRQn = 19, /*!< CAN0 TX interrupt */
140
+ CAN0_RX0_IRQn = 20, /*!< CAN0 RX0 interrupt */
141
+ CAN0_RX1_IRQn = 21, /*!< CAN0 RX1 interrupt */
142
+ CAN0_EWMC_IRQn = 22, /*!< CAN0 EWMC interrupt */
143
+ EXTI5_9_IRQn = 23, /*!< EXTI[9:5] interrupts */
144
+ TIMER0_BRK_TIMER8_IRQn = 24, /*!< TIMER0 break and TIMER8 interrupts */
145
+ TIMER0_UP_TIMER9_IRQn = 25, /*!< TIMER0 update and TIMER9 interrupts */
146
+ TIMER0_TRG_CMT_TIMER10_IRQn = 26, /*!< TIMER0 trigger and commutation and TIMER10 interrupts */
147
+ TIMER0_Channel_IRQn = 27, /*!< TIMER0 channel capture compare interrupt */
148
+ TIMER1_IRQn = 28, /*!< TIMER1 interrupt */
149
+ TIMER2_IRQn = 29, /*!< TIMER2 interrupt */
150
+ TIMER3_IRQn = 30, /*!< TIMER3 interrupts */
151
+ I2C0_EV_IRQn = 31, /*!< I2C0 event interrupt */
152
+ I2C0_ER_IRQn = 32, /*!< I2C0 error interrupt */
153
+ I2C1_EV_IRQn = 33, /*!< I2C1 event interrupt */
154
+ I2C1_ER_IRQn = 34, /*!< I2C1 error interrupt */
155
+ SPI0_IRQn = 35, /*!< SPI0 interrupt */
156
+ SPI1_IRQn = 36, /*!< SPI1 interrupt */
157
+ USART0_IRQn = 37, /*!< USART0 interrupt */
158
+ USART1_IRQn = 38, /*!< USART1 interrupt */
159
+ USART2_IRQn = 39, /*!< USART2 interrupt */
160
+ EXTI10_15_IRQn = 40, /*!< EXTI[15:10] interrupts */
161
+ RTC_Alarm_IRQn = 41, /*!< RTC alarm interrupt */
162
+ USBFS_WKUP_IRQn = 42, /*!< USBFS wakeup interrupt */
163
+ TIMER7_BRK_TIMER11_IRQn = 43, /*!< TIMER7 break and TIMER11 interrupts */
164
+ TIMER7_UP_TIMER12_IRQn = 44, /*!< TIMER7 update and TIMER12 interrupts */
165
+ TIMER7_TRG_CMT_TIMER13_IRQn = 45, /*!< TIMER7 trigger and commutation and TIMER13 interrupts */
166
+ TIMER7_Channel_IRQn = 46, /*!< TIMER7 channel capture compare interrupt */
167
+ DMA0_Channel7_IRQn = 47, /*!< DMA0 channel7 interrupt */
168
+
169
+ #if defined (GD32F450) || defined (GD32F470)
170
+ EXMC_IRQn = 48, /*!< EXMC interrupt */
171
+ SDIO_IRQn = 49, /*!< SDIO interrupt */
172
+ TIMER4_IRQn = 50, /*!< TIMER4 interrupt */
173
+ SPI2_IRQn = 51, /*!< SPI2 interrupt */
174
+ UART3_IRQn = 52, /*!< UART3 interrupt */
175
+ UART4_IRQn = 53, /*!< UART4 interrupt */
176
+ TIMER5_DAC_IRQn = 54, /*!< TIMER5 and DAC0 DAC1 underrun error interrupts */
177
+ TIMER6_IRQn = 55, /*!< TIMER6 interrupt */
178
+ DMA1_Channel0_IRQn = 56, /*!< DMA1 channel0 interrupt */
179
+ DMA1_Channel1_IRQn = 57, /*!< DMA1 channel1 interrupt */
180
+ DMA1_Channel2_IRQn = 58, /*!< DMA1 channel2 interrupt */
181
+ DMA1_Channel3_IRQn = 59, /*!< DMA1 channel3 interrupt */
182
+ DMA1_Channel4_IRQn = 60, /*!< DMA1 channel4 interrupt */
183
+ ENET_IRQn = 61, /*!< ENET interrupt */
184
+ ENET_WKUP_IRQn = 62, /*!< ENET wakeup through EXTI line interrupt */
185
+ CAN1_TX_IRQn = 63, /*!< CAN1 TX interrupt */
186
+ CAN1_RX0_IRQn = 64, /*!< CAN1 RX0 interrupt */
187
+ CAN1_RX1_IRQn = 65, /*!< CAN1 RX1 interrupt */
188
+ CAN1_EWMC_IRQn = 66, /*!< CAN1 EWMC interrupt */
189
+ USBFS_IRQn = 67, /*!< USBFS interrupt */
190
+ DMA1_Channel5_IRQn = 68, /*!< DMA1 channel5 interrupt */
191
+ DMA1_Channel6_IRQn = 69, /*!< DMA1 channel6 interrupt */
192
+ DMA1_Channel7_IRQn = 70, /*!< DMA1 channel7 interrupt */
193
+ USART5_IRQn = 71, /*!< USART5 interrupt */
194
+ I2C2_EV_IRQn = 72, /*!< I2C2 event interrupt */
195
+ I2C2_ER_IRQn = 73, /*!< I2C2 error interrupt */
196
+ USBHS_EP1_Out_IRQn = 74, /*!< USBHS endpoint 1 out interrupt */
197
+ USBHS_EP1_In_IRQn = 75, /*!< USBHS endpoint 1 in interrupt */
198
+ USBHS_WKUP_IRQn = 76, /*!< USBHS wakeup through EXTI line interrupt */
199
+ USBHS_IRQn = 77, /*!< USBHS interrupt */
200
+ DCI_IRQn = 78, /*!< DCI interrupt */
201
+ TRNG_IRQn = 80, /*!< TRNG interrupt */
202
+ FPU_IRQn = 81, /*!< FPU interrupt */
203
+ UART6_IRQn = 82, /*!< UART6 interrupt */
204
+ UART7_IRQn = 83, /*!< UART7 interrupt */
205
+ SPI3_IRQn = 84, /*!< SPI3 interrupt */
206
+ SPI4_IRQn = 85, /*!< SPI4 interrupt */
207
+ SPI5_IRQn = 86, /*!< SPI5 interrupt */
208
+ TLI_IRQn = 88, /*!< TLI interrupt */
209
+ TLI_ER_IRQn = 89, /*!< TLI error interrupt */
210
+ IPA_IRQn = 90, /*!< IPA interrupt */
211
+ #endif /* GD32F450 and GD32F470 */
212
+
213
+ #if defined (GD32F405) || defined (GD32F425)
214
+ SDIO_IRQn = 49, /*!< SDIO interrupt */
215
+ TIMER4_IRQn = 50, /*!< TIMER4 interrupt */
216
+ SPI2_IRQn = 51, /*!< SPI2 interrupt */
217
+ UART3_IRQn = 52, /*!< UART3 interrupt */
218
+ UART4_IRQn = 53, /*!< UART4 interrupt */
219
+ TIMER5_DAC_IRQn = 54, /*!< TIMER5 and DAC0 DAC1 underrun error interrupts */
220
+ TIMER6_IRQn = 55, /*!< TIMER6 interrupt */
221
+ DMA1_Channel0_IRQn = 56, /*!< DMA1 channel0 interrupt */
222
+ DMA1_Channel1_IRQn = 57, /*!< DMA1 channel1 interrupt */
223
+ DMA1_Channel2_IRQn = 58, /*!< DMA1 channel2 interrupt */
224
+ DMA1_Channel3_IRQn = 59, /*!< DMA1 channel3 interrupt */
225
+ DMA1_Channel4_IRQn = 60, /*!< DMA1 channel4 interrupt */
226
+ CAN1_TX_IRQn = 63, /*!< CAN1 TX interrupt */
227
+ CAN1_RX0_IRQn = 64, /*!< CAN1 RX0 interrupt */
228
+ CAN1_RX1_IRQn = 65, /*!< CAN1 RX1 interrupt */
229
+ CAN1_EWMC_IRQn = 66, /*!< CAN1 EWMC interrupt */
230
+ USBFS_IRQn = 67, /*!< USBFS interrupt */
231
+ DMA1_Channel5_IRQn = 68, /*!< DMA1 channel5 interrupt */
232
+ DMA1_Channel6_IRQn = 69, /*!< DMA1 channel6 interrupt */
233
+ DMA1_Channel7_IRQn = 70, /*!< DMA1 channel7 interrupt */
234
+ USART5_IRQn = 71, /*!< USART5 interrupt */
235
+ I2C2_EV_IRQn = 72, /*!< I2C2 event interrupt */
236
+ I2C2_ER_IRQn = 73, /*!< I2C2 error interrupt */
237
+ USBHS_EP1_Out_IRQn = 74, /*!< USBHS endpoint 1 Out interrupt */
238
+ USBHS_EP1_In_IRQn = 75, /*!< USBHS endpoint 1 in interrupt */
239
+ USBHS_WKUP_IRQn = 76, /*!< USBHS wakeup through EXTI line interrupt */
240
+ USBHS_IRQn = 77, /*!< USBHS interrupt */
241
+ DCI_IRQn = 78, /*!< DCI interrupt */
242
+ TRNG_IRQn = 80, /*!< TRNG interrupt */
243
+ FPU_IRQn = 81, /*!< FPU interrupt */
244
+ #endif /* GD32F405 and GD32F425 */
245
+
246
+ #if defined (GD32F407) || defined (GD32F427)
247
+ EXMC_IRQn = 48, /*!< EXMC interrupt */
248
+ SDIO_IRQn = 49, /*!< SDIO interrupt */
249
+ TIMER4_IRQn = 50, /*!< TIMER4 interrupt */
250
+ SPI2_IRQn = 51, /*!< SPI2 interrupt */
251
+ UART3_IRQn = 52, /*!< UART3 interrupt */
252
+ UART4_IRQn = 53, /*!< UART4 interrupt */
253
+ TIMER5_DAC_IRQn = 54, /*!< TIMER5 and DAC0 DAC1 underrun error interrupts */
254
+ TIMER6_IRQn = 55, /*!< TIMER6 interrupt */
255
+ DMA1_Channel0_IRQn = 56, /*!< DMA1 channel0 interrupt */
256
+ DMA1_Channel1_IRQn = 57, /*!< DMA1 channel1 interrupt */
257
+ DMA1_Channel2_IRQn = 58, /*!< DMA1 channel2 interrupt */
258
+ DMA1_Channel3_IRQn = 59, /*!< DMA1 channel3 interrupt */
259
+ DMA1_Channel4_IRQn = 60, /*!< DMA1 channel4 interrupt */
260
+ ENET_IRQn = 61, /*!< ENET interrupt */
261
+ ENET_WKUP_IRQn = 62, /*!< ENET wakeup through EXTI line interrupt */
262
+ CAN1_TX_IRQn = 63, /*!< CAN1 TX interrupt */
263
+ CAN1_RX0_IRQn = 64, /*!< CAN1 RX0 interrupt */
264
+ CAN1_RX1_IRQn = 65, /*!< CAN1 RX1 interrupt */
265
+ CAN1_EWMC_IRQn = 66, /*!< CAN1 EWMC interrupt */
266
+ USBFS_IRQn = 67, /*!< USBFS interrupt */
267
+ DMA1_Channel5_IRQn = 68, /*!< DMA1 channel5 interrupt */
268
+ DMA1_Channel6_IRQn = 69, /*!< DMA1 channel6 interrupt */
269
+ DMA1_Channel7_IRQn = 70, /*!< DMA1 channel7 interrupt */
270
+ USART5_IRQn = 71, /*!< USART5 interrupt */
271
+ I2C2_EV_IRQn = 72, /*!< I2C2 event interrupt */
272
+ I2C2_ER_IRQn = 73, /*!< I2C2 error interrupt */
273
+ USBHS_EP1_Out_IRQn = 74, /*!< USBHS endpoint 1 out interrupt */
274
+ USBHS_EP1_In_IRQn = 75, /*!< USBHS endpoint 1 in interrupt */
275
+ USBHS_WKUP_IRQn = 76, /*!< USBHS wakeup through EXTI line interrupt */
276
+ USBHS_IRQn = 77, /*!< USBHS interrupt */
277
+ DCI_IRQn = 78, /*!< DCI interrupt */
278
+ TRNG_IRQn = 80, /*!< TRNG interrupt */
279
+ FPU_IRQn = 81, /*!< FPU interrupt */
280
+ #endif /* GD32F407 and GD32F427 */
281
+
282
+ } IRQn_Type;
283
+
284
+ /* includes */
285
+ #include "core_cm4.h"
286
+ #include "system_gd32f4xx.h"
287
+ #include <stdint.h>
288
+
289
+ /* enum definitions */
290
+ typedef enum {DISABLE = 0, ENABLE = !DISABLE} EventStatus, ControlStatus;
291
+ typedef enum {RESET = 0, SET = !RESET} FlagStatus;
292
+ typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrStatus;
293
+
294
+ /* bit operations */
295
+ #define REG32(addr) (*(volatile uint32_t *)(uint32_t)(addr))
296
+ #define REG16(addr) (*(volatile uint16_t *)(uint32_t)(addr))
297
+ #define REG8(addr) (*(volatile uint8_t *)(uint32_t)(addr))
298
+ #define BIT(x) ((uint32_t)((uint32_t)0x01U<<(x)))
299
+ #define BITS(start, end) ((0xFFFFFFFFUL << (start)) & (0xFFFFFFFFUL >> (31U - (uint32_t)(end))))
300
+ #define GET_BITS(regval, start, end) (((regval) & BITS((start),(end))) >> (start))
301
+
302
+ /* main flash and SRAM memory map */
303
+ #define FLASH_BASE ((uint32_t)0x08000000U) /*!< main FLASH base address */
304
+ #define TCMSRAM_BASE ((uint32_t)0x10000000U) /*!< TCMSRAM(64KB) base address */
305
+ #define OPTION_BASE ((uint32_t)0x1FFEC000U) /*!< Option bytes base address */
306
+ #define SRAM_BASE ((uint32_t)0x20000000U) /*!< SRAM0 base address */
307
+
308
+ /* peripheral memory map */
309
+ #define APB1_BUS_BASE ((uint32_t)0x40000000U) /*!< apb1 base address */
310
+ #define APB2_BUS_BASE ((uint32_t)0x40010000U) /*!< apb2 base address */
311
+ #define AHB1_BUS_BASE ((uint32_t)0x40020000U) /*!< ahb1 base address */
312
+ #define AHB2_BUS_BASE ((uint32_t)0x50000000U) /*!< ahb2 base address */
313
+
314
+ /* EXMC memory map */
315
+ #define EXMC_BASE ((uint32_t)0xA0000000U) /*!< EXMC register base address */
316
+
317
+ /* advanced peripheral bus 1 memory map */
318
+ #define TIMER_BASE (APB1_BUS_BASE + 0x00000000U) /*!< TIMER base address */
319
+ #define RTC_BASE (APB1_BUS_BASE + 0x00002800U) /*!< RTC base address */
320
+ #define WWDGT_BASE (APB1_BUS_BASE + 0x00002C00U) /*!< WWDGT base address */
321
+ #define FWDGT_BASE (APB1_BUS_BASE + 0x00003000U) /*!< FWDGT base address */
322
+ #define I2S_ADD_BASE (APB1_BUS_BASE + 0x00003400U) /*!< I2S1_add base address */
323
+ #define SPI_BASE (APB1_BUS_BASE + 0x00003800U) /*!< SPI base address */
324
+ #define USART_BASE (APB1_BUS_BASE + 0x00004400U) /*!< USART base address */
325
+ #define I2C_BASE (APB1_BUS_BASE + 0x00005400U) /*!< I2C base address */
326
+ #define CAN_BASE (APB1_BUS_BASE + 0x00006400U) /*!< CAN base address */
327
+ #define CTC_BASE (APB1_BUS_BASE + 0x00006C00U) /*!< CTC base address */
328
+ #define PMU_BASE (APB1_BUS_BASE + 0x00007000U) /*!< PMU base address */
329
+ #define DAC_BASE (APB1_BUS_BASE + 0x00007400U) /*!< DAC base address */
330
+ #define IREF_BASE (APB1_BUS_BASE + 0x0000C400U) /*!< IREF base address */
331
+
332
+ /* advanced peripheral bus 2 memory map */
333
+ #define TLI_BASE (APB2_BUS_BASE + 0x00006800U) /*!< TLI base address */
334
+ #define SYSCFG_BASE (APB2_BUS_BASE + 0x00003800U) /*!< SYSCFG base address */
335
+ #define EXTI_BASE (APB2_BUS_BASE + 0x00003C00U) /*!< EXTI base address */
336
+ #define SDIO_BASE (APB2_BUS_BASE + 0x00002C00U) /*!< SDIO base address */
337
+ #define ADC_BASE (APB2_BUS_BASE + 0x00002000U) /*!< ADC base address */
338
+ /* advanced high performance bus 1 memory map */
339
+ #define GPIO_BASE (AHB1_BUS_BASE + 0x00000000U) /*!< GPIO base address */
340
+ #define CRC_BASE (AHB1_BUS_BASE + 0x00003000U) /*!< CRC base address */
341
+ #define RCU_BASE (AHB1_BUS_BASE + 0x00003800U) /*!< RCU base address */
342
+ #define FMC_BASE (AHB1_BUS_BASE + 0x00003C00U) /*!< FMC base address */
343
+ #define BKPSRAM_BASE (AHB1_BUS_BASE + 0x00004000U) /*!< BKPSRAM base address */
344
+ #define DMA_BASE (AHB1_BUS_BASE + 0x00006000U) /*!< DMA base address */
345
+ #define ENET_BASE (AHB1_BUS_BASE + 0x00008000U) /*!< ENET base address */
346
+ #define IPA_BASE (AHB1_BUS_BASE + 0x0000B000U) /*!< IPA base address */
347
+ #define USBHS_BASE (AHB1_BUS_BASE + 0x00020000U) /*!< USBHS base address */
348
+
349
+ /* advanced high performance bus 2 memory map */
350
+ #define USBFS_BASE (AHB2_BUS_BASE + 0x00000000U) /*!< USBFS base address */
351
+ #define DCI_BASE (AHB2_BUS_BASE + 0x00050000U) /*!< DCI base address */
352
+ #define TRNG_BASE (AHB2_BUS_BASE + 0x00060800U) /*!< TRNG base address */
353
+ /* option byte and debug memory map */
354
+ #define OB_BASE ((uint32_t)0x1FFEC000U) /*!< OB base address */
355
+ #define DBG_BASE ((uint32_t)0xE0042000U) /*!< DBG base address */
356
+
357
+ /* define marco USE_STDPERIPH_DRIVER */
358
+ #if !defined USE_STDPERIPH_DRIVER
359
+ #define USE_STDPERIPH_DRIVER
360
+ #endif
361
+ #ifdef USE_STDPERIPH_DRIVER
362
+ #include "gd32f4xx_libopt.h"
363
+ #endif /* USE_STDPERIPH_DRIVER */
364
+
365
+ #ifdef __cplusplus
366
+ }
367
+ #endif
368
+ #endif
deployment/GD32F470I_BluePill_ARMCC/ARM/System/gd32f4xx_it.c ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ \file gd32f4xx_it.c
3
+ \brief interrupt service routines
4
+
5
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
6
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
7
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
8
+ \version 2022-03-09, V3.0.0, firmware for GD32F4xx
9
+ */
10
+
11
+ /*
12
+ Copyright (c) 2022, GigaDevice Semiconductor Inc.
13
+
14
+ Redistribution and use in source and binary forms, with or without modification,
15
+ are permitted provided that the following conditions are met:
16
+
17
+ 1. Redistributions of source code must retain the above copyright notice, this
18
+ list of conditions and the following disclaimer.
19
+ 2. Redistributions in binary form must reproduce the above copyright notice,
20
+ this list of conditions and the following disclaimer in the documentation
21
+ and/or other materials provided with the distribution.
22
+ 3. Neither the name of the copyright holder nor the names of its contributors
23
+ may be used to endorse or promote products derived from this software without
24
+ specific prior written permission.
25
+
26
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
35
+ OF SUCH DAMAGE.
36
+ */
37
+
38
+ #include "gd32f4xx_it.h"
39
+ #include "main.h"
40
+ #include "systick.h"
41
+
42
+ /*!
43
+ \brief this function handles NMI exception
44
+ \param[in] none
45
+ \param[out] none
46
+ \retval none
47
+ */
48
+ void NMI_Handler(void)
49
+ {
50
+ }
51
+
52
+ /*!
53
+ \brief this function handles HardFault exception
54
+ \param[in] none
55
+ \param[out] none
56
+ \retval none
57
+ */
58
+ void HardFault_Handler(void)
59
+ {
60
+ /* if Hard Fault exception occurs, go to infinite loop */
61
+ while(1) {
62
+ }
63
+ }
64
+
65
+ /*!
66
+ \brief this function handles MemManage exception
67
+ \param[in] none
68
+ \param[out] none
69
+ \retval none
70
+ */
71
+ void MemManage_Handler(void)
72
+ {
73
+ /* if Memory Manage exception occurs, go to infinite loop */
74
+ while(1) {
75
+ }
76
+ }
77
+
78
+ /*!
79
+ \brief this function handles BusFault exception
80
+ \param[in] none
81
+ \param[out] none
82
+ \retval none
83
+ */
84
+ void BusFault_Handler(void)
85
+ {
86
+ /* if Bus Fault exception occurs, go to infinite loop */
87
+ while(1) {
88
+ }
89
+ }
90
+
91
+ /*!
92
+ \brief this function handles UsageFault exception
93
+ \param[in] none
94
+ \param[out] none
95
+ \retval none
96
+ */
97
+ void UsageFault_Handler(void)
98
+ {
99
+ /* if Usage Fault exception occurs, go to infinite loop */
100
+ while(1) {
101
+ }
102
+ }
103
+
104
+ /*!
105
+ \brief this function handles SVC exception
106
+ \param[in] none
107
+ \param[out] none
108
+ \retval none
109
+ */
110
+ void SVC_Handler(void)
111
+ {
112
+ }
113
+
114
+ /*!
115
+ \brief this function handles DebugMon exception
116
+ \param[in] none
117
+ \param[out] none
118
+ \retval none
119
+ */
120
+ void DebugMon_Handler(void)
121
+ {
122
+ }
123
+
124
+ /*!
125
+ \brief this function handles PendSV exception
126
+ \param[in] none
127
+ \param[out] none
128
+ \retval none
129
+ */
130
+ void PendSV_Handler(void)
131
+ {
132
+ }
133
+
134
+ /*!
135
+ \brief this function handles SysTick exception
136
+ \param[in] none
137
+ \param[out] none
138
+ \retval none
139
+ */
140
+ //void SysTick_Handler(void)
141
+ //{
142
+ //
143
+ //}
deployment/GD32F470I_BluePill_ARMCC/ARM/System/gd32f4xx_it.h ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ \file gd32f4xx_it.h
3
+ \brief the header file of the ISR
4
+
5
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
6
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
7
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
8
+ \version 2022-03-09, V3.0.0, firmware for GD32F4xx
9
+ */
10
+
11
+ /*
12
+ Copyright (c) 2022, GigaDevice Semiconductor Inc.
13
+
14
+ Redistribution and use in source and binary forms, with or without modification,
15
+ are permitted provided that the following conditions are met:
16
+
17
+ 1. Redistributions of source code must retain the above copyright notice, this
18
+ list of conditions and the following disclaimer.
19
+ 2. Redistributions in binary form must reproduce the above copyright notice,
20
+ this list of conditions and the following disclaimer in the documentation
21
+ and/or other materials provided with the distribution.
22
+ 3. Neither the name of the copyright holder nor the names of its contributors
23
+ may be used to endorse or promote products derived from this software without
24
+ specific prior written permission.
25
+
26
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
35
+ OF SUCH DAMAGE.
36
+ */
37
+
38
+ #ifndef GD32F4XX_IT_H
39
+ #define GD32F4XX_IT_H
40
+
41
+ #include "gd32f4xx.h"
42
+
43
+ /* function declarations */
44
+ /* this function handles NMI exception */
45
+ void NMI_Handler(void);
46
+ /* this function handles HardFault exception */
47
+ void HardFault_Handler(void);
48
+ /* this function handles MemManage exception */
49
+ void MemManage_Handler(void);
50
+ /* this function handles BusFault exception */
51
+ void BusFault_Handler(void);
52
+ /* this function handles UsageFault exception */
53
+ void UsageFault_Handler(void);
54
+ /* this function handles SVC exception */
55
+ void SVC_Handler(void);
56
+ /* this function handles DebugMon exception */
57
+ void DebugMon_Handler(void);
58
+ /* this function handles PendSV exception */
59
+ void PendSV_Handler(void);
60
+ /* this function handles SysTick exception */
61
+ void SysTick_Handler(void);
62
+
63
+ #endif /* GD32F4XX_IT_H */
deployment/GD32F470I_BluePill_ARMCC/ARM/System/gd32f4xx_libopt.h ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ \file gd32f4xx_libopt.h
3
+ \brief library optional for gd32f4xx
4
+
5
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
6
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
7
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
8
+ \version 2022-03-09, V3.0.0, firmware for GD32F4xx
9
+ */
10
+
11
+ /*
12
+ Copyright (c) 2022, GigaDevice Semiconductor Inc.
13
+
14
+ Redistribution and use in source and binary forms, with or without modification,
15
+ are permitted provided that the following conditions are met:
16
+
17
+ 1. Redistributions of source code must retain the above copyright notice, this
18
+ list of conditions and the following disclaimer.
19
+ 2. Redistributions in binary form must reproduce the above copyright notice,
20
+ this list of conditions and the following disclaimer in the documentation
21
+ and/or other materials provided with the distribution.
22
+ 3. Neither the name of the copyright holder nor the names of its contributors
23
+ may be used to endorse or promote products derived from this software without
24
+ specific prior written permission.
25
+
26
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
35
+ OF SUCH DAMAGE.
36
+ */
37
+
38
+ #ifndef GD32F4XX_LIBOPT_H
39
+ #define GD32F4XX_LIBOPT_H
40
+
41
+ #if defined (GD32F450) || defined (GD32F405) || defined (GD32F407) || defined (GD32F470) || defined (GD32F425) || defined (GD32F427)
42
+ #include "gd32f4xx_rcu.h"
43
+ #include "gd32f4xx_adc.h"
44
+ #include "gd32f4xx_can.h"
45
+ #include "gd32f4xx_crc.h"
46
+ #include "gd32f4xx_ctc.h"
47
+ #include "gd32f4xx_dac.h"
48
+ #include "gd32f4xx_dbg.h"
49
+ #include "gd32f4xx_dci.h"
50
+ #include "gd32f4xx_dma.h"
51
+ #include "gd32f4xx_exti.h"
52
+ #include "gd32f4xx_fmc.h"
53
+ #include "gd32f4xx_fwdgt.h"
54
+ #include "gd32f4xx_gpio.h"
55
+ #include "gd32f4xx_syscfg.h"
56
+ #include "gd32f4xx_i2c.h"
57
+ #include "gd32f4xx_iref.h"
58
+ #include "gd32f4xx_pmu.h"
59
+ #include "gd32f4xx_rtc.h"
60
+ #include "gd32f4xx_sdio.h"
61
+ #include "gd32f4xx_spi.h"
62
+ #include "gd32f4xx_timer.h"
63
+ #include "gd32f4xx_trng.h"
64
+ #include "gd32f4xx_usart.h"
65
+ #include "gd32f4xx_wwdgt.h"
66
+ #include "gd32f4xx_misc.h"
67
+ #endif
68
+
69
+ #if defined (GD32F450) || defined (GD32F470)
70
+ #include "gd32f4xx_enet.h"
71
+ #include "gd32f4xx_exmc.h"
72
+ #include "gd32f4xx_ipa.h"
73
+ #include "gd32f4xx_tli.h"
74
+ #endif
75
+
76
+ #if defined (GD32F407) || defined (GD32F427)
77
+ #include "gd32f4xx_enet.h"
78
+ #include "gd32f4xx_exmc.h"
79
+ #endif
80
+
81
+ #endif /* GD32F4XX_LIBOPT_H */
deployment/GD32F470I_BluePill_ARMCC/ARM/System/startup_gd32f450_470.s ADDED
@@ -0,0 +1,470 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ;/*!
2
+ ; \file startup_gd32f450_470.s
3
+ ; \brief start up file
4
+ ;
5
+ ; \version 2016-08-15, V1.0.0, firmware for GD32F4xx
6
+ ; \version 2018-12-12, V2.0.0, firmware for GD32F4xx
7
+ ; \version 2020-09-30, V2.1.0, firmware for GD32F4xx
8
+ ; \version 2022-03-09, V3.0.0, firmware for GD32F4xx
9
+ ;*/
10
+ ;
11
+ ;/*
12
+ ; Copyright (c) 2022, GigaDevice Semiconductor Inc.
13
+ ;
14
+ ; Redistribution and use in source and binary forms, with or without modification,
15
+ ;are permitted provided that the following conditions are met:
16
+ ;
17
+ ; 1. Redistributions of source code must retain the above copyright notice, this
18
+ ; list of conditions and the following disclaimer.
19
+ ; 2. Redistributions in binary form must reproduce the above copyright notice,
20
+ ; this list of conditions and the following disclaimer in the documentation
21
+ ; and/or other materials provided with the distribution.
22
+ ; 3. Neither the name of the copyright holder nor the names of its contributors
23
+ ; may be used to endorse or promote products derived from this software without
24
+ ; specific prior written permission.
25
+ ;
26
+ ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27
+ ;AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28
+ ;WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29
+ ;IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30
+ ;INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31
+ ;NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32
+ ;PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33
+ ;WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34
+ ;ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
35
+ ;OF SUCH DAMAGE.
36
+ ;*/
37
+
38
+ ; <h> Stack Configuration
39
+ ; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
40
+ ; </h>
41
+
42
+ Stack_Size EQU 0x00001000
43
+
44
+ AREA STACK, NOINIT, READWRITE, ALIGN=3
45
+ Stack_Mem SPACE Stack_Size
46
+ ;__initial_sp
47
+ __initial_sp EQU 0x200B0000
48
+ ;__initial_sp EQU 0x10000000+Stack_Size
49
+
50
+
51
+ ; <h> Heap Configuration
52
+ ; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
53
+ ; </h>
54
+
55
+ Heap_Size EQU 0x00000F00
56
+ ;Heap_Size EQU 0x00100000
57
+
58
+ AREA HEAP, NOINIT, READWRITE, ALIGN=3
59
+ __heap_base
60
+ Heap_Mem SPACE Heap_Size
61
+ __heap_limit
62
+
63
+ PRESERVE8
64
+ THUMB
65
+
66
+ ; /* reset Vector Mapped to at Address 0 */
67
+ AREA RESET, DATA, READONLY
68
+ EXPORT __Vectors
69
+ EXPORT __Vectors_End
70
+ EXPORT __Vectors_Size
71
+
72
+ __Vectors DCD __initial_sp ; Top of Stack
73
+ DCD Reset_Handler ; Reset Handler
74
+ DCD NMI_Handler ; NMI Handler
75
+ DCD HardFault_Handler ; Hard Fault Handler
76
+ DCD MemManage_Handler ; MPU Fault Handler
77
+ DCD BusFault_Handler ; Bus Fault Handler
78
+ DCD UsageFault_Handler ; Usage Fault Handler
79
+ DCD 0 ; Reserved
80
+ DCD 0 ; Reserved
81
+ DCD 0 ; Reserved
82
+ DCD 0 ; Reserved
83
+ DCD SVC_Handler ; SVCall Handler
84
+ DCD DebugMon_Handler ; Debug Monitor Handler
85
+ DCD 0 ; Reserved
86
+ DCD PendSV_Handler ; PendSV Handler
87
+ DCD SysTick_Handler ; SysTick Handler
88
+
89
+ ; /* external interrupts handler */
90
+ DCD WWDGT_IRQHandler ; 16:Window Watchdog Timer
91
+ DCD LVD_IRQHandler ; 17:LVD through EXTI Line detect
92
+ DCD TAMPER_STAMP_IRQHandler ; 18:Tamper and TimeStamp through EXTI Line detect
93
+ DCD RTC_WKUP_IRQHandler ; 19:RTC Wakeup through EXTI Line
94
+ DCD FMC_IRQHandler ; 20:FMC
95
+ DCD RCU_CTC_IRQHandler ; 21:RCU and CTC
96
+ DCD EXTI0_IRQHandler ; 22:EXTI Line 0
97
+ DCD EXTI1_IRQHandler ; 23:EXTI Line 1
98
+ DCD EXTI2_IRQHandler ; 24:EXTI Line 2
99
+ DCD EXTI3_IRQHandler ; 25:EXTI Line 3
100
+ DCD EXTI4_IRQHandler ; 26:EXTI Line 4
101
+ DCD DMA0_Channel0_IRQHandler ; 27:DMA0 Channel0
102
+ DCD DMA0_Channel1_IRQHandler ; 28:DMA0 Channel1
103
+ DCD DMA0_Channel2_IRQHandler ; 29:DMA0 Channel2
104
+ DCD DMA0_Channel3_IRQHandler ; 30:DMA0 Channel3
105
+ DCD DMA0_Channel4_IRQHandler ; 31:DMA0 Channel4
106
+ DCD DMA0_Channel5_IRQHandler ; 32:DMA0 Channel5
107
+ DCD DMA0_Channel6_IRQHandler ; 33:DMA0 Channel6
108
+ DCD ADC_IRQHandler ; 34:ADC
109
+ DCD CAN0_TX_IRQHandler ; 35:CAN0 TX
110
+ DCD CAN0_RX0_IRQHandler ; 36:CAN0 RX0
111
+ DCD CAN0_RX1_IRQHandler ; 37:CAN0 RX1
112
+ DCD CAN0_EWMC_IRQHandler ; 38:CAN0 EWMC
113
+ DCD EXTI5_9_IRQHandler ; 39:EXTI5 to EXTI9
114
+ DCD TIMER0_BRK_TIMER8_IRQHandler ; 40:TIMER0 Break and TIMER8
115
+ DCD TIMER0_UP_TIMER9_IRQHandler ; 41:TIMER0 Update and TIMER9
116
+ DCD TIMER0_TRG_CMT_TIMER10_IRQHandler ; 42:TIMER0 Trigger and Commutation and TIMER10
117
+ DCD TIMER0_Channel_IRQHandler ; 43:TIMER0 Capture Compare
118
+ DCD TIMER1_IRQHandler ; 44:TIMER1
119
+ DCD TIMER2_IRQHandler ; 45:TIMER2
120
+ DCD TIMER3_IRQHandler ; 46:TIMER3
121
+ DCD I2C0_EV_IRQHandler ; 47:I2C0 Event
122
+ DCD I2C0_ER_IRQHandler ; 48:I2C0 Error
123
+ DCD I2C1_EV_IRQHandler ; 49:I2C1 Event
124
+ DCD I2C1_ER_IRQHandler ; 50:I2C1 Error
125
+ DCD SPI0_IRQHandler ; 51:SPI0
126
+ DCD SPI1_IRQHandler ; 52:SPI1
127
+ DCD USART0_IRQHandler ; 53:USART0
128
+ DCD USART1_IRQHandler ; 54:USART1
129
+ DCD USART2_IRQHandler ; 55:USART2
130
+ DCD EXTI10_15_IRQHandler ; 56:EXTI10 to EXTI15
131
+ DCD RTC_Alarm_IRQHandler ; 57:RTC Alarm
132
+ DCD USBFS_WKUP_IRQHandler ; 58:USBFS Wakeup
133
+ DCD TIMER7_BRK_TIMER11_IRQHandler ; 59:TIMER7 Break and TIMER11
134
+ DCD TIMER7_UP_TIMER12_IRQHandler ; 60:TIMER7 Update and TIMER12
135
+ DCD TIMER7_TRG_CMT_TIMER13_IRQHandler ; 61:TIMER7 Trigger and Commutation and TIMER13
136
+ DCD TIMER7_Channel_IRQHandler ; 62:TIMER7 Channel Capture Compare
137
+ DCD DMA0_Channel7_IRQHandler ; 63:DMA0 Channel7
138
+ DCD EXMC_IRQHandler ; 64:EXMC
139
+ DCD SDIO_IRQHandler ; 65:SDIO
140
+ DCD TIMER4_IRQHandler ; 66:TIMER4
141
+ DCD SPI2_IRQHandler ; 67:SPI2
142
+ DCD UART3_IRQHandler ; 68:UART3
143
+ DCD UART4_IRQHandler ; 69:UART4
144
+ DCD TIMER5_DAC_IRQHandler ; 70:TIMER5 and DAC0 DAC1 Underrun error
145
+ DCD TIMER6_IRQHandler ; 71:TIMER6
146
+ DCD DMA1_Channel0_IRQHandler ; 72:DMA1 Channel0
147
+ DCD DMA1_Channel1_IRQHandler ; 73:DMA1 Channel1
148
+ DCD DMA1_Channel2_IRQHandler ; 74:DMA1 Channel2
149
+ DCD DMA1_Channel3_IRQHandler ; 75:DMA1 Channel3
150
+ DCD DMA1_Channel4_IRQHandler ; 76:DMA1 Channel4
151
+ DCD ENET_IRQHandler ; 77:Ethernet
152
+ DCD ENET_WKUP_IRQHandler ; 78:Ethernet Wakeup through EXTI Line
153
+ DCD CAN1_TX_IRQHandler ; 79:CAN1 TX
154
+ DCD CAN1_RX0_IRQHandler ; 80:CAN1 RX0
155
+ DCD CAN1_RX1_IRQHandler ; 81:CAN1 RX1
156
+ DCD CAN1_EWMC_IRQHandler ; 82:CAN1 EWMC
157
+ DCD USBFS_IRQHandler ; 83:USBFS
158
+ DCD DMA1_Channel5_IRQHandler ; 84:DMA1 Channel5
159
+ DCD DMA1_Channel6_IRQHandler ; 85:DMA1 Channel6
160
+ DCD DMA1_Channel7_IRQHandler ; 86:DMA1 Channel7
161
+ DCD USART5_IRQHandler ; 87:USART5
162
+ DCD I2C2_EV_IRQHandler ; 88:I2C2 Event
163
+ DCD I2C2_ER_IRQHandler ; 89:I2C2 Error
164
+ DCD USBHS_EP1_Out_IRQHandler ; 90:USBHS Endpoint 1 Out
165
+ DCD USBHS_EP1_In_IRQHandler ; 91:USBHS Endpoint 1 in
166
+ DCD USBHS_WKUP_IRQHandler ; 92:USBHS Wakeup through EXTI Line
167
+ DCD USBHS_IRQHandler ; 93:USBHS
168
+ DCD DCI_IRQHandler ; 94:DCI
169
+ DCD 0 ; 95:Reserved
170
+ DCD TRNG_IRQHandler ; 96:TRNG
171
+ DCD FPU_IRQHandler ; 97:FPU
172
+ DCD UART6_IRQHandler ; 98:UART6
173
+ DCD UART7_IRQHandler ; 99:UART7
174
+ DCD SPI3_IRQHandler ; 100:SPI3
175
+ DCD SPI4_IRQHandler ; 101:SPI4
176
+ DCD SPI5_IRQHandler ; 102:SPI5
177
+ DCD 0 ; 103:Reserved
178
+ DCD TLI_IRQHandler ; 104:TLI
179
+ DCD TLI_ER_IRQHandler ; 105:TLI Error
180
+ DCD IPA_IRQHandler ; 106:IPA
181
+
182
+ __Vectors_End
183
+
184
+ __Vectors_Size EQU __Vectors_End - __Vectors
185
+
186
+ AREA |.text|, CODE, READONLY
187
+
188
+ ;/* reset Handler */
189
+ Reset_Handler PROC
190
+ EXPORT Reset_Handler [WEAK]
191
+ IMPORT SystemInit
192
+ IMPORT __main
193
+ LDR R0, =SystemInit
194
+ BLX R0
195
+ LDR R0, =__main
196
+ BX R0
197
+ ENDP
198
+
199
+ ;/* dummy Exception Handlers */
200
+ NMI_Handler PROC
201
+ EXPORT NMI_Handler [WEAK]
202
+ B .
203
+ ENDP
204
+ HardFault_Handler\
205
+ PROC
206
+ EXPORT HardFault_Handler [WEAK]
207
+ B .
208
+ ENDP
209
+ MemManage_Handler\
210
+ PROC
211
+ EXPORT MemManage_Handler [WEAK]
212
+ B .
213
+ ENDP
214
+ BusFault_Handler\
215
+ PROC
216
+ EXPORT BusFault_Handler [WEAK]
217
+ B .
218
+ ENDP
219
+ UsageFault_Handler\
220
+ PROC
221
+ EXPORT UsageFault_Handler [WEAK]
222
+ B .
223
+ ENDP
224
+ SVC_Handler PROC
225
+ EXPORT SVC_Handler [WEAK]
226
+ B .
227
+ ENDP
228
+ DebugMon_Handler\
229
+ PROC
230
+ EXPORT DebugMon_Handler [WEAK]
231
+ B .
232
+ ENDP
233
+ PendSV_Handler\
234
+ PROC
235
+ EXPORT PendSV_Handler [WEAK]
236
+ B .
237
+ ENDP
238
+ SysTick_Handler\
239
+ PROC
240
+ EXPORT SysTick_Handler [WEAK]
241
+ B .
242
+ ENDP
243
+
244
+ Default_Handler PROC
245
+ ; /* external interrupts handler */
246
+ EXPORT WWDGT_IRQHandler [WEAK]
247
+ EXPORT LVD_IRQHandler [WEAK]
248
+ EXPORT TAMPER_STAMP_IRQHandler [WEAK]
249
+ EXPORT RTC_WKUP_IRQHandler [WEAK]
250
+ EXPORT FMC_IRQHandler [WEAK]
251
+ EXPORT RCU_CTC_IRQHandler [WEAK]
252
+ EXPORT EXTI0_IRQHandler [WEAK]
253
+ EXPORT EXTI1_IRQHandler [WEAK]
254
+ EXPORT EXTI2_IRQHandler [WEAK]
255
+ EXPORT EXTI3_IRQHandler [WEAK]
256
+ EXPORT EXTI4_IRQHandler [WEAK]
257
+ EXPORT DMA0_Channel0_IRQHandler [WEAK]
258
+ EXPORT DMA0_Channel1_IRQHandler [WEAK]
259
+ EXPORT DMA0_Channel2_IRQHandler [WEAK]
260
+ EXPORT DMA0_Channel3_IRQHandler [WEAK]
261
+ EXPORT DMA0_Channel4_IRQHandler [WEAK]
262
+ EXPORT DMA0_Channel5_IRQHandler [WEAK]
263
+ EXPORT DMA0_Channel6_IRQHandler [WEAK]
264
+ EXPORT ADC_IRQHandler [WEAK]
265
+ EXPORT CAN0_TX_IRQHandler [WEAK]
266
+ EXPORT CAN0_RX0_IRQHandler [WEAK]
267
+ EXPORT CAN0_RX1_IRQHandler [WEAK]
268
+ EXPORT CAN0_EWMC_IRQHandler [WEAK]
269
+ EXPORT EXTI5_9_IRQHandler [WEAK]
270
+ EXPORT TIMER0_BRK_TIMER8_IRQHandler [WEAK]
271
+ EXPORT TIMER0_UP_TIMER9_IRQHandler [WEAK]
272
+ EXPORT TIMER0_TRG_CMT_TIMER10_IRQHandler [WEAK]
273
+ EXPORT TIMER0_Channel_IRQHandler [WEAK]
274
+ EXPORT TIMER1_IRQHandler [WEAK]
275
+ EXPORT TIMER2_IRQHandler [WEAK]
276
+ EXPORT TIMER3_IRQHandler [WEAK]
277
+ EXPORT I2C0_EV_IRQHandler [WEAK]
278
+ EXPORT I2C0_ER_IRQHandler [WEAK]
279
+ EXPORT I2C1_EV_IRQHandler [WEAK]
280
+ EXPORT I2C1_ER_IRQHandler [WEAK]
281
+ EXPORT SPI0_IRQHandler [WEAK]
282
+ EXPORT SPI1_IRQHandler [WEAK]
283
+ EXPORT USART0_IRQHandler [WEAK]
284
+ EXPORT USART1_IRQHandler [WEAK]
285
+ EXPORT USART2_IRQHandler [WEAK]
286
+ EXPORT EXTI10_15_IRQHandler [WEAK]
287
+ EXPORT RTC_Alarm_IRQHandler [WEAK]
288
+ EXPORT USBFS_WKUP_IRQHandler [WEAK]
289
+ EXPORT TIMER7_BRK_TIMER11_IRQHandler [WEAK]
290
+ EXPORT TIMER7_UP_TIMER12_IRQHandler [WEAK]
291
+ EXPORT TIMER7_TRG_CMT_TIMER13_IRQHandler [WEAK]
292
+ EXPORT TIMER7_Channel_IRQHandler [WEAK]
293
+ EXPORT DMA0_Channel7_IRQHandler [WEAK]
294
+ EXPORT EXMC_IRQHandler [WEAK]
295
+ EXPORT SDIO_IRQHandler [WEAK]
296
+ EXPORT TIMER4_IRQHandler [WEAK]
297
+ EXPORT SPI2_IRQHandler [WEAK]
298
+ EXPORT UART3_IRQHandler [WEAK]
299
+ EXPORT UART4_IRQHandler [WEAK]
300
+ EXPORT TIMER5_DAC_IRQHandler [WEAK]
301
+ EXPORT TIMER6_IRQHandler [WEAK]
302
+ EXPORT DMA1_Channel0_IRQHandler [WEAK]
303
+ EXPORT DMA1_Channel1_IRQHandler [WEAK]
304
+ EXPORT DMA1_Channel2_IRQHandler [WEAK]
305
+ EXPORT DMA1_Channel3_IRQHandler [WEAK]
306
+ EXPORT DMA1_Channel4_IRQHandler [WEAK]
307
+ EXPORT ENET_IRQHandler [WEAK]
308
+ EXPORT ENET_WKUP_IRQHandler [WEAK]
309
+ EXPORT CAN1_TX_IRQHandler [WEAK]
310
+ EXPORT CAN1_RX0_IRQHandler [WEAK]
311
+ EXPORT CAN1_RX1_IRQHandler [WEAK]
312
+ EXPORT CAN1_EWMC_IRQHandler [WEAK]
313
+ EXPORT USBFS_IRQHandler [WEAK]
314
+ EXPORT DMA1_Channel5_IRQHandler [WEAK]
315
+ EXPORT DMA1_Channel6_IRQHandler [WEAK]
316
+ EXPORT DMA1_Channel7_IRQHandler [WEAK]
317
+ EXPORT USART5_IRQHandler [WEAK]
318
+ EXPORT I2C2_EV_IRQHandler [WEAK]
319
+ EXPORT I2C2_ER_IRQHandler [WEAK]
320
+ EXPORT USBHS_EP1_Out_IRQHandler [WEAK]
321
+ EXPORT USBHS_EP1_In_IRQHandler [WEAK]
322
+ EXPORT USBHS_WKUP_IRQHandler [WEAK]
323
+ EXPORT USBHS_IRQHandler [WEAK]
324
+ EXPORT DCI_IRQHandler [WEAK]
325
+ EXPORT TRNG_IRQHandler [WEAK]
326
+ EXPORT FPU_IRQHandler [WEAK]
327
+ EXPORT UART6_IRQHandler [WEAK]
328
+ EXPORT UART7_IRQHandler [WEAK]
329
+ EXPORT SPI3_IRQHandler [WEAK]
330
+ EXPORT SPI4_IRQHandler [WEAK]
331
+ EXPORT SPI5_IRQHandler [WEAK]
332
+ EXPORT TLI_IRQHandler [WEAK]
333
+ EXPORT TLI_ER_IRQHandler [WEAK]
334
+ EXPORT IPA_IRQHandler [WEAK]
335
+
336
+ ;/* external interrupts handler */
337
+ WWDGT_IRQHandler
338
+ LVD_IRQHandler
339
+ TAMPER_STAMP_IRQHandler
340
+ RTC_WKUP_IRQHandler
341
+ FMC_IRQHandler
342
+ RCU_CTC_IRQHandler
343
+ EXTI0_IRQHandler
344
+ EXTI1_IRQHandler
345
+ EXTI2_IRQHandler
346
+ EXTI3_IRQHandler
347
+ EXTI4_IRQHandler
348
+ DMA0_Channel0_IRQHandler
349
+ DMA0_Channel1_IRQHandler
350
+ DMA0_Channel2_IRQHandler
351
+ DMA0_Channel3_IRQHandler
352
+ DMA0_Channel4_IRQHandler
353
+ DMA0_Channel5_IRQHandler
354
+ DMA0_Channel6_IRQHandler
355
+ ADC_IRQHandler
356
+ CAN0_TX_IRQHandler
357
+ CAN0_RX0_IRQHandler
358
+ CAN0_RX1_IRQHandler
359
+ CAN0_EWMC_IRQHandler
360
+ EXTI5_9_IRQHandler
361
+ TIMER0_BRK_TIMER8_IRQHandler
362
+ TIMER0_UP_TIMER9_IRQHandler
363
+ TIMER0_TRG_CMT_TIMER10_IRQHandler
364
+ TIMER0_Channel_IRQHandler
365
+ TIMER1_IRQHandler
366
+ TIMER2_IRQHandler
367
+ TIMER3_IRQHandler
368
+ I2C0_EV_IRQHandler
369
+ I2C0_ER_IRQHandler
370
+ I2C1_EV_IRQHandler
371
+ I2C1_ER_IRQHandler
372
+ SPI0_IRQHandler
373
+ SPI1_IRQHandler
374
+ USART0_IRQHandler
375
+ USART1_IRQHandler
376
+ USART2_IRQHandler
377
+ EXTI10_15_IRQHandler
378
+ RTC_Alarm_IRQHandler
379
+ USBFS_WKUP_IRQHandler
380
+ TIMER7_BRK_TIMER11_IRQHandler
381
+ TIMER7_UP_TIMER12_IRQHandler
382
+ TIMER7_TRG_CMT_TIMER13_IRQHandler
383
+ TIMER7_Channel_IRQHandler
384
+ DMA0_Channel7_IRQHandler
385
+ EXMC_IRQHandler
386
+ SDIO_IRQHandler
387
+ TIMER4_IRQHandler
388
+ SPI2_IRQHandler
389
+ UART3_IRQHandler
390
+ UART4_IRQHandler
391
+ TIMER5_DAC_IRQHandler
392
+ TIMER6_IRQHandler
393
+ DMA1_Channel0_IRQHandler
394
+ DMA1_Channel1_IRQHandler
395
+ DMA1_Channel2_IRQHandler
396
+ DMA1_Channel3_IRQHandler
397
+ DMA1_Channel4_IRQHandler
398
+ ENET_IRQHandler
399
+ ENET_WKUP_IRQHandler
400
+ CAN1_TX_IRQHandler
401
+ CAN1_RX0_IRQHandler
402
+ CAN1_RX1_IRQHandler
403
+ CAN1_EWMC_IRQHandler
404
+ USBFS_IRQHandler
405
+ DMA1_Channel5_IRQHandler
406
+ DMA1_Channel6_IRQHandler
407
+ DMA1_Channel7_IRQHandler
408
+ USART5_IRQHandler
409
+ I2C2_EV_IRQHandler
410
+ I2C2_ER_IRQHandler
411
+ USBHS_EP1_Out_IRQHandler
412
+ USBHS_EP1_In_IRQHandler
413
+ USBHS_WKUP_IRQHandler
414
+ USBHS_IRQHandler
415
+ DCI_IRQHandler
416
+ TRNG_IRQHandler
417
+ FPU_IRQHandler
418
+ UART6_IRQHandler
419
+ UART7_IRQHandler
420
+ SPI3_IRQHandler
421
+ SPI4_IRQHandler
422
+ SPI5_IRQHandler
423
+ TLI_IRQHandler
424
+ TLI_ER_IRQHandler
425
+ IPA_IRQHandler
426
+
427
+ B .
428
+ ENDP
429
+
430
+ ALIGN
431
+
432
+ ; user Initial Stack & Heap
433
+
434
+ IF :DEF:__MICROLIB
435
+
436
+ EXPORT __initial_sp
437
+ EXPORT __heap_base
438
+ EXPORT __heap_limit
439
+
440
+ ELSE
441
+
442
+ IMPORT __use_two_region_memory
443
+ EXPORT __user_initial_stackheap
444
+
445
+ __user_initial_stackheap PROC
446
+ LDR R0, = 0xD1800000
447
+ LDR R1, =(0xD2000000)
448
+ LDR R2, = (0xD1A00000)
449
+ LDR R3, = 0xD1A00000
450
+ BX LR
451
+ ENDP
452
+
453
+ ALIGN
454
+
455
+ ENDIF
456
+
457
+ END
458
+ ;__user_initial_stackheap PROC
459
+ ;LDR R0, = Heap_Mem
460
+ ;LDR R1, =(Stack_Mem + Stack_Size)
461
+ ;LDR R2, = (Heap_Mem + Heap_Size)
462
+ ;LDR R3, = Stack_Mem
463
+ ;BX LR
464
+ ;ENDP
465
+
466
+ ;ALIGN
467
+
468
+ ;ENDIF
469
+
470
+ ;END
deployment/GD32F470I_BluePill_ARMCC/ARM/System/system_gd32f4xx.c ADDED
@@ -0,0 +1,1149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ \file system_gd32f4xx.c
3
+ \brief CMSIS Cortex-M4 Device Peripheral Access Layer Source File for
4
+ GD32F4xx Device Series
5
+ */
6
+
7
+ /* Copyright (c) 2012 ARM LIMITED
8
+
9
+ All rights reserved.
10
+ Redistribution and use in source and binary forms, with or without
11
+ modification, are permitted provided that the following conditions are met:
12
+ - Redistributions of source code must retain the above copyright
13
+ notice, this list of conditions and the following disclaimer.
14
+ - Redistributions in binary form must reproduce the above copyright
15
+ notice, this list of conditions and the following disclaimer in the
16
+ documentation and/or other materials provided with the distribution.
17
+ - Neither the name of ARM nor the names of its contributors may be used
18
+ to endorse or promote products derived from this software without
19
+ specific prior written permission.
20
+ *
21
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
+ ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
25
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
+ POSSIBILITY OF SUCH DAMAGE.
32
+ ---------------------------------------------------------------------------*/
33
+
34
+ /* This file refers the CMSIS standard, some adjustments are made according to GigaDevice chips */
35
+
36
+ #include "gd32f4xx.h"
37
+ #include "SDRAM.h"
38
+ /* system frequency define */
39
+ #define __IRC16M (IRC16M_VALUE) /* internal 16 MHz RC oscillator frequency */
40
+ #define __HXTAL (HXTAL_VALUE) /* high speed crystal oscillator frequency */
41
+ #define __SYS_OSC_CLK (__IRC16M) /* main oscillator frequency */
42
+
43
+ /* select a system clock by uncommenting the following line */
44
+ //#define __SYSTEM_CLOCK_IRC16M (uint32_t)(__IRC16M)
45
+ //#define __SYSTEM_CLOCK_HXTAL (uint32_t)(__HXTAL)
46
+ //#define __SYSTEM_CLOCK_120M_PLL_IRC16M (uint32_t)(120000000)
47
+ //#define __SYSTEM_CLOCK_120M_PLL_8M_HXTAL (uint32_t)(120000000)
48
+ //#define __SYSTEM_CLOCK_120M_PLL_25M_HXTAL (uint32_t)(120000000)
49
+ //#define __SYSTEM_CLOCK_168M_PLL_IRC16M (uint32_t)(168000000)
50
+ //#define __SYSTEM_CLOCK_168M_PLL_8M_HXTAL (uint32_t)(168000000)
51
+ //#define __SYSTEM_CLOCK_168M_PLL_25M_HXTAL (uint32_t)(168000000)
52
+ //#define __SYSTEM_CLOCK_200M_PLL_IRC16M (uint32_t)(200000000)
53
+ //#define __SYSTEM_CLOCK_200M_PLL_8M_HXTAL (uint32_t)(200000000)
54
+ //#define __SYSTEM_CLOCK_200M_PLL_25M_HXTAL (uint32_t)(200000000)
55
+ #define __SYSTEM_CLOCK_240M_PLL_IRC16M (uint32_t)(240000000)
56
+ //#define __SYSTEM_CLOCK_240M_PLL_8M_HXTAL (uint32_t)(240000000)
57
+ //#define __SYSTEM_CLOCK_240M_PLL_25M_HXTAL (uint32_t)(240000000)
58
+
59
+ #define SEL_IRC16M 0x00U
60
+ #define SEL_HXTAL 0x01U
61
+ #define SEL_PLLP 0x02U
62
+ #define RCU_MODIFY {volatile uint32_t i; \
63
+ RCU_CFG0 |= RCU_AHB_CKSYS_DIV2; \
64
+ for(i=0;i<50000;i++); \
65
+ RCU_CFG0 |= RCU_AHB_CKSYS_DIV4; \
66
+ for(i=0;i<50000;i++);}
67
+
68
+ /* set the system clock frequency and declare the system clock configuration function */
69
+ #ifdef __SYSTEM_CLOCK_IRC16M
70
+ uint32_t SystemCoreClock = __SYSTEM_CLOCK_IRC16M;
71
+ static void system_clock_16m_irc16m(void);
72
+ #elif defined (__SYSTEM_CLOCK_HXTAL)
73
+ uint32_t SystemCoreClock = __SYSTEM_CLOCK_HXTAL;
74
+ static void system_clock_hxtal(void);
75
+ #elif defined (__SYSTEM_CLOCK_120M_PLL_IRC16M)
76
+ uint32_t SystemCoreClock = __SYSTEM_CLOCK_120M_PLL_IRC16M;
77
+ static void system_clock_120m_irc16m(void);
78
+ #elif defined (__SYSTEM_CLOCK_120M_PLL_8M_HXTAL)
79
+ uint32_t SystemCoreClock = __SYSTEM_CLOCK_120M_PLL_8M_HXTAL;
80
+ static void system_clock_120m_8m_hxtal(void);
81
+ #elif defined (__SYSTEM_CLOCK_120M_PLL_25M_HXTAL)
82
+ uint32_t SystemCoreClock = __SYSTEM_CLOCK_120M_PLL_25M_HXTAL;
83
+ static void system_clock_120m_25m_hxtal(void);
84
+ #elif defined (__SYSTEM_CLOCK_168M_PLL_IRC16M)
85
+ uint32_t SystemCoreClock = __SYSTEM_CLOCK_168M_PLL_IRC16M;
86
+ static void system_clock_168m_irc16m(void);
87
+ #elif defined (__SYSTEM_CLOCK_168M_PLL_8M_HXTAL)
88
+ uint32_t SystemCoreClock = __SYSTEM_CLOCK_168M_PLL_8M_HXTAL;
89
+ static void system_clock_168m_8m_hxtal(void);
90
+ #elif defined (__SYSTEM_CLOCK_168M_PLL_25M_HXTAL)
91
+ uint32_t SystemCoreClock = __SYSTEM_CLOCK_168M_PLL_25M_HXTAL;
92
+ static void system_clock_168m_25m_hxtal(void);
93
+ #elif defined (__SYSTEM_CLOCK_200M_PLL_IRC16M)
94
+ uint32_t SystemCoreClock = __SYSTEM_CLOCK_200M_PLL_IRC16M;
95
+ static void system_clock_200m_irc16m(void);
96
+ #elif defined (__SYSTEM_CLOCK_200M_PLL_8M_HXTAL)
97
+ uint32_t SystemCoreClock = __SYSTEM_CLOCK_200M_PLL_8M_HXTAL;
98
+ static void system_clock_200m_8m_hxtal(void);
99
+ #elif defined (__SYSTEM_CLOCK_200M_PLL_25M_HXTAL)
100
+ uint32_t SystemCoreClock = __SYSTEM_CLOCK_200M_PLL_25M_HXTAL;
101
+ static void system_clock_200m_25m_hxtal(void);
102
+ #elif defined (__SYSTEM_CLOCK_240M_PLL_IRC16M)
103
+ uint32_t SystemCoreClock = __SYSTEM_CLOCK_240M_PLL_IRC16M;
104
+ static void system_clock_240m_irc16m(void);
105
+ #elif defined (__SYSTEM_CLOCK_240M_PLL_8M_HXTAL)
106
+ uint32_t SystemCoreClock = __SYSTEM_CLOCK_240M_PLL_8M_HXTAL;
107
+ static void system_clock_240m_8m_hxtal(void);
108
+ #elif defined (__SYSTEM_CLOCK_240M_PLL_25M_HXTAL)
109
+ uint32_t SystemCoreClock = __SYSTEM_CLOCK_240M_PLL_25M_HXTAL;
110
+ static void system_clock_240m_25m_hxtal(void);
111
+
112
+ #endif /* __SYSTEM_CLOCK_IRC16M */
113
+
114
+ /* configure the system clock */
115
+ static void system_clock_config(void);
116
+
117
+ /*!
118
+ \brief setup the microcontroller system, initialize the system
119
+ \param[in] none
120
+ \param[out] none
121
+ \retval none
122
+ */
123
+ void SystemInit (void)
124
+ {
125
+ /* FPU settings */
126
+ #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
127
+ SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
128
+ #endif
129
+ /* Reset the RCU clock configuration to the default reset state */
130
+ /* Set IRC16MEN bit */
131
+ RCU_CTL |= RCU_CTL_IRC16MEN;
132
+
133
+ RCU_MODIFY
134
+
135
+ RCU_CFG0 &= ~RCU_CFG0_SCS;
136
+
137
+ /* Reset HXTALEN, CKMEN and PLLEN bits */
138
+ RCU_CTL &= ~(RCU_CTL_PLLEN | RCU_CTL_CKMEN | RCU_CTL_HXTALEN);
139
+
140
+ /* Reset HSEBYP bit */
141
+ RCU_CTL &= ~(RCU_CTL_HXTALBPS);
142
+
143
+ /* Reset CFG0 register */
144
+ RCU_CFG0 = 0x00000000U;
145
+
146
+ /* wait until IRC16M is selected as system clock */
147
+ while(0 != (RCU_CFG0 & RCU_SCSS_IRC16M)){
148
+ }
149
+
150
+ /* Reset PLLCFGR register */
151
+ RCU_PLL = 0x24003010U;
152
+
153
+ /* Disable all interrupts */
154
+ RCU_INT = 0x00000000U;
155
+
156
+ /* Configure the System clock source, PLL Multiplier and Divider factors,
157
+ AHB/APBx prescalers and Flash settings */
158
+ system_clock_config();
159
+
160
+ InitSDRAM(); //��ʼ��SDRAMģ��
161
+ }
162
+ /*!
163
+ \brief configure the system clock
164
+ \param[in] none
165
+ \param[out] none
166
+ \retval none
167
+ */
168
+ static void system_clock_config(void)
169
+ {
170
+ #ifdef __SYSTEM_CLOCK_IRC16M
171
+ system_clock_16m_irc16m();
172
+ #elif defined (__SYSTEM_CLOCK_HXTAL)
173
+ system_clock_hxtal();
174
+ #elif defined (__SYSTEM_CLOCK_120M_PLL_IRC16M)
175
+ system_clock_120m_irc16m();
176
+ #elif defined (__SYSTEM_CLOCK_120M_PLL_8M_HXTAL)
177
+ system_clock_120m_8m_hxtal();
178
+ #elif defined (__SYSTEM_CLOCK_120M_PLL_25M_HXTAL)
179
+ system_clock_120m_25m_hxtal();
180
+ #elif defined (__SYSTEM_CLOCK_168M_PLL_IRC16M)
181
+ system_clock_168m_irc16m();
182
+ #elif defined (__SYSTEM_CLOCK_168M_PLL_8M_HXTAL)
183
+ system_clock_168m_8m_hxtal();
184
+ #elif defined (__SYSTEM_CLOCK_168M_PLL_25M_HXTAL)
185
+ system_clock_168m_25m_hxtal();
186
+ #elif defined (__SYSTEM_CLOCK_200M_PLL_IRC16M)
187
+ system_clock_200m_irc16m();
188
+ #elif defined (__SYSTEM_CLOCK_200M_PLL_8M_HXTAL)
189
+ system_clock_200m_8m_hxtal();
190
+ #elif defined (__SYSTEM_CLOCK_200M_PLL_25M_HXTAL)
191
+ system_clock_200m_25m_hxtal();
192
+ #elif defined (__SYSTEM_CLOCK_240M_PLL_IRC16M)
193
+ system_clock_240m_irc16m();
194
+ #elif defined (__SYSTEM_CLOCK_240M_PLL_8M_HXTAL)
195
+ system_clock_240m_8m_hxtal();
196
+ #elif defined (__SYSTEM_CLOCK_240M_PLL_25M_HXTAL)
197
+ system_clock_240m_25m_hxtal();
198
+ #endif /* __SYSTEM_CLOCK_IRC16M */
199
+ }
200
+
201
+ #ifdef __SYSTEM_CLOCK_IRC16M
202
+ /*!
203
+ \brief configure the system clock to 16M by IRC16M
204
+ \param[in] none
205
+ \param[out] none
206
+ \retval none
207
+ */
208
+ static void system_clock_16m_irc16m(void)
209
+ {
210
+ uint32_t timeout = 0U;
211
+ uint32_t stab_flag = 0U;
212
+
213
+ /* enable IRC16M */
214
+ RCU_CTL |= RCU_CTL_IRC16MEN;
215
+
216
+ /* wait until IRC16M is stable or the startup time is longer than IRC16M_STARTUP_TIMEOUT */
217
+ do{
218
+ timeout++;
219
+ stab_flag = (RCU_CTL & RCU_CTL_IRC16MSTB);
220
+ }while((0U == stab_flag) && (IRC16M_STARTUP_TIMEOUT != timeout));
221
+
222
+ /* if fail */
223
+ if(0U == (RCU_CTL & RCU_CTL_IRC16MSTB)){
224
+ while(1){
225
+ }
226
+ }
227
+
228
+ /* AHB = SYSCLK */
229
+ RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
230
+ /* APB2 = AHB */
231
+ RCU_CFG0 |= RCU_APB2_CKAHB_DIV1;
232
+ /* APB1 = AHB */
233
+ RCU_CFG0 |= RCU_APB1_CKAHB_DIV1;
234
+
235
+ /* select IRC16M as system clock */
236
+ RCU_CFG0 &= ~RCU_CFG0_SCS;
237
+ RCU_CFG0 |= RCU_CKSYSSRC_IRC16M;
238
+
239
+ /* wait until IRC16M is selected as system clock */
240
+ while(0 != (RCU_CFG0 & RCU_SCSS_IRC16M)){
241
+ }
242
+ }
243
+
244
+ #elif defined (__SYSTEM_CLOCK_HXTAL)
245
+ /*!
246
+ \brief configure the system clock to HXTAL
247
+ \param[in] none
248
+ \param[out] none
249
+ \retval none
250
+ */
251
+ static void system_clock_hxtal(void)
252
+ {
253
+ uint32_t timeout = 0U;
254
+ uint32_t stab_flag = 0U;
255
+
256
+ /* enable HXTAL */
257
+ RCU_CTL |= RCU_CTL_HXTALEN;
258
+
259
+ /* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
260
+ do{
261
+ timeout++;
262
+ stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
263
+ }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
264
+
265
+ /* if fail */
266
+ if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
267
+ while(1){
268
+ }
269
+ }
270
+
271
+ /* AHB = SYSCLK */
272
+ RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
273
+ /* APB2 = AHB */
274
+ RCU_CFG0 |= RCU_APB2_CKAHB_DIV1;
275
+ /* APB1 = AHB */
276
+ RCU_CFG0 |= RCU_APB1_CKAHB_DIV1;
277
+
278
+ /* select HXTAL as system clock */
279
+ RCU_CFG0 &= ~RCU_CFG0_SCS;
280
+ RCU_CFG0 |= RCU_CKSYSSRC_HXTAL;
281
+
282
+ /* wait until HXTAL is selected as system clock */
283
+ while(0 == (RCU_CFG0 & RCU_SCSS_HXTAL)){
284
+ }
285
+ }
286
+
287
+ #elif defined (__SYSTEM_CLOCK_120M_PLL_IRC16M)
288
+ /*!
289
+ \brief configure the system clock to 120M by PLL which selects IRC16M as its clock source
290
+ \param[in] none
291
+ \param[out] none
292
+ \retval none
293
+ */
294
+ static void system_clock_120m_irc16m(void)
295
+ {
296
+ uint32_t timeout = 0U;
297
+ uint32_t stab_flag = 0U;
298
+
299
+ /* enable IRC16M */
300
+ RCU_CTL |= RCU_CTL_IRC16MEN;
301
+
302
+ /* wait until IRC16M is stable or the startup time is longer than IRC16M_STARTUP_TIMEOUT */
303
+ do{
304
+ timeout++;
305
+ stab_flag = (RCU_CTL & RCU_CTL_IRC16MSTB);
306
+ }while((0U == stab_flag) && (IRC16M_STARTUP_TIMEOUT != timeout));
307
+
308
+ /* if fail */
309
+ if(0U == (RCU_CTL & RCU_CTL_IRC16MSTB)){
310
+ while(1){
311
+ }
312
+ }
313
+
314
+ RCU_APB1EN |= RCU_APB1EN_PMUEN;
315
+ PMU_CTL |= PMU_CTL_LDOVS;
316
+
317
+ /* IRC16M is stable */
318
+ /* AHB = SYSCLK */
319
+ RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
320
+ /* APB2 = AHB/2 */
321
+ RCU_CFG0 |= RCU_APB2_CKAHB_DIV2;
322
+ /* APB1 = AHB/4 */
323
+ RCU_CFG0 |= RCU_APB1_CKAHB_DIV4;
324
+
325
+ /* Configure the main PLL, PSC = 16, PLL_N = 240, PLL_P = 2, PLL_Q = 5 */
326
+ RCU_PLL = (16U | (240U << 6U) | (((2U >> 1U) - 1U) << 16U) |
327
+ (RCU_PLLSRC_IRC16M) | (5U << 24U));
328
+
329
+ /* enable PLL */
330
+ RCU_CTL |= RCU_CTL_PLLEN;
331
+
332
+ /* wait until PLL is stable */
333
+ while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
334
+ }
335
+
336
+ /* Enable the high-drive to extend the clock frequency to 120 Mhz */
337
+ PMU_CTL |= PMU_CTL_HDEN;
338
+ while(0U == (PMU_CS & PMU_CS_HDRF)){
339
+ }
340
+
341
+ /* select the high-drive mode */
342
+ PMU_CTL |= PMU_CTL_HDS;
343
+ while(0U == (PMU_CS & PMU_CS_HDSRF)){
344
+ }
345
+
346
+ /* select PLL as system clock */
347
+ RCU_CFG0 &= ~RCU_CFG0_SCS;
348
+ RCU_CFG0 |= RCU_CKSYSSRC_PLLP;
349
+
350
+ /* wait until PLL is selected as system clock */
351
+ while(0U == (RCU_CFG0 & RCU_SCSS_PLLP)){
352
+ }
353
+ }
354
+
355
+ #elif defined (__SYSTEM_CLOCK_120M_PLL_8M_HXTAL)
356
+ /*!
357
+ \brief configure the system clock to 120M by PLL which selects HXTAL(8M) as its clock source
358
+ \param[in] none
359
+ \param[out] none
360
+ \retval none
361
+ */
362
+ static void system_clock_120m_8m_hxtal(void)
363
+ {
364
+ uint32_t timeout = 0U;
365
+ uint32_t stab_flag = 0U;
366
+
367
+ /* enable HXTAL */
368
+ RCU_CTL |= RCU_CTL_HXTALEN;
369
+
370
+ /* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
371
+ do{
372
+ timeout++;
373
+ stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
374
+ }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
375
+
376
+ /* if fail */
377
+ if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
378
+ while(1){
379
+ }
380
+ }
381
+
382
+ RCU_APB1EN |= RCU_APB1EN_PMUEN;
383
+ PMU_CTL |= PMU_CTL_LDOVS;
384
+
385
+ /* HXTAL is stable */
386
+ /* AHB = SYSCLK */
387
+ RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
388
+ /* APB2 = AHB/2 */
389
+ RCU_CFG0 |= RCU_APB2_CKAHB_DIV2;
390
+ /* APB1 = AHB/4 */
391
+ RCU_CFG0 |= RCU_APB1_CKAHB_DIV4;
392
+
393
+ /* Configure the main PLL, PSC = 8, PLL_N = 240, PLL_P = 2, PLL_Q = 5 */
394
+ RCU_PLL = (8U | (240U << 6U) | (((2U >> 1U) - 1U) << 16U) |
395
+ (RCU_PLLSRC_HXTAL) | (5U << 24U));
396
+
397
+ /* enable PLL */
398
+ RCU_CTL |= RCU_CTL_PLLEN;
399
+
400
+ /* wait until PLL is stable */
401
+ while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
402
+ }
403
+
404
+ /* Enable the high-drive to extend the clock frequency to 120 Mhz */
405
+ PMU_CTL |= PMU_CTL_HDEN;
406
+ while(0U == (PMU_CS & PMU_CS_HDRF)){
407
+ }
408
+
409
+ /* select the high-drive mode */
410
+ PMU_CTL |= PMU_CTL_HDS;
411
+ while(0U == (PMU_CS & PMU_CS_HDSRF)){
412
+ }
413
+
414
+ /* select PLL as system clock */
415
+ RCU_CFG0 &= ~RCU_CFG0_SCS;
416
+ RCU_CFG0 |= RCU_CKSYSSRC_PLLP;
417
+
418
+ /* wait until PLL is selected as system clock */
419
+ while(0U == (RCU_CFG0 & RCU_SCSS_PLLP)){
420
+ }
421
+ }
422
+
423
+ #elif defined (__SYSTEM_CLOCK_120M_PLL_25M_HXTAL)
424
+ /*!
425
+ \brief configure the system clock to 120M by PLL which selects HXTAL(25M) as its clock source
426
+ \param[in] none
427
+ \param[out] none
428
+ \retval none
429
+ */
430
+ static void system_clock_120m_25m_hxtal(void)
431
+ {
432
+ uint32_t timeout = 0U;
433
+ uint32_t stab_flag = 0U;
434
+
435
+ /* enable HXTAL */
436
+ RCU_CTL |= RCU_CTL_HXTALEN;
437
+
438
+ /* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
439
+ do{
440
+ timeout++;
441
+ stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
442
+ }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
443
+
444
+ /* if fail */
445
+ if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
446
+ while(1){
447
+ }
448
+ }
449
+
450
+ RCU_APB1EN |= RCU_APB1EN_PMUEN;
451
+ PMU_CTL |= PMU_CTL_LDOVS;
452
+
453
+ /* HXTAL is stable */
454
+ /* AHB = SYSCLK */
455
+ RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
456
+ /* APB2 = AHB/2 */
457
+ RCU_CFG0 |= RCU_APB2_CKAHB_DIV2;
458
+ /* APB1 = AHB/4 */
459
+ RCU_CFG0 |= RCU_APB1_CKAHB_DIV4;
460
+
461
+ /* Configure the main PLL, PSC = 25, PLL_N = 240, PLL_P = 2, PLL_Q = 5 */
462
+ RCU_PLL = (25U | (240U << 6U) | (((2U >> 1U) - 1U) << 16U) |
463
+ (RCU_PLLSRC_HXTAL) | (5U << 24U));
464
+
465
+ /* enable PLL */
466
+ RCU_CTL |= RCU_CTL_PLLEN;
467
+
468
+ /* wait until PLL is stable */
469
+ while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
470
+ }
471
+
472
+ /* Enable the high-drive to extend the clock frequency to 120 Mhz */
473
+ PMU_CTL |= PMU_CTL_HDEN;
474
+ while(0U == (PMU_CS & PMU_CS_HDRF)){
475
+ }
476
+
477
+ /* select the high-drive mode */
478
+ PMU_CTL |= PMU_CTL_HDS;
479
+ while(0U == (PMU_CS & PMU_CS_HDSRF)){
480
+ }
481
+
482
+ /* select PLL as system clock */
483
+ RCU_CFG0 &= ~RCU_CFG0_SCS;
484
+ RCU_CFG0 |= RCU_CKSYSSRC_PLLP;
485
+
486
+ /* wait until PLL is selected as system clock */
487
+ while(0U == (RCU_CFG0 & RCU_SCSS_PLLP)){
488
+ }
489
+ }
490
+
491
+ #elif defined (__SYSTEM_CLOCK_168M_PLL_IRC16M)
492
+ /*!
493
+ \brief configure the system clock to 168M by PLL which selects IRC16M as its clock source
494
+ \param[in] none
495
+ \param[out] none
496
+ \retval none
497
+ */
498
+ static void system_clock_168m_irc16m(void)
499
+ {
500
+ uint32_t timeout = 0U;
501
+ uint32_t stab_flag = 0U;
502
+
503
+ /* enable IRC16M */
504
+ RCU_CTL |= RCU_CTL_IRC16MEN;
505
+
506
+ /* wait until IRC16M is stable or the startup time is longer than IRC16M_STARTUP_TIMEOUT */
507
+ do{
508
+ timeout++;
509
+ stab_flag = (RCU_CTL & RCU_CTL_IRC16MSTB);
510
+ }while((0U == stab_flag) && (IRC16M_STARTUP_TIMEOUT != timeout));
511
+
512
+ /* if fail */
513
+ if(0U == (RCU_CTL & RCU_CTL_IRC16MSTB)){
514
+ while(1){
515
+ }
516
+ }
517
+
518
+ RCU_APB1EN |= RCU_APB1EN_PMUEN;
519
+ PMU_CTL |= PMU_CTL_LDOVS;
520
+
521
+ /* IRC16M is stable */
522
+ /* AHB = SYSCLK */
523
+ RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
524
+ /* APB2 = AHB/2 */
525
+ RCU_CFG0 |= RCU_APB2_CKAHB_DIV2;
526
+ /* APB1 = AHB/4 */
527
+ RCU_CFG0 |= RCU_APB1_CKAHB_DIV4;
528
+
529
+ /* Configure the main PLL, PSC = 16, PLL_N = 336, PLL_P = 2, PLL_Q = 7 */
530
+ RCU_PLL = (16U | (336U << 6U) | (((2U >> 1U) - 1U) << 16U) |
531
+ (RCU_PLLSRC_IRC16M) | (7U << 24U));
532
+
533
+ /* enable PLL */
534
+ RCU_CTL |= RCU_CTL_PLLEN;
535
+
536
+ /* wait until PLL is stable */
537
+ while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
538
+ }
539
+
540
+ /* Enable the high-drive to extend the clock frequency to 168 Mhz */
541
+ PMU_CTL |= PMU_CTL_HDEN;
542
+ while(0U == (PMU_CS & PMU_CS_HDRF)){
543
+ }
544
+
545
+ /* select the high-drive mode */
546
+ PMU_CTL |= PMU_CTL_HDS;
547
+ while(0U == (PMU_CS & PMU_CS_HDSRF)){
548
+ }
549
+
550
+ /* select PLL as system clock */
551
+ RCU_CFG0 &= ~RCU_CFG0_SCS;
552
+ RCU_CFG0 |= RCU_CKSYSSRC_PLLP;
553
+
554
+ /* wait until PLL is selected as system clock */
555
+ while(0U == (RCU_CFG0 & RCU_SCSS_PLLP)){
556
+ }
557
+ }
558
+
559
+ #elif defined (__SYSTEM_CLOCK_168M_PLL_8M_HXTAL)
560
+ /*!
561
+ \brief configure the system clock to 168M by PLL which selects HXTAL(8M) as its clock source
562
+ \param[in] none
563
+ \param[out] none
564
+ \retval none
565
+ */
566
+ static void system_clock_168m_8m_hxtal(void)
567
+ {
568
+ uint32_t timeout = 0U;
569
+
570
+ /* enable HXTAL */
571
+ RCU_CTL |= RCU_CTL_HXTALEN;
572
+
573
+ /* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
574
+ while((0U == (RCU_CTL & RCU_CTL_HXTALSTB)) && (HXTAL_STARTUP_TIMEOUT != timeout++)){
575
+ }
576
+
577
+ /* if fail */
578
+ if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
579
+ while(1){
580
+ }
581
+ }
582
+
583
+ RCU_APB1EN |= RCU_APB1EN_PMUEN;
584
+ PMU_CTL |= PMU_CTL_LDOVS;
585
+ /* HXTAL is stable */
586
+ /* AHB = SYSCLK */
587
+ RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
588
+ /* APB2 = AHB/2 */
589
+ RCU_CFG0 |= RCU_APB2_CKAHB_DIV2;
590
+ /* APB1 = AHB/4 */
591
+ RCU_CFG0 |= RCU_APB1_CKAHB_DIV4;
592
+
593
+ /* Configure the main PLL, PSC = 8, PLL_N = 336, PLL_P = 2, PLL_Q = 7 */
594
+ RCU_PLL = (8U | (336 << 6U) | (((2 >> 1U) -1U) << 16U) |
595
+ (RCU_PLLSRC_HXTAL) | (7 << 24U));
596
+
597
+ /* enable PLL */
598
+ RCU_CTL |= RCU_CTL_PLLEN;
599
+
600
+ /* wait until PLL is stable */
601
+ while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
602
+ }
603
+
604
+ /* Enable the high-drive to extend the clock frequency to 168 Mhz */
605
+ PMU_CTL |= PMU_CTL_HDEN;
606
+ while(0U == (PMU_CS & PMU_CS_HDRF)){
607
+ }
608
+
609
+ /* select the high-drive mode */
610
+ PMU_CTL |= PMU_CTL_HDS;
611
+ while(0U == (PMU_CS & PMU_CS_HDSRF)){
612
+ }
613
+
614
+ /* select PLL as system clock */
615
+ RCU_CFG0 &= ~RCU_CFG0_SCS;
616
+ RCU_CFG0 |= RCU_CKSYSSRC_PLLP;
617
+
618
+ /* wait until PLL is selected as system clock */
619
+ while(0U == (RCU_CFG0 & RCU_SCSS_PLLP)){
620
+ }
621
+ }
622
+
623
+ #elif defined (__SYSTEM_CLOCK_168M_PLL_25M_HXTAL)
624
+ /*!
625
+ \brief configure the system clock to 168M by PLL which selects HXTAL(25M) as its clock source
626
+ \param[in] none
627
+ \param[out] none
628
+ \retval none
629
+ */
630
+ static void system_clock_168m_25m_hxtal(void)
631
+ {
632
+ uint32_t timeout = 0U;
633
+ uint32_t stab_flag = 0U;
634
+
635
+ /* enable HXTAL */
636
+ RCU_CTL |= RCU_CTL_HXTALEN;
637
+
638
+ /* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
639
+ do{
640
+ timeout++;
641
+ stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
642
+ }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
643
+
644
+ /* if fail */
645
+ if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
646
+ while(1){
647
+ }
648
+ }
649
+
650
+ RCU_APB1EN |= RCU_APB1EN_PMUEN;
651
+ PMU_CTL |= PMU_CTL_LDOVS;
652
+
653
+ /* HXTAL is stable */
654
+ /* AHB = SYSCLK */
655
+ RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
656
+ /* APB2 = AHB */
657
+ RCU_CFG0 |= RCU_APB2_CKAHB_DIV2;
658
+ /* APB1 = AHB */
659
+ RCU_CFG0 |= RCU_APB1_CKAHB_DIV4;
660
+
661
+ /* Configure the main PLL, PSC = 25, PLL_N = 336, PLL_P = 2, PLL_Q = 7 */
662
+ RCU_PLL = (25U | (336U << 6U) | (((2U >> 1U) - 1U) << 16U) |
663
+ (RCU_PLLSRC_HXTAL) | (7U << 24U));
664
+
665
+ /* enable PLL */
666
+ RCU_CTL |= RCU_CTL_PLLEN;
667
+
668
+ /* wait until PLL is stable */
669
+ while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
670
+ }
671
+
672
+ /* Enable the high-drive to extend the clock frequency to 168 Mhz */
673
+ PMU_CTL |= PMU_CTL_HDEN;
674
+ while(0U == (PMU_CS & PMU_CS_HDRF)){
675
+ }
676
+
677
+ /* select the high-drive mode */
678
+ PMU_CTL |= PMU_CTL_HDS;
679
+ while(0U == (PMU_CS & PMU_CS_HDSRF)){
680
+ }
681
+
682
+ /* select PLL as system clock */
683
+ RCU_CFG0 &= ~RCU_CFG0_SCS;
684
+ RCU_CFG0 |= RCU_CKSYSSRC_PLLP;
685
+
686
+ /* wait until PLL is selected as system clock */
687
+ while(0U == (RCU_CFG0 & RCU_SCSS_PLLP)){
688
+ }
689
+ }
690
+
691
+ #elif defined (__SYSTEM_CLOCK_200M_PLL_IRC16M)
692
+ /*!
693
+ \brief configure the system clock to 200M by PLL which selects IRC16M as its clock source
694
+ \param[in] none
695
+ \param[out] none
696
+ \retval none
697
+ */
698
+ static void system_clock_200m_irc16m(void)
699
+ {
700
+ uint32_t timeout = 0U;
701
+ uint32_t stab_flag = 0U;
702
+
703
+ /* enable IRC16M */
704
+ RCU_CTL |= RCU_CTL_IRC16MEN;
705
+
706
+ /* wait until IRC16M is stable or the startup time is longer than IRC16M_STARTUP_TIMEOUT */
707
+ do{
708
+ timeout++;
709
+ stab_flag = (RCU_CTL & RCU_CTL_IRC16MSTB);
710
+ }while((0U == stab_flag) && (IRC16M_STARTUP_TIMEOUT != timeout));
711
+
712
+ /* if fail */
713
+ if(0U == (RCU_CTL & RCU_CTL_IRC16MSTB)){
714
+ while(1){
715
+ }
716
+ }
717
+
718
+ RCU_APB1EN |= RCU_APB1EN_PMUEN;
719
+ PMU_CTL |= PMU_CTL_LDOVS;
720
+
721
+ /* IRC16M is stable */
722
+ /* AHB = SYSCLK */
723
+ RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
724
+ /* APB2 = AHB/2 */
725
+ RCU_CFG0 |= RCU_APB2_CKAHB_DIV2;
726
+ /* APB1 = AHB/4 */
727
+ RCU_CFG0 |= RCU_APB1_CKAHB_DIV4;
728
+
729
+ /* Configure the main PLL, PSC = 16, PLL_N = 400, PLL_P = 2, PLL_Q = 9 */
730
+ RCU_PLL = (16U | (400U << 6U) | (((2U >> 1U) - 1U) << 16U) |
731
+ (RCU_PLLSRC_IRC16M) | (9U << 24U));
732
+
733
+ /* enable PLL */
734
+ RCU_CTL |= RCU_CTL_PLLEN;
735
+
736
+ /* wait until PLL is stable */
737
+ while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
738
+ }
739
+
740
+ /* Enable the high-drive to extend the clock frequency to 200 Mhz */
741
+ PMU_CTL |= PMU_CTL_HDEN;
742
+ while(0U == (PMU_CS & PMU_CS_HDRF)){
743
+ }
744
+
745
+ /* select the high-drive mode */
746
+ PMU_CTL |= PMU_CTL_HDS;
747
+ while(0U == (PMU_CS & PMU_CS_HDSRF)){
748
+ }
749
+
750
+ /* select PLL as system clock */
751
+ RCU_CFG0 &= ~RCU_CFG0_SCS;
752
+ RCU_CFG0 |= RCU_CKSYSSRC_PLLP;
753
+
754
+ /* wait until PLL is selected as system clock */
755
+ while(0U == (RCU_CFG0 & RCU_SCSS_PLLP)){
756
+ }
757
+ }
758
+
759
+ #elif defined (__SYSTEM_CLOCK_200M_PLL_8M_HXTAL)
760
+ /*!
761
+ \brief configure the system clock to 200M by PLL which selects HXTAL(8M) as its clock source
762
+ \param[in] none
763
+ \param[out] none
764
+ \retval none
765
+ */
766
+ static void system_clock_200m_8m_hxtal(void)
767
+ {
768
+ uint32_t timeout = 0U;
769
+ uint32_t stab_flag = 0U;
770
+
771
+ /* enable HXTAL */
772
+ RCU_CTL |= RCU_CTL_HXTALEN;
773
+
774
+ /* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
775
+ do{
776
+ timeout++;
777
+ stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
778
+ }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
779
+
780
+ /* if fail */
781
+ if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
782
+ while(1){
783
+ }
784
+ }
785
+
786
+ RCU_APB1EN |= RCU_APB1EN_PMUEN;
787
+ PMU_CTL |= PMU_CTL_LDOVS;
788
+
789
+ /* HXTAL is stable */
790
+ /* AHB = SYSCLK */
791
+ RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
792
+ /* APB2 = AHB/2 */
793
+ RCU_CFG0 |= RCU_APB2_CKAHB_DIV2;
794
+ /* APB1 = AHB/4 */
795
+ RCU_CFG0 |= RCU_APB1_CKAHB_DIV4;
796
+
797
+ /* Configure the main PLL, PSC = 8, PLL_N = 400, PLL_P = 2, PLL_Q = 9 */
798
+ RCU_PLL = (8U | (400U << 6U) | (((2U >> 1U) - 1U) << 16U) |
799
+ (RCU_PLLSRC_HXTAL) | (9U << 24U));
800
+
801
+ /* enable PLL */
802
+ RCU_CTL |= RCU_CTL_PLLEN;
803
+
804
+ /* wait until PLL is stable */
805
+ while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
806
+ }
807
+
808
+ /* Enable the high-drive to extend the clock frequency to 200 Mhz */
809
+ PMU_CTL |= PMU_CTL_HDEN;
810
+ while(0U == (PMU_CS & PMU_CS_HDRF)){
811
+ }
812
+
813
+ /* select the high-drive mode */
814
+ PMU_CTL |= PMU_CTL_HDS;
815
+ while(0U == (PMU_CS & PMU_CS_HDSRF)){
816
+ }
817
+
818
+ /* select PLL as system clock */
819
+ RCU_CFG0 &= ~RCU_CFG0_SCS;
820
+ RCU_CFG0 |= RCU_CKSYSSRC_PLLP;
821
+
822
+ /* wait until PLL is selected as system clock */
823
+ while(0U == (RCU_CFG0 & RCU_SCSS_PLLP)){
824
+ }
825
+ }
826
+
827
+ #elif defined (__SYSTEM_CLOCK_200M_PLL_25M_HXTAL)
828
+ /*!
829
+ \brief configure the system clock to 200M by PLL which selects HXTAL(25M) as its clock source
830
+ \param[in] none
831
+ \param[out] none
832
+ \retval none
833
+ */
834
+ static void system_clock_200m_25m_hxtal(void)
835
+ {
836
+ uint32_t timeout = 0U;
837
+ uint32_t stab_flag = 0U;
838
+
839
+ /* enable HXTAL */
840
+ RCU_CTL |= RCU_CTL_HXTALEN;
841
+
842
+ /* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
843
+ do{
844
+ timeout++;
845
+ stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
846
+ }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
847
+
848
+ /* if fail */
849
+ if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
850
+ while(1){
851
+ }
852
+ }
853
+
854
+ RCU_APB1EN |= RCU_APB1EN_PMUEN;
855
+ PMU_CTL |= PMU_CTL_LDOVS;
856
+
857
+ /* HXTAL is stable */
858
+ /* AHB = SYSCLK */
859
+ RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
860
+ /* APB2 = AHB/2 */
861
+ RCU_CFG0 |= RCU_APB2_CKAHB_DIV2;
862
+ /* APB1 = AHB/4 */
863
+ RCU_CFG0 |= RCU_APB1_CKAHB_DIV4;
864
+
865
+ /* Configure the main PLL, PSC = 25, PLL_N = 400, PLL_P = 2, PLL_Q = 9 */
866
+ RCU_PLL = (25U | (400U << 6U) | (((2U >> 1U) - 1U) << 16U) |
867
+ (RCU_PLLSRC_HXTAL) | (9U << 24U));
868
+
869
+ /* enable PLL */
870
+ RCU_CTL |= RCU_CTL_PLLEN;
871
+
872
+ /* wait until PLL is stable */
873
+ while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
874
+ }
875
+
876
+ /* Enable the high-drive to extend the clock frequency to 200 Mhz */
877
+ PMU_CTL |= PMU_CTL_HDEN;
878
+ while(0U == (PMU_CS & PMU_CS_HDRF)){
879
+ }
880
+
881
+ /* select the high-drive mode */
882
+ PMU_CTL |= PMU_CTL_HDS;
883
+ while(0U == (PMU_CS & PMU_CS_HDSRF)){
884
+ }
885
+
886
+ /* select PLL as system clock */
887
+ RCU_CFG0 &= ~RCU_CFG0_SCS;
888
+ RCU_CFG0 |= RCU_CKSYSSRC_PLLP;
889
+
890
+ /* wait until PLL is selected as system clock */
891
+ while(0U == (RCU_CFG0 & RCU_SCSS_PLLP)){
892
+ }
893
+ }
894
+
895
+ #elif defined (__SYSTEM_CLOCK_240M_PLL_IRC16M)
896
+ /*!
897
+ \brief configure the system clock to 240M by PLL which selects IRC16M as its clock source
898
+ \param[in] none
899
+ \param[out] none
900
+ \retval none
901
+ */
902
+ static void system_clock_240m_irc16m(void)
903
+ {
904
+ uint32_t timeout = 0U;
905
+ uint32_t stab_flag = 0U;
906
+
907
+ /* enable IRC16M */
908
+ RCU_CTL |= RCU_CTL_IRC16MEN;
909
+
910
+ /* wait until IRC16M is stable or the startup time is longer than IRC16M_STARTUP_TIMEOUT */
911
+ do{
912
+ timeout++;
913
+ stab_flag = (RCU_CTL & RCU_CTL_IRC16MSTB);
914
+ }while((0U == stab_flag) && (IRC16M_STARTUP_TIMEOUT != timeout));
915
+
916
+ /* if fail */
917
+ if(0U == (RCU_CTL & RCU_CTL_IRC16MSTB)){
918
+ while(1){
919
+ }
920
+ }
921
+
922
+ RCU_APB1EN |= RCU_APB1EN_PMUEN;
923
+ PMU_CTL |= PMU_CTL_LDOVS;
924
+
925
+ /* IRC16M is stable */
926
+ /* AHB = SYSCLK */
927
+ RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
928
+ /* APB2 = AHB/2 */
929
+ RCU_CFG0 |= RCU_APB2_CKAHB_DIV2;
930
+ /* APB1 = AHB/4 */
931
+ RCU_CFG0 |= RCU_APB1_CKAHB_DIV4;
932
+
933
+ /* Configure the main PLL, PSC = 16, PLL_N = 480, PLL_P = 2, PLL_Q = 10 */
934
+ RCU_PLL = (16U | (480U << 6U) | (((2U >> 1U) - 1U) << 16U) |
935
+ (RCU_PLLSRC_IRC16M) | (10U << 24U));
936
+
937
+ /* enable PLL */
938
+ RCU_CTL |= RCU_CTL_PLLEN;
939
+
940
+ /* wait until PLL is stable */
941
+ while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
942
+ }
943
+
944
+ /* Enable the high-drive to extend the clock frequency to 240 Mhz */
945
+ PMU_CTL |= PMU_CTL_HDEN;
946
+ while(0U == (PMU_CS & PMU_CS_HDRF)){
947
+ }
948
+
949
+ /* select the high-drive mode */
950
+ PMU_CTL |= PMU_CTL_HDS;
951
+ while(0U == (PMU_CS & PMU_CS_HDSRF)){
952
+ }
953
+
954
+ /* select PLL as system clock */
955
+ RCU_CFG0 &= ~RCU_CFG0_SCS;
956
+ RCU_CFG0 |= RCU_CKSYSSRC_PLLP;
957
+
958
+ /* wait until PLL is selected as system clock */
959
+ while(0U == (RCU_CFG0 & RCU_SCSS_PLLP)){
960
+ }
961
+ }
962
+
963
+ #elif defined (__SYSTEM_CLOCK_240M_PLL_8M_HXTAL)
964
+ /*!
965
+ \brief configure the system clock to 240M by PLL which selects HXTAL(8M) as its clock source
966
+ \param[in] none
967
+ \param[out] none
968
+ \retval none
969
+ */
970
+ static void system_clock_240m_8m_hxtal(void)
971
+ {
972
+ uint32_t timeout = 0U;
973
+ uint32_t stab_flag = 0U;
974
+
975
+ /* enable HXTAL */
976
+ RCU_CTL |= RCU_CTL_HXTALEN;
977
+
978
+ /* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
979
+ do{
980
+ timeout++;
981
+ stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
982
+ }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
983
+
984
+ /* if fail */
985
+ if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
986
+ while(1){
987
+ }
988
+ }
989
+
990
+ RCU_APB1EN |= RCU_APB1EN_PMUEN;
991
+ PMU_CTL |= PMU_CTL_LDOVS;
992
+
993
+ /* HXTAL is stable */
994
+ /* AHB = SYSCLK */
995
+ RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
996
+ /* APB2 = AHB/2 */
997
+ RCU_CFG0 |= RCU_APB2_CKAHB_DIV2;
998
+ /* APB1 = AHB/4 */
999
+ RCU_CFG0 |= RCU_APB1_CKAHB_DIV4;
1000
+
1001
+ /* Configure the main PLL, PSC = 8, PLL_N = 480, PLL_P = 2, PLL_Q = 10 */
1002
+ RCU_PLL = (8U | (480U << 6U) | (((2U >> 1U) - 1U) << 16U) |
1003
+ (RCU_PLLSRC_HXTAL) | (10U << 24U));
1004
+
1005
+ /* enable PLL */
1006
+ RCU_CTL |= RCU_CTL_PLLEN;
1007
+
1008
+ /* wait until PLL is stable */
1009
+ while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
1010
+ }
1011
+
1012
+ /* Enable the high-drive to extend the clock frequency to 240 Mhz */
1013
+ PMU_CTL |= PMU_CTL_HDEN;
1014
+ while(0U == (PMU_CS & PMU_CS_HDRF)){
1015
+ }
1016
+
1017
+ /* select the high-drive mode */
1018
+ PMU_CTL |= PMU_CTL_HDS;
1019
+ while(0U == (PMU_CS & PMU_CS_HDSRF)){
1020
+ }
1021
+
1022
+ /* select PLL as system clock */
1023
+ RCU_CFG0 &= ~RCU_CFG0_SCS;
1024
+ RCU_CFG0 |= RCU_CKSYSSRC_PLLP;
1025
+
1026
+ /* wait until PLL is selected as system clock */
1027
+ while(0U == (RCU_CFG0 & RCU_SCSS_PLLP)){
1028
+ }
1029
+ }
1030
+
1031
+ #elif defined (__SYSTEM_CLOCK_240M_PLL_25M_HXTAL)
1032
+ /*!
1033
+ \brief configure the system clock to 240M by PLL which selects HXTAL(25M) as its clock source
1034
+ \param[in] none
1035
+ \param[out] none
1036
+ \retval none
1037
+ */
1038
+ static void system_clock_240m_25m_hxtal(void)
1039
+ {
1040
+ uint32_t timeout = 0U;
1041
+ uint32_t stab_flag = 0U;
1042
+
1043
+ /* enable HXTAL */
1044
+ RCU_CTL |= RCU_CTL_HXTALEN;
1045
+
1046
+ /* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
1047
+ do{
1048
+ timeout++;
1049
+ stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
1050
+ }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
1051
+
1052
+ /* if fail */
1053
+ if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
1054
+ while(1){
1055
+ }
1056
+ }
1057
+
1058
+ RCU_APB1EN |= RCU_APB1EN_PMUEN;
1059
+ PMU_CTL |= PMU_CTL_LDOVS;
1060
+
1061
+ /* HXTAL is stable */
1062
+ /* AHB = SYSCLK */
1063
+ RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
1064
+ /* APB2 = AHB/2 */
1065
+ RCU_CFG0 |= RCU_APB2_CKAHB_DIV2;
1066
+ /* APB1 = AHB/4 */
1067
+ RCU_CFG0 |= RCU_APB1_CKAHB_DIV4;
1068
+
1069
+ /* Configure the main PLL, PSC = 25, PLL_N = 480, PLL_P = 2, PLL_Q = 10 */
1070
+ // RCU_PLL = (25U | (480U << 6U) | (((2U >> 1U) - 1U) << 16U) |
1071
+ // (RCU_PLLSRC_HXTAL) | (10U << 24U));
1072
+ RCU_PLL = (25U | (480U << 6U) | (((2U >> 1U) - 1U) << 16U) |
1073
+ (RCU_PLLSRC_HXTAL) | (10U << 24U));
1074
+
1075
+ /* enable PLL */
1076
+ RCU_CTL |= RCU_CTL_PLLEN;
1077
+
1078
+ /* wait until PLL is stable */
1079
+ while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
1080
+ }
1081
+
1082
+ /* Enable the high-drive to extend the clock frequency to 240 Mhz */
1083
+ PMU_CTL |= PMU_CTL_HDEN;
1084
+ while(0U == (PMU_CS & PMU_CS_HDRF)){
1085
+ }
1086
+
1087
+ /* select the high-drive mode */
1088
+ PMU_CTL |= PMU_CTL_HDS;
1089
+ while(0U == (PMU_CS & PMU_CS_HDSRF)){
1090
+ }
1091
+
1092
+ /* select PLL as system clock */
1093
+ RCU_CFG0 &= ~RCU_CFG0_SCS;
1094
+ RCU_CFG0 |= RCU_CKSYSSRC_PLLP;
1095
+
1096
+ /* wait until PLL is selected as system clock */
1097
+ while(0U == (RCU_CFG0 & RCU_SCSS_PLLP)){
1098
+ }
1099
+ }
1100
+ #endif /* __SYSTEM_CLOCK_IRC16M */
1101
+ /*!
1102
+ \brief update the SystemCoreClock with current core clock retrieved from cpu registers
1103
+ \param[in] none
1104
+ \param[out] none
1105
+ \retval none
1106
+ */
1107
+ void SystemCoreClockUpdate(void)
1108
+ {
1109
+ uint32_t sws;
1110
+ uint32_t pllpsc, plln, pllsel, pllp, ck_src, idx, clk_exp;
1111
+
1112
+ /* exponent of AHB, APB1 and APB2 clock divider */
1113
+ const uint8_t ahb_exp[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
1114
+
1115
+ sws = GET_BITS(RCU_CFG0, 2, 3);
1116
+ switch(sws){
1117
+ /* IRC16M is selected as CK_SYS */
1118
+ case SEL_IRC16M:
1119
+ SystemCoreClock = IRC16M_VALUE;
1120
+ break;
1121
+ /* HXTAL is selected as CK_SYS */
1122
+ case SEL_HXTAL:
1123
+ SystemCoreClock = HXTAL_VALUE;
1124
+ break;
1125
+ /* PLLP is selected as CK_SYS */
1126
+ case SEL_PLLP:
1127
+ /* get the value of PLLPSC[5:0] */
1128
+ pllpsc = GET_BITS(RCU_PLL, 0U, 5U);
1129
+ plln = GET_BITS(RCU_PLL, 6U, 14U);
1130
+ pllp = (GET_BITS(RCU_PLL, 16U, 17U) + 1U) * 2U;
1131
+ /* PLL clock source selection, HXTAL or IRC8M/2 */
1132
+ pllsel = (RCU_PLL & RCU_PLL_PLLSEL);
1133
+ if (RCU_PLLSRC_HXTAL == pllsel) {
1134
+ ck_src = HXTAL_VALUE;
1135
+ } else {
1136
+ ck_src = IRC16M_VALUE;
1137
+ }
1138
+ SystemCoreClock = ((ck_src / pllpsc) * plln) / pllp;
1139
+ break;
1140
+ /* IRC16M is selected as CK_SYS */
1141
+ default:
1142
+ SystemCoreClock = IRC16M_VALUE;
1143
+ break;
1144
+ }
1145
+ /* calculate AHB clock frequency */
1146
+ idx = GET_BITS(RCU_CFG0, 4, 7);
1147
+ clk_exp = ahb_exp[idx];
1148
+ SystemCoreClock = SystemCoreClock >> clk_exp;
1149
+ }
deployment/GD32F470I_BluePill_ARMCC/ARM/System/system_gd32f4xx.h ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ \file system_gd32f4xx.h
3
+ \brief CMSIS Cortex-M4 Device Peripheral Access Layer Header File for
4
+ GD32F4xx Device Series
5
+ */
6
+
7
+ /* Copyright (c) 2012 ARM LIMITED
8
+
9
+ All rights reserved.
10
+ Redistribution and use in source and binary forms, with or without
11
+ modification, are permitted provided that the following conditions are met:
12
+ - Redistributions of source code must retain the above copyright
13
+ notice, this list of conditions and the following disclaimer.
14
+ - Redistributions in binary form must reproduce the above copyright
15
+ notice, this list of conditions and the following disclaimer in the
16
+ documentation and/or other materials provided with the distribution.
17
+ - Neither the name of ARM nor the names of its contributors may be used
18
+ to endorse or promote products derived from this software without
19
+ specific prior written permission.
20
+ *
21
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
+ ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
25
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
+ POSSIBILITY OF SUCH DAMAGE.
32
+ ---------------------------------------------------------------------------*/
33
+
34
+ /* This file refers the CMSIS standard, some adjustments are made according to GigaDevice chips */
35
+
36
+ #ifndef SYSTEM_GD32F4XX_H
37
+ #define SYSTEM_GD32F4XX_H
38
+
39
+ #ifdef __cplusplus
40
+ extern "C" {
41
+ #endif
42
+
43
+ #include <stdint.h>
44
+
45
+ /* system clock frequency (core clock) */
46
+ extern uint32_t SystemCoreClock;
47
+
48
+ /* function declarations */
49
+ /* initialize the system and update the SystemCoreClock variable */
50
+ extern void SystemInit (void);
51
+ /* update the SystemCoreClock with current core clock retrieved from cpu registers */
52
+ extern void SystemCoreClockUpdate (void);
53
+
54
+ #ifdef __cplusplus
55
+ }
56
+ #endif
57
+
58
+ #endif /* SYSTEM_GD32F4XX_H */
deployment/GD32F470I_BluePill_ARMCC/App/Beep/Beep.c ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�LED.c
3
+ * ժ Ҫ��LEDģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�SZLY(COPYRIGHT 2018 - 2020 SZLY. All rights reserved.)
6
+ * ������ڣ�2020��01��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+
17
+ /*********************************************************************************************************
18
+ * ����ͷ�ļ�
19
+ *********************************************************************************************************/
20
+ #include "Beep.h"
21
+ #include "SysTick.h"
22
+
23
+ /*********************************************************************************************************
24
+ * �궨��
25
+ *********************************************************************************************************/
26
+
27
+ /*********************************************************************************************************
28
+ * ö�ٽṹ��
29
+ *********************************************************************************************************/
30
+
31
+ /*********************************************************************************************************
32
+ * �ڲ�����
33
+ *********************************************************************************************************/
34
+ static i32 s_iBeepTimeCnt = 0;
35
+
36
+ /*********************************************************************************************************
37
+ * �ڲ���������
38
+ *********************************************************************************************************/
39
+ static void ConfigBeepGPIO(void);
40
+
41
+ /*********************************************************************************************************
42
+ * �ڲ�����ʵ��
43
+ *********************************************************************************************************/
44
+ /*********************************************************************************************************
45
+ * �������ƣ�ConfigBeepGPIO
46
+ * �������ܣ�����BEEP��GPIO
47
+ * ���������void
48
+ * ���������void
49
+ * �� �� ֵ��void
50
+ * �������ڣ�2018��01��01��
51
+ * ע �⣺
52
+ *********************************************************************************************************/
53
+ static void ConfigBeepGPIO(void)
54
+ {
55
+ rcu_periph_clock_enable(RCU_GPIOI); //ʹ��GPIOI��ʱ��
56
+ gpio_mode_set(GPIOI, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_11); //�������
57
+ gpio_output_options_set(GPIOI, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_11); //�������
58
+ gpio_bit_reset(GPIOI, GPIO_PIN_11); //Ϩ��LED2
59
+ }
60
+
61
+ /*********************************************************************************************************
62
+ * API����ʵ��
63
+ *********************************************************************************************************/
64
+ /*********************************************************************************************************
65
+ * �������ƣ�InitBeep
66
+ * �������ܣ���ʼ��������
67
+ * ���������void
68
+ * ���������void
69
+ * �� �� ֵ��void
70
+ * �������ڣ�2018��01��01��
71
+ * ע �⣺
72
+ *********************************************************************************************************/
73
+ void InitBeep(void)
74
+ {
75
+ ConfigBeepGPIO();
76
+ s_iBeepTimeCnt = 0;
77
+ }
78
+
79
+ /*********************************************************************************************************
80
+ * ��������: BeepWithTime
81
+ * ��������: ����������һ��ʱ��
82
+ * �������: time-ʱ��
83
+ * �������: void
84
+ * �� �� ֵ: void
85
+ * ��������: 2018��01��01��
86
+ * ע ��:
87
+ *********************************************************************************************************/
88
+ void BeepWithTime(u16 time)
89
+ {
90
+ s_iBeepTimeCnt = time;
91
+ }
92
+
93
+ /*********************************************************************************************************
94
+ * ��������: BeepCalcDown
95
+ * ��������: �������������
96
+ * �������: time������ʱ������ms��
97
+ * �������: void
98
+ * �� �� ֵ: void
99
+ * ��������: 2013��12��11��
100
+ * ע ��:
101
+ *********************************************************************************************************/
102
+ void BeepCalcDown(u32 time)
103
+ {
104
+ if(s_iBeepTimeCnt > 0)
105
+ {
106
+ BEEP_ON
107
+ s_iBeepTimeCnt = s_iBeepTimeCnt - time;
108
+ }
109
+ else
110
+ {
111
+ BEEP_OFF
112
+ }
113
+ }
deployment/GD32F470I_BluePill_ARMCC/App/Beep/Beep.h ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�Beep.h
3
+ * ժ Ҫ������������ģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�SZLY(COPYRIGHT 2018 - 2020 SZLY. All rights reserved.)
6
+ * ������ڣ�2020��01��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+ #ifndef _BEEP_H_
17
+ #define _BEEP_H_
18
+
19
+ /*********************************************************************************************************
20
+ * ����ͷ�ļ�
21
+ *********************************************************************************************************/
22
+ #include "DataType.h"
23
+ #include "gd32f470x_conf.h"
24
+
25
+ /*********************************************************************************************************
26
+ * �궨��
27
+ *********************************************************************************************************/
28
+ #define BEEP_ON gpio_bit_set(GPIOI, GPIO_PIN_11); //��������
29
+ #define BEEP_OFF gpio_bit_reset(GPIOI, GPIO_PIN_11); //�������ر�
30
+
31
+ /*********************************************************************************************************
32
+ * �ṹ�嶨��
33
+ *********************************************************************************************************/
34
+
35
+ /*********************************************************************************************************
36
+ * API��������
37
+ *********************************************************************************************************/
38
+ void InitBeep(void);
39
+ void BeepWithTime(u16 time);
40
+ void BeepCalcDown(u32 time);
41
+
42
+ #endif
43
+
44
+
deployment/GD32F470I_BluePill_ARMCC/App/Camera/Camera.c ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�Camera.c
3
+ * ժ Ҫ������ͷģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+
17
+ /*********************************************************************************************************
18
+ * ����ͷ�ļ�
19
+ *********************************************************************************************************/
20
+ #include "Camera.h"
21
+ #include "GUITop.h"
22
+ #include "stdio.h"
23
+ #include "TLILCD.h"
24
+ #include "OV2640.h"
25
+ #include "SysTick.h"
26
+
27
+ #include "Beep.h"
28
+ #include "DCI.h"
29
+
30
+ #include "FontLib.h"
31
+
32
+
33
+ /*********************************************************************************************************
34
+ * �궨��
35
+ *********************************************************************************************************/
36
+ //�ַ�����ʾ���
37
+ #define STRING_MAX_LEN (64) //��ʾ�ַ���󳤶�
38
+ #define STRIGN_X0 (105) //��ʾ�ַ����������
39
+ #define STRING_Y0 (747) //��ʾ�ַ����������
40
+ #define STRING_X1 (373) //��ʾ�ַ��������յ�
41
+ #define STRING_SIZE (24) //�����С
42
+
43
+ //��Ƭ���
44
+ #define IMAGE_X0 (116)
45
+ #define IMAGE_Y0 (195)
46
+
47
+ #define IMAGE_SIZE (IMAGE_WIDTH * IMAGE_HEIGHT * 2)
48
+
49
+ /*********************************************************************************************************
50
+ * ö�ٽṹ��
51
+ *********************************************************************************************************/
52
+
53
+ /*********************************************************************************************************
54
+ * �ڲ�����
55
+ *********************************************************************************************************/
56
+ static u32 s_iImageFrameAdd = NULL; //ͼ��֡�׵�ַ
57
+ //static StructRadioWidget s_arrRadio[GUI_RADIO_MAX]; //��ѡ�ؼ�
58
+
59
+ static u8* s_pStringBackground = NULL; //�ַ�����ʾ����������
60
+ //static EnumGUIRadio s_enumRadio = GUI_RADIO_NONE; //��ǰѡ�еĿؼ�
61
+
62
+ static StructGUIDev s_structGUIDev; //GUI�豸�ṹ��
63
+ static char s_arrStringBuf[64]; //�ַ���ת��������
64
+
65
+ //6�ֹ���ģʽ����ƽ�⣩
66
+ const char* s_arrLmodeTable[5] = {"�Զ�", "����", "����", "�칫��", "����"};
67
+
68
+ //7����Ч
69
+ const char* s_arrEffectTable[7] = {"����", "��Ƭ", "�ڰ�", "ƫ��", "ƫ��", "ƫ��", "����"};
70
+
71
+ //����ͷ����
72
+ static i32 s_iLightMode = 0; //��ƽ�⣨0-4��
73
+ static i32 s_iColorSaturation = 0; //ɫ�ȣ�-2~+2��
74
+ static i32 s_iBrightness = 0; //���ȣ�-2~+2��
75
+ static i32 s_iContrast = 0; //�Աȶȣ�-2~+2��
76
+ static i32 s_iEffects = 0; //����0-6��
77
+
78
+ /*********************************************************************************************************
79
+ * �ڲ�����ʵ��
80
+ *********************************************************************************************************/
81
+
82
+
83
+
84
+ /*********************************************************************************************************
85
+ * �������ƣ�TakePhotoCallback
86
+ * �������ܣ����ջص�����
87
+ * ���������button���ؼ��׵�ַ
88
+ * ���������void
89
+ * �� �� ֵ��void
90
+ * �������ڣ�2021��07��01��
91
+ * ע �⣺
92
+ *********************************************************************************************************/
93
+ static void TakePhotoCallback(void)
94
+ {
95
+ //����������100ms
96
+ BeepWithTime(100);
97
+
98
+ //��ȡ��Ļͼ�񲢱��浽SD��
99
+
100
+ }
101
+ /*********************************************************************************************************
102
+ * API����ʵ��
103
+ *********************************************************************************************************/
104
+ /*********************************************************************************************************
105
+ * �������ƣ�InitCamera
106
+ * �������ܣ���ʼ������ͷģ��
107
+ * ���������void
108
+ * ���������void
109
+ * �� �� ֵ��void
110
+ * �������ڣ�2021��07��01��
111
+ * ע �⣺
112
+ *********************************************************************************************************/
113
+ void InitCamera(void)
114
+ {
115
+ //��ʼ������ͷ����
116
+ s_iLightMode = 0;
117
+ s_iColorSaturation = 0;
118
+ s_iBrightness = 0;
119
+ s_iContrast = 0;
120
+ s_iEffects = 0;
121
+
122
+ //��ʼ������ͷ
123
+ if(InitOV2640() == 0)
124
+ {
125
+ //����OV2640
126
+ DelayNms(50);
127
+ OV2640RGB565Mode();
128
+ OV2640OutSizeSet(IMAGE_WIDTH, IMAGE_HEIGHT);
129
+ OV2640AutoExposure(0);
130
+ OV2640LightMode(s_iLightMode);
131
+ OV2640ColorSaturation(s_iColorSaturation);
132
+ OV2640Brightness(s_iBrightness);
133
+ OV2640Contrast(s_iContrast);
134
+ OV2640SpecialEffects(s_iEffects);
135
+
136
+ //����ͼ���Դ��ַΪǰ�����׵�ַ
137
+ s_iImageFrameAdd = g_structTLILCDDev.foreFrameAddr;
138
+ //����DCI
139
+ InitDCI(s_iImageFrameAdd, IMAGE_SIZE, IMAGE_X0, IMAGE_Y0, IMAGE_WIDTH, IMAGE_HEIGHT, 0);
140
+ }
141
+ else
142
+ {
143
+ LCDShowString(30, 210, 200, 16, LCD_FONT_16,LCD_TEXT_NORMAL,LCD_COLOR_BLUE,LCD_COLOR_BLACK,"OV2640 Error!!");
144
+ while(1);
145
+ }
146
+ }
147
+
148
+ /*********************************************************************************************************
149
+ * �������ƣ�CameraTask
150
+ * �������ܣ�����ͷģ������
151
+ * ���������void
152
+ * ���������void
153
+ * �� �� ֵ��void
154
+ * �������ڣ�2021��07��01��
155
+ * ע �⣺
156
+ *********************************************************************************************************/
157
+ void CameraTask(void)
158
+ {
159
+ //GUI����
160
+
161
+ //��ʾһ֡ͼ�ε���Ļ��
162
+ DCIShowImage();
163
+ }
deployment/GD32F470I_BluePill_ARMCC/App/Camera/Camera.h ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�Camera.h
3
+ * ժ Ҫ������ͷģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+ #ifndef _CAMERA_H_
17
+ #define _CAMERA_H_
18
+
19
+ /*********************************************************************************************************
20
+ * ����ͷ�ļ�
21
+ *********************************************************************************************************/
22
+ #include "DataType.h"
23
+
24
+
25
+ /*********************************************************************************************************
26
+ * �궨��
27
+ *********************************************************************************************************/
28
+ #define IMAGE_WIDTH (256)
29
+ #define IMAGE_HEIGHT (256)
30
+ /*********************************************************************************************************
31
+ * ö�ٽṹ��
32
+ *********************************************************************************************************/
33
+
34
+ /*********************************************************************************************************
35
+ * API��������
36
+ *********************************************************************************************************/
37
+ void InitCamera(void); //��ʼ������ͷģ��
38
+ void CameraTask(void); //����ͷģ������
39
+
40
+ #endif
deployment/GD32F470I_BluePill_ARMCC/App/Camera/DCI.c ADDED
@@ -0,0 +1,341 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�DCI.c
3
+ * ժ Ҫ����������ͷ�ӿ�����ģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+
17
+ /*********************************************************************************************************
18
+ * ����ͷ�ļ�
19
+ *********************************************************************************************************/
20
+ #include "DCI.h"
21
+ #include "gd32f470x_conf.h"
22
+ #include "stdio.h"
23
+ #include "TLILCD.h"
24
+
25
+ /*********************************************************************************************************
26
+ * �궨��
27
+ *********************************************************************************************************/
28
+ #define DCI_DR_ADDRESS (0x50050028U)
29
+ #define DCI_TIMEOUT 20000
30
+
31
+ /*********************************************************************************************************
32
+ * ö�ٽṹ��
33
+ *********************************************************************************************************/
34
+
35
+ /*********************************************************************************************************
36
+ * �ڲ�����
37
+ *********************************************************************************************************/
38
+ u32 s_iFrameAddr, s_iFrameSize; //֡��ַ�Լ�֡��С
39
+ u32 s_iX0, s_iY0, s_iWidth, s_iHeight; //ͼ����ʾ��Ϣ
40
+ u32 s_iMode; //��ʾģʽ��0-ֱ�Ӽ��ص��Դ棬1-���ص���ʱ������������ʾ
41
+ u32 s_iGetFrameFlag; //���1֡ͼ���־λ
42
+
43
+ /*********************************************************************************************************
44
+ * �ڲ���������
45
+ *********************************************************************************************************/
46
+ static void ConfigDCIGPIO(void); //��ʼ��DCI��GPIO
47
+ static void ConfigCKOut0(void); //����CKOut0���
48
+ void ConfigDCI(void); //����DCI
49
+
50
+ /*********************************************************************************************************
51
+ * �ڲ�����ʵ��
52
+ *********************************************************************************************************/
53
+ /*********************************************************************************************************
54
+ * �������ƣ�ConfigDCIGPIO
55
+ * �������ܣ���ʼ��DCI��GPIO
56
+ * ���������void
57
+ * ���������void
58
+ * �� �� ֵ��void
59
+ * �������ڣ�2021��07��01��
60
+ * ע �⣺
61
+ *********************************************************************************************************/
62
+ static void ConfigDCIGPIO(void)
63
+ {
64
+ //ʹ��RCC���ʱ��
65
+ rcu_periph_clock_enable(RCU_DCI); //ʹ��DCIʱ��
66
+ rcu_periph_clock_enable(RCU_GPIOA); //ʹ��GPIOA��ʱ��
67
+ rcu_periph_clock_enable(RCU_GPIOB); //ʹ��GPIOB��ʱ��
68
+ rcu_periph_clock_enable(RCU_GPIOC); //ʹ��GPIOC��ʱ��
69
+ rcu_periph_clock_enable(RCU_GPIOD); //ʹ��GPIOD��ʱ��
70
+ rcu_periph_clock_enable(RCU_GPIOH); //ʹ��GPIOH��ʱ��
71
+ rcu_periph_clock_enable(RCU_GPIOI); //ʹ��GPIOI��ʱ��
72
+
73
+ //DCI D0
74
+ gpio_af_set(GPIOH, GPIO_AF_13, GPIO_PIN_9);
75
+ gpio_mode_set(GPIOH, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_9);
76
+ gpio_output_options_set(GPIOH, GPIO_OTYPE_PP, GPIO_OSPEED_MAX, GPIO_PIN_9);
77
+
78
+ //DCI D1
79
+ gpio_af_set(GPIOC, GPIO_AF_13, GPIO_PIN_7);
80
+ gpio_mode_set(GPIOC, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_7);
81
+ gpio_output_options_set(GPIOC, GPIO_OTYPE_PP, GPIO_OSPEED_MAX, GPIO_PIN_7);
82
+
83
+ //DCI D2
84
+ gpio_af_set(GPIOC, GPIO_AF_13, GPIO_PIN_8);
85
+ gpio_mode_set(GPIOC, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_8);
86
+ gpio_output_options_set(GPIOC, GPIO_OTYPE_PP, GPIO_OSPEED_MAX, GPIO_PIN_8);
87
+
88
+ //DCI D3
89
+ gpio_af_set(GPIOH, GPIO_AF_13, GPIO_PIN_12);
90
+ gpio_mode_set(GPIOH, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_12);
91
+ gpio_output_options_set(GPIOH, GPIO_OTYPE_PP, GPIO_OSPEED_MAX, GPIO_PIN_12);
92
+
93
+ //DCI D4
94
+ gpio_af_set(GPIOH, GPIO_AF_13, GPIO_PIN_14);
95
+ gpio_mode_set(GPIOH, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_14);
96
+ gpio_output_options_set(GPIOH, GPIO_OTYPE_PP, GPIO_OSPEED_MAX, GPIO_PIN_14);
97
+
98
+ //DCI D5
99
+ gpio_af_set(GPIOD, GPIO_AF_13, GPIO_PIN_3);
100
+ gpio_mode_set(GPIOD, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_3);
101
+ gpio_output_options_set(GPIOD, GPIO_OTYPE_PP, GPIO_OSPEED_MAX, GPIO_PIN_3);
102
+
103
+ //DCI D6
104
+ gpio_af_set(GPIOI, GPIO_AF_13, GPIO_PIN_6);
105
+ gpio_mode_set(GPIOI, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_6);
106
+ gpio_output_options_set(GPIOI, GPIO_OTYPE_PP, GPIO_OSPEED_MAX, GPIO_PIN_6);
107
+
108
+ //DCI D7
109
+ gpio_af_set(GPIOI, GPIO_AF_13, GPIO_PIN_7);
110
+ gpio_mode_set(GPIOI, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_7);
111
+ gpio_output_options_set(GPIOI, GPIO_OTYPE_PP, GPIO_OSPEED_MAX, GPIO_PIN_7);
112
+
113
+ //DCI VSYNC
114
+ gpio_af_set(GPIOI, GPIO_AF_13, GPIO_PIN_5);
115
+ gpio_mode_set(GPIOI, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_5);
116
+ gpio_output_options_set(GPIOI, GPIO_OTYPE_PP, GPIO_OSPEED_MAX, GPIO_PIN_5);
117
+
118
+ //DCI HSYNC
119
+ gpio_af_set(GPIOA, GPIO_AF_13, GPIO_PIN_4);
120
+ gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_4);
121
+ gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_MAX, GPIO_PIN_4);
122
+
123
+ //DCI PIXCLK
124
+ gpio_af_set(GPIOA, GPIO_AF_13, GPIO_PIN_6);
125
+ gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_6);
126
+ gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_MAX, GPIO_PIN_6);
127
+ }
128
+
129
+ /*********************************************************************************************************
130
+ * �������ƣ�ConfigCKOut0
131
+ * �������ܣ�����CKOut0���
132
+ * ���������void
133
+ * ���������void
134
+ * �� �� ֵ��void
135
+ * �������ڣ�2021��07��01��
136
+ * ע �⣺
137
+ *********************************************************************************************************/
138
+ static void ConfigCKOut0(void)
139
+ {
140
+ rcu_periph_clock_enable(RCU_GPIOA);
141
+ gpio_af_set(GPIOA, GPIO_AF_0, GPIO_PIN_8);
142
+ gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_8);
143
+ gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_MAX,GPIO_PIN_8);
144
+ rcu_ckout0_config(RCU_CKOUT0SRC_HXTAL, RCU_CKOUT0_DIV3);
145
+ }
146
+
147
+ /*********************************************************************************************************
148
+ * �������ƣ�ConfigDCI
149
+ * �������ܣ�����DCI
150
+ * ���������frameAddr��ͼ��֡�����ַ��frameSize��1֡ͼ���С�����ֽڼ��㣩
151
+ * ���������void
152
+ * �� �� ֵ��void
153
+ * �������ڣ�2021��07��01��
154
+ * ע �⣺Ҫ����DCI��������жϲ�����������DCI��ֱ�ӹҵ�������
155
+ *********************************************************************************************************/
156
+ void ConfigDCI(void)
157
+ {
158
+ dci_parameter_struct dci_struct;
159
+ dma_single_data_parameter_struct dma_single_struct;
160
+
161
+ //ʹ��RCC���ʱ��
162
+ rcu_periph_clock_enable(RCU_DCI); //ʹ��DCIʱ��
163
+ rcu_periph_clock_enable(RCU_DMA1); //ʹ��DMA1ʱ��
164
+
165
+ //DCI����
166
+ dci_deinit(); //��λDCI
167
+ if(0 == s_iMode)
168
+ {
169
+ dci_struct.capture_mode = DCI_CAPTURE_MODE_CONTINUOUS; //��������ģʽ��������ͼ������ֱ�ӱ��浽LCD�Դ�
170
+ }
171
+ else
172
+ {
173
+ dci_struct.capture_mode = DCI_CAPTURE_MODE_SNAPSHOT; //ʹ�ÿ���ģʽ��ͨ�����㺯����ͼ����ʾ��LCD��
174
+ }
175
+ dci_struct.clock_polarity = DCI_CK_POLARITY_RISING; //ʱ�Ӽ���ѡ��
176
+ dci_struct.hsync_polarity = DCI_HSYNC_POLARITY_LOW; //ˮƽͬ������ѡ��
177
+ dci_struct.vsync_polarity = DCI_VSYNC_POLARITY_LOW; //��ֱͬ������ѡ��
178
+ dci_struct.frame_rate = DCI_FRAME_RATE_ALL; //��������֡
179
+ dci_struct.interface_format = DCI_INTERFACE_FORMAT_8BITS; //ÿ������ʱ�Ӳ��� 8 λ����
180
+ dci_init(&dci_struct); //���ݲ�������DCI
181
+ nvic_irq_enable(DCI_IRQn, 2, 0); //ʹ��DCI NVIC�ж�
182
+ dci_interrupt_enable(DCI_INT_OVR); //ʹ��DCI FIFO����жϣ��dz���Ҫ��������
183
+ dci_interrupt_flag_clear(DCI_INT_OVR); //�������жϱ�־λ
184
+ if(0 != s_iMode)
185
+ {
186
+ dci_interrupt_enable(DCI_INT_EF); //֡�����ж�ʹ�ܣ����Ի���һ֡ͼ��LCD�ϲ�������һ�β���
187
+ dci_interrupt_flag_clear(DCI_INT_EF); //���֡�����жϱ�־λ
188
+ }
189
+
190
+ //DMA����
191
+ dma_deinit(DMA1, DMA_CH7); //��λDMA
192
+ dma_single_struct.periph_addr = (u32)&DCI_DATA; //���������ַ
193
+ dma_single_struct.memory0_addr = (u32)s_iFrameAddr; //���ô洢����ַ
194
+ dma_single_struct.direction = DMA_PERIPH_TO_MEMORY; //���䷽��Ϊ���赽�ڴ�
195
+ dma_single_struct.number = s_iFrameSize / 4; //����������
196
+ dma_single_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE; //��ֹ�����ַ����
197
+ dma_single_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE; //�����ڴ��ַ����
198
+ dma_single_struct.periph_memory_width = DMA_PERIPH_WIDTH_32BIT; //�������ݿ���Ϊ32λ
199
+ dma_single_struct.priority = DMA_PRIORITY_ULTRA_HIGH; //�߳����ȼ�
200
+ if(0 == s_iMode)
201
+ {
202
+ dma_single_struct.circular_mode = DMA_CIRCULAR_MODE_ENABLE; //DCI��������ģʽ�¿���ѭ��ģʽ
203
+ }
204
+ else
205
+ {
206
+ dma_single_struct.circular_mode = DMA_CIRCULAR_MODE_DISABLE; //DCI����ģʽ�½���ѭ��ģʽ
207
+ }
208
+ dma_single_data_mode_init(DMA1, DMA_CH7, &dma_single_struct); //���ݲ�������DMAͨ��
209
+ dma_channel_subperipheral_select(DMA1, DMA_CH7, DMA_SUBPERI1); //��DMAͨ������Ӧ����
210
+ dma_flow_controller_config(DMA1, DMA_CH7, DMA_FLOW_CONTROLLER_DMA); //DMA�����������
211
+ dma_channel_enable(DMA1, DMA_CH7); //ʹ��DMA����
212
+
213
+ dci_enable(); //ʹ��DCI
214
+ dci_capture_enable(); //��������
215
+ }
216
+
217
+ /*********************************************************************************************************
218
+ * �������ƣ�DCI_IRQHandler
219
+ * �������ܣ�DCI�жϷ�����
220
+ * ���������void
221
+ * ���������void
222
+ * �� �� ֵ��void
223
+ * �������ڣ�2021��07��01��
224
+ * ע �⣺
225
+ *********************************************************************************************************/
226
+ void DCI_IRQHandler(void)
227
+ {
228
+ //֡����
229
+ if(SET == dci_interrupt_flag_get(DCI_INT_FLAG_EF))
230
+ {
231
+ //��ǻ��1֡����
232
+ s_iGetFrameFlag = 1;
233
+
234
+ //����жϱ�־λ
235
+ dci_interrupt_flag_clear(DCI_INT_EF);
236
+ }
237
+
238
+ //FIFO�����������������ǰ֡��ֱ�ӿ�����һ֡ͼ����
239
+ if(SET == dci_interrupt_flag_get(DCI_INT_FLAG_OVR))
240
+ {
241
+ dci_interrupt_flag_clear(DCI_INT_OVR);
242
+ ConfigDCI();
243
+ }
244
+ }
245
+
246
+ /*********************************************************************************************************
247
+ * API����ʵ��
248
+ *********************************************************************************************************/
249
+ /*********************************************************************************************************
250
+ * �������ƣ�InitDCI
251
+ * �������ܣ���ʼ����������ͷ�ӿ�����ģ��
252
+ * ���������frameAddr��ͼ��֡�����ַ���������ڲ�SRAM��Ҳ�������ⲿSDRAM
253
+ * frameSize��1֡ͼ���С�����ֽڼ��㣩
254
+ * x0��Y0��ͼ����ʾ��㣬mode����ʱʹ��
255
+ * width��heigh��ͼ���С��mode����ʱʹ��
256
+ * mode��0-�Ƽ�����ʱʹ�ã�����DMAֱ�ӽ�DCI���յ������ݴ��䵽�Դ棬���������ڴ�ռ䣬ˢ���ٶȿ�
257
+ * 1-��DCI���յ������ݱ��浽��ʱ��������Ȼ����ͨ�����㺯����һ֡ͼ����Ƴ������ٶȽ���
258
+ * ���������void
259
+ * �� �� ֵ��void
260
+ * �������ڣ�2021��07��01��
261
+ * ע �⣺����ʱ�Ƽ�����˫����ʾ��ѡ��ģʽ0��DMAֱ�ӽ����ݴ��䵽�Դ棬�������ˢ����
262
+ *********************************************************************************************************/
263
+ void InitDCI(u32 frameAddr, u32 frameSize, u32 x0, u32 y0, u32 width, u32 height, u32 mode)
264
+ {
265
+ //�������
266
+ s_iFrameAddr = frameAddr;
267
+ s_iFrameSize = frameSize;
268
+ s_iX0 = x0;
269
+ s_iY0 = y0;
270
+ s_iWidth = width;
271
+ s_iHeight = height;
272
+ s_iMode = mode;
273
+
274
+ //����DCI��GPIO
275
+ ConfigDCIGPIO();
276
+
277
+ //����CK_OUT0���
278
+ ConfigCKOut0();
279
+
280
+ //����DCI����
281
+ s_iGetFrameFlag = 0;
282
+ ConfigDCI();
283
+ }
284
+
285
+ /*********************************************************************************************************
286
+ * �������ƣ�DeInitDCI
287
+ * �������ܣ�ע����������ͷ�ӿ�����ģ��
288
+ * ���������void
289
+ * ���������void
290
+ * �� �� ֵ��void
291
+ * �������ڣ�2021��07��01��
292
+ * ע �⣺
293
+ *********************************************************************************************************/
294
+ void DeInitDCI(void)
295
+ {
296
+ //�ر�DMA����
297
+ dma_channel_disable(DMA1, DMA_CH7);
298
+
299
+ //��λDCI
300
+ dci_deinit();
301
+
302
+ //��ֹDCI_XCLK���
303
+ gpio_mode_set(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, GPIO_PIN_8);
304
+ }
305
+
306
+ /*********************************************************************************************************
307
+ * �������ƣ�DCIShowImage
308
+ * �������ܣ���ʾһ֡ͼ����Ļ��
309
+ * ���������void
310
+ * ���������void
311
+ * �� �� ֵ��void
312
+ * �������ڣ�2021��07��01��
313
+ * ע �⣺
314
+ *********************************************************************************************************/
315
+ void DCIShowImage(void)
316
+ {
317
+ u32 x0, y0, x1, y1, x, y, i;
318
+ u16* frame;
319
+
320
+ if((0 != s_iMode) && (1 == s_iGetFrameFlag))
321
+ {
322
+ //��һ֡ͼ����ʾ����Ļ��
323
+ x0 = s_iX0;
324
+ y0 = s_iY0;
325
+ x1 = x0 + s_iWidth - 1;
326
+ y1 = y0 + s_iHeight - 1;
327
+ i = 0;
328
+ frame = (u16*)s_iFrameAddr;
329
+ for(y = y0; y <= y1; y++)
330
+ {
331
+ for(x = x0; x <= x1; x++)
332
+ {
333
+ LCDDrawPoint(x, y, frame[s_iWidth*s_iHeight-1-i++]);
334
+ }
335
+ }
336
+
337
+ //������һ֡����
338
+ s_iGetFrameFlag = 0;
339
+ ConfigDCI();
340
+ }
341
+ }
deployment/GD32F470I_BluePill_ARMCC/App/Camera/DCI.h ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�DCI.h
3
+ * ժ Ҫ����������ͷ�ӿ�����ģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+ #ifndef _DCI_H_
17
+ #define _DCI_H_
18
+
19
+ /*********************************************************************************************************
20
+ * ����ͷ�ļ�
21
+ *********************************************************************************************************/
22
+ #include "DataType.h"
23
+
24
+ /*********************************************************************************************************
25
+ * �궨��
26
+ *********************************************************************************************************/
27
+
28
+ /*********************************************************************************************************
29
+ * ö�ٽṹ��
30
+ *********************************************************************************************************/
31
+
32
+ /*********************************************************************************************************
33
+ * API��������
34
+ *********************************************************************************************************/
35
+ //��ʼ����������ͷ�ӿ�����ģ��
36
+ void InitDCI(u32 frameAddr, u32 frameSize, u32 x0, u32 y0, u32 width, u32 height, u32 mode);
37
+
38
+ //ע����������ͷ�ӿ�����ģ��
39
+ void DeInitDCI(void);
40
+
41
+ //��ʾһ֡ͼ����Ļ��
42
+ void DCIShowImage(void);
43
+
44
+ void ConfigDCI(void);
45
+
46
+
47
+
48
+ #endif
deployment/GD32F470I_BluePill_ARMCC/App/Camera/OV2640.c ADDED
@@ -0,0 +1,611 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�OV2640.h
3
+ * ժ Ҫ��OV2640����ͷ����
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+
17
+ /*********************************************************************************************************
18
+ * ����ͷ�ļ�
19
+ *********************************************************************************************************/
20
+ #include "OV2640.h"
21
+ #include "OV2640Cfg.h"
22
+ #include "gd32f470x_conf.h"
23
+ #include "SysTick.h"
24
+ #include "stdio.h"
25
+ #include "SCCB.h"
26
+
27
+ /*********************************************************************************************************
28
+ * �궨��
29
+ *********************************************************************************************************/
30
+
31
+ /*********************************************************************************************************
32
+ * ö�ٽṹ��
33
+ *********************************************************************************************************/
34
+
35
+ /*********************************************************************************************************
36
+ * �ڲ�����
37
+ *********************************************************************************************************/
38
+
39
+ /*********************************************************************************************************
40
+ * �ڲ���������
41
+ *********************************************************************************************************/
42
+ static void ConfigGPIO(void); //����OV2640��GPIO
43
+
44
+ /*********************************************************************************************************
45
+ * �ڲ�����ʵ��
46
+ *********************************************************************************************************/
47
+ /*********************************************************************************************************
48
+ * �������ƣ�ConfigGPIO
49
+ * �������ܣ�����OV2640��GPIO
50
+ * ���������void
51
+ * ���������void
52
+ * �� �� ֵ��void
53
+ * �������ڣ�2021��07��01��
54
+ * ע �⣺
55
+ *********************************************************************************************************/
56
+ static void ConfigGPIO(void)
57
+ {
58
+ //����RCCʱ��
59
+ rcu_periph_clock_enable(RCU_GPIOA); //ʹ��GPIOA��ʱ��
60
+ rcu_periph_clock_enable(RCU_GPIOB); //ʹ��GPIOB��ʱ��
61
+
62
+ //PWDN
63
+ gpio_mode_set(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLUP, GPIO_PIN_15);
64
+ gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_15);
65
+
66
+ //RESET
67
+ gpio_mode_set(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLUP, GPIO_PIN_3);
68
+ gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_3);
69
+ }
70
+
71
+ /*********************************************************************************************************
72
+ * API����ʵ��
73
+ *********************************************************************************************************/
74
+ /*********************************************************************************************************
75
+ * �������ƣ�InitOV2640
76
+ * �������ܣ���ʼ��OV2640
77
+ * ���������void
78
+ * ���������void
79
+ * �� �� ֵ��0-�ɹ�������-�������
80
+ * �������ڣ�2021��07��01��
81
+ * ע �⣺�������Ժ�,Ĭ�������800*600�ߴ��ͼƬ
82
+ *********************************************************************************************************/
83
+ u8 InitOV2640(void)
84
+ {
85
+ u16 i, reg;
86
+
87
+ //����GPIO
88
+ ConfigGPIO();
89
+
90
+ //POWER ON
91
+ OV2640PWDNSet(0);
92
+ DelayNms(10);
93
+
94
+ //��λOV2640
95
+ gpio_bit_reset(GPIOB, GPIO_PIN_3);
96
+ DelayNms(10);
97
+ gpio_bit_set(GPIOB, GPIO_PIN_3);
98
+ DelayNms(50);
99
+
100
+ //��ʼ��SCCB
101
+ InitSCCB();
102
+
103
+ //����OV2640����ģʽ
104
+ SCCBWriteReg(OV2640_DSP_RA_DLMT, 0x01); //����sensor�Ĵ���
105
+ SCCBWriteReg(OV2640_SENSOR_COM7, 0x80); //����λOV2640
106
+ DelayNms(50);
107
+
108
+ //��ID
109
+ reg = SCCBReadReg(OV2640_SENSOR_MIDH);
110
+ reg <<= 8;
111
+ reg |= SCCBReadReg(OV2640_SENSOR_MIDL);
112
+ if(reg != OV2640_MID)
113
+ {
114
+ printf("InitOV2640: MID:%d\r\n", reg);
115
+ return 1;
116
+ }
117
+ reg = SCCBReadReg(OV2640_SENSOR_PIDH);
118
+ reg <<= 8;
119
+ reg |= SCCBReadReg(OV2640_SENSOR_PIDL);
120
+ if(reg != OV2640_PID)
121
+ {
122
+ printf("InitOV2640: HID:%d\r\n", reg);
123
+ return 2;
124
+ }
125
+
126
+ //��ʼ��OV2640������SVGA�ֱ���800*600)
127
+ for(i = 0; i < sizeof(ov2640_svga_init_reg_tbl) / 2; i++)
128
+ {
129
+ SCCBWriteReg(ov2640_svga_init_reg_tbl[i][0], ov2640_svga_init_reg_tbl[i][1]);
130
+ }
131
+ return 0x00;
132
+ }
133
+
134
+ /*********************************************************************************************************
135
+ * �������ƣ�OV2640PWDNSet
136
+ * �������ܣ���������ͷģ��PWDN�ŵ�״̬
137
+ * ���������sta��0-PWDN=0���ϵ磻1-PWDN=1������
138
+ * ���������void
139
+ * �� �� ֵ��void
140
+ * �������ڣ�2021��07��01��
141
+ * ע �⣺
142
+ *********************************************************************************************************/
143
+ void OV2640PWDNSet(u8 sta)
144
+ {
145
+ gpio_bit_write(GPIOA, GPIO_PIN_15, (bit_status)sta);
146
+ }
147
+
148
+ /*********************************************************************************************************
149
+ * �������ƣ�OV2640PWDNSet
150
+ * �������ܣ�OV2640�л�ΪJPEGģʽ
151
+ * ���������void
152
+ * ���������void
153
+ * �� �� ֵ��void
154
+ * �������ڣ�2021��07��01��
155
+ * ע �⣺
156
+ *********************************************************************************************************/
157
+ void OV2640JPEGMode(void)
158
+ {
159
+ u16 i;
160
+
161
+ //����:YUV422��ʽ
162
+ for(i = 0; i < (sizeof(ov2640_yuv422_reg_tbl) / 2); i++)
163
+ {
164
+ SCCBWriteReg(ov2640_yuv422_reg_tbl[i][0], ov2640_yuv422_reg_tbl[i][1]);
165
+ }
166
+
167
+ //����:���JPEG����
168
+ for(i = 0; i < (sizeof(ov2640_jpeg_reg_tbl) / 2); i++)
169
+ {
170
+ SCCBWriteReg(ov2640_jpeg_reg_tbl[i][0], ov2640_jpeg_reg_tbl[i][1]);
171
+ }
172
+ }
173
+
174
+ /*********************************************************************************************************
175
+ * �������ƣ�OV2640RGB565Mode
176
+ * �������ܣ�OV2640�л�ΪRGB565ģʽ
177
+ * ���������void
178
+ * ���������void
179
+ * �� �� ֵ��void
180
+ * �������ڣ�2021��07��01��
181
+ * ע �⣺
182
+ *********************************************************************************************************/
183
+ void OV2640RGB565Mode(void)
184
+ {
185
+ u16 i = 0;
186
+
187
+ //����:RGB565���
188
+ for(i = 0; i < (sizeof(ov2640_rgb565_reg_tbl) / 2); i++)
189
+ {
190
+ SCCBWriteReg(ov2640_rgb565_reg_tbl[i][0], ov2640_rgb565_reg_tbl[i][1]);
191
+ }
192
+ }
193
+
194
+ /*********************************************************************************************************
195
+ * �������ƣ�OV2640AutoExposure
196
+ * �������ܣ�OV2640�Զ��ع�ȼ�����
197
+ * ���������level��0-4
198
+ * ���������void
199
+ * �� �� ֵ��void
200
+ * �������ڣ�2021��07��01��
201
+ * ע �⣺
202
+ *********************************************************************************************************/
203
+ void OV2640AutoExposure(u8 level)
204
+ {
205
+ //�Զ��ع����ò�����,֧��5���ȼ�
206
+ const static u8 OV2640_AUTOEXPOSURE_LEVEL[5][8]=
207
+ {
208
+ {
209
+ 0xFF, 0x01,
210
+ 0x24, 0x20,
211
+ 0x25, 0x18,
212
+ 0x26, 0x60,
213
+ },
214
+ {
215
+ 0xFF, 0x01,
216
+ 0x24, 0x34,
217
+ 0x25, 0x1c,
218
+ 0x26, 0x00,
219
+ },
220
+ {
221
+ 0xFF, 0x01,
222
+ 0x24, 0x3e,
223
+ 0x25, 0x38,
224
+ 0x26, 0x81,
225
+ },
226
+ {
227
+ 0xFF, 0x01,
228
+ 0x24, 0x48,
229
+ 0x25, 0x40,
230
+ 0x26, 0x81,
231
+ },
232
+ {
233
+ 0xFF, 0x01,
234
+ 0x24, 0x58,
235
+ 0x25, 0x50,
236
+ 0x26, 0x92,
237
+ },
238
+ };
239
+
240
+ u8 i;
241
+ u8* p= (u8*)OV2640_AUTOEXPOSURE_LEVEL[level];
242
+ for(i = 0; i < 4; i++)
243
+ {
244
+ SCCBWriteReg(p[i * 2], p[i * 2 + 1]);
245
+ }
246
+ }
247
+
248
+ /*********************************************************************************************************
249
+ * �������ƣ�OV2640LightMode
250
+ * �������ܣ���ƽ������
251
+ * ���������mode��
252
+ * 0:�Զ�
253
+ * 1:̫��sunny
254
+ * 2,����cloudy
255
+ * 3,�칫��office
256
+ * 4,����home
257
+ * ���������void
258
+ * �� �� ֵ��void
259
+ * �������ڣ�2021��07��01��
260
+ * ע �⣺
261
+ *********************************************************************************************************/
262
+ void OV2640LightMode(u8 mode)
263
+ {
264
+ u8 regccval;
265
+ u8 regcdval;
266
+ u8 regceval;
267
+ switch(mode)
268
+ {
269
+ case 0://auto
270
+ SCCBWriteReg(0xFF, 0x00);
271
+ SCCBWriteReg(0xC7, 0x10);
272
+ return;
273
+ case 1://sunny
274
+ regccval = 0x5E;
275
+ regcdval = 0x41;
276
+ regceval = 0x54;
277
+ break;
278
+ case 2://cloudy
279
+ regccval = 0x65;
280
+ regcdval = 0x41;
281
+ regceval = 0x4F;
282
+ break;
283
+ case 3://office
284
+ regccval = 0x52;
285
+ regcdval = 0x41;
286
+ regceval = 0x66;
287
+ break;
288
+ case 4://home
289
+ regccval = 0x42;
290
+ regcdval = 0x3F;
291
+ regceval = 0x71;
292
+ break;
293
+ }
294
+ SCCBWriteReg(0xFF, 0x00);
295
+ SCCBWriteReg(0xC7, 0x40);
296
+ SCCBWriteReg(0xCC, regccval);
297
+ SCCBWriteReg(0xCD, regcdval);
298
+ SCCBWriteReg(0xCE, regceval);
299
+ }
300
+
301
+ /*********************************************************************************************************
302
+ * �������ƣ�OV2640ColorSaturation
303
+ * �������ܣ�ɫ������
304
+ * ���������sat��
305
+ * 0:-2
306
+ * 1:-1
307
+ * 2,0
308
+ * 3,+1
309
+ * 4,+2
310
+ * ���������void
311
+ * �� �� ֵ��void
312
+ * �������ڣ�2021��07��01��
313
+ * ע �⣺
314
+ *********************************************************************************************************/
315
+ void OV2640ColorSaturation(u8 sat)
316
+ {
317
+ u8 reg7dval = ((sat + 2) << 4) | 0x08;
318
+ SCCBWriteReg(0xFF, 0x00);
319
+ SCCBWriteReg(0x7C, 0x00);
320
+ SCCBWriteReg(0x7D, 0x02);
321
+ SCCBWriteReg(0x7C, 0x03);
322
+ SCCBWriteReg(0x7D, reg7dval);
323
+ SCCBWriteReg(0x7D, reg7dval);
324
+ }
325
+
326
+ /*********************************************************************************************************
327
+ * �������ƣ�OV2640Brightness
328
+ * �������ܣ���������
329
+ * ���������bright��
330
+ * 0:(0x00)-2
331
+ * 1:(0x10)-1
332
+ * 2:(0x20) 0
333
+ * 3:(0x30)+1
334
+ * 4:(0x40)+2
335
+ * ���������void
336
+ * �� �� ֵ��void
337
+ * �������ڣ�2021��07��01��
338
+ * ע �⣺
339
+ *********************************************************************************************************/
340
+ void OV2640Brightness(u8 bright)
341
+ {
342
+ SCCBWriteReg(0xFF, 0x00);
343
+ SCCBWriteReg(0x7C, 0x00);
344
+ SCCBWriteReg(0x7D, 0x04);
345
+ SCCBWriteReg(0x7C, 0x09);
346
+ SCCBWriteReg(0x7D, bright << 4);
347
+ SCCBWriteReg(0x7D, 0x00);
348
+ }
349
+
350
+ /*********************************************************************************************************
351
+ * �������ƣ�OV2640Contrast
352
+ * �������ܣ��Աȶ�����
353
+ * ���������contrast��
354
+ * 0:-2
355
+ * 1:-1
356
+ * 2:0
357
+ * 3:+1
358
+ * 4:+2
359
+ * ���������void
360
+ * �� �� ֵ��void
361
+ * �������ڣ�2021��07��01��
362
+ * ע �⣺
363
+ *********************************************************************************************************/
364
+ void OV2640Contrast(u8 contrast)
365
+ {
366
+ //Ĭ��Ϊ��ͨģʽ
367
+ u8 reg7d0val = 0x20;
368
+ u8 reg7d1val = 0x20;
369
+ switch(contrast)
370
+ {
371
+ case 0://-2
372
+ reg7d0val = 0x18;
373
+ reg7d1val = 0x34;
374
+ break;
375
+ case 1://-1
376
+ reg7d0val = 0x1C;
377
+ reg7d1val = 0x2A;
378
+ break;
379
+ case 3://1
380
+ reg7d0val = 0x24;
381
+ reg7d1val = 0x16;
382
+ break;
383
+ case 4://2
384
+ reg7d0val = 0x28;
385
+ reg7d1val = 0x0C;
386
+ break;
387
+ }
388
+ SCCBWriteReg(0xFF, 0x00);
389
+ SCCBWriteReg(0x7C, 0x00);
390
+ SCCBWriteReg(0x7D, 0x04);
391
+ SCCBWriteReg(0x7C, 0x07);
392
+ SCCBWriteReg(0x7D, 0x20);
393
+ SCCBWriteReg(0x7D, reg7d0val);
394
+ SCCBWriteReg(0x7D, reg7d1val);
395
+ SCCBWriteReg(0x7D, 0x06);
396
+ }
397
+
398
+ /*********************************************************************************************************
399
+ * �������ƣ�OV2640SpecialEffects
400
+ * �������ܣ���Ч����
401
+ * ���������eft��
402
+ * 0:��ͨģʽ
403
+ * 1:��Ƭ
404
+ * 2:�ڰ�
405
+ * 3:ƫ��ɫ
406
+ * 4:ƫ��ɫ
407
+ * 5:ƫ��ɫ
408
+ * 6:����
409
+ * ���������void
410
+ * �� �� ֵ��void
411
+ * �������ڣ�2021��07��01��
412
+ * ע �⣺
413
+ *********************************************************************************************************/
414
+ void OV2640SpecialEffects(u8 eft)
415
+ {
416
+ //Ĭ��Ϊ��ͨģʽ
417
+ u8 reg7d0val = 0x00;
418
+ u8 reg7d1val = 0x80;
419
+ u8 reg7d2val = 0x80;
420
+ switch(eft)
421
+ {
422
+ case 1://��Ƭ
423
+ reg7d0val = 0x40;
424
+ break;
425
+ case 2://�ڰ�
426
+ reg7d0val = 0x18;
427
+ break;
428
+ case 3://ƫ��ɫ
429
+ reg7d0val = 0x18;
430
+ reg7d1val = 0x40;
431
+ reg7d2val = 0xC0;
432
+ break;
433
+ case 4://ƫ��ɫ
434
+ reg7d0val = 0x18;
435
+ reg7d1val = 0x40;
436
+ reg7d2val = 0x40;
437
+ break;
438
+ case 5://ƫ��ɫ
439
+ reg7d0val = 0x18;
440
+ reg7d1val = 0xA0;
441
+ reg7d2val = 0x40;
442
+ break;
443
+ case 6://����
444
+ reg7d0val = 0x18;
445
+ reg7d1val = 0x40;
446
+ reg7d2val = 0xA6;
447
+ break;
448
+ }
449
+ SCCBWriteReg(0xFF, 0x00);
450
+ SCCBWriteReg(0x7C, 0x00);
451
+ SCCBWriteReg(0x7D, reg7d0val);
452
+ SCCBWriteReg(0x7C, 0x05);
453
+ SCCBWriteReg(0x7D, reg7d1val);
454
+ SCCBWriteReg(0x7D, reg7d2val);
455
+ }
456
+
457
+ /*********************************************************************************************************
458
+ * �������ƣ�OV2640ColorBar
459
+ * �������ܣ���������
460
+ * ���������sw��0-�رղ�����1-��������(ע��OV2640�IJ����ǵ�����ͼ�������)
461
+ * ���������void
462
+ * �� �� ֵ��void
463
+ * �������ڣ�2021��07��01��
464
+ * ע �⣺
465
+ *********************************************************************************************************/
466
+ void OV2640ColorBar(u8 sw)
467
+ {
468
+ u8 reg;
469
+ SCCBWriteReg(0xFF, 0x01);
470
+ reg = SCCBReadReg(0x12);
471
+ reg &= ~(1 << 1);
472
+ if(sw)
473
+ {
474
+ reg |= 1 << 1;
475
+ }
476
+ SCCBWriteReg(0x12, reg);
477
+ }
478
+
479
+ /*********************************************************************************************************
480
+ * �������ƣ�OV2640WindowSet
481
+ * �������ܣ�����ͼ���������
482
+ * ���������sx,sy-��ʼ��ַ��width,height:����(��Ӧ:horizontal)�͸߶�(��Ӧ:vertical)
483
+ * ���������void
484
+ * �� �� ֵ��void
485
+ * �������ڣ�2021��07��01��
486
+ * ע �⣺
487
+ *********************************************************************************************************/
488
+ void OV2640WindowSet(u16 sx,u16 sy,u16 width,u16 height)
489
+ {
490
+ u16 endx;
491
+ u16 endy;
492
+ u8 temp;
493
+ endx = sx + width / 2; //V*2
494
+ endy = sy + height / 2;
495
+
496
+ SCCBWriteReg(0xFF, 0x01);
497
+ temp = SCCBReadReg(0x03); //��ȡVref֮ǰ��ֵ
498
+ temp &= 0xF0;
499
+ temp |= ((endy & 0x03) << 2) | (sy & 0x03);
500
+ SCCBWriteReg(0x03, temp); //����Vref��start��end�����2λ
501
+ SCCBWriteReg(0x19, sy >> 2); //����Vref��start��8λ
502
+ SCCBWriteReg(0x1A, endy >> 2); //����Vref��end�ĸ�8λ
503
+ temp = SCCBReadReg(0x32); //��ȡHref֮ǰ��ֵ
504
+ temp &= 0xC0;
505
+ temp |= ((endx & 0x07) << 3) | (sx & 0x07);
506
+ SCCBWriteReg(0x32, temp); //����Href��start��end�����3λ
507
+ SCCBWriteReg(0x17, sx >> 3); //����Href��start��8λ
508
+ SCCBWriteReg(0x18, endx >> 3); //����Href��end�ĸ�8λ
509
+ }
510
+
511
+ /*********************************************************************************************************
512
+ * �������ƣ�OV2640OutSizeSet
513
+ * �������ܣ�����ͼ�������С
514
+ * ���������width,height:����(��Ӧ:horizontal)�͸߶�(��Ӧ:vertical),width��height������4�ı���
515
+ * ���������void
516
+ * �� �� ֵ��0-���óɹ�������-����ʧ��
517
+ * �������ڣ�2021��07��01��
518
+ * ע �⣺OV2640���ͼ��Ĵ�С(�ֱ���),��ȫ�ɸĺ���ȷ��
519
+ *********************************************************************************************************/
520
+ u8 OV2640OutSizeSet(u16 width,u16 height)
521
+ {
522
+ u16 outh;
523
+ u16 outw;
524
+ u8 temp;
525
+ if(width % 4)
526
+ {
527
+ return 1;
528
+ }
529
+ if(height % 4)
530
+ {
531
+ return 2;
532
+ }
533
+ outw = width / 4;
534
+ outh = height / 4;
535
+ SCCBWriteReg(0xFF, 0x00);
536
+ SCCBWriteReg(0xE0, 0x04);
537
+ SCCBWriteReg(0x5A, outw & 0xFF); //����OUTW�ĵͰ�λ
538
+ SCCBWriteReg(0x5B, outh & 0xFF); //����OUTH�ĵͰ�λ
539
+ temp = (outw >> 8) & 0x03;
540
+ temp |= (outh >> 6) & 0x04;
541
+ SCCBWriteReg(0x5C,temp); //����OUTH/OUTW�ĸ�λ
542
+ SCCBWriteReg(0xE0,0x00);
543
+ return 0;
544
+ }
545
+
546
+ /*********************************************************************************************************
547
+ * �������ƣ�OV2640ImageWinSet
548
+ * �������ܣ�����ͼ�񿪴���С
549
+ * ���������width,height:����(��Ӧ:horizontal)�͸߶�(��Ӧ:vertical),width��height������4�ı���
550
+ * ���������void
551
+ * �� �� ֵ��0-���óɹ�������-����ʧ��
552
+ * �������ڣ�2021��07��01��
553
+ * ע �⣺OV2640ImageSizeSetȷ������������ֱ��ʴӴ�С��
554
+ * �ú������������Χ������п���,����OV2640_OutSize_Set�����
555
+ * �������Ŀ��Ⱥ͸߶�,������ڵ���OV2640_OutSize_Set�����Ŀ��Ⱥ͸߶�
556
+ * OV2640OutSizeSet���õĿ��Ⱥ͸߶�,���ݱ��������õĿ��Ⱥ͸߶�,��DSP�Զ��������ű���,������ⲿ�豸
557
+ *********************************************************************************************************/
558
+ u8 OV2640ImageWinSet(u16 offx,u16 offy,u16 width,u16 height)
559
+ {
560
+ u16 hsize;
561
+ u16 vsize;
562
+ u8 temp;
563
+ if(width % 4)
564
+ {
565
+ return 1;
566
+ }
567
+ if(height % 4)
568
+ {
569
+ return 2;
570
+ }
571
+ hsize = width / 4;
572
+ vsize = height / 4;
573
+ SCCBWriteReg(0xFF, 0x00);
574
+ SCCBWriteReg(0xE0, 0x04);
575
+ SCCBWriteReg(0x51, hsize & 0xFF); //����H_SIZE�ĵͰ�λ
576
+ SCCBWriteReg(0x52, vsize & 0xFF); //����V_SIZE�ĵͰ�λ
577
+ SCCBWriteReg(0x53, offx & 0xFF); //����offx�ĵͰ�λ
578
+ SCCBWriteReg(0x54, offy & 0xFF); //����offy�ĵͰ�λ
579
+ temp = (vsize >> 1) & 0x80;
580
+ temp |= (offy >> 4) & 0x70;
581
+ temp |= (hsize >> 5) & 0x08;
582
+ temp |= (offx >> 8) & 0x07;
583
+ SCCBWriteReg(0x55, temp); //����H_SIZE/V_SIZE/OFFX,OFFY�ĸ�λ
584
+ SCCBWriteReg(0x57, (hsize >> 2) & 0x80); //����H_SIZE/V_SIZE/OFFX,OFFY�ĸ�λ
585
+ SCCBWriteReg(0xE0, 0x00);
586
+ return 0;
587
+ }
588
+
589
+ /*********************************************************************************************************
590
+ * �������ƣ�OV2640ImageSizeSet
591
+ * �������ܣ��ú�������ͼ��ߴ��С��Ҳ������ѡ��ʽ������ֱ���
592
+ * ���������width,height:ͼ����Ⱥ�ͼ��߶�
593
+ * ���������void
594
+ * �� �� ֵ��0-���óɹ�������-����ʧ��
595
+ * �������ڣ�2021��07��01��
596
+ * ע �⣺UXGA:1600*1200,SVGA:800*600,CIF:352*288
597
+ *********************************************************************************************************/
598
+ u8 OV2640ImageSizeSet(u16 width,u16 height)
599
+ {
600
+ u8 temp;
601
+ SCCBWriteReg(0xFF, 0x00);
602
+ SCCBWriteReg(0xE0, 0x04);
603
+ SCCBWriteReg(0xC0, (width >> 3) & 0xFF); //����HSIZE��10:3λ
604
+ SCCBWriteReg(0xC1, (height >> 3) & 0xFF); //����VSIZE��10:3λ
605
+ temp = (width & 0x07) << 3;
606
+ temp |= height & 0x07;
607
+ temp |= (width >> 4) & 0x80;
608
+ SCCBWriteReg(0x8C, temp);
609
+ SCCBWriteReg(0xE0, 0x00);
610
+ return 0;
611
+ }
deployment/GD32F470I_BluePill_ARMCC/App/Camera/OV2640.h ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�OV2640.h
3
+ * ժ Ҫ��OV2640����ͷ����
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+ #ifndef _OV2640_H_
17
+ #define _OV2640_H_
18
+
19
+ /*********************************************************************************************************
20
+ * ����ͷ�ļ�
21
+ *********************************************************************************************************/
22
+ #include "DataType.h"
23
+
24
+ /*********************************************************************************************************
25
+ * �궨��
26
+ *********************************************************************************************************/
27
+ #define OV2640_MID 0x7FA2
28
+ #define OV2640_PID 0x2642
29
+
30
+ //��ѡ��DSP��ַ(0XFF=0X00)ʱ,OV2640��DSP�Ĵ�����ַӳ���
31
+ #define OV2640_DSP_R_BYPASS 0x05
32
+ #define OV2640_DSP_Qs 0x44
33
+ #define OV2640_DSP_CTRL 0x50
34
+ #define OV2640_DSP_HSIZE1 0x51
35
+ #define OV2640_DSP_VSIZE1 0x52
36
+ #define OV2640_DSP_XOFFL 0x53
37
+ #define OV2640_DSP_YOFFL 0x54
38
+ #define OV2640_DSP_VHYX 0x55
39
+ #define OV2640_DSP_DPRP 0x56
40
+ #define OV2640_DSP_TEST 0x57
41
+ #define OV2640_DSP_ZMOW 0x5A
42
+ #define OV2640_DSP_ZMOH 0x5B
43
+ #define OV2640_DSP_ZMHH 0x5C
44
+ #define OV2640_DSP_BPADDR 0x7C
45
+ #define OV2640_DSP_BPDATA 0x7D
46
+ #define OV2640_DSP_CTRL2 0x86
47
+ #define OV2640_DSP_CTRL3 0x87
48
+ #define OV2640_DSP_SIZEL 0x8C
49
+ #define OV2640_DSP_HSIZE2 0xC0
50
+ #define OV2640_DSP_VSIZE2 0xC1
51
+ #define OV2640_DSP_CTRL0 0xC2
52
+ #define OV2640_DSP_CTRL1 0xC3
53
+ #define OV2640_DSP_R_DVP_SP 0xD3
54
+ #define OV2640_DSP_IMAGE_MODE 0xDA
55
+ #define OV2640_DSP_RESET 0xE0
56
+ #define OV2640_DSP_MS_SP 0xF0
57
+ #define OV2640_DSP_SS_ID 0x7F
58
+ #define OV2640_DSP_SS_CTRL 0xF8
59
+ #define OV2640_DSP_MC_BIST 0xF9
60
+ #define OV2640_DSP_MC_AL 0xFA
61
+ #define OV2640_DSP_MC_AH 0xFB
62
+ #define OV2640_DSP_MC_D 0xFC
63
+ #define OV2640_DSP_P_STATUS 0xFE
64
+ #define OV2640_DSP_RA_DLMT 0xFF
65
+
66
+ //��ѡ�񴫸�����ַ(0XFF=0X01)ʱ,OV2640��DSP�Ĵ�����ַӳ���
67
+ #define OV2640_SENSOR_GAIN 0x00
68
+ #define OV2640_SENSOR_COM1 0x03
69
+ #define OV2640_SENSOR_REG04 0x04
70
+ #define OV2640_SENSOR_REG08 0x08
71
+ #define OV2640_SENSOR_COM2 0x09
72
+ #define OV2640_SENSOR_PIDH 0x0A
73
+ #define OV2640_SENSOR_PIDL 0x0B
74
+ #define OV2640_SENSOR_COM3 0x0C
75
+ #define OV2640_SENSOR_COM4 0x0D
76
+ #define OV2640_SENSOR_AEC 0x10
77
+ #define OV2640_SENSOR_CLKRC 0x11
78
+ #define OV2640_SENSOR_COM7 0x12
79
+ #define OV2640_SENSOR_COM8 0x13
80
+ #define OV2640_SENSOR_COM9 0x14
81
+ #define OV2640_SENSOR_COM10 0x15
82
+ #define OV2640_SENSOR_HREFST 0x17
83
+ #define OV2640_SENSOR_HREFEND 0x18
84
+ #define OV2640_SENSOR_VSTART 0x19
85
+ #define OV2640_SENSOR_VEND 0x1A
86
+ #define OV2640_SENSOR_MIDH 0x1C
87
+ #define OV2640_SENSOR_MIDL 0x1D
88
+ #define OV2640_SENSOR_AEW 0x24
89
+ #define OV2640_SENSOR_AEB 0x25
90
+ #define OV2640_SENSOR_W 0x26
91
+ #define OV2640_SENSOR_REG2A 0x2A
92
+ #define OV2640_SENSOR_FRARL 0x2B
93
+ #define OV2640_SENSOR_ADDVSL 0x2D
94
+ #define OV2640_SENSOR_ADDVHS 0x2E
95
+ #define OV2640_SENSOR_YAVG 0x2F
96
+ #define OV2640_SENSOR_REG32 0x32
97
+ #define OV2640_SENSOR_ARCOM2 0x34
98
+ #define OV2640_SENSOR_REG45 0x45
99
+ #define OV2640_SENSOR_FLL 0x46
100
+ #define OV2640_SENSOR_FLH 0x47
101
+ #define OV2640_SENSOR_COM19 0x48
102
+ #define OV2640_SENSOR_ZOOMS 0x49
103
+ #define OV2640_SENSOR_COM22 0x4B
104
+ #define OV2640_SENSOR_COM25 0x4E
105
+ #define OV2640_SENSOR_BD50 0x4F
106
+ #define OV2640_SENSOR_BD60 0x50
107
+ #define OV2640_SENSOR_REG5D 0x5D
108
+ #define OV2640_SENSOR_REG5E 0x5E
109
+ #define OV2640_SENSOR_REG5F 0x5F
110
+ #define OV2640_SENSOR_REG60 0x60
111
+ #define OV2640_SENSOR_HISTO_LOW 0x61
112
+ #define OV2640_SENSOR_HISTO_HIGH 0x62
113
+
114
+ /*********************************************************************************************************
115
+ * ö�ٽṹ��
116
+ *********************************************************************************************************/
117
+
118
+ /*********************************************************************************************************
119
+ * API��������
120
+ *********************************************************************************************************/
121
+ u8 InitOV2640(void); //��ʼ��OV2640
122
+ void OV2640PWDNSet(u8 sta); //��������ͷģ��PWDN�ŵ�״̬
123
+ void OV2640JPEGMode(void); //�л�ΪJPEGģʽ
124
+ void OV2640RGB565Mode(void); //�л�ΪRGB565ģʽ
125
+ void OV2640AutoExposure(u8 level); //�Զ��ع�ȼ�����
126
+ void OV2640LightMode(u8 mode); //��ƽ������
127
+ void OV2640ColorSaturation(u8 sat); //ɫ������
128
+ void OV2640Brightness(u8 bright); //��������
129
+ void OV2640Contrast(u8 contrast); //�Աȶ�����
130
+ void OV2640SpecialEffects(u8 eft); //������
131
+ void OV2640ColorBar(u8 sw); //��������
132
+ void OV2640WindowSet(u16 sx,u16 sy,u16 width,u16 height); //����ͼ���������
133
+ u8 OV2640OutSizeSet(u16 width,u16 height); //����ͼ�������С
134
+ u8 OV2640ImageWinSet(u16 offx,u16 offy,u16 width,u16 height); //����ͼ�񿪴���С
135
+ u8 OV2640ImageSizeSet(u16 width,u16 height); //����ͼ��ߴ��С
136
+
137
+ #endif
deployment/GD32F470I_BluePill_ARMCC/App/Camera/OV2640Cfg.h ADDED
@@ -0,0 +1,463 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef _OV2640CFG_H
2
+ #define _OV2640CFG_H
3
+ #include "DataType.h"
4
+
5
+
6
+ //OV2640 SXGA��ʼ���Ĵ������б�
7
+ //��ģʽ��֡��Ϊ15֡
8
+ //SXGA(1600*1200)
9
+ const u8 ov2640_sxga_init_reg_tbl[][2]=
10
+ {
11
+ 0xff, 0x00,
12
+ 0x2c, 0xff,
13
+ 0x2e, 0xdf,
14
+ 0xff, 0x01,
15
+ 0x3c, 0x32,
16
+ //
17
+ 0x11, 0x00,
18
+ 0x09, 0x02,
19
+ 0x04, 0xD8,//ˮƽ����,��ֱ��ת
20
+ 0x13, 0xe5,
21
+ 0x14, 0x48,
22
+ 0x2c, 0x0c,
23
+ 0x33, 0x78,
24
+ 0x3a, 0x33,
25
+ 0x3b, 0xfB,
26
+ //
27
+ 0x3e, 0x00,
28
+ 0x43, 0x11,
29
+ 0x16, 0x10,
30
+ //
31
+ 0x39, 0x92,
32
+ //
33
+ 0x35, 0xda,
34
+ 0x22, 0x1a,
35
+ 0x37, 0xc3,
36
+ 0x23, 0x00,
37
+ 0x34, 0xc0,
38
+ 0x36, 0x1a,
39
+ 0x06, 0x88,
40
+ 0x07, 0xc0,
41
+ 0x0d, 0x87,
42
+ 0x0e, 0x41,
43
+ 0x4c, 0x00,
44
+
45
+ 0x48, 0x00,
46
+ 0x5B, 0x00,
47
+ 0x42, 0x03,
48
+ //
49
+ 0x4a, 0x81,
50
+ 0x21, 0x99,
51
+ //
52
+ 0x24, 0x40,
53
+ 0x25, 0x38,
54
+ 0x26, 0x82,
55
+ 0x5c, 0x00,
56
+ 0x63, 0x00,
57
+ 0x46, 0x00,
58
+ 0x0c, 0x3c,
59
+ //
60
+ 0x61, 0x70,
61
+ 0x62, 0x80,
62
+ 0x7c, 0x05,
63
+ //
64
+ 0x20, 0x80,
65
+ 0x28, 0x30,
66
+ 0x6c, 0x00,
67
+ 0x6d, 0x80,
68
+ 0x6e, 0x00,
69
+ 0x70, 0x02,
70
+ 0x71, 0x94,
71
+ 0x73, 0xc1,
72
+ 0x3d, 0x34,
73
+ 0x5a, 0x57,
74
+ //
75
+ 0x12, 0x00,//UXGA 1600*1200
76
+
77
+ 0x17, 0x11,
78
+ 0x18, 0x75,
79
+ 0x19, 0x01,
80
+ 0x1a, 0x97,
81
+ 0x32, 0x36,
82
+ 0x03, 0x0f,
83
+ 0x37, 0x40,
84
+ //
85
+ 0x4f, 0xca,
86
+ 0x50, 0xa8,
87
+ 0x5a, 0x23,
88
+ 0x6d, 0x00,
89
+ 0x6d, 0x38,
90
+ //
91
+ 0xff, 0x00,
92
+ 0xe5, 0x7f,
93
+ 0xf9, 0xc0,
94
+ 0x41, 0x24,
95
+ 0xe0, 0x14,
96
+ 0x76, 0xff,
97
+ 0x33, 0xa0,
98
+ 0x42, 0x20,
99
+ 0x43, 0x18,
100
+ 0x4c, 0x00,
101
+ 0x87, 0xd5,
102
+ 0x88, 0x3f,
103
+ 0xd7, 0x03,
104
+ 0xd9, 0x10,
105
+ 0xd3, 0x82,
106
+ //
107
+ 0xc8, 0x08,
108
+ 0xc9, 0x80,
109
+ //
110
+ 0x7c, 0x00,
111
+ 0x7d, 0x00,
112
+ 0x7c, 0x03,
113
+ 0x7d, 0x48,
114
+ 0x7d, 0x48,
115
+ 0x7c, 0x08,
116
+ 0x7d, 0x20,
117
+ 0x7d, 0x10,
118
+ 0x7d, 0x0e,
119
+ //
120
+ 0x90, 0x00,
121
+ 0x91, 0x0e,
122
+ 0x91, 0x1a,
123
+ 0x91, 0x31,
124
+ 0x91, 0x5a,
125
+ 0x91, 0x69,
126
+ 0x91, 0x75,
127
+ 0x91, 0x7e,
128
+ 0x91, 0x88,
129
+ 0x91, 0x8f,
130
+ 0x91, 0x96,
131
+ 0x91, 0xa3,
132
+ 0x91, 0xaf,
133
+ 0x91, 0xc4,
134
+ 0x91, 0xd7,
135
+ 0x91, 0xe8,
136
+ 0x91, 0x20,
137
+ //
138
+ 0x92, 0x00,
139
+ 0x93, 0x06,
140
+ 0x93, 0xe3,
141
+ 0x93, 0x05,
142
+ 0x93, 0x05,
143
+ 0x93, 0x00,
144
+ 0x93, 0x04,
145
+ 0x93, 0x00,
146
+ 0x93, 0x00,
147
+ 0x93, 0x00,
148
+ 0x93, 0x00,
149
+ 0x93, 0x00,
150
+ 0x93, 0x00,
151
+ 0x93, 0x00,
152
+ //
153
+ 0x96, 0x00,
154
+ 0x97, 0x08,
155
+ 0x97, 0x19,
156
+ 0x97, 0x02,
157
+ 0x97, 0x0c,
158
+ 0x97, 0x24,
159
+ 0x97, 0x30,
160
+ 0x97, 0x28,
161
+ 0x97, 0x26,
162
+ 0x97, 0x02,
163
+ 0x97, 0x98,
164
+ 0x97, 0x80,
165
+ 0x97, 0x00,
166
+ 0x97, 0x00,
167
+ //
168
+ 0xc3, 0xef,
169
+
170
+ 0xa4, 0x00,
171
+ 0xa8, 0x00,
172
+ 0xc5, 0x11,
173
+ 0xc6, 0x51,
174
+ 0xbf, 0x80,
175
+ 0xc7, 0x10,
176
+ 0xb6, 0x66,
177
+ 0xb8, 0xA5,
178
+ 0xb7, 0x64,
179
+ 0xb9, 0x7C,
180
+ 0xb3, 0xaf,
181
+ 0xb4, 0x97,
182
+ 0xb5, 0xFF,
183
+ 0xb0, 0xC5,
184
+ 0xb1, 0x94,
185
+ 0xb2, 0x0f,
186
+ 0xc4, 0x5c,
187
+ //
188
+ 0xc0, 0xc8,
189
+ 0xc1, 0x96,
190
+ 0x8c, 0x00,
191
+ 0x86, 0x3d,
192
+ 0x50, 0x00,
193
+ 0x51, 0x90,
194
+ 0x52, 0x2c,
195
+ 0x53, 0x00,
196
+ 0x54, 0x00,
197
+ 0x55, 0x88,
198
+
199
+ 0x5a, 0x90,
200
+ 0x5b, 0x2C,
201
+ 0x5c, 0x05,
202
+
203
+ 0xd3, 0x02,//auto����ҪС��
204
+ //
205
+ 0xc3, 0xed,
206
+ 0x7f, 0x00,
207
+
208
+ 0xda, 0x09,
209
+
210
+ 0xe5, 0x1f,
211
+ 0xe1, 0x67,
212
+ 0xe0, 0x00,
213
+ 0xdd, 0x7f,
214
+ 0x05, 0x00,
215
+ };
216
+ //OV2640 SVGA��ʼ���Ĵ������б�
217
+ //��ģʽ��,֡�ʿ��Դﵽ30֡
218
+ //SVGA 800*600
219
+ const u8 ov2640_svga_init_reg_tbl[][2]=
220
+ {
221
+ 0xff, 0x00,
222
+ 0x2c, 0xff,
223
+ 0x2e, 0xdf,
224
+ 0xff, 0x01,
225
+ 0x3c, 0x32,
226
+ //
227
+ 0x11, 0x00,
228
+ 0x09, 0x02,
229
+ 0x04, 0xD8,//ˮƽ����,��ֱ��ת
230
+ // 0x04, 0x58, //ˮƽ����,��ֱ��ת
231
+ 0x13, 0xe5,
232
+ 0x14, 0x48,
233
+ 0x2c, 0x0c,
234
+ 0x33, 0x78,
235
+ 0x3a, 0x33,
236
+ 0x3b, 0xfB,
237
+ //
238
+ 0x3e, 0x00,
239
+ 0x43, 0x11,
240
+ 0x16, 0x10,
241
+ //
242
+ 0x39, 0x92,
243
+ //
244
+ 0x35, 0xda,
245
+ 0x22, 0x1a,
246
+ 0x37, 0xc3,
247
+ 0x23, 0x00,
248
+ 0x34, 0xc0,
249
+ 0x36, 0x1a,
250
+ 0x06, 0x88,
251
+ 0x07, 0xc0,
252
+ 0x0d, 0x87,
253
+ 0x0e, 0x41,
254
+ 0x4c, 0x00,
255
+ 0x48, 0x00,
256
+ 0x5B, 0x00,
257
+ 0x42, 0x03,
258
+ //
259
+ 0x4a, 0x81,
260
+ 0x21, 0x99,
261
+ //
262
+ 0x24, 0x40,
263
+ 0x25, 0x38,
264
+ 0x26, 0x82,
265
+ 0x5c, 0x00,
266
+ 0x63, 0x00,
267
+ 0x46, 0x22,
268
+ 0x0c, 0x3c,
269
+ //
270
+ 0x61, 0x70,
271
+ 0x62, 0x80,
272
+ 0x7c, 0x05,
273
+ //
274
+ 0x20, 0x80,
275
+ 0x28, 0x30,
276
+ 0x6c, 0x00,
277
+ 0x6d, 0x80,
278
+ 0x6e, 0x00,
279
+ 0x70, 0x02,
280
+ 0x71, 0x94,
281
+ 0x73, 0xc1,
282
+
283
+ 0x3d, 0x34,
284
+ 0x5a, 0x57,
285
+ //���ݷֱ��ʲ�ͬ������
286
+ 0x12, 0x40,//SVGA 800*600
287
+ 0x17, 0x11,
288
+ 0x18, 0x43,
289
+ 0x19, 0x00,
290
+ 0x1a, 0x4b,
291
+ 0x32, 0x09,
292
+ 0x37, 0xc0,
293
+ //
294
+ 0x4f, 0xca,
295
+ 0x50, 0xa8,
296
+ 0x5a, 0x23,
297
+ 0x6d, 0x00,
298
+ 0x3d, 0x38,
299
+ //
300
+ 0xff, 0x00,
301
+ 0xe5, 0x7f,
302
+ 0xf9, 0xc0,
303
+ 0x41, 0x24,
304
+ 0xe0, 0x14,
305
+ 0x76, 0xff,
306
+ 0x33, 0xa0,
307
+ 0x42, 0x20,
308
+ 0x43, 0x18,
309
+ 0x4c, 0x00,
310
+ 0x87, 0xd5,
311
+ 0x88, 0x3f,
312
+ 0xd7, 0x03,
313
+ 0xd9, 0x10,
314
+ 0xd3, 0x82,
315
+ //
316
+ 0xc8, 0x08,
317
+ 0xc9, 0x80,
318
+ //
319
+ 0x7c, 0x00,
320
+ 0x7d, 0x00,
321
+ 0x7c, 0x03,
322
+ 0x7d, 0x48,
323
+ 0x7d, 0x48,
324
+ 0x7c, 0x08,
325
+ 0x7d, 0x20,
326
+ 0x7d, 0x10,
327
+ 0x7d, 0x0e,
328
+ //
329
+ 0x90, 0x00,
330
+ 0x91, 0x0e,
331
+ 0x91, 0x1a,
332
+ 0x91, 0x31,
333
+ 0x91, 0x5a,
334
+ 0x91, 0x69,
335
+ 0x91, 0x75,
336
+ 0x91, 0x7e,
337
+ 0x91, 0x88,
338
+ 0x91, 0x8f,
339
+ 0x91, 0x96,
340
+ 0x91, 0xa3,
341
+ 0x91, 0xaf,
342
+ 0x91, 0xc4,
343
+ 0x91, 0xd7,
344
+ 0x91, 0xe8,
345
+ 0x91, 0x20,
346
+ //
347
+ 0x92, 0x00,
348
+ 0x93, 0x06,
349
+ 0x93, 0xe3,
350
+ 0x93, 0x05,
351
+ 0x93, 0x05,
352
+ 0x93, 0x00,
353
+ 0x93, 0x04,
354
+ 0x93, 0x00,
355
+ 0x93, 0x00,
356
+ 0x93, 0x00,
357
+ 0x93, 0x00,
358
+ 0x93, 0x00,
359
+ 0x93, 0x00,
360
+ 0x93, 0x00,
361
+ //
362
+ 0x96, 0x00,
363
+ 0x97, 0x08,
364
+ 0x97, 0x19,
365
+ 0x97, 0x02,
366
+ 0x97, 0x0c,
367
+ 0x97, 0x24,
368
+ 0x97, 0x30,
369
+ 0x97, 0x28,
370
+ 0x97, 0x26,
371
+ 0x97, 0x02,
372
+ 0x97, 0x98,
373
+ 0x97, 0x80,
374
+ 0x97, 0x00,
375
+ 0x97, 0x00,
376
+ //
377
+ 0xc3, 0xed,
378
+ 0xa4, 0x00,
379
+ 0xa8, 0x00,
380
+ 0xc5, 0x11,
381
+ 0xc6, 0x51,
382
+ 0xbf, 0x80,
383
+ 0xc7, 0x10,
384
+ 0xb6, 0x66,
385
+ 0xb8, 0xA5,
386
+ 0xb7, 0x64,
387
+ 0xb9, 0x7C,
388
+ 0xb3, 0xaf,
389
+ 0xb4, 0x97,
390
+ 0xb5, 0xFF,
391
+ 0xb0, 0xC5,
392
+ 0xb1, 0x94,
393
+ 0xb2, 0x0f,
394
+ 0xc4, 0x5c,
395
+ //���ݷֱ��ʲ�ͬ������
396
+ 0xc0, 0x64,
397
+ 0xc1, 0x4B,
398
+ 0x8c, 0x00,
399
+ 0x86, 0x3D,
400
+ 0x50, 0x00,
401
+ 0x51, 0xC8,
402
+ 0x52, 0x96,
403
+ 0x53, 0x00,
404
+ 0x54, 0x00,
405
+ 0x55, 0x00,
406
+ 0x5a, 0xC8,
407
+ 0x5b, 0x96,
408
+ 0x5c, 0x00,
409
+
410
+ 0xd3, 0x02,//auto����ҪС��
411
+ //
412
+ 0xc3, 0xed,
413
+ 0x7f, 0x00,
414
+
415
+ 0xda, 0x09,
416
+
417
+ 0xe5, 0x1f,
418
+ 0xe1, 0x67,
419
+ 0xe0, 0x00,
420
+ 0xdd, 0x7f,
421
+ 0x05, 0x00,
422
+ };
423
+ const u8 ov2640_jpeg_reg_tbl[][2]=
424
+ {
425
+ 0xff, 0x01,
426
+ 0xe0, 0x14,
427
+ 0xe1, 0x77,
428
+ 0xe5, 0x1f,
429
+ 0xd7, 0x03,
430
+ 0xda, 0x10,
431
+ 0xe0, 0x00,
432
+ };
433
+ const u8 ov2640_rgb565_reg_tbl[][2]=
434
+ {
435
+ 0xFF, 0x00,
436
+ 0xDA, 0x09,
437
+ 0xD7, 0x03,
438
+ 0xDF, 0x02,
439
+ 0x33, 0xa0,
440
+ 0x3C, 0x00,
441
+ 0xe1, 0x67,
442
+
443
+ 0xff, 0x01,
444
+ 0xe0, 0x00,
445
+ 0xe1, 0x00,
446
+ 0xe5, 0x00,
447
+ 0xd7, 0x00,
448
+ 0xda, 0x00,
449
+ 0xe0, 0x00,
450
+ };
451
+ const u8 ov2640_yuv422_reg_tbl[][2]=
452
+ {
453
+ 0xFF, 0x00,
454
+ 0xDA, 0x10,
455
+ 0xD7, 0x03,
456
+ 0xDF, 0x00,
457
+ 0x33, 0x80,
458
+ 0x3C, 0x40,
459
+ 0xe1, 0x77,
460
+ 0x00, 0x00,
461
+ };
462
+
463
+ #endif
deployment/GD32F470I_BluePill_ARMCC/App/Camera/SCCB.c ADDED
@@ -0,0 +1,236 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�SCCB.h
3
+ * ժ Ҫ��SCCBЭ������
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+
17
+ /*********************************************************************************************************
18
+ * ����ͷ�ļ�
19
+ *********************************************************************************************************/
20
+ #include "SCCB.h"
21
+ #include "gd32f470x_conf.h"
22
+ #include "SysTick.h"
23
+ #include "IICCommon.h"
24
+
25
+ /*********************************************************************************************************
26
+ * �궨��
27
+ *********************************************************************************************************/
28
+
29
+ /*********************************************************************************************************
30
+ * ö�ٽṹ��
31
+ *********************************************************************************************************/
32
+
33
+ /*********************************************************************************************************
34
+ * �ڲ�����
35
+ *********************************************************************************************************/
36
+ //IICͨ���豸�ṹ��
37
+ static StructIICCommonDev s_structIICDev;
38
+
39
+ /*********************************************************************************************************
40
+ * �ڲ���������
41
+ *********************************************************************************************************/
42
+ static void ConfigIICGPIO(void); //����IIC��GPIO
43
+ static void ConfigSDAMode(u8 mode); //����SDA�������
44
+ static void SetSCL(u8 state); //ʱ���ź���SCL����
45
+ static void SetSDA(u8 state); //�������SDA����
46
+ static u8 GetSDA(void); //��ȡSDA�����ƽ
47
+ static void Delay(u8 time); //��ʱ����
48
+
49
+ /*********************************************************************************************************
50
+ * �ڲ�����ʵ��
51
+ *********************************************************************************************************/
52
+ /*********************************************************************************************************
53
+ * �������ƣ�ConfigIICGPIO
54
+ * �������ܣ�����IIC��GPIO
55
+ * ���������void
56
+ * ���������void
57
+ * �� �� ֵ��void
58
+ * �������ڣ�2021��07��01��
59
+ * ע �⣺
60
+ *********************************************************************************************************/
61
+ static void ConfigIICGPIO(void)
62
+ {
63
+ //ʹ��RCU���ʱ��
64
+ rcu_periph_clock_enable(RCU_GPIOB); //ʹ��GPIOB��ʱ��
65
+
66
+ //SCL
67
+ gpio_mode_set(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLUP, GPIO_PIN_6); //�������
68
+ gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_MAX,GPIO_PIN_6); //�������
69
+ gpio_bit_set(GPIOB, GPIO_PIN_6); //����SCL
70
+
71
+ //SDA
72
+ gpio_mode_set(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLUP, GPIO_PIN_7); //�������
73
+ gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_MAX,GPIO_PIN_7); //�������
74
+ gpio_bit_set(GPIOB, GPIO_PIN_7); //����SCL
75
+ }
76
+
77
+ /*********************************************************************************************************
78
+ * �������ƣ�ConfigSDAMode
79
+ * �������ܣ�����SDA�������
80
+ * ���������mode��IIC_COMMON_INPUT��IIC_COMMON_OUTPUT
81
+ * ���������void
82
+ * �� �� ֵ��void
83
+ * �������ڣ�2018��01��01��
84
+ * ע �⣺
85
+ *********************************************************************************************************/
86
+ static void ConfigSDAMode(u8 mode)
87
+ {
88
+ rcu_periph_clock_enable(RCU_GPIOB); //ʹ��GPIOB��ʱ��
89
+
90
+ //�����
91
+ if(IIC_COMMON_OUTPUT == mode)
92
+ {
93
+ gpio_mode_set(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLUP, GPIO_PIN_7); //�������
94
+ gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_MAX,GPIO_PIN_7); //�������
95
+ }
96
+
97
+ //������
98
+ else if(IIC_COMMON_INPUT == mode)
99
+ {
100
+ gpio_mode_set(GPIOB, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, GPIO_PIN_7); //��������
101
+ }
102
+ }
103
+
104
+ /*********************************************************************************************************
105
+ * �������ƣ�SetSCL
106
+ * �������ܣ�ʱ���ź���SCL����
107
+ * ���������state��0-����͵�ƽ��1-����ߵ�ƽ
108
+ * ���������void
109
+ * �� �� ֵ��void
110
+ * �������ڣ�2018��01��01��
111
+ * ע �⣺
112
+ *********************************************************************************************************/
113
+ static void SetSCL(u8 state)
114
+ {
115
+ if(1 == state)
116
+ {
117
+ gpio_bit_set(GPIOB, GPIO_PIN_6);
118
+ }
119
+ else
120
+ {
121
+ gpio_bit_reset(GPIOB, GPIO_PIN_6);
122
+ }
123
+ }
124
+
125
+ /*********************************************************************************************************
126
+ * �������ƣ�SetSDA
127
+ * �������ܣ������ź���SDA����
128
+ * ���������state��0-����͵�ƽ��1-����ߵ�ƽ
129
+ * ���������void
130
+ * �� �� ֵ��void
131
+ * �������ڣ�2018��01��01��
132
+ * ע �⣺
133
+ *********************************************************************************************************/
134
+ static void SetSDA(u8 state)
135
+ {
136
+ if(1 == state)
137
+ {
138
+ gpio_bit_set(GPIOB, GPIO_PIN_7);
139
+ }
140
+ else
141
+ {
142
+ gpio_bit_reset(GPIOB, GPIO_PIN_7);
143
+ }
144
+ }
145
+
146
+ /*********************************************************************************************************
147
+ * �������ƣ�GetSDA
148
+ * �������ܣ���ȡSDA�����ƽ
149
+ * ���������void
150
+ * ���������void
151
+ * �� �� ֵ��SDA�����ƽ
152
+ * �������ڣ�2018��01��01��
153
+ * ע �⣺
154
+ *********************************************************************************************************/
155
+ static u8 GetSDA(void)
156
+ {
157
+ if(RESET == gpio_input_bit_get(GPIOB, GPIO_PIN_7))
158
+ {
159
+ return 0;
160
+ }
161
+ else
162
+ {
163
+ return 1;
164
+ }
165
+ }
166
+
167
+ /*********************************************************************************************************
168
+ * �������ƣ�Delay
169
+ * �������ܣ���ʱ����
170
+ * ���������time����ʱʱ������
171
+ * ���������void
172
+ * �� �� ֵ��SDA�����ƽ
173
+ * �������ڣ�2018��01��01��
174
+ * ע �⣺
175
+ *********************************************************************************************************/
176
+ static void Delay(u8 time)
177
+ {
178
+ DelayNus(50 * time);
179
+ }
180
+
181
+ /*********************************************************************************************************
182
+ * API����ʵ��
183
+ *********************************************************************************************************/
184
+ /*********************************************************************************************************
185
+ * �������ƣ�InitSCCB
186
+ * �������ܣ���ʼ��SCCB�ӿ�
187
+ * ���������void
188
+ * ���������void
189
+ * �� �� ֵ��void
190
+ * �������ڣ�2021��07��01��
191
+ * ע �⣺
192
+ *********************************************************************************************************/
193
+ void InitSCCB(void)
194
+ {
195
+ //��ʼ��IIC��GPIO
196
+ ConfigIICGPIO();
197
+
198
+ //����IIC
199
+ s_structIICDev.deviceID = SCCB_ID; //�豸ID
200
+ s_structIICDev.SetSCL = SetSCL; //����SCL��ƽֵ
201
+ s_structIICDev.SetSDA = SetSDA; //����SDA��ƽֵ
202
+ s_structIICDev.GetSDA = GetSDA; //��ȡSDA�����ƽ
203
+ s_structIICDev.ConfigSDAMode = ConfigSDAMode; //����SDA�����������
204
+ s_structIICDev.Delay = Delay; //��ʱ����
205
+ }
206
+
207
+ /*********************************************************************************************************
208
+ * �������ƣ�SCCBWriteReg
209
+ * �������ܣ�д�Ĵ���
210
+ * ���������reg���Ĵ�����ַ��data��Ҫд�������
211
+ * ���������void
212
+ * �� �� ֵ��0-�ɹ���1-ʧ��
213
+ * �������ڣ�2021��07��01��
214
+ * ע �⣺
215
+ *********************************************************************************************************/
216
+ u8 SCCBWriteReg(u8 reg, u8 data)
217
+ {
218
+ return IICCommonWriteBytes(&s_structIICDev, reg, &data, 1);
219
+ }
220
+
221
+ /*********************************************************************************************************
222
+ * �������ƣ�SCCBReadReg
223
+ * �������ܣ����Ĵ���
224
+ * ���������reg���Ĵ�����ַ
225
+ * ���������void
226
+ * �� �� ֵ�������ļĴ���ֵ
227
+ * �������ڣ�2021��07��01��
228
+ * ע �⣺
229
+ *********************************************************************************************************/
230
+ u8 SCCBReadReg(u8 reg)
231
+ {
232
+ u8 readData;
233
+ IICCommonReadBytes(&s_structIICDev, reg, &readData, 1, IIC_COMMON_NACK);
234
+ return readData;
235
+ }
236
+
deployment/GD32F470I_BluePill_ARMCC/App/Camera/SCCB.h ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�SCCB.h
3
+ * ժ Ҫ��SCCBЭ������
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+ #ifndef _SCCB_H_
17
+ #define _SCCB_H_
18
+
19
+ /*********************************************************************************************************
20
+ * ����ͷ�ļ�
21
+ *********************************************************************************************************/
22
+ #include "DataType.h"
23
+
24
+ /*********************************************************************************************************
25
+ * �궨��
26
+ *********************************************************************************************************/
27
+ #define SCCB_ID 0x60 //OV2640��ID
28
+
29
+ /*********************************************************************************************************
30
+ * ö�ٽṹ��
31
+ *********************************************************************************************************/
32
+
33
+ /*********************************************************************************************************
34
+ * API��������
35
+ *********************************************************************************************************/
36
+ void InitSCCB(void); //��ʼ��SCCB�ӿ�
37
+ u8 SCCBWriteReg(u8 reg,u8 data); //д�Ĵ���
38
+ u8 SCCBReadReg(u8 reg); //���Ĵ���
39
+
40
+ #endif
deployment/GD32F470I_BluePill_ARMCC/App/DataType/DataType.h ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�DataType.h
3
+ * ժ Ҫ���������Ͷ���
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�SZLY(COPYRIGHT 2018 - 2020 SZLY. All rights reserved.)
6
+ * ������ڣ�2020��01��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+ #ifndef _DATA_TYPE_H_
17
+ #define _DATA_TYPE_H_
18
+
19
+ /*********************************************************************************************************
20
+ * ����ͷ�ļ�
21
+ *********************************************************************************************************/
22
+
23
+ /*********************************************************************************************************
24
+ * �궨��
25
+ *********************************************************************************************************/
26
+
27
+ typedef signed char i8;
28
+ typedef signed short i16;
29
+ typedef signed int i32;
30
+ typedef unsigned char u8;
31
+ typedef unsigned short u16;
32
+ typedef unsigned int u32;
33
+ typedef unsigned long long u64;
34
+
35
+
36
+ // typedef int BOOL;
37
+ // typedef unsigned char BYTE;
38
+ // typedef unsigned short HWORD; //�����ֽ����һ������
39
+ // typedef unsigned int WORD; //�ĸ��ֽ����һ����
40
+ // typedef long LONG;
41
+
42
+ // #define LOHWORD(w) ((HWORD)(w)) //�ֵĵͰ���
43
+ // #define HIHWORD(w) ((HWORD)(((WORD)(w) >> 16) & 0xFFFF)) //�ֵĸ߰���
44
+
45
+ // #define LOBYTE(hw) ((BYTE)(hw) ) //���ֵĵ��ֽ�
46
+ // #define HIBYTE(hw) ((BYTE)(((WORD)(hw) >> 8) & 0xFF)) //���ֵĸ��ֽ�
47
+
48
+ // //�����ֽ����һ������
49
+ // #define MAKEHWORD(bH, bL) ((HWORD)(((BYTE)(bL)) | ((HWORD)((BYTE)(bH))) << 8))
50
+
51
+ // //�����������һ����
52
+ // #define MAKEWORD(hwH, hwL) ((WORD)(((HWORD)(hwL)) | ((WORD)((HWORD)(hwH))) << 16))
53
+
54
+ #define TRUE 1
55
+ #define FALSE 0
56
+ #define NULL 0
57
+ #define INVALID_DATA -100
58
+
59
+ /*********************************************************************************************************
60
+ * ö�ٽṹ��
61
+ *********************************************************************************************************/
62
+
63
+ /*********************************************************************************************************
64
+ * API��������
65
+ *********************************************************************************************************/
66
+
67
+ #endif
deployment/GD32F470I_BluePill_ARMCC/App/DbgMCU/CheckLineFeed.c ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * �����: CheckLineFeed.c
3
+ * ժ Ҫ: CheckLineFeedģ��
4
+ * ��ǰ�汾: 1.0.0
5
+ * �� ��: SZLY(COPYRIGHT 2019 SZLY. All rights reserved.)
6
+ * �������: 2019��08��01��
7
+ * �� ��:
8
+ * ע ��: none
9
+ **********************************************************************************************************
10
+ * ȡ���汾:
11
+ * �� ��:
12
+ * �������:
13
+ * �޸�����:
14
+ * �޸��ļ�:
15
+ *********************************************************************************************************/
16
+
17
+ /*********************************************************************************************************
18
+ * ����ͷ�ļ�
19
+ *********************************************************************************************************/
20
+ #include "CheckLineFeed.h"
21
+
22
+ /*********************************************************************************************************
23
+ * �궨��
24
+ *********************************************************************************************************/
25
+
26
+ /*********************************************************************************************************
27
+ * ö�ٽṹ�嶨��
28
+ *********************************************************************************************************/
29
+
30
+ /*********************************************************************************************************
31
+ * �ڲ�����
32
+ *********************************************************************************************************/
33
+ static u8 s_arrRecData[MAX_REC_DATA_CNT]; //�������ݻ�����
34
+ static i16 s_iDataCnt; //�������ݼ���
35
+ static u8 s_iRecLineFeedFlag = 0; //���յ����з���־λ��0-δ���յ����з���1-���յ����з�
36
+
37
+ /*********************************************************************************************************
38
+ * �ڲ���������
39
+ *********************************************************************************************************/
40
+
41
+ /*********************************************************************************************************
42
+ * �ڲ�����ʵ��
43
+ *********************************************************************************************************/
44
+ /*********************************************************************************************************
45
+ * API����ʵ��
46
+ *********************************************************************************************************/
47
+ /*********************************************************************************************************
48
+ * ��������: InitCheckLineFeed
49
+ * ��������: ��ʼ��CheckLineFeedģ��
50
+ * �������: void
51
+ * �������: void
52
+ * �� �� ֵ: void
53
+ * ��������: 2019��08��01��
54
+ * ע ��:
55
+ *********************************************************************************************************/
56
+ void InitCheckLineFeed(void)
57
+ {
58
+ i16 i;
59
+
60
+ for(i = 0; i < MAX_REC_DATA_CNT; i++)
61
+ {
62
+ s_arrRecData[i] = 0; //���������ݻ����������������
63
+ }
64
+
65
+ s_iDataCnt = 0; //�������ݼ�������
66
+ s_iRecLineFeedFlag = 0; //���յ����з���־���
67
+
68
+ }
69
+
70
+ /*********************************************************************************************************
71
+ * ��������: CheckLineFeed
72
+ * ��������: ����Ƿ���յ����з�
73
+ * �������: data�����յ�������
74
+ * �������: void
75
+ * �� �� ֵ: ���յ����з��ı�־��1-���յ����з���־��0-δ���յ����з���־
76
+ * ��������: 2019��08��01��
77
+ * ע ��:
78
+ *********************************************************************************************************/
79
+ u8 CheckLineFeed(u8 data)
80
+ {
81
+ static u8 s_iRec0x0DFlag = 0; //���յ�0x0D��־��1-���յ���0x0D��0-δ���յ�0x0D
82
+
83
+ if(0 == s_iRecLineFeedFlag) //δ������ɣ���δ���յ���0x0D 0x0A�����
84
+ {
85
+ if(1 == s_iRec0x0DFlag) //���յ���0x0D
86
+ {
87
+ if(data != 0x0A) //��������Ƿ���յ���0x0A
88
+ {
89
+ s_iRecLineFeedFlag = 0; //δ���յ�0x0A����ʾ���մ�����Ҫ���¿�ʼ
90
+ }
91
+ else
92
+ {
93
+ s_iRecLineFeedFlag = 1; //���յ���0x0A����ʾ�յ����з�����������ɱ�־��1
94
+ s_iRec0x0DFlag = 0; //������յ�0x0D��־�����¿�ʼ��һ�ֽ���
95
+ }
96
+ }
97
+ else
98
+ {
99
+ if(data == 0x0D)
100
+ {
101
+ s_iRec0x0DFlag = 1; //���յ�0x0D�������յ�0x0D��־��1
102
+ }
103
+ else
104
+ {
105
+ s_arrRecData[s_iDataCnt] = data;
106
+ s_iDataCnt++; //�洢���ݣ���ַ����
107
+
108
+ if(s_iDataCnt >= MAX_REC_DATA_CNT)
109
+ {
110
+ s_iRec0x0DFlag = 0; //������յ�0x0D��־�����¿�ʼ��һ�ֽ���
111
+ }
112
+ }
113
+ }
114
+ }
115
+
116
+ return s_iRecLineFeedFlag; //���ؽ��յ����з���־
117
+ }
118
+
119
+ /*********************************************************************************************************
120
+ * ��������: GetRecData
121
+ * ��������: ��ȡ���յ�������
122
+ * �������: void
123
+ * �������: pRecData�����յ����ݵ�ָ��
124
+ * �� �� ֵ: ���յ����ݵ�����
125
+ * ��������: 2019��08��01��
126
+ * ע ��: ��ȡ�����ݺ󣬴˺������Զ������յ����з���־���
127
+ *********************************************************************************************************/
128
+ i16 GetRecData(u8* pRecData)
129
+ {
130
+ i16 i;
131
+ i16 retCnt;
132
+
133
+ retCnt = s_iDataCnt;
134
+
135
+ for(i = 0; i < retCnt; i++)
136
+ {
137
+ pRecData[i] = s_arrRecData[i];
138
+ }
139
+
140
+ s_iDataCnt = 0;
141
+ s_iRecLineFeedFlag = 0;
142
+
143
+ return retCnt;
144
+ }
deployment/GD32F470I_BluePill_ARMCC/App/DbgMCU/CheckLineFeed.h ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * �����: CheckLineFeed.h
3
+ * ժ Ҫ: CheckLineFeedģ��
4
+ * ��ǰ�汾: 1.0.0
5
+ * �� ��: SZLY(COPYRIGHT 2019 SZLY. All rights reserved.)
6
+ * �������: 2019��08��01��
7
+ * �� ��:
8
+ * ע ��: none
9
+ **********************************************************************************************************
10
+ * ȡ���汾:
11
+ * �� ��:
12
+ * �������:
13
+ * �޸�����:
14
+ * �޸��ļ�:
15
+ *********************************************************************************************************/
16
+ #ifndef _CHECK_LINE_FEED_H_
17
+ #define _CHECK_LINE_FEED_H_
18
+
19
+ /*********************************************************************************************************
20
+ * ����ͷ�ļ�
21
+ *********************************************************************************************************/
22
+ #include "DataType.h"
23
+
24
+ /*********************************************************************************************************
25
+ * �궨��
26
+ *********************************************************************************************************/
27
+ #define MAX_REC_DATA_CNT 2048 //���յ����������ݣ�������32768��
28
+
29
+ /*********************************************************************************************************
30
+ * ö�ٽṹ�嶨��
31
+ *********************************************************************************************************/
32
+
33
+ /*********************************************************************************************************
34
+ * API��������
35
+ *********************************************************************************************************/
36
+ void InitCheckLineFeed(void); //��ʼ��
37
+ u8 CheckLineFeed(u8 data); //����Ƿ���յ����з�
38
+ i16 GetRecData(u8* pRecData); //��ȡ���յ�������,��ȡ�����ݺ󣬴˺������Զ������յ����з���־���
39
+
40
+ #endif
41
+
deployment/GD32F470I_BluePill_ARMCC/App/DbgMCU/DbgMCU.c ADDED
@@ -0,0 +1,387 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * �����: DbgMCU.c
3
+ * ժ Ҫ: �������
4
+ * ��ǰ�汾: 1.0.0
5
+ * �� ��: SZLY(COPYRIGHT 2019 SZLY. All rights reserved.)
6
+ * �������: 2019��08��01��
7
+ * �� ��:
8
+ * ע ��:
9
+ **********************************************************************************************************
10
+ * ȡ���汾:
11
+ * �� ��:
12
+ * �������:
13
+ * �޸�����:
14
+ * �޸��ļ�:
15
+ *********************************************************************************************************/
16
+
17
+ /*********************************************************************************************************
18
+ * ����ͷ�ļ�
19
+ *********************************************************************************************************/
20
+ #include "DbgMCU.h"
21
+ #include "DataType.h"
22
+ #include "stdlib.h"
23
+ #include "CheckLineFeed.h"
24
+ #include "stdio.h"
25
+ #include "UART0.h"
26
+ #include "DataType.h"
27
+ #include "BMPEncoder.h"
28
+ #include "RTC.h"
29
+ #include "InTemp.h"
30
+ #include "SHT20.h"
31
+
32
+ /*********************************************************************************************************
33
+ * �궨��
34
+ *********************************************************************************************************/
35
+ #define PARA_NUM_MAX 10 //��������������
36
+ #define FUNC_NUM_MAX 100 //�������Ӳ�����󳤶�
37
+
38
+ /*********************************************************************************************************
39
+ * ö�ٽṹ�嶨��
40
+ *********************************************************************************************************/
41
+ //��������ṹ��
42
+ typedef struct
43
+ {
44
+ void* func; //���Ժ���ָ��
45
+ u8 paraNum; //��������
46
+ char* name; //��������
47
+ }StructDbgMCU; //��������ṹ��
48
+
49
+ /*********************************************************************************************************
50
+ * �ڲ�����
51
+ *********************************************************************************************************/
52
+ //���������б�
53
+ static StructDbgMCU s_arrDbgMCUProc[] =
54
+ {
55
+ {PrintHelloWorld, 1, "PrintHelloWorld(num)" }, //PrintHelloWorld���Ժ���
56
+ {ScreeShot, 0, "ScreeShot(void)" }, //��ͼ
57
+ {RTCSet, 7, "RTCSet(year, month, date, week, hour, min, sec)"}, //����RTCʱ��
58
+ {RTCPrintTime, 0, "RTCPrintTime(void)" }, //��ʾʱ��
59
+ {RTCSetAlarm0, 3, "RTCSetAlarm0(hour, min, sec)" }, //��������0
60
+ {RTCSetAlarm1, 3, "RTCSetAlarm1(hour, min, sec)" }, //��������1
61
+ {PrintImTemp, 0, "PrintImTemp(void)" }, //��ӡCPU�ڲ��¶�
62
+ {PrintSHT20, 0, "PrintSHT20(void)" }, //��ӡ��ʪ����
63
+ };
64
+
65
+ static int s_iFuncId; //�����õ��ĺ���ID,��s_arrDbgMCUProc�������±�
66
+ static int s_arrPara[sizeof(s_arrDbgMCUProc) / sizeof(StructDbgMCU)][PARA_NUM_MAX]; //��ŵõ��ĺ�������
67
+
68
+ /*********************************************************************************************************
69
+ * �ڲ���������
70
+ *********************************************************************************************************/
71
+ static void DbgShowHelp(void); //��ʾ����
72
+ static void DbgMCUExe(void); //����ִ�к���
73
+ static u8 DbgMCUAnalyza(u8 *data); //���Է�������
74
+
75
+ /*********************************************************************************************************
76
+ * �ڲ�����ʵ��
77
+ *********************************************************************************************************/
78
+ /*********************************************************************************************************
79
+ * ��������: DbgShowHelp
80
+ * ��������: ��ʾ����
81
+ * �������: void
82
+ * �������: void
83
+ * �� �� ֵ: void
84
+ * ��������: 2019��08��01��
85
+ * ע ��:
86
+ *********************************************************************************************************/
87
+ static void DbgShowHelp(void)
88
+ {
89
+ int i = 0;
90
+
91
+ printf("\r\n");
92
+ printf("\r\n");
93
+ printf("------------------------DbgMCU V1.0.0-------------------------\r\n");
94
+ printf(" DbgMCU�������������Ƽ����޹�˾�з��ĵ��Թ��ߣ�ͨ��������Ժ�\r\n");
95
+ printf("����ĵ��ó����еĽӿڵ��Ժ�����ʹ�������dz����㡣\r\n");
96
+ printf(" DbgMCU���֧��10�������ĵ��Ժ�����֧�ָ���������Ҳ֧������ո�\r\n");
97
+ printf("ʹ��ʱ���ϸ��ո�ʽ���롣\r\n");
98
+ printf("\r\n");
99
+ printf("�������\r\n");
100
+ for (i = 0; i < (sizeof(s_arrDbgMCUProc) / sizeof(StructDbgMCU)); i++)
101
+ {
102
+ printf("ID:%d, Name:%s\r\n", i, s_arrDbgMCUProc[i].name);
103
+ }
104
+ printf("\r\n");
105
+ printf("ע�����\r\n");
106
+ printf("1�����ϸ���ո�ʽ���루ID������1������2��...����ʾ����0:1\r\n");
107
+ printf("2����֧�ֺ궨���������֧��ʮ���Ʋ�������ʹ��Ӣ���ַ�\r\n");
108
+ printf("2�����ŷָ����������з�Ϊ���������\r\n");
109
+ printf("4�����⡢Ѱ�⡢������WIFI���Ժ�����Ҫ��ʱ��������\r\n");
110
+ printf("-------SZLY(COPYRIGHT 2018-2020 SZLY. All rights reserved.)--------\r\n");
111
+ }
112
+
113
+ /*********************************************************************************************************
114
+ * ��������: DbgMCUExe
115
+ * ��������: ��������ִ�к���
116
+ * �������: void
117
+ * �������: void
118
+ * �� �� ֵ: void
119
+ * ��������: 2019��08��01��
120
+ * ע ��:
121
+ *********************************************************************************************************/
122
+ static void DbgMCUExe(void)
123
+ {
124
+ int i;
125
+ int para[PARA_NUM_MAX];
126
+ for (i = 0; i < s_arrDbgMCUProc[s_iFuncId].paraNum; i++)
127
+ {
128
+ para[i] = s_arrPara[s_iFuncId][i];
129
+ }
130
+
131
+ //��ӡִ����Ϣ
132
+ i = 0;
133
+ printf("\r\n");
134
+ while (('(' != *(s_arrDbgMCUProc[s_iFuncId].name + i)) && i < FUNC_NUM_MAX)
135
+ {
136
+ printf("%c", *(s_arrDbgMCUProc[s_iFuncId].name + i));
137
+ i++;
138
+ }
139
+ printf("(");
140
+ for (i = 0; i < s_arrDbgMCUProc[s_iFuncId].paraNum; i++)
141
+ {
142
+ printf("%d", para[i]);
143
+ if (i != (s_arrDbgMCUProc[s_iFuncId].paraNum - 1))
144
+ {
145
+ printf(", ");
146
+ }
147
+ }
148
+ printf(")\r\n");
149
+
150
+ //ִ�е��Ժ���
151
+ switch (s_arrDbgMCUProc[s_iFuncId].paraNum)
152
+ {
153
+ case 0:
154
+ (*(void(*)())s_arrDbgMCUProc[s_iFuncId].func)();
155
+ break;
156
+ case 1:
157
+ (*(void(*)())s_arrDbgMCUProc[s_iFuncId].func)(para[0]);
158
+ break;
159
+ case 2:
160
+ (*(void(*)())s_arrDbgMCUProc[s_iFuncId].func)(para[0], para[1]);
161
+ break;
162
+ case 3:
163
+ (*(void(*)())s_arrDbgMCUProc[s_iFuncId].func)(para[0], para[1], para[2]);
164
+ break;
165
+ case 4:
166
+ (*(void(*)())s_arrDbgMCUProc[s_iFuncId].func)(para[0], para[1], para[2], para[3]);
167
+ break;
168
+ case 5:
169
+ (*(void(*)())s_arrDbgMCUProc[s_iFuncId].func)(para[0], para[1], para[2], para[3], para[4]);
170
+ break;
171
+ case 6:
172
+ (*(void(*)())s_arrDbgMCUProc[s_iFuncId].func)(para[0], para[1], para[2], para[3], para[4], para[5]);
173
+ break;
174
+ case 7:
175
+ (*(void(*)())s_arrDbgMCUProc[s_iFuncId].func)(para[0], para[1], para[2], para[3], para[4], para[5],
176
+ para[6]);
177
+ break;
178
+ case 8:
179
+ (*(void(*)())s_arrDbgMCUProc[s_iFuncId].func)(para[0], para[1], para[2], para[3], para[4], para[5],
180
+ para[6], para[7]);
181
+ break;
182
+ case 9:
183
+ (*(void(*)())s_arrDbgMCUProc[s_iFuncId].func)(para[0], para[1], para[2], para[3], para[4], para[5],
184
+ para[6], para[7], para[8]);
185
+ break;
186
+ case 10:
187
+ (*(void(*)())s_arrDbgMCUProc[s_iFuncId].func)(para[0], para[1], para[2], para[3], para[4], para[5],
188
+ para[6], para[7], para[8], para[9]);
189
+ break;
190
+ default:
191
+ break;
192
+ }
193
+ }
194
+
195
+ /*********************************************************************************************************
196
+ * ��������: DbgMCUAnalyza
197
+ * ��������: �������ַ�����������ȡ����ID�����
198
+ * �������: void
199
+ * �������: void
200
+ * �� �� ֵ: ok: 0-ָ�����1-�ɹ���2-��ʾ������3-��������
201
+ * ��������: 2019��08��01��
202
+ * ע ��: ���ڶ�����IJ�����ȡ������̬��
203
+ *********************************************************************************************************/
204
+ static u8 DbgMCUAnalyza(u8 *data)
205
+ {
206
+ u8 i = 0;
207
+ u8 paraNum = 0;
208
+ u8 ok = 0;
209
+
210
+ char numBuf[124] = { '\0' };
211
+ int numMark = 0;
212
+ int id = 0;
213
+
214
+ //��ʾ����
215
+ if(('h' == *(data + 0)) && ('e' == *(data + 1)) && ('l' == *(data + 2)) && ('p' == *(data + 3)))
216
+ {
217
+ ok = 2;
218
+ return ok;
219
+ }
220
+
221
+ //����ð�Ų���ȡID
222
+ i = 0;
223
+ numMark = 0;
224
+ while ((':' != *(data + i)) && (i < FUNC_NUM_MAX)) //���ִ��FUNC_NUM_MAX��
225
+ {
226
+ if ((*(data + i) >= '0') && (*(data + i) <= '9'))
227
+ {
228
+ numBuf[numMark] = *(data + i);
229
+ numMark++;
230
+ }
231
+ i++;
232
+ }
233
+ if ((i == FUNC_NUM_MAX) || (0 == numMark))
234
+ {
235
+ ok = 0;
236
+ return ok; //����ָ�����
237
+ }
238
+ else if(numMark > 0)
239
+ {
240
+ numBuf[numMark] = '\0';
241
+ id = atoi(numBuf);
242
+ }
243
+
244
+ //����ID�ں�����Χ֮��
245
+ if (id < (sizeof(s_arrDbgMCUProc) / sizeof(StructDbgMCU)))
246
+ {
247
+ s_iFuncId = id;
248
+ }
249
+ else
250
+ {
251
+ ok = 0;
252
+ return ok; //����ָ�����
253
+ }
254
+
255
+ //��ȡ����
256
+ numMark = 0;
257
+ while (i < FUNC_NUM_MAX) //���ִ��FUNC_NUM_MAX��
258
+ {
259
+ //��������
260
+ if (',' == *(data + i))
261
+ {
262
+ numBuf[numMark] = '\0';
263
+ if (numMark > 0)
264
+ {
265
+ s_arrPara[s_iFuncId][paraNum] = atoi(numBuf);
266
+ paraNum++;
267
+ numMark = 0;
268
+ }
269
+ }
270
+
271
+ //����������ֹ��
272
+ else if ('\0' == *(data + i))
273
+ {
274
+ numBuf[numMark] = '\0';
275
+ if (numMark > 0)
276
+ {
277
+ s_arrPara[s_iFuncId][paraNum] = atoi(numBuf);
278
+ paraNum++;
279
+ }
280
+ ok = 1; //�ɹ���ȡ����
281
+ break;
282
+ }
283
+
284
+ //�����ں�����Χ֮��
285
+ else if(((*(data + i) >= '0') && (*(data + i) <= '9')) || '-' == *(data + i))
286
+ {
287
+ numBuf[numMark] = *(data + i);
288
+ numMark++;
289
+ }
290
+
291
+ i++;
292
+ }
293
+
294
+ //��������
295
+ if (paraNum != s_arrDbgMCUProc[s_iFuncId].paraNum)
296
+ {
297
+ ok = 3;
298
+ }
299
+
300
+ return ok;
301
+ }
302
+
303
+ /*********************************************************************************************************
304
+ * API����ʵ��
305
+ *********************************************************************************************************/
306
+ /*********************************************************************************************************
307
+ * ��������: InitDbgMCU
308
+ * ��������: ��ʼ���������
309
+ * �������: void
310
+ * �������: void
311
+ * �� �� ֵ: void
312
+ * ��������: 2019��08��01��
313
+ * ע ��:
314
+ *********************************************************************************************************/
315
+ void InitDbgMCU(void)
316
+ {
317
+ int i = 0;
318
+ int j = 0;
319
+
320
+ InitCheckLineFeed();
321
+ s_iFuncId = (sizeof(s_arrDbgMCUProc) / sizeof(StructDbgMCU)); //��ЧID
322
+
323
+ for (i = 0; i < (sizeof(s_arrDbgMCUProc) / sizeof(StructDbgMCU)); i++)
324
+ {
325
+ for (j = 0; j < PARA_NUM_MAX; j++)
326
+ {
327
+ s_arrPara[i][j] = 0;
328
+ }
329
+ }
330
+ }
331
+
332
+ /*********************************************************************************************************
333
+ * ��������: DbgMCUScan
334
+ * ��������: ����ɨ�躯��
335
+ * �������: void
336
+ * �������: void
337
+ * �� �� ֵ: void
338
+ * ��������: 2019��08��01��
339
+ * ע ��:
340
+ *********************************************************************************************************/
341
+ void DbgMCUScan(void) //����ɨ�躯��
342
+ {
343
+ u8 recData; //���յ�����
344
+ i16 recCnt; //���յ������ݼ�����
345
+ u8 arrData[MAX_REC_DATA_CNT]; //���ݻ�����
346
+
347
+ while (ReadUART0(&recData, 1))
348
+ {
349
+ if (1 == CheckLineFeed(recData))
350
+ {
351
+ recCnt = GetRecData(arrData);
352
+ arrData[recCnt] = '\0'; //��ĩβ���������
353
+
354
+ switch (DbgMCUAnalyza(arrData))
355
+ {
356
+ case 0:
357
+ printf("ָ�����\r\n");
358
+ break;
359
+ case 1:
360
+ DbgMCUExe();
361
+ break;
362
+ case 2:
363
+ DbgShowHelp();
364
+ break;
365
+ case 3:
366
+ printf("��������\r\n");
367
+ break;
368
+ default:
369
+ break;
370
+ }
371
+ }
372
+ }
373
+ }
374
+
375
+ /*********************************************************************************************************
376
+ * ��������: PrintHelloWorld
377
+ * ��������: ���Ժ���
378
+ * �������: void
379
+ * �������: void
380
+ * �� �� ֵ: void
381
+ * ��������: 2019��08��01��
382
+ * ע ��:
383
+ *********************************************************************************************************/
384
+ void PrintHelloWorld(int num)
385
+ {
386
+ printf("Hello World! The number you sent is : %d\r\n", num);
387
+ }
deployment/GD32F470I_BluePill_ARMCC/App/DbgMCU/DbgMCU.h ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * �����: DbgMCU.h
3
+ * ժ Ҫ: �������
4
+ * ��ǰ�汾: 1.0.0
5
+ * �� ��: SZLY(COPYRIGHT 2019 SZLY. All rights reserved.)
6
+ * �������: 2019��08��01��
7
+ * �� ��:
8
+ * ע ��: none
9
+ **********************************************************************************************************
10
+ * ȡ���汾:
11
+ * �� ��:
12
+ * �������:
13
+ * �޸�����:
14
+ * �޸��ļ�:
15
+ *********************************************************************************************************/
16
+ #ifndef _DBG_MCU_H_
17
+ #define _DBG_MCU_H_
18
+
19
+ /*********************************************************************************************************
20
+ * ����ͷ�ļ�
21
+ *********************************************************************************************************/
22
+
23
+ /*********************************************************************************************************
24
+ * �궨��
25
+ *********************************************************************************************************/
26
+
27
+ /*********************************************************************************************************
28
+ * ö�ٽṹ�嶨��
29
+ *********************************************************************************************************/
30
+
31
+ /*********************************************************************************************************
32
+ * API��������
33
+ *********************************************************************************************************/
34
+ void InitDbgMCU(void); //��ʼ���������
35
+ void DbgMCUScan(void); //�������ɨ�躯��
36
+ void PrintHelloWorld(int num); //���Ժ���
37
+
38
+ #endif
39
+
40
+
deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/BookByteRead.c ADDED
@@ -0,0 +1,256 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�BookByteRead.h
3
+ * ժ Ҫ�����ֽڴ��ı��ļ��ж�ȡ����ģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺SD����д�������ݿ����ʽ���У�ÿ�ζ�д512���ֽڣ�Ϊ�����SD����дЧ�ʣ���Ҫ��ר�ŵ�ģ�����SD����д
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+
17
+ /*********************************************************************************************************
18
+ * ����ͷ�ļ�
19
+ *********************************************************************************************************/
20
+ #include "BookByteRead.h"
21
+ #include "ff.h"
22
+ #include "stdio.h"
23
+
24
+ /*********************************************************************************************************
25
+ * �궨��
26
+ *********************************************************************************************************/
27
+ #define BOOK_READ_BUF_SIZE (1024 * 5) //SD�����ʶ�ȡ����������Ҫ��4����������
28
+
29
+ /*********************************************************************************************************
30
+ * ö�ٽṹ�嶨��
31
+ *********************************************************************************************************/
32
+
33
+ /*********************************************************************************************************
34
+ * �ڲ�����
35
+ *********************************************************************************************************/
36
+ static FIL s_fileBook; //�ı��ļ�
37
+ static char s_arrReadBuf[BOOK_READ_BUF_SIZE]; //��ȡ������
38
+ static u32 s_iByteRemain = 0; //��������ʣ���ֽ�����Ϊ0ʱ��ʾ��Ҫ���ļ��ж�ȡ������
39
+ static u32 s_iEndFlag = 0; //�ļ���ȡ��ϱ�־λ��Ϊ1ʱ��ʾ�ļ��е������ѱ�ȫ����ȡ
40
+ static u32 s_iFilePos = 0; //�ļ���ȡλ��
41
+ static u32 s_iByteCnt = 0; //��ȡ�ֽڼ���
42
+ static u32 s_iBookSize = 0; //�鱾��С���ֽڣ�
43
+
44
+ /*********************************************************************************************************
45
+ * �ڲ���������
46
+ *********************************************************************************************************/
47
+ static u32 ReadData(void); //����һ������
48
+
49
+ /*********************************************************************************************************
50
+ * �ڲ�����ʵ��
51
+ *********************************************************************************************************/
52
+ /*********************************************************************************************************
53
+ * �������ƣ�ReadData
54
+ * �������ܣ�����һ������
55
+ * ���������void
56
+ * ���������void
57
+ * �� �� ֵ��1-��ȡ�ɹ���0-��ȡʧ��
58
+ * �������ڣ�2021��07��01��
59
+ * ע �⣺
60
+ *********************************************************************************************************/
61
+ static u32 ReadData(void)
62
+ {
63
+ //�ļ���������ֵ
64
+ FRESULT result;
65
+
66
+ //ѭ������
67
+ u32 i;
68
+
69
+ //���ļ�
70
+ result = f_open(&s_fileBook, "0:/book/���μ�.txt", FA_OPEN_EXISTING | FA_READ);
71
+ if (result != FR_OK)
72
+ {
73
+ printf("BookByteRead: ��ָ���ļ�ʧ��\r\n");
74
+ return 0;
75
+ }
76
+
77
+ //���ö�ȡλ�ã�Ҫȷ����ȡλ��Ϊ4�ı�������Ȼ�Ῠ����
78
+ result = f_lseek(&s_fileBook, s_iFilePos * BOOK_READ_BUF_SIZE);
79
+ if (result != FR_OK)
80
+ {
81
+ printf("BookByteRead: ���ö�ȡλ��ʧ��\r\n");
82
+ return 0;
83
+ }
84
+
85
+ //�建����
86
+ for(i = 0; i < BOOK_READ_BUF_SIZE; i++)
87
+ {
88
+ s_arrReadBuf[i] = 0;
89
+ }
90
+
91
+ //��ȡһ������
92
+ result = f_read(&s_fileBook, s_arrReadBuf, BOOK_READ_BUF_SIZE, &s_iByteRemain);
93
+ if (result != FR_OK)
94
+ {
95
+ printf("BookByteRead: ��ȡ����ʧ��\r\n");
96
+ return 0;
97
+ }
98
+
99
+ //���¶�ȡλ��
100
+ s_iFilePos = s_iFilePos + 1;
101
+
102
+ //�ж��Dz����ļ������һ������
103
+ if(s_fileBook.fptr >= s_fileBook.fsize)
104
+ {
105
+ s_iEndFlag = 1;
106
+ }
107
+
108
+ //����ͼ���С
109
+ s_iBookSize = s_fileBook.fsize;
110
+
111
+ //�ر��ļ�
112
+ result = f_close(&s_fileBook);
113
+ if (result != FR_OK)
114
+ {
115
+ printf("BookByteRead: �ر�ָ���ļ�ʧ��\r\n");
116
+ return 0;
117
+ }
118
+
119
+ return 1;
120
+ }
121
+
122
+ /*********************************************************************************************************
123
+ * API����ʵ��
124
+ *********************************************************************************************************/
125
+ /*********************************************************************************************************
126
+ * �������ƣ�ReadBookByte
127
+ * �������ܣ���ȡ1�ֽ�����
128
+ * ���������byte���������ݴ�������visi����ǰ�ַ���ʼ�����ж��ٸ������ַ���������ǰ�ַ���
129
+ * ���������void
130
+ * �� �� ֵ��1-��ȡ�ɹ���0-��ȡʧ��
131
+ * �������ڣ�2021��07��01��
132
+ * ע �⣺
133
+ *********************************************************************************************************/
134
+ u32 ReadBookByte(char* byte, u32* visi)
135
+ {
136
+ u32 result; //�ļ���������ֵ
137
+ u32 visible; //�����ַ�ͳ��
138
+
139
+ //��ǰ��������ʣ���ֽ���Ϊ0����Ҫ��ȡ��һ������
140
+ if((0 == s_iByteRemain) && (0 == s_iEndFlag))
141
+ {
142
+ //��ȡһ������
143
+ result = ReadData();
144
+ if(0 == result)
145
+ {
146
+ return 0;
147
+ }
148
+
149
+ //��ȡ�ֽڼ�������
150
+ s_iByteCnt = 0;
151
+ }
152
+
153
+ //��ǰ��������ʣ���ֽ���Ϊ0�������ļ���ȫ����ȡ���
154
+ else if((0 == s_iByteRemain) && (1 == s_iEndFlag))
155
+ {
156
+ return 0;
157
+ }
158
+
159
+ //����ֽ�����
160
+ *byte = s_arrReadBuf[s_iByteCnt];
161
+
162
+ //�����ַ�ͳ��
163
+ visible = 0;
164
+ while(1)
165
+ {
166
+ //��������Ƿ�Խ��
167
+ if((s_iByteCnt + visible + 1) >= BOOK_READ_BUF_SIZE)
168
+ {
169
+ break;
170
+ }
171
+
172
+ //���ҵ��˷ǿ����ַ�
173
+ if(s_arrReadBuf[s_iByteCnt + visible + 1] <= ' ')
174
+ {
175
+ break;
176
+ }
177
+ visible++;
178
+ }
179
+ *visi = visible;
180
+
181
+ //���¼���
182
+ s_iByteCnt++;
183
+ s_iByteRemain--;
184
+
185
+ //��ȡ�ɹ�
186
+ return 1;
187
+ }
188
+
189
+ /*********************************************************************************************************
190
+ * �������ƣ�GetBytePosition
191
+ * �������ܣ���ȡ��ǰ�ֽ����ı��ļ��е�λ��
192
+ * ���������void
193
+ * ���������void
194
+ * �� �� ֵ����ȡ��ǰ�ֽ����ı��ļ��е�λ��
195
+ * �������ڣ�2021��07��01��
196
+ * ע �⣺��ǰ�ֽ�ָ���ǽ�Ҫ��ȡ���ֽ�
197
+ *********************************************************************************************************/
198
+ u32 GetBytePosition(void)
199
+ {
200
+ //��δ��SD����ȡ�κ�����
201
+ if(0 == s_iFilePos)
202
+ {
203
+ return 0;
204
+ }
205
+ else
206
+ {
207
+ return ((s_iFilePos - 1) * BOOK_READ_BUF_SIZE + s_iByteCnt);
208
+ }
209
+ }
210
+
211
+ /*********************************************************************************************************
212
+ * �������ƣ�SetPosision
213
+ * �������ܣ����ö�ȡλ��
214
+ * ���������void
215
+ * ���������void
216
+ * �� �� ֵ��1-���óɹ���0-����ʧ��
217
+ * �������ڣ�2021��07��01��
218
+ * ע �⣺����Ķ�ȡλ����ָ�ļ��еĶ�ȡλ��
219
+ *********************************************************************************************************/
220
+ u32 SetPosision(u32 posision)
221
+ {
222
+ //��ȡλ�ó����ļ���С
223
+ if((posision >= s_iBookSize) && (0 != s_iBookSize))
224
+ {
225
+ return 0;
226
+ }
227
+
228
+ //������һ������
229
+ s_iFilePos = posision / BOOK_READ_BUF_SIZE;
230
+ if(0 == ReadData())
231
+ {
232
+ return 0;
233
+ }
234
+
235
+ //���¶�ȡ�ֽڼ���
236
+ s_iByteCnt = posision % BOOK_READ_BUF_SIZE;
237
+
238
+ //���»�����ʣ����
239
+ s_iByteRemain = s_iByteRemain - s_iByteCnt;
240
+
241
+ return 1;
242
+ }
243
+
244
+ /*********************************************************************************************************
245
+ * �������ƣ�GetBookSize
246
+ * �������ܣ���ȡ�鱾��С
247
+ * ���������void
248
+ * ���������void
249
+ * �� �� ֵ���鱾��С���ֽڣ�
250
+ * �������ڣ�2021��07��01��
251
+ * ע �⣺
252
+ *********************************************************************************************************/
253
+ u32 GetBookSize(void)
254
+ {
255
+ return s_iBookSize;
256
+ }
deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/BookByteRead.h ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�BookByteRead.h
3
+ * ժ Ҫ�����ֽڴ��ı��ļ��ж�ȡ����ģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺SD����д�������ݿ����ʽ���У�ÿ�ζ�д512���ֽڣ�Ϊ�����SD����дЧ�ʣ���Ҫ��ר�ŵ�ģ�����SD����д
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+ #ifndef _BOOK_BYTE_READ_H_
17
+ #define _BOOK_BYTE_READ_H_
18
+
19
+ /*********************************************************************************************************
20
+ * ����ͷ�ļ�
21
+ *********************************************************************************************************/
22
+ #include "DataType.h"
23
+
24
+ /*********************************************************************************************************
25
+ * �궨��
26
+ *********************************************************************************************************/
27
+
28
+ /*********************************************************************************************************
29
+ * ö�ٽṹ�嶨��
30
+ *********************************************************************************************************/
31
+
32
+ /*********************************************************************************************************
33
+ * API��������
34
+ *********************************************************************************************************/
35
+ u32 ReadBookByte(char* byte, u32* visi); //��ȡһ���ֽ�
36
+ u32 GetBytePosition(void); //��ȡ��ǰ�ֽ����ı��ļ��е�λ��
37
+ u32 SetPosision(u32 posision); //���ö�ȡλ��
38
+ u32 GetBookSize(void); //��ȡ�鱾��С
39
+
40
+ #endif
deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/Canvas.c ADDED
@@ -0,0 +1,361 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�Canvas.c
3
+ * ժ Ҫ������ģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+
17
+ /*********************************************************************************************************
18
+ * ����ͷ�ļ�
19
+ *********************************************************************************************************/
20
+ #include "Canvas.h"
21
+ #include "gd32f450x_conf.h"
22
+ #include "stdio.h"
23
+ #include "Touch.h"
24
+ #include "TLILCD.h"
25
+ #include "JPEG.h"
26
+ #include "TextWidget.h"
27
+
28
+ /*********************************************************************************************************
29
+ * �궨��
30
+ *********************************************************************************************************/
31
+
32
+ /*********************************************************************************************************
33
+ * ö�ٽṹ�嶨��
34
+ *********************************************************************************************************/
35
+
36
+ /*********************************************************************************************************
37
+ * �ڲ�����
38
+ *********************************************************************************************************/
39
+ //������ɫ
40
+ static const u16 s_arrLineColor[5] = {LCD_COLOR_YELLOW, LCD_COLOR_GREEN, LCD_COLOR_BLUE, LCD_COLOR_CYAN, LCD_COLOR_RED};
41
+ static StructTextWidget s_arrText[5]; //text�ؼ�����ʾ������Ϣ
42
+ static StructTouchDev* s_pTouchDev; //������ɨ����
43
+
44
+ /*********************************************************************************************************
45
+ * �ڲ���������
46
+ *********************************************************************************************************/
47
+ static void DrawPoint(u16 x0,u16 y0, u16 r, u16 color); //����ʵ��Բ
48
+ static void DrawLine(u16 x0, u16 y0, u16 x1, u16 y1, u16 size, u16 color); //����ֱ��
49
+ static void DisplayBackground(void); //���Ʊ���
50
+
51
+ /*********************************************************************************************************
52
+ * �ڲ�����ʵ��
53
+ *********************************************************************************************************/
54
+ /*********************************************************************************************************
55
+ * �������ƣ�DrawPoint
56
+ * �������ܣ�����ʵ��Բ
57
+ * �����������x0��y0����Բ�����꣬r���뾶��color����ɫ
58
+ * ���������void
59
+ * �� �� ֵ��void
60
+ * �������ڣ�2021��07��01��
61
+ * ע �⣺
62
+ *********************************************************************************************************/
63
+ static void DrawPoint(u16 x0,u16 y0, u16 r, u16 color)
64
+ {
65
+ int a, b;
66
+ int di;
67
+ a = 0; b = r;
68
+ di = 3 - (r << 1); //�ж��¸���λ�õı�־
69
+ while(a <= b)
70
+ {
71
+ int i = a, p = b;
72
+ while(i > 0)
73
+ {
74
+ LCDDrawPoint(x0+b,y0-i, color);
75
+ LCDDrawPoint(x0-i,y0+b, color);
76
+ i--;
77
+ }
78
+ while( p > 0)
79
+ {
80
+ LCDDrawPoint(x0 - a, y0 - p, color);
81
+ LCDDrawPoint(x0 - p, y0 - a, color);
82
+ LCDDrawPoint(x0 + a, y0 - p, color);
83
+ LCDDrawPoint(x0 - p, y0 + a, color);
84
+ LCDDrawPoint(x0 + a, y0 + p, color);
85
+ LCDDrawPoint(x0 + p, y0 + a, color);
86
+ p--;
87
+ }
88
+ a++;
89
+
90
+ //Bresenham�㷨��Բ
91
+ if(di < 0)
92
+ {
93
+ di += 4 * a + 6;
94
+ }
95
+ else
96
+ {
97
+ di += 10 + 4 * (a - b);
98
+ b--;
99
+ }
100
+ }
101
+ LCDDrawPoint(x0, y0, color); //Բ������
102
+ }
103
+ /*********************************************************************************************************
104
+ * �������ƣ�DrawLine
105
+ * �������ܣ�����ֱ��
106
+ * �����������x0��y0����������꣬��x1��y1�����յ����꣬size��ֱ�ߴ�ϸ��color����ɫ
107
+ * ���������void
108
+ * �� �� ֵ��void
109
+ * �������ڣ�2021��07��01��
110
+ * ע �⣺ֱ��̫�ֻᵼ�»��ƻ���
111
+ *********************************************************************************************************/
112
+ static void DrawLine(u16 x0, u16 y0, u16 x1, u16 y1, u16 size, u16 color)
113
+ {
114
+ u16 t;
115
+ int xerr = 0, yerr = 0, delta_x, delta_y, distance;
116
+ int incx, incy, uRow, uCol;
117
+ delta_x = x1 - x0; //������������
118
+ delta_y = y1 - y0;
119
+ uRow = x0;
120
+ uCol = y0;
121
+
122
+ //���õ�������
123
+ if(delta_x > 0)
124
+ {
125
+ incx=1;
126
+ }
127
+
128
+ //��ֱ��
129
+ else if(delta_x==0)
130
+ {
131
+ incx=0;
132
+ }
133
+ else
134
+ {
135
+ incx = -1;
136
+ delta_x =- delta_x;
137
+ }
138
+
139
+ if(delta_y > 0)
140
+ {
141
+ incy = 1;
142
+ }
143
+
144
+ //ˮƽ��
145
+ else if(delta_y == 0)
146
+ {
147
+ incy = 0;
148
+ }
149
+ else
150
+ {
151
+ incy = -1;
152
+ delta_y =- delta_y;
153
+ }
154
+
155
+ //ѡȡ��������������
156
+ if( delta_x>delta_y)
157
+ {
158
+ distance = delta_x;
159
+ }
160
+ else
161
+ {
162
+ distance = delta_y;
163
+ }
164
+
165
+ //�������
166
+ for(t = 0; t <= distance + 1; t++ )
167
+ {
168
+ DrawPoint(uRow, uCol, size, color);
169
+ xerr += delta_x ;
170
+ yerr += delta_y ;
171
+ if(xerr > distance)
172
+ {
173
+ xerr -= distance;
174
+ uRow += incx;
175
+ }
176
+ if(yerr > distance)
177
+ {
178
+ yerr -= distance;
179
+ uCol += incy;
180
+ }
181
+ }
182
+ }
183
+ /*********************************************************************************************************
184
+ * �������ƣ�DisplayBackground
185
+ * �������ܣ����Ʊ���
186
+ * ���������void
187
+ * ���������void
188
+ * �� �� ֵ��void
189
+ * �������ڣ�2021��07��01��
190
+ * ע �⣺����֮ǰҪȷ��LCD����Ϊ����
191
+ *********************************************************************************************************/
192
+ static void DisplayBackground(void)
193
+ {
194
+ //����ͼƬ���ƽṹ��
195
+ StructJpegImage backgroundImage;
196
+
197
+ //��ʼ��backgroundImage
198
+ backgroundImage.image = (unsigned char*)s_arrJpegBackgroundImage;
199
+ backgroundImage.size = sizeof(s_arrJpegBackgroundImage) / sizeof(unsigned char);
200
+
201
+ //���벢��ʾͼƬ
202
+ DisplayJPEGInFlash(&backgroundImage, 0, 0);
203
+ }
204
+ /*********************************************************************************************************
205
+ * �������ƣ�CreateText
206
+ * �������ܣ�����text�ؼ�������ʾ������
207
+ * ���������void
208
+ * ���������void
209
+ * �� �� ֵ��0-�����ɹ�������-����ʧ��
210
+ * �������ڣ�2021��07��01��
211
+ * ע �⣺����֮ǰҪȷ��LCD����Ϊ����
212
+ *********************************************************************************************************/
213
+ static u8 CreateText(void)
214
+ {
215
+ static const u16 s_arrTextX0[5] = {65, 224, 384, 543, 703}; //text�ؼ���ʼ������
216
+ u16 i = 0; //ѭ������
217
+
218
+ for(i = 0; i < 5; i++)
219
+ {
220
+ //����text
221
+ s_arrText[i].x0 = s_arrTextX0[i]; //�ؼ���ʼ������
222
+ s_arrText[i].y0 = 52; //�ؼ���ʼ������
223
+ s_arrText[i].width = 83; //�ؼ�����
224
+ s_arrText[i].height = 24; //�ؼ��߶�
225
+ s_arrText[i].size = 24; //�����С
226
+ s_arrText[i].color = LCD_COLOR_WHITE; //������ɫ
227
+ CreateTextWidget(&s_arrText[i]); //����text�ؼ�
228
+ }
229
+
230
+ return 0;
231
+ }
232
+
233
+ /*********************************************************************************************************
234
+ * API����ʵ��
235
+ *********************************************************************************************************/
236
+ /*********************************************************************************************************
237
+ * �������ƣ�InitCanvas
238
+ * �������ܣ���ʼ������
239
+ * ���������void
240
+ * ���������void
241
+ * �� �� ֵ��void
242
+ * �������ڣ�2021��07��01��
243
+ * ע �⣺
244
+ *********************************************************************************************************/
245
+ void InitCanvas(void)
246
+ {
247
+ //LCD������ʾ
248
+ LCDDisplayDir(LCD_SCREEN_HORIZONTAL);
249
+ LCDClear(LCD_COLOR_BLUE);
250
+
251
+ //���Ʊ���
252
+ DisplayBackground();
253
+
254
+ //����text�ؼ�
255
+ CreateText();
256
+
257
+ //��ȡ������ɨ���豸�ṹ���ַ
258
+ s_pTouchDev = GetTouchDev();
259
+ }
260
+
261
+ /*********************************************************************************************************
262
+ * �������ƣ�CanvasTask
263
+ * �������ܣ���������
264
+ * ���������void
265
+ * ���������void
266
+ * �� �� ֵ��void
267
+ * �������ڣ�2021��07��01��
268
+ * ע �⣺
269
+ *********************************************************************************************************/
270
+ void CanvasTask(void)
271
+ {
272
+ static char s_arrString[20] = {0}; //�ַ���ת��������
273
+ static u8 s_arrFirstFlag[5] = {1, 1, 1, 1, 1}; //��������Ƿ��ѿ�ʼ����
274
+ static StructTouchPoint s_arrLastPoints[5]; //��һ���������
275
+
276
+ u8 i;
277
+ u16 x0, y0, x1, y1, size, color;
278
+
279
+ //ѭ������5����
280
+ for(i = 0; i < 5; i++)
281
+ {
282
+ //�м�⵽����
283
+ if(1 == s_pTouchDev->pointFlag[i])
284
+ {
285
+ //�ַ���ת��
286
+ sprintf(s_arrString, "%d,%d", s_pTouchDev->point[i].x, s_pTouchDev->point[i].y);
287
+
288
+ //���µ�text��ʾ
289
+ s_arrText[i].setText(&s_arrText[i], s_arrString);
290
+
291
+ //�������յ����ꡢ��ɫ�ʹ����С
292
+ x0 = s_arrLastPoints[i].x;
293
+ y0 = s_arrLastPoints[i].y;
294
+ x1 = s_pTouchDev->point[i].x;
295
+ y1 = s_pTouchDev->point[i].y;
296
+ color = s_arrLineColor[i];
297
+ size = s_pTouchDev->point[i].size;
298
+
299
+ //����̫����Ҫ��С����
300
+ size = size / 5;
301
+ if(0 == size)
302
+ {
303
+ size = 1;
304
+ }
305
+ else if(size > 15)
306
+ {
307
+ size = 15;
308
+ }
309
+
310
+ //������һ�����û��㷽ʽ
311
+ if(1 == s_arrFirstFlag[i])
312
+ {
313
+ //��������Ѿ���ʼ����
314
+ s_arrFirstFlag[i] = 0;
315
+
316
+ //����
317
+ if(y0 > (90 + size))
318
+ {
319
+ DrawPoint(x0, y0, size, color);
320
+ }
321
+
322
+ //Խ��
323
+ else
324
+ {
325
+ //��Ǹ�����δ��ʼ����
326
+ s_arrFirstFlag[i] = 1;
327
+ }
328
+ }
329
+
330
+ //��ߵ��û��߷�ʽ
331
+ else
332
+ {
333
+ //����
334
+ if((y0 > (90 + size)) && (y1 > (90 + size)))
335
+ {
336
+ DrawLine(x0, y0, x1, y1, size, color);
337
+ }
338
+
339
+ //Խ��
340
+ else
341
+ {
342
+ //��Ǹ�����δ��ʼ����
343
+ s_arrFirstFlag[i] = 1;
344
+ }
345
+ }
346
+
347
+ //���浱ǰλ�ã�Ϊ������׼��
348
+ s_arrLastPoints[i].x = s_pTouchDev->point[i].x;
349
+ s_arrLastPoints[i].y = s_pTouchDev->point[i].y;
350
+ }
351
+ else
352
+ {
353
+ //δ��⵽�������������ʾ
354
+ s_arrText[i].setText(&s_arrText[i], "");
355
+
356
+ //��Ǹ�����δ��ʼ����
357
+ s_arrFirstFlag[i] = 1;
358
+ }
359
+ }
360
+ }
361
+
deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/Canvas.h ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�Canvas.h
3
+ * ժ Ҫ������ģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+ #ifndef _CANVAS_H_
17
+ #define _CANVAS_H_
18
+
19
+ /*********************************************************************************************************
20
+ * ����ͷ�ļ�
21
+ *********************************************************************************************************/
22
+ #include "DataType.h"
23
+
24
+ /*********************************************************************************************************
25
+ * �궨��
26
+ *********************************************************************************************************/
27
+
28
+ /*********************************************************************************************************
29
+ * ö�ٽṹ�嶨��
30
+ *********************************************************************************************************/
31
+
32
+ /*********************************************************************************************************
33
+ * API��������
34
+ *********************************************************************************************************/
35
+ void InitCanvas(void); //��ʼ������
36
+ void CanvasTask(void); //��������
37
+
38
+ #endif
deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUIBreathLED.c ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�GUIBreathLED.c
3
+ * ժ Ҫ����������ʾģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+
17
+ /*********************************************************************************************************
18
+ * ����ͷ�ļ�
19
+ *********************************************************************************************************/
20
+ #include "GUIBreathLED.h"
21
+ #include "TLILCD.h"
22
+ #include "GUIPlatform.h"
23
+ #include "GraphWidget.h"
24
+ #include "BMP.h"
25
+ #include "Common.h"
26
+ #include "SliderWidget.h"
27
+ #include "BreathLED.h"
28
+
29
+ /*********************************************************************************************************
30
+ * �궨��
31
+ *********************************************************************************************************/
32
+
33
+ /*********************************************************************************************************
34
+ * ö�ٽṹ�嶨��
35
+ *********************************************************************************************************/
36
+
37
+ /*********************************************************************************************************
38
+ * �ڲ�����
39
+ *********************************************************************************************************/
40
+ static StructSliderWidget s_structSlider; //�����ؼ�
41
+ static u16 s_arrSliderBackground[20 * 1024]; //��������������
42
+
43
+ /*********************************************************************************************************
44
+ * �ڲ���������
45
+ *********************************************************************************************************/
46
+
47
+ /*********************************************************************************************************
48
+ * �ڲ�����ʵ��
49
+ *********************************************************************************************************/
50
+
51
+ /*********************************************************************************************************
52
+ * API����ʵ��
53
+ *********************************************************************************************************/
54
+ /*********************************************************************************************************
55
+ * �������ƣ�CreateGUIBreathLED
56
+ * �������ܣ�������������ʾģ��
57
+ * ���������void
58
+ * ���������void
59
+ * �� �� ֵ��void
60
+ * �������ڣ�2021��07��01��
61
+ * ע �⣺
62
+ *********************************************************************************************************/
63
+ void CreateGUIBreathLED(void)
64
+ {
65
+ static StructBmpImage s_structPoint;
66
+
67
+ //LCD������ʾ
68
+ LCDDisplayDir(LCD_SCREEN_HORIZONTAL);
69
+
70
+ //���Ʊ���
71
+ DisPlayBMPByIPA(0, 0, BREATH_LED_BACKGROUND_DIR);
72
+
73
+ //��ʼ��������
74
+ InitBreathLED();
75
+
76
+ //���������ؼ�
77
+ s_structPoint.alphaType = BMP_UES_ALPHA;
78
+ s_structPoint.storageType = BMP_IN_FATFS;
79
+ s_structPoint.addr = (void*)BREATH_LED_POINT_DIR;
80
+ InitSliderWidgetStruct(&s_structSlider);
81
+ s_structSlider.x0 = 100; //��ʼ������
82
+ s_structSlider.y0 = 300; //��ʼ������
83
+ s_structSlider.width = 600; //����
84
+ s_structSlider.height = 30; //�߶�
85
+ s_structSlider.value = 50; //����Ԥ���ã�0-100��
86
+ s_structSlider.lineImage = NULL; //������ʹ��ˢͼƬ��ʽ
87
+ s_structSlider.circleImage = (void*)&s_structPoint; //����Բ��ͼƬ
88
+ s_structSlider.lineSize = 4; //���߿���Ϊ4
89
+ s_structSlider.lineColor = 0xFDCA; //������ɫ
90
+ s_structSlider.circleColor = 0xFDCA; //Բ����ɫ
91
+ s_structSlider.background = (u32)s_arrSliderBackground; //����������
92
+ CreateSliderWidget(&s_structSlider); //���������ؼ�
93
+ }
94
+
95
+ /*********************************************************************************************************
96
+ * �������ƣ�DeleteGUIBreathLED
97
+ * �������ܣ�ɾ����������ʾģ��
98
+ * ���������void
99
+ * ���������void
100
+ * �� �� ֵ��void
101
+ * �������ڣ�2021��07��01��
102
+ * ע �⣺
103
+ *********************************************************************************************************/
104
+ void DeleteGUIBreathLED(void)
105
+ {
106
+ DeInitBreathLED();
107
+ }
108
+
109
+ /*********************************************************************************************************
110
+ * �������ƣ�GUIBreathLEDPoll
111
+ * �������ܣ���������ѯ����
112
+ * ���������void
113
+ * ���������void
114
+ * �� �� ֵ��void
115
+ * �������ڣ�2021��07��01��
116
+ * ע �⣺
117
+ *********************************************************************************************************/
118
+ void GUIBreathLEDPoll(void)
119
+ {
120
+ u32 period;
121
+
122
+ //������ɨ��
123
+ ScanSliderWidget(&s_structSlider);
124
+
125
+ //��ȡ����������
126
+ period = 2500 * s_structSlider.value / 100;
127
+ if(period < 50)
128
+ {
129
+ period = 50;
130
+ }
131
+
132
+ //����������
133
+ BreathLEDTask(period);
134
+ }
deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUIBreathLED.h ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�GUIBreathLED.h
3
+ * ժ Ҫ����������ʾģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+ #ifndef _GUI_BREATH_LED_H_
17
+ #define _GUI_BREATH_LED_H_
18
+
19
+ /*********************************************************************************************************
20
+ * ����ͷ�ļ�
21
+ *********************************************************************************************************/
22
+ #include "DataType.h"
23
+
24
+ /*********************************************************************************************************
25
+ * �궨��
26
+ *********************************************************************************************************/
27
+
28
+ /*********************************************************************************************************
29
+ * ö�ٽṹ�嶨��
30
+ *********************************************************************************************************/
31
+
32
+ /*********************************************************************************************************
33
+ * API��������
34
+ *********************************************************************************************************/
35
+ void CreateGUIBreathLED(void); //������������ʾģ��
36
+ void DeleteGUIBreathLED(void); //ɾ����������ʾģ��
37
+ void GUIBreathLEDPoll(void); //��������ѯ����
38
+
39
+ #endif
deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUICAN.c ADDED
@@ -0,0 +1,659 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�GUICAN.c
3
+ * ժ Ҫ��GUI CANͨ��ģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+
17
+ /*********************************************************************************************************
18
+ * ����ͷ�ļ�
19
+ *********************************************************************************************************/
20
+ #include "GUICAN.h"
21
+ #include "GUIPlatform.h"
22
+ #include "ButtonWidget.h"
23
+ #include "LineEditWidget.h"
24
+ #include "TerminalWidget.h"
25
+ #include "BMP.h"
26
+ #include "JPEG.h"
27
+ #include "Common.h"
28
+ #include "TLILCD.h"
29
+ #include "CAN.h"
30
+
31
+ /*********************************************************************************************************
32
+ * �궨��
33
+ *********************************************************************************************************/
34
+
35
+ /*********************************************************************************************************
36
+ * ö�ٽṹ�嶨��
37
+ *********************************************************************************************************/
38
+ typedef enum
39
+ {
40
+ GUI_BUTTON_K0 = 0, //K0�����������Ǵ�0��ʼ
41
+ GUI_BUTTON_K1, //K1����
42
+ GUI_BUTTON_K2, //K2����
43
+ GUI_BUTTON_K3, //K3����
44
+ GUI_BUTTON_K4, //K4����
45
+ GUI_BUTTON_K5, //K5����
46
+ GUI_BUTTON_K6, //K6����
47
+ GUI_BUTTON_K7, //K7����
48
+ GUI_BUTTON_K8, //K8����
49
+ GUI_BUTTON_K9, //K9����
50
+ GUI_BUTTON_KA, //KA����
51
+ GUI_BUTTON_KB, //KB����
52
+ GUI_BUTTON_KC, //KC����
53
+ GUI_BUTTON_KD, //KD����
54
+ GUI_BUTTON_KE, //KE����
55
+ GUI_BUTTON_KF, //KF����
56
+ GUI_BUTTON_SEND, //���Ͱ���
57
+ GUI_BUTTON_BACK, //���ذ���
58
+ GUI_BUTTON_MAX, //��������
59
+ GUI_BUTTON_NONE, //������
60
+ }EnumGUIButtons;
61
+
62
+ typedef enum
63
+ {
64
+ GUI_LINE_EDIT_SEND_ID = 0, //����ID
65
+ GUI_LINE_EDIT_SEND_DATA, //�������ݣ������Ǵ�0��ʼ
66
+ GUI_LINE_EDIT_MAX, //�ؼ�����
67
+ GUI_LINE_EDIT_NONE, //��Ч�ؼ�
68
+ }EnumGUILineEdit;
69
+
70
+ /*********************************************************************************************************
71
+ * �ڲ�����
72
+ *********************************************************************************************************/
73
+ //�������
74
+ static StructButtonWidget s_arrButton[GUI_BUTTON_MAX]; //��������
75
+ static EnumGUIButtons s_enumButtonPress; //��������Ǹ���������
76
+
77
+ //�б༭���
78
+ static StructLineEditWidget s_arrLineEdit[GUI_LINE_EDIT_MAX];
79
+
80
+ //�ն����
81
+ static StructTerminalWidget s_structTerminal;
82
+
83
+ /*********************************************************************************************************
84
+ * �ڲ���������
85
+ *********************************************************************************************************/
86
+ static void ButtonPressCallback(void* button); //�����ص�����
87
+ static EnumGUIButtons ScanGUIButton(void); //����ɨ��
88
+ static void LineEditPressCallback(void* lineEdit); //�б༭�ص�����
89
+ static u32 CharToU32(char c); //�ַ�תint
90
+ static void ScanGUILineEdit(void); //�б༭ģ��ɨ��
91
+ static u8 GetGUILineEditIDResult(u32* result); //��ȡ����ID������
92
+ static u8 GetGUILineEditDataResult(char** result); //��ȡ����ID������
93
+ static void SendProc(u32 id, char* data); //���ʹ�������
94
+ static void ReadProc(void); //�����ڴ���
95
+
96
+ /*********************************************************************************************************
97
+ * �ڲ�����ʵ��
98
+ *********************************************************************************************************/
99
+ /*********************************************************************************************************
100
+ * �������ƣ�ButtonPressCallback
101
+ * �������ܣ������ص�����
102
+ * ���������void
103
+ * ���������void
104
+ * �� �� ֵ��void
105
+ * �������ڣ�2021��07��01��
106
+ * ע �⣺
107
+ *********************************************************************************************************/
108
+ static void ButtonPressCallback(void* button)
109
+ {
110
+ EnumGUIButtons i;
111
+
112
+ for(i = (EnumGUIButtons)0; i < GUI_BUTTON_MAX; i++)
113
+ {
114
+ if((StructButtonWidget*)button == &s_arrButton[i])
115
+ {
116
+ s_enumButtonPress = i;
117
+ return;
118
+ }
119
+ }
120
+ }
121
+
122
+ /*********************************************************************************************************
123
+ * �������ƣ�ScanGUIButton
124
+ * �������ܣ�����ɨ��
125
+ * ���������void
126
+ * ���������void
127
+ * �� �� ֵ��void
128
+ * �������ڣ�2021��07��01��
129
+ * ע �⣺ÿ��20����ִ��һ��
130
+ *********************************************************************************************************/
131
+ static EnumGUIButtons ScanGUIButton(void)
132
+ {
133
+ EnumGUIButtons i;
134
+
135
+ for(i = (EnumGUIButtons)0; i < GUI_BUTTON_MAX; i++)
136
+ {
137
+ s_enumButtonPress = GUI_BUTTON_NONE;
138
+ ScanButtonWidget(&s_arrButton[i]);
139
+
140
+ if(GUI_BUTTON_NONE != s_enumButtonPress)
141
+ {
142
+ return s_enumButtonPress;
143
+ }
144
+ }
145
+
146
+ return GUI_BUTTON_NONE;
147
+ }
148
+
149
+ /*********************************************************************************************************
150
+ * �������ƣ�LineEditPressCallback
151
+ * �������ܣ��б༭�ص�����
152
+ * ���������void
153
+ * ���������void
154
+ * �� �� ֵ��void
155
+ * �������ڣ�2021��07��01��
156
+ * ע �⣺���ҽ���һ���б༭�ؼ��ܻ�ȡ����
157
+ *********************************************************************************************************/
158
+ static void LineEditPressCallback(void* lineEdit)
159
+ {
160
+ u8 i;
161
+ for(i = 0; i < GUI_LINE_EDIT_MAX; i++)
162
+ {
163
+ if((StructLineEditWidget*)lineEdit != &s_arrLineEdit[i])
164
+ {
165
+ //ȡ���ؼ�����״̬
166
+ ClearLineEditWidgetFocus(&s_arrLineEdit[i]);
167
+ }
168
+ }
169
+ }
170
+
171
+ /*********************************************************************************************************
172
+ * �������ƣ�CharToU32
173
+ * �������ܣ��ַ�תint
174
+ * ���������c����Ҫת�����ַ�
175
+ * ���������void
176
+ * �� �� ֵ���ַ���Ӧ����ֵ������16��ʾ����
177
+ * �������ڣ�2021��07��01��
178
+ * ע �⣺���ҽ���һ���б༭�ؼ��ܻ�ȡ����
179
+ *********************************************************************************************************/
180
+ static u32 CharToU32(char c)
181
+ {
182
+ u32 result;
183
+ switch(c)
184
+ {
185
+ case '0': result = 0 ; break;
186
+ case '1': result = 1 ; break;
187
+ case '2': result = 2 ; break;
188
+ case '3': result = 3 ; break;
189
+ case '4': result = 4 ; break;
190
+ case '5': result = 5 ; break;
191
+ case '6': result = 6 ; break;
192
+ case '7': result = 7 ; break;
193
+ case '8': result = 8 ; break;
194
+ case '9': result = 9 ; break;
195
+ case 'A': result = 10; break;
196
+ case 'a': result = 10; break;
197
+ case 'B': result = 11; break;
198
+ case 'b': result = 11; break;
199
+ case 'C': result = 12; break;
200
+ case 'c': result = 12; break;
201
+ case 'D': result = 13; break;
202
+ case 'd': result = 13; break;
203
+ case 'E': result = 14; break;
204
+ case 'e': result = 14; break;
205
+ case 'F': result = 15; break;
206
+ case 'f': result = 15; break;
207
+ default : result = 16; break;
208
+ }
209
+
210
+ return result;
211
+ }
212
+
213
+ /*********************************************************************************************************
214
+ * �������ƣ�ScanGUILineEdit
215
+ * �������ܣ��б༭ģ��ɨ��
216
+ * ���������void
217
+ * ���������void
218
+ * �� �� ֵ��void
219
+ * �������ڣ�2021��07��01��
220
+ * ע �⣺
221
+ *********************************************************************************************************/
222
+ static void ScanGUILineEdit(void)
223
+ {
224
+ u8 i;
225
+ for(i = 0; i < GUI_LINE_EDIT_MAX; i++)
226
+ {
227
+ ScanLineEditWidget(&s_arrLineEdit[i]);
228
+ }
229
+ }
230
+
231
+ /*********************************************************************************************************
232
+ * �������ƣ�GetGUILineEditIDResult
233
+ * �������ܣ���ȡ����ID������
234
+ * ���������result�����ڷ���������
235
+ * ���������void
236
+ * �� �� ֵ��0-��ȡ�ɹ�����������ȡʧ��
237
+ * �������ڣ�2021��07��01��
238
+ * ע �⣺�б༭��Ϊ10��������
239
+ *********************************************************************************************************/
240
+ static u8 GetGUILineEditIDResult(u32* result)
241
+ {
242
+ u32 sum; //���ս��
243
+ u32 charValue; //��ǰ�ַ���Ӧ����ֵ
244
+ u8 i = 0;
245
+
246
+ //�����б༭����ֵ
247
+ i = 0;
248
+ sum = 0;
249
+ while(1)
250
+ {
251
+ charValue = CharToU32(s_arrLineEdit[GUI_LINE_EDIT_SEND_ID].text[i]);
252
+ if(charValue < 16)
253
+ {
254
+ sum = sum * 16 + charValue;
255
+ }
256
+ else
257
+ {
258
+ break;
259
+ }
260
+
261
+ i = i + 1;
262
+ }
263
+
264
+ //��ȡ��һ���ַ���Ӧ����ֵʱʧ�ܣ���ʾ��ǰ�б༭����Ϊ��
265
+ if(0 == i)
266
+ {
267
+ return 1;
268
+ }
269
+
270
+ //��������ֵ
271
+ else
272
+ {
273
+ *result = sum;
274
+ return 0;
275
+ }
276
+ }
277
+
278
+ /*********************************************************************************************************
279
+ * �������ƣ�GetGUILineEditIDResult
280
+ * �������ܣ���ȡ����ID������
281
+ * ���������result�����ڷ���������
282
+ * ���������void
283
+ * �� �� ֵ��0-��ȡ�ɹ�����������ȡʧ��
284
+ * �������ڣ�2021��07��01��
285
+ * ע �⣺�б༭��Ϊ10��������
286
+ *********************************************************************************************************/
287
+ static u8 GetGUILineEditDataResult(char** result)
288
+ {
289
+ //�б༭��������
290
+ if(0 != s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA].text[0])
291
+ {
292
+ *result = s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA].text;
293
+ return 0;
294
+ }
295
+
296
+ //������
297
+ else
298
+ {
299
+ result = NULL;
300
+ return 1;
301
+ }
302
+ }
303
+
304
+ /*********************************************************************************************************
305
+ * �������ƣ�SendProc
306
+ * �������ܣ����ʹ�������
307
+ * ���������id������ID��data����������
308
+ * ���������void
309
+ * �� �� ֵ��void
310
+ * �������ڣ�2021��07��01��
311
+ * ע �⣺��Ϊ����ֻ��0-9������ID�������10�������ݣ������������ַ���
312
+ *********************************************************************************************************/
313
+ static void SendProc(u32 id, char* data)
314
+ {
315
+ u8 i; //���ͼ���
316
+ u8 sendData; //��������
317
+
318
+ //У�������ַ�Ƿ�Ϊ��ָ��
319
+ if(NULL == data)
320
+ {
321
+ return;
322
+ }
323
+
324
+ //����������
325
+ i = 0;
326
+ while(0 != *(data + i))
327
+ {
328
+ i++;
329
+ }
330
+
331
+ //ͨ��CAN0�����ݷ��ͳ�ȥ
332
+ WriteCAN0(id, (u8*)data, i);
333
+
334
+ //���ͻس�����
335
+ sendData = '\r';
336
+ WriteCAN0(id, &sendData, 1);
337
+ sendData = '\n';
338
+ WriteCAN0(id, &sendData, 1);
339
+ }
340
+
341
+ /*********************************************************************************************************
342
+ * �������ƣ�ReadProc
343
+ * �������ܣ������ڴ���
344
+ * ���������void
345
+ * ���������void
346
+ * �� �� ֵ��void
347
+ * �������ڣ�2021��07��01��
348
+ * ע �⣺ÿ��һ��ʱ�����һ��
349
+ *********************************************************************************************************/
350
+ static void ReadProc(void)
351
+ {
352
+ static char s_arrReadBuf[48] = {0}; //���ջ�����
353
+ static u8 s_iReadCnt = 0; //���ռ���
354
+ static u64 s_iBeginTime = 0; //���յ���һ���ַ�ʱ��ϵͳʱ��
355
+
356
+ u8 readData;
357
+ u64 time;
358
+
359
+ //��ȡϵͳ����ʱ��
360
+ time = GUIGetSysTime(); //ms
361
+
362
+ //�������ݴ���
363
+ while(ReadCAN0(&readData, 1))
364
+ {
365
+ //��¼���յ���һ���ַ�ʱ��ϵͳʱ��
366
+ if(0 == s_iReadCnt)
367
+ {
368
+ s_iBeginTime = time;
369
+ }
370
+
371
+ //�����ݴ��浽������
372
+ s_arrReadBuf[s_iReadCnt] = readData;
373
+
374
+ //���ռ�����һ
375
+ s_iReadCnt = (s_iReadCnt + 1) % (sizeof(s_arrReadBuf) / sizeof(u8));
376
+
377
+ //���յ��س�����
378
+ if(s_iReadCnt >= 2)
379
+ {
380
+ if(('\r' == s_arrReadBuf[s_iReadCnt - 2]) && ('\n' == s_arrReadBuf[s_iReadCnt - 1]))
381
+ {
382
+ //�����ַ�����β
383
+ s_arrReadBuf[s_iReadCnt] = 0;
384
+
385
+ //���ռ�������
386
+ s_iReadCnt = 0;
387
+
388
+ //������ն���ʾ
389
+ TerminalWidgetShowLine(&s_structTerminal, s_arrReadBuf);
390
+ }
391
+ }
392
+ }
393
+
394
+ //����250���뻹û���յ��س�������ǿ�Ƹ��µ��ն���ʾ
395
+ if((s_iReadCnt > 0) && ((time - s_iBeginTime) > 250))
396
+ {
397
+ //�����ַ�����β
398
+ s_arrReadBuf[s_iReadCnt] = 0;
399
+
400
+ //���ռ�������
401
+ s_iReadCnt = 0;
402
+
403
+ //������ն���ʾ
404
+ TerminalWidgetShowLine(&s_structTerminal, s_arrReadBuf);
405
+ }
406
+ }
407
+
408
+ /*********************************************************************************************************
409
+ * API����ʵ��
410
+ *********************************************************************************************************/
411
+ /*********************************************************************************************************
412
+ * �������ƣ�CreateGUICAN
413
+ * �������ܣ�����GUI CAN����
414
+ * ���������void
415
+ * ���������void
416
+ * �� �� ֵ��void
417
+ * �������ڣ�2021��07��01��
418
+ * ע �⣺
419
+ *********************************************************************************************************/
420
+ void CreateGUICAN(void)
421
+ {
422
+ static const u16 s_arrButtonX[GUI_BUTTON_MAX] = {485, 560, 635, 710, //K0-K3
423
+ 485, 560, 635, 710, //K4-K7
424
+ 485, 560, 635, 710, //K8-KB
425
+ 485, 560, 635, 710, //KC-KF
426
+ 485, 635}; //Send, Back
427
+
428
+ static const u16 s_arrButtonY[GUI_BUTTON_MAX] = {105, 105, 105, 105, //K0-K3
429
+ 180, 180, 180, 180, //K4-K7
430
+ 255, 255, 255, 255, //K8-KB
431
+ 330, 330, 330, 330, //KC-KF
432
+ 405, 405}; //Send, Back
433
+ static const char* s_arrButtonText[16] = {"0","1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"};
434
+ static StructBmpImage s_structKeyNumPressImage;
435
+ static StructBmpImage s_structKeyNumReleaseImage;
436
+ static StructBmpImage s_structKeyFucPressImage;
437
+ static StructBmpImage s_structKeyFucReleaseImage;
438
+ static StructJpegImage s_structHasFocusImage;
439
+ static StructJpegImage s_structNoFocusImage;
440
+ static StructJpegImage s_structTerminalImage;
441
+
442
+ EnumGUIButtons i;
443
+
444
+ //LCD������ʾ
445
+ LCDDisplayDir(LCD_SCREEN_HORIZONTAL);
446
+
447
+ //��ʾ����ͼƬ
448
+ DisPlayBMPByIPA(0, 0, CAN_BACKGROUND_DIR);
449
+
450
+ s_structKeyNumPressImage.alphaType = BMP_GATE_ALPHA;
451
+ s_structKeyNumPressImage.alphaGate = 1;
452
+ s_structKeyNumPressImage.storageType = BMP_IN_FATFS;
453
+ s_structKeyNumPressImage.addr = (void*)CAN_BUTTON_PRESS_65x65_DIR;
454
+
455
+ s_structKeyNumReleaseImage.alphaType = BMP_GATE_ALPHA;
456
+ s_structKeyNumReleaseImage.alphaGate = 1;
457
+ s_structKeyNumReleaseImage.storageType = BMP_IN_FATFS;
458
+ s_structKeyNumReleaseImage.addr = (void*)CAN_BUTTON_RELEASE_65x65_DIR;
459
+
460
+ s_structKeyFucPressImage.alphaType = BMP_GATE_ALPHA;
461
+ s_structKeyFucPressImage.alphaGate = 1;
462
+ s_structKeyFucPressImage.storageType = BMP_IN_FATFS;
463
+ s_structKeyFucPressImage.addr = (void*)CAN_BUTTON_PRESS_140x65_DIR;
464
+
465
+ s_structKeyFucReleaseImage.alphaType = BMP_GATE_ALPHA;
466
+ s_structKeyFucReleaseImage.alphaGate = 1;
467
+ s_structKeyFucReleaseImage.storageType = BMP_IN_FATFS;
468
+ s_structKeyFucReleaseImage.addr = (void*)CAN_BUTTON_RELEASE_140x65_DIR;
469
+
470
+ //����ް�������
471
+ s_enumButtonPress = GUI_BUTTON_NONE;
472
+
473
+ //����K0-KF
474
+ for(i = GUI_BUTTON_K0; i <= GUI_BUTTON_KF; i++)
475
+ {
476
+ InitButtonWidgetStruct(&s_arrButton[i]);
477
+ s_arrButton[i].x0 = s_arrButtonX[i];
478
+ s_arrButton[i].y0 = s_arrButtonY[i];
479
+ s_arrButton[i].width = 65;
480
+ s_arrButton[i].height = 65;
481
+ s_arrButton[i].textX0 = 25;
482
+ s_arrButton[i].textY0 = 20;
483
+ s_arrButton[i].text = s_arrButtonText[i];
484
+ s_arrButton[i].pressBackgroudImage = (void*)(&s_structKeyNumPressImage);
485
+ s_arrButton[i].releaseBackgroudImage = (void*)(&s_structKeyNumReleaseImage);
486
+ s_arrButton[i].pressCallback = ButtonPressCallback;
487
+ CreateButtonWidget(&s_arrButton[i]);
488
+ }
489
+
490
+ //������ȡ��ť
491
+ InitButtonWidgetStruct(&s_arrButton[GUI_BUTTON_SEND]);
492
+ s_arrButton[GUI_BUTTON_SEND].x0 = s_arrButtonX[GUI_BUTTON_SEND];
493
+ s_arrButton[GUI_BUTTON_SEND].y0 = s_arrButtonY[GUI_BUTTON_SEND];
494
+ s_arrButton[GUI_BUTTON_SEND].width = 140;
495
+ s_arrButton[GUI_BUTTON_SEND].height = 65;
496
+ s_arrButton[GUI_BUTTON_SEND].textX0 = 46;
497
+ s_arrButton[GUI_BUTTON_SEND].textY0 = 20;
498
+ s_arrButton[GUI_BUTTON_SEND].text = "SEND";
499
+ s_arrButton[GUI_BUTTON_SEND].pressBackgroudImage = (void*)(&s_structKeyFucPressImage);
500
+ s_arrButton[GUI_BUTTON_SEND].releaseBackgroudImage = (void*)(&s_structKeyFucReleaseImage);
501
+ s_arrButton[GUI_BUTTON_SEND].pressCallback = ButtonPressCallback;
502
+ CreateButtonWidget(&s_arrButton[GUI_BUTTON_SEND]);
503
+
504
+ //�������ذ�ť
505
+ InitButtonWidgetStruct(&s_arrButton[GUI_BUTTON_BACK]);
506
+ s_arrButton[GUI_BUTTON_BACK].x0 = s_arrButtonX[GUI_BUTTON_BACK];
507
+ s_arrButton[GUI_BUTTON_BACK].y0 = s_arrButtonY[GUI_BUTTON_BACK];
508
+ s_arrButton[GUI_BUTTON_BACK].width = 140;
509
+ s_arrButton[GUI_BUTTON_BACK].height = 65;
510
+ s_arrButton[GUI_BUTTON_BACK].textX0 = 46;
511
+ s_arrButton[GUI_BUTTON_BACK].textY0 = 20;
512
+ s_arrButton[GUI_BUTTON_BACK].text = "BACK";
513
+ s_arrButton[GUI_BUTTON_BACK].pressBackgroudImage = (void*)(&s_structKeyFucPressImage);
514
+ s_arrButton[GUI_BUTTON_BACK].releaseBackgroudImage = (void*)(&s_structKeyFucReleaseImage);
515
+ s_arrButton[GUI_BUTTON_BACK].pressCallback = ButtonPressCallback;
516
+ CreateButtonWidget(&s_arrButton[GUI_BUTTON_BACK]);
517
+
518
+ //��ʼ��JPEGͼƬ
519
+ s_structHasFocusImage.image = (unsigned char*)CAN_LINE_EDIT_HAS_FOCUS_DIR;
520
+ s_structNoFocusImage.image = (unsigned char*)CAN_LINE_EDIT_NO_FOCUS_DIR;
521
+
522
+ //����ID
523
+ InitLineEditWidgetStruct(&s_arrLineEdit[GUI_LINE_EDIT_SEND_ID]);
524
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_ID].x0 = 25;
525
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_ID].y0 = 405;
526
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_ID].width = 200;
527
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_ID].height = 65;
528
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_ID].textX0 = 3;
529
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_ID].textY0 = 19;
530
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_ID].hasFocusBackgroundImage = (void*)(&s_structHasFocusImage);
531
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_ID].noFocusBackgroundImage = (void*)(&s_structNoFocusImage);
532
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_ID].pressCallback = LineEditPressCallback;
533
+ CreateLineEditWidget(&s_arrLineEdit[GUI_LINE_EDIT_SEND_ID]);
534
+ SetLineEditPreText(&s_arrLineEdit[GUI_LINE_EDIT_SEND_ID], "ID:");
535
+
536
+ //��������
537
+ InitLineEditWidgetStruct(&s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA]);
538
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA].x0 = 255;
539
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA].y0 = 405;
540
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA].width = 200;
541
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA].height = 65;
542
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA].textX0 = 3;
543
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA].textY0 = 19;
544
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA].hasFocusBackgroundImage = (void*)(&s_structHasFocusImage);
545
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA].noFocusBackgroundImage = (void*)(&s_structNoFocusImage);
546
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA].pressCallback = LineEditPressCallback;
547
+ CreateLineEditWidget(&s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA]);
548
+ SetLineEditPreText(&s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA], "DATA:");
549
+
550
+ //�ն˿ؼ�
551
+ InitTerminalWidgetStruct(&s_structTerminal);
552
+ s_structTerminalImage.image = (unsigned char*)CAN_TERMINAL_BACKGROUND_DIR;
553
+ s_structTerminal.x0 = 25;
554
+ s_structTerminal.y0 = 55;
555
+ s_structTerminal.width = 430;
556
+ s_structTerminal.height = 340;
557
+ s_structTerminal.topOff = 30;
558
+ s_structTerminal.showSpace = 3;
559
+ s_structTerminal.textColor = GUI_COLOR_WHITE;
560
+ s_structTerminal.textFont = GUI_FONT_ASCII_24;
561
+ s_structTerminal.textHeight = 30;
562
+ s_structTerminal.background = NULL;
563
+ s_structTerminal.backImage = (void*)(&s_structTerminalImage);
564
+ s_structTerminal.imageType = GUI_IMAGE_TYPE_JPEG;
565
+ CreateTerminalWidget(&s_structTerminal);
566
+ TerminalWidgetClear(&s_structTerminal);
567
+
568
+ //CONX��ʾ
569
+ LCDShowString(545, 58, 100, 16, LCD_FONT_16, LCD_TEXT_TRANS, GUI_COLOR_WHITE, NULL, "CAN0");
570
+
571
+ //�ٶ���ʾ
572
+ LCDShowString(545, 83, 100, 16, LCD_FONT_16, LCD_TEXT_TRANS, GUI_COLOR_WHITE, NULL, "1MBps");
573
+
574
+ //��ʶ����ʾ
575
+ LCDShowString(690, 58, 100, 16, LCD_FONT_16, LCD_TEXT_TRANS, GUI_COLOR_WHITE, NULL, "0x5A5");
576
+
577
+ //������ʾ
578
+ LCDShowString(690, 83, 100, 16, LCD_FONT_16, LCD_TEXT_TRANS, GUI_COLOR_WHITE, NULL, "0xFFFFFFFF");
579
+
580
+ //��ʼ��CANģ��
581
+ InitCAN();
582
+ }
583
+
584
+ /*********************************************************************************************************
585
+ * �������ƣ�DeleteGUICAN
586
+ * �������ܣ�ע��GUI CAN����
587
+ * ���������void
588
+ * ���������void
589
+ * �� �� ֵ��void
590
+ * �������ڣ�2021��07��01��
591
+ * ע �⣺
592
+ *********************************************************************************************************/
593
+ void DeleteGUICAN(void)
594
+ {
595
+ //ע��CANģ��
596
+ DeInitCAN();
597
+ }
598
+
599
+ /*********************************************************************************************************
600
+ * �������ƣ�GUICANPoll
601
+ * �������ܣ�GUI CAN��ѯ����
602
+ * ���������void
603
+ * ���������void
604
+ * �� �� ֵ��void
605
+ * �������ڣ�2021��07��01��
606
+ * ע �⣺
607
+ *********************************************************************************************************/
608
+ void GUICANPoll(void)
609
+ {
610
+ const char s_arrButtonValue[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
611
+ EnumGUIButtons button;
612
+ EnumGUILineEdit lineEdit;
613
+ char* data = NULL;
614
+ u32 id = 0;
615
+
616
+ //�б༭ģ��ɨ��
617
+ ScanGUILineEdit();
618
+
619
+ //����ɨ��
620
+ button = ScanGUIButton();
621
+ if(GUI_BUTTON_NONE != button)
622
+ {
623
+ //���ʹ���
624
+ if(GUI_BUTTON_SEND == button)
625
+ {
626
+ if((0 == GetGUILineEditDataResult(&data)) && (0 == GetGUILineEditIDResult(&id)))
627
+ {
628
+ SendProc(id, data);
629
+ }
630
+ }
631
+
632
+ //ɾ������
633
+ else if(GUI_BUTTON_BACK == button)
634
+ {
635
+ for(lineEdit = (EnumGUILineEdit)0; lineEdit < GUI_LINE_EDIT_MAX; lineEdit++)
636
+ {
637
+ if(1 == s_arrLineEdit[lineEdit].hasFocus)
638
+ {
639
+ DeleteCodeFromLineEdit(&s_arrLineEdit[lineEdit]);
640
+ }
641
+ }
642
+ }
643
+
644
+ //K0-KF����
645
+ else
646
+ {
647
+ for(lineEdit = (EnumGUILineEdit)0; lineEdit < GUI_LINE_EDIT_MAX; lineEdit++)
648
+ {
649
+ if(1 == s_arrLineEdit[lineEdit].hasFocus)
650
+ {
651
+ AddrCharToLineEdit(&s_arrLineEdit[lineEdit], s_arrButtonValue[button]);
652
+ }
653
+ }
654
+ }
655
+ }
656
+
657
+ //�������ݲ����µ��ն���ʾ
658
+ ReadProc();
659
+ }
deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUICAN.h ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�GUICAN.h
3
+ * ժ Ҫ��GUI CANͨ��ģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+ #ifndef _GUI_CAN_H_
17
+ #define _GUI_CAN_H_
18
+
19
+ /*********************************************************************************************************
20
+ * ����ͷ�ļ�
21
+ *********************************************************************************************************/
22
+ #include "DataType.h"
23
+
24
+ /*********************************************************************************************************
25
+ * �궨��
26
+ *********************************************************************************************************/
27
+
28
+ /*********************************************************************************************************
29
+ * ö�ٽṹ�嶨��
30
+ *********************************************************************************************************/
31
+
32
+ /*********************************************************************************************************
33
+ * API��������
34
+ *********************************************************************************************************/
35
+ void CreateGUICAN(void); //����GUI CAN����
36
+ void DeleteGUICAN(void); //ע��GUI CAN����
37
+ void GUICANPoll(void); //GUI CAN��ѯ����
38
+
39
+ #endif
deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUICamera.c ADDED
@@ -0,0 +1,630 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�GUICamera.c
3
+ * ժ Ҫ�������ģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+
17
+ /*********************************************************************************************************
18
+ * ����ͷ�ļ�
19
+ *********************************************************************************************************/
20
+ #include "GUICamera.h"
21
+ #include "GUIPlatform.h"
22
+ #include "RadioWidget.h"
23
+ #include "ButtonWidget.h"
24
+ #include "TLILCD.h"
25
+ #include "BMP.h"
26
+ #include "Common.h"
27
+ #include "stdio.h"
28
+ #include "OV2640.h"
29
+ #include "DCI.h"
30
+ #include "Malloc.h"
31
+ #include "Beep.h"
32
+ #include "BMPEncoder.h"
33
+
34
+ /*********************************************************************************************************
35
+ * �궨��
36
+ *********************************************************************************************************/
37
+ //�ַ�����ʾ���
38
+ #define STRING_MAX_LEN (64) //��ʾ�ַ���󳤶�
39
+ #define STRIGN_X0 (105) //��ʾ�ַ����������
40
+ #define STRING_Y0 (747) //��ʾ�ַ����������
41
+ #define STRING_X1 (373) //��ʾ�ַ��������յ�
42
+ #define STRING_SIZE (24) //�����С
43
+
44
+ //��Ƭ���
45
+ #define IMAGE_X0 (116)
46
+ #define IMAGE_Y0 (195)
47
+ #define IMAGE_WIDTH (240)
48
+ #define IMAGE_HEIGHT (320)
49
+ #define IMAGE_SIZE (IMAGE_WIDTH * IMAGE_HEIGHT * 2)
50
+
51
+ /*********************************************************************************************************
52
+ * ö�ٽṹ�嶨��
53
+ *********************************************************************************************************/
54
+ typedef enum
55
+ {
56
+ GUI_RADIO_COLOR = 0, //ɫ�ȣ������Ǵ�0��ʼ
57
+ GUI_RADIO_LIGHT, //����
58
+ GUI_RADIO_CONTRAST, //�Աȶ�
59
+ GUI_RADIO_WB, //��ƽ��
60
+ GUI_RADIO_EFECT, //��Ч
61
+ GUI_RADIO_MAX, //�ؼ�����
62
+ GUI_RADIO_NONE, //��Ч�ؼ�
63
+ }EnumGUIRadio;
64
+
65
+ typedef enum
66
+ {
67
+ GUI_BUTTON_PREVIOUS = 0, //��һ�������������Ǵ�0��ʼ
68
+ GUI_BUTTON_NEXT, //��һ������
69
+ GUI_BUTTON_PHOTO, //���հ���
70
+ GUI_BUTTON_MAX, //��������
71
+ GUI_BUTTON_NONE, //������
72
+ }EnumGUIButtons;
73
+
74
+ /*********************************************************************************************************
75
+ * �ڲ�����
76
+ *********************************************************************************************************/
77
+ static StructRadioWidget s_arrRadio[GUI_RADIO_MAX]; //��ѡ�ؼ�
78
+ static StructButtonWidget s_arrButton[GUI_BUTTON_MAX]; //��������
79
+ static u32 s_iImageFrameAdd = NULL; //ͼ��֡�׵�ַ
80
+ static u8* s_pStringBackground = NULL; //�ַ�����ʾ����������
81
+ static EnumGUIRadio s_enumRadio = GUI_RADIO_NONE; //��ǰѡ�еĿؼ�
82
+ static char s_arrStringBuf[64]; //�ַ���ת��������
83
+
84
+ //6�ֹ���ģʽ����ƽ�⣩
85
+ const char* s_arrLmodeTable[5] = {"�Զ�", "����", "����", "�칫��", "����"};
86
+
87
+ //7����Ч
88
+ const char* s_arrEffectTable[7] = {"����", "��Ƭ", "�ڰ�", "ƫ��", "ƫ��", "ƫ��", "����"};
89
+
90
+ //����ͷ����
91
+ static i32 s_iLightMode = 0; //��ƽ�⣨0-4��
92
+ static i32 s_iColorSaturation = 0; //ɫ�ȣ�-2~+2��
93
+ static i32 s_iBrightness = 0; //���ȣ�-2~+2��
94
+ static i32 s_iContrast = 0; //�Աȶȣ�-2~+2��
95
+ static i32 s_iEffects = 0; //����0-6��
96
+
97
+ /*********************************************************************************************************
98
+ * �ڲ���������
99
+ *********************************************************************************************************/
100
+
101
+ /*********************************************************************************************************
102
+ * �ڲ�����ʵ��
103
+ *********************************************************************************************************/
104
+ /*********************************************************************************************************
105
+ * �������ƣ�RadioPressCallback
106
+ * �������ܣ���ѡ�ص�����
107
+ * ���������radio�������µĵ�ѡ�ؼ���ַ
108
+ * ���������void
109
+ * �� �� ֵ��void
110
+ * �������ڣ�2021��07��01��
111
+ * ע �⣺���ҽ���һ����ѡ�ؼ��ܻ�ȡ����
112
+ *********************************************************************************************************/
113
+ static void RadioPressCallback(void* radio)
114
+ {
115
+ u8 i;
116
+ for(i = 0; i < GUI_RADIO_MAX; i++)
117
+ {
118
+ if((StructRadioWidget*)radio != &s_arrRadio[i])
119
+ {
120
+ //ȡ���ؼ�������̬
121
+ ClearRadioWidgetFocus(&s_arrRadio[i]);
122
+ }
123
+ }
124
+ }
125
+
126
+ /*********************************************************************************************************
127
+ * �������ƣ�ScanGUIRadio
128
+ * �������ܣ���ѡģ��ɨ��
129
+ * ���������void
130
+ * ���������void
131
+ * �� �� ֵ��void
132
+ * �������ڣ�2021��07��01��
133
+ * ע �⣺
134
+ *********************************************************************************************************/
135
+ static EnumGUIRadio ScanGUIRadio(void)
136
+ {
137
+ u32 i;
138
+ EnumGUIRadio result;
139
+
140
+ //ɨ��
141
+ for(i = 0; i < GUI_RADIO_MAX; i++)
142
+ {
143
+ ScanRadioWidget(&s_arrRadio[i]);
144
+ }
145
+
146
+ //��ȡ���н���Ŀؼ�ID
147
+ result = GUI_RADIO_NONE;
148
+ for(i = 0; i < GUI_RADIO_MAX; i++)
149
+ {
150
+ if(RADIO_HAS_FOCUS == s_arrRadio[i].hasFocus)
151
+ {
152
+ result = (EnumGUIRadio)i;
153
+ break;
154
+ }
155
+ }
156
+
157
+ //����
158
+ return result;
159
+ }
160
+
161
+ /*********************************************************************************************************
162
+ * �������ƣ�UpdataString
163
+ * �������ܣ������ַ�����ʾ
164
+ * ���������text���ַ���
165
+ * ���������void
166
+ * �� �� ֵ��void
167
+ * �������ڣ�2021��07��01��
168
+ * ע �⣺
169
+ *********************************************************************************************************/
170
+ static void UpdataString(char* text)
171
+ {
172
+ u32 len, max, total, begin;
173
+
174
+ //�����ַ�������
175
+ len = 0;
176
+ while((0 != text[len]) && ('\r' != text[len]) && ('\n' != text[len]))
177
+ {
178
+ len++;
179
+ }
180
+
181
+ //������Ļһ�������ʾ���ٸ��ַ�
182
+ max = (STRING_X1 - STRIGN_X0) / 12;
183
+
184
+ //��������ص�����
185
+ total = 12 * len;
186
+
187
+ //������ʼ��ʾ���ص�
188
+ begin = STRIGN_X0 + ((STRING_X1 - STRIGN_X0) - total) / 2;
189
+
190
+ //���Ʊ���ͼƬ
191
+ if(NULL != s_pStringBackground)
192
+ {
193
+ GUIDrawBackground(STRIGN_X0, STRING_Y0, STRING_X1 - STRIGN_X0, STRING_SIZE, (u32)s_pStringBackground);
194
+ }
195
+
196
+ //��ʾ
197
+ GUIDrawTextLine(begin, STRING_Y0, (u32)text, GUI_FONT_ASCII_24, NULL, GUI_COLOR_BLACK, 1, max);
198
+ }
199
+
200
+ /*********************************************************************************************************
201
+ * �������ƣ�PreviouCallback
202
+ * �������ܣ�ǰһ��ص�����
203
+ * ���������button���ؼ��׵�ַ
204
+ * ���������void
205
+ * �� �� ֵ��void
206
+ * �������ڣ�2021��07��01��
207
+ * ע �⣺��һ��Ĭ�ϵݼ�����һ��Ĭ�ϵ���
208
+ *********************************************************************************************************/
209
+ static void PreviouCallback(void* button)
210
+ {
211
+ //ɫ�ȵ���
212
+ if(GUI_RADIO_COLOR == s_enumRadio)
213
+ {
214
+ if(s_iColorSaturation > -2)
215
+ {
216
+ s_iColorSaturation = s_iColorSaturation - 1;
217
+ }
218
+ else
219
+ {
220
+ s_iColorSaturation = +2;
221
+ }
222
+ sprintf(s_arrStringBuf, "ɫ�ȣ�%+d", s_iColorSaturation);
223
+ UpdataString(s_arrStringBuf);
224
+ OV2640ColorSaturation(s_iColorSaturation);
225
+ }
226
+
227
+ //���ȵ���
228
+ else if(GUI_RADIO_LIGHT == s_enumRadio)
229
+ {
230
+ if(s_iBrightness > -2)
231
+ {
232
+ s_iBrightness = s_iBrightness - 1;
233
+ }
234
+ else
235
+ {
236
+ s_iBrightness = +2;
237
+ }
238
+ sprintf(s_arrStringBuf, "���ȣ�%+d", s_iBrightness);
239
+ UpdataString(s_arrStringBuf);
240
+ OV2640Brightness(s_iBrightness);
241
+ }
242
+
243
+ //�Աȶȵ���
244
+ else if(GUI_RADIO_CONTRAST == s_enumRadio)
245
+ {
246
+ if(s_iContrast > -2)
247
+ {
248
+ s_iContrast = s_iContrast - 1;
249
+ }
250
+ else
251
+ {
252
+ s_iContrast = +2;
253
+ }
254
+ sprintf(s_arrStringBuf, "�Աȶȣ�%+d", s_iContrast);
255
+ UpdataString(s_arrStringBuf);
256
+ OV2640Contrast(s_iContrast);
257
+ }
258
+
259
+ //��ƽ�����
260
+ else if(GUI_RADIO_WB == s_enumRadio)
261
+ {
262
+ if(s_iLightMode > 0)
263
+ {
264
+ s_iLightMode = s_iLightMode - 1;
265
+ }
266
+ else
267
+ {
268
+ s_iLightMode = 4;
269
+ }
270
+ sprintf(s_arrStringBuf, "��ƽ�⣺%s", s_arrLmodeTable[s_iLightMode]);
271
+ UpdataString(s_arrStringBuf);
272
+ OV2640LightMode(s_iLightMode);
273
+ }
274
+
275
+ //������
276
+ else if(GUI_RADIO_EFECT == s_enumRadio)
277
+ {
278
+ if(s_iEffects > 0)
279
+ {
280
+ s_iEffects = s_iEffects - 1;
281
+ }
282
+ else
283
+ {
284
+ s_iEffects = 6;
285
+ }
286
+ sprintf(s_arrStringBuf, "����%s", s_arrEffectTable[s_iEffects]);
287
+ UpdataString(s_arrStringBuf);
288
+ OV2640SpecialEffects(s_iEffects);
289
+ }
290
+ }
291
+
292
+ /*********************************************************************************************************
293
+ * �������ƣ�NextCallback
294
+ * �������ܣ���һ��ص�����
295
+ * ���������button���ؼ��׵�ַ
296
+ * ���������void
297
+ * �� �� ֵ��void
298
+ * �������ڣ�2021��07��01��
299
+ * ע �⣺��һ��Ĭ�ϵݼ�����һ��Ĭ�ϵ���
300
+ *********************************************************************************************************/
301
+ static void NextCallback(void* button)
302
+ {
303
+ //ɫ�ȵ���
304
+ if(GUI_RADIO_COLOR == s_enumRadio)
305
+ {
306
+ if(s_iColorSaturation < 2)
307
+ {
308
+ s_iColorSaturation = s_iColorSaturation + 1;
309
+ }
310
+ else
311
+ {
312
+ s_iColorSaturation = -2;
313
+ }
314
+ sprintf(s_arrStringBuf, "ɫ�ȣ�%+d", s_iColorSaturation);
315
+ UpdataString(s_arrStringBuf);
316
+ OV2640ColorSaturation(s_iColorSaturation);
317
+ }
318
+
319
+ //���ȵ���
320
+ else if(GUI_RADIO_LIGHT == s_enumRadio)
321
+ {
322
+ if(s_iBrightness < 2)
323
+ {
324
+ s_iBrightness = s_iBrightness + 1;
325
+ }
326
+ else
327
+ {
328
+ s_iBrightness = -2;
329
+ }
330
+ sprintf(s_arrStringBuf, "���ȣ�%+d", s_iBrightness);
331
+ UpdataString(s_arrStringBuf);
332
+ OV2640Brightness(s_iBrightness);
333
+ }
334
+
335
+ //�Աȶȵ���
336
+ else if(GUI_RADIO_CONTRAST == s_enumRadio)
337
+ {
338
+ if(s_iContrast < 2)
339
+ {
340
+ s_iContrast = s_iContrast + 1;
341
+ }
342
+ else
343
+ {
344
+ s_iContrast = -2;
345
+ }
346
+ sprintf(s_arrStringBuf, "�Աȶȣ�%+d", s_iContrast);
347
+ UpdataString(s_arrStringBuf);
348
+ OV2640Contrast(s_iContrast);
349
+ }
350
+
351
+ //��ƽ�����
352
+ else if(GUI_RADIO_WB == s_enumRadio)
353
+ {
354
+ if(s_iLightMode < 4)
355
+ {
356
+ s_iLightMode = s_iLightMode + 1;
357
+ }
358
+ else
359
+ {
360
+ s_iLightMode = 0;
361
+ }
362
+ sprintf(s_arrStringBuf, "��ƽ�⣺%s", s_arrLmodeTable[s_iLightMode]);
363
+ UpdataString(s_arrStringBuf);
364
+ OV2640LightMode(s_iLightMode);
365
+ }
366
+
367
+ //������
368
+ else if(GUI_RADIO_EFECT == s_enumRadio)
369
+ {
370
+ if(s_iEffects < 6)
371
+ {
372
+ s_iEffects = s_iEffects + 1;
373
+ }
374
+ else
375
+ {
376
+ s_iEffects = 0;
377
+ }
378
+ sprintf(s_arrStringBuf, "����%s", s_arrEffectTable[s_iEffects]);
379
+ UpdataString(s_arrStringBuf);
380
+ OV2640SpecialEffects(s_iEffects);
381
+ }
382
+ }
383
+
384
+ /*********************************************************************************************************
385
+ * �������ƣ�RadioChange
386
+ * �������ܣ���ѡ�л������ַ�����ʾ
387
+ * ���������void
388
+ * ���������void
389
+ * �� �� ֵ��void
390
+ * �������ڣ�2021��07��01��
391
+ * ע �⣺
392
+ *********************************************************************************************************/
393
+ static void RadioChange(void)
394
+ {
395
+ //�л���ɫ�ȵ���
396
+ if(GUI_RADIO_COLOR == s_enumRadio)
397
+ {
398
+ sprintf(s_arrStringBuf, "ɫ�ȣ�%+d", s_iColorSaturation);
399
+ UpdataString(s_arrStringBuf);
400
+ }
401
+
402
+ //�л������ȵ���
403
+ else if(GUI_RADIO_LIGHT == s_enumRadio)
404
+ {
405
+ sprintf(s_arrStringBuf, "���ȣ�%+d", s_iBrightness);
406
+ UpdataString(s_arrStringBuf);
407
+ }
408
+
409
+ //�л����Աȶȵ���
410
+ else if(GUI_RADIO_CONTRAST == s_enumRadio)
411
+ {
412
+ sprintf(s_arrStringBuf, "�Աȶȣ�%+d", s_iContrast);
413
+ UpdataString(s_arrStringBuf);
414
+ }
415
+
416
+ //�л�����ƽ�����
417
+ else if(GUI_RADIO_WB == s_enumRadio)
418
+ {
419
+ sprintf(s_arrStringBuf, "��ƽ�⣺%s", s_arrLmodeTable[s_iLightMode]);
420
+ UpdataString(s_arrStringBuf);
421
+ }
422
+
423
+ //���������
424
+ else if(GUI_RADIO_EFECT == s_enumRadio)
425
+ {
426
+ sprintf(s_arrStringBuf, "����%s", s_arrEffectTable[s_iEffects]);
427
+ UpdataString(s_arrStringBuf);
428
+ }
429
+
430
+ //�����ʾ
431
+ else
432
+ {
433
+ UpdataString("");
434
+ }
435
+ }
436
+
437
+ /*********************************************************************************************************
438
+ * �������ƣ�TakePhotoCallback
439
+ * �������ܣ����ջص�����
440
+ * ���������button���ؼ��׵�ַ
441
+ * ���������void
442
+ * �� �� ֵ��void
443
+ * �������ڣ�2021��07��01��
444
+ * ע �⣺
445
+ *********************************************************************************************************/
446
+ static void TakePhotoCallback(void* button)
447
+ {
448
+ //����������100ms
449
+ BeepWithTime(100);
450
+
451
+ //��ȡ��Ļͼ�񲢱��浽SD��
452
+ BMPEncodeWithRGB565(IMAGE_X0, IMAGE_Y0, IMAGE_WIDTH, IMAGE_HEIGHT, "0:/photo", "OV2640Image");
453
+ }
454
+
455
+ /*********************************************************************************************************
456
+ * API����ʵ��
457
+ *********************************************************************************************************/
458
+ /*********************************************************************************************************
459
+ * �������ƣ�CreateGUICamera
460
+ * �������ܣ����������
461
+ * ���������void
462
+ * ���������void
463
+ * �� �� ֵ��void
464
+ * �������ڣ�2021��07��01��
465
+ * ע �⣺����ʱ�����ǰ���㣬ͬʱDCIʹ��ģʽ0��DMAֱ�ӽ�DCI���ݴ��䵽�ִ��У�ˢ���ٶȿ�
466
+ * ��LCDˢ����Ҫ���ͣ������п��ܻ���ֻ���
467
+ *********************************************************************************************************/
468
+ void CreateGUICamera(void)
469
+ {
470
+ //��ѡ�ؼ�����
471
+ static const u16 s_arrX0[GUI_RADIO_MAX] = {43, 204, 365, 42 , 365}; //������
472
+ static const u16 s_arrY0[GUI_RADIO_MAX] = {17, 20 , 20 , 645, 645}; //������
473
+ u32 i;
474
+
475
+ //LCD������ʾ
476
+ LCDDisplayDir(LCD_SCREEN_VERTICAL);
477
+
478
+ //���Ʊ���
479
+ DisPlayBMPByIPA(0, 0, CAMERA_BACKGROUND_DIR);
480
+
481
+ //ͼ����ʾ�������Ϊ��ɫ
482
+ GUIFillColor(IMAGE_X0, IMAGE_Y0, IMAGE_X0 + IMAGE_WIDTH - 1, IMAGE_Y0 + IMAGE_HEIGHT - 1, GUI_COLOR_BLACK);
483
+
484
+ //������һ�ť
485
+ InitButtonWidgetStruct(&s_arrButton[GUI_BUTTON_PREVIOUS]);
486
+ s_arrButton[GUI_BUTTON_PREVIOUS].x0 = 52;
487
+ s_arrButton[GUI_BUTTON_PREVIOUS].y0 = 733;
488
+ s_arrButton[GUI_BUTTON_PREVIOUS].width = 53;
489
+ s_arrButton[GUI_BUTTON_PREVIOUS].height = 53;
490
+ s_arrButton[GUI_BUTTON_PREVIOUS].text = "";
491
+ s_arrButton[GUI_BUTTON_PREVIOUS].pressImageType = GUI_IMAGE_TYPE_CLEAR;
492
+ s_arrButton[GUI_BUTTON_PREVIOUS].releaseImageType = GUI_IMAGE_TYPE_CLEAR;
493
+ s_arrButton[GUI_BUTTON_PREVIOUS].pressCallback = PreviouCallback;
494
+ CreateButtonWidget(&s_arrButton[GUI_BUTTON_PREVIOUS]);
495
+
496
+ //������һ�ť
497
+ InitButtonWidgetStruct(&s_arrButton[GUI_BUTTON_NEXT]);
498
+ s_arrButton[GUI_BUTTON_NEXT].x0 = 373;
499
+ s_arrButton[GUI_BUTTON_NEXT].y0 = 733;
500
+ s_arrButton[GUI_BUTTON_NEXT].width = 53;
501
+ s_arrButton[GUI_BUTTON_NEXT].height = 53;
502
+ s_arrButton[GUI_BUTTON_NEXT].text = "";
503
+ s_arrButton[GUI_BUTTON_NEXT].pressImageType = GUI_IMAGE_TYPE_CLEAR;
504
+ s_arrButton[GUI_BUTTON_NEXT].releaseImageType = GUI_IMAGE_TYPE_CLEAR;
505
+ s_arrButton[GUI_BUTTON_NEXT].pressCallback = NextCallback;
506
+ CreateButtonWidget(&s_arrButton[GUI_BUTTON_NEXT]);
507
+
508
+ //�������հ�ť
509
+ InitButtonWidgetStruct(&s_arrButton[GUI_BUTTON_PHOTO]);
510
+ s_arrButton[GUI_BUTTON_PHOTO].x0 = 183;
511
+ s_arrButton[GUI_BUTTON_PHOTO].y0 = 622;
512
+ s_arrButton[GUI_BUTTON_PHOTO].width = 115;
513
+ s_arrButton[GUI_BUTTON_PHOTO].height = 115;
514
+ s_arrButton[GUI_BUTTON_PHOTO].text = "";
515
+ s_arrButton[GUI_BUTTON_PHOTO].pressImageType = GUI_IMAGE_TYPE_CLEAR;
516
+ s_arrButton[GUI_BUTTON_PHOTO].releaseImageType = GUI_IMAGE_TYPE_CLEAR;
517
+ s_arrButton[GUI_BUTTON_PHOTO].pressCallback = TakePhotoCallback;
518
+ CreateButtonWidget(&s_arrButton[GUI_BUTTON_PHOTO]);
519
+
520
+ //������ѡ�ؼ�
521
+ for(i = 0; i < GUI_RADIO_MAX; i++)
522
+ {
523
+ InitRadioWidgetStruct(&s_arrRadio[i]);
524
+ s_arrRadio[i].x0 = s_arrX0[i];
525
+ s_arrRadio[i].y0 = s_arrY0[i];
526
+ s_arrRadio[i].width = 75;
527
+ s_arrRadio[i].height = 75;
528
+ s_arrRadio[i].type = RADIO_TYPE_LINE;
529
+ s_arrRadio[i].lineColor = GUI_COLOR_WHITE;
530
+ s_arrRadio[i].lineSize = 4;
531
+ s_arrRadio[i].background = MyMalloc(SRAMEX, s_arrRadio[i].width * s_arrRadio[i].height * 2);
532
+ s_arrRadio[i].pressCallback = RadioPressCallback;
533
+ CreateRadioWidget(&s_arrRadio[i]);
534
+ }
535
+
536
+ //Ϊ�ַ������������ڴ�
537
+ s_pStringBackground = MyMalloc(SRAMEX, (STRING_X1 - STRIGN_X0) * STRING_SIZE * 2);
538
+ if(NULL == s_pStringBackground)
539
+ {
540
+ while(1);
541
+ }
542
+
543
+ //�����ַ�������
544
+ GUISaveBackground(STRIGN_X0, STRING_Y0, STRING_X1 - STRIGN_X0, STRING_SIZE, (u32)s_pStringBackground);
545
+
546
+ //����OV2640
547
+ InitOV2640();
548
+ OV2640RGB565Mode();
549
+ OV2640OutSizeSet(IMAGE_WIDTH, IMAGE_HEIGHT);
550
+ OV2640AutoExposure(0);
551
+ OV2640LightMode(s_iLightMode);
552
+ OV2640ColorSaturation(s_iColorSaturation);
553
+ OV2640Brightness(s_iBrightness);
554
+ OV2640Contrast(s_iContrast);
555
+ OV2640SpecialEffects(s_iEffects);
556
+
557
+ //����ͼ���Դ��ַΪǰ�����׵�ַ
558
+ s_iImageFrameAdd = g_structTLILCDDev.foreFrameAddr;
559
+
560
+ //����DCI
561
+ InitDCI(s_iImageFrameAdd, IMAGE_SIZE, IMAGE_X0, IMAGE_Y0, IMAGE_WIDTH, IMAGE_HEIGHT, 1);
562
+ }
563
+
564
+ /*********************************************************************************************************
565
+ * �������ƣ�DeleteGUICamera
566
+ * �������ܣ�ɾ�������
567
+ * ���������void
568
+ * ���������void
569
+ * �� �� ֵ��void
570
+ * �������ڣ�2021��07��01��
571
+ * ע �⣺
572
+ *********************************************************************************************************/
573
+ void DeleteGUICamera(void)
574
+ {
575
+ u32 i;
576
+
577
+ //��λDCI
578
+ DeInitDCI();
579
+
580
+ //����ͷ�������ģʽ
581
+ OV2640PWDNSet(1);
582
+
583
+ //����ǰ����
584
+ //LCDLayerDisable(LCD_LAYER_FOREGROUND);
585
+
586
+ //�ͷŵ�ѡ�ؼ�����Ķ�̬�ڴ棬��ɾ���ؼ�
587
+ for(i = 0; i < GUI_RADIO_MAX; i++)
588
+ {
589
+ MyFree(SRAMEX, s_arrRadio[i].background);
590
+ DeleteRadioWidget(&s_arrRadio[i]);
591
+ }
592
+
593
+ //ɾ�������ؼ�
594
+ for(i = 0; i < GUI_BUTTON_MAX; i++)
595
+ {
596
+ DeleteButtonWidget(&s_arrButton[i]);
597
+ }
598
+ }
599
+
600
+ /*********************************************************************************************************
601
+ * �������ƣ�GUICameraPoll
602
+ * �������ܣ��������ѯ����
603
+ * ���������void
604
+ * ���������void
605
+ * �� �� ֵ��void
606
+ * �������ڣ�2021��07��01��
607
+ * ע �⣺
608
+ *********************************************************************************************************/
609
+ void GUICameraPoll(void)
610
+ {
611
+ EnumGUIRadio radio;
612
+ u32 i;
613
+
614
+ //��ʾһ֡ͼ�ε���Ļ��
615
+ DCIShowImage();
616
+
617
+ //��ѡ�ؼ�ɨ��
618
+ radio = ScanGUIRadio();
619
+ if(s_enumRadio != radio)
620
+ {
621
+ s_enumRadio = radio;
622
+ RadioChange();
623
+ }
624
+
625
+ //����ɨ��
626
+ for(i = 0; i < GUI_BUTTON_MAX; i++)
627
+ {
628
+ ScanButtonWidget(&s_arrButton[i]);
629
+ }
630
+ }
deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUICamera.h ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�GUICamera.h
3
+ * ժ Ҫ�������ģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+ #ifndef _GUI_CAMERA_H_
17
+ #define _GUI_CAMERA_H_
18
+
19
+ /*********************************************************************************************************
20
+ * ����ͷ�ļ�
21
+ *********************************************************************************************************/
22
+ #include "DataType.h"
23
+
24
+ /*********************************************************************************************************
25
+ * �궨��
26
+ *********************************************************************************************************/
27
+
28
+ /*********************************************************************************************************
29
+ * ö�ٽṹ�嶨��
30
+ *********************************************************************************************************/
31
+
32
+ /*********************************************************************************************************
33
+ * API��������
34
+ *********************************************************************************************************/
35
+ void CreateGUICamera(void); //���������
36
+ void DeleteGUICamera(void); //ɾ�������
37
+ void GUICameraPoll(void); //�������ѯ����
38
+
39
+ #endif
deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUICanvas.c ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�GUICanvas.c
3
+ * ժ Ҫ������ģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+
17
+ /*********************************************************************************************************
18
+ * ����ͷ�ļ�
19
+ *********************************************************************************************************/
20
+ #include "GUICanvas.h"
21
+ #include "GUIPlatform.h"
22
+ #include "TLILCD.h"
23
+ #include "BMP.h"
24
+ #include "Common.h"
25
+ #include "stdio.h"
26
+ #include "Touch.h"
27
+ #include "SysTick.h"
28
+ #include "KeyOne.h"
29
+
30
+ /*********************************************************************************************************
31
+ * �궨��
32
+ *********************************************************************************************************/
33
+
34
+ /*********************************************************************************************************
35
+ * ö�ٽṹ�嶨��
36
+ *********************************************************************************************************/
37
+
38
+ /*********************************************************************************************************
39
+ * �ڲ�����
40
+ *********************************************************************************************************/
41
+ //������ɫ
42
+ static const u16 s_arrLineColor[5] = {LCD_COLOR_YELLOW, LCD_COLOR_GREEN, LCD_COLOR_BLUE, LCD_COLOR_CYAN, LCD_COLOR_RED};
43
+
44
+ //������ɨ����
45
+ static StructTouchDev* s_pTouchDev;
46
+
47
+ //��������Ƿ��ѿ�ʼ����
48
+ static u8 s_arrFirstFlag[5] = {1, 1, 1, 1, 1};
49
+
50
+ //��һ���������
51
+ static StructTouchPoint s_arrLastPoints[5];
52
+
53
+ /*********************************************************************************************************
54
+ * �ڲ���������
55
+ *********************************************************************************************************/
56
+ static void ClearCanvas(void); //�廭��
57
+
58
+ /*********************************************************************************************************
59
+ * �ڲ�����ʵ��
60
+ *********************************************************************************************************/
61
+ /*********************************************************************************************************
62
+ * �������ƣ�ClearCanvas
63
+ * �������ܣ��廭��
64
+ * ���������void
65
+ * ���������void
66
+ * �� �� ֵ��void
67
+ * �������ڣ�2021��07��01��
68
+ * ע �⣺
69
+ *********************************************************************************************************/
70
+ static void ClearCanvas(void)
71
+ {
72
+ u32 i;
73
+
74
+ //�ȴ��û���ָ�뿪��Ļ
75
+ WaitForTouchRelease();
76
+
77
+ //�廭��
78
+ DisPlayBMPByIPA(0, 0, MAIN_WINDOWN_BACKGROUND_DIR);
79
+ for(i = 0; i < sizeof(s_arrFirstFlag) / sizeof(u8); i++)
80
+ {
81
+ s_arrFirstFlag[i] = 1;
82
+ s_arrLastPoints[i].x = 0xFFFF;
83
+ s_arrLastPoints[i].y = 0xFFFF;
84
+ s_arrLastPoints[i].size = 0;
85
+ }
86
+ }
87
+
88
+ /*********************************************************************************************************
89
+ * API����ʵ��
90
+ *********************************************************************************************************/
91
+ /*********************************************************************************************************
92
+ * �������ƣ�CreateGUICanvas
93
+ * �������ܣ���������
94
+ * ���������void
95
+ * ���������void
96
+ * �� �� ֵ��void
97
+ * �������ڣ�2021��07��01��
98
+ * ע �⣺
99
+ *********************************************************************************************************/
100
+ void CreateGUICanvas(void)
101
+ {
102
+ //LCD������ʾ
103
+ LCDDisplayDir(LCD_SCREEN_VERTICAL);
104
+
105
+ //�廭��
106
+ ClearCanvas();
107
+
108
+ //��ȡ������ɨ���豸�ṹ���ַ
109
+ s_pTouchDev = GetTouchDev();
110
+ }
111
+
112
+ /*********************************************************************************************************
113
+ * �������ƣ�GUICanvasPoll
114
+ * �������ܣ�������ѯ����
115
+ * ���������void
116
+ * ���������void
117
+ * �� �� ֵ��void
118
+ * �������ڣ�2021��07��01��
119
+ * ע �⣺
120
+ *********************************************************************************************************/
121
+ void GUICanvasPoll(void)
122
+ {
123
+ u8 i;
124
+ u16 x0, y0, x1, y1, size, color;
125
+
126
+ //KEY1ɨ��
127
+ ScanKeyOne(KEY_NAME_KEY1, NULL, ClearCanvas);
128
+
129
+ //ѭ������5����
130
+ for(i = 0; i < 5; i++)
131
+ {
132
+ //�м�⵽����
133
+ if(1 == s_pTouchDev->pointFlag[i])
134
+ {
135
+ //�������յ����ꡢ��ɫ�ʹ����С
136
+ x0 = s_arrLastPoints[i].x;
137
+ y0 = s_arrLastPoints[i].y;
138
+ x1 = s_pTouchDev->point[i].x;
139
+ y1 = s_pTouchDev->point[i].y;
140
+ color = s_arrLineColor[i];
141
+ size = s_pTouchDev->point[i].size;
142
+
143
+ //����̫����Ҫ��С����
144
+ size = size / 5;
145
+ if(0 == size)
146
+ {
147
+ size = 1;
148
+ }
149
+ else if(size > 15)
150
+ {
151
+ size = 15;
152
+ }
153
+
154
+ //������һ�����û��㷽ʽ
155
+ if(1 == s_arrFirstFlag[i])
156
+ {
157
+ //��������Ѿ���ʼ����
158
+ s_arrFirstFlag[i] = 0;
159
+ GUIDrawPoint(x1, y1, size / 2, color);
160
+ }
161
+
162
+ //��ߵ��û��߷�ʽ
163
+ else
164
+ {
165
+ GUIDrawLine(x0, y0, x1, y1, size, color, GUI_LINE_CIRCLE);
166
+ }
167
+
168
+ //���浱ǰλ�ã�Ϊ������׼��
169
+ s_arrLastPoints[i].x = s_pTouchDev->point[i].x;
170
+ s_arrLastPoints[i].y = s_pTouchDev->point[i].y;
171
+ }
172
+ else
173
+ {
174
+ //��Ǹ�����δ��ʼ����
175
+ s_arrFirstFlag[i] = 1;
176
+ }
177
+ }
178
+ }
179
+
180
+ /*********************************************************************************************************
181
+ * �������ƣ�DeleteGUICanvas
182
+ * �������ܣ�ɾ������
183
+ * ���������void
184
+ * ���������void
185
+ * �� �� ֵ��void
186
+ * �������ڣ�2021��07��01��
187
+ * ע �⣺
188
+ *********************************************************************************************************/
189
+ void DeleteGUICanvas(void)
190
+ {
191
+
192
+ }
deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUICanvas.h ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�GUICanvas.h
3
+ * ժ Ҫ������ģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+ #ifndef _GUI_CANVAS_H_
17
+ #define _GUI_CANVAS_H_
18
+
19
+ /*********************************************************************************************************
20
+ * ����ͷ�ļ�
21
+ *********************************************************************************************************/
22
+ #include "DataType.h"
23
+
24
+ /*********************************************************************************************************
25
+ * �궨��
26
+ *********************************************************************************************************/
27
+
28
+ /*********************************************************************************************************
29
+ * ö�ٽṹ�嶨��
30
+ *********************************************************************************************************/
31
+
32
+ /*********************************************************************************************************
33
+ * API��������
34
+ *********************************************************************************************************/
35
+ void CreateGUICanvas(void); //��������
36
+ void GUICanvasPoll(void); //������ѯ����
37
+ void DeleteGUICanvas(void); //ɾ������
38
+
39
+ #endif
deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUIClock.c ADDED
@@ -0,0 +1,250 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�GUIClock.c
3
+ * ժ Ҫ��ʱ��ģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+
17
+ /*********************************************************************************************************
18
+ * ����ͷ�ļ�
19
+ *********************************************************************************************************/
20
+ #include "GUIClock.h"
21
+ #include "GUIPlatform.h"
22
+ #include "TLILCD.h"
23
+ #include "BMP.h"
24
+ #include "Common.h"
25
+ #include "stdio.h"
26
+ #include "Malloc.h"
27
+ #include "FontLib.h"
28
+ #include "RTC.h"
29
+
30
+ /*********************************************************************************************************
31
+ * �궨��
32
+ *********************************************************************************************************/
33
+ #define GUI_CLOCK_BACK_COLOR RGB888ToRGB565A(69, 185, 124) //ʱ��ģ�鱳����ɫ
34
+
35
+ //ʱ����ʾλ�ö���
36
+ #define TIME_Y0 (160)
37
+ #define HOUR_X0 (120)
38
+ #define HOUR_X1 (HOUR_X0 + 80)
39
+ #define COLON_X0 (HOUR_X1 + 80)
40
+ #define MIN_X0 (COLON_X0 + 36)
41
+ #define MIN_X1 (MIN_X0 + 80)
42
+ #define COLON_X1 (MIN_X1 + 80)
43
+ #define SEC_X0 (COLON_X1 + 36)
44
+ #define SEC_X1 (SEC_X0 + 80)
45
+
46
+ /*********************************************************************************************************
47
+ * ö�ٽṹ�嶨��
48
+ *********************************************************************************************************/
49
+
50
+ /*********************************************************************************************************
51
+ * �ڲ�����
52
+ *********************************************************************************************************/
53
+ //ʱ�����
54
+ static u32 s_iHour = 0xFFFFFFFF, s_iMin = 0xFFFFFFFF, s_iSec = 0xFFFFFFFF;
55
+
56
+ //�����ַ���
57
+ static const char* s_arrWeek[] =
58
+ {
59
+ "����һ",
60
+ "���ڶ�",
61
+ "������",
62
+ "������",
63
+ "������",
64
+ "������",
65
+ "������",
66
+ };
67
+
68
+ /*********************************************************************************************************
69
+ * �ڲ���������
70
+ *********************************************************************************************************/
71
+ static void DiaplayChar160x80(u32 x0, u32 y0, u32 code); //��ʾ160x80�ַ�
72
+
73
+ /*********************************************************************************************************
74
+ * �ڲ�����ʵ��
75
+ *********************************************************************************************************/
76
+ /*********************************************************************************************************
77
+ * �������ƣ�DiaplayChar160x80
78
+ * �������ܣ���ʾ160x80�ַ�
79
+ * ���������x0��y0����ʾ��ʼ���꣬code��ASCII�����
80
+ * ���������void
81
+ * �� �� ֵ��void
82
+ * �������ڣ�2021��07��01��
83
+ * ע �⣺
84
+ * 1��160x80���ֵ������ݹ̶�Ϊ1600�ֽ�
85
+ * 2��ɨ�跽ʽ�������ҡ����ϵ��£��ֽڸ�λ��ǰ����λ�ں�
86
+ *********************************************************************************************************/
87
+ static void DiaplayChar160x80(u32 x0, u32 y0, u32 code)
88
+ {
89
+ u32 x, y, i, j;
90
+ u8 byte;
91
+ u8* buf;
92
+
93
+ //�ַ���ʾ�ڴ�����
94
+ buf = MyMalloc(SRAMEX, 1600);
95
+ if(NULL == buf)
96
+ {
97
+ printf("DiaplayChar160x80: ���붯̬�ڴ�ʧ��\r\n");
98
+ while(1);
99
+ }
100
+
101
+ //��ȡ��������
102
+ GetFont160x80(code, buf);
103
+
104
+ //�屳��
105
+ if(':' == code)
106
+ {
107
+ LCDFill(x0, y0, 36, 160, GUI_CLOCK_BACK_COLOR);
108
+ }
109
+ else
110
+ {
111
+ LCDFill(x0, y0, 80, 160, GUI_CLOCK_BACK_COLOR);
112
+ }
113
+
114
+ //��ʾ�ַ�
115
+ x = x0;
116
+ y = y0;
117
+ for(i = 0; i < 1600; i++)
118
+ {
119
+ byte = buf[i];
120
+ for(j = 0; j < 8; j++)
121
+ {
122
+ if(byte & 0x80)
123
+ {
124
+ LCDDrawPoint(x, y, LCD_COLOR_WHITE);
125
+ }
126
+ byte = byte << 1;
127
+
128
+ x++;
129
+ if((x - x0) >= 80)
130
+ {
131
+ y++;
132
+ x = x0;
133
+ }
134
+ }
135
+ }
136
+
137
+ //�ͷ��ڴ�
138
+ MyFree(SRAMEX, buf);
139
+ }
140
+
141
+ /*********************************************************************************************************
142
+ * API����ʵ��
143
+ *********************************************************************************************************/
144
+ /*********************************************************************************************************
145
+ * �������ƣ�CreateGUIClock
146
+ * �������ܣ�����ʱ��
147
+ * ���������void
148
+ * ���������void
149
+ * �� �� ֵ��void
150
+ * �������ڣ�2021��07��01��
151
+ * ע �⣺
152
+ *********************************************************************************************************/
153
+ void CreateGUIClock(void)
154
+ {
155
+ //LCD������ʾ
156
+ LCDDisplayDir(LCD_SCREEN_HORIZONTAL);
157
+
158
+ //��ս�����ʾ
159
+ LCDClear(GUI_CLOCK_BACK_COLOR);
160
+
161
+ //��ʾð��
162
+ DiaplayChar160x80(COLON_X0, TIME_Y0, ':');
163
+ DiaplayChar160x80(COLON_X1, TIME_Y0, ':');
164
+
165
+ s_iHour = 0xFFFFFFFF;
166
+ s_iMin = 0xFFFFFFFF;
167
+ s_iSec = 0xFFFFFFFF;
168
+ }
169
+
170
+ /*********************************************************************************************************
171
+ * �������ƣ�DeleteGUIClock
172
+ * �������ܣ�ɾ��ʱ��
173
+ * ���������void
174
+ * ���������void
175
+ * �� �� ֵ��void
176
+ * �������ڣ�2021��07��01��
177
+ * ע �⣺
178
+ *********************************************************************************************************/
179
+ void DeleteGUIClock(void)
180
+ {
181
+
182
+ }
183
+
184
+ /*********************************************************************************************************
185
+ * �������ƣ�GUIClockPoll
186
+ * �������ܣ�ʱ����ѯ����
187
+ * ���������void
188
+ * ���������void
189
+ * �� �� ֵ��void
190
+ * �������ڣ�2021��07��01��
191
+ * ע �⣺
192
+ *********************************************************************************************************/
193
+ void GUIClockPoll(void)
194
+ {
195
+ u32 hour, min, sec;
196
+ u32 year, mon, date, week;
197
+ char string[32];
198
+
199
+ //��ȡʱ��
200
+ RTCGetTime(&hour, &min, &sec);
201
+
202
+ //Сʱ��λ
203
+ if(((s_iHour / 10) != (hour / 10)) || (0xFFFFFFFF == s_iHour))
204
+ {
205
+ DiaplayChar160x80(HOUR_X0, TIME_Y0, 48 + hour / 10);
206
+ }
207
+
208
+ //Сʱ��λ
209
+ if(((s_iHour % 10) != (hour % 10)) || (0xFFFFFFFF == s_iHour))
210
+ {
211
+ DiaplayChar160x80(HOUR_X1, TIME_Y0, 48 + hour % 10);
212
+ }
213
+
214
+ //���Ӹ�λ
215
+ if(((s_iMin / 10) != (min / 10)) || (0xFFFFFFFF == s_iMin))
216
+ {
217
+ DiaplayChar160x80(MIN_X0, TIME_Y0, 48 + min / 10);
218
+ }
219
+
220
+ //���ӵ�λ
221
+ if(((s_iMin % 10) != (min % 10)) || (0xFFFFFFFF == s_iMin))
222
+ {
223
+ DiaplayChar160x80(MIN_X1, TIME_Y0, 48 + min % 10);
224
+ }
225
+
226
+ //���λ
227
+ if(((s_iSec / 10) != (sec / 10)) || (0xFFFFFFFF == s_iSec))
228
+ {
229
+ DiaplayChar160x80(SEC_X0, TIME_Y0, 48 + sec / 10);
230
+ }
231
+
232
+ //���ӵ�λ
233
+ if(((s_iSec % 10) != (sec % 10)) || (0xFFFFFFFF == s_iSec))
234
+ {
235
+ DiaplayChar160x80(SEC_X1, TIME_Y0, 48 + sec % 10);
236
+ }
237
+
238
+ //��ʾ����
239
+ if((s_iHour != hour) || (s_iMin != min) || (s_iSec != sec))
240
+ {
241
+ RTCGetDate(&year, &mon, &date, &week);
242
+ sprintf(string, "%02d��%02d��%02d�� %s", year, mon, date, s_arrWeek[week - 1]);
243
+ LCDFill(0, TIME_Y0 - 10, 800, 24, GUI_CLOCK_BACK_COLOR);
244
+ GUIDrawTextLine(HOUR_X0 + 10, TIME_Y0 - 10, (u32)string, GUI_FONT_ASCII_24, NULL, GUI_COLOR_WHITE, 1, 32);
245
+ }
246
+
247
+ s_iHour = hour;
248
+ s_iMin = min;
249
+ s_iSec = sec;
250
+ }
deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUIClock.h ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�GUIClock.h
3
+ * ժ Ҫ��ʱ��ģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+ #ifndef _GUI_CLOCK_H_
17
+ #define _GUI_CLOCK_H_
18
+
19
+ /*********************************************************************************************************
20
+ * ����ͷ�ļ�
21
+ *********************************************************************************************************/
22
+ #include "DataType.h"
23
+
24
+ /*********************************************************************************************************
25
+ * �궨��
26
+ *********************************************************************************************************/
27
+
28
+ /*********************************************************************************************************
29
+ * ö�ٽṹ�嶨��
30
+ *********************************************************************************************************/
31
+
32
+ /*********************************************************************************************************
33
+ * API��������
34
+ *********************************************************************************************************/
35
+ void CreateGUIClock(void); //����ʱ��
36
+ void DeleteGUIClock(void); //ɾ��ʱ��
37
+ void GUIClockPoll(void); //ʱ����ѯ����
38
+
39
+ #endif
deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUIEthernet.c ADDED
@@ -0,0 +1,594 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�GUIEthernet.c
3
+ * ժ Ҫ��GUI ��̫��ͨ��ģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+
17
+ /*********************************************************************************************************
18
+ * ����ͷ�ļ�
19
+ *********************************************************************************************************/
20
+ #include "GUIEthernet.h"
21
+ #include "GUIPlatform.h"
22
+ #include "ButtonWidget.h"
23
+ #include "LineEditWidget.h"
24
+ #include "TerminalWidget.h"
25
+ #include "TLILCD.h"
26
+ #include "BMP.h"
27
+ #include "JPEG.h"
28
+ #include "Common.h"
29
+ #include "SysTick.h"
30
+ #include "Timer.h"
31
+ #include "stdio.h"
32
+ #include "LWIPComm.h"
33
+ #include "TCPServerBase.h"
34
+ #include "RTC.h"
35
+ #include "Malloc.h"
36
+
37
+ /*********************************************************************************************************
38
+ * �궨��
39
+ *********************************************************************************************************/
40
+ #define MAX_STRING_LEN 64 //��ʾ�ַ���󳤶�
41
+
42
+ /*********************************************************************************************************
43
+ * ö�ٽṹ�嶨��
44
+ *********************************************************************************************************/
45
+ typedef enum
46
+ {
47
+ GUI_BUTTON_K7 = 0, //K7�����������Ǵ�0��ʼ
48
+ GUI_BUTTON_K8, //K8����
49
+ GUI_BUTTON_K9, //K9����
50
+ GUI_BUTTON_K4, //K4����
51
+ GUI_BUTTON_K5, //K5����
52
+ GUI_BUTTON_K6, //K6����
53
+ GUI_BUTTON_K1, //K1����
54
+ GUI_BUTTON_K2, //K2����
55
+ GUI_BUTTON_K3, //K3����
56
+ GUI_BUTTON_POINT, //С�㰴��
57
+ GUI_BUTTON_K0, //K0����
58
+ GUI_BUTTON_BACK, //ɾ����ť
59
+ GUI_BUTTON_SEND, //���Ͱ�ť
60
+ GUI_BUTTON_MAX, //��������
61
+ GUI_BUTTON_NONE, //������
62
+ }EnumGUIButtons;
63
+
64
+ typedef enum
65
+ {
66
+ GUI_LINE_EDIT_CLIENT_IP = 0, //�ͻ���IP�������Ǵ�0��ʼ
67
+ GUI_LINE_EDIT_SEND_DATA, //��������
68
+ GUI_LINE_EDIT_MAX, //�ؼ�����
69
+ GUI_LINE_EDIT_NONE, //��Ч�ؼ�
70
+ }EnumGUILineEdit;
71
+
72
+ /*********************************************************************************************************
73
+ * �ڲ�����
74
+ *********************************************************************************************************/
75
+ //�������
76
+ static StructButtonWidget s_arrButton[GUI_BUTTON_MAX]; //��������
77
+ static EnumGUIButtons s_enumButtonPress; //��������Ǹ���������
78
+
79
+ //�б༭���
80
+ static StructLineEditWidget s_arrLineEdit[GUI_LINE_EDIT_MAX];
81
+
82
+ //�ն����
83
+ static StructTerminalWidget s_structTerminal;
84
+
85
+ //�ַ���ת��������
86
+ static char s_arrStringBuff[MAX_STRING_LEN];
87
+
88
+ /*********************************************************************************************************
89
+ * �ڲ���������
90
+ *********************************************************************************************************/
91
+ static void ButtonPressCallback(void* button); //�����ص�����
92
+ static EnumGUIButtons ScanGUIButton(void); //����ɨ��
93
+ static void LineEditPressCallback(void* lineEdit); //�б༭�ص�����
94
+ static void ScanGUILineEdit(void); //�б༭ģ��ɨ��
95
+ static void ReadClientData(void); //��ȡ�ͻ������ݲ���ӡ������ն�
96
+ static void SendDataToClient(char* ip, char* data); //�������ݸ�ָ���ͻ���
97
+
98
+ /*********************************************************************************************************
99
+ * �ڲ�����ʵ��
100
+ *********************************************************************************************************/
101
+ /*********************************************************************************************************
102
+ * �������ƣ�ButtonPressCallback
103
+ * �������ܣ������ص�����
104
+ * ���������void
105
+ * ���������void
106
+ * �� �� ֵ��void
107
+ * �������ڣ�2021��07��01��
108
+ * ע �⣺
109
+ *********************************************************************************************************/
110
+ static void ButtonPressCallback(void* button)
111
+ {
112
+ EnumGUIButtons i;
113
+
114
+ for(i = (EnumGUIButtons)0; i < GUI_BUTTON_MAX; i++)
115
+ {
116
+ if((StructButtonWidget*)button == &s_arrButton[i])
117
+ {
118
+ s_enumButtonPress = i;
119
+ return;
120
+ }
121
+ }
122
+ }
123
+
124
+ /*********************************************************************************************************
125
+ * �������ƣ�ScanGUIButton
126
+ * �������ܣ�����ɨ��
127
+ * ���������void
128
+ * ���������void
129
+ * �� �� ֵ��void
130
+ * �������ڣ�2021��07��01��
131
+ * ע �⣺ÿ��20����ִ��һ��
132
+ *********************************************************************************************************/
133
+ static EnumGUIButtons ScanGUIButton(void)
134
+ {
135
+ EnumGUIButtons i;
136
+
137
+ for(i = (EnumGUIButtons)0; i < GUI_BUTTON_MAX; i++)
138
+ {
139
+ s_enumButtonPress = GUI_BUTTON_NONE;
140
+ ScanButtonWidget(&s_arrButton[i]);
141
+
142
+ if(GUI_BUTTON_NONE != s_enumButtonPress)
143
+ {
144
+ return s_enumButtonPress;
145
+ }
146
+ }
147
+
148
+ return GUI_BUTTON_NONE;
149
+ }
150
+
151
+ /*********************************************************************************************************
152
+ * �������ƣ�LineEditPressCallback
153
+ * �������ܣ��б༭�ص�����
154
+ * ���������void
155
+ * ���������void
156
+ * �� �� ֵ��void
157
+ * �������ڣ�2021��07��01��
158
+ * ע �⣺���ҽ���һ���б༭�ؼ��ܻ�ȡ����
159
+ *********************************************************************************************************/
160
+ static void LineEditPressCallback(void* lineEdit)
161
+ {
162
+ u8 i;
163
+ for(i = 0; i < GUI_LINE_EDIT_MAX; i++)
164
+ {
165
+ if((StructLineEditWidget*)lineEdit != &s_arrLineEdit[i])
166
+ {
167
+ //ȡ���ؼ�����״̬
168
+ ClearLineEditWidgetFocus(&s_arrLineEdit[i]);
169
+ }
170
+ }
171
+ }
172
+
173
+ /*********************************************************************************************************
174
+ * �������ƣ�ScanGUILineEdit
175
+ * �������ܣ��б༭ģ��ɨ��
176
+ * ���������void
177
+ * ���������void
178
+ * �� �� ֵ��void
179
+ * �������ڣ�2021��07��01��
180
+ * ע �⣺
181
+ *********************************************************************************************************/
182
+ static void ScanGUILineEdit(void)
183
+ {
184
+ u8 i;
185
+ for(i = 0; i < GUI_LINE_EDIT_MAX; i++)
186
+ {
187
+ ScanLineEditWidget(&s_arrLineEdit[i]);
188
+ }
189
+ }
190
+
191
+ /*********************************************************************************************************
192
+ * �������ƣ�ReadClientData
193
+ * �������ܣ���ȡ�ͻ������ݲ���ӡ������ն�
194
+ * ���������void
195
+ * ���������void
196
+ * �� �� ֵ��void
197
+ * �������ڣ�2021��07��01��
198
+ * ע �⣺
199
+ *********************************************************************************************************/
200
+ static void ReadClientData(void)
201
+ {
202
+ static char s_arrReadBuf[64]; //��ȡ������
203
+ u32 readCnt; //��ȡ����������
204
+ u32 i; //ѭ������
205
+ u32 ipAddr; //�ͻ���IP��ַ
206
+ u8 ip[4]; //�ͻ���IP��ַ���
207
+ u32 hour, minute, second; //ϵͳ����ʱ�䣨Сʱ�����ӡ��룩
208
+
209
+ //ѭ�����ÿ���ͻ����Ƿ��з������ݵ�������
210
+ for(i = 0; i < TCP_SERVER_CLIENT_NUM; i++)
211
+ {
212
+ //��ȡ�ͻ���IP��ַ
213
+ ipAddr = GetClientIP((EnumTCPClientList)i);
214
+
215
+ //һ���Զ����ͻ��������������ݣ�����ȡ��Ϊ����������-1
216
+ readCnt = ReadTCPServer(i, (u8*)s_arrReadBuf, (sizeof(s_arrReadBuf) / sizeof(u8)) - 1);
217
+
218
+ //IP��ַ��Ϊ�㣬��ʾ�пͻ��˽��ϣ�readCnt���������ʾ�ɹ���ȡ������
219
+ if(0 != ipAddr && readCnt > 0)
220
+ {
221
+ //��ȡʵʱʱ��ʱ��
222
+ RTCGetTime(&hour, &minute, &second);
223
+
224
+ //����ַ�����β
225
+ s_arrReadBuf[readCnt] = 0;
226
+
227
+ //�ն����һ������
228
+ TerminalWidgetShowLine(&s_structTerminal, "");
229
+
230
+ //��ӡ�ͻ���IP��ַ���ն�
231
+ ip[0] = (ipAddr >> 0 ) & 0xff; //IADDR4
232
+ ip[1] = (ipAddr >> 8 ) & 0xff; //IADDR3
233
+ ip[2] = (ipAddr >> 16) & 0xff; //IADDR2
234
+ ip[3] = (ipAddr >> 24) & 0xff; //IADDR1
235
+ sprintf(s_arrStringBuff, "<receive ip: %d.%d.%d.%d %02d:%02d:%02d>", ip[0], ip[1], ip[2], ip[3], hour, minute, second);
236
+ TerminalWidgetShowLine(&s_structTerminal, s_arrStringBuff);
237
+
238
+ //��ӡ�ͻ������ݵ��ն�
239
+ TerminalWidgetShowLine(&s_structTerminal, s_arrReadBuf);
240
+ }
241
+ }
242
+ }
243
+
244
+ /*********************************************************************************************************
245
+ * �������ƣ�SendDataToClient
246
+ * �������ܣ��������ݸ�ָ���ͻ���
247
+ * ���������ip���ͻ���IP��ַ��data��Ҫ���͵�����
248
+ * ���������void
249
+ * �� �� ֵ��void
250
+ * �������ڣ�2021��07��01��
251
+ * ע �⣺
252
+ *********************************************************************************************************/
253
+ static void SendDataToClient(char* ip, char* data)
254
+ {
255
+ u8 sum; //�ͣ�����IP��ַʱʹ��
256
+ u8 i; //ѭ������������IP��ַʱʹ��
257
+ u8 strCnt; //�ַ�����������IP��ַʱʹ��
258
+ u8 ipBuf[4]; //IP��ַ�������ʽ��
259
+ u32 ipAddr; //IP��ַ���ϲ���ʽ��
260
+ u32 sendNum; //��Ҫ���͵�������
261
+ u32 ret; //�������ݷ���ֵ����ʾ�ɹ����͵�������
262
+ u32 hour, minute, second; //ϵͳ����ʱ�䣨Сʱ�����ӡ��룩
263
+
264
+ //��ȡʵʱʱ��ʱ��
265
+ RTCGetTime(&hour, &minute, &second);
266
+
267
+ //������IP��ַ
268
+ strCnt = 0;
269
+ for(i = 0; i < 4; i++)
270
+ {
271
+ sum = 0;
272
+ while((ip[strCnt] >= '0') && (ip[strCnt] <= '9'))
273
+ {
274
+ sum = sum * 10 + (ip[strCnt] - 48);
275
+ strCnt++;
276
+ }
277
+ strCnt++;
278
+
279
+ ipBuf[i] = sum;
280
+ }
281
+ ipAddr = (ipBuf[0] << 0) | (ipBuf[1] << 8) | (ipBuf[2] << 16) | (ipBuf[3] << 24);
282
+
283
+ //ͳ�Ʒ���������
284
+ sendNum = 0;
285
+ while(0 != data[sendNum])
286
+ {
287
+ sendNum++;
288
+ }
289
+
290
+ //������ͨ��TCP�������������ͻ���
291
+ ret = WriteTCPServer(ipAddr, (u8*)data, sendNum);
292
+
293
+ //���һ������
294
+ TerminalWidgetShowLine(&s_structTerminal, "");
295
+
296
+ //���ʱ����Ϣ
297
+ sprintf(s_arrStringBuff, "<send ip: %d.%d.%d.%d %02d:%02d:%02d>", ipBuf[0], ipBuf[1], ipBuf[2], ipBuf[3], hour, minute, second);
298
+ TerminalWidgetShowLine(&s_structTerminal, (char*)s_arrStringBuff);
299
+
300
+ if(0 != ret)
301
+ {
302
+ //���ͳɹ�
303
+ TerminalWidgetShowLine(&s_structTerminal, (char*)data);
304
+ }
305
+ else
306
+ {
307
+ //����ʧ��
308
+ TerminalWidgetShowLine(&s_structTerminal, (char*)"Failed to send");
309
+ }
310
+ }
311
+
312
+ /*********************************************************************************************************
313
+ * API����ʵ��
314
+ *********************************************************************************************************/
315
+ /*********************************************************************************************************
316
+ * �������ƣ�CreateGUIEthernet
317
+ * �������ܣ�����GUI Ethernet����
318
+ * ���������void
319
+ * ���������void
320
+ * �� �� ֵ��void
321
+ * �������ڣ�2021��07��01��
322
+ * ע �⣺
323
+ *********************************************************************************************************/
324
+ void CreateGUIEthernet(void)
325
+ {
326
+ static const u16 s_arrButtonX[GUI_BUTTON_MAX] = {560, 640, 720, //K7-K9
327
+ 560, 640, 720, //K4-K5
328
+ 560, 640, 720, //K1-K3
329
+ 560, 640, 720}; //POINT-BACK
330
+
331
+ static const u16 s_arrButtonY[GUI_BUTTON_MAX] = {213, 213, 213, //K7-K9
332
+ 263, 263, 263, //K4-K5
333
+ 313, 313, 313, //K1-K3
334
+ 363, 363, 363}; //POINT-BACK
335
+
336
+ static const char* s_arrButtonText[16] = {"7","8", "9", "4", "5", "6", "1", "2", "3", ".", "0", "<-"};
337
+ static StructBmpImage s_structKeyNumPressImage;
338
+ static StructBmpImage s_structKeyNumReleaseImage;
339
+ static StructBmpImage s_structKeySendPressImage;
340
+ static StructBmpImage s_structKeySendReleaseImage;
341
+ static StructJpegImage s_structHasFocusImage;
342
+ static StructJpegImage s_structNoFocusImage;
343
+ static StructJpegImage s_structTerminalImage;
344
+ EnumGUIButtons i;
345
+ StructLWIPDev* lwipDev;
346
+
347
+ //LCD������ʾ
348
+ LCDDisplayDir(LCD_SCREEN_HORIZONTAL);
349
+
350
+ //��ʾ����ͼƬ
351
+ DisPlayBMPByIPA(0, 0, ETHERNET_BACKGROUND_DIR);
352
+
353
+ //��ʼ����������ͼƬ
354
+ s_structKeyNumPressImage.alphaType = BMP_GATE_ALPHA;
355
+ s_structKeyNumPressImage.alphaGate = 200;
356
+ s_structKeyNumPressImage.storageType = BMP_IN_FATFS;
357
+ s_structKeyNumPressImage.addr = (void*)ETHERNET_BUTTON_PRESS_60x45_DIR;
358
+
359
+ s_structKeyNumReleaseImage.alphaType = BMP_GATE_ALPHA;
360
+ s_structKeyNumReleaseImage.alphaGate = 200;
361
+ s_structKeyNumReleaseImage.storageType = BMP_IN_FATFS;
362
+ s_structKeyNumReleaseImage.addr = (void*)ETHERNET_BUTTON_RELEASE_60x45_DIR;
363
+
364
+ s_structKeySendPressImage.alphaType = BMP_GATE_ALPHA;
365
+ s_structKeySendPressImage.alphaGate = 200;
366
+ s_structKeySendPressImage.storageType = BMP_IN_FATFS;
367
+ s_structKeySendPressImage.addr = (void*)ETHERNET_BUTTON_PRESS_220x45_DIR;
368
+
369
+ s_structKeySendReleaseImage.alphaType = BMP_GATE_ALPHA;
370
+ s_structKeySendReleaseImage.alphaGate = 200;
371
+ s_structKeySendReleaseImage.storageType = BMP_IN_FATFS;
372
+ s_structKeySendReleaseImage.addr = (void*)ETHERNET_BUTTON_RELEASE_220x45_DIR;
373
+
374
+ //����ް�������
375
+ s_enumButtonPress = GUI_BUTTON_NONE;
376
+
377
+ //����K0-KF
378
+ for(i = (EnumGUIButtons)0; i <= GUI_BUTTON_BACK; i++)
379
+ {
380
+ InitButtonWidgetStruct(&s_arrButton[i]);
381
+ s_arrButton[i].x0 = s_arrButtonX[i];
382
+ s_arrButton[i].y0 = s_arrButtonY[i];
383
+ s_arrButton[i].width = 60;
384
+ s_arrButton[i].height = 45;
385
+
386
+ if(GUI_BUTTON_BACK == i)
387
+ {
388
+ s_arrButton[i].textX0 = 16;
389
+ s_arrButton[i].textY0 = 10;
390
+ }
391
+ else if(GUI_BUTTON_POINT == i)
392
+ {
393
+ s_arrButton[i].textX0 = 25;
394
+ s_arrButton[i].textY0 = 4;
395
+ }
396
+ else
397
+ {
398
+ s_arrButton[i].textX0 = 23;
399
+ s_arrButton[i].textY0 = 10;
400
+ }
401
+
402
+
403
+ s_arrButton[i].text = s_arrButtonText[i];
404
+ s_arrButton[i].pressBackgroudImage = (void*)(&s_structKeyNumPressImage);
405
+ s_arrButton[i].releaseBackgroudImage = (void*)(&s_structKeyNumReleaseImage);
406
+ s_arrButton[i].pressCallback = ButtonPressCallback;
407
+ CreateButtonWidget(&s_arrButton[i]);
408
+ }
409
+
410
+ //�������Ͱ�ť
411
+ InitButtonWidgetStruct(&s_arrButton[GUI_BUTTON_SEND]);
412
+ s_arrButton[GUI_BUTTON_SEND].x0 = 560;
413
+ s_arrButton[GUI_BUTTON_SEND].y0 = 413;
414
+ s_arrButton[GUI_BUTTON_SEND].width = 220;
415
+ s_arrButton[GUI_BUTTON_SEND].height = 45;
416
+ s_arrButton[GUI_BUTTON_SEND].textX0 = 86;
417
+ s_arrButton[GUI_BUTTON_SEND].textY0 = 10;
418
+ s_arrButton[GUI_BUTTON_SEND].text = "SEND";
419
+ s_arrButton[GUI_BUTTON_SEND].pressBackgroudImage = (void*)(&s_structKeySendPressImage);
420
+ s_arrButton[GUI_BUTTON_SEND].releaseBackgroudImage = (void*)(&s_structKeySendReleaseImage);
421
+ s_arrButton[GUI_BUTTON_SEND].pressCallback = ButtonPressCallback;
422
+ CreateButtonWidget(&s_arrButton[GUI_BUTTON_SEND]);
423
+
424
+ //��ʼ���б༭����ͼƬ
425
+ s_structHasFocusImage.image = (unsigned char*)ETHERNET_LINE_EDIT_HAS_FOCUS_220x45_DIR;
426
+ s_structNoFocusImage.image = (unsigned char*)ETHERNET_LINE_EDIT_NO_FOCUS_220x45_DIR;
427
+
428
+ //����ID
429
+ InitLineEditWidgetStruct(&s_arrLineEdit[GUI_LINE_EDIT_CLIENT_IP]);
430
+ s_arrLineEdit[GUI_LINE_EDIT_CLIENT_IP].x0 = 560;
431
+ s_arrLineEdit[GUI_LINE_EDIT_CLIENT_IP].y0 = 105;
432
+ s_arrLineEdit[GUI_LINE_EDIT_CLIENT_IP].width = 220;
433
+ s_arrLineEdit[GUI_LINE_EDIT_CLIENT_IP].height = 45;
434
+ s_arrLineEdit[GUI_LINE_EDIT_CLIENT_IP].textX0 = 2;
435
+ s_arrLineEdit[GUI_LINE_EDIT_CLIENT_IP].textY0 = 10;
436
+ s_arrLineEdit[GUI_LINE_EDIT_CLIENT_IP].hasFocusBackgroundImage = (void*)(&s_structHasFocusImage);
437
+ s_arrLineEdit[GUI_LINE_EDIT_CLIENT_IP].noFocusBackgroundImage = (void*)(&s_structNoFocusImage);
438
+ s_arrLineEdit[GUI_LINE_EDIT_CLIENT_IP].pressCallback = LineEditPressCallback;
439
+ CreateLineEditWidget(&s_arrLineEdit[GUI_LINE_EDIT_CLIENT_IP]);
440
+ SetLineEditPreText(&s_arrLineEdit[GUI_LINE_EDIT_CLIENT_IP], "IP:");
441
+
442
+ //��������
443
+ InitLineEditWidgetStruct(&s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA]);
444
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA].x0 = 560;
445
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA].y0 = 160;
446
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA].width = 220;
447
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA].height = 45;
448
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA].textX0 = 3;
449
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA].textY0 = 10;
450
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA].hasFocusBackgroundImage = (void*)(&s_structHasFocusImage);
451
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA].noFocusBackgroundImage = (void*)(&s_structNoFocusImage);
452
+ s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA].pressCallback = LineEditPressCallback;
453
+ CreateLineEditWidget(&s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA]);
454
+ SetLineEditPreText(&s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA], "DATA:");
455
+
456
+ //�ն˿ؼ�
457
+ InitTerminalWidgetStruct(&s_structTerminal);
458
+ s_structTerminalImage.image = (unsigned char*)ETHERNET_TERMINAL_BACKGROUND_DIR;
459
+ s_structTerminal.x0 = 20;
460
+ s_structTerminal.y0 = 60;
461
+ s_structTerminal.width = 520;
462
+ s_structTerminal.height = 400;
463
+ s_structTerminal.topOff = 30;
464
+ s_structTerminal.showSpace = 3;
465
+ s_structTerminal.textColor = GUI_COLOR_WHITE;
466
+ s_structTerminal.textFont = GUI_FONT_ASCII_24;
467
+ s_structTerminal.textHeight = 30;
468
+ s_structTerminal.background = NULL;
469
+ s_structTerminal.backImage = (void*)(&s_structTerminalImage);
470
+ s_structTerminal.imageType = GUI_IMAGE_TYPE_JPEG;
471
+ CreateTerminalWidget(&s_structTerminal);
472
+ TerminalWidgetClear(&s_structTerminal);
473
+
474
+ //��ȡLWIP�豸�ṹ���ַ�����ڴ�ӡTCP������IP��ַ
475
+ lwipDev = GetLWIPCommDev();
476
+
477
+ //LWIP��ʼ��
478
+ TerminalWidgetShowLine(&s_structTerminal, "Initializing LWIP");
479
+ while(LWIPCommInit())
480
+ {
481
+ TerminalWidgetShowLine(&s_structTerminal, "LWIP Init Falied!");
482
+ DelayNms(1200);
483
+ TerminalWidgetShowLine(&s_structTerminal, "Retrying...");
484
+ }
485
+ TerminalWidgetShowLine(&s_structTerminal, "LWIP Init Success!");
486
+ DelayNms(500);
487
+
488
+ #if LWIP_DHCP //ʹ��DHCP���Զ���ȡ����IP��ַ��
489
+ //�ȴ�DHCP��ȡ�ɹ�/��ʱ���
490
+ TerminalWidgetShowLine(&s_structTerminal, "DHCP IP configing...");
491
+ while((lwipDev->dhcpstatus!=2)&&(lwipDev->dhcpstatus!=0XFF))
492
+ {
493
+ LWIPPeriodicHandle();
494
+ LWIPReadPackHandle();
495
+ }
496
+ TerminalWidgetShowLine(&s_structTerminal, "DHCP IP configing finish");
497
+ #endif
498
+
499
+ //����TCP������
500
+ CreateTCPServer();
501
+
502
+ //��ʾ������IP
503
+ sprintf(s_arrStringBuff, "Server IP: %d.%d.%d.%d", lwipDev->ip[0], lwipDev->ip[1], lwipDev->ip[2], lwipDev->ip[3]);
504
+ GUIDrawTextLine(560, 56, (u32)s_arrStringBuff, GUI_FONT_ASCII_16, NULL, GUI_COLOR_WHITE, 1, 100);
505
+
506
+ //��ʾ�������˿�
507
+ sprintf(s_arrStringBuff, "Server Port: %d", TCP_SERVER_PORT);
508
+ GUIDrawTextLine(560, 78, (u32)s_arrStringBuff, GUI_FONT_ASCII_16, NULL, GUI_COLOR_WHITE, 1, 100);
509
+ }
510
+
511
+ /*********************************************************************************************************
512
+ * �������ƣ�DeleteGUIEthernet
513
+ * �������ܣ�ע��GUI Ethernet����
514
+ * ���������void
515
+ * ���������void
516
+ * �� �� ֵ��void
517
+ * �������ڣ�2021��07��01��
518
+ * ע �⣺
519
+ *********************************************************************************************************/
520
+ void DeleteGUIEthernet(void)
521
+ {
522
+ CloseTCPServer(); //�ر�TCP������
523
+ DeInitLWIPComm(); //ע��LWIP����λ��̫���ײ�����
524
+ }
525
+
526
+ /*********************************************************************************************************
527
+ * �������ƣ�GUIEthernetPoll
528
+ * �������ܣ�GUI Ethernet��ѯ����
529
+ * ���������void
530
+ * ���������void
531
+ * �� �� ֵ��void
532
+ * �������ڣ�2021��07��01��
533
+ * ע �⣺
534
+ *********************************************************************************************************/
535
+ void GUIEthernetPoll(void)
536
+ {
537
+ const char s_arrButtonValue[] = {'7', '8', '9', '4', '5', '6', '1', '2', '3', '.', '0'};
538
+ EnumGUIButtons button;
539
+ EnumGUILineEdit lineEdit;
540
+ char* ip;
541
+ char* data;
542
+
543
+ //����ɨ��
544
+ button = ScanGUIButton();
545
+ if(GUI_BUTTON_NONE != button)
546
+ {
547
+ //K0-KF���б༭������ʾ
548
+ if(button <= GUI_BUTTON_K0)
549
+ {
550
+ for(lineEdit = (EnumGUILineEdit)0; lineEdit < GUI_LINE_EDIT_MAX; lineEdit++)
551
+ {
552
+ if(1 == s_arrLineEdit[lineEdit].hasFocus)
553
+ {
554
+ AddrCharToLineEdit(&s_arrLineEdit[lineEdit], s_arrButtonValue[button]);
555
+ }
556
+ }
557
+ }
558
+
559
+ //ɾ����
560
+ else if(GUI_BUTTON_BACK == button)
561
+ {
562
+ for(lineEdit = (EnumGUILineEdit)0; lineEdit < GUI_LINE_EDIT_MAX; lineEdit++)
563
+ {
564
+ if(1 == s_arrLineEdit[lineEdit].hasFocus)
565
+ {
566
+ DeleteCodeFromLineEdit(&s_arrLineEdit[lineEdit]);
567
+ }
568
+ }
569
+ }
570
+
571
+ //���ͼ�
572
+ else if(GUI_BUTTON_SEND)
573
+ {
574
+ if((0 != s_arrLineEdit[GUI_LINE_EDIT_CLIENT_IP].text[0]) && (0 != s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA].text[0]))
575
+ {
576
+ ip = s_arrLineEdit[GUI_LINE_EDIT_CLIENT_IP].text;
577
+ data = s_arrLineEdit[GUI_LINE_EDIT_SEND_DATA].text;
578
+ SendDataToClient(ip, data);
579
+ }
580
+ }
581
+ }
582
+
583
+ //�б༭ģ��ɨ��
584
+ ScanGUILineEdit();
585
+
586
+ //LWIP��ѯ����
587
+ LWIPPeriodicHandle();
588
+
589
+ //LWIP�������ݰ���ѯ����
590
+ LWIPReadPackHandle();
591
+
592
+ //���տͻ������ݲ������ӡ���ն�
593
+ ReadClientData();
594
+ }
deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUIEthernet.h ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�GUIEthernet.h
3
+ * ժ Ҫ��GUI��̫��ͨ��ģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+ #ifndef _GUI_ETHERNET_H_
17
+ #define _GUI_ETHERNET_H_
18
+
19
+ /*********************************************************************************************************
20
+ * ����ͷ�ļ�
21
+ *********************************************************************************************************/
22
+ #include "DataType.h"
23
+
24
+ /*********************************************************************************************************
25
+ * �궨��
26
+ *********************************************************************************************************/
27
+
28
+ /*********************************************************************************************************
29
+ * ö�ٽṹ�嶨��
30
+ *********************************************************************************************************/
31
+
32
+ /*********************************************************************************************************
33
+ * API��������
34
+ *********************************************************************************************************/
35
+ void CreateGUIEthernet(void); //����GUI Ethernet����
36
+ void DeleteGUIEthernet(void); //ע��GUI Ethernet����
37
+ void GUIEthernetPoll(void); //GUI Ethernet��ѯ����
38
+
39
+ #endif
deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUIFileSys.c ADDED
@@ -0,0 +1,899 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�GUIFileSys.c
3
+ * ժ Ҫ���ļ�ϵͳ��ʾģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+
17
+ /*********************************************************************************************************
18
+ * ����ͷ�ļ�
19
+ *********************************************************************************************************/
20
+ #include "GUIFileSys.h"
21
+ #include "TLILCD.h"
22
+ #include "GUIPlatform.h"
23
+ #include "BMP.h"
24
+ #include "ff.h"
25
+ #include "stdio.h"
26
+ #include "Common.h"
27
+ #include "SysTick.h"
28
+ #include "Touch.h"
29
+ #include "JPEG.h"
30
+
31
+ /*********************************************************************************************************
32
+ * �궨��
33
+ *********************************************************************************************************/
34
+ #define FILE_INFO_X0 (32)
35
+ #define FILE_INFO_X1 (448)
36
+ #define FILE_INFO_WIDTH (FILE_INFO_X1 - FILE_INFO_X0 + 1)
37
+
38
+ #define DIR_SHOW_Y0 (52)
39
+ #define DIR_SHOW_HEIGHT (34)
40
+ #define DIR_FILL_COLOR ((242 << 16) | (242 << 8) | (242))
41
+ #define DIR_FONT (GUI_FONT_ASCII_24)
42
+
43
+ #define ICON_WIDTH (40) //ͼ�����
44
+ #define ICON_HEIGHT (40) //ͼ��߶�
45
+ #define ICON_TEXT_SPACE (5) //ͼƬ���ַ�����ʾ�ļ�϶
46
+ #define TEXT_TEXT_SPACE (1) //���������ַ���֮��ļ�϶
47
+ #define BUTTON_LINE_SPACE (2) //�ײ�������ͼƬ�ļ�϶
48
+ #define MAX_NAME_LEN _MAX_LFN //��ļ���
49
+ #define NAME_FONT (GUI_FONT_ASCII_24)
50
+ #define DATE_FONT (GUI_FONT_ASCII_12)
51
+ #define LINE_COLOR ((217 << 16) | (217 << 8) | (217)) //�׶�������ɫ��RGB888��
52
+ #define FILL_COLOR ((242 << 16) | (242 << 8) | (242)) //ѡ�������ɫ��RGB888��
53
+
54
+ #define ITEM_SHOW_SPACE (10)
55
+ #define ITEM_SHOW_Y0 (DIR_SHOW_Y0 + DIR_SHOW_HEIGHT + ITEM_SHOW_SPACE)
56
+ #define ITEM_HEIGHT (ICON_HEIGHT + BUTTON_LINE_SPACE)
57
+ #define MAX_ITEM_NUM ((LCD_PIXEL_WIDTH - ITEM_SHOW_Y0) / (ITEM_HEIGHT + ITEM_SHOW_SPACE))
58
+
59
+ //��������ض���
60
+ #define PROBAR_X0 (452)
61
+ #define PROBAR_Y0 (140)
62
+ #define PROBAR_WIDTH (15)
63
+ #define PROBAR_HEIGHT (620)
64
+ #define PROBAR_X1 (PROBAR_X0 + PROBAR_WIDTH - 1)
65
+ #define PROBAR_Y1 (PROBAR_Y0 + PROBAR_HEIGHT - 1)
66
+ //#define PROBAR_COLOR RGB888ToRGB565B((181 << 16) | (210 << 8) | (236 << 0))
67
+ #define PROBAR_COLOR RGB888ToRGB565B((46 << 16) | (117 << 8) | (182 << 0))
68
+
69
+ /*********************************************************************************************************
70
+ * ö�ٽṹ�嶨��
71
+ *********************************************************************************************************/
72
+ //�ļ���Ϣ�ṹ��
73
+ typedef struct
74
+ {
75
+ u32 x0; //��ʼ����
76
+ u32 y0; //��ʼ����
77
+ u32 width; //����
78
+ u32 height; //�߶�
79
+ u32 fileType; //�ļ����ͣ�0-��ͨ�ļ���1-·����2-�����ļ�
80
+ u32 dirType; //0-��Ŀ¼��1-��Ŀ¼
81
+ u32 hasfocus; //���޽��㣬0-�޽��㣬1-�н���
82
+ char fileName[MAX_NAME_LEN]; //�ļ���������·��
83
+ char fileData[MAX_NAME_LEN]; //�ļ���Ϣ
84
+ StructBmpImage image; //�ļ�ͼ��
85
+ }StructFileInfo;
86
+
87
+ /*********************************************************************************************************
88
+ * �ڲ�����
89
+ *********************************************************************************************************/
90
+ static char s_arrCurrentDir[MAX_NAME_LEN] = "0:";
91
+ static char s_arrFileLname[MAX_NAME_LEN];
92
+ static DIR s_dirFileDir; //��ǰ·��
93
+ static FILINFO s_infoFileInfo; //��ǰ�ļ���Ϣ
94
+
95
+ //��Ŀ�ؼ���ÿһ��һ����Ŀ��
96
+ static StructFileInfo s_arrItem[MAX_ITEM_NUM];
97
+
98
+ //��ǰ��Ŀ����
99
+ static u32 s_iItemNum = 0;
100
+
101
+ //��ʾģʽ��0-������ʾ��1-��ʾͼƬ��
102
+ static u32 s_iShowMode = 0;
103
+
104
+ //�ļ��������֣���·����
105
+ static char s_arrFileCompleteName[MAX_NAME_LEN];
106
+
107
+ //��ǰ��ʾ���ļ����
108
+ static u32 s_iDirFilePos = 0;
109
+
110
+ /*********************************************************************************************************
111
+ * �ڲ���������
112
+ *********************************************************************************************************/
113
+ static void ShowSingleFile(StructFileInfo* file); //��ʾ�����ļ���Ϣ
114
+ static void FileIconMatch(StructFileInfo* file); //ͼ��ƥ��
115
+ static void CopyFileInfo(StructFileInfo* file, FILINFO* info); //�����ļ���Ϣ
116
+ static u32 GetFileNum(void); //ͳ�Ƶ�ǰĿ¼���ļ���������·����
117
+ static void UpdateShow(void); //������ʾ
118
+ static u32 IsRoot(void); //У�鵱ǰĿ¼�Ƿ�Ϊ��Ŀ¼
119
+ static void GotoParentDir(void); //�л�����Ŀ¼
120
+ static void GotoSubDir(char* dir); //�л�����Ŀ¼
121
+ static char* CombiPathAndName(char* fileName); //����ǰ·�����ļ������
122
+ static void ScanAllItem(void); //ɨ�����е���ʾ��Ŀ
123
+ static void ScanProbar(void); //������ɨ��
124
+
125
+ /*********************************************************************************************************
126
+ * �ڲ�����ʵ��
127
+ *********************************************************************************************************/
128
+ /*********************************************************************************************************
129
+ * �������ƣ�ShowSingleFile
130
+ * �������ܣ���ʾ�����ļ���Ϣ
131
+ * ���������file���ļ���Ϣ�ṹ��
132
+ * ���������void
133
+ * �� �� ֵ��void
134
+ * �������ڣ�2021��07��01��
135
+ * ע �⣺
136
+ *********************************************************************************************************/
137
+ static void ShowSingleFile(StructFileInfo* file)
138
+ {
139
+ u32 x0, y0, x1, y1;
140
+
141
+ //ѡ��ʱ������ɫ�л�
142
+ if(1 == file->hasfocus)
143
+ {
144
+ x0 = file->x0;
145
+ y0 = file->y0;
146
+ x1 = file->x0 + file->width - 1;
147
+ y1 = file->y0 + file->height - 1;
148
+ GUIFillColor(x0, y0, x1, y1, RGB888ToRGB565B(FILL_COLOR));
149
+ }
150
+
151
+ //����ͼ��
152
+ if(NULL != file->image.addr)
153
+ {
154
+ DisplayBMP(&file->image, file->x0, file->y0);
155
+ }
156
+ else
157
+ {
158
+ x0 = file->x0;
159
+ y0 = file->y0;
160
+ x1 = file->x0 + ICON_WIDTH - 1;
161
+ y1 = file->y0 + ICON_HEIGHT - 1;
162
+ GUIFillColor(x0, y0, x1, y1, GUI_COLOR_BLUE);
163
+ }
164
+
165
+ //��ʾ�ļ���
166
+ x0 = file->x0 + ICON_WIDTH + ICON_TEXT_SPACE;
167
+ y0 = file->y0;
168
+ GUIDrawTextLine(x0, y0, (u32)file->fileName, NAME_FONT, NULL, GUI_COLOR_BLACK, 1,
169
+ ((FILE_INFO_WIDTH - ICON_WIDTH - ICON_TEXT_SPACE) / GetFontWidth(NAME_FONT)) - 1);
170
+
171
+ //��ʾ����
172
+ y0 = y0 + GetFontHeight(NAME_FONT) + TEXT_TEXT_SPACE;
173
+ GUIDrawTextLine(x0, y0, (u32)file->fileData, DATE_FONT, NULL, GUI_COLOR_BLACK, 1,
174
+ ((FILE_INFO_WIDTH - ICON_WIDTH - ICON_TEXT_SPACE) / GetFontWidth(DATE_FONT)) - 1);
175
+
176
+ //��ʾ�׶�����
177
+ x0 = file->x0;
178
+ y0 = file->y0 + ICON_HEIGHT + BUTTON_LINE_SPACE;
179
+ x1 = file->x0 + file->width - 1;
180
+ y1 = y0;
181
+ GUIDrawLine(x0, y0, x1, y1, 1, RGB888ToRGB565B(LINE_COLOR), GUI_LINE_CIRCLE);
182
+ }
183
+
184
+ /*********************************************************************************************************
185
+ * �������ƣ�FileIconMatch
186
+ * �������ܣ�ͼ��ƥ��
187
+ * ���������file���ļ���Ϣ�ṹ��
188
+ * ���������void
189
+ * �� �� ֵ��void
190
+ * �������ڣ�2021��07��01��
191
+ * ע �⣺
192
+ *********************************************************************************************************/
193
+ static void FileIconMatch(StructFileInfo* file)
194
+ {
195
+ //Ĭ�ϴ洢���ļ�ϵͳ�У�����ʹ��͸�����㷨
196
+ file->image.storageType = BMP_IN_FATFS;
197
+ file->image.alphaType = BMP_UES_ALPHA;
198
+
199
+ if(2 == file->fileType)
200
+ {
201
+ file->image.addr = FILESYS_DISK_ICON_DIR;
202
+ }
203
+ else if(1 == file->fileType)
204
+ {
205
+ file->image.addr = FILESYS_FOLDER_ICON_DIR;
206
+ }
207
+ else if(1 == FileSuffixCheck(file->fileName, "zip"))
208
+ {
209
+ file->image.addr = FILESYS_COMP_ICON_DIR;
210
+ }
211
+ else if(1 == FileSuffixCheck(file->fileName, "rar"))
212
+ {
213
+ file->image.addr = FILESYS_COMP_ICON_DIR;
214
+ }
215
+ else if(1 == FileSuffixCheck(file->fileName, "7z"))
216
+ {
217
+ file->image.addr = FILESYS_COMP_ICON_DIR;
218
+ }
219
+ else if(1 == FileSuffixCheck(file->fileName, "bmp"))
220
+ {
221
+ file->image.addr = FILESYS_IMAGE_ICON_DIR;
222
+ }
223
+ else if(1 == FileSuffixCheck(file->fileName, "jpg"))
224
+ {
225
+ file->image.addr = FILESYS_IMAGE_ICON_DIR;
226
+ }
227
+ else if(1 == FileSuffixCheck(file->fileName, "jpeg"))
228
+ {
229
+ file->image.addr = FILESYS_IMAGE_ICON_DIR;
230
+ }
231
+ else if(1 == FileSuffixCheck(file->fileName, "gif"))
232
+ {
233
+ file->image.addr = FILESYS_IMAGE_ICON_DIR;
234
+ }
235
+ else if(1 == FileSuffixCheck(file->fileName, "png"))
236
+ {
237
+ file->image.addr = FILESYS_IMAGE_ICON_DIR;
238
+ }
239
+ else if(1 == FileSuffixCheck(file->fileName, "mp3"))
240
+ {
241
+ file->image.addr = FILESYS_MUSIC_ICON_DIR;
242
+ }
243
+ else if(1 == FileSuffixCheck(file->fileName, "wav"))
244
+ {
245
+ file->image.addr = FILESYS_MUSIC_ICON_DIR;
246
+ }
247
+ else if(1 == FileSuffixCheck(file->fileName, "pdf"))
248
+ {
249
+ file->image.addr = FILESYS_PDF_ICON_DIR;
250
+ }
251
+ else if(1 == FileSuffixCheck(file->fileName, "txt"))
252
+ {
253
+ file->image.addr = FILESYS_TEXT_ICON_DIR;
254
+ }
255
+ else if(1 == FileSuffixCheck(file->fileName, "c"))
256
+ {
257
+ file->image.addr = FILESYS_TEXT_ICON_DIR;
258
+ }
259
+ else if(1 == FileSuffixCheck(file->fileName, "h"))
260
+ {
261
+ file->image.addr = FILESYS_TEXT_ICON_DIR;
262
+ }
263
+ else if(1 == FileSuffixCheck(file->fileName, "mp4"))
264
+ {
265
+ file->image.addr = FILESYS_VIDEO_ICON_DIR;
266
+ }
267
+ else
268
+ {
269
+ file->image.addr = FILESYS_FILE_ICON_DIR;
270
+ }
271
+ }
272
+
273
+ /*********************************************************************************************************
274
+ * �������ƣ�CopyFileInfo
275
+ * �������ܣ������ļ���Ϣ
276
+ * ���������void
277
+ * ���������void
278
+ * �� �� ֵ��void
279
+ * �������ڣ�2021��07��01��
280
+ * ע �⣺
281
+ *********************************************************************************************************/
282
+ static void CopyFileInfo(StructFileInfo* file, FILINFO* info)
283
+ {
284
+ u32 i, year, month, data, hour, minute, second;
285
+ char* name;
286
+
287
+ //�������
288
+ if(0 != info->lfname[0])
289
+ {
290
+ name = info->lfname;
291
+ }
292
+ else
293
+ {
294
+ name = info->fname;
295
+ }
296
+ i = 0;
297
+ while(0 != name[i])
298
+ {
299
+ file->fileName[i] = name[i];
300
+ i++;
301
+ }
302
+ file->fileName[i] = 0;
303
+
304
+ //���������
305
+ year = ((info->fdate & 0xFE00) >> 9 ) + 1980;
306
+ month = ((info->fdate & 0x01E0) >> 5 );
307
+ data = ((info->fdate & 0x001F) >> 0 );
308
+ hour = ((info->ftime & 0xF800) >> 11);
309
+ minute = ((info->ftime & 0x07E0) >> 5 );
310
+ second = ((info->ftime & 0x001F) >> 0 );
311
+
312
+ //Ŀ¼
313
+ if(info->fattrib & AM_DIR)
314
+ {
315
+ sprintf(file->fileData, "%02d/%02d/%02d %02d:%02d:%02d", year, month, data, hour, minute, second);
316
+ }
317
+
318
+ //�ļ�
319
+ else
320
+ {
321
+ //����1G
322
+ if(info->fsize > 1024 * 1024 * 1024)
323
+ {
324
+ sprintf(file->fileData, "%02d/%02d/%02d %02d:%02d:%02d %.1fGB",
325
+ year, month, data, hour, minute, second, info->fsize / (1024.0 * 1024.0 * 1024.0));
326
+ }
327
+
328
+ //����1M
329
+ else if(info->fsize > 1024 * 1024)
330
+ {
331
+ sprintf(file->fileData, "%02d/%02d/%02d %02d:%02d:%02d %.1fMB",
332
+ year, month, data, hour, minute, second, info->fsize / (1024.0 * 1024.0));
333
+ }
334
+
335
+ //����1K
336
+ else if(info->fsize > 1024)
337
+ {
338
+ sprintf(file->fileData, "%02d/%02d/%02d %02d:%02d:%02d %.1fKB",
339
+ year, month, data, hour, minute, second, info->fsize / (1024.0));
340
+ }
341
+
342
+ //��1K
343
+ else
344
+ {
345
+ sprintf(file->fileData, "%02d/%02d/%02d %02d:%02d:%02d %dB",
346
+ year, month, data, hour, minute, second, info->fsize);
347
+ }
348
+ }
349
+ }
350
+
351
+ /*********************************************************************************************************
352
+ * �������ƣ�GetFileNum
353
+ * �������ܣ�ͳ�Ƶ�ǰĿ¼���ļ���������·����
354
+ * ���������void
355
+ * ���������void
356
+ * �� �� ֵ���ļ�����
357
+ * �������ڣ�2021��07��01��
358
+ * ע �⣺
359
+ *********************************************************************************************************/
360
+ static u32 GetFileNum(void)
361
+ {
362
+ FRESULT result; //�ļ��������ر���
363
+ u32 fileNum; //��ǰĿ¼���ļ���������·����
364
+
365
+ //ͳ��
366
+ fileNum = 0;
367
+ f_opendir(&s_dirFileDir, s_arrCurrentDir);
368
+ while(1)
369
+ {
370
+ result = f_readdir(&s_dirFileDir, &s_infoFileInfo);
371
+ if((result != FR_OK) || (0 == s_infoFileInfo.fname[0]))
372
+ {
373
+ f_closedir(&s_dirFileDir);
374
+ break;
375
+ }
376
+ else
377
+ {
378
+ fileNum++;
379
+ }
380
+ }
381
+
382
+ return fileNum;
383
+ }
384
+
385
+ /*********************************************************************************************************
386
+ * �������ƣ�UpdateShow
387
+ * �������ܣ�������ʾ
388
+ * ���������void
389
+ * ���������void
390
+ * �� �� ֵ��void
391
+ * �������ڣ�2021��07��01��
392
+ * ע �⣺
393
+ *********************************************************************************************************/
394
+ static void UpdateShow(void)
395
+ {
396
+ FRESULT result; //�ļ��������ر���
397
+ u32 itemCnt; //��ʾ����
398
+ u32 x0, y0, x1, y1; //�������
399
+ u32 fileNum; //��ǰĿ¼���ļ���������·����
400
+ u32 probarLen; //����������
401
+ u32 fileCnt; //�����
402
+
403
+ //��ʾ����ͼƬ������ͼƬռ��������Ļ��
404
+ DisPlayBMPByIPA(0, 0, FILESYS_BACKGROUND_DIR);
405
+
406
+ //ͳ�Ƶ�ǰĿ¼���ļ�����
407
+ fileNum = GetFileNum();
408
+
409
+ //ȷ�����������鳤��
410
+ if(1 != IsRoot()){fileNum = fileNum + 1;}
411
+ if(fileNum <= MAX_ITEM_NUM)
412
+ {
413
+ probarLen = PROBAR_HEIGHT;
414
+ }
415
+ else
416
+ {
417
+ probarLen = PROBAR_HEIGHT * MAX_ITEM_NUM / fileNum;
418
+ }
419
+
420
+ //ȷ����������������λ��
421
+ if(1 == IsRoot()){fileNum = fileNum - 1;}
422
+ x0 = PROBAR_X0;
423
+ x1 = PROBAR_X1;
424
+ y0 = PROBAR_Y0 + PROBAR_HEIGHT * s_iDirFilePos / fileNum;
425
+ y1 = y0 + probarLen - 1;
426
+ if(y1 > PROBAR_Y1)
427
+ {
428
+ y1 = PROBAR_Y1;
429
+ }
430
+
431
+ //���ƽ���������
432
+ GUIFillColor(x0, y0, x1, y1, PROBAR_COLOR);
433
+
434
+ //���ӳ��ļ���������
435
+ s_infoFileInfo.lfname = s_arrFileLname;
436
+ s_infoFileInfo.lfsize = MAX_NAME_LEN;
437
+
438
+ //��ʾ��ǰĿ¼
439
+ x0 = FILE_INFO_X0;
440
+ y0 = DIR_SHOW_Y0 + (DIR_SHOW_HEIGHT - GetFontHeight(DIR_FONT)) / 2;
441
+ GUIDrawTextLine(x0, y0, (u32)s_arrCurrentDir, DIR_FONT, NULL, GUI_COLOR_BLACK, 1, FILE_INFO_WIDTH / GetFontWidth(DIR_FONT));
442
+
443
+ //�򿪵�ǰĿ¼
444
+ f_opendir(&s_dirFileDir, s_arrCurrentDir);
445
+
446
+ //��ʾ��һ��Ŀ¼����Ŀ¼�²���ʾ��
447
+ if(1 != IsRoot())
448
+ {
449
+ s_arrItem[0].x0 = FILE_INFO_X0;
450
+ s_arrItem[0].y0 = ITEM_SHOW_Y0;
451
+ s_arrItem[0].width = FILE_INFO_WIDTH;
452
+ s_arrItem[0].height = ICON_HEIGHT + BUTTON_LINE_SPACE;
453
+ s_arrItem[0].fileType = 1;
454
+ s_arrItem[0].dirType = 1;
455
+ s_arrItem[0].hasfocus = 0;
456
+ sprintf(s_arrItem[0].fileName, "..");
457
+ sprintf(s_arrItem[0].fileData, "");
458
+ FileIconMatch(&s_arrItem[0]);
459
+ ShowSingleFile(&s_arrItem[0]);
460
+ itemCnt = 1;
461
+ }
462
+ else
463
+ {
464
+ itemCnt = 0;
465
+ }
466
+
467
+ //��ѯĿ¼�������ļ�������ʾ
468
+ fileCnt = 0;
469
+ while(1)
470
+ {
471
+ //��ȡ�����ļ���Ϣ
472
+ result = f_readdir(&s_dirFileDir, &s_infoFileInfo);
473
+ if((result != FR_OK) || (0 == s_infoFileInfo.fname[0]))
474
+ {
475
+ f_closedir(&s_dirFileDir);
476
+ break;
477
+ }
478
+
479
+ //δ����ʾλ�ã�ֱ��������һ��ѭ��
480
+ if(fileCnt < s_iDirFilePos)
481
+ {
482
+ fileCnt++;
483
+ continue;
484
+ }
485
+
486
+ //������
487
+ if(itemCnt >= MAX_ITEM_NUM)
488
+ {
489
+ f_closedir(&s_dirFileDir);
490
+ break;
491
+ }
492
+
493
+ //���û�������
494
+ s_arrItem[itemCnt].x0 = FILE_INFO_X0;
495
+ s_arrItem[itemCnt].width = FILE_INFO_WIDTH;
496
+ s_arrItem[itemCnt].height = ICON_HEIGHT + BUTTON_LINE_SPACE;
497
+ s_arrItem[itemCnt].hasfocus = 0;
498
+ if(0 == itemCnt)
499
+ {
500
+ s_arrItem[itemCnt].y0 = ITEM_SHOW_Y0;
501
+ }
502
+ else
503
+ {
504
+ s_arrItem[itemCnt].y0 = s_arrItem[itemCnt - 1].y0 + s_arrItem[itemCnt].height + ITEM_SHOW_SPACE;
505
+ }
506
+
507
+ //�����ļ���Ϣ
508
+ CopyFileInfo(&s_arrItem[itemCnt], &s_infoFileInfo);
509
+
510
+ //ƥ��Ŀ¼ͼ��
511
+ if(s_infoFileInfo.fattrib & AM_DIR)
512
+ {
513
+ s_arrItem[itemCnt].fileType = 1;
514
+ s_arrItem[itemCnt].dirType = 0;
515
+ }
516
+
517
+ //ƥ���ļ�ͼ��
518
+ else
519
+ {
520
+ s_arrItem[itemCnt].fileType = 0;
521
+ }
522
+ FileIconMatch(&s_arrItem[itemCnt]);
523
+
524
+ //�����ļ���ʾ
525
+ ShowSingleFile(&s_arrItem[itemCnt]);
526
+
527
+ //������Ŀ����
528
+ itemCnt++;
529
+ }
530
+
531
+ //��¼��Ŀ����
532
+ s_iItemNum = itemCnt;
533
+ }
534
+
535
+ /*********************************************************************************************************
536
+ * �������ƣ�IsRoot
537
+ * �������ܣ�У�鵱ǰĿ¼�Ƿ�Ϊ��Ŀ¼
538
+ * ���������void
539
+ * ���������void
540
+ * �� �� ֵ��0-��1-��
541
+ * �������ڣ�2021��07��01��
542
+ * ע �⣺
543
+ *********************************************************************************************************/
544
+ static u32 IsRoot(void)
545
+ {
546
+ u32 i, cnt;
547
+
548
+ //����'/'������
549
+ i = 0;
550
+ cnt = 0;
551
+ while(0 != s_arrCurrentDir[i])
552
+ {
553
+ if('/' == s_arrCurrentDir[i])
554
+ {
555
+ cnt++;
556
+ }
557
+ i++;
558
+ }
559
+
560
+ //��ǰĿ¼Ϊ��Ŀ¼
561
+ if(0 == cnt)
562
+ {
563
+ return 1;
564
+ }
565
+ else
566
+ {
567
+ return 0;
568
+ }
569
+ }
570
+
571
+ /*********************************************************************************************************
572
+ * �������ƣ�GotoParentDir
573
+ * �������ܣ��л�����Ŀ¼
574
+ * ���������void
575
+ * ���������void
576
+ * �� �� ֵ��void
577
+ * �������ڣ�2021��07��01��
578
+ * ע �⣺
579
+ *********************************************************************************************************/
580
+ static void GotoParentDir(void)
581
+ {
582
+ u32 i, pos, cnt;
583
+
584
+ //�������һ��'/'����λ��
585
+ i = 0;
586
+ pos = 0xFFFFFFFF;
587
+ cnt = 0;
588
+ while(0 != s_arrCurrentDir[i])
589
+ {
590
+ if('/' == s_arrCurrentDir[i])
591
+ {
592
+ pos = i;
593
+ cnt++;
594
+ }
595
+ i++;
596
+ }
597
+
598
+ //��ǰĿ¼Ϊ��Ŀ¼
599
+ if(0 == cnt)
600
+ {
601
+ return;
602
+ }
603
+
604
+ //�쳣
605
+ if(0xFFFFFFFF == pos)
606
+ {
607
+ printf("�л�����һ��Ŀ¼ʧ��\r\n");
608
+ while(1);
609
+ }
610
+
611
+ //ɾ����Ŀ¼��Ϣ
612
+ s_arrCurrentDir[pos] = 0;
613
+
614
+ //�ӵ�һ���ļ���ʼ��ʾ
615
+ s_iDirFilePos = 0;
616
+
617
+ //������ʾ
618
+ UpdateShow();
619
+ }
620
+
621
+ /*********************************************************************************************************
622
+ * �������ƣ�GotoSubDir
623
+ * �������ܣ��л�����Ŀ¼
624
+ * ���������void
625
+ * ���������void
626
+ * �� �� ֵ��void
627
+ * �������ڣ�2021��07��01��
628
+ * ע �⣺
629
+ *********************************************************************************************************/
630
+ static void GotoSubDir(char* dir)
631
+ {
632
+ u32 i;
633
+ char* currentDir;
634
+
635
+ //�����ַ�����β����λ��
636
+ i = 0;
637
+ while(0 != s_arrCurrentDir[i])
638
+ {
639
+ i++;
640
+ }
641
+ currentDir = s_arrCurrentDir + i;
642
+
643
+ //�������'/'
644
+ currentDir[0] = '/';
645
+ currentDir++;
646
+
647
+ //������Ŀ¼��Ϣ
648
+ i = 0;
649
+ while(0 != dir[i])
650
+ {
651
+ currentDir[i] = dir[i];
652
+ i++;
653
+ }
654
+ currentDir[i] = 0;
655
+
656
+ //�ӵ�һ���ļ���ʼ��ʾ
657
+ s_iDirFilePos = 0;
658
+
659
+ //������ʾ
660
+ UpdateShow();
661
+ }
662
+
663
+ /*********************************************************************************************************
664
+ * �������ƣ�CombiPathAndName
665
+ * �������ܣ�����ǰ·�����ļ������
666
+ * ���������void
667
+ * ���������void
668
+ * �� �� ֵ��ת�����
669
+ * �������ڣ�2021��07��01��
670
+ * ע �⣺
671
+ *********************************************************************************************************/
672
+ static char* CombiPathAndName(char* fileName)
673
+ {
674
+ u32 i;
675
+ char* path;
676
+
677
+ //����·��
678
+ i = 0;
679
+ while(0 != s_arrCurrentDir[i])
680
+ {
681
+ s_arrFileCompleteName[i] = s_arrCurrentDir[i];
682
+ i++;
683
+ }
684
+ path = s_arrFileCompleteName + i;
685
+
686
+ //�������'/'
687
+ path[0] = '/';
688
+ path++;
689
+
690
+ //�������
691
+ i = 0;
692
+ while(0 != fileName[i])
693
+ {
694
+ path[i] = fileName[i];
695
+ i++;
696
+ }
697
+ path[i] = 0;
698
+
699
+ return s_arrFileCompleteName;
700
+ }
701
+
702
+ /*********************************************************************************************************
703
+ * �������ƣ�ScanAllItem
704
+ * �������ܣ�ɨ�����е���ʾ��Ŀ
705
+ * ���������void
706
+ * ���������void
707
+ * �� �� ֵ��void
708
+ * �������ڣ�2021��07��01��
709
+ * ע �⣺
710
+ *********************************************************************************************************/
711
+ static void ScanAllItem(void)
712
+ {
713
+ u32 i, x, y, x0, y0, x1, y1, width, height;
714
+ StructBmpImage bmpImage;
715
+ StructJpegImage jpegImage;
716
+
717
+ //��ȡ��������
718
+ if(1 == GUIGetTouch(&x, &y, 0))
719
+ {
720
+ //������ʾ�ļ�
721
+ if(0 == s_iShowMode)
722
+ {
723
+ for(i = 0; i < s_iItemNum; i++)
724
+ {
725
+ x0 = s_arrItem[i].x0;
726
+ y0 = s_arrItem[i].y0;
727
+ x1 = s_arrItem[i].x0 + s_arrItem[i].width * 3 / 4 - 1;
728
+ y1 = s_arrItem[i].y0 + s_arrItem[i].height - 1;
729
+ if((x >= x0) && (x <= x1) && (y >= y0) && (y <= y1))
730
+ {
731
+ //���ظ�Ŀ¼
732
+ if((1 == s_arrItem[i].fileType) && (1 == s_arrItem[i].dirType))
733
+ {
734
+ GotoParentDir();
735
+ }
736
+
737
+ //�л�����Ŀ¼
738
+ else if(1 == s_arrItem[i].fileType)
739
+ {
740
+ GotoSubDir(s_arrItem[i].fileName);
741
+ }
742
+
743
+ //λͼ��ʾ
744
+ else if(1 == FileSuffixCheck(s_arrItem[i].fileName, "bmp"))
745
+ {
746
+ bmpImage.addr = CombiPathAndName(s_arrItem[i].fileName);
747
+ bmpImage.alphaType = BMP_UES_ALPHA;
748
+ bmpImage.storageType = BMP_IN_FATFS;
749
+
750
+ //��ȡͼ���С
751
+ GetBMPSize(&bmpImage, &width, &height);
752
+
753
+ //����ͼƬ��ʾλ��
754
+ if((width <= LCD_PIXEL_HEIGHT) && (height <= LCD_PIXEL_WIDTH))
755
+ {
756
+ x0 = (LCD_PIXEL_HEIGHT - width) / 2;
757
+ y0 = (LCD_PIXEL_WIDTH - height) / 2;
758
+ }
759
+ else
760
+ {
761
+ return;
762
+ }
763
+
764
+ //��ʾͼƬ
765
+ LCDClear(LCD_COLOR_WHITE);
766
+ DisplayBMP(&bmpImage, x0, y0);
767
+
768
+ //���������ʾͼƬ
769
+ s_iShowMode = 1;
770
+ }
771
+
772
+ //JPEGͼƬ��ʾ
773
+ else if((1 == FileSuffixCheck(s_arrItem[i].fileName, "jpg")) || (1 == FileSuffixCheck(s_arrItem[i].fileName, "jpeg")))
774
+ {
775
+
776
+ //��ȡ�����ļ�������·����
777
+ jpegImage.image = (u8*)CombiPathAndName(s_arrItem[i].fileName);
778
+
779
+ //��ʾJPEGͼƬ
780
+ LCDClear(LCD_COLOR_WHITE);
781
+ DisplayJPEGInCentral(&jpegImage);
782
+
783
+ //���������ʾͼƬ
784
+ s_iShowMode = 1;
785
+ }
786
+
787
+ //�ȴ��û���ָ�뿪��Ļ
788
+ WaitForTouchRelease();
789
+ }
790
+ }
791
+ }
792
+
793
+ //��ʾͼƬ��
794
+ else
795
+ {
796
+ //�ȴ��û���ָ�뿪��Ļ
797
+ WaitForTouchRelease();
798
+
799
+ //�л�������ʾ
800
+ s_iShowMode = 0;
801
+ UpdateShow();
802
+ }
803
+ }
804
+ }
805
+
806
+ /*********************************************************************************************************
807
+ * �������ƣ�ScanProbar
808
+ * �������ܣ�������ɨ��
809
+ * ���������void
810
+ * ���������void
811
+ * �� �� ֵ��void
812
+ * �������ڣ�2021��07��01��
813
+ * ע �⣺
814
+ *********************************************************************************************************/
815
+ static void ScanProbar(void)
816
+ {
817
+ u32 x, y, x0, y0, x1, y1;
818
+ u32 fileNum;
819
+
820
+ //��ȡ��������
821
+ fileNum = 0xFFFFFFFF;
822
+ while(1 == GUIGetTouch(&x, &y, 0))
823
+ {
824
+ x0 = PROBAR_X0 - PROBAR_WIDTH * 2;
825
+ y0 = PROBAR_Y0;
826
+ x1 = PROBAR_X1;
827
+ y1 = PROBAR_Y1;
828
+ if((x >= x0) && (x <= x1) && (y >= y0) && (y <= y1))
829
+ {
830
+ //��ȡ��ǰ·�����ļ�����
831
+ if(0xFFFFFFFF == fileNum)
832
+ {
833
+ fileNum = GetFileNum();
834
+ }
835
+
836
+ //�����ļ���ʾλ��
837
+ s_iDirFilePos = fileNum * (y - y0) / PROBAR_HEIGHT;
838
+
839
+ //������ʾ
840
+ UpdateShow();
841
+
842
+ break;
843
+ }
844
+ else
845
+ {
846
+ break;
847
+ }
848
+ }
849
+ }
850
+
851
+ /*********************************************************************************************************
852
+ * API����ʵ��
853
+ *********************************************************************************************************/
854
+ /*********************************************************************************************************
855
+ * �������ƣ�CreateGUIFileSys
856
+ * �������ܣ������ļ�ϵͳ��ʾ����
857
+ * ���������void
858
+ * ���������void
859
+ * �� �� ֵ��void
860
+ * �������ڣ�2021��07��01��
861
+ * ע �⣺
862
+ *********************************************************************************************************/
863
+ void CreateGUIFileSys(void)
864
+ {
865
+ //������ʾ
866
+ LCDDisplayDir(LCD_SCREEN_VERTICAL);
867
+
868
+ //������ʾ
869
+ UpdateShow();
870
+ }
871
+
872
+ /*********************************************************************************************************
873
+ * �������ƣ�DeleteGUIFileSys
874
+ * �������ܣ�ɾ���ļ�ϵͳ��ʾ����
875
+ * ���������void
876
+ * ���������void
877
+ * �� �� ֵ��void
878
+ * �������ڣ�2021��07��01��
879
+ * ע �⣺
880
+ *********************************************************************************************************/
881
+ void DeleteGUIFileSys(void)
882
+ {
883
+
884
+ }
885
+
886
+ /*********************************************************************************************************
887
+ * �������ƣ�GUIFileSysPoll
888
+ * �������ܣ��ļ�ϵͳ��ѯ����
889
+ * ���������void
890
+ * ���������void
891
+ * �� �� ֵ��void
892
+ * �������ڣ�2021��07��01��
893
+ * ע �⣺
894
+ *********************************************************************************************************/
895
+ void GUIFileSysPoll(void)
896
+ {
897
+ ScanAllItem();
898
+ ScanProbar();
899
+ }
deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUIFileSys.h ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�GUIFileSys.h
3
+ * ժ Ҫ���ļ�ϵͳ��ʾģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+ #ifndef _GUI_FILE_SYS_H_
17
+ #define _GUI_FILE_SYS_H_
18
+
19
+ /*********************************************************************************************************
20
+ * ����ͷ�ļ�
21
+ *********************************************************************************************************/
22
+ #include "DataType.h"
23
+
24
+ /*********************************************************************************************************
25
+ * �궨��
26
+ *********************************************************************************************************/
27
+
28
+ /*********************************************************************************************************
29
+ * ö�ٽṹ�嶨��
30
+ *********************************************************************************************************/
31
+
32
+ /*********************************************************************************************************
33
+ * API��������
34
+ *********************************************************************************************************/
35
+ void CreateGUIFileSys(void); //�����ļ�ϵͳ��ʾ����
36
+ void DeleteGUIFileSys(void); //ɾ���ļ�ϵͳ��ʾ����
37
+ void GUIFileSysPoll(void); //�ļ�ϵͳ��ѯ����
38
+
39
+ #endif
deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUIHome.c ADDED
@@ -0,0 +1,335 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�GUIHome.c
3
+ * ժ Ҫ��������
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+
17
+ /*********************************************************************************************************
18
+ * ����ͷ�ļ�
19
+ *********************************************************************************************************/
20
+ #include "GUIHome.h"
21
+ #include "TLILCD.h"
22
+ #include "GUIPlatform.h"
23
+ #include "BMP.h"
24
+ #include "Common.h"
25
+ #include "GUITop.h"
26
+ #include "stdio.h"
27
+
28
+ /*********************************************************************************************************
29
+ * �궨��
30
+ *********************************************************************************************************/
31
+ #define ICON_IMAGE_WIDTH (80) //ͼ�����
32
+ #define ICON_IMAGE_HEIGHT (80) //ͼ��߶�
33
+ #define ICON_TEXT_FONT (GUI_FONT_ASCII_24) //ͼ������
34
+ #define ICON_TEXT_SPACE (2) //�ַ�����ͼƬ�ļ�϶
35
+ #define ICON_APP_SPAGE ((480 - ICON_IMAGE_WIDTH * 4) / 5)
36
+
37
+ /*********************************************************************************************************
38
+ * ö�ٽṹ�嶨��
39
+ *********************************************************************************************************/
40
+ //������ͼ��
41
+ typedef struct
42
+ {
43
+ EnumGUIList app; //����App
44
+ u32 x0; //�������
45
+ u32 y0; //�������
46
+ u32 width; //����
47
+ u32 height; //�߶�
48
+ StructBmpImage* image; //ͼ��ͼƬ��ʹ��λͼ�ļ���û�ж���ʱĬ��ʹ����ɫ���
49
+ const char* text; //App���⣬��Ĭ��ʹ��24x24����
50
+ }StructAppIcon;
51
+
52
+ /*********************************************************************************************************
53
+ * �ڲ�����
54
+ *********************************************************************************************************/
55
+ static StructAppIcon s_arrAppIcon[GUI_LIST_MAX - 1]; //APPͼ�꼯��
56
+ static StructBmpImage s_arrAppImage[GUI_LIST_MAX - 1]; //ͼ��λͼ
57
+
58
+ //App����
59
+ static const char* s_arrAppTitle[GUI_LIST_MAX - 1] =
60
+ {
61
+ "ʱ��",
62
+ "RS232",
63
+ "RS485",
64
+ "CAN",
65
+ "����",
66
+ "�ļ�",
67
+ "��̫��",
68
+ "����",
69
+ "¼����",
70
+ "�����",
71
+ "��",
72
+ "����",
73
+ "Wave",
74
+ "��ʪ��",
75
+ "������",
76
+ "OLED",
77
+ };
78
+
79
+ //Appͼ��
80
+ static const char* s_arrImageAddr[GUI_LIST_MAX - 1] =
81
+ {
82
+ CLOCK_ICON_DIR,
83
+ RS232_ICON_DIR,
84
+ RS485_ICON_DIR,
85
+ CAN_ICON_DIR,
86
+ KEYBOARD_ICON_DIR,
87
+ FILESYS_ICON_DIR,
88
+ ETHERNET_ICON_DIR,
89
+ MUSIC_ICON_DIR,
90
+ RECORDER_ICON_DIR,
91
+ CAMERA_ICON_DIR,
92
+ READER_ICON_DIR,
93
+ CANVAS_ICON_DIR,
94
+ WAVE_ICON_DIR,
95
+ TEMP_ICON_DIR,
96
+ BREATH_LED_ICON_DIR,
97
+ OLED_ICON_DIR,
98
+ };
99
+
100
+ /*********************************************************************************************************
101
+ * �ڲ���������
102
+ *********************************************************************************************************/
103
+ static void DisplayBackground(void); //���Ʊ���
104
+ static void CreateAppIcon(StructAppIcon* app); //����Appͼ��
105
+ static void InitAllAppStruct(void); //��ʼ������Appͼ��
106
+ static StructAppIcon* ScanAppIcon(void); //ɨ��Appͼ��
107
+
108
+ /*********************************************************************************************************
109
+ * �ڲ�����ʵ��
110
+ *********************************************************************************************************/
111
+ /*********************************************************************************************************
112
+ * �������ƣ�DisplayBackground
113
+ * �������ܣ����Ʊ���
114
+ * ���������void
115
+ * ���������void
116
+ * �� �� ֵ��void
117
+ * �������ڣ�2021��07��01��
118
+ * ע �⣺����֮ǰҪȷ��LCD����Ϊ����
119
+ *********************************************************************************************************/
120
+ static void DisplayBackground(void)
121
+ {
122
+ DisPlayBMPByIPA(0, 0, MAIN_WINDOWN_BACKGROUND_DIR);
123
+ }
124
+
125
+ /*********************************************************************************************************
126
+ * �������ƣ�CreateAppIcon
127
+ * �������ܣ�����Appͼ��
128
+ * ���������app��Appͼ��ṹ���ַ
129
+ * ���������void
130
+ * �� �� ֵ��void
131
+ * �������ڣ�2021��07��01��
132
+ * ע �⣺
133
+ *********************************************************************************************************/
134
+ static void CreateAppIcon(StructAppIcon* app)
135
+ {
136
+ u32 stringNum; //�ַ����ַ���
137
+ u32 stringLen; //�ַ������ȣ����ص㣩
138
+ u32 beginX, beginY; //�ַ����������
139
+ u32 x0, y0, x1, y1;
140
+
141
+ //��ʾͼƬ
142
+ x0 = app->x0;
143
+ y0 = app->y0;
144
+ x1 = app->x0 + ICON_IMAGE_WIDTH - 1;
145
+ y1 = app->y0 + ICON_IMAGE_HEIGHT - 1;
146
+ if(NULL != app->image)
147
+ {
148
+ if(NULL != app->image->addr)
149
+ {
150
+ GUIDrawImage(app->x0, app->y0, (u32)app->image, GUI_IMAGE_TYPE_BMP);
151
+ }
152
+ else
153
+ {
154
+ GUIFillColor(x0, y0, x1, y1, GUI_COLOR_BLUE);
155
+ }
156
+ }
157
+ else
158
+ {
159
+ GUIFillColor(x0, y0, x1, y1, GUI_COLOR_BLUE);
160
+ }
161
+
162
+ //ͳ���ַ����ܳ���
163
+ stringNum = 0;
164
+ while(0 != app->text[stringNum])
165
+ {
166
+ stringNum++;
167
+ }
168
+
169
+ //У���ַ������ȣ�App���ⲻ�ܳ���ͼƬ����
170
+ if(stringNum > (app->width / GetFontWidth(ICON_TEXT_FONT)))
171
+ {
172
+ stringNum = app->width / GetFontWidth(ICON_TEXT_FONT);
173
+ }
174
+
175
+ //�����ַ������ȣ����ص㣩
176
+ stringLen = stringNum * GetFontWidth(ICON_TEXT_FONT);
177
+
178
+ //������ʼ������
179
+ beginY = app->y0 + ICON_IMAGE_HEIGHT + ICON_TEXT_SPACE;
180
+
181
+ //������ʼ������
182
+ beginX = app->x0 + (app->width - stringLen) / 2;
183
+
184
+ //��ʾApp����
185
+ GUIDrawTextLine(beginX, beginY, (u32)app->text, ICON_TEXT_FONT, NULL, GUI_COLOR_WHITE, 1, stringNum);
186
+ }
187
+
188
+ /*********************************************************************************************************
189
+ * �������ƣ�InitAllAppStruct
190
+ * �������ܣ���ʼ������Appͼ��
191
+ * ���������void
192
+ * ���������void
193
+ * �� �� ֵ��void
194
+ * �������ڣ�2021��07��01��
195
+ * ע �⣺
196
+ *********************************************************************************************************/
197
+ static void InitAllAppStruct(void)
198
+ {
199
+ u32 i, x, y;
200
+
201
+ //��ʼ��Appλͼ����
202
+ for(i = 0; i < GUI_LIST_MAX - 1; i++)
203
+ {
204
+ s_arrAppImage[i].storageType = BMP_IN_FATFS;
205
+ s_arrAppImage[i].alphaType = BMP_UES_ALPHA;
206
+ s_arrAppImage[i].addr = (void*)s_arrImageAddr[i];
207
+ }
208
+
209
+ //��ʼ��Appͼ��
210
+ x = ICON_APP_SPAGE;
211
+ y = ICON_APP_SPAGE;
212
+ for(i = 0; i < GUI_LIST_MAX - 1; i++)
213
+ {
214
+ //����y��
215
+ if((0 == (i % 4)) && (0 != i))
216
+ {
217
+ y = y + s_arrAppIcon[0].height + ICON_APP_SPAGE;
218
+ x = ICON_APP_SPAGE;
219
+ }
220
+
221
+ s_arrAppIcon[i].app = (EnumGUIList)(i + 1);
222
+ s_arrAppIcon[i].x0 = x;
223
+ s_arrAppIcon[i].y0 = y;
224
+ s_arrAppIcon[i].width = ICON_IMAGE_WIDTH;
225
+ s_arrAppIcon[i].height = ICON_IMAGE_HEIGHT + ICON_TEXT_SPACE + GetFontHeight(ICON_TEXT_FONT);
226
+ s_arrAppIcon[i].image = &s_arrAppImage[i];
227
+ s_arrAppIcon[i].text = s_arrAppTitle[i];
228
+
229
+ //���º�����
230
+ x = x + ICON_IMAGE_WIDTH + ICON_APP_SPAGE;
231
+ }
232
+ }
233
+
234
+ /*********************************************************************************************************
235
+ * �������ƣ�ScanAppIcon
236
+ * �������ܣ�ɨ��Appͼ��
237
+ * ���������void
238
+ * ���������void
239
+ * �� �� ֵ�����µ�ͼ��
240
+ * �������ڣ�2021��07��01��
241
+ * ע �⣺
242
+ *********************************************************************************************************/
243
+ static StructAppIcon* ScanAppIcon(void)
244
+ {
245
+ u32 i, x, y, x0, y0, x1, y1;
246
+
247
+ //��ȡ��������
248
+ if(1 == GUIGetTouch(&x, &y, 0))
249
+ {
250
+ for(i = 0; i < GUI_LIST_MAX - 1; i++)
251
+ {
252
+ x0 = s_arrAppIcon[i].x0;
253
+ y0 = s_arrAppIcon[i].y0;
254
+ x1 = s_arrAppIcon[i].x0 + s_arrAppIcon[i].width - 1;
255
+ y1 = s_arrAppIcon[i].y0 + s_arrAppIcon[i].height - 1;
256
+ if((x >= x0) && (x <= x1) && (y >= y0) && (y <= y1))
257
+ {
258
+ return &s_arrAppIcon[i];
259
+ }
260
+ }
261
+ return NULL;
262
+ }
263
+
264
+ //�޴��㰴�£�ֱ�ӷ���
265
+ else
266
+ {
267
+ return NULL;
268
+ }
269
+ }
270
+
271
+ /*********************************************************************************************************
272
+ * API����ʵ��
273
+ *********************************************************************************************************/
274
+ /*********************************************************************************************************
275
+ * �������ƣ�CreateGUIHome
276
+ * �������ܣ�����Home����
277
+ * ���������void
278
+ * ���������void
279
+ * �� �� ֵ��void
280
+ * �������ڣ�2021��07��01��
281
+ * ע �⣺
282
+ *********************************************************************************************************/
283
+ void CreateGUIHome(void)
284
+ {
285
+ u32 i;
286
+
287
+ //LCD������ʾ
288
+ LCDDisplayDir(LCD_SCREEN_VERTICAL);
289
+
290
+ //���Ʊ���
291
+ DisplayBackground();
292
+
293
+ //��ʼ��ͼ�����
294
+ InitAllAppStruct();
295
+
296
+ //��������ͼ��
297
+ for(i = 0; i < GUI_LIST_MAX - 1; i++)
298
+ {
299
+ CreateAppIcon(&s_arrAppIcon[i]);
300
+ }
301
+ }
302
+
303
+ /*********************************************************************************************************
304
+ * �������ƣ�DeleteGUIHome
305
+ * �������ܣ�ɾ��������
306
+ * ���������void
307
+ * ���������void
308
+ * �� �� ֵ��void
309
+ * �������ڣ�2021��07��01��
310
+ * ע �⣺
311
+ *********************************************************************************************************/
312
+ void DeleteGUIHome(void)
313
+ {
314
+
315
+ }
316
+
317
+ /*********************************************************************************************************
318
+ * �������ƣ�GUIHomePoll
319
+ * �������ܣ���������ѯ
320
+ * ���������void
321
+ * ���������void
322
+ * �� �� ֵ��void
323
+ * �������ڣ�2021��07��01��
324
+ * ע �⣺
325
+ *********************************************************************************************************/
326
+ void GUIHomePoll(void)
327
+ {
328
+ StructAppIcon* icon;
329
+ icon = ScanAppIcon();
330
+ if(NULL != icon)
331
+ {
332
+ printf("�����%s����\r\n", icon->text);
333
+ GUISwitch(icon->app);
334
+ }
335
+ }
deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUIHome.h ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�GUIHome.h
3
+ * ժ Ҫ��������
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+ #ifndef _GUI_HOME_H_
17
+ #define _GUI_HOME_H_
18
+
19
+ /*********************************************************************************************************
20
+ * ����ͷ�ļ�
21
+ *********************************************************************************************************/
22
+ #include "DataType.h"
23
+
24
+ /*********************************************************************************************************
25
+ * �궨��
26
+ *********************************************************************************************************/
27
+
28
+ /*********************************************************************************************************
29
+ * ö�ٽṹ�嶨��
30
+ *********************************************************************************************************/
31
+
32
+ /*********************************************************************************************************
33
+ * API��������
34
+ *********************************************************************************************************/
35
+ void CreateGUIHome(void); //����������
36
+ void DeleteGUIHome(void); //ɾ��������
37
+ void GUIHomePoll(void); //��������ѯ
38
+
39
+ #endif
deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUIKeyBoard.c ADDED
@@ -0,0 +1,504 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�GUIKeyBoard.c
3
+ * ժ Ҫ������ģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+
17
+ /*********************************************************************************************************
18
+ * ����ͷ�ļ�
19
+ *********************************************************************************************************/
20
+ #include "GUIKeyBoard.h"
21
+ #include "GUIPlatform.h"
22
+ #include "ButtonWidget.h"
23
+ #include "InfoWidget.h"
24
+ #include "TLILCD.h"
25
+ #include "BMP.h"
26
+ #include "JPEG.h"
27
+ #include "Common.h"
28
+ #include "stdio.h"
29
+ #include "Keyboard.h"
30
+ #include "Malloc.h"
31
+ #include "SysTick.h"
32
+
33
+ /*********************************************************************************************************
34
+ * �궨��
35
+ *********************************************************************************************************/
36
+
37
+ /*********************************************************************************************************
38
+ * ö�ٽṹ�嶨��
39
+ *********************************************************************************************************/
40
+ //����ö��
41
+ typedef enum
42
+ {
43
+ GUI_BUTTON_ESC = 0, // ESC�������Ǵ�0��ʼ
44
+ GUI_BUTTON_K1, // 1
45
+ GUI_BUTTON_K2, // 2
46
+ GUI_BUTTON_K3, // 3
47
+ GUI_BUTTON_K4, // 4
48
+ GUI_BUTTON_K5, // 5
49
+ GUI_BUTTON_K6, // 6
50
+ GUI_BUTTON_K7, // 7
51
+ GUI_BUTTON_K8, // 8
52
+ GUI_BUTTON_K9, // 9
53
+ GUI_BUTTON_K0, // 0
54
+ GUI_BUTTON_MINUS, // - _
55
+ GUI_BUTTON_EQUAL, // = +
56
+ GUI_BUTTON_BACK, // Backspace
57
+ GUI_BUTTON_TAB, // Tab
58
+ GUI_BUTTON_Q, // Q
59
+ GUI_BUTTON_W, // W
60
+ GUI_BUTTON_E, // E
61
+ GUI_BUTTON_R, // R
62
+ GUI_BUTTON_T, // T
63
+ GUI_BUTTON_Y, // Y
64
+ GUI_BUTTON_U, // U
65
+ GUI_BUTTON_I, // I
66
+ GUI_BUTTON_O, // O
67
+ GUI_BUTTON_P, // P
68
+ GUI_BUTTON_LPARAN, // [ {
69
+ GUI_BUTTON_RPARAN, // ] }
70
+ GUI_BUTTON_SLASH, // \ |
71
+ GUI_BUTTON_CAPSLOCK, // CapLock
72
+ GUI_BUTTON_A, // A
73
+ GUI_BUTTON_S, // S
74
+ GUI_BUTTON_D, // D
75
+ GUI_BUTTON_F, // F
76
+ GUI_BUTTON_G, // G
77
+ GUI_BUTTON_H, // H
78
+ GUI_BUTTON_J, // J
79
+ GUI_BUTTON_K, // K
80
+ GUI_BUTTON_L, // L
81
+ GUI_BUTTON_SEMICOLON, // ; :semicolon
82
+ GUI_BUTTON_QUOTATION, // ' "
83
+ GUI_BUTTON_ENTER, // Enter
84
+ GUI_BUTTON_LSHIFT, // left Shift
85
+ GUI_BUTTON_Z, // Z
86
+ GUI_BUTTON_X, // X
87
+ GUI_BUTTON_C, // C
88
+ GUI_BUTTON_V, // V
89
+ GUI_BUTTON_B, // B
90
+ GUI_BUTTON_N, // N
91
+ GUI_BUTTON_M, // M
92
+ GUI_BUTTON_COMMA, // , <
93
+ GUI_BUTTON_PERIOD, // . >
94
+ GUI_BUTTON_QUESTION, // / ?
95
+ GUI_BUTTON_RSHIFT, // right Shift
96
+ GUI_BUTTON_LCTRL, // left Ctrl
97
+ GUI_BUTTON_WIN, // Windows
98
+ GUI_BUTTON_LALT, // left Alt
99
+ GUI_BUTTON_SPASEBAR, // Spacebar
100
+ GUI_BUTTON_RALT, // Right Alt
101
+ GUI_BUTTON_RCTRL, // right Ctrl
102
+ GUI_BUTTON_MAX, // ��������
103
+ GUI_BUTTON_NONE, // ������
104
+ }EnumGUIButtons;
105
+
106
+ //����ɨ����
107
+ typedef struct
108
+ {
109
+ u32 num; //����������������
110
+ EnumGUIButtons button[GUI_BUTTON_MAX]; //����ɨ����������ǵ�һ�����ڶ�������n���������µļ�ֵ
111
+ }StructGUIButtonResult;
112
+
113
+ /*********************************************************************************************************
114
+ * �ڲ�����
115
+ *********************************************************************************************************/
116
+ static StructButtonWidget s_arrButton[GUI_BUTTON_MAX]; //��������
117
+ static StructGUIButtonResult s_structButtonPress; //����ɨ����
118
+
119
+ //��ֵת����GUI�������ļ�ֵ��HID��ֵ��һ�£���Ҫ��ת��
120
+ //GUI��ֵ����Ǵ������ң��������£���0��ʼ���
121
+ static u8 s_arrKeyTable[] =
122
+ {
123
+ //��һ��
124
+ KEYBOARD_ESC, KEYBOARD_1, KEYBOARD_2, KEYBOARD_3, KEYBOARD_4, KEYBOARD_5, KEYBOARD_6, KEYBOARD_7,
125
+ KEYBOARD_8, KEYBOARD_9, KEYBOARD_0, KEYBOARD_MINUS, KEYBOARD_EQUAL, KEYBOARD_BACKSPACE,
126
+
127
+ //�ڶ���
128
+ KEYBOARD_TAB, KEYBOARD_Q, KEYBOARD_W, KEYBOARD_E, KEYBOARD_R, KEYBOARD_T, KEYBOARD_Y, KEYBOARD_U,
129
+ KEYBOARD_I, KEYBOARD_O, KEYBOARD_P, KEYBOARD_LPARAN, KEYBOARD_RPARAN, KEYBOARD_SLASH,
130
+
131
+ //������
132
+ KEYBOARD_CAPSLOCK, KEYBOARD_A, KEYBOARD_S, KEYBOARD_D, KEYBOARD_F, KEYBOARD_G, KEYBOARD_H, KEYBOARD_J,
133
+ KEYBOARD_K, KEYBOARD_L, KEYBOARD_SEMICOLON, KEYBOARD_QUOTATION, KEYBOARD_ENTER,
134
+
135
+ //������
136
+ KEYBOARD_LEFT_SHIFT, KEYBOARD_Z, KEYBOARD_X, KEYBOARD_C, KEYBOARD_V, KEYBOARD_B, KEYBOARD_N, KEYBOARD_M,
137
+ KEYBOARD_COMMA, KEYBOARD_PERIOD, KEYBOARD_QUESTION, KEYBOARD_RIGHT_SHIFT,
138
+
139
+ //������
140
+ KEYBOARD_LEFT_CTRL, KEYBOARD_LEFT_WIN, KEYBOARD_LEFT_ALT, KEYBOARD_SPACEBAR, KEYBOARD_RIGHT_ALT,
141
+ KEYBOARD_RIGHT_CTRL,
142
+ };
143
+
144
+ /*********************************************************************************************************
145
+ * �ڲ���������
146
+ *********************************************************************************************************/
147
+ static void ButtonPressCallback(void* button); //�����ص�����
148
+ static StructGUIButtonResult* ScanGUIButton(void); //����ɨ��
149
+
150
+ /*********************************************************************************************************
151
+ * �ڲ�����ʵ��
152
+ *********************************************************************************************************/
153
+ /*********************************************************************************************************
154
+ * �������ƣ�ButtonPressCallback
155
+ * �������ܣ������ص�����
156
+ * ���������void
157
+ * ���������void
158
+ * �� �� ֵ��void
159
+ * �������ڣ�2021��07��01��
160
+ * ע �⣺
161
+ *********************************************************************************************************/
162
+ static void ButtonPressCallback(void* button)
163
+ {
164
+ EnumGUIButtons i;
165
+
166
+ //��ȡ�������½��
167
+ for(i = (EnumGUIButtons)0; i < GUI_BUTTON_MAX; i++)
168
+ {
169
+ if((StructButtonWidget*)button == &s_arrButton[i])
170
+ {
171
+ s_structButtonPress.button[s_structButtonPress.num++] = i;
172
+ }
173
+ }
174
+ }
175
+
176
+ /*********************************************************************************************************
177
+ * �������ƣ�ScanGUIButton
178
+ * �������ܣ�����ɨ��
179
+ * ���������void
180
+ * ���������void
181
+ * �� �� ֵ��void
182
+ * �������ڣ�2021��07��01��
183
+ * ע �⣺
184
+ *********************************************************************************************************/
185
+ static StructGUIButtonResult* ScanGUIButton(void)
186
+ {
187
+ EnumGUIButtons i;
188
+
189
+ //����ް�������
190
+ s_structButtonPress.num = 0;
191
+ for(i = (EnumGUIButtons)0; i < GUI_BUTTON_MAX; i++)
192
+ {
193
+ s_structButtonPress.button[i] = GUI_BUTTON_NONE;
194
+ }
195
+
196
+ //����ɨ�����а�������������ɨ��������s_structButtonPress��
197
+ for(i = (EnumGUIButtons)0; i < GUI_BUTTON_MAX; i++)
198
+ {
199
+ ScanButtonWidget(&s_arrButton[i]);
200
+ }
201
+
202
+ return &s_structButtonPress;
203
+ }
204
+
205
+ /*********************************************************************************************************
206
+ * �������ƣ�KeyProc
207
+ * �������ܣ�������������
208
+ * ���������void
209
+ * ���������void
210
+ * �� �� ֵ��void
211
+ * �������ڣ�2021��07��01��
212
+ * ע �⣺
213
+ * 1�����¿��Ƽ���shift��ctrl��win����ǵ÷��Ϳհ���ָ���������ȡ�����Ƽ�״̬��������Ի�����Ϊ���Ƽ�һֱ
214
+ * ���ڰ���״̬���������ظ��ŵ���������������
215
+ * 2��GUI����ɨ���⵽û�а�������ʱҲ�����һ�δ˻ص����������Է����û�������Ƽ�״̬
216
+ *********************************************************************************************************/
217
+ static void KeyProc(StructGUIButtonResult* result)
218
+ {
219
+ u8 i, funcKey, key[6];
220
+
221
+ //��ʼ����ֵ
222
+ funcKey = 0;
223
+ for(i = 0; i < 6; i++)
224
+ {
225
+ key[i] = 0;
226
+ }
227
+
228
+ //��ȡ��ֵ������ʱ������
229
+ for(i = 0; i < result->num; i++)
230
+ {
231
+ //��Ctrl��
232
+ if(GUI_BUTTON_LCTRL == result->button[i])
233
+ {
234
+ funcKey = funcKey | SET_LEFT_CTRL;
235
+ }
236
+
237
+ //��Ctrl��
238
+ else if(GUI_BUTTON_RCTRL == result->button[i])
239
+ {
240
+ funcKey = funcKey | SET_RIGHT_CTRL;
241
+ }
242
+
243
+ //��Shift��
244
+ else if(GUI_BUTTON_LSHIFT == result->button[i])
245
+ {
246
+ funcKey = funcKey | SET_LEFT_SHIFT;
247
+ }
248
+
249
+ //��Shift��
250
+ else if(GUI_BUTTON_RSHIFT == result->button[i])
251
+ {
252
+ funcKey = funcKey | SET_RIGHT_SHIFT;
253
+ }
254
+
255
+ //��Alt��
256
+ else if(GUI_BUTTON_LALT == result->button[i])
257
+ {
258
+ funcKey = funcKey | SET_LEFT_ALT;
259
+ }
260
+
261
+ //��Alt��
262
+ else if(GUI_BUTTON_RALT == result->button[i])
263
+ {
264
+ funcKey = funcKey | SET_RIGHT_ALT;
265
+ }
266
+
267
+ //Windows��
268
+ else if(GUI_BUTTON_WIN == result->button[i])
269
+ {
270
+ funcKey = funcKey | SET_LEFT_WINDOWS;
271
+ }
272
+
273
+ //��ֵת�������浽��ֵ������
274
+ if(GUI_BUTTON_NONE != result->button[i])
275
+ {
276
+ key[i] = s_arrKeyTable[result->button[i]];
277
+ }
278
+
279
+ //ֻ��ȡǰ6����ֵ
280
+ if(i >= 5)
281
+ {
282
+ break;
283
+ }
284
+ }
285
+
286
+ //�ϱ���ֵ
287
+ while(0 != SendKeyVal(funcKey, key[0], key[1], key[2], key[3], key[4], key[5]));
288
+ }
289
+
290
+ /*********************************************************************************************************
291
+ * API����ʵ��
292
+ *********************************************************************************************************/
293
+ /*********************************************************************************************************
294
+ * �������ƣ�CreateGUIKeyBoard
295
+ * �������ܣ���������
296
+ * ���������void
297
+ * ���������void
298
+ * �� �� ֵ��void
299
+ * �������ڣ�2021��07��01��
300
+ * ע �⣺
301
+ *********************************************************************************************************/
302
+ void CreateGUIKeyBoard(void)
303
+ {
304
+ static StructJpegImage s_structPressImage45x45;
305
+ static StructJpegImage s_structReleaseImage45x45;
306
+ static StructJpegImage s_structPressImage70x45;
307
+ static StructJpegImage s_structReleaseImage70x45;
308
+ static StructJpegImage s_structPressImage96x45;
309
+ static StructJpegImage s_structReleaseImage96x45;
310
+ static StructJpegImage s_structPressImage123x45;
311
+ static StructJpegImage s_structReleaseImage123x45;
312
+ static StructJpegImage s_structPressImage416x45;
313
+ static StructJpegImage s_structReleaseImage416x45;
314
+ StructInfoWidget infoWidget;
315
+ StructBmpImage infoBmp;
316
+
317
+ //��ʾ�ַ�
318
+ static const char* s_arrButtonText[GUI_BUTTON_MAX] =
319
+ {"ESC", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "- -", "= +", "Back", //��һ��
320
+ "Tab", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "[ {", "] }", "\\ |", //�ڶ���
321
+ "CapsLock", "A", "S", "D", "F", "G", "H", "J", "K", "L", "; :", "' \"", "Enter", //������
322
+ "Shift", "Z", "X", "C", "V", "B", "N", "M", ", <", ". >", "/ ?", "Shift", //������
323
+ "Ctrl", "Win", "Alt", "", "Alt", "Ctrl"}; //������
324
+
325
+ //�ؼ�����
326
+ static const u16 s_arrButtonWidth[GUI_BUTTON_MAX] =
327
+ {
328
+ 45 , 45, 45, 45 , 45, 45, 45, 45, 45, 45, 45, 45 , 45, 96, //��һ��
329
+ 70 , 45, 45, 45 , 45, 45, 45, 45, 45, 45, 45, 45 , 45, 70, //�ڶ���
330
+ 96 , 45, 45, 45 , 45, 45, 45, 45, 45, 45, 45, 45 , 96, //������
331
+ 123, 45, 45, 45 , 45, 45, 45, 45, 45, 45, 45, 123, //������
332
+ 96 , 45, 45, 416, 45, 96}; //������
333
+
334
+ //�ַ�����������ڿؼ���ƫ����
335
+ static const u8 s_arrStringX0[GUI_BUTTON_MAX] =
336
+ {
337
+ 4 , 16, 16, 16 , 16, 16, 16, 16, 16, 16, 16, 4 , 4 , 24, //��һ��
338
+ 17 , 16, 16, 16 , 16, 16, 16, 16, 16, 16, 16, 4 , 4 , 17, //�ڶ���
339
+ 0 , 16, 16, 16 , 16, 16, 16, 16, 16, 16, 4 , 4 , 18, //������
340
+ 31 , 16, 16, 16 , 16, 16, 16, 16, 4 , 4 , 4 , 31, //������
341
+ 24 , 4 , 4 , 0 , 4 , 24}; //������
342
+
343
+ EnumGUIButtons i;
344
+ u32 x, y;
345
+
346
+ //LCD������ʾ
347
+ LCDDisplayDir(LCD_SCREEN_HORIZONTAL);
348
+
349
+ //���Ʊ���
350
+ DisPlayBMPByIPA(0, 0, MAIN_WINDOWN_BACKGROUND_DIR);
351
+
352
+ s_structPressImage45x45.image = (unsigned char*)KEYBOARD_KEY_45x45_PRESS_DIR;
353
+ s_structReleaseImage45x45.image = (unsigned char*)KEYBOARD_KEY_45x45_RELEASE_DIR;
354
+ s_structPressImage70x45.image = (unsigned char*)KEYBOARD_KEY_70x45_PRESS_DIR;
355
+ s_structReleaseImage70x45.image = (unsigned char*)KEYBOARD_KEY_70x45_RELEASE_DIR;
356
+ s_structPressImage96x45.image = (unsigned char*)KEYBOARD_KEY_96x45_PRESS_DIR;
357
+ s_structReleaseImage96x45.image = (unsigned char*)KEYBOARD_KEY_96x45_RELEASE_DIR;
358
+ s_structPressImage123x45.image = (unsigned char*)KEYBOARD_KEY_123x45_PRESS_DIR;
359
+ s_structReleaseImage123x45.image = (unsigned char*)KEYBOARD_KEY_123x45_RELEASE_DIR;
360
+ s_structPressImage416x45.image = (unsigned char*)KEYBOARD_KEY_416x45_PRESS_DIR;
361
+ s_structReleaseImage416x45.image = (unsigned char*)KEYBOARD_KEY_416x45_RELEASE_DIR;
362
+
363
+ //����ް�������
364
+ s_structButtonPress.num = 0;
365
+ for(i = (EnumGUIButtons)0; i < GUI_BUTTON_MAX; i++)
366
+ {
367
+ s_structButtonPress.button[i] = GUI_BUTTON_NONE;
368
+ }
369
+
370
+ //��������
371
+ x = 6;
372
+ y = 130;
373
+ for(i = (EnumGUIButtons)0; i < GUI_BUTTON_MAX; i++)
374
+ {
375
+ InitButtonWidgetStruct(&s_arrButton[i]);
376
+ s_arrButton[i].x0 = x;
377
+ s_arrButton[i].y0 = y;
378
+ s_arrButton[i].width = s_arrButtonWidth[i];
379
+ s_arrButton[i].height = 45;
380
+ s_arrButton[i].textX0 = s_arrStringX0[i];
381
+ s_arrButton[i].textY0 = 10;
382
+ // s_arrButton[i].textColor = GUI_COLOR_ORANGE;
383
+ s_arrButton[i].text = s_arrButtonText[i];
384
+ s_arrButton[i].type = BUTTON_WIDGET_TYPE_LEVEL;
385
+ s_arrButton[i].pressCallback = ButtonPressCallback;
386
+
387
+ //���ñ���ͼƬ
388
+ s_arrButton[i].pressImageType = GUI_IMAGE_TYPE_JPEG;
389
+ s_arrButton[i].releaseImageType = GUI_IMAGE_TYPE_JPEG;
390
+ if(45 == s_arrButton[i].width)
391
+ {
392
+ s_arrButton[i].pressBackgroudImage = (void*)(&s_structPressImage45x45);
393
+ s_arrButton[i].releaseBackgroudImage = (void*)(&s_structReleaseImage45x45);
394
+ }
395
+ else if(70 == s_arrButton[i].width)
396
+ {
397
+ s_arrButton[i].pressBackgroudImage = (void*)(&s_structPressImage70x45);
398
+ s_arrButton[i].releaseBackgroudImage = (void*)(&s_structReleaseImage70x45);
399
+ }
400
+ else if(96 == s_arrButton[i].width)
401
+ {
402
+ s_arrButton[i].pressBackgroudImage = (void*)(&s_structPressImage96x45);
403
+ s_arrButton[i].releaseBackgroudImage = (void*)(&s_structReleaseImage96x45);
404
+ }
405
+ else if(123 == s_arrButton[i].width)
406
+ {
407
+ s_arrButton[i].pressBackgroudImage = (void*)(&s_structPressImage123x45);
408
+ s_arrButton[i].releaseBackgroudImage = (void*)(&s_structReleaseImage123x45);
409
+ }
410
+ else if(416 == s_arrButton[i].width)
411
+ {
412
+ s_arrButton[i].pressBackgroudImage = (void*)(&s_structPressImage416x45);
413
+ s_arrButton[i].releaseBackgroudImage = (void*)(&s_structReleaseImage416x45);
414
+ }
415
+
416
+ //�����ؼ�
417
+ CreateButtonWidget(&s_arrButton[i]);
418
+
419
+ //���������
420
+ x = x + s_arrButton[i].width + 8;
421
+
422
+ //�л�����һ��
423
+ if((GUI_BUTTON_BACK == i) || (GUI_BUTTON_SLASH == i) || (GUI_BUTTON_ENTER == i) || (GUI_BUTTON_RSHIFT == i) || (GUI_BUTTON_RCTRL == i))
424
+ {
425
+ x = 6;
426
+ y = y + s_arrButton[0].height + 10;
427
+ }
428
+ }
429
+
430
+ //��ʼ��USB��������
431
+ InitKeyboard();
432
+
433
+ //�ȴ��������
434
+ infoBmp.alphaType = BMP_UES_ALPHA;
435
+ infoBmp.storageType = BMP_IN_FATFS;
436
+ infoBmp.addr = (void*)INFO_BACKGROUND_DIR;
437
+ InitInfoWidgetStruct(&infoWidget);
438
+ infoWidget.width = 300;
439
+ infoWidget.height = 193;
440
+ infoWidget.x0 = (g_structTLILCDDev.width[g_structTLILCDDev.currentLayer] - infoWidget.width) / 2;
441
+ infoWidget.y0 = (g_structTLILCDDev.height[g_structTLILCDDev.currentLayer] - infoWidget.height) / 2;
442
+ infoWidget.background = MyMalloc(SRAMEX, infoWidget.width * infoWidget.height * 2);
443
+ infoWidget.image = (void*)&infoBmp;
444
+ infoWidget.imageType = GUI_IMAGE_TYPE_BMP;
445
+ CreateInfoWidget(&infoWidget);
446
+ while(!IsKeyboardConfigFinish())
447
+ {
448
+ if(0 == infoWidget.isShow)
449
+ {
450
+ SetInfoWidgetShow(&infoWidget, "�����²��USB");
451
+ DelayNms(500);
452
+ }
453
+ }
454
+ DeleteInfoWidget(&infoWidget);
455
+ MyFree(SRAMEX, infoWidget.background);
456
+ }
457
+
458
+ /*********************************************************************************************************
459
+ * �������ƣ�DeleteGUIKeyBoard
460
+ * �������ܣ�ɾ������
461
+ * ���������void
462
+ * ���������void
463
+ * �� �� ֵ��void
464
+ * �������ڣ�2021��07��01��
465
+ * ע �⣺
466
+ *********************************************************************************************************/
467
+ void DeleteGUIKeyBoard(void)
468
+ {
469
+ DeInitKeyboard();
470
+ }
471
+
472
+ /*********************************************************************************************************
473
+ * �������ƣ�GUIKeyBoardPoll
474
+ * �������ܣ�������ѯ����
475
+ * ���������void
476
+ * ���������void
477
+ * �� �� ֵ��void
478
+ * �������ڣ�2021��07��01��
479
+ * ע �⣺
480
+ *********************************************************************************************************/
481
+ void GUIKeyBoardPoll(void)
482
+ {
483
+ static u64 s_iSysLastTime = 0;
484
+ static u64 s_iSysCurrentTime = 0;
485
+ static u32 s_iLastKeyNum = 0;
486
+ StructGUIButtonResult* button;
487
+
488
+ //��ȡ��ǰʱ��
489
+ s_iSysCurrentTime = GUIGetSysTime();
490
+
491
+ if((s_iSysCurrentTime - s_iSysLastTime) >= KEY_BOARD_SCAN_TIME)
492
+ {
493
+ s_iSysLastTime = s_iSysCurrentTime;
494
+
495
+ //����ɨ��
496
+ button = ScanGUIButton();
497
+ if((0 != button->num) || (s_iLastKeyNum != button->num))
498
+ {
499
+ KeyProc(button);
500
+ }
501
+
502
+ s_iLastKeyNum = button->num;
503
+ }
504
+ }
deployment/GD32F470I_BluePill_ARMCC/App/EmbGUI/App/GUIKeyBoard.h ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*********************************************************************************************************
2
+ * ģ�����ƣ�GUIKeyBoard.h
3
+ * ժ Ҫ������ģ��
4
+ * ��ǰ�汾��1.0.0
5
+ * �� �ߣ�Leyutek(COPYRIGHT 2018 - 2021 Leyutek. All rights reserved.)
6
+ * ������ڣ�2021��07��01��
7
+ * �� �ݣ�
8
+ * ע �⣺
9
+ **********************************************************************************************************
10
+ * ȡ���汾��
11
+ * �� �ߣ�
12
+ * ������ڣ�
13
+ * �޸����ݣ�
14
+ * �޸��ļ���
15
+ *********************************************************************************************************/
16
+ #ifndef _GUI_KEY_BOARD_H_
17
+ #define _GUI_KEY_BOARD_H_
18
+
19
+ /*********************************************************************************************************
20
+ * ����ͷ�ļ�
21
+ *********************************************************************************************************/
22
+ #include "DataType.h"
23
+
24
+ /*********************************************************************************************************
25
+ * �궨��
26
+ *********************************************************************************************************/
27
+ #define KEY_BOARD_SCAN_TIME 100
28
+
29
+ /*********************************************************************************************************
30
+ * ö�ٽṹ�嶨��
31
+ *********************************************************************************************************/
32
+
33
+ /*********************************************************************************************************
34
+ * API��������
35
+ *********************************************************************************************************/
36
+ void CreateGUIKeyBoard(void); //��������
37
+ void DeleteGUIKeyBoard(void); //ɾ������
38
+ void GUIKeyBoardPoll(void); //������ѯ����
39
+
40
+ #endif