diff --git a/Porting-to-non-Arduino-Platforms.md b/Porting-to-non-Arduino-Platforms.md index 5a2f2eb..bc15c37 100644 --- a/Porting-to-non-Arduino-Platforms.md +++ b/Porting-to-non-Arduino-Platforms.md @@ -1,46 +1,3 @@ # 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); - -// callback argument macro -// the first argument is the return type of the wrapper function -// the second argument is the name of the corresponding Arduino function -// all other arguments are the arguments of the wrapper function -#define RADIOLIB_CB_ARGS_DIGITAL_WRITE (void, digitalWrite, 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). - -Once done, the last thing left to do is to initialize all callbacks defined in the `noarduino.h` file. The callbacks themselves are generated by RadioLib - the user only has to call the initalizing functions: - -```c++ -// some random NSS/IRQ/RST/GPIO pins -Module mod(1, 2, 3, 4); -SX1278 radio(&mod); - -(...) -mod.setCb_digitalRead(::wrap_HAL_GPIO_ReadPin); -mod.setCb_digitalWrite(::wrap_HAL_GPIO_WritePin); -// etc. for all the callbacks -(...) - -// we can go now! -radio.begin(); -``` \ No newline at end of file +Under construction - in the meantime, see https://github.com/jgromes/RadioLib/blob/master/examples/NonArduino/Raspberry/main.cpp for an example. \ No newline at end of file