# Bridge 1.1 API - SPI Commands

### Set Voltage

See [#set-bus-voltage](https://support.binho.io/user-guide/protocols-and-interfaces/bridge-1.1-api-i2c-commands#set-bus-voltage "mention").

### SPI Initialization

* **Command Request:**

  ```json
  {
    "transaction_id": "1",
    "command": "spi_init",
    "params": {
      {
        "mode": "<0..3>",
        "clockFrequencyInKHz": "<Unsigned Integer>",
        "bitOrder": "<MSB|LSB>",
        "bitsPerTransfer": "<8|16>",
        "chipSelect": "<0..3>",
        "chipSelectPol": "<0,1>"
      }
    }
  }
  ```
* **Responses:**
  * Immediate Promise Response:

    ```json
    {
      "transaction_id": "1",
      "status": "success",
      "type": "command_response",
      "is_promise": true,
      "data": {
        "command": "spi_init"
      }
    }
    ```
  * Final Response:

    ```json
    {
      "transaction_id": "1",
      "status": "success",
      "type": "command_response",
      "is_promise": false,
      "data": {
        "is_response_to": "spi_init",
        "status": "success"
      }
    }
    ```

### SPI Configuration

* **Command Request:**

  ```json
  {
    "transaction_id": "1",
    "command": "spi_config",
    "params": {
      {
        "mode": "<0..3>",
        "clockFrequencyInKHz": "<Unsigned Integer>",
        "bitOrder": "<MSB|LSB>",
        "bitsPerTransfer": "<8|16>",
        "chipSelect": "<0..3>",
        "chipSelectPol": "<0,1>"
      }
    }
  }
  ```
* **Responses:**
  * Immediate Promise Response:

    ```json
    {
      "transaction_id": "1",
      "status": "success",
      "type": "command_response",
      "is_promise": true,
      "data": {
        "command": "spi_config"
      }
    }
    ```
  * Final Response:

    ```json
    {
      "transaction_id": "1",
      "status": "success",
      "type": "command_response",
      "is_promise": false,
      "data": {
        "is_response_to": "spi_config",
        "status": "success"
      }
    }
    ```

### SPI Transfer

* **Command Request:**

  ```json
  {
    "transaction_id": "1",
    "command": "spi_transfer",
    "params": {
      "bytesToRead": "<Unsigned Integer>",
      "writeBuffer": "<Hex String (e.g. DEADBEEF)>"
      }
    }
  }
  ```
* **Responses:**
  * Immediate Promise Response:

    ```json
    {
      "transaction_id": "1",
      "status": "success",
      "type": "command_response",
      "is_promise": true,
      "data": {
        "command": "spi_transfer"
      }
    }
    ```
  * Final Response:

    ```json
    {
      "transaction_id": "1",
      "status": "success",
      "is_promise": false,
      "data": {
        "is_response_to": "spi_transfer",
        "status": "success",
        "payload_length": <Unsigned Integer>,
        "data": <Array of 2-Byte Hex String (e.g. "DE", "AD", "BE", "EF")>}
      }
    }
    ```
