| 1 | Adding a new driver class takes a few steps: |
| 2 | |
| 3 | * Add the class in the class enumeration |
| 4 | * Add a header describing the class |
| 5 | * its request functions |
| 6 | * a structure containing pointer to request functions |
| 7 | * utility function prototypes (blocking request wrappers, …) [1] |
| 8 | * Add reference to the class in the driver structure |
| 9 | * Add a directory for the class |
| 10 | * Add a C-file with utility functions [1] |
| 11 | |
| 12 | [1]: This is only needed if the class has such utility functions. |
| 13 | |
| 14 | |
| 15 | In the examples, we'll call the new class `foobar`. |
| 16 | |
| 17 | = Adding the class in the device type enumeration = |
| 18 | |
| 19 | Edit [source:trunk/mutekh/hexo/include/hexo/device.h hexo/include/hexo/device.h], you'll see a `enum device_class_e`. Add the new device type at the end. |
| 20 | |
| 21 | {{{ |
| 22 | device_class_lcd, |
| 23 | device_class_gpio, |
| 24 | device_class_i2c, |
| 25 | + device_class_foobar, |
| 26 | }; |
| 27 | }}} |
| 28 | |
| 29 | = Adding a header describing the class = |
| 30 | |
| 31 | Create a file in `driver/include/device/foobar.h`. It may contain |
| 32 | |
| 33 | * Callback definitions, |
| 34 | * Request function prototypes, |
| 35 | * Global utility functions. |
| 36 | |
| 37 | See [source:trunk/mutekh/driver/include/device/char.h] for sample file. |
| 38 | |
| 39 | The `struct dev_class_foobar_s` is a structure holding all the class-specific request functions. |
| 40 | You may ensure this structure holds less pointers than the `DRV_MAX_FUNC_COUNT` |
| 41 | constant defined in [source:trunk/mutekh/driver/include/device/driver.h]. |
| 42 | |
| 43 | Don't forget to protect the new header against circular inclusions with the lines: |
| 44 | {{{ |
| 45 | #ifndef __DEVICE_FOOBAR_H__ |
| 46 | #define __DEVICE_FOOBAR_H__ |
| 47 | |
| 48 | #endif |
| 49 | }}} |
| 50 | We'll use that macro later. |
| 51 | |
| 52 | = Adding a reference to the class in the driver structure = |
| 53 | |
| 54 | Edit [source:trunk/mutekh/driver/include/device/driver.h] and add an entry in the `f` union of the `struct driver_s`. |
| 55 | |
| 56 | You must protect it with the macros defined in the header of the class, in case the class is not included in legacy code. |
| 57 | |
| 58 | Dont `#include` your driver class in `driver.h`. |
| 59 | |
| 60 | {{{ |
| 61 | #ifdef __DEVICE_FOOBAR_H__ |
| 62 | struct dev_class_foobar_s foobar; |
| 63 | #endif |
| 64 | }}} |
| 65 | |
| 66 | = Create a directory for the class = |
| 67 | |
| 68 | * create a `driver/device/foobar` directory, |
| 69 | * add a Makefile inside it, |
| 70 | * add `foobar` in the list of subdirectories in `driver/device/Makefile`. |
| 71 | |
| 72 | = Create the global helper functions file for your class = |
| 73 | |
| 74 | * create a `driver/device/foobar/device_foobar.c`, |
| 75 | * add it in `driver/device/foobar/Makefile`. |