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 ¶
- func GetGPIOBoardMappingFromPinDefs(pinDefs []PinDefinition) (map[string]GPIOBoardMapping, error)
- func GetGPIOBoardMappings(modelName string, boardInfoMappings map[string]BoardInformation) (map[string]GPIOBoardMapping, error)
- func GetI2CBus(deps resource.Dependencies, boardName, busName, busNum string) (board.I2C, error)
- func NewBoard(ctx context.Context, conf resource.Config, convertConfig ConfigConverter, ...) (board.Board, error)
- func NewSpiBus(name string) board.SPI
- func RegisterBoard(modelName string, gpioMappings map[string]GPIOBoardMapping)
- type Board
- func (b *Board) AnalogReaderByName(name string) (board.AnalogReader, bool)
- func (b *Board) AnalogReaderNames() []string
- func (b *Board) Close(ctx context.Context) error
- func (b *Board) DigitalInterruptByName(name string) (board.DigitalInterrupt, bool)
- func (b *Board) DigitalInterruptNames() []string
- func (b *Board) GPIOPinByName(pinName string) (board.GPIOPin, error)
- func (b *Board) GPIOPinNames() []string
- func (b *Board) I2CByName(name string) (board.I2C, bool)
- func (b *Board) I2CNames() []string
- func (b *Board) ModelAttributes() board.ModelAttributes
- func (b *Board) Reconfigure(ctx context.Context, _ resource.Dependencies, conf resource.Config) error
- func (b *Board) SPIByName(name string) (board.SPI, bool)
- func (b *Board) SPINames() []string
- func (b *Board) SetPowerMode(ctx context.Context, mode pb.PowerMode, duration *time.Duration) error
- func (b *Board) Status(ctx context.Context, extra map[string]interface{}) (*commonpb.BoardStatus, error)
- func (b *Board) WriteAnalog(ctx context.Context, pin string, value int32, extra map[string]interface{}) error
- type BoardInformation
- type Config
- type ConfigConverter
- type GPIOBoardMapping
- type I2cBus
- type I2cHandle
- func (h *I2cHandle) Close() error
- func (h *I2cHandle) Read(ctx context.Context, count int) ([]byte, error)
- func (h *I2cHandle) ReadBlockData(ctx context.Context, register byte, numBytes uint8) ([]byte, error)
- func (h *I2cHandle) ReadByteData(ctx context.Context, register byte) (byte, error)
- func (h *I2cHandle) Write(ctx context.Context, tx []byte) error
- func (h *I2cHandle) WriteBlockData(ctx context.Context, register byte, data []byte) error
- func (h *I2cHandle) WriteByteData(ctx context.Context, register, data byte) error
- type LinuxBoardConfig
- type NoBoardFoundError
- type PinDefinition
- type PinDefinitions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetGPIOBoardMappingFromPinDefs ¶ added in v0.6.0
func GetGPIOBoardMappingFromPinDefs(pinDefs []PinDefinition) (map[string]GPIOBoardMapping, error)
GetGPIOBoardMappingFromPinDefs attempts to find a compatible board-pin mapping using the pin definitions.
func GetGPIOBoardMappings ¶
func GetGPIOBoardMappings(modelName string, boardInfoMappings map[string]BoardInformation) (map[string]GPIOBoardMapping, error)
GetGPIOBoardMappings attempts to find a compatible GPIOBoardMapping for the given board.
func GetI2CBus ¶ added in v0.11.0
GetI2CBus retrieves an I2C interface. If the bus number is specified, it uses that on the local machine, and otherwise it tries to get the named bus from the named board. Although it would be intuitive for the bus number to be an integer, we keep it as a string because it's possible for a devicetree overlay on some unusual board to make it non-numerical. TODO(RSDK-5254): remove this once all I2C devices are talking directly to the bus without going through the board.
func NewBoard ¶ added in v0.7.3
func NewBoard( ctx context.Context, conf resource.Config, convertConfig ConfigConverter, logger logging.Logger, ) (board.Board, error)
NewBoard is the constructor for a Board.
func NewSpiBus ¶ added in v0.12.0
NewSpiBus creates a new SPI bus. The name passed in should be the bus number, such as "0" or "1". We don't open this bus until you call spiHandle.Xfer(), so there are no errors to return immediately here.
func RegisterBoard ¶
func RegisterBoard(modelName string, gpioMappings map[string]GPIOBoardMapping)
RegisterBoard registers a sysfs based board of the given model.
Types ¶
type Board ¶ added in v0.7.3
Board implements a component for a Linux machine.
func (*Board) AnalogReaderByName ¶ added in v0.7.3
func (b *Board) AnalogReaderByName(name string) (board.AnalogReader, bool)
AnalogReaderByName returns the analog reader by the given name if it exists.
func (*Board) AnalogReaderNames ¶ added in v0.7.3
AnalogReaderNames returns the names of all known analog readers.
func (*Board) DigitalInterruptByName ¶ added in v0.7.3
func (b *Board) DigitalInterruptByName(name string) (board.DigitalInterrupt, bool)
DigitalInterruptByName returns the interrupt by the given name if it exists.
func (*Board) DigitalInterruptNames ¶ added in v0.7.3
DigitalInterruptNames returns the names of all known digital interrupts.
func (*Board) GPIOPinByName ¶ added in v0.7.3
GPIOPinByName returns a GPIOPin by name.
func (*Board) GPIOPinNames ¶ added in v0.7.3
GPIOPinNames returns the names of all known GPIO pins.
func (*Board) ModelAttributes ¶ added in v0.7.3
func (b *Board) ModelAttributes() board.ModelAttributes
ModelAttributes returns attributes related to the model of this board.
func (*Board) Reconfigure ¶ added in v0.7.3
func (b *Board) Reconfigure( ctx context.Context, _ resource.Dependencies, conf resource.Config, ) error
Reconfigure reconfigures the board with interrupt pins, spi and i2c, and analogs.
func (*Board) SetPowerMode ¶ added in v0.7.3
func (b *Board) SetPowerMode( ctx context.Context, mode pb.PowerMode, duration *time.Duration, ) error
SetPowerMode sets the board to the given power mode. If provided, the board will exit the given power mode after the specified duration.
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"` AnalogReaders []board.MCP3008AnalogConfig `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.
type ConfigConverter ¶ added in v0.7.3
type ConfigConverter = func(resource.Config) (*LinuxBoardConfig, error)
ConfigConverter is a type synonym for a function to turn whatever config we get during reconfiguration into a LinuxBoardConfig, so that we can reconfigure based on that. We return a pointer to a LinuxBoardConfig instead of the struct itself so that we can return nil if we encounter an error.
func ConstPinDefs ¶ added in v0.7.3
func ConstPinDefs(gpioMappings map[string]GPIOBoardMapping) ConfigConverter
ConstPinDefs takes in a map from pin names to GPIOBoardMapping structs, and returns a ConfigConverter that will use these pin definitions in the underlying config. It is intended to be used for board components whose pin definitions are built into the RDK, such as the BeagleBone or Jetson boards.
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 (*I2cBus) OpenHandle ¶ added in v0.4.0
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
Close closes the handle to the device, and unlocks the I2C bus.
func (*I2cHandle) Read ¶ added in v0.4.0
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
ReadByteData reads a single byte from the given register on this I2C device.
func (*I2cHandle) Write ¶ added in v0.4.0
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
WriteBlockData writes the given bytes into the given register on the I2C device.
type LinuxBoardConfig ¶ added in v0.7.3
type LinuxBoardConfig struct { I2Cs []board.I2CConfig SPIs []board.SPIConfig AnalogReaders []board.MCP3008AnalogConfig DigitalInterrupts []board.DigitalInterruptConfig GpioMappings map[string]GPIOBoardMapping }
LinuxBoardConfig is a struct containing absolutely everything a genericlinux board might need configured. It is a union of the configs for the customlinux boards and the genericlinux boards with static pin definitions, because those components all use the same underlying code but have different config types (e.g., only genericlinux has named I2C and SPI buses, while only customlinux can change its pin definitions during reconfiguration). The LinuxBoardConfig struct is a unification of the two of them. Whenever we go through reconfiguration, we convert the provided config into this type, and then reconfigure based on this.
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 { Name string `json:"name"` DeviceName string `json:"device_name"` // name of the pin's chip's device, within /dev LineNumber int `json:"line_number"` // relative line number on chip PwmChipSysfsDir string `json:"pwm_chip_sysfs_dir,omitempty"` PwmID int `json:"pwm_id,omitempty"` }
PinDefinition describes a gpio pin on a linux board.
func (*PinDefinition) UnmarshalJSON ¶ added in v0.6.0
func (conf *PinDefinition) UnmarshalJSON(text []byte) error
UnmarshalJSON handles setting defaults for pin configs. Int values default to -1.
func (*PinDefinition) Validate ¶ added in v0.6.0
func (conf *PinDefinition) Validate(path string) error
Validate ensures all parts of the config are valid.
type PinDefinitions ¶ added in v0.6.0
type PinDefinitions struct {
Pins []PinDefinition `json:"pins"`
}
PinDefinitions describes a list of pins on a linux board.