YAHAL
Yet Another Hardware Abstraction Library
Loading...
Searching...
No Matches
spi_BBB.cpp
1#include <fcntl.h> // O_RDWR
2#include <unistd.h> // close
3#include <sys/ioctl.h> // ioctl
4#include <linux/spi/spidev.h> // SPI_IOC_MESSAGE
5#include <memory.h> // memset
6#include "spi_BBB.h"
7#include "yahal_assert.h"
8
9spi_BBB::spi_BBB(const char * dev) : _device(dev) {
10 _fd = open(_device, O_RDWR);
11 yahal_assert(_fd != -1);
12}
13
14spi_BBB::~spi_BBB() {
15 int ret = close( _fd );
16 yahal_assert(ret != -1);
17}
18
19
20int16_t spi_BBB::spiTxRx(const uint8_t *txbuf, uint8_t *rxbuf, uint16_t len) {
21 spi_ioc_transfer tr;
22 memset(&tr, 0, sizeof(tr));
23
24 tr.tx_buf = (unsigned long)txbuf;
25 tr.rx_buf = (unsigned long)rxbuf;
26 tr.len = len;
27
28 int ret = ioctl(_fd, SPI_IOC_MESSAGE(1), &tr);
29 yahal_assert(ret != -1);
30 return ret;
31}
32
33int16_t spi_BBB::spiTx(const uint8_t *txbuf, uint16_t len) {
34 spi_ioc_transfer tr;
35 memset(&tr, 0, sizeof(tr));
36
37 tr.tx_buf = (unsigned long)txbuf;
38 tr.rx_buf = (unsigned long)NULL;
39 tr.len = len;
40
41 int ret = ioctl(_fd, SPI_IOC_MESSAGE(1), &tr);
42 yahal_assert(ret != -1);
43 return ret;
44}
45
46int16_t spi_BBB::spiRx(uint8_t txbyte, uint8_t *rxbuf, uint16_t len) {
47 spi_ioc_transfer tr;
48 memset(&tr, 0, sizeof(tr));
49
50 tr.tx_buf = (unsigned long)NULL;
51 tr.rx_buf = (unsigned long)rxbuf;
52 tr.len = len;
53
54 int ret = ioctl(_fd, SPI_IOC_MESSAGE(1), &tr);
55 yahal_assert(ret != -1);
56 return ret;
57}
58
59void spi_BBB::setSpeed(uint32_t Hz) {
60}
61
62void spi_BBB::generateCS(bool val) {
63}
64
65void spi_BBB::setCS(bool val) {
66}
67
68void spi_BBB::spiAttachRxIrq(void (*)(uint8_t data)) {
69}
70