2021-06-26 15:24:07 +02:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2020-04-21 08:53:52 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2020 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef SRC_SPIINTERFACE_HPP_
|
|
|
|
|
#define SRC_SPIINTERFACE_HPP_
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \file SPIInterface.hpp
|
|
|
|
|
* \class SPIInterface
|
|
|
|
|
* \brief abstract class between spi implementation and converters
|
|
|
|
|
* \author Gwenhael Goavec-Merou
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
class SPIInterface {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~SPIInterface() {}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief send a command, followed by len byte.
|
|
|
|
|
* \param[in] cmd: command/opcode to send
|
|
|
|
|
* \param[in] tx: buffer to send
|
|
|
|
|
* \param[in] rx: buffer for read access
|
|
|
|
|
* \param[in] len: number of byte to send/receive (cmd not comprise)
|
|
|
|
|
* to send only a cmd set len to 0
|
|
|
|
|
* \return 0 when success
|
|
|
|
|
*/
|
|
|
|
|
virtual int spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx,
|
2020-08-23 17:16:21 +02:00
|
|
|
uint32_t len) = 0;
|
2020-04-21 08:53:52 +02:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief send a command, followed by len byte.
|
|
|
|
|
* \param[in] tx: buffer to send
|
|
|
|
|
* \param[in] rx: buffer for read access
|
|
|
|
|
* \param[in] len: number of byte to send/receive
|
|
|
|
|
* \return 0 when success
|
|
|
|
|
*/
|
2020-08-23 17:16:21 +02:00
|
|
|
virtual int spi_put(uint8_t *tx, uint8_t *rx, uint32_t len) = 0;
|
2020-04-21 08:53:52 +02:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief wait until register content and mask match cond, or timeout
|
|
|
|
|
* \param[in] cmd: register to read
|
|
|
|
|
* \param[in] mask: mask used with read byte
|
|
|
|
|
* \param[in] cond: condition to wait
|
|
|
|
|
* \param[in] timeout: number of try before fail
|
|
|
|
|
* \return 0 when success, -ETIME when timeout occur
|
|
|
|
|
*/
|
|
|
|
|
virtual int spi_wait(uint8_t cmd, uint8_t mask, uint8_t cond,
|
|
|
|
|
uint32_t timeout, bool verbose = false) = 0;
|
|
|
|
|
};
|
|
|
|
|
#endif // SRC_SPIINTERFACE_HPP_
|