genericlinux

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2023 License: AGPL-3.0 Imports: 26 Imported by: 2

Documentation

Overview

Package genericlinux implements a Linux-based board making heavy use of sysfs (https://en.wikipedia.org/wiki/Sysfs). This does not provide a board model itself but provides the underlying logic for any Linux/sysfs based board.

Package genericlinux is for Linux boards, and this particular file is for digital interrupt pins using the ioctl interface, indirectly by way of mkch's gpio package.

Package genericlinux is for Linux boards, and this particular file is for GPIO pins using the ioctl interface, indirectly by way of mkch's gpio package.

Package genericlinux is for Linux boards. This particular file is for using sysfs to interact with PWM devices. All of these functions are idempotent: you can double-export a pin or double-close it with no problems.

Package genericlinux is for boards that run Linux. This file is for I2C support on those boards.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetGPIOBoardMappings

func GetGPIOBoardMappings(modelName string, boardInfoMappings map[string]BoardInformation) (map[int]GPIOBoardMapping, error)

GetGPIOBoardMappings attempts to find a compatible GPIOBoardMapping for the given board.

func RegisterBoard

func RegisterBoard(modelName string, gpioMappings map[int]GPIOBoardMapping)

RegisterBoard registers a sysfs based board of the given model.

Types

type BoardInformation

type BoardInformation struct {
	PinDefinitions []PinDefinition
	Compats        []string
}

BoardInformation details pin definitions and device compatibility for a particular board.

type Config

type Config struct {
	I2Cs              []board.I2CConfig              `json:"i2cs,omitempty"`
	SPIs              []board.SPIConfig              `json:"spis,omitempty"`
	Analogs           []board.AnalogConfig           `json:"analogs,omitempty"`
	DigitalInterrupts []board.DigitalInterruptConfig `json:"digital_interrupts,omitempty"`
	Attributes        utils.AttributeMap             `json:"attributes,omitempty"`
}

A Config describes the configuration of a board and all of its connected parts.

func (*Config) Validate

func (conf *Config) Validate(path string) ([]string, error)

Validate ensures all parts of the config are valid.

type GPIOBoardMapping

type GPIOBoardMapping struct {
	GPIOChipDev    string
	GPIO           int
	GPIOName       string
	PWMSysFsDir    string // Absolute path to the directory, empty string for none
	PWMID          int
	HWPWMSupported bool
}

GPIOBoardMapping represents a GPIO pin's location locally within a GPIO chip and globally within sysfs.

type I2cBus added in v0.4.0

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

I2cBus represents an I2C bus. You can use it to create handles for devices at specific addresses on the bus. Creating a handle locks the bus, and closing the handle unlocks the bus again, so that you can only communicate with 1 device on the bus at a time.

func NewI2cBus added in v0.4.0

func NewI2cBus(deviceName string) (*I2cBus, error)

NewI2cBus creates a new I2cBus object.

func (*I2cBus) OpenHandle added in v0.4.0

func (bus *I2cBus) OpenHandle(addr byte) (board.I2CHandle, error)

OpenHandle lets the I2cBus type implement the board.I2C interface. It returns a handle for communicating with a device at a specific I2C handle. Opening a handle locks the I2C bus so nothing else can use it, and closing the handle unlocks the bus again.

type I2cHandle added in v0.4.0

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

I2cHandle represents a way to talk to a specific device on the I2C bus. Creating a handle locks the bus so nothing else can use it, and closing the handle unlocks it again.

func (*I2cHandle) Close added in v0.4.0

func (h *I2cHandle) Close() error

Close closes the handle to the device, and unlocks the I2C bus.

func (*I2cHandle) Read added in v0.4.0

func (h *I2cHandle) Read(ctx context.Context, count int) ([]byte, error)

Read reads the given number of bytes from the handle. For I2C devices that organize their data into registers, prefer using ReadBlockData instead.

func (*I2cHandle) ReadBlockData added in v0.4.0

func (h *I2cHandle) ReadBlockData(ctx context.Context, register byte, numBytes uint8) ([]byte, error)

ReadBlockData reads the given number of bytes from the I2C device, starting at the given register.

func (*I2cHandle) ReadByteData added in v0.4.0

func (h *I2cHandle) ReadByteData(ctx context.Context, register byte) (byte, error)

ReadByteData reads a single byte from the given register on this I2C device.

func (*I2cHandle) Write added in v0.4.0

func (h *I2cHandle) Write(ctx context.Context, tx []byte) error

Write writes the given bytes to the handle. For I2C devices that organize their data into registers, prefer using WriteBlockData instead.

func (*I2cHandle) WriteBlockData added in v0.4.0

func (h *I2cHandle) WriteBlockData(ctx context.Context, register byte, data []byte) error

WriteBlockData writes the given bytes into the given register on the I2C device.

func (*I2cHandle) WriteByteData added in v0.4.0

func (h *I2cHandle) WriteByteData(ctx context.Context, register, data byte) error

WriteByteData writes a single byte to the given register on this I2C device.

type NoBoardFoundError

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

A NoBoardFoundError is returned when no compatible mapping is found for a board during GPIO board mapping.

func (NoBoardFoundError) Error

func (err NoBoardFoundError) Error() string

type PinDefinition

type PinDefinition struct {
	GPIOChipRelativeIDs map[int]int    // ngpio -> relative id
	GPIONames           map[int]string // e.g. ngpio=169=PQ.06 for claraAGXXavier
	GPIOChipSysFSDir    string
	PinNumberBoard      int
	PinNumberBCM        int
	PinNameCVM          string
	PinNameTegraSOC     string
	PWMChipSysFSDir     string // empty for none
	PWMID               int    // -1 for none
}

PinDefinition describes board specific information on how a particular pin can be accessed via sysfs along with information about its PWM capabilities.

Jump to

Keyboard shortcuts

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