Line data Source code
1 : /**
2 : * @file I2CExpanderNode.cpp
3 : *
4 : * This is part of the DUNE DAQ Software Suite, copyright 2020.
5 : * Licensing/copyright details are in the COPYING file that you should have
6 : * received with this code.
7 : */
8 :
9 : #include "timing/I2C9546SwitchNode.hpp"
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 :
19 : namespace dunedaq {
20 : namespace timing {
21 :
22 : //-----------------------------------------------------------------------------
23 0 : I2C9546SwitchSlave::I2C9546SwitchSlave(const I2CMasterNode* i2c_master, uint8_t address) // NOLINT(build/unsigned)
24 0 : : I2CSlave(i2c_master, address)
25 0 : {}
26 : //-----------------------------------------------------------------------------
27 :
28 : //-----------------------------------------------------------------------------
29 0 : I2C9546SwitchSlave::~I2C9546SwitchSlave() {}
30 : //-----------------------------------------------------------------------------
31 :
32 : //-----------------------------------------------------------------------------
33 : void
34 0 : I2C9546SwitchSlave::ensure_valid_channel(uint8_t channel) const // NOLINT(build/unsigned)
35 : {
36 0 : if (channel < 4)
37 0 : return;
38 :
39 0 : throw I2C9546SwitchSlaveChannelError(ERS_HERE, std::to_string(channel));
40 : }
41 : //-----------------------------------------------------------------------------
42 :
43 :
44 : //-----------------------------------------------------------------------------
45 : void
46 0 : I2C9546SwitchSlave::enable_channel(uint8_t channel) const // NOLINT(build/unsigned)
47 : {
48 0 : this->ensure_valid_channel(channel);
49 0 : std::vector<uint8_t> enable_byte = this->read_i2cPrimitive(1); // NOLINT(build/unsigned)
50 0 : uint8_t new_enable_byte = enable_byte.at(0) | (1UL << channel); // NOLINT(build/unsigned)
51 0 : this->write_i2cPrimitive({new_enable_byte});
52 0 : }
53 : //-----------------------------------------------------------------------------
54 :
55 : //-----------------------------------------------------------------------------
56 : void
57 0 : I2C9546SwitchSlave::disable_channel(uint8_t channel) const // NOLINT(build/unsigned)
58 : {
59 0 : this->ensure_valid_channel(channel);
60 0 : std::vector<uint8_t> enable_byte = this->read_i2cPrimitive(1); // NOLINT(build/unsigned)
61 0 : uint8_t new_enable_byte = enable_byte.at(0) & ~(1UL << channel); // NOLINT(build/unsigned)
62 0 : this->write_i2cPrimitive({new_enable_byte});
63 0 : }
64 : //-----------------------------------------------------------------------------
65 :
66 : //-----------------------------------------------------------------------------
67 : uint8_t // NOLINT(build/unsigned)
68 0 : I2C9546SwitchSlave::read_channels_states() const
69 : {
70 0 : std::vector<uint8_t> enable_byte = this->read_i2cPrimitive(1); // NOLINT(build/unsigned)
71 0 : return enable_byte.at(0);
72 0 : }
73 : //-----------------------------------------------------------------------------
74 :
75 : //-----------------------------------------------------------------------------
76 : void // NOLINT(build/unsigned)
77 0 : I2C9546SwitchSlave::set_channels_states(uint8_t channels) const // NOLINT(build/unsigned)
78 : {
79 0 : this->write_i2cPrimitive({channels});
80 0 : }
81 : //-----------------------------------------------------------------------------
82 :
83 : } // namespace timing
84 : } // namespace dunedaq
|