forked from TheCacophonyProject/periph
/
driverskeleton.go
82 lines (66 loc) · 2.05 KB
/
driverskeleton.go
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright 2016 The Periph Authors. All rights reserved.
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.
package driverskeleton
import (
"errors"
"periph.io/x/periph"
"periph.io/x/periph/conn"
"periph.io/x/periph/conn/i2c"
)
// FIXME: Expose public symbols as relevant. Do not export more than needed!
// See https://periph.io/x/periph/tree/master/doc/drivers#requirements
// for the expectations.
// Dev is a handle to the device. FIXME.
type Dev struct {
c conn.Conn
}
// New opens a handle to the device. FIXME.
func New(i i2c.Bus) (*Dev, error) {
d := &Dev{&i2c.Dev{Bus: i, Addr: 42}}
// FIXME: Simulate a setup dance.
var b [2]byte
if err := d.c.Tx([]byte("in"), b[:]); err != nil {
return nil, err
}
if b[0] != 'I' || b[1] != 'N' {
return nil, errors.New("driverskeleton: unexpected reply")
}
return d, nil
}
// Read is a method on your device. FIXME.
func (d *Dev) Read() string {
var b [12]byte
if err := d.c.Tx([]byte("what"), b[:]); err != nil {
return err.Error()
}
return string(b[:])
}
// FIXME: A driver is generally only needed for host drivers. If you implement
// a device driver, delete the remainder of this file.
// driver implements periph.Driver.
type driver struct {
}
func (d *driver) String() string {
// FIXME: Change this string to be unique. It must match the directory name.
return "driverskeleton"
}
func (d *driver) Prerequisites() []string {
// FIXME: Declare prerequisites drivers if relevant.
return nil
}
func (d *driver) Init() (bool, error) {
// FIXME: If the driver is not needed, do the following:
// return false, errors.New("not running on a skeleton")
// FIXME: Add implementation.
return true, errors.New("driverskeleton: not implemented")
}
func init() {
// Since isArm is a compile time constant, the compile can strip the
// unnecessary code and unused private symbols.
//if isArm {
periph.MustRegister(&driver{})
//}
}
// FIXME: This verifies that the driver implements all the required methods.
var _ periph.Driver = &driver{}