DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
I2C9546SwitchNode.cpp
Go to the documentation of this file.
1
10
11// PDT headers
12#include "ers/ers.hpp"
13#include "timing/toolbox.hpp"
14
15#include <vector>
16// #include <fstream>
17// #include <sstream>
18
19namespace dunedaq {
20namespace timing {
21
22//-----------------------------------------------------------------------------
23I2C9546SwitchSlave::I2C9546SwitchSlave(const I2CMasterNode* i2c_master, uint8_t address) // NOLINT(build/unsigned)
24 : I2CSlave(i2c_master, address)
25{}
26//-----------------------------------------------------------------------------
27
28//-----------------------------------------------------------------------------
29I2C9546SwitchSlave::~I2C9546SwitchSlave() {}
30//-----------------------------------------------------------------------------
31
32//-----------------------------------------------------------------------------
33void
34I2C9546SwitchSlave::ensure_valid_channel(uint8_t channel) const // NOLINT(build/unsigned)
35{
36 if (channel < 4)
37 return;
38
39 throw I2C9546SwitchSlaveChannelError(ERS_HERE, std::to_string(channel));
40}
41//-----------------------------------------------------------------------------
42
43
44//-----------------------------------------------------------------------------
45void
46I2C9546SwitchSlave::enable_channel(uint8_t channel) const // NOLINT(build/unsigned)
47{
48 this->ensure_valid_channel(channel);
49 std::vector<uint8_t> enable_byte = this->read_i2cPrimitive(1); // NOLINT(build/unsigned)
50 uint8_t new_enable_byte = enable_byte.at(0) | (1UL << channel); // NOLINT(build/unsigned)
51 this->write_i2cPrimitive({new_enable_byte});
52}
53//-----------------------------------------------------------------------------
54
55//-----------------------------------------------------------------------------
56void
57I2C9546SwitchSlave::disable_channel(uint8_t channel) const // NOLINT(build/unsigned)
58{
59 this->ensure_valid_channel(channel);
60 std::vector<uint8_t> enable_byte = this->read_i2cPrimitive(1); // NOLINT(build/unsigned)
61 uint8_t new_enable_byte = enable_byte.at(0) & ~(1UL << channel); // NOLINT(build/unsigned)
62 this->write_i2cPrimitive({new_enable_byte});
63}
64//-----------------------------------------------------------------------------
65
66//-----------------------------------------------------------------------------
67uint8_t // NOLINT(build/unsigned)
68I2C9546SwitchSlave::read_channels_states() const
69{
70 std::vector<uint8_t> enable_byte = this->read_i2cPrimitive(1); // NOLINT(build/unsigned)
71 return enable_byte.at(0);
72}
73//-----------------------------------------------------------------------------
74
75//-----------------------------------------------------------------------------
76void // NOLINT(build/unsigned)
77I2C9546SwitchSlave::set_channels_states(uint8_t channels) const // NOLINT(build/unsigned)
78{
79 this->write_i2cPrimitive({channels});
80}
81//-----------------------------------------------------------------------------
82
83} // namespace timing
84} // namespace dunedaq
#define ERS_HERE
OpenCode I2C interface to a ipbus node.
Class to provide OpenCode I2C interface to a ipbus node.
Including Qt Headers.