d2xx

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

README

d2xx

codecov

Package d2xx is a thin Go wrapper for the Future Technology "D2XX" driver at https://ftdichip.com/drivers/d2xx-drivers/.

This package is not Go idiomatic. You will want to use https://periph.io/x/host/v3/ftdi (or later) instead.

But if you really want, here it goes: PkgGoDev

This Go package includes third party software. See third_party/README.md.

Configuration

See https://periph.io/device/ftdi/ to configure the host to be able to use this driver.

Availability

On darwin_amd64, linux_amd64 linux_arm (v6, v7 compatible) and linux_arm64 (v8), cgo is required. If cgo is disabled (via CGO_ENABLED=0), all functions in this driver return error NoCGO.

On Windows, cgo is not required. If the dynamic library is not found at runtime, Missing is returned.

bcm2385

On linux_arm (v6), hard-float is required. For cross compilation, this means arm-linux-gnueabihf-gcc is preferred to arm-linux-gnueabi-gcc. Using hardfloat causes a segfault on Raspberry Pi 1, Zero and Zero Wireless. It is recommended to disable this driver if targeting these hosts, see below.

Disabling

To disable this driver, build with tag no_d2xx, e.g.

go install -tags no_d2xx periph.io/x/cmd/gpio-list@latest

This will behave has if cgo was disabled, even on Windows.

Documentation

Overview

Package d2xx is a thin Go wrapper for the Future Technology "D2XX" driver.

This package is not Go idiomatic. You want to use https://periph.io/x/host/v3/ftdi (or later) instead.

A static library of the d2xx driver is included for linux and macOS. They are from https://ftdichip.com/drivers/d2xx-drivers/. See third_party/README.md for more details.

Configuration

See https://periph.io/device/ftdi/ for more details, and how to configure the host to be able to use this driver.

Index

Examples

Constants

View Source
const Available = true

Available is true if the library is available on this system.

Variables

This section is empty.

Functions

func Open

func Open(i int) (Handle, Err)

Open opens the ith device discovered.

If the driver is disabled via build tag `no_d2xx`, or on posix `CGO_ENABLED=0` environment variable, NoCGO is returned.

On Windows, Missing is returned if the dynamic library is not found at runtime.

func Version

func Version() (uint8, uint8, uint8)

Version returns the library's version.

0, 0, 0 is returned if the library is unavailable.

Example
package main

import (
	"fmt"

	"periph.io/x/d2xx"
)

func main() {
	// Print the d2xx driver version. It will be 0.0.0 if not found.
	major, minor, build := d2xx.Version()
	fmt.Printf("Using library %d.%d.%d\n", major, minor, build)
}
Output:

Types

type EEPROM

type EEPROM struct {
	// Raw is the raw EEPROM content. It excludes the strings.
	Raw []byte

	// The following condition must be true: len(Manufacturer) + len(Desc) <= 40.
	Manufacturer   string
	ManufacturerID string
	Desc           string
	Serial         string
}

EEPROM is the unprocessed EEPROM content.

The EEPROM is in 3 parts: the defined struct, the 4 strings and the rest which is used as an 'user area'. The size of the user area depends on the length of the strings. The user area content is not included in this struct.

type Err

type Err int

Err is the error type returned by d2xx functions.

const (
	// NoCGO is returned when the package was compiled without cgo, thus the d2xx
	// library is unavailable or the library was disabled via the `no_d2xx` build
	// tag.
	NoCGO Err = -2
	// Missing is returned when the dynamic library is not available.
	Missing Err = -1
)

These are additional synthetic error codes.

func CreateDeviceInfoList

func CreateDeviceInfoList() (int, Err)

CreateDeviceInfoList discovers the currently found devices.

If the driver is disabled via build tag `no_d2xx`, or on posix `CGO_ENABLED=0` environment variable, NoCGO is returned.

On Windows, Missing is returned if the dynamic library is not found at runtime.

func Rescan

func Rescan() Err

Rescan rescan the USB bus for new devices.

func (Err) String

func (e Err) String() string

String converts a error integer to a string representation of the error.

type Handle

type Handle interface {
	Close() Err
	// ResetDevice takes >1.2ms
	ResetDevice() Err
	GetDeviceInfo() (uint32, uint16, uint16, Err)
	EEPROMRead(devType uint32, e *EEPROM) Err
	EEPROMProgram(e *EEPROM) Err
	EraseEE() Err
	WriteEE(offset uint8, value uint16) Err
	EEUASize() (int, Err)
	EEUARead(ua []byte) Err
	EEUAWrite(ua []byte) Err
	SetChars(eventChar byte, eventEn bool, errorChar byte, errorEn bool) Err
	SetUSBParameters(in, out int) Err
	SetFlowControl() Err
	SetTimeouts(readMS, writeMS int) Err
	SetLatencyTimer(delayMS uint8) Err
	SetBaudRate(hz uint32) Err
	// GetQueueStatus takes >60µs
	GetQueueStatus() (uint32, Err)
	// Read takes <5µs if GetQueueStatus was called just before,
	// 300µs~800µs otherwise (!)
	Read(b []byte) (int, Err)
	// Write takes >0.1ms
	Write(b []byte) (int, Err)
	GetBitMode() (byte, Err)
	// SetBitMode takes >0.1ms
	SetBitMode(mask, mode byte) Err
}

Handle is d2xx device handle.

Directories

Path Synopsis
Package d2xxtest defines logging wrapper and fake for unit testing.
Package d2xxtest defines logging wrapper and fake for unit testing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL