How modify code =============== .. toctree:: :maxdepth: 3 :caption: Contents: The code proposed is just made to be used as example and propose an architecture. Any compatible library can be integrated, and included library can be reused in other projects. Platform support ---------------- Framework: - Arduino This code is made to be used with: - All General configuration --------------------- To be able to read sensors on your platform, some configurations are needed, especially the GPIO assignments for the SPI bus. Everything is located in the `src/common.hpp` file. GPIO ^^^^ Adjust the GPIO assignments with directly modifying the :cpp:struct:`PIN_CONFIG` structure. Depending of the wiring chosen, this fields should be modified: .. code-block:: cpp struct PIN_CONFIG { uint8_t pinSS = SS; uint8_t pinMmcSS = 11U; uint8_t pinLpsSS = 9U; uint8_t pinMosi = 12U; uint8_t pinMiso = 13U; uint8_t pinClk = 14U; }; .. attention:: Do not forget to adapt the pins defined in common.hpp with the ones you want to use for your board. For esp32 (non S3), avoid using the GPIO 9-10-11 as they are used for the flash memory! If the board you use has fixed SPI pins, this configurations is not needed. SPI configuration ^^^^^^^^^^^^^^^^^ The SPI configuration can also be found in `src/common.hpp` file. It is configured with the struct :cpp:struct:`GENERAL_CONFIG`: .. code-block:: cpp struct GENERAL_CONFIG { uint32_t icmSpiClock = 24000000U; // [Hz] uint32_t lpsSpiClock = 10000000U; // [Hz] uint32_t mmcSpiClock = 10000000U; // [Hz] }; Tasks ------ There is only a single task located in the loop() function. It is used to read all three sensors at 500Hz frequency. Sensors ------- A light mechanism is used to manage sensors. It is described by :cpp:class:`SENSOR_UNIT_CONFIG`. Any sensor can be modified, removed or added with the same configuration as the existing ones. The principle is the create a sensor object, set its activation state and indicate the frequency at which it should be read. Once inside the task that will be used to read the sensor, a call to :cpp:func:`SENSOR_UNIT_CONFIG::setRatio` with the current task period will complete the sensor configuration. Once inside the task's loop, a call to :cpp:func:`SENSOR_UNIT_CONFIG::checkRatio` will return true if the sensor should be read at this loop iteration. An example could be: .. code-block:: cpp // Create a sensor object which is activated and should be read at 100Hz (10ms period) SENSOR_UNIT_CONFIG sensorTest = SENSOR_UNIT_CONFIG(true, 10); // Inside task setup sensorTest.setRatio(currentTask.period); // Inside task loop while(true) { if(sensorTest.checkRatio()) { // Read sensor } } Add a library to the code ------------------------- Any library code can be cloned in the `lib` folder. It will be compiled and linked with the code thanks to platformio library dependency finder. If a library is added, user just need to include its headers in the app_ins code and add include source code folders in `platformio.ini` file of app_ins folder: .. code-block:: ini build_flags = -I lib/newlib_folder/src/ ... Like explained in the :ref:`Build code` section, we can build the code with: .. code-block:: bash pio run -e your_platform and build+flash with: .. code-block:: bash pio run -e your_platform --target upload