1Porting a module from Arduino                         {#porting}
2=============================
3
4Porting arduino libraries to libmraa as UPM libraries is usually fairly easy.
5The issues typically come from misunderstanding of how a non real time OS deals
6with interrupts and timers. It also highly depends on the sensor. A concrete
7example is explained in detail on @ref max31855
8
9### Adding a new module to UPM
10
111. Choose a name for your module (see @ref naming)
122. Make a new folder in src/modulename
133. Create a CMakeLists.txt file inside src/modulename
14
15### CmakeLists.txt
16
17By default you need a header called modulename.h and a C++ file called
18modulename.cxx. You can have multiple headers and source files. Only public
19headers need to be added to module_h and all source files need to be in
20module_src.
21
22~~~~~~~~~~~
23set (libname "modulename")
24set (libdescription "Module Description")
25set (module_src ${libname}.cxx)
26set (module_h ${libname}.h)
27upm_module_init()
28~~~~~~~~~~~
29
30### Making your API
31
32The easiest way to do this is to have a look at a similar sensor to yours.
33Typically create a class for your sensor with a constructor that defines the
34pins it is on. This constructor will create the mraa_*_context structs that are
35required to talk to the board's IO. An I2c sensor will create a
36mraa_i2c_context, keep it as a private member and require a bus number and slave
37address in it's constructor.
38
39Typically in sensors a simple object->read() function is preferred, depending on
40your sensor/actuator this may or may not be easy or not even make sense. Most
41UPM APIs have a simple set of functions.
42
43### Mapping arduino API to libmraa
44
45Your constructor is similar to the setup() function in arduino, you should
46initialise your IO the way you want it. This means initialising contexts
47(private members) and setting the correct modes for them.
48
49See the mraa API documentation for exact API.
50
51### Building
52
53To build your module just follow @ref building. By creating a folder and the
54CMakelists.txt file you have done all that is required to add your sensor to
55the UPM build system.
56
57### Sending your module to us for inclusion in UPM
58
59The last step is when you're happy with your module and it works send us a pull
60request! We'd love to include your sensor in our repository.
61
62If you don't like github you can also send mihai.tudor.panu@intel.com a git
63formatted patch of your sensor. More details are on @ref contributions and on
64https://help.github.com/articles/creating-a-pull-request
65
66