LCOV - code coverage report
Current view: top level - include/core/hardio/interfaces - spi_slave.h (source / functions) Hit Total Coverage
Test: hardiocore_coverage Lines: 0 1 0.0 %
Date: 2025-05-26 19:00:29 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /*      File: spi_slave.h
       2             :  *       This file is part of the program hardiocore
       3             :  *       Program description : Abstract low level I/O removing direct hardware
       4             :  * implementation Copyright (C) 2018-2020 -  Robin Passama (CNRS / LIRMM)
       5             :  * Clement Rebut (EPITA / LIRMM) Charles Villard (EPITA / LIRMM). All Right
       6             :  * reserved.
       7             :  *
       8             :  *       This software is free software: you can redistribute it and/or modify
       9             :  *       it under the terms of the CeCILL-C license as published by
      10             :  *       the CEA CNRS INRIA, either version 1
      11             :  *       of the License, or (at your option) any later version.
      12             :  *       This software is distributed in the hope that it will be useful,
      13             :  *       but WITHOUT ANY WARRANTY without even the implied warranty of
      14             :  *       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      15             :  *       CeCILL-C License for more details.
      16             :  *
      17             :  *       You should have received a copy of the CeCILL-C License
      18             :  *       along with this software. If not, it can be found on the official
      19             :  * website of the CeCILL licenses family (http://www.cecill.info/index.en.html).
      20             :  */
      21             : /**
      22             :  * @file interfaces/spi_slave.h
      23             :  * @author Robin Passama
      24             :  * @brief header file for SPISlaveInterface class.
      25             :  * @date May 2025
      26             :  * @ingroup  core
      27             :  */
      28             : #pragma once
      29             : 
      30             : #include <hardio/common/interface.h>
      31             : #include <hardio/protocols/spi.h>
      32             : 
      33             : namespace hardio {
      34             : 
      35             : /**
      36             :  * @brief Access point to a slave device in a SPI network
      37             :  *
      38             :  */
      39             : class SPISlaveInterface : public ProtocolInterface<SPIProtocol> {
      40             : public:
      41             :     using base_type = SPISlaveInterface;
      42             :     SPISlaveInterface(size_t slave_select_index);
      43           0 :     virtual ~SPISlaveInterface() = default;
      44             : 
      45             :     /**
      46             :      * @brief Get interface id
      47             :      *
      48             :      * @return string representing the id of the interface
      49             :      */
      50             :     std::string id() const override;
      51             : 
      52             :     /**
      53             :      * @brief proceed to a SPI data transfer of one byte
      54             :      * @param [in] data_out the byte sent to the slave
      55             :      * @param [out] data_in the byte received from the slave
      56             :      * @return true if the transfer was successful, false otherwise
      57             :      */
      58             :     bool transfer(uint8_t data_out, uint8_t& data_in);
      59             : 
      60             :     /**
      61             :      * @brief proceed to a SPI data transfer of many bytes
      62             :      * @param [in] length the size of bytes buffer length
      63             :      * @param [in] data the buffer of bytes sent to the slave
      64             :      * @param [out] received the pointer to buffer that received bytes from the
      65             :      * slave
      66             :      * @return true if the transfer was successful, false otherwise
      67             :      */
      68             :     bool transfer(size_t length, uint8_t* data, uint8_t* received);
      69             : 
      70             :     /**
      71             :      * @brief Get SPI index of teh slave
      72             :      *
      73             :      * @return the index of the slave in the SPI bus
      74             :      */
      75             :     size_t index() const;
      76             : 
      77             : private:
      78             :     size_t slave_select_index_;
      79             : };
      80             : 
      81             : } // namespace hardio

Generated by: LCOV version 1.16