Changeset 419 in flair-src for trunk/lib


Ignore:
Timestamp:
Apr 20, 2021, 6:27:53 PM (4 years ago)
Author:
Sanahuja Guillaume
Message:

spi changes

Location:
trunk/lib/FlairCore/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairCore/src/Unix_SpiPort.cpp

    r415 r419  
    3030                                 string device,int mode, int bits, int speed) : SpiPort(parent, name) {
    3131 
    32   memset(&xfer, 0, sizeof(xfer));
    33 
    34   // open SPIdev
    3532  fd = open(device.c_str(), O_RDWR);
    3633  if (fd < 0) {
     
    3835  }
    3936
    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");
    4439  }
    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");
    5443  }
    5544
    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  }
    8148}
    8249
    83 Unix_SpiPort::~Unix_SpiPort() { close(fd); }
     50Unix_SpiPort::~Unix_SpiPort() {
     51  close(fd);
     52}
    8453
    8554ssize_t Unix_SpiPort::Write(const void *buf, size_t nbyte) {
    8655  int retv;
     56  struct spi_ioc_transfer xfer;
     57  memset(&xfer, 0, sizeof(xfer));
    8758
    8859  xfer.tx_buf = (__u64) buf;
     
    10071ssize_t Unix_SpiPort::Read(void *buf, size_t nbyte) {
    10172  int retv;
     73  struct spi_ioc_transfer xfer;
     74  memset(&xfer, 0, sizeof(xfer));
    10275
    10376  xfer.tx_buf = (__u64) 0;
     
    11588ssize_t Unix_SpiPort::WriteRead(const void *tx_buf, void *rx_buf,size_t nbyte) {
    11689  int retv;
     90  struct spi_ioc_transfer xfer;
     91  memset(&xfer, 0, sizeof(xfer));
    11792
    11893  xfer.tx_buf = (__u64) tx_buf;
  • trunk/lib/FlairCore/src/Unix_SpiPort.h

    r415 r419  
    8282private:
    8383  int fd;
    84   struct spi_ioc_transfer xfer;
    8584 
    8685};
Note: See TracChangeset for help on using the changeset viewer.