aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/lib/spi
diff options
context:
space:
mode:
authorBrent Stapleton <brent.stapleton@ettus.com>2019-01-14 10:35:25 -0800
committerBrent Stapleton <brent.stapleton@ettus.com>2019-01-16 11:40:23 -0800
commit967be2a4e82b1a125b26bb72a60318a4fb2b50c4 (patch)
tree8a24954b54d1546dc8049a17e485adb0a605f74f /mpm/lib/spi
parentaafe4e8b742a0e21d3818f21f34e3c8613132530 (diff)
downloaduhd-967be2a4e82b1a125b26bb72a60318a4fb2b50c4.tar.gz
uhd-967be2a4e82b1a125b26bb72a60318a4fb2b50c4.tar.bz2
uhd-967be2a4e82b1a125b26bb72a60318a4fb2b50c4.zip
uhd: mpm: apply clang-format to all files
Applying formatting changes to all .cpp and .hpp files in the following directories: ``` find host/examples/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/tests/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/lib/usrp/dboard/neon/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/lib/usrp/dboard/magnesium/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/lib/usrp/device3/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/lib/usrp/mpmd/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/lib/usrp/x300/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/utils/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find mpm/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file ``` Also formatted host/include/, except Cpp03 was used as a the language standard instead of Cpp11. ``` sed -i 's/ Cpp11/ Cpp03/g' .clang-format find host/include/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file ``` Formatting style was designated by the .clang-format file.
Diffstat (limited to 'mpm/lib/spi')
-rw-r--r--mpm/lib/spi/spi_regs_iface.cpp98
-rw-r--r--mpm/lib/spi/spidev_iface.cpp83
2 files changed, 57 insertions, 124 deletions
diff --git a/mpm/lib/spi/spi_regs_iface.cpp b/mpm/lib/spi/spi_regs_iface.cpp
index a1b5d29f8..842f45d42 100644
--- a/mpm/lib/spi/spi_regs_iface.cpp
+++ b/mpm/lib/spi/spi_regs_iface.cpp
@@ -4,10 +4,10 @@
// SPDX-License-Identifier: GPL-3.0-or-later
//
-#include <mpm/types/regs_iface.hpp>
+#include <mpm/exception.hpp>
#include <mpm/spi/spi_iface.hpp>
#include <mpm/spi/spi_regs_iface.hpp>
-#include <mpm/exception.hpp>
+#include <mpm/types/regs_iface.hpp>
using mpm::types::regs_iface;
@@ -18,29 +18,23 @@ using mpm::types::regs_iface;
class spi_regs_iface_impl : public regs_iface
{
public:
-
- spi_regs_iface_impl(
- mpm::spi::spi_iface::sptr spi_iface,
+ spi_regs_iface_impl(mpm::spi::spi_iface::sptr spi_iface,
uint32_t addr_shift,
uint32_t data_shift,
uint32_t read_flags,
- uint32_t write_flags = 0
- ) : _spi_iface(spi_iface),
- _addr_shift(addr_shift),
- _data_shift(data_shift),
- _read_flags(read_flags),
- _write_flags(write_flags)
+ uint32_t write_flags = 0)
+ : _spi_iface(spi_iface)
+ , _addr_shift(addr_shift)
+ , _data_shift(data_shift)
+ , _read_flags(read_flags)
+ , _write_flags(write_flags)
{
/* nop */
}
- uint8_t peek8(
- const uint32_t addr
- ) {
- uint32_t transaction = 0
- | (addr << _addr_shift)
- | _read_flags
- ;
+ uint8_t peek8(const uint32_t addr)
+ {
+ uint32_t transaction = 0 | (addr << _addr_shift) | _read_flags;
uint32_t data = _spi_iface->transfer24_8(transaction);
if ((data & 0xFFFFFF00) != 0) {
@@ -50,26 +44,17 @@ public:
return data;
}
- void poke8(
- const uint32_t addr,
- const uint8_t data
- ) {
- uint32_t transaction = 0
- | _write_flags
- | (addr << _addr_shift)
- | (data << _data_shift)
- ;
+ void poke8(const uint32_t addr, const uint8_t data)
+ {
+ uint32_t transaction = 0 | _write_flags | (addr << _addr_shift)
+ | (data << _data_shift);
_spi_iface->transfer24_8(transaction);
}
- uint16_t peek16(
- const uint32_t addr
- ) {
- uint32_t transaction = 0
- | (addr << _addr_shift)
- | _read_flags
- ;
+ uint16_t peek16(const uint32_t addr)
+ {
+ uint32_t transaction = 0 | (addr << _addr_shift) | _read_flags;
uint32_t data = _spi_iface->transfer24_16(transaction);
if ((data & 0xFFFF0000) != 0) {
@@ -79,15 +64,10 @@ public:
return data;
}
- void poke16(
- const uint32_t addr,
- const uint16_t data
- ) {
- uint32_t transaction = 0
- | _write_flags
- | (addr << _addr_shift)
- | (data << _data_shift)
- ;
+ void poke16(const uint32_t addr, const uint16_t data)
+ {
+ uint32_t transaction = 0 | _write_flags | (addr << _addr_shift)
+ | (data << _data_shift);
_spi_iface->transfer24_16(transaction);
}
@@ -101,39 +81,25 @@ private:
uint32_t _write_flags;
};
-regs_iface::sptr mpm::spi::make_spi_regs_iface(
- mpm::spi::spi_iface::sptr spi_iface,
+regs_iface::sptr mpm::spi::make_spi_regs_iface(mpm::spi::spi_iface::sptr spi_iface,
uint32_t addr_shift,
uint32_t data_shift,
uint32_t read_flags,
- uint32_t write_flags
-) {
+ uint32_t write_flags)
+{
return std::make_shared<spi_regs_iface_impl>(
- spi_iface,
- addr_shift,
- data_shift,
- read_flags,
- write_flags
- );
+ spi_iface, addr_shift, data_shift, read_flags, write_flags);
}
-mpm::types::regs_iface::sptr mpm::spi::make_spidev_regs_iface(
- const std::string &device,
+mpm::types::regs_iface::sptr mpm::spi::make_spidev_regs_iface(const std::string& device,
const int speed_hz,
const int spi_mode,
uint32_t addr_shift,
uint32_t data_shift,
uint32_t read_flags,
- uint32_t write_flags
-) {
- auto spi_iface_sptr = mpm::spi::spi_iface::make_spidev(
- device, speed_hz, spi_mode
- );
+ uint32_t write_flags)
+{
+ auto spi_iface_sptr = mpm::spi::spi_iface::make_spidev(device, speed_hz, spi_mode);
return std::make_shared<spi_regs_iface_impl>(
- spi_iface_sptr,
- addr_shift,
- data_shift,
- read_flags,
- write_flags
- );
+ spi_iface_sptr, addr_shift, data_shift, read_flags, write_flags);
}
diff --git a/mpm/lib/spi/spidev_iface.cpp b/mpm/lib/spi/spidev_iface.cpp
index 8b629e7b6..c8a2133e8 100644
--- a/mpm/lib/spi/spidev_iface.cpp
+++ b/mpm/lib/spi/spidev_iface.cpp
@@ -5,14 +5,13 @@
//
-#include <mpm/spi/spi_iface.hpp>
#include <mpm/exception.hpp>
+#include <mpm/spi/spi_iface.hpp>
extern "C" {
#include "spidev.h"
}
#include <fcntl.h>
#include <linux/spi/spidev.h>
-
#include <boost/format.hpp>
#include <iostream>
@@ -24,29 +23,18 @@ using namespace mpm::spi;
class spidev_iface_impl : public spi_iface
{
public:
-
spidev_iface_impl(
- const std::string &device,
- const int max_speed_hz,
- const int spi_mode
- ) : _speed(max_speed_hz),
- _mode(spi_mode)
+ const std::string& device, const int max_speed_hz, const int spi_mode)
+ : _speed(max_speed_hz), _mode(spi_mode)
{
- if (init_spi(
- &_fd,
- device.c_str(),
- _mode, _speed, _bits, _delay) < 0)
- {
- throw mpm::runtime_error(str(
- boost::format("Could not initialize spidev device %s")
- % device));
+ if (init_spi(&_fd, device.c_str(), _mode, _speed, _bits, _delay) < 0) {
+ throw mpm::runtime_error(
+ str(boost::format("Could not initialize spidev device %s") % device));
}
- if (_fd < 0)
- {
- throw mpm::runtime_error(str(
- boost::format("Could not open spidev device %s")
- % device));
+ if (_fd < 0) {
+ throw mpm::runtime_error(
+ str(boost::format("Could not open spidev device %s") % device));
}
}
@@ -55,53 +43,37 @@ public:
close(_fd);
}
- uint32_t transfer24_8(
- const uint32_t data_
- ) {
+ uint32_t transfer24_8(const uint32_t data_)
+ {
int ret(0);
- uint32_t data = data_;
- uint8_t *tx_data = reinterpret_cast<uint8_t *>(&data);
+ uint32_t data = data_;
+ uint8_t* tx_data = reinterpret_cast<uint8_t*>(&data);
// Create tx and rx buffers:
uint8_t tx[] = {tx_data[2], tx_data[1], tx_data[0]}; // FIXME guarantee endianness
uint8_t rx[3]; // Buffer length must match tx buffer
- if (transfer(
- _fd,
- &tx[0], &rx[0],
- 3,
- _speed, _bits, _delay
- ) != 0) {
- throw mpm::runtime_error(str(
- boost::format("SPI Transaction failed!")
- ));
+ if (transfer(_fd, &tx[0], &rx[0], 3, _speed, _bits, _delay) != 0) {
+ throw mpm::runtime_error(str(boost::format("SPI Transaction failed!")));
}
return uint32_t(rx[2]);
}
- uint32_t transfer24_16(
- const uint32_t data_
- ) {
+ uint32_t transfer24_16(const uint32_t data_)
+ {
int ret(0);
- uint32_t data = data_;
- uint8_t *tx_data = reinterpret_cast<uint8_t *>(&data);
+ uint32_t data = data_;
+ uint8_t* tx_data = reinterpret_cast<uint8_t*>(&data);
// Create tx and rx buffers:
uint8_t tx[] = {tx_data[2], tx_data[1], tx_data[0]}; // FIXME guarantee endianness
uint8_t rx[3]; // Buffer length must match tx buffer
- if (transfer(
- _fd,
- &tx[0], &rx[0],
- 3,
- _speed, _bits, _delay
- ) != 0) {
- throw mpm::runtime_error(str(
- boost::format("SPI Transaction failed!")
- ));
+ if (transfer(_fd, &tx[0], &rx[0], 3, _speed, _bits, _delay) != 0) {
+ throw mpm::runtime_error(str(boost::format("SPI Transaction failed!")));
}
return uint32_t(rx[1] << 8 | rx[2]);
@@ -111,7 +83,7 @@ private:
int _fd;
const uint32_t _mode;
uint32_t _speed = 2000000;
- uint8_t _bits = 8;
+ uint8_t _bits = 8;
uint16_t _delay = 0;
};
@@ -119,12 +91,7 @@ private:
* Factory
*****************************************************************************/
spi_iface::sptr spi_iface::make_spidev(
- const std::string &device,
- const int speed_hz,
- const int spi_mode
-) {
- return std::make_shared<spidev_iface_impl>(
- device, speed_hz, spi_mode
- );
+ const std::string& device, const int speed_hz, const int spi_mode)
+{
+ return std::make_shared<spidev_iface_impl>(device, speed_hz, spi_mode);
}
-