mirror of
https://github.com/kidoman/embd
synced 2025-07-03 20:07:40 +02:00
spi: remove types from const declarations and added few more go docs
This commit is contained in:
parent
2d3dee8764
commit
32c9a96af5
2 changed files with 21 additions and 15 deletions
|
@ -5,16 +5,22 @@ import (
|
|||
"github.com/kidoman/embd"
|
||||
)
|
||||
|
||||
// MCP3008 represents a mcp3008 8bit DAC
|
||||
// MCP3008 represents a mcp3008 8bit DAC.
|
||||
type MCP3008 struct {
|
||||
mode byte
|
||||
Mode byte
|
||||
|
||||
bus embd.SPIBus
|
||||
Bus embd.SPIBus
|
||||
}
|
||||
|
||||
var SingleMode byte = 1
|
||||
var DifferenceMode byte = 0
|
||||
const (
|
||||
// SingleMode represents the single-ended mode for the mcp3008.
|
||||
SingleMode = 1
|
||||
|
||||
// DifferenceMode represents the diffenrential mode for the mcp3008.
|
||||
DifferenceMode = 0
|
||||
)
|
||||
|
||||
// New creates a representation of the mcp3008 convertor
|
||||
func New(mode byte, bus embd.SPIBus) *MCP3008 {
|
||||
return &MCP3008{mode, bus}
|
||||
}
|
||||
|
@ -23,14 +29,15 @@ const (
|
|||
startBit = 1
|
||||
)
|
||||
|
||||
// AnalogValueAt returns the analog value at the given channel of the convertor.
|
||||
func (m *MCP3008) AnalogValueAt(chanNum int) (int, error) {
|
||||
var data [3]uint8
|
||||
data[0] = startBit
|
||||
data[1] = uint8(m.mode)<<7 | uint8(chanNum)<<4
|
||||
data[1] = uint8(m.Mode)<<7 | uint8(chanNum)<<4
|
||||
data[2] = 0
|
||||
|
||||
glog.V(2).Infof("mcp3008: sendingdata buffer %v", data)
|
||||
if err := m.bus.TransferAndRecieveData(data[:]); err != nil {
|
||||
if err := m.Bus.TransferAndRecieveData(data[:]); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue