Subversion Repositories DashDisplay

Rev

Rev 24 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 24 Rev 27
Line 1... Line 1...
1
/**
1
/**
2
  ******************************************************************************
2
 ******************************************************************************
3
  * File Name          : main.c
3
 * File Name          : main.c
4
  * Description        : Main program body
4
 * Description        : Main program body
5
  ******************************************************************************
5
 ******************************************************************************
6
  *
6
 *
7
  * COPYRIGHT(c) 2017 STMicroelectronics
7
 * COPYRIGHT(c) 2017 STMicroelectronics
8
  *
8
 *
9
  * Redistribution and use in source and binary forms, with or without modification,
9
 * Redistribution and use in source and binary forms, with or without modification,
10
  * are permitted provided that the following conditions are met:
10
 * are permitted provided that the following conditions are met:
11
  *   1. Redistributions of source code must retain the above copyright notice,
11
 *   1. Redistributions of source code must retain the above copyright notice,
12
  *      this list of conditions and the following disclaimer.
12
 *      this list of conditions and the following disclaimer.
13
  *   2. Redistributions in binary form must reproduce the above copyright notice,
13
 *   2. Redistributions in binary form must reproduce the above copyright notice,
14
  *      this list of conditions and the following disclaimer in the documentation
14
 *      this list of conditions and the following disclaimer in the documentation
15
  *      and/or other materials provided with the distribution.
15
 *      and/or other materials provided with the distribution.
16
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
16
 *   3. Neither the name of STMicroelectronics nor the names of its contributors
17
  *      may be used to endorse or promote products derived from this software
17
 *      may be used to endorse or promote products derived from this software
18
  *      without specific prior written permission.
18
 *      without specific prior written permission.
19
  *
19
 *
20
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
  *
30
 *
31
  ******************************************************************************
31
 ******************************************************************************
32
  */
32
 */
33
/* Includes ------------------------------------------------------------------*/
33
/* Includes ------------------------------------------------------------------*/
34
#include "stm32f1xx_hal.h"
34
#include "stm32f1xx_hal.h"
35
 
35
 
36
/* USER CODE BEGIN Includes */
36
/* USER CODE BEGIN Includes */
37
#include "ap_math.h"
37
#include "ap_math.h"
Line 42... Line 42...
42
#include "switches.h"
42
#include "switches.h"
43
#include <math.h>
43
#include <math.h>
44
#include "plx.h"
44
#include "plx.h"
45
#include "eeprom.h"
45
#include "eeprom.h"
46
#include "displayinfo.h"
46
#include "displayinfo.h"
-
 
47
#include "small_printf.h"
47
 
48
 
48
/* USER CODE END Includes */
49
/* USER CODE END Includes */
49
 
50
 
50
/* Private variables ---------------------------------------------------------*/
51
/* Private variables ---------------------------------------------------------*/
51
SPI_HandleTypeDef hspi1;
52
SPI_HandleTypeDef hspi1;
Line 60... Line 61...
60
 
61
 
61
/* timeout when the ignition is switched off */
62
/* timeout when the ignition is switched off */
62
#define IGNITION_OFF_TIMEOUT 30000UL
63
#define IGNITION_OFF_TIMEOUT 30000UL
63
 
64
 
64
int OldObservation[2] =
65
int OldObservation[2] =
65
{ -1, -1 }; // illegal initial value
66
  { -1, -1 }; // illegal initial value
66
int OldObservationIndex[2] =
67
int OldObservationIndex[2] =
67
{ -1, -1 }; // if more than one sensor this will be printed
68
  { -1, -1 }; // if more than one sensor this will be printed
68
int16_t dial0[2] =
69
int16_t dial0[2] =
69
{ 0, 0 };
70
  { 0, 0 };
70
int16_t dial1[2] =
71
int16_t dial1[2] =
71
{ -1, -1 };
72
  { -1, -1 };
72
 
73
 
73
uint16_t dial_timer[2] =
74
uint16_t dial_timer[2] =
74
{ 0, 0 };
75
  { 0, 0 };
75
 
76
 
76
static const int DialTimeout = 50; // about 20 seconds after twiddle, save the dial position.
77
static const int DialTimeout = 50; // about 20 seconds after twiddle, save the dial position.
77
 
78
 
78
/* Virtual address defined by the user: 0xFFFF value is prohibited */
79
/* Virtual address defined by the user: 0xFFFF value is prohibited */
79
uint16_t VirtAddVarTab[NumbOfVar] = {0x1111,0x2222 }  ;
80
uint16_t VirtAddVarTab[NumbOfVar] =
-
 
81
  { 0x1111, 0x2222 };
80
 
82
 
81
union
83
union
82
{
84
{
83
        PLX_SensorInfo Sensor[MAXRDG];
85
  PLX_SensorInfo Sensor[MAXRDG];
84
        char Bytes[MAXRDG * sizeof(PLX_SensorInfo)];
86
  char Bytes[MAXRDG * sizeof(PLX_SensorInfo)];
85
} Data;
87
} Data;
86
int Max[MAXRDG];
88
int Max[MAXRDG];
87
int Min[MAXRDG];
89
int Min[MAXRDG];
88
int PLXItems;
90
int PLXItems;
89
 
91
 
90
uint32_t  Latch_Timer = IGNITION_OFF_TIMEOUT;
92
uint32_t Latch_Timer = IGNITION_OFF_TIMEOUT;
91
 
-
 
92
 
93
 
93
/* USER CODE END PV */
94
/* USER CODE END PV */
94
 
95
 
95
/* Private function prototypes -----------------------------------------------*/
96
/* Private function prototypes -----------------------------------------------*/
-
 
97
void
96
void SystemClock_Config(void);
98
SystemClock_Config (void);
-
 
99
void
97
void Error_Handler(void);
100
Error_Handler (void);
-
 
101
static void
98
static void MX_GPIO_Init(void);
102
MX_GPIO_Init (void);
-
 
103
static void
99
static void MX_SPI1_Init(void);
104
MX_SPI1_Init (void);
-
 
105
static void
100
static void MX_USART2_UART_Init(void);
106
MX_USART2_UART_Init (void);
-
 
107
static void
101
static void MX_USART1_UART_Init(void);
108
MX_USART1_UART_Init (void);
-
 
109
static void
102
static void MX_USART3_UART_Init(void);
110
MX_USART3_UART_Init (void);
103
 
111
 
104
/* USER CODE BEGIN PFP */
112
/* USER CODE BEGIN PFP */
105
/* Private function prototypes -----------------------------------------------*/
113
/* Private function prototypes -----------------------------------------------*/
106
 
114
 
107
/* USER CODE END PFP */
115
/* USER CODE END PFP */
108
 
116
 
109
/* USER CODE BEGIN 0 */
117
/* USER CODE BEGIN 0 */
110
/* dummy function */
118
/* dummy function */
-
 
119
void
111
void _init(void)
120
_init (void)
112
{
121
{
113
 
122
 
114
}
123
}
115
// the dial is the switch number we are using.
124
// the dial is the switch number we are using.
116
// suppress is the ItemIndex we wish to suppress on this display
125
// suppress is the ItemIndex we wish to suppress on this display
-
 
126
int
117
int  DisplayCurrent(int dial,int suppress)
127
DisplayCurrent (int dial, int suppress)
118
{
128
{
119
        char buff[10];
129
  char buff[10];
120
        int i;
130
  int i;
121
        int rc;
131
  int rc;
122
        select_display(dial); // pick the display we are using
132
  select_display (dial); // pick the display we are using
123
        int ItemIndex = dial_pos[dial]/4;
133
  int ItemIndex = dial_pos[dial] / 4;
-
 
134
 
-
 
135
  // wrap around count if dial too far to the right
-
 
136
  if (ItemIndex >= PLXItems)
-
 
137
    {
-
 
138
      dial_pos[dial] = 0;
-
 
139
      ItemIndex = 0;
-
 
140
    }
-
 
141
  if (ItemIndex < 0)
-
 
142
    {
-
 
143
      ItemIndex = PLXItems - 1;
-
 
144
      dial_pos[dial] = (PLXItems - 1) * 4;
-
 
145
    }
-
 
146
 
-
 
147
  // check for item suppression
-
 
148
  if (ItemIndex == suppress)
-
 
149
    {
-
 
150
      dial1[dial] = -1;
-
 
151
      OldObservation[dial] = -1;
-
 
152
      OldObservationIndex[dial] = -1;
-
 
153
 
-
 
154
      clearDisplay ();
-
 
155
      display ();
-
 
156
      return -1; // we suppressed this display
-
 
157
    }
-
 
158
  // do not try to convert if no items in buffer
-
 
159
  if (PLXItems > 0)
-
 
160
    {
-
 
161
      int DataVal = ConvPLX (Data.Sensor[ItemIndex].ReadingH,
-
 
162
                             Data.Sensor[ItemIndex].ReadingL); // data reading
-
 
163
      int Observation = ConvPLX (Data.Sensor[ItemIndex].AddrH,
-
 
164
                                 Data.Sensor[ItemIndex].AddrL);
-
 
165
      int ObservationIndex = ConvPLX (0, Data.Sensor[ItemIndex].Instance);
-
 
166
      // now to convert the readings and format strings
-
 
167
      // find out limits
-
 
168
      char * msg;
-
 
169
      int len;
124
 
170
 
125
        // wrap around count if dial too far to the right
171
      // if the user presses the dial then reset min/max to current value
126
        if (ItemIndex >= PLXItems)
-
 
127
        {
-
 
128
                dial_pos[dial] = 0;
172
      if (push_pos[dial] == 1)
129
                ItemIndex = 0;
-
 
130
        }
-
 
131
        if (ItemIndex < 0)
-
 
132
        {
173
        {
133
                ItemIndex = PLXItems-1;
174
          Max[ItemIndex] = DataVal;
134
                dial_pos[dial] = (PLXItems-1)*4;
175
          Min[ItemIndex] = DataVal; // 12 bit max value
135
        }
176
        }
136
 
177
 
137
 
-
 
138
 
-
 
139
        // check for item suppression
-
 
140
        if(ItemIndex == suppress)
178
      if (Observation < PLX_MAX_OBS)
141
        {
179
        {
142
                dial1[dial] = -1;
-
 
143
                OldObservation[dial] = -1;
180
          if (Observation != OldObservation[dial]
144
                OldObservationIndex[dial] = -1;
181
              || ObservationIndex != OldObservationIndex[dial])
-
 
182
            {
145
 
183
 
146
                clearDisplay();
-
 
147
                display();
-
 
148
                return -1; // we suppressed this display
184
              dial_timer[dial] = DialTimeout;
149
        }
185
 
150
        // do not try to convert if no items in buffer
186
              dial1[dial] = -1;
151
        if (PLXItems > 0)
187
              clearDisplay ();
152
        {
-
 
153
                int DataVal = ConvPLX(Data.Sensor[ItemIndex].ReadingH,
188
              dial_draw_scale (DisplayInfo[Observation].Low,
154
                                Data.Sensor[ItemIndex].ReadingL); // data reading
189
                               DisplayInfo[Observation].High, 12, 1,
155
                int Observation = ConvPLX(Data.Sensor[ItemIndex].AddrH,
-
 
156
                                Data.Sensor[ItemIndex].AddrL);
190
                               DisplayInfo[Observation].TickScale);
157
                int ObservationIndex = ConvPLX(0, Data.Sensor[ItemIndex].Instance);
-
 
-
 
191
 
158
                // now to convert the readings and format strings
192
              msg = DisplayInfo[Observation].name;
159
                // find out limits
-
 
160
                char * msg;
-
 
161
                int len;
193
              len = 7;
162
 
-
 
163
                // if the user presses the dial then reset min/max to current value
194
              int len1 = ObservationIndex > 0 ? len - 1 : len;
164
                if(push_pos[dial] == 1)
195
              for (i = 0; i < len1 && msg[i]; i++)
165
                {
196
                {
166
                                Max[ItemIndex] = DataVal;
197
                  buff[i] = msg[i];
-
 
198
                }
167
                                Min[ItemIndex] = DataVal; // 12 bit max value
199
              if (ObservationIndex > 0 && i < len)
-
 
200
                {
-
 
201
                  buff[i++] = ObservationIndex + '1';
168
                }
202
                }
169
 
203
 
-
 
204
              print_large_string (buff, 64 - i * 4, 48, i); // this prints spaces for \0 at end of string
170
 
205
 
171
 
-
 
-
 
206
              // print suffix if present.
-
 
207
              font_gotoxy (15, 4);
-
 
208
              int i = 0;
172
                if (Observation < PLX_MAX_OBS)
209
              while (DisplayInfo[Observation].suffix[i])
173
                {
210
                {
174
                        if (Observation != OldObservation[dial]
-
 
175
                                        || ObservationIndex != OldObservationIndex[dial])
211
                  font_putchar (DisplayInfo[Observation].suffix[i++]);
176
                        {
212
                }
177
 
213
 
178
                dial_timer[dial] = DialTimeout;
214
              OldObservation[dial] = Observation;
-
 
215
              OldObservationIndex[dial] = ObservationIndex;
-
 
216
              //
-
 
217
              display ();
179
 
218
 
180
                                dial1[dial] = -1;
-
 
181
                                clearDisplay();
-
 
182
                                dial_draw_scale(
-
 
183
                                                DisplayInfo[Observation].Low,
-
 
184
                                                DisplayInfo[Observation].High,
-
 
185
                                            12, 1,DisplayInfo[Observation].TickScale);
-
 
186
 
-
 
187
                                msg = DisplayInfo[Observation].name;
-
 
188
                                len = 7;
-
 
189
                                int len1  = ObservationIndex > 0 ? len-1: len;
-
 
190
                                for (i = 0; i < len1 && msg[i]; i++)
-
 
191
                                {
219
            }
192
                                        buff[i] = msg[i];
-
 
193
                                }
220
          else
194
                                if (ObservationIndex > 0 && i<len)
-
 
195
                                {
221
            {
196
                                        buff[i++] = ObservationIndex + '1';
222
              // check for timer timeout on consistent timer
197
                                }
-
 
198
 
-
 
199
                                print_large_string(buff, 64-i*4, 48, i); // this prints spaces for \0 at end of string
-
 
200
 
-
 
201
                                // print suffix if present.
223
              if (dial_timer[dial])
202
                                font_gotoxy(15,4);
-
 
203
                                int i=0;
-
 
204
                                while(DisplayInfo[Observation].suffix[i])
-
 
205
                                {
224
                {
206
                                        font_putchar(DisplayInfo[Observation].suffix[i++]);
-
 
207
                                }
-
 
208
 
-
 
209
                                OldObservation[dial] = Observation;
-
 
210
                                OldObservationIndex[dial] = ObservationIndex;
-
 
211
                                //
-
 
212
                                display();
225
                  dial_timer[dial]--;
213
 
226
 
214
                        }
227
                  if (dial_timer[dial] == 0)
215
                        else
228
                    {
-
 
229
                      uint16_t curr_val = dial_pos[dial];
-
 
230
                      rc = EE_ReadVariable (VirtAddVarTab[dial], &curr_val);
-
 
231
                      if ((rc != 0) || (curr_val != dial_pos[dial]))
216
                        {
232
                        {
217
                                // check for timer timeout on consistent timer
-
 
218
                                if(dial_timer[dial])
-
 
219
                                {
-
 
220
                                        dial_timer[dial]--;
-
 
221
 
-
 
222
                                        if(dial_timer[dial]==0  )
-
 
223
                                        {
-
 
224
                                                uint16_t curr_val = dial_pos[dial];
-
 
225
                                                rc = EE_ReadVariable(VirtAddVarTab[dial],&curr_val);
-
 
226
                                                if((rc !=0) || (curr_val != dial_pos[dial]))
-
 
227
                                                {
-
 
228
                                                        //__disable_irq();
233
                          //__disable_irq();
229
                                                        HAL_FLASH_Unlock();
234
                          HAL_FLASH_Unlock ();
230
 
-
 
231
                                                        rc = EE_WriteVariable(VirtAddVarTab[dial],dial_pos[dial]);
-
 
232
                                                        HAL_FLASH_Lock();
-
 
233
                                                        //__enable_irq();
-
 
234
                                                }
-
 
235
                                        }
-
 
236
                                }
-
 
237
 
235
 
-
 
236
                          rc = EE_WriteVariable (VirtAddVarTab[dial],
-
 
237
                                                 dial_pos[dial]);
-
 
238
                          HAL_FLASH_Lock ();
-
 
239
                          //__enable_irq();
238
                        }
240
                        }
-
 
241
                    }
-
 
242
                }
239
 
243
 
240
                        double max_rdg;
-
 
241
                        double min_rdg;
-
 
242
                        double cur_rdg;
-
 
243
                        int int_rdg;
-
 
244
                        int int_max;
-
 
245
                        int int_min;
-
 
246
 
-
 
247
                        max_rdg = ConveriMFDRaw2Data(Observation,
-
 
248
                                        DisplayInfo[Observation].Units, Max[ItemIndex]);
-
 
249
                        min_rdg = ConveriMFDRaw2Data(Observation,
-
 
250
                                        DisplayInfo[Observation].Units, Min[ItemIndex]);
-
 
251
                        cur_rdg = ConveriMFDRaw2Data(Observation,
-
 
252
                                        DisplayInfo[Observation].Units, DataVal);
-
 
253
 
-
 
254
                        int dp_pos;  // where to print the decimal place
-
 
255
                        float scale = 1.0;
-
 
256
                        switch (DisplayInfo[Observation].DP)
-
 
257
                        {
-
 
258
                        case 0:
-
 
259
                                scale = 1.0;
-
 
260
                                dp_pos = 100;
-
 
261
                                break;
-
 
262
                        case 1:
-
 
263
                                scale = 10.0;
-
 
264
                                dp_pos = 1;
-
 
265
                                break;
-
 
266
                        case 2:
-
 
267
                                scale = 100.0;
-
 
268
                                dp_pos = 2;
-
 
269
                                break;
-
 
270
                        }
244
            }
271
                        int_rdg = (int) (cur_rdg * scale);
-
 
272
                        int_max = (int) (max_rdg * scale);
-
 
273
                        int_min = (int) (min_rdg * scale);
-
 
274
 
-
 
275
                        cur_rdg -= DisplayInfo[Observation].Low;
-
 
276
                        cur_rdg = 100 * cur_rdg
-
 
277
                                        / (DisplayInfo[Observation].High
-
 
278
                                                        - DisplayInfo[Observation].Low);
-
 
279
 
-
 
280
                        dial0[dial] = (int) cur_rdg  ;
-
 
281
 
245
 
-
 
246
          double max_rdg;
-
 
247
          double min_rdg;
-
 
248
          double cur_rdg;
-
 
249
          int int_rdg;
-
 
250
          int int_max;
-
 
251
          int int_min;
-
 
252
 
-
 
253
          max_rdg = ConveriMFDRaw2Data (Observation,
-
 
254
                                        DisplayInfo[Observation].Units,
-
 
255
                                        Max[ItemIndex]);
-
 
256
          min_rdg = ConveriMFDRaw2Data (Observation,
-
 
257
                                        DisplayInfo[Observation].Units,
-
 
258
                                        Min[ItemIndex]);
-
 
259
          cur_rdg = ConveriMFDRaw2Data (Observation,
-
 
260
                                        DisplayInfo[Observation].Units,
-
 
261
                                        DataVal);
-
 
262
 
-
 
263
          int dp_pos;  // where to print the decimal place
-
 
264
          float scale = 1.0;
-
 
265
          switch (DisplayInfo[Observation].DP)
-
 
266
            {
-
 
267
            case 0:
-
 
268
              scale = 1.0;
-
 
269
              dp_pos = 100;
-
 
270
              break;
-
 
271
            case 1:
-
 
272
              scale = 10.0;
-
 
273
              dp_pos = 1;
-
 
274
              break;
-
 
275
            case 2:
-
 
276
              scale = 100.0;
-
 
277
              dp_pos = 2;
-
 
278
              break;
-
 
279
            }
-
 
280
          int_rdg = (int) (cur_rdg * scale);
-
 
281
          int_max = (int) (max_rdg * scale);
-
 
282
          int_min = (int) (min_rdg * scale);
-
 
283
 
-
 
284
          cur_rdg -= DisplayInfo[Observation].Low;
-
 
285
          cur_rdg = 100 * cur_rdg
-
 
286
              / (DisplayInfo[Observation].High - DisplayInfo[Observation].Low);
-
 
287
 
-
 
288
          dial0[dial] = (int) cur_rdg;
-
 
289
 
282
                        /* old needle un-draw */
290
          /* old needle un-draw */
283
                        if (dial1[dial] >= 0)
291
          if (dial1[dial] >= 0)
284
                        {
292
            {
285
                                dial_draw_needle(dial1[dial]);
293
              dial_draw_needle (dial1[dial]);
286
                        }
294
            }
287
                        dial_draw_needle(dial0[dial]);
295
          dial_draw_needle (dial0[dial]);
288
                        // print value overlaid by needle
296
          // print value overlaid by needle
289
                        // this is actual reading
297
          // this is actual reading
290
                        print_digits(30, 30, 5, dp_pos, int_rdg);
298
          print_digits (30, 30, 5, dp_pos, int_rdg);
291
                        font_gotoxy(0,0);
299
          font_gotoxy (0, 0);
292
                        font_digits(5,dp_pos,int_min);
300
          font_digits (5, dp_pos, int_min);
293
 
301
 
294
                        font_gotoxy(0,1);
302
          font_gotoxy (0, 1);
295
                        font_puts("Min");
303
          font_puts ("Min");
296
 
304
 
297
                        font_gotoxy(15,0);
305
          font_gotoxy (15, 0);
298
                        font_digits(5,dp_pos,int_max);
306
          font_digits (5, dp_pos, int_max);
299
                        font_gotoxy(18,1);
307
          font_gotoxy (18, 1);
300
                        font_puts("Max");
308
          font_puts ("Max");
301
 
309
 
302
                        dial1[dial] = dial0[dial];
310
          dial1[dial] = dial0[dial];
303
 
311
 
304
                        display();
312
          display ();
305
 
313
 
306
                }
-
 
307
        }
314
        }
-
 
315
    }
308
        return ItemIndex;
316
  return ItemIndex;
309
}
317
}
310
/* USER CODE END 0 */
318
/* USER CODE END 0 */
311
 
319
 
-
 
320
int
312
int main(void)
321
main (void)
313
{
322
{
314
 
323
 
315
  /* USER CODE BEGIN 1 */
324
  /* USER CODE BEGIN 1 */
316
 
325
 
317
        GPIO_InitTypeDef GPIO_InitStruct;
326
  GPIO_InitTypeDef GPIO_InitStruct;
318
 
327
 
319
        __HAL_RCC_SPI1_CLK_ENABLE();
328
  __HAL_RCC_SPI1_CLK_ENABLE()
-
 
329
  ;
320
        __HAL_RCC_USART1_CLK_ENABLE(); // PLX main port
330
  __HAL_RCC_USART1_CLK_ENABLE()
-
 
331
  ; // PLX main port
321
        __HAL_RCC_USART2_CLK_ENABLE(); // debug port
332
  __HAL_RCC_USART2_CLK_ENABLE()
-
 
333
  ; // debug port
322
        __HAL_RCC_USART3_CLK_ENABLE(); // Bluetooth port
334
  __HAL_RCC_USART3_CLK_ENABLE (); // Bluetooth port
323
 
335
 
324
  /* USER CODE END 1 */
336
  /* USER CODE END 1 */
325
 
337
 
326
  /* MCU Configuration----------------------------------------------------------*/
338
  /* MCU Configuration----------------------------------------------------------*/
327
 
339
 
328
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
340
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
329
  HAL_Init();
341
  HAL_Init ();
330
 
342
 
331
  /* Configure the system clock */
343
  /* Configure the system clock */
332
  SystemClock_Config();
344
  SystemClock_Config ();
333
 
345
 
334
  /* Initialize all configured peripherals */
346
  /* Initialize all configured peripherals */
335
  MX_GPIO_Init();
347
  MX_GPIO_Init ();
336
  MX_SPI1_Init();
348
  MX_SPI1_Init ();
337
  MX_USART2_UART_Init();
349
  MX_USART2_UART_Init ();
338
  MX_USART1_UART_Init();
350
  MX_USART1_UART_Init ();
339
  MX_USART3_UART_Init();
351
  MX_USART3_UART_Init ();
340
 
352
 
341
  /* USER CODE BEGIN 2 */
353
  /* USER CODE BEGIN 2 */
342
 
354
 
-
 
355
  /* Turn on USART1 IRQ */
-
 
356
  HAL_NVIC_SetPriority (USART1_IRQn, 2, 0);
-
 
357
  HAL_NVIC_EnableIRQ (USART1_IRQn);
343
 
358
 
-
 
359
  /* Turn on USART2 IRQ  */
-
 
360
  HAL_NVIC_SetPriority (USART2_IRQn, 4, 0);
-
 
361
  HAL_NVIC_EnableIRQ (USART2_IRQn);
344
 
362
 
345
        /* Turn on USART1 IRQ */
363
  /* turn on USART3 IRQ */
346
        HAL_NVIC_SetPriority(USART1_IRQn, 2, 0);
-
 
347
        HAL_NVIC_EnableIRQ(USART1_IRQn);
-
 
348
 
-
 
349
    /* Turn on USART2 IRQ  */
-
 
350
        HAL_NVIC_SetPriority(USART2_IRQn, 4, 0);
364
  HAL_NVIC_SetPriority (USART3_IRQn, 4, 0);
351
        HAL_NVIC_EnableIRQ(USART2_IRQn);
365
  HAL_NVIC_EnableIRQ (USART3_IRQn);
352
 
366
 
353
        /* turn on USART3 IRQ */
367
  /* setup the USART control blocks */
354
        HAL_NVIC_SetPriority(USART3_IRQn, 4, 0);
368
  init_usart_ctl (&uc1, huart1.Instance);
-
 
369
  init_usart_ctl (&uc2, huart2.Instance);
355
        HAL_NVIC_EnableIRQ(USART3_IRQn);
370
  init_usart_ctl (&uc3, huart3.Instance);
356
 
371
 
-
 
372
  EnableSerialRxInterrupt (&uc1);
-
 
373
  EnableSerialRxInterrupt (&uc2);
-
 
374
  EnableSerialRxInterrupt (&uc3);
357
 
375
 
-
 
376
  /* Unlock the Flash to enable the flash control register access *************/
-
 
377
  HAL_FLASH_Unlock ();
358
 
378
 
359
        /* setup the USART control blocks */
-
 
360
        init_usart_ctl(&uc1, huart1.Instance);
379
  //__disable_irq();
361
        init_usart_ctl(&uc2, huart2.Instance);
380
  EE_Init ();
362
        init_usart_ctl(&uc3, huart3.Instance);
381
  //__enable_irq();
363
 
382
 
364
        EnableSerialRxInterrupt(&uc1);
-
 
365
        EnableSerialRxInterrupt(&uc2);
-
 
366
        EnableSerialRxInterrupt(&uc3);
383
  HAL_FLASH_Lock ();
367
 
384
 
368
        /* Unlock the Flash to enable the flash control register access *************/
-
 
369
        HAL_FLASH_Unlock();
385
  InitSwitches ();
370
 
386
 
371
        //__disable_irq();
387
  int i;
372
        EE_Init();
388
  uint16_t rc;
-
 
389
  for (i = 0; i < 2; i++)
-
 
390
    {
373
        //__enable_irq();
391
      uint16_t val;
374
 
392
 
375
    HAL_FLASH_Lock();
393
      uint16_t rc = EE_ReadVariable (VirtAddVarTab[i], &val);
376
 
394
 
377
 
-
 
378
        InitSwitches();
-
 
379
 
-
 
380
        int i;
-
 
381
        uint16_t rc;
-
 
382
        for(i=0;i<2;i++)
395
      if (rc == 0)
383
        {
396
        {
384
          uint16_t val;
-
 
385
 
-
 
386
          uint16_t rc =  EE_ReadVariable(VirtAddVarTab[i], &val);
-
 
387
 
-
 
388
          if (rc == 0)
-
 
389
          {
-
 
390
                  dial_pos[i] = val;
397
          dial_pos[i] = val;
391
          }
-
 
392
          else
-
 
393
          {
-
 
394
                  break;
-
 
395
          }
-
 
396
        }
398
        }
-
 
399
      else
-
 
400
        {
-
 
401
          break;
-
 
402
        }
-
 
403
    }
397
 
404
 
-
 
405
  ap_init (); // set up the approximate math library
398
 
406
 
-
 
407
  int disp;
399
 
408
 
400
        ap_init(); // set up the approximate math library
-
 
401
 
-
 
402
        int disp;
-
 
403
 
-
 
404
        ssd1306_begin(1, 0);
409
  ssd1306_begin (1, 0);
405
        dial_origin(64, 60);
410
  dial_origin (64, 60);
406
        dial_size(60);
411
  dial_size (60);
407
 
-
 
408
    /* reset the display timeout, latch on power from accessories */
-
 
409
        Latch_Timer = IGNITION_OFF_TIMEOUT;
-
 
410
        HAL_GPIO_WritePin(POWER_LATCH_GPIO_Port,POWER_LATCH_Pin,GPIO_PIN_RESET);
-
 
411
 
412
 
412
        for (disp = 0; disp < 2; disp++)
-
 
413
        {
-
 
414
                select_display(disp);
-
 
415
                clearDisplay();
-
 
416
                dim(0);
-
 
417
                //font_puts(
-
 
418
                //              "Hello world !!\rThis text is a test of the text rendering library in a 5*7 font");
413
  /* reset the display timeout, latch on power from accessories */
419
 
-
 
420
                dial_draw_scale(0, 10, 12, 5,1);
-
 
421
                char  buffer[] = "Display  ";
414
  Latch_Timer = IGNITION_OFF_TIMEOUT;
422
                buffer[8] = disp+'1';
-
 
423
                print_large_string(buffer, 20,30, 9);
415
  HAL_GPIO_WritePin (POWER_LATCH_GPIO_Port, POWER_LATCH_Pin, GPIO_PIN_RESET);
424
 
416
 
-
 
417
  for (disp = 0; disp < 2; disp++)
-
 
418
    {
-
 
419
      select_display (disp);
425
                display();
420
      clearDisplay ();
-
 
421
      dim (0);
-
 
422
      //font_puts(
-
 
423
      //                "Hello world !!\rThis text is a test of the text rendering library in a 5*7 font");
426
 
424
 
427
        }
-
 
-
 
425
      dial_draw_scale (0, 10, 12, 5, 1);
-
 
426
      char buffer[] = "Display  ";
-
 
427
      buffer[8] = disp + '1';
-
 
428
      print_large_string (buffer, 20, 30, 9);
428
 
429
 
-
 
430
      display ();
429
 
431
 
-
 
432
    }
430
 
433
 
431
  /* USER CODE END 2 */
434
  /* USER CODE END 2 */
432
 
435
 
433
  /* Infinite loop */
436
  /* Infinite loop */
434
  /* USER CODE BEGIN WHILE */
437
  /* USER CODE BEGIN WHILE */
435
        uint32_t Ticks = HAL_GetTick() + 100;
438
  uint32_t Ticks = HAL_GetTick () + 100;
436
 
439
 
437
    /* while ignition is on, keep resetting power latch timer */
440
  /* while ignition is on, keep resetting power latch timer */
438
        if(HAL_GPIO_ReadPin(IGNITION_GPIO_Port,IGNITION_Pin) == GPIO_PIN_RESET)
441
  if (HAL_GPIO_ReadPin (IGNITION_GPIO_Port, IGNITION_Pin) == GPIO_PIN_RESET)
439
        {
442
    {
440
                Latch_Timer = HAL_GetTick() + IGNITION_OFF_TIMEOUT;
443
      Latch_Timer = HAL_GetTick () + IGNITION_OFF_TIMEOUT;
441
        }
444
    }
442
        else
445
  else
-
 
446
    {
-
 
447
      /* if the ignition has been off for a while, then turn off power */
-
 
448
      if (HAL_GetTick () > Latch_Timer)
443
        {
449
        {
444
                /* if the ignition has been off for a while, then turn off power */
-
 
445
                if(HAL_GetTick() > Latch_Timer )
-
 
446
                {
-
 
447
                        HAL_GPIO_WritePin(POWER_LATCH_GPIO_Port,POWER_LATCH_Pin,GPIO_PIN_RESET);
450
          HAL_GPIO_WritePin (POWER_LATCH_GPIO_Port, POWER_LATCH_Pin,
448
                }
451
                             GPIO_PIN_RESET);
449
        }
452
        }
-
 
453
    }
450
 
454
 
451
    uint32_t timeout = 0;  //
455
  uint32_t timeout = 0;  //
452
        // PLX decoder protocols
456
  // PLX decoder protocols
453
        char PLXPacket = 0;
457
  char PLXPacket = 0;
454
        for (i = 0; i < MAXRDG; i++)
458
  for (i = 0; i < MAXRDG; i++)
455
        {
459
    {
456
                Max[i] = 0;
460
      Max[i] = 0;
457
                Min[i] = 0xFFF; // 12 bit max value
461
      Min[i] = 0xFFF; // 12 bit max value
458
        }
462
    }
459
 
463
 
460
        int PLXPtr = 0;
464
  int PLXPtr = 0;
461
 
465
 
462
        while (1)
466
  while (1)
463
        {
467
    {
464
// poll switche
468
// poll switche
465
                HandleSwitches();
469
      HandleSwitches ();
466
// Handle the bluetooth pairing function by pressing both buttons.
470
// Handle the bluetooth pairing function by pressing both buttons.
467
                if((push_pos[0] == 1) && (push_pos[1] == 1))
471
      if ((push_pos[0] == 1) && (push_pos[1] == 1))
468
                {
472
        {
469
                  HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, GPIO_PIN_SET);
473
          HAL_GPIO_WritePin (BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, GPIO_PIN_SET);
470
                }
474
        }
471
                else
475
      else
472
                {
476
        {
473
                  HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, GPIO_PIN_RESET);
477
          HAL_GPIO_WritePin (BT_BUTTON_GPIO_Port, BT_BUTTON_Pin,
-
 
478
                             GPIO_PIN_RESET);
474
 
479
 
475
                }
480
        }
476
 
481
 
-
 
482
      uint16_t cc = SerialCharsReceived (&uc1);
-
 
483
      int chr;
-
 
484
      if (cc == 0)
-
 
485
        {
-
 
486
          timeout++;
-
 
487
          if (timeout % 1000 == 0)
-
 
488
            {
-
 
489
              PutCharSerial (&uc3, '+');
-
 
490
            }
-
 
491
          if (timeout > 60000)
-
 
492
            {
-
 
493
              // do turn off screen
-
 
494
            }
477
 
495
 
478
                uint16_t cc = SerialCharsReceived(&uc1);
-
 
479
                int chr;
-
 
480
                if(cc==0)
-
 
481
                {
496
        }
482
                        timeout++;
-
 
483
                        if (timeout % 1000 ==0)
497
      for (chr = 0; chr < cc; chr++)
484
                        {
498
        {
485
                                PutCharSerial(&uc3,'+');
499
          char c = GetCharSerial (&uc1);
486
                        }
-
 
487
                        if(timeout > 60000)
500
          timeout = 0;
488
                        {
-
 
489
                                // do turn off screen
-
 
490
                        }
-
 
491
 
501
 
-
 
502
          if (c == PLX_Start) // at any time if the start byte appears, reset the pointers
-
 
503
            {
-
 
504
              PLXPtr = 0;    // reset the pointer
-
 
505
              PLXPacket = 1;
492
                }
506
            }
493
                for (chr = 0; chr < cc; chr++)
507
          else if (c == PLX_Stop)
-
 
508
            {
-
 
509
              if (PLXPacket)
494
                {
510
                {
-
 
511
                  // we can now decode the selected parameter
-
 
512
                  PLXItems = PLXPtr / sizeof(PLX_SensorInfo); // total
-
 
513
                  // saturate the rotary switch position
-
 
514
 
-
 
515
                  int DataVal;
-
 
516
                  // process min/max
-
 
517
                  for (i = 0; i < PLXItems; i++)
-
 
518
                    {
-
 
519
                      // Send item to BT
-
 
520
                      uint16_t addr = ConvPLX (Data.Sensor[i].AddrH,
495
                        char c = GetCharSerial(&uc1);
521
                                               Data.Sensor[i].AddrL);
-
 
522
                      uint8_t inst = Data.Sensor[i].Instance;
-
 
523
                      uint16_t reading = ConvPLX (Data.Sensor[i].ReadingH,
-
 
524
                                                  Data.Sensor[i].ReadingL);
-
 
525
 
-
 
526
                      char outbuff[100];
-
 
527
                      int cnt = simple_sprintf (outbuff, "%d,%d,%d\n", addr, inst,
496
                        timeout = 0;
528
                                         reading);
-
 
529
                      int i;
497
                        PutCharSerial(&uc3,c);
530
                      for (i = 0; i < cnt; i++)
498
 
531
 
499
                        if (c == PLX_Start) // at any time if the start byte appears, reset the pointers
-
 
500
                        {
532
                        {
501
                                PLXPtr = 0;    // reset the pointer
533
                          PutCharSerial (&uc3, outbuff[i]);
502
                                PLXPacket = 1;
-
 
503
                        }
534
                        }
-
 
535
                      DataVal = ConvPLX (Data.Sensor[i].ReadingH,
-
 
536
                                         Data.Sensor[i].ReadingL);
504
                        else if (c == PLX_Stop)
537
                      if (DataVal > Max[i])
505
                        {
538
                        {
506
                                if (PLXPacket)
-
 
507
                                {
-
 
508
                                        // we can now decode the selected parameter
-
 
509
                                        PLXItems = PLXPtr / sizeof(PLX_SensorInfo); // total
-
 
510
                                        // saturate the rotary switch position
-
 
511
 
-
 
512
                                        int DataVal;
-
 
513
                                        // process min/max
-
 
514
                                        for (i = 0; i < PLXItems; i++)
-
 
515
                                        {
-
 
516
                                                DataVal = ConvPLX(Data.Sensor[i].ReadingH,
-
 
517
                                                                Data.Sensor[i].ReadingL);
-
 
518
                                                if (DataVal > Max[i])
-
 
519
                                                {
-
 
520
                                                        Max[i] = DataVal;
539
                          Max[i] = DataVal;
521
                                                }
-
 
522
                                                if (DataVal < Min[i])
-
 
523
                                                {
-
 
524
                                                        Min[i] = DataVal;
-
 
525
                                                }
-
 
526
                                        }
-
 
527
 
-
 
528
                                        // now to display the information
-
 
529
                                    int suppress = DisplayCurrent(0,-1);
-
 
530
                                        DisplayCurrent(1, suppress);
-
 
531
                                }
-
 
532
                                PLXPtr = 0;
-
 
533
                                PLXPacket = 0;
-
 
534
                        }
540
                        }
535
                        else if (c > PLX_Stop) // illegal char, restart reading
541
                      if (DataVal < Min[i])
536
                        {
542
                        {
537
                                PLXPacket = 0;
-
 
538
                                PLXPtr = 0;
543
                          Min[i] = DataVal;
539
                        }
544
                        }
540
                        else if (PLXPtr < sizeof(Data.Bytes))
-
 
541
                        {
-
 
542
                                Data.Bytes[PLXPtr++] = c;
-
 
543
                        }
545
                    }
544
                }
-
 
545
 
546
 
-
 
547
                  // now to display the information
-
 
548
                  int suppress = DisplayCurrent (0, -1);
-
 
549
                  DisplayCurrent (1, suppress);
-
 
550
                }
546
                HAL_Delay(1);
551
              PLXPtr = 0;
-
 
552
              PLXPacket = 0;
-
 
553
            }
-
 
554
          else if (c > PLX_Stop) // illegal char, restart reading
-
 
555
            {
-
 
556
              PLXPacket = 0;
-
 
557
              PLXPtr = 0;
-
 
558
            }
-
 
559
          else if (PLXPtr < sizeof(Data.Bytes))
-
 
560
            {
-
 
561
              Data.Bytes[PLXPtr++] = c;
-
 
562
            }
547
        }
563
        }
-
 
564
 
-
 
565
      HAL_Delay (1);
-
 
566
    }
548
  /* USER CODE END WHILE */
567
  /* USER CODE END WHILE */
549
 
568
 
550
  /* USER CODE BEGIN 3 */
569
  /* USER CODE BEGIN 3 */
551
 
570
 
552
 
-
 
553
  /* USER CODE END 3 */
571
  /* USER CODE END 3 */
554
 
572
 
555
}
573
}
556
 
574
 
557
/** System Clock Configuration
575
/** System Clock Configuration
558
*/
576
 */
-
 
577
void
559
void SystemClock_Config(void)
578
SystemClock_Config (void)
560
{
579
{
561
 
580
 
562
  RCC_OscInitTypeDef RCC_OscInitStruct;
581
  RCC_OscInitTypeDef RCC_OscInitStruct;
563
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
582
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
564
 
583
 
Line 566... Line 585...
566
  RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
585
  RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
567
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
586
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
568
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
587
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
569
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
588
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
570
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
589
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
571
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
590
  if (HAL_RCC_OscConfig (&RCC_OscInitStruct) != HAL_OK)
572
  {
591
    {
573
    Error_Handler();
592
      Error_Handler ();
574
  }
593
    }
575
 
594
 
576
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
595
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
577
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
596
      | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
578
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
597
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
579
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
598
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
580
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
599
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
581
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
600
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
582
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
601
  if (HAL_RCC_ClockConfig (&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
583
  {
602
    {
584
    Error_Handler();
603
      Error_Handler ();
585
  }
604
    }
586
 
605
 
587
  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
606
  HAL_SYSTICK_Config (HAL_RCC_GetHCLKFreq () / 1000);
588
 
607
 
589
  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
608
  HAL_SYSTICK_CLKSourceConfig (SYSTICK_CLKSOURCE_HCLK);
590
 
609
 
591
  /* SysTick_IRQn interrupt configuration */
610
  /* SysTick_IRQn interrupt configuration */
592
  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
611
  HAL_NVIC_SetPriority (SysTick_IRQn, 0, 0);
593
}
612
}
594
 
613
 
595
/* SPI1 init function */
614
/* SPI1 init function */
-
 
615
static void
596
static void MX_SPI1_Init(void)
616
MX_SPI1_Init (void)
597
{
617
{
598
 
618
 
599
  hspi1.Instance = SPI1;
619
  hspi1.Instance = SPI1;
600
  hspi1.Init.Mode = SPI_MODE_MASTER;
620
  hspi1.Init.Mode = SPI_MODE_MASTER;
601
  hspi1.Init.Direction = SPI_DIRECTION_1LINE;
621
  hspi1.Init.Direction = SPI_DIRECTION_1LINE;
Line 606... Line 626...
606
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
626
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
607
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
627
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
608
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
628
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
609
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
629
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
610
  hspi1.Init.CRCPolynomial = 10;
630
  hspi1.Init.CRCPolynomial = 10;
611
  if (HAL_SPI_Init(&hspi1) != HAL_OK)
631
  if (HAL_SPI_Init (&hspi1) != HAL_OK)
612
  {
632
    {
613
    Error_Handler();
633
      Error_Handler ();
614
  }
634
    }
615
 
635
 
616
}
636
}
617
 
637
 
618
/* USART1 init function */
638
/* USART1 init function */
-
 
639
static void
619
static void MX_USART1_UART_Init(void)
640
MX_USART1_UART_Init (void)
620
{
641
{
621
 
642
 
622
  huart1.Instance = USART1;
643
  huart1.Instance = USART1;
623
  huart1.Init.BaudRate = 19200;
644
  huart1.Init.BaudRate = 19200;
624
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
645
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
625
  huart1.Init.StopBits = UART_STOPBITS_1;
646
  huart1.Init.StopBits = UART_STOPBITS_1;
626
  huart1.Init.Parity = UART_PARITY_NONE;
647
  huart1.Init.Parity = UART_PARITY_NONE;
627
  huart1.Init.Mode = UART_MODE_TX_RX;
648
  huart1.Init.Mode = UART_MODE_TX_RX;
628
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
649
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
629
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
650
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
630
  if (HAL_UART_Init(&huart1) != HAL_OK)
651
  if (HAL_UART_Init (&huart1) != HAL_OK)
631
  {
652
    {
632
    Error_Handler();
653
      Error_Handler ();
633
  }
654
    }
634
 
655
 
635
}
656
}
636
 
657
 
637
/* USART2 init function */
658
/* USART2 init function */
-
 
659
static void
638
static void MX_USART2_UART_Init(void)
660
MX_USART2_UART_Init (void)
639
{
661
{
640
 
662
 
641
  huart2.Instance = USART2;
663
  huart2.Instance = USART2;
642
  huart2.Init.BaudRate = 115200;
664
  huart2.Init.BaudRate = 115200;
643
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
665
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
644
  huart2.Init.StopBits = UART_STOPBITS_1;
666
  huart2.Init.StopBits = UART_STOPBITS_1;
645
  huart2.Init.Parity = UART_PARITY_NONE;
667
  huart2.Init.Parity = UART_PARITY_NONE;
646
  huart2.Init.Mode = UART_MODE_TX_RX;
668
  huart2.Init.Mode = UART_MODE_TX_RX;
647
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
669
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
648
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
670
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
649
  if (HAL_UART_Init(&huart2) != HAL_OK)
671
  if (HAL_UART_Init (&huart2) != HAL_OK)
650
  {
672
    {
651
    Error_Handler();
673
      Error_Handler ();
652
  }
674
    }
653
 
675
 
654
}
676
}
655
 
677
 
656
/* USART3 init function */
678
/* USART3 init function */
-
 
679
static void
657
static void MX_USART3_UART_Init(void)
680
MX_USART3_UART_Init (void)
658
{
681
{
659
 
682
 
660
  huart3.Instance = USART3;
683
  huart3.Instance = USART3;
661
  huart3.Init.BaudRate = 19200;
684
  huart3.Init.BaudRate = 19200;
662
  huart3.Init.WordLength = UART_WORDLENGTH_8B;
685
  huart3.Init.WordLength = UART_WORDLENGTH_8B;
663
  huart3.Init.StopBits = UART_STOPBITS_1;
686
  huart3.Init.StopBits = UART_STOPBITS_1;
664
  huart3.Init.Parity = UART_PARITY_NONE;
687
  huart3.Init.Parity = UART_PARITY_NONE;
665
  huart3.Init.Mode = UART_MODE_TX_RX;
688
  huart3.Init.Mode = UART_MODE_TX_RX;
666
  huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
689
  huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
667
  huart3.Init.OverSampling = UART_OVERSAMPLING_16;
690
  huart3.Init.OverSampling = UART_OVERSAMPLING_16;
668
  if (HAL_UART_Init(&huart3) != HAL_OK)
691
  if (HAL_UART_Init (&huart3) != HAL_OK)
669
  {
692
    {
670
    Error_Handler();
693
      Error_Handler ();
671
  }
694
    }
672
 
695
 
673
}
696
}
674
 
697
 
675
/** Configure pins as
698
/** Configure pins as
676
        * Analog
699
 * Analog
677
        * Input
700
 * Input
678
        * Output
701
 * Output
679
        * EVENT_OUT
702
 * EVENT_OUT
680
        * EXTI
703
 * EXTI
681
*/
704
 */
-
 
705
static void
682
static void MX_GPIO_Init(void)
706
MX_GPIO_Init (void)
683
{
707
{
684
 
708
 
685
  GPIO_InitTypeDef GPIO_InitStruct;
709
  GPIO_InitTypeDef GPIO_InitStruct;
686
 
710
 
687
  /* GPIO Ports Clock Enable */
711
  /* GPIO Ports Clock Enable */
688
  __HAL_RCC_GPIOD_CLK_ENABLE();
712
  __HAL_RCC_GPIOD_CLK_ENABLE()
-
 
713
  ;
689
  __HAL_RCC_GPIOA_CLK_ENABLE();
714
  __HAL_RCC_GPIOA_CLK_ENABLE()
-
 
715
  ;
690
  __HAL_RCC_GPIOC_CLK_ENABLE();
716
  __HAL_RCC_GPIOC_CLK_ENABLE()
-
 
717
  ;
691
  __HAL_RCC_GPIOB_CLK_ENABLE();
718
  __HAL_RCC_GPIOB_CLK_ENABLE()
-
 
719
  ;
692
 
720
 
693
  /*Configure GPIO pin Output Level */
721
  /*Configure GPIO pin Output Level */
694
  HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET);
722
  HAL_GPIO_WritePin (SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET);
695
 
723
 
696
  /*Configure GPIO pin Output Level */
724
  /*Configure GPIO pin Output Level */
697
  HAL_GPIO_WritePin(GPIOA, SPI1CD_Pin|BT_BUTTON_Pin, GPIO_PIN_RESET);
725
  HAL_GPIO_WritePin (GPIOA, SPI1CD_Pin | BT_BUTTON_Pin, GPIO_PIN_RESET);
698
 
726
 
699
  /*Configure GPIO pin Output Level */
727
  /*Configure GPIO pin Output Level */
700
  HAL_GPIO_WritePin(GPIOC, SPI_RESET_Pin|POWER_LATCH_Pin|USB_PWR_Pin, GPIO_PIN_RESET);
728
  HAL_GPIO_WritePin (GPIOC, SPI_RESET_Pin | POWER_LATCH_Pin | USB_PWR_Pin,
-
 
729
                     GPIO_PIN_RESET);
701
 
730
 
702
  /*Configure GPIO pin Output Level */
731
  /*Configure GPIO pin Output Level */
703
  HAL_GPIO_WritePin(SPI_NSS2_GPIO_Port, SPI_NSS2_Pin, GPIO_PIN_SET);
732
  HAL_GPIO_WritePin (SPI_NSS2_GPIO_Port, SPI_NSS2_Pin, GPIO_PIN_SET);
704
 
733
 
705
  /*Configure GPIO pins : SPI_NSS1_Pin SPI1CD_Pin BT_BUTTON_Pin */
734
  /*Configure GPIO pins : SPI_NSS1_Pin SPI1CD_Pin BT_BUTTON_Pin */
706
  GPIO_InitStruct.Pin = SPI_NSS1_Pin|SPI1CD_Pin|BT_BUTTON_Pin;
735
  GPIO_InitStruct.Pin = SPI_NSS1_Pin | SPI1CD_Pin | BT_BUTTON_Pin;
707
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
736
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
708
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
737
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
709
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
738
  HAL_GPIO_Init (GPIOA, &GPIO_InitStruct);
710
 
739
 
711
  /*Configure GPIO pins : SPI_RESET_Pin SPI_NSS2_Pin POWER_LATCH_Pin USB_PWR_Pin */
740
  /*Configure GPIO pins : SPI_RESET_Pin SPI_NSS2_Pin POWER_LATCH_Pin USB_PWR_Pin */
712
  GPIO_InitStruct.Pin = SPI_RESET_Pin|SPI_NSS2_Pin|POWER_LATCH_Pin|USB_PWR_Pin;
741
  GPIO_InitStruct.Pin = SPI_RESET_Pin | SPI_NSS2_Pin | POWER_LATCH_Pin
-
 
742
      | USB_PWR_Pin;
713
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
743
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
714
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
744
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
715
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
745
  HAL_GPIO_Init (GPIOC, &GPIO_InitStruct);
716
 
746
 
717
  /*Configure GPIO pins : SW1_PUSH_Pin SW1_I_Pin SW1_Q_Pin SW2_PUSH_Pin */
747
  /*Configure GPIO pins : SW1_PUSH_Pin SW1_I_Pin SW1_Q_Pin SW2_PUSH_Pin */
718
  GPIO_InitStruct.Pin = SW1_PUSH_Pin|SW1_I_Pin|SW1_Q_Pin|SW2_PUSH_Pin;
748
  GPIO_InitStruct.Pin = SW1_PUSH_Pin | SW1_I_Pin | SW1_Q_Pin | SW2_PUSH_Pin;
719
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
749
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
720
  GPIO_InitStruct.Pull = GPIO_PULLUP;
750
  GPIO_InitStruct.Pull = GPIO_PULLUP;
721
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
751
  HAL_GPIO_Init (GPIOB, &GPIO_InitStruct);
722
 
752
 
723
  /*Configure GPIO pins : SW2_I_Pin SW2_Q_Pin */
753
  /*Configure GPIO pins : SW2_I_Pin SW2_Q_Pin */
724
  GPIO_InitStruct.Pin = SW2_I_Pin|SW2_Q_Pin;
754
  GPIO_InitStruct.Pin = SW2_I_Pin | SW2_Q_Pin;
725
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
755
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
726
  GPIO_InitStruct.Pull = GPIO_PULLUP;
756
  GPIO_InitStruct.Pull = GPIO_PULLUP;
727
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
757
  HAL_GPIO_Init (GPIOC, &GPIO_InitStruct);
728
 
758
 
729
  /*Configure GPIO pin : IGNITION_Pin */
759
  /*Configure GPIO pin : IGNITION_Pin */
730
  GPIO_InitStruct.Pin = IGNITION_Pin;
760
  GPIO_InitStruct.Pin = IGNITION_Pin;
731
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
761
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
732
  GPIO_InitStruct.Pull = GPIO_NOPULL;
762
  GPIO_InitStruct.Pull = GPIO_NOPULL;
733
  HAL_GPIO_Init(IGNITION_GPIO_Port, &GPIO_InitStruct);
763
  HAL_GPIO_Init (IGNITION_GPIO_Port, &GPIO_InitStruct);
734
 
764
 
735
}
765
}
736
 
766
 
737
/* USER CODE BEGIN 4 */
767
/* USER CODE BEGIN 4 */
738
 
768
 
739
/* USER CODE END 4 */
769
/* USER CODE END 4 */
740
 
770
 
741
/**
771
/**
742
  * @brief  This function is executed in case of error occurrence.
772
 * @brief  This function is executed in case of error occurrence.
743
  * @param  None
773
 * @param  None
744
  * @retval None
774
 * @retval None
745
  */
775
 */
-
 
776
void
746
void Error_Handler(void)
777
Error_Handler (void)
747
{
778
{
748
  /* USER CODE BEGIN Error_Handler */
779
  /* USER CODE BEGIN Error_Handler */
749
/* User can add his own implementation to report the HAL error return state */
780
  /* User can add his own implementation to report the HAL error return state */
750
while (1)
781
  while (1)
751
{
782
    {
752
}
783
    }
753
  /* USER CODE END Error_Handler */
784
  /* USER CODE END Error_Handler */
754
}
785
}
755
 
786
 
756
#ifdef USE_FULL_ASSERT
787
#ifdef USE_FULL_ASSERT
757
 
788
 
758
/**
789
/**
759
   * @brief Reports the name of the source file and the source line number
790
 * @brief Reports the name of the source file and the source line number
760
   * where the assert_param error has occurred.
791
 * where the assert_param error has occurred.
761
   * @param file: pointer to the source file name
792
 * @param file: pointer to the source file name
762
   * @param line: assert_param error line source number
793
 * @param line: assert_param error line source number
763
   * @retval None
794
 * @retval None
764
   */
795
 */
765
void assert_failed(uint8_t* file, uint32_t line)
796
void assert_failed(uint8_t* file, uint32_t line)
766
{
797
  {
767
  /* USER CODE BEGIN 6 */
798
    /* USER CODE BEGIN 6 */
768
/* User can add his own implementation to report the file name and line number,
799
    /* User can add his own implementation to report the file name and line number,
769
 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
800
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
770
  /* USER CODE END 6 */
801
    /* USER CODE END 6 */
771
 
802
 
772
}
803
  }
773
 
804
 
774
#endif
805
#endif
775
 
806
 
776
/**
807
/**
777
  * @}
808
 * @}
778
  */
809
 */
779
 
810
 
780
/**
811
/**
781
  * @}
812
 * @}
782
*/
813
 */
783
 
814
 
784
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
815
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/