{
  "name": "GPIO",
  "status": "experimental",
  "shortId": "gpio",
  "camelName": "GPIO",
  "shortName": "GPIO",
  "extends": [
    "_base",
    "_sensor"
  ],
  "notes": {
    "short": "Access to General Purpose Input/Output (GPIO) pins on a board.\nThe pins are indexed `0 ... num_pins-1`.\nThe indexing does not correspond to hardware pin names, nor labels on the board (see `get_pin_info` command for that),\nand should **not** be exposed to the user."
  },
  "classIdentifier": 282614377,
  "enums": {
    "Mode": {
      "name": "Mode",
      "storage": 1,
      "members": {
        "Off": 0,
        "OffPullUp": 16,
        "OffPullDown": 32,
        "Input": 1,
        "InputPullUp": 17,
        "InputPullDown": 33,
        "Output": 2,
        "OutputHigh": 18,
        "OutputLow": 34,
        "AnalogIn": 3,
        "Alternative": 4,
        "BaseModeMask": 15
      }
    },
    "Capabilities": {
      "name": "Capabilities",
      "storage": 2,
      "isFlags": true,
      "members": {
        "PullUp": 1,
        "PullDown": 2,
        "Input": 4,
        "Output": 8,
        "Analog": 16
      }
    }
  },
  "constants": {},
  "packets": [
    {
      "kind": "report",
      "name": "command_not_implemented",
      "identifier": 3,
      "description": "This report may be emitted by a server in response to a command (action or register operation)\nthat it does not understand.\nThe `service_command` and `packet_crc` fields are copied from the command packet that was unhandled.\nNote that it's possible to get an ACK, followed by such an error report.",
      "fields": [
        {
          "name": "service_command",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        },
        {
          "name": "packet_crc",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        }
      ],
      "identifierName": "command_not_implemented",
      "packFormat": "u16 u16",
      "derived": "_base"
    },
    {
      "kind": "const",
      "name": "instance_name",
      "identifier": 265,
      "description": "A friendly name that describes the role of this service instance in the device.\nIt often corresponds to what's printed on the device:\nfor example, `A` for button A, or `S0` for servo channel 0.\nWords like `left` should be avoided because of localization issues (unless they are printed on the device).",
      "fields": [
        {
          "name": "_",
          "type": "string",
          "storage": 0
        }
      ],
      "optional": true,
      "identifierName": "instance_name",
      "packFormat": "s",
      "derived": "_base"
    },
    {
      "kind": "ro",
      "name": "status_code",
      "identifier": 259,
      "description": "Reports the current state or error status of the device. ``code`` is a standardized value from \nthe Jacdac status/error codes. ``vendor_code`` is any vendor specific error code describing the device\nstate. This report is typically not queried, when a device has an error, it will typically\nadd this report in frame along with the announce packet. If a service implements this register,\nit should also support the ``status_code_changed`` event defined below.",
      "fields": [
        {
          "name": "code",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        },
        {
          "name": "vendor_code",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        }
      ],
      "optional": true,
      "identifierName": "status_code",
      "packFormat": "u16 u16",
      "derived": "_base"
    },
    {
      "kind": "rw",
      "name": "client_variant",
      "identifier": 9,
      "description": "An optional register in the format of a URL query string where the client can provide hints how\nthe device twin should be rendered. If the register is not implemented, the client library can simulate the register client side.",
      "fields": [
        {
          "name": "_",
          "type": "string",
          "storage": 0
        }
      ],
      "optional": true,
      "identifierName": "client_variant",
      "packFormat": "s",
      "derived": "_base"
    },
    {
      "kind": "event",
      "name": "status_code_changed",
      "identifier": 4,
      "description": "Notifies that the status code of the service changed.",
      "fields": [
        {
          "name": "code",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        },
        {
          "name": "vendor_code",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        }
      ],
      "optional": true,
      "identifierName": "status_code_changed",
      "packFormat": "u16 u16",
      "derived": "_base"
    },
    {
      "kind": "rw",
      "name": "streaming_samples",
      "identifier": 3,
      "description": "Asks device to stream a given number of samples\n(clients will typically write `255` to this register every second or so, while streaming is required).",
      "fields": [
        {
          "name": "_",
          "unit": "#",
          "type": "u8",
          "storage": 1,
          "isSimpleType": true
        }
      ],
      "internal": true,
      "identifierName": "streaming_samples",
      "packFormat": "u8",
      "derived": "_sensor"
    },
    {
      "kind": "rw",
      "name": "streaming_interval",
      "identifier": 4,
      "description": "Period between packets of data when streaming in milliseconds.",
      "fields": [
        {
          "name": "_",
          "unit": "ms",
          "type": "u32",
          "storage": 4,
          "isSimpleType": true,
          "defaultValue": 100,
          "typicalMin": 1,
          "typicalMax": 60000
        }
      ],
      "identifierName": "streaming_interval",
      "packFormat": "u32",
      "derived": "_sensor"
    },
    {
      "kind": "const",
      "name": "streaming_preferred_interval",
      "identifier": 258,
      "description": "Preferred default streaming interval for sensor in milliseconds.",
      "fields": [
        {
          "name": "_",
          "unit": "ms",
          "type": "u32",
          "storage": 4,
          "isSimpleType": true
        }
      ],
      "internal": true,
      "optional": true,
      "identifierName": "streaming_preferred_interval",
      "packFormat": "u32",
      "derived": "_sensor"
    },
    {
      "kind": "ro",
      "name": "state",
      "identifier": 257,
      "description": "For every pin set to `Input*` the corresponding **bit** in `digital_values` will be `1` if and only if\nthe pin is high.\nFor other pins, the bit is `0`.\nThis is normally streamed at low-ish speed, but it's also automatically reported whenever\na digital input pin changes value (throttled to ~100Hz).\nThe analog values can be read with the `ADC` service.",
      "fields": [
        {
          "name": "digital_values",
          "type": "bytes",
          "storage": 0,
          "isSimpleType": true
        }
      ],
      "volatile": true,
      "identifierName": "reading",
      "packFormat": "b"
    },
    {
      "kind": "ro",
      "name": "num_pins",
      "identifier": 384,
      "description": "Number of pins that can be operated through this service.",
      "fields": [
        {
          "name": "_",
          "unit": "#",
          "type": "u8",
          "storage": 1,
          "isSimpleType": true,
          "absoluteMax": 128,
          "absoluteMin": 0
        }
      ],
      "packFormat": "u8"
    },
    {
      "kind": "command",
      "name": "configure",
      "identifier": 128,
      "description": "Configure (including setting the value) zero or more pins.\n`Alternative` settings means the pin is controlled by other service (SPI, I2C, UART, PWM, etc.).",
      "fields": [
        {
          "name": "pin",
          "type": "u8",
          "storage": 1,
          "isSimpleType": true,
          "startRepeats": true
        },
        {
          "name": "mode",
          "type": "Mode",
          "storage": 1
        }
      ],
      "packFormat": "r: u8 u8"
    },
    {
      "kind": "command",
      "name": "pin_info",
      "identifier": 129,
      "description": "Report capabilities and name of a pin.",
      "fields": [
        {
          "name": "pin",
          "type": "u8",
          "storage": 1,
          "isSimpleType": true
        }
      ],
      "hasReport": true,
      "packFormat": "u8"
    },
    {
      "kind": "report",
      "name": "pin_info",
      "identifier": 129,
      "description": "Report capabilities and name of a pin.",
      "fields": [
        {
          "name": "pin",
          "type": "u8",
          "storage": 1,
          "isSimpleType": true
        },
        {
          "name": "hw_pin",
          "type": "u8",
          "storage": 1,
          "isSimpleType": true
        },
        {
          "name": "capabilities",
          "type": "Capabilities",
          "storage": 2
        },
        {
          "name": "mode",
          "type": "Mode",
          "storage": 1
        },
        {
          "name": "label",
          "type": "string",
          "storage": 0
        }
      ],
      "secondary": true,
      "packFormat": "u8 u8 u16 u8 s"
    },
    {
      "kind": "command",
      "name": "pin_by_label",
      "identifier": 131,
      "description": "This responds with `pin_info` report.",
      "fields": [
        {
          "name": "label",
          "type": "string",
          "storage": 0
        }
      ],
      "hasReport": true,
      "packFormat": "s"
    },
    {
      "kind": "report",
      "name": "pin_by_label",
      "identifier": 131,
      "description": "This responds with `pin_info` report.",
      "fields": [
        {
          "name": "pin",
          "type": "u8",
          "storage": 1,
          "isSimpleType": true
        },
        {
          "name": "hw_pin",
          "type": "u8",
          "storage": 1,
          "isSimpleType": true
        },
        {
          "name": "capabilities",
          "type": "Capabilities",
          "storage": 2
        },
        {
          "name": "mode",
          "type": "Mode",
          "storage": 1
        },
        {
          "name": "label",
          "type": "string",
          "storage": 0
        }
      ],
      "secondary": true,
      "packFormat": "u8 u8 u16 u8 s"
    },
    {
      "kind": "command",
      "name": "pin_by_hw_pin",
      "identifier": 132,
      "description": "This responds with `pin_info` report.",
      "fields": [
        {
          "name": "hw_pin",
          "type": "u8",
          "storage": 1,
          "isSimpleType": true
        }
      ],
      "hasReport": true,
      "packFormat": "u8"
    },
    {
      "kind": "report",
      "name": "pin_by_hw_pin",
      "identifier": 132,
      "description": "This responds with `pin_info` report.",
      "fields": [
        {
          "name": "pin",
          "type": "u8",
          "storage": 1,
          "isSimpleType": true
        },
        {
          "name": "hw_pin",
          "type": "u8",
          "storage": 1,
          "isSimpleType": true
        },
        {
          "name": "capabilities",
          "type": "Capabilities",
          "storage": 2
        },
        {
          "name": "mode",
          "type": "Mode",
          "storage": 1
        },
        {
          "name": "label",
          "type": "string",
          "storage": 0
        }
      ],
      "secondary": true,
      "packFormat": "u8 u8 u16 u8 s"
    }
  ],
  "tags": [
    "io"
  ]
}