28
28
#define UART_TX_BUFFER_MASK ((UART_TX_BUFFER_SIZE<<1 )-1 )
29
29
#define UART_TX_INDEX_MASK (UART_TX_BUFFER_SIZE-1 )
30
30
31
- Uart::Uart (struct _stm32l4_uart_t *uart, unsigned int instance, const struct _stm32l4_uart_pins_t *pins, unsigned int priority, unsigned int mode)
31
+ Uart::Uart (struct _stm32l4_uart_t *uart, unsigned int instance, const struct _stm32l4_uart_pins_t *pins, unsigned int priority, unsigned int mode, bool serialEvent )
32
32
{
33
33
_uart = uart;
34
34
@@ -41,11 +41,14 @@ Uart::Uart(struct _stm32l4_uart_t *uart, unsigned int instance, const struct _st
41
41
_completionCallback = NULL ;
42
42
43
43
stm32l4_uart_create (uart, instance, pins, priority, mode);
44
+
45
+ if (serialEvent)
46
+ serialEventCallback = serialEventDispatch;
44
47
}
45
48
46
49
void Uart::begin (unsigned long baudrate)
47
50
{
48
- begin (baudrate, ( uint8_t ) SERIAL_8N1);
51
+ begin (baudrate, SERIAL_8N1);
49
52
}
50
53
51
54
void Uart::begin (unsigned long baudrate, uint16_t config)
@@ -476,59 +479,69 @@ void Uart::_event_callback(void *context, uint32_t events)
476
479
reinterpret_cast <class Uart *>(context)->EventCallback (events);
477
480
}
478
481
482
+ bool Serial1_empty () { return Serial1.empty (); }
483
+
484
+ extern void serialEvent1 () __attribute__((weak));
485
+
479
486
static stm32l4_uart_t stm32l4_usart3;
480
487
481
488
static const stm32l4_uart_pins_t stm32l4_usart3_pins = { GPIO_PIN_PC5_USART3_RX, GPIO_PIN_PC4_USART3_TX, GPIO_PIN_NONE, GPIO_PIN_NONE };
482
489
483
- Uart __attribute__ ((weak)) Serial1(&stm32l4_usart3, UART_INSTANCE_USART3, &stm32l4_usart3_pins, STM32L4_UART_IRQ_PRIORITY, UART_MODE_RX_DMA | UART_MODE_TX_DMA);
484
-
485
- bool Serial1_empty () { return Serial1.empty (); }
490
+ Uart __attribute__ ((weak)) Serial1(&stm32l4_usart3, UART_INSTANCE_USART3, &stm32l4_usart3_pins, STM32L4_UART_IRQ_PRIORITY, UART_MODE_RX_DMA | UART_MODE_TX_DMA, (serialEvent1 != NULL ));
486
491
487
492
#if SERIAL_INTERFACES_COUNT > 1
488
493
494
+ bool Serial2_empty () { return Serial2.empty (); }
495
+
496
+ extern void serialEvent2 () __attribute__((weak));
497
+
489
498
static stm32l4_uart_t stm32l4_uart4;
490
499
491
500
static const stm32l4_uart_pins_t stm32l4_uart4_pins = { GPIO_PIN_PA1_UART4_RX, GPIO_PIN_PA0_UART4_TX, GPIO_PIN_NONE, GPIO_PIN_NONE };
492
501
493
- Uart __attribute__ ((weak)) Serial2(&stm32l4_uart4, UART_INSTANCE_UART4, &stm32l4_uart4_pins, STM32L4_UART_IRQ_PRIORITY, UART_MODE_RX_DMA | UART_MODE_RX_DMA_SECONDARY);
494
-
495
- bool Serial2_empty () { return Serial2.empty (); }
502
+ Uart __attribute__ ((weak)) Serial2(&stm32l4_uart4, UART_INSTANCE_UART4, &stm32l4_uart4_pins, STM32L4_UART_IRQ_PRIORITY, UART_MODE_RX_DMA | UART_MODE_RX_DMA_SECONDARY, (serialEvent2 != NULL ));
496
503
497
504
#endif
498
505
499
506
#if SERIAL_INTERFACES_COUNT > 2
500
507
508
+ bool Serial3_empty () { return Serial3.empty (); }
509
+
510
+ extern void serialEvent3 () __attribute__((weak));
511
+
501
512
static stm32l4_uart_t stm32l4_usart2;
502
513
503
514
static const stm32l4_uart_pins_t stm32l4_usart2_pins = { GPIO_PIN_PA3_USART2_RX, GPIO_PIN_PA2_USART2_TX, GPIO_PIN_NONE, GPIO_PIN_NONE };
504
515
505
- Uart __attribute__ ((weak)) Serial3(&stm32l4_usart2, UART_INSTANCE_USART2, &stm32l4_usart2_pins, STM32L4_UART_IRQ_PRIORITY, 0 );
506
-
507
- bool Serial3_empty () { return Serial3.empty (); }
516
+ Uart __attribute__ ((weak)) Serial3(&stm32l4_usart2, UART_INSTANCE_USART2, &stm32l4_usart2_pins, STM32L4_UART_IRQ_PRIORITY, 0 , (serialEvent3 != NULL ));
508
517
509
518
#endif
510
519
511
520
#if SERIAL_INTERFACES_COUNT > 3
512
521
522
+ bool Serial4_empty () { return Serial4.empty (); }
523
+
524
+ extern void serialEvent4 () __attribute__((weak));
525
+
513
526
static stm32l4_uart_t stm32l4_uart5;
514
527
515
528
static const stm32l4_uart_pins_t stm32l4_uart5_pins = { GPIO_PIN_PD2_UART5_RX, GPIO_PIN_PC12_UART5_TX, GPIO_PIN_NONE, GPIO_PIN_NONE };
516
529
517
- Uart __attribute__ ((weak)) Serial4(&stm32l4_uart5, UART_INSTANCE_UART5, &stm32l4_uart5_pins, STM32L4_UART_IRQ_PRIORITY, 0 );
518
-
519
- bool Serial4_empty () { return Serial4.empty (); }
530
+ Uart __attribute__ ((weak)) Serial4(&stm32l4_uart5, UART_INSTANCE_UART5, &stm32l4_uart5_pins, STM32L4_UART_IRQ_PRIORITY, 0 , (serialEvent4 != NULL ));
520
531
521
532
#endif
522
533
523
534
#if SERIAL_INTERFACES_COUNT > 4
524
535
536
+ bool Serial5_empty () { return Serial5.empty (); }
537
+
538
+ extern void serialEvent5 () __attribute__((weak));
539
+
525
540
static stm32l4_uart_t stm32l4_usart1;
526
541
527
542
static const stm32l4_uart_pins_t stm32l4_usart1_pins = { GPIO_PIN_PB7_USART1_RX, GPIO_PIN_PB6_USART1_TX, GPIO_PIN_NONE, GPIO_PIN_NONE };
528
543
529
- Uart __attribute__ ((weak)) Serial5(&stm32l4_usart1, UART_INSTANCE_USART1, &stm32l4_usart1_pins, STM32L4_UART_IRQ_PRIORITY, 0 );
530
-
531
- bool Serial5_empty () { return Serial5.empty (); }
544
+ Uart __attribute__ ((weak)) Serial5(&stm32l4_usart1, UART_INSTANCE_USART1, &stm32l4_usart1_pins, STM32L4_UART_IRQ_PRIORITY, 0 , (serialEvent5 != NULL ));
532
545
533
546
#endif
534
547
0 commit comments