2014-06-13 11:53:51 +01:00
|
|
|
Porting a module from Arduino {#porting}
|
|
|
|
=============================
|
|
|
|
|
2014-06-25 10:05:27 +01:00
|
|
|
Porting arduino libraries to libmraa as UPM libraries is usually fairly easy.
|
2014-06-13 11:53:51 +01:00
|
|
|
The issues typically come from misunderstanding of how a non real time OS deals
|
2015-03-04 11:22:56 -08:00
|
|
|
with interrupts and timers. It also highly depends on the sensor. A concrete
|
2014-06-13 16:44:48 +01:00
|
|
|
example is explained in detail on @ref max31855
|
2014-06-13 11:53:51 +01:00
|
|
|
|
|
|
|
### Adding a new module to UPM
|
|
|
|
|
|
|
|
1. Choose a name for your module (see @ref naming)
|
2014-08-28 17:59:21 +01:00
|
|
|
2. Make a new folder in src/modulename
|
|
|
|
3. Create a CMakeLists.txt file inside src/modulename
|
2014-06-13 11:53:51 +01:00
|
|
|
|
|
|
|
### CmakeLists.txt
|
|
|
|
|
2016-04-28 17:21:20 -07:00
|
|
|
By default you need a header called modulename.hpp and a C++ file called
|
2014-08-28 17:59:21 +01:00
|
|
|
modulename.cxx. You can have multiple headers and source files. Only public
|
2016-04-28 17:21:20 -07:00
|
|
|
headers need to be added to module_hpp and all source files need to be in
|
2014-06-13 11:53:51 +01:00
|
|
|
module_src.
|
|
|
|
|
|
|
|
~~~~~~~~~~~
|
|
|
|
set (libname "modulename")
|
|
|
|
set (libdescription "Module Description")
|
|
|
|
set (module_src ${libname}.cxx)
|
2016-04-28 17:21:20 -07:00
|
|
|
set (module_hpp ${libname}.hpp)
|
2014-06-13 11:53:51 +01:00
|
|
|
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
|
2014-06-25 10:05:27 +01:00
|
|
|
pins it is on. This constructor will create the mraa_*_context structs that are
|
2014-06-13 11:53:51 +01:00
|
|
|
required to talk to the board's IO. An I2c sensor will create a
|
2014-06-25 10:05:27 +01:00
|
|
|
mraa_i2c_context, keep it as a private member and require a bus number and slave
|
2014-06-13 11:53:51 +01:00
|
|
|
address in it's constructor.
|
|
|
|
|
2015-03-04 11:22:56 -08:00
|
|
|
Typically in sensors a simple object->read() function is preferred, depending on
|
|
|
|
your sensor/actuator this may or may not be easy or not even make sense. Most
|
|
|
|
UPM APIs have a simple set of functions.
|
2014-06-13 11:53:51 +01:00
|
|
|
|
2014-06-25 10:05:27 +01:00
|
|
|
### Mapping arduino API to libmraa
|
2014-06-13 11:53:51 +01:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2014-06-25 10:05:27 +01:00
|
|
|
See the mraa API documentation for exact API.
|
2014-06-13 11:53:51 +01:00
|
|
|
|
|
|
|
### 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.
|
|
|
|
|
2021-07-23 12:58:00 -07:00
|
|
|
More details on @ref contributions and on
|
2014-06-13 11:53:51 +01:00
|
|
|
https://help.github.com/articles/creating-a-pull-request
|
|
|
|
|