Development GenericI2CSensor

LinuxJohannes edited this page Jan 25, 2014 · 1 revision

Quick Links

Clone this wiki locally

Generic I2C Sensor Module


This module is intended to allow users to collect (and log via telemetry) data from external I2C sensors attached to the flight controller board.

This is accomplished by running a "program" on an embedded virtual machine inside of the flight controller firmware.

Using the module

First, make sure the module is enabled. This module may be compiled as an Optional Module and may need to be specifically enabled before it does anything. See Optional Modules.

Select the program that you want to run on the virtual machine. This is set via the ModuleSettings.I2CVMProgramSelect field.

You will now need to save your configuration and reboot before it will take effect.

If you have selected one of the built-in programs, congratulations, your board should be running it now.

If you want to provide your own custom program to run on the virtual machine, you need a few more steps.

NOTE: The GUI for making an I2C program and compiling it to the bytecode for the virtual machine has not been finished. You will currently need to hand-assemble the bytecode if you really, really want to run your own program.

Populate the bytecode in the I2CVMUserProgram.Program UAVO field.

Save to flash. Reboot. Congratulations, you are now running your new program.

Where does my sensor data go?

At key intervals in the selected program's execution, it will provide sensor readings in the I2CVM UAVO. The exact meaning of the values contained in the I2CVM UAVO's fields will depend on which program you have selected above.

Developer Information

Where's the code

This module is officially named GenericI2CSensor and its code can be found in ./flight/Modules/GenericI2CSensor.

How it works

On initialization, the module uses ModuleSettings.I2CVMProgramSelect to choose a program to run on the I2C virtual machine. The program may be one of the built-in programs or alternatively may be a user-supplied program stored in the I2CVMUserProgram UAVO.

The module starts a FreeRTOS task (GenericI2CSensor) and starts the I2C virtual machine and passes it the selected program to run.

The module will run the selected program repeatedly until the board is powered off.

I2C Virtual Machine

The I2C virtual machine is a very simple emulated machine that executes bytecode that is passed to it during VM initialization.

The instruction set (and a very minimal assembler) for the virtual machine is defined in ./shared/api/i2c_vm_asm.h and the virtual machine implementation is in ./flight/Modules/GenericI2CSensor/i2c_vm.c.