mockup

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package mockup provides GPIO mockups using the Linux gpio-mockup kernel module. This is intended for GPIO testing of gpiod, but could also be used for testing by users of their own code that uses gpiod.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckKernelVersion

func CheckKernelVersion(min Semver) error

CheckKernelVersion returns an error if the kernel version is less than the min.

func IsSupported

func IsSupported() error

IsSupported returns an error if this package cannot run on this platform.

func KernelVersion

func KernelVersion() (semver []byte, err error)

KernelVersion returns the running kernel version.

Types

type Chip

type Chip struct {
	Name      string
	Label     string
	Lines     int
	DevPath   string
	DbgfsPath string
}

Chip represents a single mocked GPIO chip.

func (*Chip) SetValue

func (c *Chip) SetValue(line int, value int) error

SetValue sets the pull value of the line.

func (*Chip) Value

func (c *Chip) Value(line int) (int, error)

Value returns the value of the line.

type ErrorBadVersion

type ErrorBadVersion struct {
	Need Semver
	Have Semver
}

ErrorBadVersion indicates the kernel version is insufficient.

func (ErrorBadVersion) Error

func (e ErrorBadVersion) Error() string

type ErrorIndexRange

type ErrorIndexRange struct {
	Req   int
	Limit int
}

ErrorIndexRange indicates the requested index is beyond the limit of the array.

func (ErrorIndexRange) Error

func (e ErrorIndexRange) Error() string

type Mockup

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

Mockup represents a number of GPIO chips being mocked.

func New

func New(lines []int, namedLines bool) (*Mockup, error)

New creates a new Mockup. A number of GPIO chips can be mocked, with the number of lines on each specified in lines. e.g. []int{4,6} would create two chips, the first with 4 lines and the second with 6. Requires the gpio-mockup kernel module and Linux 5.1.0 or later. Note that only one Mockup can be present on a system at any time and that this function unloads the gpio-mockup module if it is already loaded.

func (*Mockup) Chip

func (m *Mockup) Chip(num int) (*Chip, error)

Chip returns the mocked chip indicated by num.

func (*Mockup) Chips

func (m *Mockup) Chips() int

Chips returns the number of chips mocked.

func (*Mockup) Close

func (m *Mockup) Close() error

Close releases all resources held by the Mockup and unloads the gpio-mockup module.

type ModprobeMonitor

type ModprobeMonitor interface {
	Chips([]int) ([]Chip, error)
	Close()
}

ModprobeMonitor finds the details of gpio-mockup based gpiochips loaded via modprobe.

type Semver

type Semver []byte

Semver is 3 part version, Major, Minor, Patch.

func (Semver) String

func (v Semver) String() string

type SimpleMonitor

type SimpleMonitor struct{}

SimpleMonitor assumes an empty platform so any added gpiochips will be the first and only gpiochips.

func (*SimpleMonitor) Chips

func (m *SimpleMonitor) Chips(lines []int) ([]Chip, error)

Chips returns the chips corresponding to the requested number of lines per chip.

func (*SimpleMonitor) Close

func (m *SimpleMonitor) Close()

Close is just a stub to fulfil the ModprobeMonitor interface.

Jump to

Keyboard shortcuts

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