aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/machine/serial.go
blob: 4aacc502e89f3ff57752a8df74128baad0c0c510 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package machine

import "errors"

var errNoByte = errors.New("machine: no byte read")

// UARTConfig is a struct with which a UART (or similar object) can be
// configured. The baud rate is usually respected, but TX and RX may be ignored
// depending on the chip and the type of object.
type UARTConfig struct {
	BaudRate uint32
	TX       Pin
	RX       Pin
	RTS      Pin
	CTS      Pin
}

// NullSerial is a serial version of /dev/null (or null router): it drops
// everything that is written to it.
type NullSerial struct {
}

// Configure does nothing: the null serial has no configuration.
func (ns NullSerial) Configure(config UARTConfig) error {
	return nil
}

// WriteByte is a no-op: the null serial doesn't write bytes.
func (ns NullSerial) WriteByte(b byte) error {
	return nil
}

// ReadByte always returns an error because there aren't any bytes to read.
func (ns NullSerial) ReadByte() (byte, error) {
	return 0, errNoByte
}

// Buffered returns how many bytes are buffered in the UART. It always returns 0
// as there are no bytes to read.
func (ns NullSerial) Buffered() int {
	return 0
}

// Write is a no-op: none of the data is being written and it will not return an
// error.
func (ns NullSerial) Write(p []byte) (n int, err error) {
	return len(p), nil
}