sdwire

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2025 License: MIT Imports: 2 Imported by: 0

README

SDWire Go Library

Go Reference Go Report Card

Go library for controlling SDWireC devices - USB-controlled SD card multiplexers for automated testing and development.

Features

🔀 SD Card Switching - Switch SD cards between target device and host computer
🎯 Simple API - Easy-to-use interface following Go best practices
🔍 Device Discovery - Automatically find and enumerate connected devices
💾 Device Information - Access device serial, product, and manufacturer details
🖥️ Cross-Platform - Works on Linux, macOS, and Windows
No Dependencies - Only uses standard library and gousb

Installation

go get github.com/fcjr/sdwire

Quick Start

package main

import (
    "log"
    "github.com/fcjr/sdwire"
)

func main() {
    // Connect to the first available SDWireC device
    device, err := sdwire.New()
    if err != nil {
        log.Fatal(err)
    }
    defer device.Close()

    // Switch SD card to host computer for flashing
    device.SetMode(sdwire.ModeHost)
    
    // Flash your image here...
    
    // Switch SD card to target device for testing
    device.SetMode(sdwire.ModeTarget)
}

Usage Examples

Basic SD Card Switching
device, err := sdwire.New()
if err != nil {
    log.Fatal(err)
}
defer device.Close()

// Switch to Host (for flashing/accessing SD card)
err = device.SetMode(sdwire.ModeHost)
if err != nil {
    log.Fatal(err)
}

// Switch to Target (for testing)
err = device.SetMode(sdwire.ModeTarget)
if err != nil {
    log.Fatal(err)
}
Getting Device Information
import (
    "fmt"
    "log"
    "github.com/fcjr/sdwire"
)

device, err := sdwire.New()
if err != nil {
    log.Fatal(err)
}
defer device.Close()

// Get device information
fmt.Printf("Device: %s [%s::%s]\n", 
    device.GetSerial(), 
    device.GetProduct(), 
    device.GetManufacturer())
Managing Multiple Devices
import (
    "fmt"
    "log"
    "github.com/fcjr/sdwire"
)

// List all connected SDWireC devices
devices, err := sdwire.ListDevices()
if err != nil {
    log.Fatal(err)
}

for i, info := range devices {
    fmt.Printf("Device %d: %s [%s::%s]\n", 
        i+1, info.Serial, info.Product, info.Manufacturer)
}

// Connect to a specific device by serial number
device, err := sdwire.NewWithSerial(devices[0].Serial)
if err != nil {
    log.Fatal(err)
}
defer device.Close()

API Reference

Types
type SDWireC struct {
    // Represents a connected SDWireC device
}

type SwitchMode int
const (
    ModeTarget SwitchMode = iota  // Target device mode
    ModeHost                      // Host computer mode
)

type DeviceInfo struct {
    Serial       string
    Product      string
    Manufacturer string
}
Connection Management
Function Description
New() (*SDWireC, error) Connect to the first available device
NewWithSerial(serial string) (*SDWireC, error) Connect to device by serial number
ListDevices() ([]*DeviceInfo, error) List all connected devices
Close() error Close device connection
Device Control
Function Description
SetMode(mode SwitchMode) error Switch to specified mode
Device Information
Function Description
GetSerial() string Get device serial number
GetProduct() string Get device product name
GetManufacturer() string Get device manufacturer
Constants
const (
    ModeTarget  // Connects SD card to target device
    ModeHost    // Connects SD card to host computer
)

Hardware Requirements

  • SDWireC device (USB-controlled SD card multiplexer)
  • USB connection to host computer
  • Proper USB permissions (see Troubleshooting)

Supported Operating Systems

  • Linux ✅ (Tested on Ubuntu, Debian)
  • macOS ✅ (Tested on macOS 10.15+)
  • Windows ✅ (Tested on Windows 10+)

Troubleshooting

Device Not Found

If ListDevices() returns no devices:

  1. Check USB connection - Ensure the SDWireC is properly connected
  2. Verify device - Run the debug utility to list all USB devices:
    go run debug/list_usb.go
    
  3. Check VID/PID - SDWireC should appear as 04E8:6001
Permission Issues (Linux)

If you get permission errors on Linux:

  1. Add udev rules - Create /etc/udev/rules.d/99-sdwire.rules:

    SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6001", MODE="0666"
    
  2. Reload udev rules:

    sudo udevadm control --reload-rules
    sudo udevadm trigger
    
  3. Add user to plugdev group:

    sudo usermod -a -G plugdev $USER
    
Multiple Devices

When using multiple SDWireC devices:

devices, err := sdwire.ListDevices()
if err != nil {
    log.Fatal(err)
}

for _, info := range devices {
    device, err := sdwire.NewWithSerial(info.Serial)
    if err != nil {
        continue
    }
    defer device.Close()
    
    // Use device...
    device.SetMode(sdwire.ModeTarget)
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

License

MIT License - see LICENSE file for details.

  • sdwire-cli - Python CLI tool for SDWireC
  • ykush3 - Go library for YKUSH3 USB switches

Made with ❤️ for embedded testing automation

Documentation

Overview

Package sdwire provides a Go SDK for controlling SDWireC devices. SDWireC is a USB-controlled SD card multiplexer that allows switching an SD card between a Device Under Test (DUT) and Test System (TS).

Index

Constants

View Source
const (
	SDWireCVID         = 0x04E8
	SDWireCPID         = 0x6001
	SDWireCProductName = "sd-wire"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DeviceInfo

type DeviceInfo struct {
	Serial       string
	Product      string
	Manufacturer string
}

DeviceInfo contains identifying information about an SDWireC device.

func ListDevices

func ListDevices() ([]*DeviceInfo, error)

ListDevices discovers all connected SDWireC devices and returns their information. This is useful for device enumeration before connecting to a specific device.

type SDWireC

type SDWireC struct {
	// contains filtered or unexported fields
}

SDWireC represents a connected SDWireC device that can switch an SD card between a target device and host computer.

func New

func New() (*SDWireC, error)

New connects to the first available SDWireC device. This is a convenience function for single-device setups. The returned SDWireC must be closed with Close() when done.

func NewWithSerial

func NewWithSerial(serial string) (*SDWireC, error)

NewWithSerial connects to a specific SDWireC device by its serial number. Use ListDevices() first to discover available devices and their serial numbers. The returned SDWireC must be closed with Close() when done.

func (*SDWireC) Close

func (s *SDWireC) Close() error

Close releases the USB device connection. Always call this when done with the device.

func (*SDWireC) GetManufacturer

func (s *SDWireC) GetManufacturer() string

GetManufacturer returns the device's USB manufacturer name.

func (*SDWireC) GetProduct

func (s *SDWireC) GetProduct() string

GetProduct returns the device's USB product name.

func (*SDWireC) GetSerial

func (s *SDWireC) GetSerial() string

GetSerial returns the device's USB serial number.

func (*SDWireC) SetMode

func (s *SDWireC) SetMode(mode SwitchMode) error

SetMode switches the SD card to the specified mode.

func (*SDWireC) String

func (s *SDWireC) String() string

String returns a formatted string with device information.

type SwitchMode

type SwitchMode int

SwitchMode represents the SD card connection mode.

const (
	// ModeTarget connects the SD card to the target device being tested.
	ModeTarget SwitchMode = iota
	// ModeHost connects the SD card to the host computer for flashing/access.
	ModeHost
)

func (SwitchMode) String

func (m SwitchMode) String() string

String returns a human-readable description of the switch mode.

Jump to

Keyboard shortcuts

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