github.com/embeddedgo/x@v0.0.6-0.20191217015414-d79a36f562e7/radio/nrf24/nrf.go (about) 1 // Copyright 2019 Michal Derkacz. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package nrf24 6 7 // DCI represents the simplified nRF24L01(+) Data and Control Interface: only 8 // SPI part of the full DCI is need. 9 type DCI interface { 10 // WriteRead performs full SPI transation: sets CSN low, writes and reads oi 11 // data and sets CSN high. 12 WriteRead(oi ...[]byte) int 13 14 // Err returns and clears internal error status. 15 Err(clear bool) error 16 } 17 18 // Radio provides interface to the nRF24L01(+) transceiver. Radio methods are 19 // mainly used to send commands that read or write internal registers. Every 20 // such command, as a side effect, always reads the value of STATUS regster as 21 // it was just before the command was executed. This status value is always 22 // returned as the last return value of the command method. 23 type Radio struct { 24 DCI DCI 25 } 26 27 // NewRadio provides convenient way to create heap allocated Radio struct. 28 func NewRadio(dci DCI) *Radio { 29 dev := new(Radio) 30 dev.DCI = dci 31 return dev 32 } 33 34 // Err returns the error value of the last executed command. You can freely 35 // invoke many commands before check an error. If one command have caused an 36 // error the subsequent commands will not be executed until Err(true) will be 37 // called. 38 func (r *Radio) Err(clear bool) error { 39 return r.DCI.Err(clear) 40 }