-
Notifications
You must be signed in to change notification settings - Fork 8
/
myCode.cpp
204 lines (165 loc) · 3.91 KB
/
myCode.cpp
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/***************************************************
STM32 duino based firmware for DSO SHELL/150
* * GPL v2
* (c) mean 2019 fixounet@free.fr
****************************************************/
#include "dso_global.h"
#include "Fonts/waree9.h"
#include "Fonts/waree12.h"
#include "dso_test_signal.h"
#include "dso_eeprom.h"
#include "dso_adc_gain.h"
#include "cpuID.h"
#include "pinConfiguration.h"
#include "helpers/helper_pwm.h"
#include "dso_debug.h"
static void MainTask( void *a );
void splash(void);
//--
Adafruit_TFTLCD_8bit_STM32 *tft;
testSignal *myTestSignal;
DSOControl *controlButtons;
DSOADC *adc;
uint16_t displayIdentifier=0;
xMutex *adc2Lock;
// Globals
uint16_t calibrationHash=0;
//
// Test functions
//
#include "testFunc/testFunc.h"
extern void mainDSOUI(void);
/**
*
*/
#ifdef __cplusplus
extern "C" {
#endif
void vApplicationDaemonTaskStartupHook(void);
#ifdef __cplusplus
}
#endif
void mySetup()
{
afio_cfg_debug_ports( AFIO_DEBUG_SW_ONLY); // Unlock PB3 & PB4
#if 0
__IO uint32 *mapr = &AFIO_BASE->MAPR;
uint32_t r=*mapr;
r=r & ~AFIO_MAPR_SWJ_CFG;
r|=AFIO_DEBUG_SW_ONLY;
*mapr=r;
#endif
Serial.end();
Serial1.begin(115200); //Wire.begin();
Serial.end();
Serial1.begin(115200);
Logger("Init");
cpuID::identify(); // enable FPU ASAP
// Ok let's go, switch to FreeRTOS
xTaskCreate( MainTask, "MainTask", 350, NULL, DSO_MAIN_TASK_PRIORITY, NULL );
vTaskStartScheduler();
}
/**
*
*/
void vApplicationDaemonTaskStartupHook()
{
}
int adcLockCount=0;
void useAdc2(bool use)
{
if(use)
{
adc2Lock->lock();
xAssert(!adcLockCount);
adcLockCount++;
}
else
{
xAssert(adcLockCount==1);
adcLockCount--;
adc2Lock->unlock();
}
}
/**
*
* @param a
*/
void MainTask( void *a )
{
displayIdentifier = tft->readID();
if(!displayIdentifier) displayIdentifier=0x7789;
tft=Adafruit_TFTLCD_8bit_STM32::spawn(displayIdentifier);
if(!tft)
{
xAssert(0);
}
interrupts();
tft->begin();
tft->setRotation(1);
tft->setFontFamily(&Waree9pt7b, &Waree9pt7b, &Waree12pt7b);
tft->fillScreen(BLACK);
splash();
adc2Lock=new xMutex;
delay(500);
myTestSignal=new testSignal( PIN_TEST_SIGNAL,PIN_TEST_SIGNAL_AMP);
myTestSignal->setAmplitude(true);
myTestSignal->setFrequency(1000); // 1Khz
controlButtons=new DSOControl ;
controlButtons->setup();
adc=new DSOADC(DSO_INPUT_PIN);
tft->fillScreen(BLACK);
tft->setTextSize(3);
//DSOCalibrate::calibrate();
// Start ADC timer timebase at 8 Mhz
// total period = 0.125 us
setTimerFrequency(&Timer2,2, 62, 63);
//xAssert(0);
adc->setupADCs ();
// Do a dummy capture to make sure everything is fine
adc->setADCPin(PA0);
adc->setupDmaSampling();
adc->prepareDMASampling(ADC_SMPR_239_5,DSOADC::ADC_PRESCALER_8);
adc->stopDmaCapture();
//testCalibrate();
// testTestSignal();
//testButtonCoupling();
//testButtons();
//testDualADC();
//testPigOsCope();
//
//
if(!DSOEeprom::read())
{
DSOEeprom::format();
DSOCalibrate::zeroCalibrate();
}
DSOEeprom::readFineVoltage();
//testAdc();
//testAdc2(); //fast
// testAdc3(); // slow
//testDisplay();
// testCalibrate();
DSOInputGain::readCalibrationValue(); // re-read calibration value
adc->setupADCs ();
// --- TEST ---
//DSOCalibrate::voltageCalibrate();
// --- TEST ---
DSOCapture::initialize();
//testI2c();
mainDSOUI();
//testTrigger();
//testCapture();
//testAdcWatchdog();
while(1)
{};
}
void dummyForwardReference()
{
mainDSOUI();
}
float testFpu(float f, float g)
{
return f*g-1.1;
}
//-