peary/interfaces/SPI/spi.hpp

Peary SPI Interface. More…

Namespaces

Name
peary
peary::interface

Classes

Name
class peary::interface::iface_spi SPI interface class.

Detailed Description

Peary SPI Interface.

Copyright: Copyright (c) 2016-2025 CERN and the Peary Caribou authors. This software is distributed under the terms of the LGPL-3.0-only License, copied verbatim in the file “LICENSE.md”. SPDX-License-Identifier: LGPL-3.0-only

Source code

  
#pragma once

#include <cstdint>
#include <mutex>
#include <string>
#include <vector>

#include "peary/interfaces/Interface.hpp"
#include "peary/interfaces/InterfaceManager.hpp"

namespace peary::interface {

    using spi_t = uint8_t;

    template <typename REG_T = uint8_t> class iface_spi : public Interface<REG_T, spi_t> {
    public:
        using spi_reg_t = REG_T;

    protected:
        explicit iface_spi(const Interface<>::configuration_type& config);

        ~iface_spi() override;

        // Descriptor of the device
        int spiDesc;

        // Protects access to the bus
        std::mutex mutex;

        // SPI bits per word
        const uint32_t bits_per_word = 8;

        GENERATE_FRIENDS()

        
        std::pair<REG_T, spi_t> write(const std::pair<REG_T, spi_t>& data) override;

        Interface<>::dataVector_type write(const REG_T& reg, const Interface<>::dataVector_type& data) override;

        std::vector<std::pair<REG_T, spi_t>> write(const std::vector<std::pair<REG_T, spi_t>>& data) override;

        Interface<>::dataVector_type read(const REG_T& reg, const unsigned int length) override;

        friend iface_spi& InterfaceManager::getInterface<iface_spi<REG_T>>(const Interface<>::configuration_type&);

        friend void InterfaceManager::deleteInterface<iface_spi<REG_T>>(iface_spi<REG_T>*);

    public:
        iface_spi() = delete;

    }; // class iface_spi

} // namespace peary::interface

#ifdef SPI_EMULATED
#include "emulator.tcc"
#else
#include "spi.tcc"
#endif
  

Updated on 2025-11-14 at 11:31:23 +0100