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/I2CExpanderNode.hpp"
10 :
11 : // PDT headers
12 : #include "ers/ers.hpp"
13 : #include "timing/toolbox.hpp"
14 :
15 : // #include <boost/tuple/tuple.hpp>
16 :
17 : #include <vector>
18 : // #include <fstream>
19 : // #include <sstream>
20 :
21 : namespace dunedaq {
22 : namespace timing {
23 :
24 : //-----------------------------------------------------------------------------
25 0 : I2CExpanderSlave::I2CExpanderSlave(const I2CMasterNode* i2c_master, uint8_t address) // NOLINT(build/unsigned)
26 0 : : I2CSlave(i2c_master, address)
27 0 : {}
28 : //-----------------------------------------------------------------------------
29 :
30 : //-----------------------------------------------------------------------------
31 0 : I2CExpanderSlave::~I2CExpanderSlave() {}
32 : //-----------------------------------------------------------------------------
33 :
34 : //-----------------------------------------------------------------------------
35 : void
36 0 : I2CExpanderSlave::ensure_valid_bank_id(uint8_t bank_id) const // NOLINT(build/unsigned)
37 : {
38 0 : if (bank_id == 0 || bank_id == 1)
39 0 : return;
40 :
41 0 : throw SFPExpanderBankIDError(ERS_HERE, std::to_string(bank_id));
42 : }
43 : //-----------------------------------------------------------------------------
44 :
45 : //-----------------------------------------------------------------------------
46 : void
47 0 : I2CExpanderSlave::set_inversion(uint8_t bank_id, uint32_t inversion_mask) const // NOLINT(build/unsigned)
48 : {
49 :
50 0 : this->ensure_valid_bank_id(bank_id);
51 0 : this->write_i2c(0x4 + bank_id, inversion_mask);
52 0 : }
53 : //-----------------------------------------------------------------------------
54 :
55 : //-----------------------------------------------------------------------------
56 : void
57 0 : I2CExpanderSlave::set_io(uint8_t bank_id, uint32_t io_mask) const // NOLINT(build/unsigned)
58 : {
59 :
60 0 : this->ensure_valid_bank_id(bank_id);
61 0 : this->write_i2c(0x6 + bank_id, io_mask);
62 0 : }
63 : //-----------------------------------------------------------------------------
64 :
65 : //-----------------------------------------------------------------------------
66 : void
67 0 : I2CExpanderSlave::set_outputs(uint8_t bank_id, uint32_t output_values) const // NOLINT(build/unsigned)
68 : {
69 :
70 0 : this->ensure_valid_bank_id(bank_id);
71 0 : this->write_i2c(0x2 + bank_id, output_values);
72 0 : }
73 : //-----------------------------------------------------------------------------
74 :
75 : //-----------------------------------------------------------------------------
76 : uint32_t // NOLINT(build/unsigned)
77 0 : I2CExpanderSlave::read_inputs(uint8_t bank_id) const // NOLINT(build/unsigned)
78 : {
79 :
80 0 : this->ensure_valid_bank_id(bank_id);
81 0 : return this->read_i2c(0x0 + bank_id);
82 : }
83 : //-----------------------------------------------------------------------------
84 :
85 : //-----------------------------------------------------------------------------
86 : uint8_t // NOLINT(build/unsigned)
87 0 : I2CExpanderSlave::read_outputs_config(uint8_t bank_id) const { // NOLINT(build/unsigned)
88 :
89 0 : this->ensure_valid_bank_id(bank_id);
90 0 : return this->read_i2c(0x2 + bank_id);
91 :
92 : }
93 : //-----------------------------------------------------------------------------
94 :
95 : //-----------------------------------------------------------------------------
96 : std::vector<uint32_t> // NOLINT(build/unsigned)
97 0 : I2CExpanderSlave::debug() const
98 : {
99 :
100 0 : std::vector<uint32_t> values(8); // NOLINT(build/unsigned)
101 :
102 0 : for (size_t a(0); a < 8; ++a) {
103 0 : values[a] = this->read_i2c(a);
104 : }
105 0 : return values;
106 0 : }
107 : //-----------------------------------------------------------------------------
108 :
109 : } // namespace timing
110 : } // namespace dunedaq
|