Low-Level API Reference

The Low-Level API commands mostly map to the HID commands supported by the chip. In case of doubts, please refer to the chip's documentation.

Summary of commands and responses.

CommandResponse
GetGPIOValuesCommandGetGPIOValuesResponse
GetI2CDataCommandGetI2CDataResponse
GetSRAMSettingsCommandGetSRAMSettingsResponse
I2CReadDataCommandGenericResponse
I2CWriteDataCommandGenericResponse
ReadFlashDataChipFactorySerialNumberCommandReadFlashDataChipFactorySerialNumberResponse
ReadFlashDataChipSettingsCommandReadFlashDataChipSettingsResponse
ReadFlashDataGPSettingsCommandReadFlashDataGPSettingsResponse
ReadFlashDataUSBManufacturerDescriptorStringCommandStringResponse
ReadFlashDataUSBProductDescriptorStringCommandStringResponse
ReadFlashDataUSBSerialNumberDescriptorStringCommandStringResponse
ResetChipCommandNo response.
SendFlashAccessPasswordCommandGenericResponse
SetGPIOOutputValuesCommandGenericResponse
SetSRAMSettingsCommandGenericResponse
StatusSetParametersCommandStatusSetParametersResponse
WriteFlashDataChipSettingsCommandGenericResponse
WriteFlashDataGPSettingsCommandGenericResponse
WriteFlashDataUSBManufacturerDescriptorStringCommandGenericResponse
WriteFlashDataUSBProductDescriptorStringCommandGenericResponse
WriteFlashDataUSBSerialNumberDescriptorStringCommandGenericResponse

Constants

Enumerations and Utility Structures

Communication protocol

MCP2221Driver.ResponseStatusType

Status flag for a response.

  • Success: command succeded,
  • I2CBusy:
  • CommandNotSupported: Command not supported,
  • COmmandNotAllowed: Command not allowed.
source

Analog to Digital / Ditital to Analog conversion

MCP2221Driver.ReferenceVoltageOptionType

Reference voltage configuration for DAC and ADC.

  • Reference4p096: reference is 4.096V (only if VDD is above this voltage)
  • Reference2p048: reference is 2.048V
  • Reference1p024: reference is 1.024V
source

I²C

MCP2221Driver.I2CFrameModeType

I²C Frame mode. Writing and reading on the I²C bus is affected by this enumeration.

  • I2CSingle
  • I2CRepeatedStart
  • I2CNoStop
source

General Purpose pins

MCP2221Driver.GPDesignationType

Enum to set the dedicated function of a GP pin.

  • GPIOOperation
  • DedicatedFunctionOperation
  • AlternateFunction0
  • AlternateFunction1
  • AlternateFunction2
Not all members available!

Not all members of the enum are available to all four GP pins. Refer to the following table for a list of available modes:

GP pinGPIOOperationDedicatedFunctionOperationAlternateFunction0AlternateFunction1AlternateFunction2
GP0AvailableSSPNDLED_URxNot AvailableNot Available
GP1Availableclock outputADC1LED_UTxInterrupt detection
GP2AvailableUSBCFGADC2DAC1Not Available
GP3AvailableLED_I2CADC3DAC2Not Available
source
MCP2221Driver.GPIOStatusType

Store the status of a GPIO.

Fields

  • outputvalue::Bool: Logical value present at the output.

  • direction::MCP2221Driver.GPDirection: GPIO direction.

  • designation::MCP2221Driver.GPDesignation: GPIO designation. See GPDesignation for a list of available designation for each pin.

source

Commands and Responses

MCP2221Driver.queryFunction
query(dev, command)

Blocking call to the device to send the command and receive the response if one is expected.

source

Chip configuration commands and responses

MCP2221Driver.StatusSetParametersResponseType

Response for a StatusSetParametersCommand.

Fields

  • status::MCP2221Driver.ResponseStatus: See ResponseStatus.

  • cancellationstatus::MCP2221Driver.CancellationStatus: Status of the cancellation request.

  • speedstatus::MCP2221Driver.CommunicationSpeedStatus: Status of the new speed request.

  • divider::UInt8: Divider value for the speed.

  • requestedtransferlength::UInt16: Length of the requested I²C transfer.

  • alreadytransferedlength::UInt16: Length of the already transfered I²C message.

  • i2cbuffercounter::UInt8: Internal I²C data buffer counter.

  • currentcommunicationspeeddividervalue::UInt8: Current communication speed divider value.

  • currenti2ctimeoutvalue::UInt8: Current I²C timeout value.

  • currenti2caddress::UInt16: Current I²C address.

  • ackreceived::Bool: If ACK was received from client.

  • sclvalue::UInt8: Current SCL line value.

  • sdavalue::UInt8: Current SDA line value.

  • interuptedgestate::Bool: Interrupt edge detector state.

  • i2creadpendingvalue::UInt8: I²C read pending value.

  • hardwareversion::VersionNumber: MCP2221 hardware version.

  • firmwareversion::VersionNumber: MCP2221 firmware version.

  • adcdatach0::UInt16: Channel 0 ADC value.

  • adcdatach1::UInt16: Channel 1 ADC value.

  • adcdatach2::UInt16: Channel 2 ADC value.

source
MCP2221Driver.ResetChipCommandType

This command is used to force a Reset of the MCP2221A device. This command is useful when the Flash memory is updated with new data. The MCP2221A would need to be re-enumerated to see the new data.

MCP2221Driver.ResetChipCommand does not expects a response.

Note

This command is the only command that does not expect a response.

source

Flash Memory Manipulation

MCP2221Driver.ReadFlashDataChipSettingsResponseType

Response for a ReadFlashDataChipSettingsCommand.

Fields

  • status::MCP2221Driver.ResponseStatus: See ResponseStatus.

  • cdcserialnumberenumerationenable::Bool: If true, the USB serial number will be used during the USB enumeration of the CDC interface.

  • chipconfigurationsecurityoption::MCP2221Driver.ChipConfigurationSecurityOption: Chip configuration security option.

  • clockoutputduty::MCP2221Driver.ClockOutputDutyCycle: If the GP pin is enabled for clock output operations, this is the duty cycle of the output.

  • clockoutputdividervalue::MCP2221Driver.ClockOutputFrequency: If the GP pin is enabled for clock output operations, the divider value will be used on the 48MHz US internal clock and the divider output will be sent to this pin.

  • dacreferencevoltage::MCP2221Driver.ReferenceVoltageOption: DAC reference voltage option.

  • dacreferenceoption::MCP2221Driver.SourceReferenceOption: DAC reference option.

  • powerupdacvalue::UInt8: Power-up DAC value.

  • interruptdetectionnegativeedge::Bool: If true, the interrupt detection flag will be set when a negative edge occurs.

  • interruptdetectionpositiveedge::Bool: If true, the interrupt detection flag will be set when a positive edge occurs.

  • adcreferencevoltage::MCP2221Driver.ReferenceVoltageOption: ADC reference voltage.

  • adcreferenceoption::MCP2221Driver.SourceReferenceOption: ADC reference option.

  • vid::UInt16: USB VID value.

  • pid::UInt16: USB PID value.

  • usbpowerattributes::UInt8: USB power attribute as per USB 2.0 specification.

  • usbrequestednumberofma::UInt8: USB requested number of mA(s) as per USB 2.0 specification.

source
MCP2221Driver.WriteFlashDataChipSettingsCommandType

Write chip settings into Flash memory.

MCP2221Driver.WriteFlashDataChipSettingsCommand expects a MCP2221Driver.GenericResponse response. See also ReadFlashDataChipSettingsCommand.

Fields

  • cdcserialnumberenumerationenable::Bool: If true, the USB serial number will be used during the USB enumeration of the CDC interface.

  • chipconfigurationsecurityoption::MCP2221Driver.ChipConfigurationSecurityOption: Chip configuration security option.

  • clockoutputduty::MCP2221Driver.ClockOutputDutyCycle: If the GP pin is enabled for clock output operations, this is the duty cycle of the output.

  • clockoutputdividervalue::MCP2221Driver.ClockOutputFrequency: If the GP pin is enabled for clock output operations, the divider value will be used on the 48MHz US internal clock and the divider output will be sent to this pin.

  • dacreferencevoltage::MCP2221Driver.ReferenceVoltageOption: DAC reference voltage option.

  • dacreferenceoption::MCP2221Driver.SourceReferenceOption: DAC reference option.

  • powerupdacvalue::UInt8: Power-up DAC value.

  • interruptdetectionnegativeedge::Bool: If true, the interrupt detection flag will be set when a negative edge occurs.

  • interruptdetectionpositiveedge::Bool: If true, the interrupt detection flag will be set when a positive edge occurs.

  • adcreferencevoltage::MCP2221Driver.ReferenceVoltageOption: ADC reference voltage.

  • adcreferenceoption::MCP2221Driver.SourceReferenceOption: ADC reference option.

  • vid::UInt16: USB VID value.

  • pid::UInt16: USB PID value.

  • usbpowerattributes::UInt8: USB power attribute as per USB 2.0 specification.

  • usbrequestednumberofma::UInt8: USB requested number of mA(s) as per USB 2.0 specification.

  • password::String: 8-byte password (for Flash modifications protection).

source
MCP2221Driver.WriteFlashDataGPSettingsCommandType

Write GP settings into Flash memory.

MCP2221Driver.WriteFlashDataGPSettingsCommand expects a MCP2221Driver.GenericResponse response. ReadFlashDataGPSettingsCommand.

Fields

  • gpio0powerupstatus::MCP2221Driver.GPIOStatus: GPIO0 status at power-up.

  • gpio1powerupstatus::MCP2221Driver.GPIOStatus: GPIO1 status at power-up.

  • gpio2powerupstatus::MCP2221Driver.GPIOStatus: GPIO2 status at power-up.

  • gpio3powerupstatus::MCP2221Driver.GPIOStatus: GPIO3 status at power-up.

source
MCP2221Driver.SendFlashAccessPasswordCommandType

Send user-supplied password that will be compared to the one stored in the device's Flash when Flash updates are required and the Flash data are password-protected.

The password must be at most 8 bytes long. If your string contains characters more than one byte long, their LSB will be written first.

MCP2221Driver.SendFlashAccessPasswordCommand expects a MCP2221Driver.GenericResponse response.

Fields

  • password::AbstractString: 8-bytes of password.
source

SRAM Manipulation

MCP2221Driver.SetSRAMSettingsCommandType

This command is used to al,er various run-time Chip settings. The altered settings reside in SRAM me,ory and they will not affect the Chip’s power-up/Reset default settings. These altered settings will be active until the next chip power-up/Reset.

MCP2221Driver.SetSRAMSettingsCommand expects a MCP2221Driver.GenericResponse response.

Fields

  • clockoutputsettings::Union{Nothing, @NamedTuple{duty::MCP2221Driver.ClockOutputDutyCycle, dividervalue::MCP2221Driver.ClockOutputFrequency}}: If the GP pin is enabled for clock output operations, these are the duty cycle and the output frequency.
  • dacsettings::Union{Nothing, @NamedTuple{referencevoltage::MCP2221Driver.ReferenceVoltageOption, referenceoption::MCP2221Driver.SourceReferenceOption}}: DAC settings.

  • dacoutputvalue::Union{Nothing, UInt8}: DAC output value, only the 5 LSB are taken into account.

  • adcsettings::Union{Nothing, @NamedTuple{referencevoltage::MCP2221Driver.ReferenceVoltageOption, referenceoption::MCP2221Driver.SourceReferenceOption}}: ADC settings.

  • interruptdetectionpositiveedge::Union{Nothing, Bool}: If set to a boolean value, control wether interrupt detection will trigger on positive edges.

  • interruptdetectionnegativeedge::Union{Nothing, Bool}: If set to a boolean value, control wether interrupt detection will trigger on negative edges.

  • clearinterrupt::Bool: If set to true, clear the interrupt flag. Default is false.

  • gpiosettings::Union{Nothing, @NamedTuple{gpio0::MCP2221Driver.GPIOStatus, gpio1::MCP2221Driver.GPIOStatus, gpio2::MCP2221Driver.GPIOStatus, gpio3::MCP2221Driver.GPIOStatus}}: If set, change GPIO settings. For more fine-grained control, see SetGPIOOutputValuesCommand.

source
MCP2221Driver.GetSRAMSettingsResponseType

Response to a GetSRAMSettingsCommand.

Fields

  • status::MCP2221Driver.ResponseStatus: See ResponseStatus.

  • lengthchipsettings::UInt8: Length in bytes of the SRAM Chip settings area.

  • lengthgpsettings::UInt8: Length in bytes of the SRAM GP settings area.

  • cdcserialnumberenumerationenable::Bool: If true, the USB serial number will be used during the USB enumeration of the CDC interface.

  • chipconfigurationsecurityoption::MCP2221Driver.ChipConfigurationSecurityOption: Chip configuration security option.

  • clockoutputduty::MCP2221Driver.ClockOutputDutyCycle: If the GP pin is enabled for clock output operations, this is the duty cycle of the output.

  • clockoutputdividervalue::MCP2221Driver.ClockOutputFrequency: If the GP pin is enabled for clock output operations, the divider value will be used on the 48MHz US internal clock and the divider output will be sent to this pin.

  • dacreferencevoltage::MCP2221Driver.ReferenceVoltageOption: DAC reference voltage option.

  • dacreferenceoption::MCP2221Driver.SourceReferenceOption: DAC reference option.

  • powerupdacvalue::UInt8: Power-up DAC value.

  • interruptdetectionnegativeedge::Bool: If true, the interrupt detection flag will be set when a negative edge occurs.

  • interruptdetectionpositiveedge::Bool: If true, the interrupt detection flag will be set when a positive edge occurs.

  • adcreferencevoltage::MCP2221Driver.ReferenceVoltageOption: ADC reference voltage.

  • adcreferenceoption::MCP2221Driver.SourceReferenceOption: ADC reference option.

  • vid::UInt16: USB VID value.

  • pid::UInt16: USB PID value.

  • usbpowerattributes::UInt8: USB power attribute as per USB 2.0 specification.

  • usbrequestednumberofma::UInt8: USB requested number of mA(s) as per USB 2.0 specification.

  • password::String: Current Supplied Password (8 bytes).

  • gpio0status::MCP2221Driver.GPIOStatus: GPIO0 status.

  • gpio1status::MCP2221Driver.GPIOStatus: GPIO1 status.

  • gpio2status::MCP2221Driver.GPIOStatus: GPIO2 status.

  • gpio3status::MCP2221Driver.GPIOStatus: GPIO3 status.

source

I²C Communications

MCP2221Driver.I2CWriteDataCommandType

Write data on the I²C bus. Depending on the chosen I2CFrameMode, the behavior will vary. The command has the following effects:

  • Send the "Start" (I2CSingle, I2CNoStop) or "RepeatedStart" (I2CRepeatedStart) condition.
  • Send the I²C client address and wait for the client to send an Acknowledge bit.
  • The user data follow next. The I²C engine waits for the Acknowledge bit from the client.
  • If the requested length is more than 60 bytes, subsequent user bytes will be sent on the bus.
  • When the user data length reaches the requested length, the I²C engine will send the "Stop" condition on the bus, except when the mode is I2CNoStop.

Note that you can send data longer than 60 bytes by repeating the command, but this layer will not take care of that for you and will error if your data is longer than 60 bytes.

MCP2221Driver.I2CWriteDataCommand expects a MCP2221Driver.GenericResponse response.

Fields

  • address::MCP2221Driver.I2CAddress

  • writemode::MCP2221Driver.I2CFrameMode

  • data::Vector{UInt8}

source
MCP2221Driver.I2CReadDataCommandType

Read data from the I²C bus. Depending on the chosen I2CFrameMode, the behavior will vary. Note that the I2CNoStop mode is not supported. The command has the following effects:

  • Send the "Start" (I2CSingle) or "RepeatedStart" (I2CRepeatedStart) condition.
  • Send the I²C client address and wait for the client to send an Acknowledge bit.
  • The user data follow next. The I²C engine sends the Acknowledge bit to the client.
  • If the requested length is more than 60 bytes, subsequent user bytes will be read from the bus.
  • When the user data length reaches the requested length, the I²C engine will send the "Stop" condition on the bus.

MCP2221Driver.I2CReadDataCommand expects a MCP2221Driver.GenericResponse response.

Fields

  • address::MCP2221Driver.I2CAddress

  • readmode::MCP2221Driver.I2CFrameMode

  • length::UInt16

source

GPIO Manipulation

MCP2221Driver.SetGPIOOutputValuesCommandType

This command is used to change the GPIO output value for those GP pins assigned for GPIO operation (GPIO outputs).

MCP2221Driver.SetGPIOOutputValuesCommand expects a MCP2221Driver.GenericResponse response.

Fields

  • gp0outputvalue::Union{Nothing, Bool}: GP0 output value, set to nothing to leave unchanged.

  • gp0pindirection::Union{Nothing, Bool}: GP0 pin direction, set to nothing to leave unchanged, false for output, true for input.

  • gp1outputvalue::Union{Nothing, Bool}: GP1 output value, set to nothing to leave unchanged.

  • gp1pindirection::Union{Nothing, Bool}: GP1 pin direction, set to nothing to leave unchanged, false for output, true for input.

  • gp2outputvalue::Union{Nothing, Bool}: GP2 output value, set to nothing to leave unchanged.

  • gp2pindirection::Union{Nothing, Bool}: GP2 pin direction, set to nothing to leave unchanged, false for output, true for input.

  • gp3outputvalue::Union{Nothing, Bool}: GP3 output value, set to nothing to leave unchanged.

  • gp3pindirection::Union{Nothing, Bool}: GP3 pin direction, set to nothing to leave unchanged, false for output, true for input.

source
MCP2221Driver.GetGPIOValuesResponseType

Response to a GetGPIOValuesCommand.

Fields

  • status::MCP2221Driver.ResponseStatus: See ResponseStatus.

  • gp0pinvalue::Union{Nothing, Bool}: GP0 logic pin value, or nothing if not set for GPIO operations.

  • gp0directionvalue::Union{Nothing, Bool}: GP0 pin designation (false for output true for input), or nothing if not set for GPIO operations.

  • gp1pinvalue::Union{Nothing, Bool}: GP1 logic pin value, or nothing if not set for GPIO operations.

  • gp1directionvalue::Union{Nothing, Bool}: GP1 pin designation (false for output true for input), or nothing if not set for GPIO operations.

  • gp2pinvalue::Union{Nothing, Bool}: GP2 logic pin value, or nothing if not set for GPIO operations.

  • gp2directionvalue::Union{Nothing, Bool}: GP2 pin designation (false for output true for input), or nothing if not set for GPIO operations.

  • gp3pinvalue::Union{Nothing, Bool}: GP3 logic pin value, or nothing if not set for GPIO operations.

  • gp3directionvalue::Union{Nothing, Bool}: GP3 pin designation (false for output true for input), or nothing if not set for GPIO operations.

source

Index