periph: periph.io/x/periph/conn/mmr Index | Examples | Files

package mmr

import "periph.io/x/periph/conn/mmr"

Package mmr defines helpers to interact with devices exposing Memory Mapped Registers protocol.

The protocol is defined two supported commands:

- Write Address, Read Value
- Write Address, Write Value

Index

Examples

Package Files

mmr.go

type Dev16 Uses

type Dev16 struct {
    Conn conn.Conn
    // Order specifies the binary encoding of words. It is expected to be either
    // binary.BigEndian or binary.LittleEndian or a specialized implemented if
    // necessary. A good example of such need is devices communicating 32bits
    // little endian values encoded over 16bits big endian words.
    Order binary.ByteOrder
}

Dev16 is a Dev that exposes memory mapped registers in a 16bits address space.

func (*Dev16) Duplex Uses

func (d *Dev16) Duplex() conn.Duplex

Duplex implements conn.Conn.

func (*Dev16) ReadStruct Uses

func (d *Dev16) ReadStruct(reg uint16, b interface{}) error

ReadStruct writes the register number to the connection, then reads the data into `b` and marshall it via `.Order` as appropriate.

It is expected to be called with a slice of integers, slice of structs, pointer to an integer or to a struct.

func (*Dev16) ReadUint16 Uses

func (d *Dev16) ReadUint16(reg uint16) (uint16, error)

ReadUint16 reads a 16 bit register.

func (*Dev16) ReadUint32 Uses

func (d *Dev16) ReadUint32(reg uint16) (uint32, error)

ReadUint32 reads a 32 bit register.

func (*Dev16) ReadUint64 Uses

func (d *Dev16) ReadUint64(reg uint16) (uint64, error)

ReadUint64 reads a 64 bit register.

func (*Dev16) ReadUint8 Uses

func (d *Dev16) ReadUint8(reg uint16) (uint8, error)

ReadUint8 reads a 8 bit register.

func (*Dev16) String Uses

func (d *Dev16) String() string

String implements conn.Conn.

func (*Dev16) Tx Uses

func (d *Dev16) Tx(w, r []byte) error

Tx implements conn.Conn.

func (*Dev16) WriteStruct Uses

func (d *Dev16) WriteStruct(reg uint16, b interface{}) error

WriteStruct writes the register number to the connection, then the data `b` marshalled via `.Order` as appropriate.

It is expected to be called with a slice of integers, slice of structs, pointer to an integer or to a struct.

func (*Dev16) WriteUint16 Uses

func (d *Dev16) WriteUint16(reg uint16, v uint16) error

WriteUint16 writes a 16 bit register.

func (*Dev16) WriteUint32 Uses

func (d *Dev16) WriteUint32(reg uint16, v uint32) error

WriteUint32 writes a 32 bit register.

func (*Dev16) WriteUint64 Uses

func (d *Dev16) WriteUint64(reg uint16, v uint64) error

WriteUint64 writes a 64 bit register.

func (*Dev16) WriteUint8 Uses

func (d *Dev16) WriteUint8(reg uint16, v uint8) error

WriteUint8 writes a 8 bit register.

type Dev8 Uses

type Dev8 struct {
    Conn conn.Conn
    // Order specifies the binary encoding of words. It is expected to be either
    // binary.BigEndian or binary.LittleEndian or a specialized implemented if
    // necessary. A good example of such need is devices communicating 32bits
    // little endian values encoded over 16bits big endian words.
    Order binary.ByteOrder
}

Dev8 is a connection that exposes memory mapped registers in a 8bit address space.

Code:

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

// Open a connection, using I²C as an example:
b, err := i2creg.Open("")
if err != nil {
    log.Fatal(err)
}
defer b.Close()
c := &i2c.Dev{Bus: b, Addr: 0xD0}

d := mmr.Dev8{Conn: c, Order: binary.BigEndian}
v, err := d.ReadUint8(0xD0)
if err != nil {
    log.Fatal(err)
}
if v == 0x60 {
    fmt.Printf("Found bme280 on bus %s\n", b)
}

func (*Dev8) Duplex Uses

func (d *Dev8) Duplex() conn.Duplex

Duplex implements conn.Conn.

func (*Dev8) ReadStruct Uses

func (d *Dev8) ReadStruct(reg uint8, b interface{}) error

ReadStruct writes the register number to the connection, then reads the data into `b` and marshall it via `.Order` as appropriate.

It is expected to be called with a slice of integers, slice of structs, pointer to an integer or to a struct.

Code:

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

// Open a connection, using I²C as an example:
b, err := i2creg.Open("")
if err != nil {
    log.Fatal(err)
}
defer b.Close()
c := &i2c.Dev{Bus: b, Addr: 0xD0}

d := mmr.Dev8{Conn: c, Order: binary.BigEndian}
flags := struct {
    Flag16 uint16
    Flag8  [2]uint8
}{}
if err = d.ReadStruct(0xD0, &flags); err != nil {
    log.Fatal(err)
}
// Use flags.Flag16 and flags.Flag8.

func (*Dev8) ReadUint16 Uses

func (d *Dev8) ReadUint16(reg uint8) (uint16, error)

ReadUint16 reads a 16 bit register.

func (*Dev8) ReadUint32 Uses

func (d *Dev8) ReadUint32(reg uint8) (uint32, error)

ReadUint32 reads a 32 bit register.

func (*Dev8) ReadUint64 Uses

func (d *Dev8) ReadUint64(reg uint8) (uint64, error)

ReadUint64 reads a 64 bit register.

func (*Dev8) ReadUint8 Uses

func (d *Dev8) ReadUint8(reg uint8) (uint8, error)

ReadUint8 reads a 8 bit register.

func (*Dev8) String Uses

func (d *Dev8) String() string

String implements conn.Conn.

func (*Dev8) Tx Uses

func (d *Dev8) Tx(w, r []byte) error

Tx implements conn.Conn.

func (*Dev8) WriteStruct Uses

func (d *Dev8) WriteStruct(reg uint8, b interface{}) error

WriteStruct writes the register number to the connection, then the data `b` marshalled via `.Order` as appropriate.

It is expected to be called with a slice of integers, slice of structs, pointer to an integer or to a struct.

Code:

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

// Open a connection, using 1-wire as an example:
b, err := onewirereg.Open("")
if err != nil {
    log.Fatal(err)
}
defer b.Close()
c := &onewire.Dev{Bus: b, Addr: 0xD0}

d := mmr.Dev8{Conn: c, Order: binary.LittleEndian}
flags := struct {
    Flag16 uint16
    Flag8  [2]uint8
}{
    0x1234,
    [2]uint8{1, 2},
}
if err = d.WriteStruct(0xD0, &flags); err != nil {
    log.Fatal(err)
}

func (*Dev8) WriteUint16 Uses

func (d *Dev8) WriteUint16(reg uint8, v uint16) error

WriteUint16 writes a 16 bit register.

func (*Dev8) WriteUint32 Uses

func (d *Dev8) WriteUint32(reg uint8, v uint32) error

WriteUint32 writes a 32 bit register.

func (*Dev8) WriteUint64 Uses

func (d *Dev8) WriteUint64(reg uint8, v uint64) error

WriteUint64 writes a 64 bit register.

func (*Dev8) WriteUint8 Uses

func (d *Dev8) WriteUint8(reg uint8, v uint8) error

WriteUint8 writes a 8 bit register.

Package mmr imports 6 packages (graph) and is imported by 9 packages. Updated 2018-12-22. Refresh now. Tools for package owners.