Subversion Repositories DashDisplay

Rev

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

Rev 22 Rev 23
Line 2... Line 2...
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) 2016 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.
Line 50... Line 50...
50
/* Private variables ---------------------------------------------------------*/
50
/* Private variables ---------------------------------------------------------*/
51
SPI_HandleTypeDef hspi1;
51
SPI_HandleTypeDef hspi1;
52
 
52
 
53
UART_HandleTypeDef huart1;
53
UART_HandleTypeDef huart1;
54
UART_HandleTypeDef huart2;
54
UART_HandleTypeDef huart2;
-
 
55
UART_HandleTypeDef huart3;
55
 
56
 
56
/* USER CODE BEGIN PV */
57
/* USER CODE BEGIN PV */
57
/* Private variables ---------------------------------------------------------*/
58
/* Private variables ---------------------------------------------------------*/
58
#define MAXRDG 32
59
#define MAXRDG 32
59
 
60
 
Line 89... Line 90...
89
void Error_Handler(void);
90
void Error_Handler(void);
90
static void MX_GPIO_Init(void);
91
static void MX_GPIO_Init(void);
91
static void MX_SPI1_Init(void);
92
static void MX_SPI1_Init(void);
92
static void MX_USART2_UART_Init(void);
93
static void MX_USART2_UART_Init(void);
93
static void MX_USART1_UART_Init(void);
94
static void MX_USART1_UART_Init(void);
-
 
95
static void MX_USART3_UART_Init(void);
94
 
96
 
95
/* USER CODE BEGIN PFP */
97
/* USER CODE BEGIN PFP */
96
/* Private function prototypes -----------------------------------------------*/
98
/* Private function prototypes -----------------------------------------------*/
97
 
99
 
98
/* USER CODE END PFP */
100
/* USER CODE END PFP */
Line 297... Line 299...
297
 
299
 
298
  /* USER CODE BEGIN 1 */
300
  /* USER CODE BEGIN 1 */
299
 
301
 
300
        GPIO_InitTypeDef GPIO_InitStruct;
302
        GPIO_InitTypeDef GPIO_InitStruct;
301
 
303
 
302
        __HAL_RCC_SPI1_CLK_ENABLE()
304
        __HAL_RCC_SPI1_CLK_ENABLE();
303
        ;
-
 
304
        __HAL_RCC_USART1_CLK_ENABLE()
305
        __HAL_RCC_USART1_CLK_ENABLE(); // PLX main port
305
        ; // PLX main port
-
 
306
        __HAL_RCC_USART2_CLK_ENABLE()
306
        __HAL_RCC_USART2_CLK_ENABLE(); // debug port
307
        ; // debug port
307
        __HAL_RCC_USART3_CLK_ENABLE(); // Bluetooth port
-
 
308
 
308
  /* USER CODE END 1 */
309
  /* USER CODE END 1 */
309
 
310
 
310
  /* MCU Configuration----------------------------------------------------------*/
311
  /* MCU Configuration----------------------------------------------------------*/
311
 
312
 
312
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
313
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
Line 318... Line 319...
318
  /* Initialize all configured peripherals */
319
  /* Initialize all configured peripherals */
319
  MX_GPIO_Init();
320
  MX_GPIO_Init();
320
  MX_SPI1_Init();
321
  MX_SPI1_Init();
321
  MX_USART2_UART_Init();
322
  MX_USART2_UART_Init();
322
  MX_USART1_UART_Init();
323
  MX_USART1_UART_Init();
-
 
324
  MX_USART3_UART_Init();
323
 
325
 
324
  /* USER CODE BEGIN 2 */
326
  /* USER CODE BEGIN 2 */
325
        /* SPI bus AF pin selects */
-
 
326
 
327
 
327
 
328
 
328
  /* Turn on USART2 IRQ  */
-
 
329
        HAL_NVIC_SetPriority(USART2_IRQn, 4, 0);
-
 
330
        HAL_NVIC_EnableIRQ(USART2_IRQn);
-
 
331
 
329
 
332
        /* Turn on USART1 IRQ */
330
        /* Turn on USART1 IRQ */
333
        HAL_NVIC_SetPriority(USART1_IRQn, 2, 0);
331
        HAL_NVIC_SetPriority(USART1_IRQn, 2, 0);
334
        HAL_NVIC_EnableIRQ(USART1_IRQn);
332
        HAL_NVIC_EnableIRQ(USART1_IRQn);
335
 
333
 
-
 
334
    /* Turn on USART2 IRQ  */
-
 
335
        HAL_NVIC_SetPriority(USART2_IRQn, 4, 0);
-
 
336
        HAL_NVIC_EnableIRQ(USART2_IRQn);
-
 
337
 
-
 
338
        /* turn on USART3 IRQ */
-
 
339
        HAL_NVIC_SetPriority(USART3_IRQn, 4, 0);
-
 
340
        HAL_NVIC_EnableIRQ(USART3_IRQn);
-
 
341
 
-
 
342
 
-
 
343
 
336
        /* setup the USART control blocks */
344
        /* setup the USART control blocks */
337
        init_usart_ctl(&uc1, huart1.Instance);
345
        init_usart_ctl(&uc1, huart1.Instance);
338
        init_usart_ctl(&uc2, huart2.Instance);
346
        init_usart_ctl(&uc2, huart2.Instance);
-
 
347
        init_usart_ctl(&uc3, huart3.Instance);
339
 
348
 
340
        EnableSerialRxInterrupt(&uc1);
349
        EnableSerialRxInterrupt(&uc1);
341
        EnableSerialRxInterrupt(&uc2);
350
        EnableSerialRxInterrupt(&uc2);
-
 
351
        EnableSerialRxInterrupt(&uc3);
-
 
352
 
342
        /* Unlock the Flash to enable the flash control register access *************/
353
        /* Unlock the Flash to enable the flash control register access *************/
343
        HAL_FLASH_Unlock();
354
        HAL_FLASH_Unlock();
344
 
355
 
345
        //__disable_irq();
356
        //__disable_irq();
346
        EE_Init();
357
        EE_Init();
Line 408... Line 419...
408
 
419
 
409
  /* Infinite loop */
420
  /* Infinite loop */
410
  /* USER CODE BEGIN WHILE */
421
  /* USER CODE BEGIN WHILE */
411
        uint32_t Ticks = HAL_GetTick() + 100;
422
        uint32_t Ticks = HAL_GetTick() + 100;
412
 
423
 
413
 
-
 
-
 
424
    uint32_t timeout = 0;  //
414
        // PLX decoder protocol
425
        // PLX decoder protocol
415
        char PLXPacket = 0;
426
        char PLXPacket = 0;
416
        for (i = 0; i < MAXRDG; i++)
427
        for (i = 0; i < MAXRDG; i++)
417
        {
428
        {
418
                Max[i] = 0;
429
                Max[i] = 0;
Line 423... Line 434...
423
 
434
 
424
        while (1)
435
        while (1)
425
        {
436
        {
426
// poll switches
437
// poll switches
427
                HandleSwitches();
438
                HandleSwitches();
-
 
439
// Handle the bluetooth pairing function by pressing both buttons.
-
 
440
                if((push_pos[0] == 1) && (push_pos[1] == 1))
-
 
441
                {
-
 
442
                  HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, GPIO_PIN_SET);
-
 
443
                }
-
 
444
                else
-
 
445
                {
-
 
446
                  HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, GPIO_PIN_RESET);
-
 
447
 
-
 
448
                }
428
 
449
 
429
 
450
 
430
                uint16_t cc = SerialCharsReceived(&uc1);
451
                uint16_t cc = SerialCharsReceived(&uc1);
431
                int chr;
452
                int chr;
-
 
453
                if(cc==0)
-
 
454
                {
-
 
455
                        timeout++;
-
 
456
                        if (timeout % 1000 ==0)
-
 
457
                        {
-
 
458
                                PutCharSerial(&uc3,'+');
-
 
459
                        }
-
 
460
                        if(timeout > 60000)
-
 
461
                        {
-
 
462
                                // do turn off screen
-
 
463
                        }
-
 
464
 
-
 
465
                }
432
                for (chr = 0; chr < cc; chr++)
466
                for (chr = 0; chr < cc; chr++)
433
                {
467
                {
434
                        char c = GetCharSerial(&uc1);
468
                        char c = GetCharSerial(&uc1);
-
 
469
                        timeout = 0;
-
 
470
                        PutCharSerial(&uc3,c);
-
 
471
 
435
                        if (c == PLX_Start) // at any time if the start byte appears, reset the pointers
472
                        if (c == PLX_Start) // at any time if the start byte appears, reset the pointers
436
                        {
473
                        {
437
                                PLXPtr = 0;    // reset the pointer
474
                                PLXPtr = 0;    // reset the pointer
438
                                PLXPacket = 1;
475
                                PLXPacket = 1;
439
                        }
476
                        }
Line 587... Line 624...
587
    Error_Handler();
624
    Error_Handler();
588
  }
625
  }
589
 
626
 
590
}
627
}
591
 
628
 
-
 
629
/* USART3 init function */
-
 
630
static void MX_USART3_UART_Init(void)
-
 
631
{
-
 
632
 
-
 
633
  huart3.Instance = USART3;
-
 
634
  huart3.Init.BaudRate = 19200;
-
 
635
  huart3.Init.WordLength = UART_WORDLENGTH_8B;
-
 
636
  huart3.Init.StopBits = UART_STOPBITS_1;
-
 
637
  huart3.Init.Parity = UART_PARITY_NONE;
-
 
638
  huart3.Init.Mode = UART_MODE_TX_RX;
-
 
639
  huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
-
 
640
  huart3.Init.OverSampling = UART_OVERSAMPLING_16;
-
 
641
  if (HAL_UART_Init(&huart3) != HAL_OK)
-
 
642
  {
-
 
643
    Error_Handler();
-
 
644
  }
-
 
645
 
-
 
646
}
-
 
647
 
592
/** Configure pins as
648
/** Configure pins as
593
        * Analog
649
        * Analog
594
        * Input
650
        * Input
595
        * Output
651
        * Output
596
        * EVENT_OUT
652
        * EVENT_OUT
Line 609... Line 665...
609
 
665
 
610
  /*Configure GPIO pin Output Level */
666
  /*Configure GPIO pin Output Level */
611
  HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET);
667
  HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET);
612
 
668
 
613
  /*Configure GPIO pin Output Level */
669
  /*Configure GPIO pin Output Level */
614
  HAL_GPIO_WritePin(SPI1CD_GPIO_Port, SPI1CD_Pin, GPIO_PIN_RESET);
670
  HAL_GPIO_WritePin(GPIOA, SPI1CD_Pin|BT_BUTTON_Pin, GPIO_PIN_RESET);
615
 
671
 
616
  /*Configure GPIO pin Output Level */
672
  /*Configure GPIO pin Output Level */
617
  HAL_GPIO_WritePin(GPIOC, SPI_RESET_Pin|USART3_INVERT_Pin|USB_PWR_Pin, GPIO_PIN_RESET);
673
  HAL_GPIO_WritePin(GPIOC, SPI_RESET_Pin|USART3_INVERT_Pin|USB_PWR_Pin, GPIO_PIN_RESET);
618
 
674
 
619
  /*Configure GPIO pin Output Level */
675
  /*Configure GPIO pin Output Level */
620
  HAL_GPIO_WritePin(SPI_NSS2_GPIO_Port, SPI_NSS2_Pin, GPIO_PIN_SET);
676
  HAL_GPIO_WritePin(SPI_NSS2_GPIO_Port, SPI_NSS2_Pin, GPIO_PIN_SET);
621
 
677
 
622
  /*Configure GPIO pins : SPI_NSS1_Pin SPI1CD_Pin */
678
  /*Configure GPIO pins : SPI_NSS1_Pin SPI1CD_Pin BT_BUTTON_Pin */
623
  GPIO_InitStruct.Pin = SPI_NSS1_Pin|SPI1CD_Pin;
679
  GPIO_InitStruct.Pin = SPI_NSS1_Pin|SPI1CD_Pin|BT_BUTTON_Pin;
624
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
680
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
625
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
681
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
626
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
682
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
627
 
683
 
628
  /*Configure GPIO pins : SPI_RESET_Pin SPI_NSS2_Pin USART3_INVERT_Pin USB_PWR_Pin */
684
  /*Configure GPIO pins : SPI_RESET_Pin SPI_NSS2_Pin USART3_INVERT_Pin USB_PWR_Pin */