From 3bd1eee9a54543da170aeba4dc345095a421c4ea Mon Sep 17 00:00:00 2001 From: Paul Watts Date: Sat, 27 Apr 2024 12:45:27 +0100 Subject: [PATCH] Added Renesas Uno Support Added Support for Renesas Uno (Arduino Uno R4) --- library.properties | 2 +- src/IBusBM.cpp | 30 +++++++++++++++++++++++++++++- src/IBusBM.h | 11 +++++++---- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/library.properties b/library.properties index 1b03bbf..27b68e9 100644 --- a/library.properties +++ b/library.properties @@ -6,5 +6,5 @@ sentence=Arduino library for the Flysky/Turnigy RC iBUS protocol - servo (receiv paragraph=With this library you can interface to any RC receiver that supports the Flysky iBUS protocol (such as TGY-IA6B). Flysky iBUS uses a half-duplex asynchronous protocol format at 115200 baud. The library requires at least one free hardware UART (serial) port. The library can be used to receive data (typically servo data) and send data (telemetry or sensors). category=Communication url=https://github.com/bmellink/IBusBM -architectures=avr,esp32,stm32,mbed,STM32F1,megaavr +architectures=avr,esp32,stm32,mbed,STM32F1,megaavr,renesas_uno includes=IBusBM.h diff --git a/src/IBusBM.cpp b/src/IBusBM.cpp index 624c11a..10fb13d 100644 --- a/src/IBusBM.cpp +++ b/src/IBusBM.cpp @@ -36,6 +36,16 @@ IBusBM* IBusBMfirst = NULL; SIGNAL(TIMER0_COMPA_vect) { if (IBusBMfirst) IBusBMfirst->loop(); // gets new servo values if available and process any sensor data } +#elif defined _VARIANT_ARDUINO_STM32_ +void onTimer(stimer_t *htim) { + if (IBusBMfirst) IBusBMfirst->loop(); // gets new servo values if available and process any sensor data +} +#elif defined _RENESAS_RA_ +FspTimer _fspTimer; +void onTimerCallback(timer_callback_args_t __attribute((unused))* p_args) +{ + if (IBusBMfirst) IBusBMfirst->loop(); +} #else void onTimer() { if (IBusBMfirst) IBusBMfirst->loop(); // gets new servo values if available and process any sensor data @@ -144,9 +154,27 @@ void IBusBM::begin(HardwareSerial &serial, int8_t timerid, int8_t rxPin, int8_t NVIC_EnableIRQ(TIMER4_IRQn); NRF_TIMER4->TASKS_START = 1; // Start TIMER2 + + #elif defined(_RENESAS_RA_) + uint8_t timer_type = GPT_TIMER; + int timerIndex = FspTimer::get_available_timer(timer_type); + if (timerIndex < 0) + { + // Failed. Force it to get any timer even AGT_TIMER + int timerIndex = FspTimer::get_available_timer(timer_type, true); + } + if (timerIndex > -1) + { + // We have a valid timer. Proceed to set the timer + FspTimer::force_use_of_pwm_reserved_timer(); + _fspTimer.begin(TIMER_MODE_PERIODIC, timer_type, timerIndex, 1000, 0.0f, onTimerCallback); + _fspTimer.setup_overflow_irq(); + _fspTimer.open(); + _fspTimer.start(); + } #else // It should not be too difficult to support additional architectures as most have timer functions, but I only tested AVR and ESP32 - #warning "Timing only supportted for AVR, ESP32 and STM32 architectures. Use timerid IBUSBM_NOTIMER" + #warning "Timing only supportted for AVR, ESP32, Renesas_Uno and STM32 architectures. Use timerid IBUSBM_NOTIMER" #endif #endif } diff --git a/src/IBusBM.h b/src/IBusBM.h index 9287d43..fb33a3b 100644 --- a/src/IBusBM.h +++ b/src/IBusBM.h @@ -15,7 +15,10 @@ #if defined(ARDUINO_ARCH_MBED) #include "mbed.h" -#include "HardwareSerial.h" + #include "mbed.h" + #include "HardwareSerial.h" +#elif defined(_RENESAS_RA_) + #include "FspTimer.h" #endif // if you have an opentx transciever you can add additional sensor types here. @@ -32,9 +35,9 @@ #if defined(ARDUINO_ARCH_MBED) #define HardwareSerial arduino::HardwareSerial #else - #if !defined(ARDUINO_ARCH_MEGAAVR) -class HardwareSerial; - #endif + #if !defined(ARDUINO_ARCH_MEGAAVR) && !defined(_RENESAS_RA_) + class HardwareSerial; + #endif #endif class Stream;