bcm283x

package
v2.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2017 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package bcm283x exposes the BCM283x GPIO functionality.

This driver implements memory-mapped GPIO pin manipulation and leverages sysfs-gpio for edge detection.

If you are looking at the actual implementation, open doc.go for further implementation details.

Datasheet

https://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf

Its crowd-sourced errata: http://elinux.org/BCM2835_datasheet_errata

BCM2836: https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2836/QA7_rev3.4.pdf

Another doc about PCM and PWM: https://scribd.com/doc/127599939/BCM2835-Audio-clocks

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Nanospin

func Nanospin(t time.Duration)

Nanospin spins the CPU without calling into the kernel code if possible.

func Present

func Present() bool

Present returns true if running on a Broadcom bcm283x based CPU.

func ReadTime

func ReadTime() time.Duration

ReadTime returns the time on a monotonic 1Mhz clock (1µs resolution).

It only works if bcm283x-dma successfully loaded. Otherwise it returns 0.

Types

type Pin

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

Pin is a GPIO number (GPIOnn) on BCM238(5|6|7).

Pin implements gpio.PinIO.

var (
	GPIO0  *Pin // I2C0_SDA
	GPIO1  *Pin // I2C0_SCL
	GPIO2  *Pin // I2C1_SDA
	GPIO3  *Pin // I2C1_SCL
	GPIO4  *Pin // GPCLK0
	GPIO5  *Pin // GPCLK1
	GPIO6  *Pin // GPCLK2
	GPIO7  *Pin // SPI0_CS1
	GPIO8  *Pin // SPI0_CS0
	GPIO9  *Pin // SPI0_MISO
	GPIO10 *Pin // SPI0_MOSI
	GPIO11 *Pin // SPI0_CLK
	GPIO12 *Pin // PWM0_OUT
	GPIO13 *Pin // PWM1_OUT
	GPIO14 *Pin // UART0_TXD, UART1_TXD
	GPIO15 *Pin // UART0_RXD, UART1_RXD
	GPIO16 *Pin // UART0_CTS, SPI1_CS2, UART1_CTS
	GPIO17 *Pin // UART0_RTS, SPI1_CS1, UART1_RTS
	GPIO18 *Pin // PCM_CLK, SPI1_CS0, PWM0_OUT
	GPIO19 *Pin // PCM_FS, SPI1_MISO, PWM1_OUT
	GPIO20 *Pin // PCM_DIN, SPI1_MOSI, GPCLK0
	GPIO21 *Pin // PCM_DOUT, SPI1_CLK, GPCLK1
	GPIO22 *Pin //
	GPIO23 *Pin //
	GPIO24 *Pin //
	GPIO25 *Pin //
	GPIO26 *Pin //
	GPIO27 *Pin //
	GPIO28 *Pin // I2C0_SDA, PCM_CLK
	GPIO29 *Pin // I2C0_SCL, PCM_FS
	GPIO30 *Pin // PCM_DIN, UART0_CTS, UART1_CTS
	GPIO31 *Pin // PCM_DOUT, UART0_RTS, UART1_RTS
	GPIO32 *Pin // GPCLK0, UART0_TXD, UART1_TXD
	GPIO33 *Pin // UART0_RXD, UART1_RXD
	GPIO34 *Pin // GPCLK0
	GPIO35 *Pin // SPI0_CS1
	GPIO36 *Pin // SPI0_CS0, UART0_TXD
	GPIO37 *Pin // SPI0_MISO, UART0_RXD
	GPIO38 *Pin // SPI0_MOSI, UART0_RTS
	GPIO39 *Pin // SPI0_CLK, UART0_CTS
	GPIO40 *Pin // PWM0_OUT, SPI2_MISO, UART1_TXD
	GPIO41 *Pin // PWM1_OUT, SPI2_MOSI, UART1_RXD
	GPIO42 *Pin // GPCLK1, SPI2_CLK, UART1_RTS
	GPIO43 *Pin // GPCLK2, SPI2_CS0, UART1_CTS
	GPIO44 *Pin // GPCLK1, I2C0_SDA, I2C1_SDA, SPI2_CS1
	GPIO45 *Pin // PWM1_OUT, I2C0_SCL, I2C1_SCL, SPI2_CS2
	GPIO46 *Pin //

)

All the pins supported by the CPU.

func (*Pin) DefaultPull

func (p *Pin) DefaultPull() gpio.Pull

DefaultPull returns the default pull for the pin.

Implements gpio.PinDefaultPull.

The CPU doesn't return the current pull.

func (*Pin) FastOut

func (p *Pin) FastOut(l gpio.Level)

FastOut sets a pin output level with Absolutely No error checking.

Out() Must be called once first before calling FastOut(), otherwise the behavior is undefined. Then FastOut() can be used for minimal CPU overhead to reach Mhz scale bit banging.

func (*Pin) Function

func (p *Pin) Function() string

Function returns the current pin function, ex: "In/PullUp".

func (*Pin) Halt

func (p *Pin) Halt() error

Halt implements conn.Resource.

If the pin is running a clock, PWM or waiting for edges, it is halted.

In the case of clock or PWM, all pins with this clock source are also disabled.

func (*Pin) In

func (p *Pin) In(pull gpio.Pull, edge gpio.Edge) error

In setups a pin as an input and implements gpio.PinIn.

Specifying a value for pull other than gpio.PullNoChange causes this function to be slightly slower (about 1ms).

For pull down, the resistor is 50KOhm~60kOhm For pull up, the resistor is 50kOhm~65kOhm

The pull resistor stays set even after the processor shuts down. It is not possible to 'read back' what value was specified for each pin.

Will fail if requesting to change a pin that is set to special functionality.

Using edge detection requires opening a gpio sysfs file handle. On Raspbian, make sure the user is member of group 'gpio'. The pin will be exported at /sys/class/gpio/gpio*/. Note that the pin will not be unexported at shutdown.

For edge detection, the processor samples the input at its CPU clock rate and looks for '011' to rising and '100' for falling detection to avoid glitches. Because gpio sysfs is used, the latency is unpredictable.

func (*Pin) Name

func (p *Pin) Name() string

Name returns the pin name, ex: "GPIO10".

func (*Pin) Number

func (p *Pin) Number() int

Number returns the pin number as assigned by gpio sysfs.

func (*Pin) Out

func (p *Pin) Out(l gpio.Level) error

Out sets a pin as output and implements gpio.PinOut.

Fails if requesting to change a pin that is set to special functionality.

func (*Pin) PWM

func (p *Pin) PWM(duty gpio.Duty, period time.Duration) error

PWM outputs a periodic signal on supported pins.

PWM pins

PWM0 is exposed on pins 12, 18 and 40.

PWM1 is exposed on pins 13, 19, 41 and 45.

PWM0 and PWM1 share the same 25Mhz clock source. The period must be a divisor of 25Mhz.

Clock pins

Clock GPCLK0 is exposed on pins 4, 20 32 and 34.

Clock GPCLK2 is exposed on pins 6 and 43.

Clocks can only be used with duty 0, gpio.DutyHalf or gpio.DutyMax. They also have relatively limited frequency range from 4.8kHz to 1MHz with a specific set of values supported.

Furthermore, these can only be used if the drive "bcm283x-dma" was loaded. It can only be loaded if the process has root level access.

The user must call either Halt(), In(), Out(), PWM(0,..) or PWM(gpio.DutyMax,..) to stop the clock source before exiting the program.

func (*Pin) Pull

func (p *Pin) Pull() gpio.Pull

Pull implemented gpio.PinIn.

bcm283x doesn't support querying the pull resistor of any GPIO pin.

func (*Pin) Read

func (p *Pin) Read() gpio.Level

Read return the current pin level and implements gpio.PinIn.

This function is very fast. It works even if the pin is set as output.

func (*Pin) String

func (p *Pin) String() string

String returns the pin name, ex: "GPIO10".

func (*Pin) WaitForEdge

func (p *Pin) WaitForEdge(timeout time.Duration) bool

WaitForEdge does edge detection and implements gpio.PinIn.

Notes

Bugs

  • PWM(): There is no conflict verification when multiple pins are used simultaneously. The last call to PWM() will affect all pins of the same type (GPCLK0, GPCLK2, PWM0 or PWM1).

Directories

Path Synopsis
Package bcm283xsmoketest verifies that bcm283x specific functionality work.
Package bcm283xsmoketest verifies that bcm283x specific functionality work.

Jump to

Keyboard shortcuts

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