-
Notifications
You must be signed in to change notification settings - Fork 418
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 - 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:
// 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.