4#include <linux/spi/spidev.h>
7#include "yahal_assert.h"
9spi_BBB::spi_BBB(
const char * dev) : _device(dev) {
10 _fd = open(_device, O_RDWR);
11 yahal_assert(_fd != -1);
15 int ret = close( _fd );
16 yahal_assert(ret != -1);
20int16_t spi_BBB::spiTxRx(
const uint8_t *txbuf, uint8_t *rxbuf, uint16_t len) {
22 memset(&tr, 0,
sizeof(tr));
24 tr.tx_buf = (
unsigned long)txbuf;
25 tr.rx_buf = (
unsigned long)rxbuf;
28 int ret = ioctl(_fd, SPI_IOC_MESSAGE(1), &tr);
29 yahal_assert(ret != -1);
33int16_t spi_BBB::spiTx(
const uint8_t *txbuf, uint16_t len) {
35 memset(&tr, 0,
sizeof(tr));
37 tr.tx_buf = (
unsigned long)txbuf;
38 tr.rx_buf = (
unsigned long)NULL;
41 int ret = ioctl(_fd, SPI_IOC_MESSAGE(1), &tr);
42 yahal_assert(ret != -1);
46int16_t spi_BBB::spiRx(uint8_t txbyte, uint8_t *rxbuf, uint16_t len) {
48 memset(&tr, 0,
sizeof(tr));
50 tr.tx_buf = (
unsigned long)NULL;
51 tr.rx_buf = (
unsigned long)rxbuf;
54 int ret = ioctl(_fd, SPI_IOC_MESSAGE(1), &tr);
55 yahal_assert(ret != -1);
59void spi_BBB::setSpeed(uint32_t Hz) {
62void spi_BBB::generateCS(
bool val) {
65void spi_BBB::setCS(
bool val) {
68void spi_BBB::spiAttachRxIrq(
void (*)(uint8_t data)) {