From 90799f95b1f55970d337ee4fd4089485287762b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Grome=C5=A1?= Date: Sun, 28 Aug 2022 16:53:47 +0200 Subject: [PATCH] Created Porting to non-Arduino Platforms (markdown) --- Porting-to-non-Arduino-Platforms.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Porting-to-non-Arduino-Platforms.md diff --git a/Porting-to-non-Arduino-Platforms.md b/Porting-to-non-Arduino-Platforms.md new file mode 100644 index 0000000..5a4580e --- /dev/null +++ b/Porting-to-non-Arduino-Platforms.md @@ -0,0 +1,24 @@ +# Porting to non-Arduino Platforms + +There are several things that have to be done to port RadioLib to a non-Arduino platform. First, since RadioLib is written in C++, you have to make sure your build system can compile C++ files. Next, you have to make sure your build system DOES NOT define the macro `ARDUINO`. If this macro is defined, RadioLib will attempt to automatically detect which Arduino is being used. If the macro is not defined, RadioLib will attempt to include the file `noarduino.h`, which has to be provided by your build system (e.g. by using GCC's `-I` flag). + +The `noarduino.h` file has to define all the platform macros shown in [Custom Build Configuration](https://github.com/jgromes/RadioLib/wiki/Custom-Build-Configuration) - this includes callbacks to Arduino functions, like `digitalRead()`, or `tone()`. Therefore, your platform has to define an equivalent of these functions. For example, in STM32 HAL, there's a function `HAL_GPIO_WritePin()`, which behaves similarly as Arduino `digitalWrite()`, but has an extra argument - the GPIO port. Therefore, an appropriate wrapper should look something like this: + +```c++ +// noarduino.h +// forward declaration +void wrap_HAL_GPIO_WritePin(uint8_t pin, uint8_t value); +#define RADIOLIB_CB_ARGS_DIGITAL_WRITE (void, wrap_HAL_GPIO_WritePin, uint32_t pin, GPIO_PinState value) + +// noarduino.c/cpp +// now the implementation - pin number also includes the GPIOx port +void wrap_HAL_GPIO_WritePin(uint32_t pin, GPIO_PinState value) { + if(pin > 16) { + HAL_GPIO_WritePin(GPIOB, uint16_t pin, GPIO_PinState value); + } else { + HAL_GPIO_WritePin(GPIOA, uint16_t pin, GPIO_PinState value); + } +} +``` + +This has to be done for all Arduino functions listed on the page [Custom Build Configuration](https://github.com/jgromes/RadioLib/wiki/Custom-Build-Configuration). \ No newline at end of file