summaryrefslogtreecommitdiff
path: root/113-13801.c
blob: d0eb83a22b6fdea20b821a303cf832ed4823c803 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//////////////////////////////////////////////////////////////////////////////
//
// 	Filename:	113-13801.c
//	Version:		
//	Data:		
//
//	Author:		Liu, Zemin
//	Company:	JYE Tech
//
//-----------------------------------------------------------------------------
//
// 	Target: 		STM32F103C8 
// 	Tool chain: 	CodeSourcery G++
//
//	Descriptions: 	Main firmware for low-cost DSO kit
//	PCB: 		109-13800-00C
//-----------------------------------------------------------------------------
//	Required files:
//
//-----------------------------------------------------------------------------
//	ATTENTION: 
//-----------------------------------------------------------------------------
//	Revision History:
//
//
///////////////////////////////////////////////////////////////////////////////

#include "stm32f10x.h"
#include "stm32f10x_conf.h"

#include "Common.h"
#include "Board.h"
#include	"Screen.h"
#include	"Command.h"
#include 	"Eeprom.h"

#include	"libdso138.h"


int main (void)
{
 U16 tmp1, tmp2;
 
 Clock_Init();
 
 Port_Init();

 // Check SW4 pin. If the pin is read LOW enter TEST mode
 tmp1 = (PB_Port & PB_Bits) | ~PB_Bits;
 if(!BitTest(tmp1, 0x8000)) {
	// Enter TEST mode
	TestMode();
 	}
 
 /* Unlock the Flash Program Erase controller */
 FLASH_Unlock();

 /* EEPROM Init */
 EE_Init();

 TFT_Init_Ili9341();
 
 USART1_Init();
 uputs((U8 *)"Uart1 Ok\n\r", USART1);

 SysTick_Init();
 TIM3_Init();
 TIM4_Init();

 ADC2_Init();
 
 AppInit();  
 
 tmp1 = clBlack;
 PutsGenic(24, 120, (U8 *)"FW: 113-13801-037", clWhite, tmp1, &ASC8X16);
 PutsGenic(24, 140, (U8 *)LibVersion, clWhite, tmp1, &ASC8X16);
 PutsGenic(24, 180, (U8 *)"Booting...", clWhite, tmp1, &ASC8X16);

 // LED blink twice
 LedBlink();

 NVIC_Configuration();

 Flags = 0;
 
// Uncomment the following line to disable display of scope panel
// NoScopePanel = 1;
 
 while(1) {
// ============================
// Note: 	Keep this section in the main loop for proper capture engine running
//		even scope panel display is disabled.

 	DsoDisplay();

	tmp1 = GetDsoStatus();

// --------------------------------------------------------	
	if(BitTest(tmp1, DSO_NormalDisplay)) {

		// Add your diaplay codes here

		
		}
// --------------------------------------------------------

 	if(GTimeout) {
		GTimeout = 0;
		StartCapture();
 		}
	
// ============================	


	if(BitTest(Keypad.Flags, (1 << KF_DoKeyScan))) {
		BitClr(Keypad.Flags, (1 << KF_DoKeyScan));
		// Do key scan
		KeyScan();
		}

	if(Keypad.KeyCode) {
		// Process key code
		KeyProc();
		Keypad.KeyCode = 0;
		}

	if(GTimer == 0) {
		if(BitTest(tmp1, DSO_CaptureDone)) {
			UpdateDisp(Disp_Trace);
			tmp2 = GetTimebase();
			if(tmp2 <= TB_1ms) {
				// Start next capture		
				StartCapture();
				}
			else {
				// Lower capture rate
				GTimer = 40;
				}
			}
		}

	
	if(BitTest(tmp1, DSO_Rolling)) {
		Rolling();
		}

 	}
 
}