Changeset 419 in flair-src for trunk/lib/FlairCore
- Timestamp:
- Apr 20, 2021, 6:27:53 PM (4 years ago)
- Location:
- trunk/lib/FlairCore/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairCore/src/Unix_SpiPort.cpp
r415 r419 30 30 string device,int mode, int bits, int speed) : SpiPort(parent, name) { 31 31 32 memset(&xfer, 0, sizeof(xfer));33 34 // open SPIdev35 32 fd = open(device.c_str(), O_RDWR); 36 33 if (fd < 0) { … … 38 35 } 39 36 40 if (mode) { 41 if (ioctl(fd, SPI_IOC_WR_MODE, &mode) < 0) { 42 Err("can't set bus mode\n"); 43 } 37 if (ioctl(fd, SPI_IOC_WR_MODE, &mode) < 0) { 38 Err("can't set bus mode\n"); 44 39 } 45 /* 46 if (ioctl(fd, SPI_IOC_RD_MODE, &mode) < 0) { 47 Err("can't get bus mode\n"); 48 } 49 */ 50 // get "LSB first" 51 uint8_t lsb; 52 if (ioctl(fd, SPI_IOC_RD_LSB_FIRST, &lsb) < 0) { 53 Err("can't get lsb first\n"); 40 41 if (ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits) < 0) { 42 Err("can't set bits per word\n"); 54 43 } 55 44 56 if (bits) { 57 if (ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits) < 0) { 58 Err("can't set bits per word\n"); 59 } 60 } 61 /* 62 // get bits per word 63 if (ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits) < 0) { 64 Err("can't get bits per word\n"); 65 } 66 */ 67 // set max speed [Hz] 68 if (speed) { 69 if (ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed) < 0) { 70 Err("can't set max speed [Hz]\n"); 71 } 72 } 73 /* 74 // get max speed [Hz] 75 if (ioctl(self->fd, SPI_IOC_RD_MAX_SPEED_HZ, &self->speed) < 0) 76 { 77 SPI_DBG("error in spi_init(): can't get max speed [Hz]"); 78 return SPI_ERR_SET_SPEED; 79 } 80 */ 45 if (ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed) < 0) { 46 Err("can't set max speed [Hz]\n"); 47 } 81 48 } 82 49 83 Unix_SpiPort::~Unix_SpiPort() { close(fd); } 50 Unix_SpiPort::~Unix_SpiPort() { 51 close(fd); 52 } 84 53 85 54 ssize_t Unix_SpiPort::Write(const void *buf, size_t nbyte) { 86 55 int retv; 56 struct spi_ioc_transfer xfer; 57 memset(&xfer, 0, sizeof(xfer)); 87 58 88 59 xfer.tx_buf = (__u64) buf; … … 100 71 ssize_t Unix_SpiPort::Read(void *buf, size_t nbyte) { 101 72 int retv; 73 struct spi_ioc_transfer xfer; 74 memset(&xfer, 0, sizeof(xfer)); 102 75 103 76 xfer.tx_buf = (__u64) 0; … … 115 88 ssize_t Unix_SpiPort::WriteRead(const void *tx_buf, void *rx_buf,size_t nbyte) { 116 89 int retv; 90 struct spi_ioc_transfer xfer; 91 memset(&xfer, 0, sizeof(xfer)); 117 92 118 93 xfer.tx_buf = (__u64) tx_buf; -
trunk/lib/FlairCore/src/Unix_SpiPort.h
r415 r419 82 82 private: 83 83 int fd; 84 struct spi_ioc_transfer xfer;85 84 86 85 };
Note:
See TracChangeset
for help on using the changeset viewer.