Skip to content

Latest commit

 

History

History
61 lines (48 loc) · 2.21 KB

README.md

File metadata and controls

61 lines (48 loc) · 2.21 KB

MCP2221Driver

Stable Dev Build Status Aqua

MCP2221Driver.jl is a driver to use Microship's MCP2221 hardware through HidApi. This enables I²C communications, GPIO operations, and analog IO operations directly from Julia using this hardware. For now, only the low-level API is available.

Installation

The package can be installed throug the package manager:

]add MCP2221Driver

Example

See the tutorial for more in-depth usage examples. Here is an example blink program:

using MCP2221Driver
import HidApi
HidApi.init()

device = open(HidApi.find_device(
    MCP2221Driver.MCP2221A_DEFAULT_VID, 
    MCP2221Driver.MCP2221A_DEFAULT_PID
))

# Configuring pins for GPIO operations
command = MCP2221Driver.GetSRAMSettingsCommand()
response = MCP2221Driver.query(device, command)
command = MCP2221Driver.SetSRAMSettingsCommand(
    gpiosettings=(
        gpio0=response.gpio0status, 
        gpio1=response.gpio1status, 
        gpio2=MCP2221Driver.GPIOStatus(false, 
                                       MCP2221Driver.GPIOOutput, 
                                       MCP2221Driver.GPIOOperation
                                       ), 
        gpio3=MCP2221Driver.GPIOStatus(false, 
                                       MCP2221Driver.GPIOOutput, 
                                       MCP2221Driver.GPIOOperation
                                       )
    )
)
MCP2221Driver.query(device, command)

# Actual blinking
for i in 1:60
    command = MCP2221Driver.SetGPIOOutputValuesCommand(gp2outputvalue=isodd(i), gp3outputvalue=iseven(i))
    MCP2221Driver.query(device, command)
    sleep(1)
end

close(device)
HidApi.shutdown()