Proposals

From Firmata

Jump to: navigation, search

This is a place to propose extensions to the Firmata protocol

Contents

SysEx

The idea for SysEx is to have a second command space using the first byte after the SysEx Start byte. The key difference is that the data can be of any size, rather than just one or two bytes for standard MIDI messages.

#define RESERVED_COMMAND        0x00 // 2nd SysEx data byte is a chip-specific command (AVR, PIC, TI, etc).
#define SERVO_CONFIG            0x70 // set max angle, minPulse, maxPulse, freq
#define STRING_DATA             0x71 // a string message with 14-bits per char
#define PULSE_DATA              0x74 // pulseIn/pulseOut data message (34 bits)
#define SHIFT_DATA              0x75 // shiftOut config/data message (34 bits)
#define I2C_REQUEST             0x76 // I2C request messages from a host to an I/O board
#define I2C_REPLY               0x77 // I2C reply messages from an I/O board to a host
#define I2C_CONFIG              0x78 // Configure special I2C settings such as power pins and delay times
#define REPORT_FIRMWARE         0x79 // report name and version of the firmware
#define SAMPLING_INTERVAL       0x7A // sampling interval
#define SYSEX_NON_REALTIME      0x7E // MIDI Reserved for non-realtime messages
#define SYSEX_REALTIME          0x7F // MIDI Reserved for realtime messages

pulseIn/pulseOut

/* pulseIn/Out (uses 32-bit value)
 * -------------------------------
 * 0  START_SYSEX (0xF0) (MIDI System Exclusive)
 * 1  pulseIn/Out (0x74)
 * 2  dataPin (0-127)
 * 3  bits 0-6 (least significant byte)
 * 4  bits 7-13
 * 5  bits 14-20
 * 6  bits 21-27
 * 7  bits 28-34 (most significant byte)
 * 8  END_SYSEX (0xF7) (MIDI End of SysEx - EOX)
 */


ShiftOut

Supporting shift registers should be possible without much difficulty now that sysex has been implemented.

/* shiftIn/Out (uses 8-bit value)
 * ------------------------------
 * 0  START_SYSEX (0xF0)
 * 1  shiftOut (0x75)
 * 2  dataPin (0-127)
 * 3  clockPin (0-127)
 * 4  latchPin (0-127)
 * 5  msbFirst (boolean)
 * 6  bits 0-6 (least significant byte)
 * 7  bit 7 (most significant bit)
 * n  ... (as many byte pairs as needed)
 * n+1  END_SYSEX (0xF7)
 */

Or perhaps this should be more like the servo messages, with a SET_PIN_MODE-specific mode, like SHIFT, then a SHIFT_CONFIG message.

/* shiftIn/Out config
 * ------------------------------
 * 0  START_SYSEX (0xF0)
 * 1  SHIFT_CONFIG
 * 2  dataPin (0-127)
 * 3  clockPin (0-127)
 * 4  latchPin (0-127)
 * 5  msbFirst (boolean)
 * 6  END_SYSEX (0xF7)
 */


/* shiftIn/Out data (total bits chopped to multiple of 8 so extra bits are ignored)
 * ------------------------------
 * 0   START_SYSEX (0xF0)
 * 1   SHIFT_DATA
 * 2   dataPin (0-127)
 * 3   bits 0-6 (least significant byte)
 * 4   bits 7-13
 * 5   bits 14-20
 * 6   bits 21-27
 * n   ...
 * n+1 END_SYSEX (0xF7)
 */


Hardware Pin Querying

Get the available pins and resolution that the device supports.

/* hardwareSetup query request
 * ------------------------------
 * 0  START_SYSEX (0xF0)
 * 1  hardwareSetup (0x??)
 * 2  END_SYSEX (0xF7)
 */
/* hardwareSetup data message
 * ------------------------------
 * 0  START_SYSEX (0xF0)
 * 1  hardwareSetup (0x??)
 * 2  analog pins (0-127)
 * 3  analog resolution (0-127)
 * 4  digital pins (0-127)
 * 5  PWM resolution (0-127)
 * 6  PWM pin (0-127)
 * 7  next PWM pin (0-127)
 * ...
 * n  END_SYSEX (0xF7)
 */


Report Available Pin Modes

This is from a proposal by Shigeru. This is tricky because it needs to be a giant bitmask with each bit representing a boolean value of whether that pin mode is supported or not. This is basically like a HID Descriptor. This version removes the "number of pins" value of Shigeru's proposal. The number of pins can be easily derived from the number of bytes.

/* availablePinModes
 * ------------------------------
 * 0  START_SYSEX (0xF0)
 * 1  availablePinModes (0x??)
 * 2  The available pin modes for the 0th pin (0b0000000-0b1111111)
 * 3  The available pin modes for the 1st pin (0b0000000-0b1111111)
 * ...
 * n  END_SYSEX (0xF7)
 */

Report Pin Configuration

This is from a proposal by Shigeru, Massimo has also expressed interest in having an API for reporting pin configurations. This version removes the "number of pins" value of Shigeru's proposal. The number of pins can be easily derived from the number of bytes.

/* pinSettings
 * ------------------------------
 * 0  START_SYSEX (0xF0)
 * 1  pinSettings (0x??)
 * 2  port mode of the 0th pin (0-6)
 * 3  resolution of the 0th pin (0-127)
 * 4  port mode of the 1st pin (0-6)
 * 5  resolution of the 1st pin (0-127)
 * ...
 * n  END_SYSEX (0xF7)
 */


Query Pull-up Resistor Status

When a digital pin is in INPUT mode, setting the pin HIGH will turn on the internal pull-up resistors. It could be useful to query the state of that pin somehow.

SPI

There has been some preliminary work done on including SPI in Firmata. It would most likely be based on SysEx.

Personal tools