Initial commit
This commit is contained in:
commit
289cc06b2f
58
ftdi_switch.go
Normal file
58
ftdi_switch.go
Normal file
@ -0,0 +1,58 @@
|
||||
package ftdi_switch
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/ziutek/ftdi"
|
||||
)
|
||||
|
||||
var (
|
||||
logger log.Logger = *log.Default()
|
||||
ftdi_device *ftdi.Device
|
||||
data_byte byte = 0
|
||||
)
|
||||
|
||||
func imit() {
|
||||
logger.SetPrefix("ftdi_switch: ")
|
||||
}
|
||||
|
||||
func start(vendor_id int, product_id int, init_value int) error {
|
||||
var err error
|
||||
ftdi_device, err = ftdi.OpenFirst(vendor_id, product_id, ftdi.ChannelAny)
|
||||
if err != nil {
|
||||
logger.Println(err)
|
||||
}
|
||||
|
||||
err = ftdi_device.SetBitmode(0xff, ftdi.ModeBitbang)
|
||||
if err != nil {
|
||||
logger.Println(err)
|
||||
}
|
||||
|
||||
err = ftdi_device.SetBaudrate(192)
|
||||
if err != nil {
|
||||
logger.Println(err)
|
||||
}
|
||||
err = write_byte(0)
|
||||
if err != nil {
|
||||
logger.Println(err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func stop() error {
|
||||
return ftdi_device.Close()
|
||||
}
|
||||
|
||||
func write_bit(bit byte, value bool) error {
|
||||
if value {
|
||||
data_byte |= 1 << bit
|
||||
} else {
|
||||
data_byte &= ^(1 << bit)
|
||||
}
|
||||
return ftdi_device.WriteByte(data_byte)
|
||||
}
|
||||
|
||||
func write_byte(data byte) error {
|
||||
data_byte = data
|
||||
return ftdi_device.WriteByte(data_byte)
|
||||
}
|
39
ftdi_switch_test.go
Normal file
39
ftdi_switch_test.go
Normal file
@ -0,0 +1,39 @@
|
||||
package ftdi_switch
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gotest.tools/v3/assert"
|
||||
)
|
||||
|
||||
const (
|
||||
ID_VENDOR int = 0x0403
|
||||
ID_PRODUCT int = 0x6014
|
||||
)
|
||||
|
||||
func TestMain(t *testing.T) {
|
||||
logger.SetPrefix("ftdi_switch: ")
|
||||
logger.Println("Starting")
|
||||
|
||||
var err error
|
||||
err = start(ID_VENDOR, ID_PRODUCT, 0)
|
||||
assert.NilError(t, err)
|
||||
|
||||
err = write_bit(3, true)
|
||||
assert.NilError(t, err)
|
||||
|
||||
err = write_bit(5, true)
|
||||
assert.NilError(t, err)
|
||||
|
||||
err = write_bit(6, true)
|
||||
assert.NilError(t, err)
|
||||
|
||||
err = write_bit(7, true)
|
||||
assert.NilError(t, err)
|
||||
|
||||
err = write_byte(0)
|
||||
assert.NilError(t, err)
|
||||
|
||||
err = stop()
|
||||
assert.NilError(t, err)
|
||||
}
|
10
go.mod
Normal file
10
go.mod
Normal file
@ -0,0 +1,10 @@
|
||||
module git.blackfinn.de/solar/ftdi_switch
|
||||
|
||||
go 1.21.0
|
||||
|
||||
require (
|
||||
github.com/ziutek/ftdi v0.0.1
|
||||
gotest.tools/v3 v3.5.0
|
||||
)
|
||||
|
||||
require github.com/google/go-cmp v0.5.9 // indirect
|
7
go.sum
Normal file
7
go.sum
Normal file
@ -0,0 +1,7 @@
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/ziutek/ftdi v0.0.1 h1:IrFtqLisIzEfgSnuLg1suZYLkn227DTyE464XswAGK4=
|
||||
github.com/ziutek/ftdi v0.0.1/go.mod h1:fUzQhjslJJSlwoMW5Cd+0RUc8KuMDfsuZB+wfJAz1eg=
|
||||
github.com/ziutek/lcd v0.0.0-20141212131202-924f223d0903/go.mod h1:ZBCPhfHIcCtzsrXIcyEiSPDKHrjT9fXtJNKj2t1HCKw=
|
||||
gotest.tools/v3 v3.5.0 h1:Ljk6PdHdOhAb5aDMWXjDLMMhph+BpztA4v1QdqEW2eY=
|
||||
gotest.tools/v3 v3.5.0/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
|
Loading…
Reference in New Issue
Block a user