gpio

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package gpio provides interface to configure and control GPIO ports, pins and alternate functions.

This package handles the whole STM32 family in uniform way, even though the GPIO design used in STM32F1xx series is significantly different than the one used in newer series.

Index

Constants

View Source
const (
	A = iota
	B
	C
	D
	E
	F
	G
	H
	I
	J
	K
)

Port names

View Source
const Pnum = pnum

Pnum is the number of available GPIO ports.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Mode   Mode   // Mode: input, output, analog, alternate function.
	Driver Driver // Output driver type: push-pull or open-drain.
	Speed  Speed  // Output speed.
	Pull   Pull   // Pull-up/pull-down resistors.
}

Config contains parameters used to setup GPIO pin.

type Driver

type Driver byte

Driver specifies output driver mode.

const (
	PushPull  Driver = 0
	OpenDrain Driver = openDrain
)

type Mode

type Mode byte

Mode specifies operation mode.

const (
	In    Mode = 0     // Logical input.
	Out   Mode = out   // Logical output.
	Alt   Mode = alt   // Alternate function output or bidirectional i/o.
	AltIn Mode = altIn // Alternate function input.
	Ana   Mode = ana   // Analog mode.
)

type Pin

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

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

func (Pin) Clear

func (p Pin) Clear()

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

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) Lock

func (p Pin) Lock()

Lock locks configuration of pin. Locked configuration can not be modified until reset

func (Pin) Mask

func (p Pin) Mask() Pins

Mask return bitmask that represents the pin.

func (Pin) Num added in v0.4.5

func (p Pin) Num() int

Num returns pin number in the port.

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 uint16

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

const (
	Pin0 Pins = 1 << iota
	Pin1
	Pin2
	Pin3
	Pin4
	Pin5
	Pin6
	Pin7
	Pin8
	Pin9
	Pin10
	Pin11
	Pin12
	Pin13
	Pin14
	Pin15
)

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 (0 means port A, 1 means port B, etc.). You can use PA, PB, PC, ... helper functions instead of P if the port number is constant.

func (*Port) Bus

func (p *Port) Bus() bus.Bus

Bus returns a bus to which p is connected.

func (*Port) ClearAndSet

func (p *Port) ClearAndSet(clear, set Pins)

ClearAndSet clears and sets output value of all pins in one atomic operation. Setting pins has priority above clearing bits.

func (*Port) ClearPins

func (p *Port) ClearPins(pins Pins)

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

func (*Port) DisableClock

func (p *Port) DisableClock()

DisableClock disables clock for port p.

func (*Port) EnableClock

func (p *Port) EnableClock(lp bool)

EnableClock enables clock for port p. lp determines whether the clock remains on in low power (sleep) mode.

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) Lock

func (p *Port) Lock(pins Pins)

Lock locks configuration of specified pins. Locked configuration can not be modified until reset.

func (*Port) Num

func (p *Port) Num() int

Num returns the port number: 0 for A, 1 for B, etc.

func (*Port) Pin

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

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) Reset

func (p *Port) Reset()

Reset resets port p.

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(index int, cfg *Config)

SetupPin configures one pin.

func (*Port) Store

func (p *Port) Store(val Pins)

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

func (*Port) StorePins

func (p *Port) StorePins(pins, val Pins)

StorePins sets pins specified by pins to val in one atomic operation.

type Pull

type Pull byte

Pull specifies pull-up/pull-down configuration.

const (
	NoPull   Pull = 0        // No pull-up/pull-down
	PullUp   Pull = pullUp   // Activate internal pull-up resistor.
	PullDown Pull = pullDown // Activate internal pull-down resistor.
)

type Speed

type Speed int8

Speed specifies speed of output driver. Concrete STM32 series implements 3 or 4 speed levels. Slow, Medium and Fast levels are always implemented. Actual speed at given level depends on supply voltage and load capacity. See the datasheet for more info.

const (
	VeryLow  Speed = veryLow  // Typically < 1 MHz.
	Low      Speed = low      // Typically < 2 MHz.
	Medium   Speed = 0        // Typically < 25 MHz.
	High     Speed = high     // Typically < 50 MHz.
	VeryHigh Speed = veryHigh // Typically < 100 MHz.
)

Jump to

Keyboard shortcuts

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