mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 21:17:29 +03:00
65 lines
2.4 KiB
Markdown
65 lines
2.4 KiB
Markdown
![]() |
Porting a module from Arduino {#porting}
|
||
|
=============================
|
||
|
|
||
|
Porting arduino libraries to libmaa as UPM libraries is usually fairly easy.
|
||
|
The issues typically come from misunderstanding of how a non real time OS deals
|
||
|
with interupts and timers. It also highly depends on the sensor.
|
||
|
|
||
|
### Adding a new module to UPM
|
||
|
|
||
|
1. Choose a name for your module (see @ref naming)
|
||
|
2. Make a new folder in src/<modulename>
|
||
|
3. Create a CMakeLists.txt file inside src/<modulename>
|
||
|
|
||
|
### CmakeLists.txt
|
||
|
|
||
|
By default you need a header called <modulename>.h and a C++ file called
|
||
|
<modulename>.cxx. You can have multiple headers and source files. Only public
|
||
|
headers need to be added to module_h and all source files need to be in
|
||
|
module_src.
|
||
|
|
||
|
~~~~~~~~~~~
|
||
|
set (libname "modulename")
|
||
|
set (libdescription "Module Description")
|
||
|
set (module_src ${libname}.cxx)
|
||
|
set (module_h ${libname}.h)
|
||
|
upm_module_init()
|
||
|
~~~~~~~~~~~
|
||
|
|
||
|
### Making your API
|
||
|
|
||
|
The easiest way to do this is to have a look at a similar sensor to yours.
|
||
|
Typically create a class for your sensor with a constructor that defines the
|
||
|
pins it is on. This constructor will create the maa_*_context structs that are
|
||
|
required to talk to the board's IO. An I2c sensor will create a
|
||
|
maa_i2c_context, keep it as a private member and require a bus number and slave
|
||
|
address in it's constructor.
|
||
|
|
||
|
Typically in sensors a simple object->read() function is prefered, depending on
|
||
|
your sensor/actuaotr this may or may not be easy or not even make sense. Most
|
||
|
UPM apis have a simple set of functions.
|
||
|
|
||
|
### Mapping arduino API to libmaa
|
||
|
|
||
|
Your constructor is similar to the setup() function in arduino, you should
|
||
|
initialise your IO the way you want it. This means initialising contexts
|
||
|
(private members) and setting the correct modes for them.
|
||
|
|
||
|
See the maa API documentation for exact API.
|
||
|
|
||
|
### Building
|
||
|
|
||
|
To build your module just follow @ref building. By creating a folder and the
|
||
|
CMakelists.txt file you have done all that is required to add your sensor to
|
||
|
the UPM build system.
|
||
|
|
||
|
### Sending your module to us for inclusion in UPM
|
||
|
|
||
|
The last step is when you're happy with your module and it works send us a pull
|
||
|
request! We'd love to include your sensor in our repository.
|
||
|
|
||
|
If you don't like github you can also send brendan.le.foll@intel.com a git
|
||
|
formatted patch if your sensor. More details are on @ref contributing and on
|
||
|
https://help.github.com/articles/creating-a-pull-request
|
||
|
|