Loading...
Searching...
No Matches
serial.hpp
Go to the documentation of this file.
//
// Copyright 2010-2013 Ettus Research LLC
// Copyright 2018 Ettus Research, a National Instruments Company
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
#pragma once
#include <uhd/config.hpp>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
namespace uhd {
typedef std::vector<uint8_t> byte_vector_t;
class UHD_API i2c_iface
{
public:
typedef std::shared_ptr<i2c_iface> sptr;
virtual ~i2c_iface(void);
i2c_iface::sptr eeprom16(void);
virtual void write_i2c(uint16_t addr, const byte_vector_t& buf) = 0;
virtual byte_vector_t read_i2c(uint16_t addr, size_t num_bytes) = 0;
virtual void write_eeprom(uint16_t addr, uint16_t offset, const byte_vector_t& buf);
virtual byte_vector_t read_eeprom(uint16_t addr, uint16_t offset, size_t num_bytes);
};
struct UHD_API spi_config_t
{
enum edge_t { EDGE_RISE = 'r', EDGE_FALL = 'f' };
edge_t mosi_edge;
edge_t miso_edge;
bool use_custom_divider;
size_t divider;
spi_config_t(edge_t edge = EDGE_RISE);
spi_config_t(edge_t edge, size_t divider);
};
class UHD_API spi_iface
{
public:
typedef std::shared_ptr<spi_iface> sptr;
virtual ~spi_iface(void);
virtual uint32_t transact_spi(int which_slave,
const spi_config_t& config,
uint32_t data,
size_t num_bits,
bool readback) = 0;
virtual uint32_t read_spi(
int which_slave, const spi_config_t& config, uint32_t data, size_t num_bits);
virtual void write_spi(
int which_slave, const spi_config_t& config, uint32_t data, size_t num_bits);
};
class UHD_API uart_iface
{
public:
typedef std::shared_ptr<uart_iface> sptr;
virtual ~uart_iface(void);
virtual void write_uart(const std::string& buf) = 0;
virtual std::string read_uart(double timeout) = 0;
};
} // namespace uhd
uhd::i2c_iface
Definition serial.hpp:37
uhd::i2c_iface::read_i2c
virtual byte_vector_t read_i2c(uint16_t addr, size_t num_bytes)=0
uhd::i2c_iface::read_eeprom
virtual byte_vector_t read_eeprom(uint16_t addr, uint16_t offset, size_t num_bytes)
uhd::i2c_iface::~i2c_iface
virtual ~i2c_iface(void)
uhd::i2c_iface::write_i2c
virtual void write_i2c(uint16_t addr, const byte_vector_t &buf)=0
uhd::i2c_iface::eeprom16
i2c_iface::sptr eeprom16(void)
Create an i2c_iface than can talk to 16 bit addressable EEPROMS.
uhd::i2c_iface::sptr
std::shared_ptr< i2c_iface > sptr
Definition serial.hpp:39
uhd::i2c_iface::write_eeprom
virtual void write_eeprom(uint16_t addr, uint16_t offset, const byte_vector_t &buf)
uhd::spi_iface
Definition serial.hpp:123
uhd::spi_iface::sptr
std::shared_ptr< spi_iface > sptr
Definition serial.hpp:125
uhd::spi_iface::~spi_iface
virtual ~spi_iface(void)
uhd::spi_iface::transact_spi
virtual uint32_t transact_spi(int which_slave, const spi_config_t &config, uint32_t data, size_t num_bits, bool readback)=0
uhd::spi_iface::read_spi
virtual uint32_t read_spi(int which_slave, const spi_config_t &config, uint32_t data, size_t num_bits)
uhd::spi_iface::write_spi
virtual void write_spi(int which_slave, const spi_config_t &config, uint32_t data, size_t num_bits)
uhd::uart_iface
Definition serial.hpp:170
uhd::uart_iface::write_uart
virtual void write_uart(const std::string &buf)=0
uhd::uart_iface::~uart_iface
virtual ~uart_iface(void)
uhd::uart_iface::read_uart
virtual std::string read_uart(double timeout)=0
uhd::uart_iface::sptr
std::shared_ptr< uart_iface > sptr
Definition serial.hpp:172
UHD_API
#define UHD_API
Definition config.h:87
config.hpp
uhd
Definition build_info.hpp:12
uhd::byte_vector_t
std::vector< uint8_t > byte_vector_t
Byte vector used for I2C data passing and EEPROM parsing.
Definition byte_vector.hpp:21
uhd::spi_config_t
Definition serial.hpp:84
uhd::spi_config_t::miso_edge
edge_t miso_edge
on what edge is the miso data valid?
Definition serial.hpp:95
uhd::spi_config_t::spi_config_t
spi_config_t(edge_t edge=EDGE_RISE)
uhd::spi_config_t::edge_t
edge_t
Definition serial.hpp:89
uhd::spi_config_t::EDGE_RISE
@ EDGE_RISE
Definition serial.hpp:89
uhd::spi_config_t::EDGE_FALL
@ EDGE_FALL
Definition serial.hpp:89
uhd::spi_config_t::use_custom_divider
bool use_custom_divider
Set the clock speed for this transaction.
Definition serial.hpp:98
uhd::spi_config_t::mosi_edge
edge_t mosi_edge
on what edge is the mosi data valid?
Definition serial.hpp:92
uhd::spi_config_t::spi_config_t
spi_config_t(edge_t edge, size_t divider)
uhd::spi_config_t::divider
size_t divider
Optionally set the SPI clock divider for this transaction.
Definition serial.hpp:101