Subversion Repositories DashDisplay

Rev

Rev 6 | Rev 8 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6 Rev 7
Line 35... Line 35...
35
 
35
 
36
/* USER CODE BEGIN Includes */
36
/* USER CODE BEGIN Includes */
37
#include "ap_math.h"
37
#include "ap_math.h"
38
#include "serial.h"
38
#include "serial.h"
39
#include "SSD1306.h"
39
#include "SSD1306.h"
-
 
40
#include "Font.h"
40
#include "dials.h"
41
#include "dials.h"
41
#include "switches.h"
42
#include "switches.h"
42
#include <math.h>
43
#include <math.h>
43
#include "plx.h"
44
#include "plx.h"
44
 
45
 
45
/* USER CODE END Includes */
46
/* USER CODE END Includes */
46
 
47
 
47
/* Private variables ---------------------------------------------------------*/
48
/* Private variables ---------------------------------------------------------*/
48
ADC_HandleTypeDef hadc1;
-
 
49
 
-
 
50
SPI_HandleTypeDef hspi1;
49
SPI_HandleTypeDef hspi1;
51
 
50
 
52
UART_HandleTypeDef huart1;
51
UART_HandleTypeDef huart1;
53
UART_HandleTypeDef huart2;
52
UART_HandleTypeDef huart2;
54
 
53
 
55
/* USER CODE BEGIN PV */
54
/* USER CODE BEGIN PV */
56
/* Private variables ---------------------------------------------------------*/
55
/* Private variables ---------------------------------------------------------*/
-
 
56
#define MAXRDG 10
57
 
57
 
-
 
58
int OldObservation[2] =
-
 
59
{ -1, -1 }; // illegal initial value
-
 
60
int OldObservationIndex[2] =
-
 
61
{ -1, -1 }; // if more than one sensor this will be printed
-
 
62
int16_t dial0[2] =
-
 
63
{ 0, 0 };
-
 
64
int16_t dial1[2] =
-
 
65
{ -1, -1 };
-
 
66
union
-
 
67
{
-
 
68
        PLX_SensorInfo Sensor[MAXRDG];
-
 
69
        char Bytes[MAXRDG * sizeof(PLX_SensorInfo)];
-
 
70
} Data;
-
 
71
int Max[MAXRDG];
-
 
72
int Min[MAXRDG];
-
 
73
int PLXItems;
58
/* USER CODE END PV */
74
/* USER CODE END PV */
59
 
75
 
60
/* Private function prototypes -----------------------------------------------*/
76
/* Private function prototypes -----------------------------------------------*/
61
void
77
void
62
SystemClock_Config (void);
78
SystemClock_Config(void);
63
void
79
void
64
Error_Handler (void);
80
Error_Handler(void);
65
static void
81
static void
66
MX_GPIO_Init (void);
82
MX_GPIO_Init(void);
67
static void
83
static void
68
MX_ADC1_Init (void);
84
MX_SPI1_Init(void);
69
static void
85
static void
70
MX_SPI1_Init (void);
86
MX_USART2_UART_Init(void);
71
static void
87
static void
72
MX_USART2_UART_Init (void);
-
 
73
static void
-
 
74
MX_USART1_UART_Init (void);
88
MX_USART1_UART_Init(void);
75
 
89
 
76
/* USER CODE BEGIN PFP */
90
/* USER CODE BEGIN PFP */
77
/* Private function prototypes -----------------------------------------------*/
91
/* Private function prototypes -----------------------------------------------*/
78
 
92
 
79
/* USER CODE END PFP */
93
/* USER CODE END PFP */
80
 
94
 
81
/* USER CODE BEGIN 0 */
95
/* USER CODE BEGIN 0 */
82
/* dummy function */
96
/* dummy function */
83
void
-
 
84
_init (void)
97
void _init(void)
85
{
98
{
86
 
99
 
87
}
100
}
-
 
101
// the dial is the switch number we are using.
-
 
102
// suppress is the ItemIndex we wish to suppress on this display
-
 
103
int  DisplayCurrent(int dial,int suppress)
-
 
104
{
-
 
105
        char buff[10];
-
 
106
        int i;
-
 
107
        select_display(dial); // pick the display we are using
-
 
108
        int ItemIndex = dial_pos[dial];
-
 
109
        // wrap around count if dial too far to the right
-
 
110
        if (ItemIndex >= PLXItems)
-
 
111
        {
-
 
112
                dial_pos[dial] = 0;
-
 
113
                ItemIndex = 0;
-
 
114
        }
-
 
115
        if (ItemIndex < 0)
-
 
116
        {
-
 
117
                ItemIndex = 0;
-
 
118
                dial_pos[dial] = 0;
-
 
119
        }
-
 
120
 
-
 
121
        // check for item suppression
-
 
122
        if(ItemIndex == suppress)
-
 
123
        {
-
 
124
                dial1[dial] = -1;
-
 
125
                OldObservation[dial] = -1;
-
 
126
                OldObservationIndex[dial] = -1;
-
 
127
 
-
 
128
                 drawLine(0,0,127,63,1);
-
 
129
        //      display();
-
 
130
                return -1; // we suppressed this display
-
 
131
        }
-
 
132
        // do not try to convert if no items in buffer
-
 
133
        if (PLXItems > 0)
-
 
134
        {
-
 
135
                int DataVal = ConvPLX(Data.Sensor[ItemIndex].ReadingH,
-
 
136
                                Data.Sensor[ItemIndex].ReadingL); // data reading
-
 
137
                int Observation = ConvPLX(Data.Sensor[ItemIndex].AddrH,
-
 
138
                                Data.Sensor[ItemIndex].AddrL);
-
 
139
                int ObservationIndex = ConvPLX(0, Data.Sensor[ItemIndex].Instance);
-
 
140
                // now to convert the readings and format strings
-
 
141
                // find out limits
-
 
142
                char * msg;
-
 
143
                int len;
-
 
144
 
-
 
145
                if (Observation < PLX_MAX_OBS)
-
 
146
                {
-
 
147
                        if (Observation != OldObservation[dial]
-
 
148
                                        || ObservationIndex != OldObservationIndex[dial])
-
 
149
                        {
-
 
150
                                dial1[dial] = -1;
-
 
151
                                clearDisplay();
-
 
152
                                dial_draw_scale(
-
 
153
                                                DisplayInfo[Observation].Low
-
 
154
                                                                / DisplayInfo[Observation].TickScale,
-
 
155
                                                DisplayInfo[Observation].High
-
 
156
                                                                / DisplayInfo[Observation].TickScale, 16, 1);
-
 
157
                                if (ObservationIndex > 0)
-
 
158
                                {
-
 
159
                                        len = 5;
-
 
160
                                        buff[6] = ObservationIndex + '1';
-
 
161
                                }
-
 
162
                                else
-
 
163
                                {
-
 
164
                                        len = 6;
-
 
165
                                }
-
 
166
                                {
-
 
167
                                        msg = DisplayInfo[Observation].name;
-
 
168
                                }
-
 
169
                                for (i = 0; i < len; i++)
-
 
170
                                {
-
 
171
                                        buff[i] = msg[i];
-
 
172
                                }
-
 
173
                                print_large_string(buff, 32, 48, 6); // this prints spaces for \0 at end of string
-
 
174
 
-
 
175
                                OldObservation[dial] = Observation;
-
 
176
                                OldObservationIndex[dial] = ObservationIndex;
-
 
177
                                //
-
 
178
                                display();
-
 
179
 
-
 
180
                        }
88
 
181
 
-
 
182
                        double max_rdg;
-
 
183
                        double min_rdg;
-
 
184
                        double cur_rdg;
-
 
185
                        int int_rdg;
-
 
186
 
-
 
187
                        max_rdg = ConveriMFDRaw2Data(Observation,
-
 
188
                                        DisplayInfo[Observation].Units, Max[ItemIndex]);
-
 
189
                        min_rdg = ConveriMFDRaw2Data(Observation,
-
 
190
                                        DisplayInfo[Observation].Units, Min[ItemIndex]);
-
 
191
                        cur_rdg = ConveriMFDRaw2Data(Observation,
-
 
192
                                        DisplayInfo[Observation].Units, DataVal);
-
 
193
 
-
 
194
                        cur_rdg /= DisplayInfo[Observation].TickScale;
-
 
195
                        int dp_pos;  // where to print the decimal place
-
 
196
                        switch (DisplayInfo[Observation].DP)
-
 
197
                        {
-
 
198
                        case 0:
-
 
199
                                int_rdg = (int) (cur_rdg);
-
 
200
                                dp_pos = 100;
-
 
201
                                break;
-
 
202
                        case 1:
-
 
203
                                int_rdg = (int) (cur_rdg * 10.0);
-
 
204
                                dp_pos = 3;
-
 
205
                                break;
-
 
206
                        case 2:
-
 
207
                                int_rdg = (int) (cur_rdg * 100.0);
-
 
208
                                dp_pos = 2;
-
 
209
                                break;
-
 
210
                        }
-
 
211
 
-
 
212
                        cur_rdg -= DisplayInfo[Observation].Low;
-
 
213
                        cur_rdg = 100 * cur_rdg
-
 
214
                                        / (DisplayInfo[Observation].High
-
 
215
                                                        - DisplayInfo[Observation].Low);
-
 
216
 
-
 
217
                        dial0[dial] = (int) cur_rdg;
-
 
218
 
-
 
219
                        /* old needle un-draw */
-
 
220
                        if (dial1[dial] >= 0)
-
 
221
                        {
-
 
222
                                dial_draw_needle(dial1[dial]);
-
 
223
                        }
-
 
224
                        dial_draw_needle(dial0[dial]);
-
 
225
                        // print value overlaid by needle
-
 
226
                        // this is actual reading
-
 
227
                        print_digits(64 - 16, 30, 4, dp_pos, int_rdg);
-
 
228
 
-
 
229
                        dial1[dial] = dial0[dial];
-
 
230
 
-
 
231
                        display();
-
 
232
 
-
 
233
                }
-
 
234
        }
-
 
235
        return ItemIndex;
-
 
236
}
89
/* USER CODE END 0 */
237
/* USER CODE END 0 */
90
 
238
 
91
int
-
 
92
main (void)
239
int main(void)
93
{
240
{
94
 
241
 
95
  /* USER CODE BEGIN 1 */
242
        /* USER CODE BEGIN 1 */
96
 
243
 
97
  GPIO_InitTypeDef GPIO_InitStruct;
244
        GPIO_InitTypeDef GPIO_InitStruct;
98
 
245
 
99
  __HAL_RCC_SPI1_CLK_ENABLE()
246
        __HAL_RCC_SPI1_CLK_ENABLE()
100
  ;
247
        ;
101
  __HAL_RCC_USART1_CLK_ENABLE()
248
        __HAL_RCC_USART1_CLK_ENABLE()
102
  ; // PLX main port
249
        ; // PLX main port
103
  __HAL_RCC_USART2_CLK_ENABLE()
250
        __HAL_RCC_USART2_CLK_ENABLE()
104
  ; // debug port
251
        ; // debug port
105
  /* USER CODE END 1 */
252
        /* USER CODE END 1 */
106
 
253
 
107
  /* MCU Configuration----------------------------------------------------------*/
254
        /* MCU Configuration----------------------------------------------------------*/
108
 
255
 
109
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
256
        /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
110
  HAL_Init ();
257
        HAL_Init();
111
 
258
 
112
  /* Configure the system clock */
259
        /* Configure the system clock */
113
  SystemClock_Config ();
260
        SystemClock_Config();
114
 
261
 
115
  /* Initialize all configured peripherals */
262
        /* Initialize all configured peripherals */
116
  MX_GPIO_Init ();
263
        MX_GPIO_Init();
117
  // MX_ADC1_Init();
-
 
118
  MX_SPI1_Init ();
264
        MX_SPI1_Init();
119
  MX_USART2_UART_Init ();
265
        MX_USART2_UART_Init();
120
  MX_USART1_UART_Init ();
266
        MX_USART1_UART_Init();
121
 
267
 
122
  /* USER CODE BEGIN 2 */
268
        /* USER CODE BEGIN 2 */
123
  /* Need to set AF mode for output pins DURR. */
269
        /* Need to set AF mode for output pins DURR. */
124
  /* SPI bus AF pin selects */
270
        /* SPI bus AF pin selects */
125
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
271
        GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
126
 
272
 
127
  GPIO_InitStruct.Pin = GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_7;
273
        GPIO_InitStruct.Pin = GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_7;
128
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
274
        GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
129
  HAL_GPIO_Init (GPIOA, &GPIO_InitStruct);
275
        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
130
 
276
 
131
  /* USART2 AF pin selects */
277
        /* USART2 AF pin selects */
132
  GPIO_InitStruct.Pin = GPIO_PIN_2;
278
        GPIO_InitStruct.Pin = GPIO_PIN_2;
133
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
279
        GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
134
  HAL_GPIO_Init (GPIOA, &GPIO_InitStruct);
280
        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
135
 
281
 
136
  /* USART1 AF pin selects */
282
        /* USART1 AF pin selects */
137
  GPIO_InitStruct.Pin = GPIO_PIN_9;
283
        GPIO_InitStruct.Pin = GPIO_PIN_9;
138
  HAL_GPIO_Init (GPIOA, &GPIO_InitStruct);
284
        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
139
 
285
 
140
  /* Turn on USART2 IRQ  */
286
        /* Turn on USART2 IRQ  */
141
  HAL_NVIC_SetPriority (USART2_IRQn, 4, 0);
287
        HAL_NVIC_SetPriority(USART2_IRQn, 4, 0);
142
  HAL_NVIC_EnableIRQ (USART2_IRQn);
288
        HAL_NVIC_EnableIRQ(USART2_IRQn);
143
 
289
 
144
  /* Turn on USART1 IRQ */
290
        /* Turn on USART1 IRQ */
145
  HAL_NVIC_SetPriority (USART1_IRQn, 2, 0);
291
        HAL_NVIC_SetPriority(USART1_IRQn, 2, 0);
146
  HAL_NVIC_EnableIRQ (USART1_IRQn);
292
        HAL_NVIC_EnableIRQ(USART1_IRQn);
147
 
293
 
148
  /* setup the USART control blocks */
294
        /* setup the USART control blocks */
149
  init_usart_ctl (&uc1, huart1.Instance);
295
        init_usart_ctl(&uc1, huart1.Instance);
150
  init_usart_ctl (&uc2, huart2.Instance);
296
        init_usart_ctl(&uc2, huart2.Instance);
151
 
297
 
152
  EnableSerialRxInterrupt (&uc1);
298
        EnableSerialRxInterrupt(&uc1);
153
  EnableSerialRxInterrupt (&uc2);
299
        EnableSerialRxInterrupt(&uc2);
154
 
300
 
155
  ap_init (); // set up the approximate math library
301
        ap_init(); // set up the approximate math library
156
 
302
 
157
  int disp;
303
        int disp;
158
 
304
 
159
  ssd1306_begin (1, 0);
305
        ssd1306_begin(1, 0);
160
// static const int xp = 128 - 42;
306
// static const int xp = 128 - 42;
161
  for (disp = 0; disp < 2; disp++)
307
        for (disp = 0; disp < 2; disp++)
162
    {
308
        {
163
      select_display (disp);
309
                select_display(disp);
164
      clearDisplay ();
310
                clearDisplay();
165
      dim (0);
311
                dim(0);
166
      //font_puts(
312
                //font_puts(
167
      //                "Hello world !!\rThis text is a test of the text rendering library in a 5*7 font");
313
                //              "Hello world !!\rThis text is a test of the text rendering library in a 5*7 font");
168
 
314
 
169
      dial_origin (64, 60);
315
                dial_origin(64, 60);
170
      dial_size (60);
316
                dial_size(60);
171
      dial_draw_scale (10, 16, 16, 2);
317
                dial_draw_scale(0, 10, 16, 5);
172
 
-
 
173
      display ();
-
 
174
 
-
 
175
    }
-
 
176
  InitSwitches ();
-
 
177
 
-
 
178
  select_display (0);
-
 
179
  /* USER CODE END 2 */
-
 
180
 
-
 
181
  /* Infinite loop */
-
 
182
  /* USER CODE BEGIN WHILE */
-
 
183
  uint32_t Ticks = HAL_GetTick () + 100;
-
 
184
  int16_t dial0 = 0;
-
 
185
  int16_t dial1 = -1;
-
 
186
 
-
 
187
  int c = 0;
-
 
188
  int i;
-
 
189
  char buff[10];
-
 
190
 
318
 
191
  // PLX decoder protocol
-
 
192
#define MAXRDG 10
-
 
193
  char PLXPacket = 0;
-
 
194
  union
-
 
195
  {
-
 
196
    PLX_SensorInfo Sensor[MAXRDG];
-
 
197
    char Bytes[MAXRDG * sizeof(PLX_SensorInfo)];
-
 
198
  } Data;
319
                display();
199
  int Max[MAXRDG];
-
 
200
  int Min[MAXRDG];
-
 
201
  for (i = 0; i < MAXRDG; i++)
-
 
202
    {
-
 
203
      Max[i] = 0;
-
 
204
      Min[i] = 0xFFF; // 12 bit max value
-
 
205
    }
-
 
206
 
320
 
207
  int PLXPtr;
-
 
208
  int PLXItems;
-
 
209
 
321
        }
210
  int OldObservation = -1; // illegal initial value
-
 
211
  int OldObservationIndex = -1; // if more than one sensor this will be printed
-
 
212
  while (1)
-
 
213
    {
-
 
214
// poll switches
-
 
215
      HandleSwitches ();
322
        InitSwitches();
216
      int ItemIndex = dial_pos[0];
-
 
217
 
323
 
-
 
324
        /* USER CODE END 2 */
-
 
325
 
-
 
326
        /* Infinite loop */
-
 
327
        /* USER CODE BEGIN WHILE */
218
      uint16_t cc = SerialCharsReceived (&uc1);
328
        uint32_t Ticks = HAL_GetTick() + 100;
-
 
329
 
-
 
330
        int i;
-
 
331
 
-
 
332
        // PLX decoder protocol
-
 
333
        char PLXPacket = 0;
219
      for (i = 0; i < cc; i++)
334
        for (i = 0; i < MAXRDG; i++)
220
        {
335
        {
221
          char c = GetCharSerial (&uc1);
-
 
222
          if (c == PLX_Start) // at any time if the start byte appears, reset the pointers
-
 
223
            {
336
                Max[i] = 0;
224
              PLXPtr = 0;    // reset the pointer
337
                Min[i] = 0xFFF; // 12 bit max value
225
              PLXPacket = 1;
-
 
226
              continue;
-
 
227
            }
-
 
228
 
-
 
229
          if (c == PLX_Stop)
-
 
230
            {
-
 
231
              // we can now decode the selected parameter
-
 
232
              PLXPacket = 0;
-
 
233
              PLXItems = PLXPtr / sizeof(PLX_SensorInfo); // total
-
 
234
              // saturate the rotary switch position
-
 
235
              if (ItemIndex > PLXItems)
-
 
236
                {
-
 
237
                  dial_pos[0] = PLXItems;
-
 
238
                  ItemIndex = PLXItems;
-
 
239
                }
338
        }
240
 
339
 
241
              int DataVal;
340
        int PLXPtr = 0;
242
              // process min/max
-
 
243
              for (i = 0; i < PLXItems; i++)
-
 
244
                {
-
 
245
                  DataVal = ConvPLX (Data.Sensor[i].ObsH, Data.Sensor[i].ObsL);
-
 
246
                  if (DataVal > Max[i])
-
 
247
                    {
-
 
248
                      Max[i] = DataVal;
-
 
249
                    }
-
 
250
                  if (DataVal < Min[i])
-
 
251
                    {
-
 
252
                      Min[i] = DataVal;
-
 
253
                    }
-
 
254
                }
-
 
255
 
341
 
256
              DataVal = ConvPLX (Data.Sensor[ItemIndex].ObsH,
-
 
257
                                 Data.Sensor[ItemIndex].ObsL);   // data reading
-
 
258
              int Observation = ConvPLX (Data.Sensor[ItemIndex].ObsH,
-
 
259
                                         Data.Sensor[ItemIndex].ObsL);
-
 
260
              int ObservationIndex = ConvPLX (0,
-
 
261
                                              Data.Sensor[ItemIndex].ObsIndex);
-
 
262
              // now to convert the readings and format strings
-
 
263
              // find out limits
342
        while (1)
-
 
343
        {
264
              char * msg;
344
// poll switches
265
              int len;
345
                HandleSwitches();
266
 
346
 
-
 
347
                uint16_t cc = SerialCharsReceived(&uc1);
-
 
348
                int chr;
267
              if (Observation < PLX_MAX_OBS)
349
                for (chr = 0; chr < cc; chr++)
268
                {
350
                {
269
                  if (Observation != OldObservation
-
 
270
                      || ObservationIndex != OldObservationIndex)
-
 
271
                    {
-
 
272
                      dial1 = -1;
-
 
273
                      clearDisplay();
351
                        char c = GetCharSerial(&uc1);
274
 
-
 
275
                      dial_draw_scale (
-
 
276
                          DisplayInfo[Observation].Low
-
 
277
                              / DisplayInfo[Observation].TickScale,
-
 
278
                          DisplayInfo[Observation].High
-
 
279
                              / DisplayInfo[Observation].TickScale,
352
                        if (c == PLX_Start) // at any time if the start byte appears, reset the pointers
280
                          16, 1);
-
 
281
                      if (ObservationIndex > 0)
-
 
282
                        {
353
                        {
283
                          len = 5;
354
                                PLXPtr = 0;    // reset the pointer
284
                          buff[6] = ObservationIndex + '1';
355
                                PLXPacket = 1;
285
                        }
356
                        }
286
                      else
357
                        else if (c == PLX_Stop)
287
                        {
358
                        {
-
 
359
                                if (PLXPacket)
-
 
360
                                {
-
 
361
                                        // we can now decode the selected parameter
-
 
362
                                        PLXItems = PLXPtr / sizeof(PLX_SensorInfo); // total
-
 
363
                                        // saturate the rotary switch position
-
 
364
 
-
 
365
                                        int DataVal;
-
 
366
                                        // process min/max
-
 
367
                                        for (i = 0; i < PLXItems; i++)
-
 
368
                                        {
-
 
369
                                                DataVal = ConvPLX(Data.Sensor[i].ReadingH,
-
 
370
                                                                Data.Sensor[i].ReadingL);
-
 
371
                                                if (DataVal > Max[i])
-
 
372
                                                {
-
 
373
                                                        Max[i] = DataVal;
-
 
374
                                                }
-
 
375
                                                if (DataVal < Min[i])
-
 
376
                                                {
-
 
377
                                                        Min[i] = DataVal;
-
 
378
                                                }
-
 
379
                                        }
-
 
380
 
-
 
381
                                        // now to display the information
-
 
382
                                        int suppress = DisplayCurrent(0,-1);
-
 
383
                                        DisplayCurrent(1,suppress);
-
 
384
                                }
288
                          len = 6;
385
                                PLXPtr = 0;
-
 
386
                                PLXPacket = 0;
289
                        }
387
                        }
-
 
388
                        else if (c > PLX_Stop) // illegal char, restart reading
290
                        {
389
                        {
291
                          msg = DisplayInfo[Observation].name;
390
                                PLXPacket = 0;
-
 
391
                                PLXPtr = 0;
292
                        }
392
                        }
293
                      for (i = 0; i < len; i++)
393
                        else if (PLXPtr < sizeof(Data.Bytes))
294
                        {
394
                        {
295
                          buff[i] = msg[i];
395
                                Data.Bytes[PLXPtr++] = c;
296
                        }
396
                        }
297
                      print_large_string (buff, 32, 48, 6); // this prints spaces for \0 at end of string
-
 
298
 
-
 
299
                      OldObservation = Observation;
-
 
300
                      OldObservationIndex = ObservationIndex;
-
 
301
                      //
-
 
302
                    }
-
 
303
 
-
 
304
                  double max_rdg;
-
 
305
                  double min_rdg;
-
 
306
                  double cur_rdg;
-
 
307
 
-
 
308
                  max_rdg = ConveriMFDRaw2Data (Observation,
-
 
309
                                                DisplayInfo[Observation].Units,
-
 
310
                                                Max[ItemIndex]);
-
 
311
                  min_rdg = ConveriMFDRaw2Data (Observation,
-
 
312
                                                DisplayInfo[Observation].Units,
-
 
313
                                                Min[ItemIndex]);
-
 
314
                  cur_rdg = ConveriMFDRaw2Data (Observation,
-
 
315
                                                DisplayInfo[Observation].Units,
-
 
316
                                                DataVal);
-
 
317
                }
397
                }
318
            }
-
 
319
          if (c > PLX_Stop) // illegal char, restart reading
-
 
320
            {
-
 
321
              PLXPacket = 0;
-
 
322
            }
-
 
323
          if (PLXPtr < sizeof(Data.Bytes))
-
 
324
            {
-
 
325
              Data.Bytes[PLXPtr++] = c;
-
 
326
            }
-
 
327
        }
-
 
328
 
398
 
329
      HAL_Delay (1);
399
                HAL_Delay(1);
330
 
-
 
331
      /* now scale and decode the dial position etc .
-
 
332
       *
-
 
333
       */
-
 
334
      uint32_t CurrTicks = HAL_GetTick ();
-
 
335
      if (CurrTicks > Ticks)
-
 
336
        {
-
 
337
          /* Lookup the dial etc . */
-
 
338
 
-
 
339
          Ticks = CurrTicks + 100;
-
 
340
          /* old needle un-draw */
-
 
341
          if (dial1 >= 0)
-
 
342
            {
-
 
343
              dial_draw_needle (dial1);
-
 
344
            }
-
 
345
          dial0 = c % 100;
-
 
346
          dial_draw_needle (dial0);
-
 
347
          // print value overlaid by needle
-
 
348
          // this is actual reading
-
 
349
          print_digits (64 - 16, 30, 4, 3, c);
-
 
350
 
-
 
351
          dial1 = dial0;
-
 
352
 
-
 
353
          c++;
-
 
354
          //font_gotoxy(0, 2);
-
 
355
          //font_puts("baud\r\n");
-
 
356
          //char buff[10];
-
 
357
          //itoa(hirda3.Init.BaudRate, buff, 10);
-
 
358
          //char l = 6 - strlen(buff);
-
 
359
          /* pad with leading spaces */
-
 
360
          //while (l > 0) {
-
 
361
          //    font_putchar(' ');
-
 
362
          //    l--;
-
 
363
          //}
-
 
364
          //font_puts(itoa(hirda3.Init.BaudRate, buff, 10));
-
 
365
          display ();
-
 
366
        }
400
        }
367
      /* USER CODE END WHILE */
401
        /* USER CODE END WHILE */
368
 
-
 
369
      /* USER CODE BEGIN 3 */
-
 
370
 
402
 
371
    }
-
 
372
  /* USER CODE END 3 */
403
        /* USER CODE BEGIN 3 */
373
 
404
 
374
}
405
}
-
 
406
/* USER CODE END 3 */
375
 
407
 
376
/** System Clock Configuration
408
/** System Clock Configuration
377
 */
409
 */
378
void
-
 
379
SystemClock_Config (void)
410
void SystemClock_Config(void)
380
{
411
{
381
 
412
 
382
  RCC_OscInitTypeDef RCC_OscInitStruct;
413
RCC_OscInitTypeDef RCC_OscInitStruct;
383
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
414
RCC_ClkInitTypeDef RCC_ClkInitStruct;
384
  RCC_PeriphCLKInitTypeDef PeriphClkInit;
-
 
385
 
-
 
386
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
-
 
387
  RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
-
 
388
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
-
 
389
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
-
 
390
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
-
 
391
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
-
 
392
  if (HAL_RCC_OscConfig (&RCC_OscInitStruct) != HAL_OK)
-
 
393
    {
-
 
394
      Error_Handler ();
-
 
395
    }
-
 
396
 
-
 
397
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
-
 
398
      | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
-
 
399
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
-
 
400
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
-
 
401
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
-
 
402
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
-
 
403
  if (HAL_RCC_ClockConfig (&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
-
 
404
    {
-
 
405
      Error_Handler ();
-
 
406
    }
-
 
407
 
-
 
408
  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
-
 
409
  PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6;
-
 
410
  if (HAL_RCCEx_PeriphCLKConfig (&PeriphClkInit) != HAL_OK)
-
 
411
    {
-
 
412
      Error_Handler ();
-
 
413
    }
-
 
414
 
-
 
415
  HAL_SYSTICK_Config (HAL_RCC_GetHCLKFreq () / 1000);
-
 
416
 
-
 
417
  HAL_SYSTICK_CLKSourceConfig (SYSTICK_CLKSOURCE_HCLK);
-
 
418
 
415
 
-
 
416
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
-
 
417
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
-
 
418
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
419
  /* SysTick_IRQn interrupt configuration */
419
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
-
 
420
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
-
 
421
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
420
  HAL_NVIC_SetPriority (SysTick_IRQn, 0, 0);
422
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
-
 
423
{
-
 
424
        Error_Handler();
421
}
425
}
422
 
426
 
-
 
427
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
-
 
428
                | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
-
 
429
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
423
/* ADC1 init function */
430
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
424
static void
431
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
425
MX_ADC1_Init (void)
432
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
-
 
433
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
426
{
434
{
-
 
435
        Error_Handler();
-
 
436
}
427
 
437
 
428
  ADC_ChannelConfTypeDef sConfig;
438
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000);
429
 
439
 
430
  /**Common config
-
 
431
   */
-
 
432
  hadc1.Instance = ADC1;
-
 
433
  hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
-
 
434
  hadc1.Init.ContinuousConvMode = DISABLE;
-
 
435
  hadc1.Init.DiscontinuousConvMode = DISABLE;
-
 
436
  hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
440
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
437
  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
-
 
438
  hadc1.Init.NbrOfConversion = 1;
-
 
439
  if (HAL_ADC_Init (&hadc1) != HAL_OK)
-
 
440
    {
-
 
441
      Error_Handler ();
-
 
442
    }
-
 
443
 
-
 
444
  /**Configure Regular Channel
-
 
445
   */
-
 
446
  sConfig.Channel = ADC_CHANNEL_0;
-
 
447
  sConfig.Rank = 1;
-
 
448
  sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
-
 
449
  if (HAL_ADC_ConfigChannel (&hadc1, &sConfig) != HAL_OK)
-
 
450
    {
-
 
451
      Error_Handler ();
-
 
452
    }
-
 
453
 
441
 
-
 
442
/* SysTick_IRQn interrupt configuration */
-
 
443
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
454
}
444
}
455
 
445
 
456
/* SPI1 init function */
446
/* SPI1 init function */
457
static void
-
 
458
MX_SPI1_Init (void)
447
static void MX_SPI1_Init(void)
459
{
448
{
460
 
449
 
461
  hspi1.Instance = SPI1;
450
hspi1.Instance = SPI1;
462
  hspi1.Init.Mode = SPI_MODE_MASTER;
451
hspi1.Init.Mode = SPI_MODE_MASTER;
463
  hspi1.Init.Direction = SPI_DIRECTION_1LINE;
452
hspi1.Init.Direction = SPI_DIRECTION_1LINE;
464
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
453
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
465
  hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
454
hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
466
  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
455
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
467
  hspi1.Init.NSS = SPI_NSS_SOFT;
456
hspi1.Init.NSS = SPI_NSS_SOFT;
468
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
457
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
469
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
458
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
470
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
459
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
471
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
460
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
472
  hspi1.Init.CRCPolynomial = 10;
461
hspi1.Init.CRCPolynomial = 10;
473
  if (HAL_SPI_Init (&hspi1) != HAL_OK)
462
if (HAL_SPI_Init(&hspi1) != HAL_OK)
474
    {
463
{
475
      Error_Handler ();
464
        Error_Handler();
476
    }
465
}
477
 
466
 
478
}
467
}
479
 
468
 
480
/* USART1 init function */
469
/* USART1 init function */
481
static void
-
 
482
MX_USART1_UART_Init (void)
470
static void MX_USART1_UART_Init(void)
483
{
471
{
484
 
472
 
485
  huart1.Instance = USART1;
473
huart1.Instance = USART1;
486
  huart1.Init.BaudRate = 115200;
474
huart1.Init.BaudRate = 19200;
487
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
475
huart1.Init.WordLength = UART_WORDLENGTH_8B;
488
  huart1.Init.StopBits = UART_STOPBITS_1;
476
huart1.Init.StopBits = UART_STOPBITS_1;
489
  huart1.Init.Parity = UART_PARITY_NONE;
477
huart1.Init.Parity = UART_PARITY_NONE;
490
  huart1.Init.Mode = UART_MODE_TX_RX;
478
huart1.Init.Mode = UART_MODE_TX_RX;
491
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
479
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
492
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
480
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
493
  if (HAL_UART_Init (&huart1) != HAL_OK)
481
if (HAL_UART_Init(&huart1) != HAL_OK)
494
    {
482
{
495
      Error_Handler ();
483
        Error_Handler();
496
    }
484
}
497
 
485
 
498
}
486
}
499
 
487
 
500
/* USART2 init function */
488
/* USART2 init function */
501
static void
-
 
502
MX_USART2_UART_Init (void)
489
static void MX_USART2_UART_Init(void)
503
{
490
{
504
 
491
 
505
  huart2.Instance = USART2;
492
huart2.Instance = USART2;
506
  huart2.Init.BaudRate = 115200;
493
huart2.Init.BaudRate = 115200;
507
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
494
huart2.Init.WordLength = UART_WORDLENGTH_8B;
508
  huart2.Init.StopBits = UART_STOPBITS_1;
495
huart2.Init.StopBits = UART_STOPBITS_1;
509
  huart2.Init.Parity = UART_PARITY_NONE;
496
huart2.Init.Parity = UART_PARITY_NONE;
510
  huart2.Init.Mode = UART_MODE_TX_RX;
497
huart2.Init.Mode = UART_MODE_TX_RX;
511
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
498
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
512
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
499
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
513
  if (HAL_UART_Init (&huart2) != HAL_OK)
500
if (HAL_UART_Init(&huart2) != HAL_OK)
514
    {
501
{
515
      Error_Handler ();
502
        Error_Handler();
516
    }
503
}
517
 
504
 
518
}
505
}
519
 
506
 
520
/** Configure pins as
507
/** Configure pins as
521
 * Analog
508
 * Analog
522
 * Input
509
 * Input
523
 * Output
510
 * Output
524
 * EVENT_OUT
511
 * EVENT_OUT
525
 * EXTI
512
 * EXTI
526
 */
513
 */
527
static void
-
 
528
MX_GPIO_Init (void)
514
static void MX_GPIO_Init(void)
529
{
515
{
530
 
516
 
531
  GPIO_InitTypeDef GPIO_InitStruct;
517
GPIO_InitTypeDef GPIO_InitStruct;
532
 
518
 
533
  /* GPIO Ports Clock Enable */
519
/* GPIO Ports Clock Enable */
534
  __HAL_RCC_GPIOD_CLK_ENABLE()
520
__HAL_RCC_GPIOD_CLK_ENABLE()
535
  ;
521
;
536
  __HAL_RCC_GPIOA_CLK_ENABLE()
522
__HAL_RCC_GPIOA_CLK_ENABLE()
537
  ;
523
;
538
  __HAL_RCC_GPIOC_CLK_ENABLE()
524
__HAL_RCC_GPIOC_CLK_ENABLE()
539
  ;
525
;
540
  __HAL_RCC_GPIOB_CLK_ENABLE()
526
__HAL_RCC_GPIOB_CLK_ENABLE()
541
  ;
527
;
542
 
528
 
543
  /*Configure GPIO pin Output Level */
529
/*Configure GPIO pin Output Level */
544
  HAL_GPIO_WritePin (SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET);
530
HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET);
545
 
531
 
546
  /*Configure GPIO pin Output Level */
532
/*Configure GPIO pin Output Level */
547
  HAL_GPIO_WritePin (SPI1CD_GPIO_Port, SPI1CD_Pin, GPIO_PIN_RESET);
533
HAL_GPIO_WritePin(SPI1CD_GPIO_Port, SPI1CD_Pin, GPIO_PIN_RESET);
548
 
534
 
549
  /*Configure GPIO pin Output Level */
535
/*Configure GPIO pin Output Level */
550
  HAL_GPIO_WritePin (GPIOC, SPI_RESET_Pin | USART3_INVERT_Pin | USB_PWR_Pin,
536
HAL_GPIO_WritePin(GPIOC,
551
                     GPIO_PIN_RESET);
537
SPI_RESET_Pin | USART3_INVERT_Pin | USB_PWR_Pin, GPIO_PIN_RESET);
552
 
538
 
553
  /*Configure GPIO pin Output Level */
539
/*Configure GPIO pin Output Level */
554
  HAL_GPIO_WritePin (SPI_NSS2_GPIO_Port, SPI_NSS2_Pin, GPIO_PIN_SET);
540
HAL_GPIO_WritePin(SPI_NSS2_GPIO_Port, SPI_NSS2_Pin, GPIO_PIN_SET);
555
 
541
 
556
  /*Configure GPIO pins : SPI_NSS1_Pin SPI1CD_Pin */
542
/*Configure GPIO pins : SPI_NSS1_Pin SPI1CD_Pin */
557
  GPIO_InitStruct.Pin = SPI_NSS1_Pin | SPI1CD_Pin;
543
GPIO_InitStruct.Pin = SPI_NSS1_Pin | SPI1CD_Pin;
558
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
544
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
559
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
545
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
560
  HAL_GPIO_Init (GPIOA, &GPIO_InitStruct);
546
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
561
 
547
 
562
  /*Configure GPIO pins : SPI_RESET_Pin SPI_NSS2_Pin USART3_INVERT_Pin USB_PWR_Pin */
548
/*Configure GPIO pins : SPI_RESET_Pin SPI_NSS2_Pin USART3_INVERT_Pin USB_PWR_Pin */
563
  GPIO_InitStruct.Pin = SPI_RESET_Pin | SPI_NSS2_Pin | USART3_INVERT_Pin
549
GPIO_InitStruct.Pin = SPI_RESET_Pin | SPI_NSS2_Pin | USART3_INVERT_Pin
564
      | USB_PWR_Pin;
550
                | USB_PWR_Pin;
565
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
551
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
566
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
552
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
567
  HAL_GPIO_Init (GPIOC, &GPIO_InitStruct);
553
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
568
 
554
 
569
  /*Configure GPIO pins : SW1_PUSH_Pin SW1_I_Pin SW1_Q_Pin SW2_PUSH_Pin */
555
/*Configure GPIO pins : SW1_PUSH_Pin SW1_I_Pin SW1_Q_Pin SW2_PUSH_Pin */
570
  GPIO_InitStruct.Pin = SW1_PUSH_Pin | SW1_I_Pin | SW1_Q_Pin | SW2_PUSH_Pin;
556
GPIO_InitStruct.Pin = SW1_PUSH_Pin | SW1_I_Pin | SW1_Q_Pin | SW2_PUSH_Pin;
571
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
557
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
572
  GPIO_InitStruct.Pull = GPIO_PULLUP;
558
GPIO_InitStruct.Pull = GPIO_PULLUP;
573
  HAL_GPIO_Init (GPIOB, &GPIO_InitStruct);
559
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
574
 
560
 
575
  /*Configure GPIO pins : SW2_I_Pin SW2_Q_Pin */
561
/*Configure GPIO pins : SW2_I_Pin SW2_Q_Pin */
576
  GPIO_InitStruct.Pin = SW2_I_Pin | SW2_Q_Pin;
562
GPIO_InitStruct.Pin = SW2_I_Pin | SW2_Q_Pin;
577
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
563
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
578
  GPIO_InitStruct.Pull = GPIO_PULLUP;
564
GPIO_InitStruct.Pull = GPIO_PULLUP;
579
  HAL_GPIO_Init (GPIOC, &GPIO_InitStruct);
565
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
580
 
566
 
581
}
567
}
582
 
568
 
583
/* USER CODE BEGIN 4 */
569
/* USER CODE BEGIN 4 */
584
 
570
 
Line 587... Line 573...
587
/**
573
/**
588
 * @brief  This function is executed in case of error occurrence.
574
 * @brief  This function is executed in case of error occurrence.
589
 * @param  None
575
 * @param  None
590
 * @retval None
576
 * @retval None
591
 */
577
 */
592
void
-
 
593
Error_Handler (void)
578
void Error_Handler(void)
594
{
579
{
595
  /* USER CODE BEGIN Error_Handler */
580
/* USER CODE BEGIN Error_Handler */
596
  /* User can add his own implementation to report the HAL error return state */
581
/* User can add his own implementation to report the HAL error return state */
597
  while (1)
582
while (1)
598
    {
583
{
599
    }
584
}
600
  /* USER CODE END Error_Handler */
585
/* USER CODE END Error_Handler */
601
}
586
}
602
 
587
 
603
#ifdef USE_FULL_ASSERT
588
#ifdef USE_FULL_ASSERT
604
 
589
 
605
/**
590
/**
Line 608... Line 593...
608
 * @param file: pointer to the source file name
593
 * @param file: pointer to the source file name
609
 * @param line: assert_param error line source number
594
 * @param line: assert_param error line source number
610
 * @retval None
595
 * @retval None
611
 */
596
 */
612
void assert_failed(uint8_t* file, uint32_t line)
597
void assert_failed(uint8_t* file, uint32_t line)
613
  {
598
{
614
    /* USER CODE BEGIN 6 */
599
/* USER CODE BEGIN 6 */
615
    /* User can add his own implementation to report the file name and line number,
600
/* User can add his own implementation to report the file name and line number,
616
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
601
 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
617
    /* USER CODE END 6 */
602
/* USER CODE END 6 */
618
 
603
 
619
  }
604
}
620
 
605
 
621
#endif
606
#endif
622
 
607
 
623
/**
608
/**
624
 * @}
609
 * @}