mmr

package
v3.4.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dev16

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

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

Duplex implements conn.Conn.

func (*Dev16) ReadStruct

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

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

ReadUint16 reads a 16 bit register.

func (*Dev16) ReadUint32

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

ReadUint32 reads a 32 bit register.

func (*Dev16) ReadUint64

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

ReadUint64 reads a 64 bit register.

func (*Dev16) ReadUint8

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

ReadUint8 reads a 8 bit register.

func (*Dev16) String

func (d *Dev16) String() string

String implements conn.Conn.

func (*Dev16) Tx

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

Tx implements conn.Conn.

func (*Dev16) WriteStruct

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

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

WriteUint16 writes a 16 bit register.

func (*Dev16) WriteUint32

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

WriteUint32 writes a 32 bit register.

func (*Dev16) WriteUint64

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

WriteUint64 writes a 64 bit register.

func (*Dev16) WriteUint8

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

WriteUint8 writes a 8 bit register.

type Dev8

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.

Example
package main

import (
	"encoding/binary"
	"fmt"
	"log"

	"periph.io/x/periph/conn/i2c"
	"periph.io/x/periph/conn/i2c/i2creg"
	"periph.io/x/periph/conn/mmr"
	"periph.io/x/periph/host"
)

func main() {
	// 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)
	}
}
Output:

func (*Dev8) Duplex

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

Duplex implements conn.Conn.

func (*Dev8) ReadStruct

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.

Example
package main

import (
	"encoding/binary"
	"log"

	"periph.io/x/periph/conn/i2c"
	"periph.io/x/periph/conn/i2c/i2creg"
	"periph.io/x/periph/conn/mmr"
	"periph.io/x/periph/host"
)

func main() {
	// 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.
}
Output:

func (*Dev8) ReadUint16

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

ReadUint16 reads a 16 bit register.

func (*Dev8) ReadUint32

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

ReadUint32 reads a 32 bit register.

func (*Dev8) ReadUint64

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

ReadUint64 reads a 64 bit register.

func (*Dev8) ReadUint8

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

ReadUint8 reads a 8 bit register.

func (*Dev8) String

func (d *Dev8) String() string

String implements conn.Conn.

func (*Dev8) Tx

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

Tx implements conn.Conn.

func (*Dev8) WriteStruct

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.

Example
package main

import (
	"encoding/binary"
	"log"

	"periph.io/x/periph/conn/mmr"
	"periph.io/x/periph/conn/onewire"
	"periph.io/x/periph/conn/onewire/onewirereg"
	"periph.io/x/periph/host"
)

func main() {
	// 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)
	}
}
Output:

func (*Dev8) WriteUint16

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

WriteUint16 writes a 16 bit register.

func (*Dev8) WriteUint32

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

WriteUint32 writes a 32 bit register.

func (*Dev8) WriteUint64

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

WriteUint64 writes a 64 bit register.

func (*Dev8) WriteUint8

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

WriteUint8 writes a 8 bit register.

Jump to

Keyboard shortcuts

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