| USRP Hardware Driver and Device Manual Version: 4.10.0.0 UHD and USRP Manual |

Loading...
Searching...
No Matches
serial.hpp
Go to the documentation of this file.
1//
2// Copyright 2010-2013 Ettus Research LLC
3// Copyright 2018 Ettus Research, a National Instruments Company
4//
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
7
8#pragma once
9
10#include <uhd/config.hpp>
11#include <cstddef>
12#include <cstdint>
13#include <memory>
14#include <string>
15#include <vector>
16
17 namespace uhd {
18
22 typedef std::vector<uint8_t> byte_vector_t;
23
36 class UHD_API i2c_iface
37{
38 public:
39 typedef std::shared_ptr<i2c_iface> sptr;
40
41 virtual ~i2c_iface(void);
42
44 i2c_iface::sptr eeprom16(void);
45
51 virtual void write_i2c(uint16_t addr, const byte_vector_t& buf) = 0;
52
59 virtual byte_vector_t read_i2c(uint16_t addr, size_t num_bytes) = 0;
60
67 virtual void write_eeprom(uint16_t addr, uint16_t offset, const byte_vector_t& buf);
68
76 virtual byte_vector_t read_eeprom(uint16_t addr, uint16_t offset, size_t num_bytes);
77};
78
83 struct UHD_API spi_config_t
84{
89 enum edge_t : uint32_t { EDGE_RISE = 'r', EDGE_FALL = 'f' };
90
92 edge_t mosi_edge;
93
95 edge_t miso_edge;
96
98 bool use_custom_divider;
99
101 size_t divider;
102
107 spi_config_t(edge_t edge = EDGE_RISE);
108
114 spi_config_t(edge_t edge, size_t divider);
115};
116
122 class UHD_API spi_iface
123{
124 public:
125 typedef std::shared_ptr<spi_iface> sptr;
126
127 virtual ~spi_iface(void);
128
138 virtual uint32_t transact_spi(int which_slave,
139 const spi_config_t& config,
140 uint32_t data,
141 size_t num_bits,
142 bool readback) = 0;
143
152 virtual uint32_t read_spi(
153 int which_slave, const spi_config_t& config, uint32_t data, size_t num_bits);
154
162 virtual void write_spi(
163 int which_slave, const spi_config_t& config, uint32_t data, size_t num_bits);
164};
165
169 class UHD_API uart_iface
170{
171 public:
172 typedef std::shared_ptr<uart_iface> sptr;
173
174 virtual ~uart_iface(void);
175
180 virtual void write_uart(const std::string& buf) = 0;
181
187 virtual std::string read_uart(double timeout) = 0;
188};
189
190} // 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::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::spi_config_t
spi_config_t(edge_t edge=EDGE_RISE)
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