Skip to content

How the Firmware Works

vroland edited this page Oct 1, 2015 · 3 revisions

Program Flow of the MyoBridge Firmware

This article shows how the MyoBridge Firmware works in general. Read this, if you want to modify the firmware, adapt it for another purpose or just want to understand the code. If you just want to use the firmware with the Arduino library, this article might not be for you. Basic understanding of Bluetooth Low Energy is required.

Always consider looking at the MyoBridge Firmware Source Documentation, too!

General Program Flow

The diagram below shows how the firmware normally runs. Note that the system state notified via the serial protocol results from the program flow described here.

Serial Communication

There is an extra page for the [serial communication protocol](Serial Protocol).

GATT discovery

If no cached GATT handles are available for the connected Myo, they must first be discovered. For this, the Firmware goes through all services listed in the Myo Bluetooth Protocol header. For all services, three steps are needed:

  1. Service discovery. Discover the service start and end handles using GATT_DiscPrimaryServiceByUUID(). When this function is called, the program is set into MYB_DIS_THE_SERVICE_SERV (e.g. MYB_DIS_CONTRL_SERV) and waits for a GATT response. This response contains the start and end handle of the service, which are stored in myo_handles.
  2. When this procedure is complete, the program sets the state MYB_DIS_THE_SERVICE_CHAR (e.g. MYB_DIS_CONTRL_CHAR). GATT_DiscAllChars() is called to discover all characteristic handles in the service handle range, which are also stored in myo_handles.
  3. To be able to receive notifications or indications from the GATT Server (The Myo Armband), the user has to be able to set the Client Characteristic Config Descriptor (CCCD) values for the respective characteristic. That is why the program enters a third state per service, MYB_DES_THE_SERVICE_SERV (e.g. MYB_DES_CONTRL_SERV). A call to GATT_DiscAllCharDescs() causes the firmware to receive multiple GATT Messages, from which it picks the ones which contain CCCD handles and stores these in myo_cccd_handles, after matching them with their respective characteristic.

This process is then repeated for all Myo Services: ControlSerice, ImuDataService, ClassifierService, EmgData Service and BatteryService.

If MyoBridge reconnects to the same Myo after a disconnect, it uses the previously discovered handles and skips this step.