uart

package
v2.3.0+incompatible Latest Latest
Warning

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

Go to latest
Published: May 27, 2018 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package uart defines the UART protocol.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn interface {
	conn.Conn
	// Speed changes the bus speed.
	Speed(baud int) error
	// Configure changes the communication parameters of the bus.
	//
	// There's rarely a reason to use anything else than One stop bit and 8 bits
	// per character.
	Configure(stopBit Stop, parity Parity, bits int) error
}

Conn defines the interface a concrete UART driver must implement.

It implements conn.Conn.

type ConnCloser

type ConnCloser interface {
	io.Closer
	Conn
}

ConnCloser is a connection that can be closed.

type Parity

type Parity byte

Parity determines the parity bit when transmitting, if any.

const (
	// None means no parity bit
	None Parity = 'N'
	// Odd means 1 when sum is odd
	Odd Parity = 'O'
	// Even means 1 when sum is even
	Even Parity = 'E'
	// Mark means always 1
	Mark Parity = 'M'
	// Space means always 0
	Space Parity = 'S'
)

type Pins

type Pins interface {
	// RX returns the receive pin.
	RX() gpio.PinIn
	// TX returns the transmit pin.
	TX() gpio.PinOut
	// RTS returns the request to send pin.
	RTS() gpio.PinIO
	// CTS returns the clear to send pin.
	CTS() gpio.PinIO
}

Pins defines the pins that an UART bus interconnect is using on the host.

It is expected that a implementer of Conn also implement Pins but this is not a requirement.

Example
package main

import (
	"fmt"
	"log"

	"periph.io/x/periph/experimental/conn/uart"
	"periph.io/x/periph/experimental/conn/uart/uartreg"
	"periph.io/x/periph/host"
)

func main() {
	// Make sure periph is initialized.
	if _, err := host.Init(); err != nil {
		log.Fatal(err)
	}

	// Use uartreg UART port registry to find the first available UART port.
	p, err := uartreg.Open("")
	if err != nil {
		log.Fatal(err)
	}
	defer p.Close()

	// Prints out the gpio pin used.
	if p, ok := p.(uart.Pins); ok {
		fmt.Printf("  RX : %s", p.RX())
		fmt.Printf("  TX : %s", p.TX())
		fmt.Printf("  RTS: %s", p.RTS())
		fmt.Printf("  CTS: %s", p.CTS())
	}
}
Output:

type Stop

type Stop int8

Stop determines what stop bit to use.

const (
	// One is 1 stop bit
	One Stop = 0
	// OneHalf is 1.5 stop bits
	OneHalf Stop = 1
	// Two is 2 stop bits
	Two Stop = 2
)

Directories

Path Synopsis
Package uartreg defines the UART registry for UART ports discovered on the host.
Package uartreg defines the UART registry for UART ports discovered on the host.

Jump to

Keyboard shortcuts

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