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