Low-Level API internals

Communication protocol specification

The whole goal of the Low-Level API is to bridge the chip's protocol to arrays of bytes that can be sent through the USB. The protocol is specified using Julia's type system. This means that the API defines a set of commands that correspond to the chip's (sub-)commands[subcommands]. The conversion to Vector{UInt8} is done by MCP2221Driver.asarray. It initializes a 64-bytes long vector and populates the two first items using MCP2221Driver.commandcode and MCP2221Driver.subcommandcode. The array is then mutated by MCP2221Driver.initarray! to correspond to the chip's specification. This allows overwriting the sub-command item for commands that do not support sub-commands (for example, MCP2221Driver.I2CWriteDataCommand).

The specification of the protocol through the type-system gives the type-stability of MCP2221Driver.query. Indeed, since MCP2221Driver.expectsresponse and MCP2221Driver.responsetype are defined for each command types, the compiler knows what to expect as a response (nothing when expectsresponse(T) is false, responsetype(T) otherwise).

Low-Level API internals Reference

Commands and Responses

Command interface

MCP2221Driver.commandcodeFunction
commandcode(::T) where {T<:AbstractCommand} ::UInt8

Return the first byte of a command sequence, identifying the command.

source
MCP2221Driver.subcommandcodeFunction
subcommandcode(::T) where {T<:AbstractCommand} ::UInt8

Return the second byte of a command sequence, identifying the sub-command. Defaults to 0.

source
MCP2221Driver.expectsresponseFunction
expectsresponse(::Type{T}) where {T<:AbstractCommand}::Bool

If true, read a response of type responsetype(T) from the device. Defaults to true.

source
MCP2221Driver.initarray!Function
initarray!(command, v)

Initialize the array v given a command. The command does not have to handle the two first bytes. It assumes v elements are all zero.

source

Utilities

MCP2221Driver.ByteStringIteratorType

Produces bytes associated to a string, with at least L bytes per character. If it is strict, then each character will be exactly L bytes, regardless of correctness.

source
MCP2221Driver.CommandSummaryType

Internal type used to make DocStringExtensions.jl document the link between commands and reponses. Use with the COMMANDSUMMARY abbreviation.

source

Index

  • subcommandsThe chip's flash memory access commands define a set of sub-commands. For simplicity, the Low-Level API maps those as normal commands and handles internally the conversion to sub-commands. Some commands have also been grouped, such as the I²C writing commands.