Browse Source

docs: Added intial documentation for UPM and start of a porting walkthrough

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
Brendan Le Foll 10 years ago
parent
commit
e24df89ebd
7 changed files with 152 additions and 9 deletions
  1. 3
    1
      Doxyfile.in
  2. 12
    7
      README.md
  3. 31
    0
      docs/building.md
  4. 16
    0
      docs/contributions.md
  5. 24
    0
      docs/naming.md
  6. 64
    0
      docs/porting.md
  7. 2
    1
      examples/es08a.cxx

+ 3
- 1
Doxyfile.in View File

@@ -754,6 +754,7 @@ WARN_LOGFILE           =
754 754
 # Note: If this tag is empty the current directory is searched.
755 755
 
756 756
 INPUT                  = @CMAKE_CURRENT_SOURCE_DIR@/src \
757
+                         @CMAKE_CURRENT_SOURCE_DIR@/docs \
757 758
                          @CMAKE_CURRENT_SOURCE_DIR@/README.md
758 759
 
759 760
 # This tag can be used to specify the character encoding of the source files
@@ -863,7 +864,8 @@ EXCLUDE_SYMBOLS        =
863 864
 # that contain example code fragments that are included (see the \include
864 865
 # command).
865 866
 
866
-EXAMPLE_PATH           = @CMAKE_CURRENT_SOURCE_DIR@/examples/
867
+EXAMPLE_PATH           = @CMAKE_CURRENT_SOURCE_DIR@/examples/ \
868
+                         @CMAKE_CURRENT_SOURCE_DIR@/docs/
867 869
 
868 870
 # If the value of the EXAMPLE_PATH tag contains directories, you can use the
869 871
 # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and

+ 12
- 7
README.md View File

@@ -12,15 +12,20 @@ to provide identification/pin location on the board.
12 12
 Typically an update() function will be called in order to get new data from the
13 13
 sensor in order to reduce load when doing multiple reads to sensor data.
14 14
 
15
-A basic sensor is expected to work as such:
16
-s = new sensor();
17
-print(sensor->read());
18
-sleep(1);
19
-s->update();
20
-print(sensor->read();
15
+### Example
16
+
17
+A sensor/acturo is expected to work as such (here is the servo ES08A api):
18
+@snippet es08a.cxx Interesting
21 19
 
22 20
 However implementation and API design is compeltely up to the developer, some
23 21
 enumerable sensors for example may provide much clever instanciation. Displays
24 22
 may also create more complex structures in order to interface with them.
25 23
 
26
-For more information on maa, see the maa documentation
24
+### Building UPM
25
+
26
+See @ref building
27
+
28
+### Making your own UPM module
29
+
30
+@ref porting has more information on making new UPM modules
31
+

+ 31
- 0
docs/building.md View File

@@ -0,0 +1,31 @@
1
+Building UPM                         {#building}
2
+============
3
+
4
+UPM uses cmake in order to make compilation relatively painless. Cmake runs
5
+build out of tree so the recommended way is to clone from git and make a build/
6
+directory.
7
+
8
+UPM will attempt to build all directories inside src/ and they must contain
9
+individual CMakeLists.txt files.
10
+
11
+~~~~~~~~~~~~~{.sh}
12
+mkdir build
13
+cd build
14
+cmake ..
15
+make
16
+~~~~~~~~~~~~~
17
+
18
+Our cmake configure has a number of options, `cmake -i` will ask you all sorts
19
+of interesting questions, you can disable swig modules, build documentation
20
+etc...
21
+
22
+Few recommended options:
23
+Changing install path from /usr/local to /usr
24
+-DCMAKE_INSTALL_PREFIX:PATH=/usr
25
+
26
+Building debug build:
27
+-DCMAKE_BUILD_TYPE=DEBUG
28
+
29
+Using clang instead of gcc:
30
+ -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang
31
+

+ 16
- 0
docs/contributions.md View File

@@ -0,0 +1,16 @@
1
+Contributing a module                         {#contributions}
2
+=====================
3
+
4
+Here are the rules of contribution:
5
+- Try not to break master. In any commit.
6
+- Commits must have a sign-off line by everyone who reviewed them
7
+- Commits must be named <file/module>: Some decent description
8
+- You must license your module under an FOSS license. The recommended license
9
+  is MIT but any permissive license is fine. Please consider that people using
10
+  UPM may want to write proprietary programs with your sensors so we like to
11
+  avoid GPL. (LGPL is fine). If your license is not MIT please include a
12
+  LICENSE file in src/<mymodule>/
13
+- Please test your module builds before contributing and make sure it works on
14
+  the latest version of maa. If you tested on a specific board/platform please
15
+  tell us what this was in your PR.
16
+

+ 24
- 0
docs/naming.md View File

@@ -0,0 +1,24 @@
1
+Naming a module                         {#naming}
2
+===============
3
+
4
+UPM attemps to follow a clear naming pattern. Modules should be sensibly named
5
+and then placed in /usr/lib/upm and headers in /usr/include/upm.
6
+
7
+### Choosing a name
8
+
9
+1. Pick a name
10
+2. Use it
11
+
12
+### Rules for name picking
13
+
14
+1. Your lib must belong to namespace UPM
15
+2. Usually picking the name of the chip of your sensor/actuator might make
16
+sense. Other times this does not. Try to pick a generic name so people with a
17
+similar sensor can inherit your class if they only have minor changes.
18
+3. Avoid brand names
19
+
20
+### Doubt
21
+
22
+If ever, give me a ping via email: brendan.le.foll@intel.com and I'll try
23
+suggest decent names for your module.
24
+

+ 64
- 0
docs/porting.md View File

@@ -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
+

+ 2
- 1
examples/es08a.cxx View File

@@ -34,11 +34,12 @@ main(int argc, char **argv)
34 34
     //! [Interesting]
35 35
     upm::ES08A *servo = new upm::ES08A(5);    
36 36
     servo->setAngle (180);
37
+    //! [Interesting]
38
+
37 39
     servo->setAngle (90);
38 40
     servo->setAngle (0);
39 41
     servo->setAngle (90);
40 42
     servo->setAngle (180);
41
-    //! [Interesting]
42 43
 
43 44
     std::cout << "exiting application" << std::endl;
44 45