Index: /trunk/lib/FlairCore/src/SpiPort.h
===================================================================
--- /trunk/lib/FlairCore/src/SpiPort.h	(revision 415)
+++ /trunk/lib/FlairCore/src/SpiPort.h	(revision 415)
@@ -0,0 +1,79 @@
+// %flair:license{
+// This file is part of the Flair framework distributed under the
+// CECILL-C License, Version 1.0.
+// %flair:license}
+/*!
+ * \file SpiPort.h
+ * \brief Base class for spi port
+ * \author Guillaume Sanahuja, Copyright Heudiasyc UMR UTC/CNRS 7253
+ * \date 2021/04/13
+ * \version 4.0
+ */
+
+#ifndef SPIPORT_H
+#define SPIPORT_H
+
+#include <Object.h>
+#include <stdint.h>
+
+namespace flair {
+namespace core {
+/*! \class SpiPort
+*
+* \brief Base class for spi port
+*/
+class SpiPort : public Object {
+public:
+  /*!
+  * \brief Constructor
+  *
+  * Construct a spi port.
+  *
+  * \param parent parent
+  * \param name name
+  */
+  SpiPort(const Object *parent, std::string name) : Object(parent, name) {}
+
+  /*!
+  * \brief Destructor
+  *
+  */
+  ~SpiPort(){};
+
+
+  /*!
+  * \brief Write datas
+  *
+  * \param buf pointer to datas
+  * \param nbyte length of datas
+  *
+  * \return amount of written datas
+  */
+  virtual ssize_t Write(const void *buf, size_t nbyte) = 0;
+
+  /*!
+  * \brief Read datas
+  *
+  * \param buf pointer to datas
+  * \param nbyte length of datas
+  *
+  * \return amount of read datas
+  */
+  virtual ssize_t Read(void *buf, size_t nbyte) = 0;
+
+  /*!
+  * \brief Write datas
+  *
+  * \param tx_buf pointer to write datas
+  * \param rx_buf pointer to read datas
+  * \param nbyte length of datas
+  *
+  * \return amount of written datas
+  */
+  virtual ssize_t WriteRead(const void *tx_buf, void *rx_buf,size_t nbyte) = 0;
+
+};
+} // end namespace core
+} // end namespace flair
+
+#endif // SPIPORT_H
Index: /trunk/lib/FlairCore/src/Unix_SerialPort.h
===================================================================
--- /trunk/lib/FlairCore/src/Unix_SerialPort.h	(revision 414)
+++ /trunk/lib/FlairCore/src/Unix_SerialPort.h	(revision 415)
@@ -19,5 +19,5 @@
 namespace flair {
 namespace core {
-/*! \class RTDM_I2cPort
+/*! \class Unix_SerialPort
 *
 * \brief Class for unix serial port
Index: /trunk/lib/FlairCore/src/Unix_SpiPort.cpp
===================================================================
--- /trunk/lib/FlairCore/src/Unix_SpiPort.cpp	(revision 415)
+++ /trunk/lib/FlairCore/src/Unix_SpiPort.cpp	(revision 415)
@@ -0,0 +1,131 @@
+// %flair:license{
+// This file is part of the Flair framework distributed under the
+// CECILL-C License, Version 1.0.
+// %flair:license}
+//  created:    2021/04/13
+//  filename:   Unix_SpiPort.cpp
+//
+//  author:     Guillaume Sanahuja
+//              Copyright Heudiasyc UMR UTC/CNRS 7253
+//
+//  version:    $Id: $
+//
+//  purpose:    Class for unix spi port
+//
+//
+/*********************************************************************/
+
+#include "Unix_SpiPort.h"
+#include <fcntl.h> /* File control definitions */
+#include <unistd.h>
+#include <string.h>
+#include <sys/ioctl.h>
+
+using std::string;
+
+namespace flair {
+namespace core {
+
+Unix_SpiPort::Unix_SpiPort(const Object *parent, string name,
+                                 string device,int mode, int bits, int speed) : SpiPort(parent, name) {
+  
+  memset(&xfer, 0, sizeof(xfer));
+
+  // open SPIdev
+  fd = open(device.c_str(), O_RDWR);
+  if (fd < 0) {
+    Err("open_port: Unable to open %s\n", device.c_str());
+  }
+
+  if (mode) {
+    if (ioctl(fd, SPI_IOC_WR_MODE, &mode) < 0) {
+      Err("can't set bus mode\n");
+    }
+  }
+/*
+  if (ioctl(fd, SPI_IOC_RD_MODE, &mode) < 0) {
+    Err("can't get bus mode\n");
+  }
+*/
+  // get "LSB first"
+  uint8_t lsb;
+  if (ioctl(fd, SPI_IOC_RD_LSB_FIRST, &lsb) < 0) {
+    Err("can't get lsb first\n");
+  }
+
+  if (bits) {
+    if (ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits) < 0) {
+      Err("can't set bits per word\n");
+    }
+  }
+/*
+  // get bits per word
+  if (ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits) < 0) {
+    Err("can't get bits per word\n");
+  }
+*/
+  // set max speed [Hz]
+  if (speed) {
+    if (ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed) < 0) {
+      Err("can't set max speed [Hz]\n");
+    }
+  }
+  /*
+  // get max speed [Hz]
+  if (ioctl(self->fd, SPI_IOC_RD_MAX_SPEED_HZ, &self->speed) < 0)  
+  {
+    SPI_DBG("error in spi_init(): can't get max speed [Hz]");
+    return SPI_ERR_SET_SPEED;
+  }
+*/
+}
+
+Unix_SpiPort::~Unix_SpiPort() { close(fd); }
+
+ssize_t Unix_SpiPort::Write(const void *buf, size_t nbyte) {
+  int retv;
+
+  xfer.tx_buf = (__u64) buf;
+  xfer.rx_buf = (__u64) 0;
+  xfer.len    = (__u32) nbyte;
+
+  retv = ioctl(fd, SPI_IOC_MESSAGE(1), &xfer);
+  if (retv < 0) {
+    Err("ioctl SPI_IOC_MESSAGE\n");
+  }
+
+  return retv;
+}
+
+ssize_t Unix_SpiPort::Read(void *buf, size_t nbyte) {
+  int retv;
+
+  xfer.tx_buf = (__u64) 0;
+  xfer.rx_buf = (__u64) buf;
+  xfer.len    = (__u32) nbyte;
+
+  retv = ioctl(fd, SPI_IOC_MESSAGE(1), &xfer);
+  if (retv < 0) {
+    Err("ioctl SPI_IOC_MESSAGE\n");
+  }
+
+  return retv;
+}
+
+ssize_t Unix_SpiPort::WriteRead(const void *tx_buf, void *rx_buf,size_t nbyte) {
+  int retv;
+
+  xfer.tx_buf = (__u64) tx_buf;
+  xfer.rx_buf = (__u64) rx_buf;
+  xfer.len    = (__u32) nbyte;
+
+  retv = ioctl(fd, SPI_IOC_MESSAGE(1), &xfer);
+  if (retv < 0){
+    Err("ioctl SPI_IOC_MESSAGE\n");
+  }
+
+  return retv;
+}
+
+} // end namespace core
+} // end namespace flair
Index: /trunk/lib/FlairCore/src/Unix_SpiPort.h
===================================================================
--- /trunk/lib/FlairCore/src/Unix_SpiPort.h	(revision 415)
+++ /trunk/lib/FlairCore/src/Unix_SpiPort.h	(revision 415)
@@ -0,0 +1,90 @@
+// %flair:license{
+// This file is part of the Flair framework distributed under the
+// CECILL-C License, Version 1.0.
+// %flair:license}
+/*!
+ * \file Unix_SpiPort.h
+ * \brief Class for unix spi port
+ * \author Guillaume Sanahuja, Copyright Heudiasyc UMR UTC/CNRS 7253
+ * \date 2021/04/13
+ * \version 4.0
+ */
+
+#ifndef UNIX_SPIPORT_H
+#define UNIX_SPIPORT_H
+
+#include <SpiPort.h>
+#include <linux/spi/spidev.h>
+
+namespace flair {
+namespace core {
+/*! \class Unix_SpiPort
+*
+* \brief Class for unix spi port
+*
+*/
+class Unix_SpiPort : public SpiPort {
+
+public:
+  /*!
+  * \brief Constructor
+  *
+  * Construct an unix serial spi
+  *
+  * \param parent parent
+  * \param name name
+  * \param device serial device (ex /dev/ttyS0)
+  * \param mode SPI_* (look "linux/spi/spidev.h")
+  * \param bits bits per word (usually 8)
+  * \param speed max speed [Hz]
+  */
+  Unix_SpiPort(const Object *parent, std::string port_name,
+                  std::string device,int mode, int bits, int speed);
+
+  /*!
+  * \brief Destructor
+  *
+  */
+  ~Unix_SpiPort();
+
+  /*!
+  * \brief Write datas
+  *
+  * \param buf pointer to datas
+  * \param nbyte length of datas
+  *
+  * \return amount of written datas
+  */
+  ssize_t Write(const void *buf, size_t nbyte);
+
+  /*!
+  * \brief Read datas
+  *
+  * \param buf pointer to datas
+  * \param nbyte length of datas
+  *
+  * \return amount of read datas
+  */
+  ssize_t Read(void *buf, size_t nbyte);
+
+  /*!
+  * \brief Write datas
+  *
+  * \param tx_buf pointer to write datas
+  * \param rx_buf pointer to read datas
+  * \param nbyte length of datas
+  *
+  * \return amount of written datas
+  */
+  ssize_t WriteRead(const void *tx_buf, void *rx_buf,size_t nbyte);
+  
+
+private:
+  int fd;
+  struct spi_ioc_transfer xfer;
+  
+};
+} // end namespace core
+} // end namespace flair
+
+#endif // UNIX_SPIPORT_H
