gpio

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2020 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package gpio allows to configure and controll General Purpose I/O ports and their pins.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AIN added in v0.1.2

type AIN int8

AIN is an analog input number.

const (
	VDD      AIN = 9   // VDD
	VDDHDIV5 AIN = 0xD // VDDH / 5
)

func (AIN) Pin added in v0.1.2

func (a AIN) Pin() Pin

Pin returns the GPIO pin that can be used as analog input a.

type Config

type Config uint32

Config is configuration word of GPIO pin.

const (
	ModeIn     Config = 0 // Input buffer connected, output disabled.
	ModeInOut  Config = 1 // Input buffer connected, output enabled.
	ModeDiscon Config = 2 // Input buffer disconnected, output disabled.
	ModeOut    Config = 3 // Input buffer disconnected, output enabled.

	PullNone Config = 0 << 2 // Disable pull-up/down resistance.
	PullDown Config = 1 << 2 // Enable pull-down resistance.
	PullUp   Config = 3 << 2 // Enable pull-up resistance.

	DriveS0S1 Config = 0 << 8 // Standard 0, standard 1.
	DriveH0S1 Config = 1 << 8 // High drive 0, standard 1.
	DriveS0H1 Config = 2 << 8 // Standard 0, high drive 1.
	DriveH0H1 Config = 3 << 8 // High drive 0, high drive 1.
	DriveD0S1 Config = 4 << 8 // Disconnect 0, standard 1.
	DriveD0H1 Config = 5 << 8 // Disconnect 0, high drive 1.
	DriveS0D1 Config = 6 << 8 // Standard 0, disconnect 1.
	DriveH0D1 Config = 7 << 8 // High drive 0, disconnect 1.

	SenseNone Config = 0 << 16 // Sense disabled.
	SenseHigh Config = 2 << 16 // Sense for high level.
	SenseLow  Config = 3 << 16 // Sense for low level.
)

type DetectMode added in v0.1.3

type DetectMode uint8
const (
	Direct  DetectMode = 0 // DETECT directly connected to PIN DETECT signals.
	Latched DetectMode = 1 // Use the latched LDETECT behaviour.
)

type PSEL added in v0.1.2

type PSEL uint32

PSEL is numerical representation of GPIO pin used as peripheral digital signal. It can have two states: connected or disconnected to the peripheral.

func (PSEL) Connected added in v0.1.2

func (ps PSEL) Connected(connected bool) PSEL

Connected returns ps with connection state changed.

func (PSEL) IsConnected added in v0.1.2

func (ps PSEL) IsConnected() bool

IsConnected reports the connection state of ps.

func (PSEL) Pin added in v0.1.2

func (ps PSEL) Pin() Pin

Pin returns the GPIO pin corresponding to ps.

type Pin

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

Pin represents one phisical pin (specific pin in specific port).

func (Pin) AIN added in v0.1.2

func (p Pin) AIN() AIN

AIN retruns analog intput number that corresponds to p or -1 if pin can not be used as analog input.

func (Pin) Clear

func (p Pin) Clear()

Clear sets output value of the pin to 0 in one atomic operation.

func (Pin) ClearDetect added in v0.1.3

func (p Pin) ClearDetect()

ClearDetect clears the detect state for pin. nRF52.

func (Pin) Config

func (p Pin) Config() Config

Config returns current configuration of pin.

func (Pin) Detect added in v0.1.3

func (p Pin) Detect() bool

Detect reports whether the pin have met the criteria set by Sense* configuration options. nRF52.

func (Pin) IsValid

func (p Pin) IsValid() bool

IsValid reports whether p represents a valid pin.

func (Pin) Load

func (p Pin) Load() int

Load returns input value of the pin.

func (Pin) LoadOut

func (p Pin) LoadOut() int

LoadOut returns output value of the pin.

func (Pin) Mask

func (p Pin) Mask() Pins

Mask returns bitmask that represents the pin.

func (Pin) Num added in v0.1.2

func (p Pin) Num() int

Num returns the pin number in the port.

func (Pin) PSEL added in v0.1.2

func (p Pin) PSEL() PSEL

PSEL returns the PSEL representation of GPIO pin in connected state.

func (Pin) Port

func (p Pin) Port() *Port

Port returns the port where the pin is located.

func (Pin) Set

func (p Pin) Set()

Set sets output value of the pin to 1 in one atomic operation.

func (Pin) Setup

func (p Pin) Setup(cfg Config)

Setup configures pin.

func (Pin) Store

func (p Pin) Store(val int)

Store sets output value of the pin to the least significant bit of val.

type Pins

type Pins uint32

Pins is a bitmask which represents the pins of GPIO port.

const (
	Pin0 Pins = 1 << iota
	Pin1
	Pin2
	Pin3
	Pin4
	Pin5
	Pin6
	Pin7
	Pin8
	Pin9
	Pin10
	Pin11
	Pin12
	Pin13
	Pin14
	Pin15
	Pin16
	Pin17
	Pin18
	Pin19
	Pin20
	Pin21
	Pin22
	Pin23
	Pin24
	Pin25
	Pin26
	Pin27
	Pin28
	Pin29
	Pin30
	Pin31
)

type Port

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

Port represents a GPIO port.

func P

func P(n int) *Port

P returns n-th GPIO port

func (*Port) ClearDetect added in v0.1.3

func (p *Port) ClearDetect(pins Pins)

ClearDetect clears the detect state for specified pins. nRF52.

func (*Port) ClearPins

func (p *Port) ClearPins(pins Pins)

ClearPins sets output value of pins to 0 in one atomic operation.

func (*Port) Detect added in v0.1.3

func (p *Port) Detect() Pins

Detect returns pins that have met the criteria set by Sense* configuration options. nRF52.

func (*Port) DetectMode added in v0.1.3

func (p *Port) DetectMode() DetectMode

DetectMode returns current DETECT mode. nRF52.

func (*Port) Load

func (p *Port) Load() Pins

Load returns input value of all pins.

func (*Port) LoadOut

func (p *Port) LoadOut() Pins

LoadOut returns output value of all pins.

func (*Port) Num added in v0.1.2

func (p *Port) Num() int

Num returns the port number.

func (*Port) Pin

func (p *Port) Pin(n int) Pin

Pin returns n-th pin in port p.

func (*Port) PinConfig

func (p *Port) PinConfig(n int) Config

PinConfig returns current configuration of n-th pin in port p.

func (*Port) Pins

func (p *Port) Pins(pins Pins) Pins

Pins returns input value of pins.

func (*Port) PinsOut

func (p *Port) PinsOut(pins Pins) Pins

PinsOut returns output value of pins.

func (*Port) SetDetectMode added in v0.1.3

func (p *Port) SetDetectMode(mode DetectMode)

DetectMode sets DETECT mode. nRF52.

func (*Port) SetDirIn

func (p *Port) SetDirIn(pins Pins)

SetDirIn allows a fast change multiple pins to input mode.

func (*Port) SetDirOut

func (p *Port) SetDirOut(pins Pins)

SetDirIn allows a fast change multiple pins to output mode.

func (*Port) SetPins

func (p *Port) SetPins(pins Pins)

SetPins sets output value of pins to 1 in one atomic operation.

func (*Port) Setup

func (p *Port) Setup(pins Pins, cfg Config)

Setup configures pins.

func (*Port) SetupPin

func (p *Port) SetupPin(n int, cfg Config)

Setup configures n-th pin in port p.

func (*Port) Store

func (p *Port) Store(val Pins)

Store sets output value of all pins to value specified by val.

Jump to

Keyboard shortcuts

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