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 ¶
- type Dev16
- func (d *Dev16) ReadStruct(reg uint16, b interface{}) error
- func (d *Dev16) ReadUint16(reg uint16) (uint16, error)
- func (d *Dev16) ReadUint32(reg uint16) (uint32, error)
- func (d *Dev16) ReadUint64(reg uint16) (uint64, error)
- func (d *Dev16) ReadUint8(reg uint16) (uint8, error)
- func (d *Dev16) String() string
- func (d *Dev16) WriteStruct(reg uint16, b interface{}) error
- func (d *Dev16) WriteUint16(reg uint16, v uint16) error
- func (d *Dev16) WriteUint32(reg uint16, v uint32) error
- func (d *Dev16) WriteUint64(reg uint16, v uint64) error
- func (d *Dev16) WriteUint8(reg uint16, v uint8) error
- type Dev8
- func (d *Dev8) ReadStruct(reg uint8, b interface{}) error
- func (d *Dev8) ReadUint16(reg uint8) (uint16, error)
- func (d *Dev8) ReadUint32(reg uint8) (uint32, error)
- func (d *Dev8) ReadUint64(reg uint8) (uint64, error)
- func (d *Dev8) ReadUint8(reg uint8) (uint8, error)
- func (d *Dev8) String() string
- func (d *Dev8) WriteStruct(reg uint8, b interface{}) error
- func (d *Dev8) WriteUint16(reg uint8, v uint16) error
- func (d *Dev8) WriteUint32(reg uint8, v uint32) error
- func (d *Dev8) WriteUint64(reg uint8, v uint64) error
- func (d *Dev8) WriteUint8(reg uint8, v uint8) error
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) ReadStruct ¶
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 ¶
ReadUint16 reads a 16 bit register.
func (*Dev16) ReadUint32 ¶
ReadUint32 reads a 32 bit register.
func (*Dev16) ReadUint64 ¶
ReadUint64 reads a 64 bit register.
func (*Dev16) WriteStruct ¶
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 ¶
WriteUint16 writes a 16 bit register.
func (*Dev16) WriteUint32 ¶
WriteUint32 writes a 32 bit register.
func (*Dev16) WriteUint64 ¶
WriteUint64 writes a 64 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 ¶
// Open a connection, using I²C as an example: bus, err := i2creg.Open("") if err != nil { log.Fatal(err) } defer bus.Close() c := &i2c.Dev{Bus: bus, Addr: 0xD0} dev := Dev8{c, binary.BigEndian} v, err := dev.ReadUint8(0xD0) if err != nil { log.Fatal(err) } if v == 0x60 { fmt.Printf("Found bme280 on bus %s\n", bus) }
Output:
func (*Dev8) ReadStruct ¶
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 ¶
// Open a connection, using I²C as an example: bus, err := i2creg.Open("") if err != nil { log.Fatal(err) } defer bus.Close() c := &i2c.Dev{Bus: bus, Addr: 0xD0} dev := Dev8{c, binary.BigEndian} flags := struct { Flag16 uint16 Flag8 [2]uint8 }{} if err = dev.ReadStruct(0xD0, &flags); err != nil { log.Fatal(err) } // Use flags.Flag16 and flags.Flag8.
Output:
func (*Dev8) ReadUint16 ¶
ReadUint16 reads a 16 bit register.
func (*Dev8) ReadUint32 ¶
ReadUint32 reads a 32 bit register.
func (*Dev8) ReadUint64 ¶
ReadUint64 reads a 64 bit register.
func (*Dev8) WriteStruct ¶
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 ¶
// Open a connection, using 1-wire as an example: bus, err := onewirereg.Open("") if err != nil { log.Fatal(err) } defer bus.Close() c := &onewire.Dev{Bus: bus, Addr: 0xD0} dev := Dev8{c, binary.LittleEndian} flags := struct { Flag16 uint16 Flag8 [2]uint8 }{ 0x1234, [2]uint8{1, 2}, } if err = dev.WriteStruct(0xD0, &flags); err != nil { log.Fatal(err) }
Output:
func (*Dev8) WriteUint16 ¶
WriteUint16 writes a 16 bit register.
func (*Dev8) WriteUint32 ¶
WriteUint32 writes a 32 bit register.
func (*Dev8) WriteUint64 ¶
WriteUint64 writes a 64 bit register.