2017-05-22 06:25:30 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) Karan Misra 2014
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
|
|
* associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
|
|
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
|
|
|
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all copies or
|
|
|
|
* substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
|
|
|
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2014-05-07 19:53:29 +02:00
|
|
|
// +build ignore
|
|
|
|
|
2014-04-27 21:48:14 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2017-05-20 10:36:48 +02:00
|
|
|
"github.com/cfreeman/embd"
|
|
|
|
_ "github.com/cfreeman/embd/host/all"
|
2014-04-27 21:48:14 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2014-05-08 19:39:31 +02:00
|
|
|
if err := embd.InitSPI(); err != nil {
|
2014-04-27 21:48:14 +02:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer embd.CloseSPI()
|
|
|
|
|
2014-05-21 22:49:01 +02:00
|
|
|
spiBus := embd.NewSPIBus(embd.SPIMode0, 0, 1000000, 8, 0)
|
2014-04-27 21:48:14 +02:00
|
|
|
defer spiBus.Close()
|
|
|
|
|
2014-05-21 23:01:42 +02:00
|
|
|
dataBuf := [3]uint8{1, 2, 3}
|
2014-04-27 21:48:14 +02:00
|
|
|
|
2015-12-22 18:54:33 +01:00
|
|
|
if err := spiBus.TransferAndReceiveData(dataBuf[:]); err != nil {
|
2014-04-27 21:48:14 +02:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2015-12-22 23:05:28 +01:00
|
|
|
fmt.Println("received data is:", dataBuf)
|
2014-04-27 21:48:14 +02:00
|
|
|
|
|
|
|
dataReceived, err := spiBus.ReceiveData(3)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2015-12-22 23:05:28 +01:00
|
|
|
fmt.Println("received data is:", dataReceived)
|
2014-04-27 21:48:14 +02:00
|
|
|
|
|
|
|
dataByte := byte(1)
|
|
|
|
receivedByte, err := spiBus.TransferAndReceiveByte(dataByte)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2015-12-22 23:05:28 +01:00
|
|
|
fmt.Println("received byte is:", receivedByte)
|
2014-04-27 21:48:14 +02:00
|
|
|
|
|
|
|
receivedByte, err = spiBus.ReceiveByte()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2015-12-22 23:05:28 +01:00
|
|
|
fmt.Println("received byte is:", receivedByte)
|
2014-04-27 21:48:14 +02:00
|
|
|
}
|