From 0d22157ef4e474924b1ea9b8f1a28cba57ce472b Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol Date: Wed, 9 Mar 2022 16:34:16 +0100 Subject: [PATCH] feat: Add STM32Cube HAL getter to SPI, Wire and HardwareSerial Could be used for example to mix Arduino API and STM32Cube HAL API. For example to configure DMA. Warning: Use at your own risk Fixes #1035 Signed-off-by: Alexandre Bourdiol --- cores/arduino/HardwareSerial.h | 7 +++++++ libraries/SPI/src/SPI.h | 6 ++++++ libraries/Wire/src/Wire.h | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/cores/arduino/HardwareSerial.h b/cores/arduino/HardwareSerial.h index de5b6a94f9..581810a4f0 100644 --- a/cores/arduino/HardwareSerial.h +++ b/cores/arduino/HardwareSerial.h @@ -174,6 +174,13 @@ class HardwareSerial : public Stream { // Interrupt handlers static void _rx_complete_irq(serial_t *obj); static int _tx_complete_irq(serial_t *obj); + + // Could be used to mix Arduino API and STM32Cube HAL API (ex: DMA). Use at your own risk. + UART_HandleTypeDef* getHandle(void) + { + return &(_serial.handle); + } + private: bool _rx_enabled; uint8_t _config; diff --git a/libraries/SPI/src/SPI.h b/libraries/SPI/src/SPI.h index bd6677c55e..c7ec29db44 100644 --- a/libraries/SPI/src/SPI.h +++ b/libraries/SPI/src/SPI.h @@ -227,6 +227,12 @@ class SPIClass { void attachInterrupt(void); void detachInterrupt(void); + // Could be used to mix Arduino API and STM32Cube HAL API (ex: DMA). Use at your own risk. + SPI_HandleTypeDef* getHandle(void) + { + return &(_spi.handle); + } + private: /* Contains various spiSettings for the same spi instance. Each spi spiSettings is associated to a CS pin. */ diff --git a/libraries/Wire/src/Wire.h b/libraries/Wire/src/Wire.h index cd1dfe925d..a7f3720a2b 100644 --- a/libraries/Wire/src/Wire.h +++ b/libraries/Wire/src/Wire.h @@ -130,6 +130,12 @@ class TwoWire : public Stream { return write((uint8_t)n); } using Print::write; + + // Could be used to mix Arduino API and STM32Cube HAL API (ex: DMA). Use at your own risk. + I2C_HandleTypeDef* getHandle(void) + { + return &(_i2c.handle); + } };