Line data Source code
1 : /**
2 : * @file i2c.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/I2CMasterNode.hpp"
10 : #include "timing/I2CSlave.hpp"
11 : #include "timing/SIChipSlave.hpp"
12 : // #include "timing/MiniPODMasterNode.hpp"
13 : #include "timing/DACNode.hpp"
14 : #include "timing/I2CExpanderNode.hpp"
15 : #include "timing/SI534xNode.hpp"
16 : #include "timing/LTC2945Node.hpp"
17 : #include "timing/I2C9546SwitchNode.hpp"
18 :
19 : #include <pybind11/pybind11.h>
20 : #include <pybind11/stl.h>
21 :
22 : #include <vector>
23 :
24 : namespace py = pybind11;
25 :
26 : namespace dunedaq {
27 : namespace timing {
28 : namespace python {
29 :
30 : void
31 0 : register_i2c(py::module& m)
32 : {
33 : // .def("hardReset", (void ( mp7::CtrlNode::*) (double)) 0, mp7_CTRLNODE_hardReset_overloads())
34 :
35 : // Wrap timing::I2CMasterNode
36 0 : py::class_<timing::I2CMasterNode, uhal::Node>(m, "I2CMasterNode")
37 0 : .def(py::init<const uhal::Node&>())
38 0 : .def("get_i2c_clock_prescale", &timing::I2CMasterNode::get_i2c_clock_prescale)
39 0 : .def("read_i2c",
40 0 : &timing::I2CMasterNode::read_i2c,
41 0 : py::arg("i2c_device_address"),
42 0 : py::arg("i2c_reg_address"),
43 0 : py::arg("atomic") = false
44 : )
45 0 : .def("write_i2c",
46 0 : &timing::I2CMasterNode::write_i2c,
47 0 : py::arg("i2c_device_address"),
48 0 : py::arg("i2c_reg_address"),
49 0 : py::arg("data"),
50 0 : py::arg("send_stop") = true)
51 0 : .def("read_i2cArray",
52 0 : &timing::I2CMasterNode::read_i2cArray,
53 0 : py::arg("i2c_device_address"),
54 0 : py::arg("i2c_reg_address"),
55 0 : py::arg("number_of_words"),
56 0 : py::arg("atomic") = false
57 : )
58 0 : .def("write_i2cArray",
59 0 : &timing::I2CMasterNode::write_i2cArray,
60 0 : py::arg("i2c_device_address"),
61 0 : py::arg("i2c_reg_address"),
62 0 : py::arg("data"),
63 0 : py::arg("send_stop") = true)
64 0 : .def("read_i2cPrimitive", &timing::I2CMasterNode::read_i2cPrimitive)
65 0 : .def("write_i2cPrimitive",
66 0 : &timing::I2CMasterNode::write_i2cPrimitive,
67 0 : py::arg("i2c_device_address"),
68 0 : py::arg("data"),
69 0 : py::arg("send_stop") = true)
70 0 : .def("get_slaves", &timing::I2CMasterNode::get_slaves)
71 0 : .def("get_slave", &timing::I2CMasterNode::get_slave, py::return_value_policy::reference_internal)
72 0 : .def("get_slave_address", &timing::I2CMasterNode::get_slave_address)
73 0 : .def("ping", &timing::I2CMasterNode::ping)
74 0 : .def("scan", &timing::I2CMasterNode::scan)
75 0 : .def("reset", &timing::I2CMasterNode::reset);
76 :
77 : // Wrap timing::I2CSlave
78 0 : py::class_<timing::I2CSlave>(m, "I2CSlave")
79 0 : .def("get_i2c_address", &timing::I2CSlave::get_i2c_address)
80 0 : .def<uint8_t (timing::I2CSlave::*)(uint32_t) const>("read_i2c", // NOLINT(build/unsigned)
81 : &timing::I2CSlave::read_i2c)
82 0 : .def<uint8_t (timing::I2CSlave::*)(uint32_t, uint32_t) const>("read_i2c", // NOLINT(build/unsigned)
83 : &timing::I2CSlave::read_i2c)
84 0 : .def<uint8_t (timing::I2CSlave::*)(uint32_t) const>("read_i2c_atomic", // NOLINT(build/unsigned)
85 : &timing::I2CSlave::read_i2c_atomic)
86 0 : .def<uint8_t (timing::I2CSlave::*)(uint32_t, uint32_t) const>("read_i2c_atomic", // NOLINT(build/unsigned)
87 : &timing::I2CSlave::read_i2c_atomic)
88 0 : .def<void (timing::I2CSlave::*)(uint32_t, uint8_t, bool) const>("write_i2c", // NOLINT(build/unsigned)
89 : &timing::I2CSlave::write_i2c,
90 0 : py::arg("i2c_reg_address"),
91 0 : py::arg("data"),
92 0 : py::arg("send_stop") = true)
93 0 : .def<void (timing::I2CSlave::*)(uint32_t, uint32_t, uint8_t, bool) const>("write_i2c", // NOLINT(build/unsigned)
94 : &timing::I2CSlave::write_i2c,
95 0 : py::arg("i2c_device_address"),
96 0 : py::arg("i2c_reg_address"),
97 0 : py::arg("data"),
98 0 : py::arg("send_stop") = true)
99 0 : .def<std::vector<uint8_t> (timing::I2CSlave::*)(uint32_t, uint32_t) const>( // NOLINT(build/unsigned)
100 : "read_i2cArray",
101 : &timing::I2CSlave::read_i2cArray)
102 0 : .def<std::vector<uint8_t> (timing::I2CSlave::*)(uint32_t, uint32_t, uint32_t) const>( // NOLINT(build/unsigned)
103 : "read_i2cArray",
104 : &timing::I2CSlave::read_i2cArray)
105 0 : .def<std::vector<uint8_t> (timing::I2CSlave::*)(uint32_t, uint32_t) const>( // NOLINT(build/unsigned)
106 : "read_i2cArray_atomic",
107 : &timing::I2CSlave::read_i2cArray_atomic)
108 0 : .def<std::vector<uint8_t> (timing::I2CSlave::*)(uint32_t, uint32_t, uint32_t) const>( // NOLINT(build/unsigned)
109 : "read_i2cArray_atomic",
110 : &timing::I2CSlave::read_i2cArray_atomic)
111 0 : .def<void (timing::I2CSlave::*)(uint32_t, std::vector<uint8_t>, bool) const>( // NOLINT(build/unsigned)
112 : "write_i2cArray",
113 : &timing::I2CSlave::write_i2cArray,
114 0 : py::arg("i2c_reg_address"),
115 0 : py::arg("data"),
116 0 : py::arg("send_stop") = true)
117 0 : .def<void (timing::I2CSlave::*)(uint32_t, uint32_t, std::vector<uint8_t>, bool) const>( // NOLINT(build/unsigned)
118 : "write_i2cArray",
119 : &timing::I2CSlave::write_i2cArray,
120 0 : py::arg("i2c_device_address"),
121 0 : py::arg("i2c_reg_address"),
122 0 : py::arg("data"),
123 0 : py::arg("send_stop") = true)
124 0 : .def("read_i2cPrimitive", &timing::I2CSlave::read_i2cPrimitive)
125 0 : .def("write_i2cPrimitive", &timing::I2CSlave::write_i2cPrimitive, py::arg("data"), py::arg("send_stop") = true)
126 0 : .def("ping", &timing::I2CSlave::ping);
127 :
128 : // Wrap SIChipSlave
129 0 : py::class_<timing::SIChipSlave, timing::I2CSlave>(m, "SIChipSlave")
130 0 : .def(py::init<const timing::I2CMasterNode*, uint8_t>()) // NOLINT(build/unsigned)
131 0 : .def("read_page", &timing::SIChipSlave::read_page)
132 0 : .def("switch_page", &timing::SIChipSlave::switch_page)
133 0 : .def("read_device_version", &timing::SIChipSlave::read_device_version)
134 0 : .def("read_clock_register", &timing::SIChipSlave::read_clock_register)
135 0 : .def("write_clock_register", &timing::SIChipSlave::write_clock_register);
136 :
137 : // Wrap SI534xSlave
138 0 : py::class_<timing::SI534xSlave, timing::SIChipSlave>(m, "SI534xSlave")
139 0 : .def(py::init<const timing::I2CMasterNode*, uint8_t>()) // NOLINT(build/unsigned)
140 0 : .def("configure", &timing::SI534xSlave::configure)
141 0 : .def("read_config_id", &timing::SI534xSlave::read_config_id)
142 0 : .def("get_status", &timing::SI534xSlave::get_status, py::arg("print_out"))
143 : // .def("registers", &timing::SI534xSlave::registers)
144 : ;
145 :
146 : // Wrap SI534xNode
147 0 : py::class_<timing::SI534xNode, timing::SI534xSlave, timing::I2CMasterNode>(m, "SI534xNode")
148 0 : .def(py::init<const uhal::Node&>());
149 :
150 : // Wrap I2CExpanderSlave
151 0 : py::class_<timing::I2CExpanderSlave, timing::I2CSlave>(m, "I2CExpanderSlave")
152 0 : .def(py::init<const timing::I2CMasterNode*, uint8_t>()) // NOLINT(build/unsigned)
153 0 : .def("set_io", &timing::I2CExpanderSlave::set_io)
154 0 : .def("set_inversion", &timing::I2CExpanderSlave::set_inversion)
155 0 : .def("set_outputs", &timing::I2CExpanderSlave::set_outputs)
156 0 : .def("read_inputs", &timing::I2CExpanderSlave::read_inputs)
157 0 : .def("read_outputs_config", &timing::I2CExpanderSlave::read_outputs_config)
158 0 : .def("debug", &timing::I2CExpanderSlave::debug);
159 :
160 : // // Wrap I2CExpanderNode
161 : // py::class_<timing::I2CExpanderNode, timing::I2CExpanderSlave, timing::I2CMasterNode>(m, "I2CExpanderNode")
162 : // .def(py::init<const uhal::Node&>());
163 :
164 : // Wrap DACSlave
165 0 : py::class_<timing::DACSlave, timing::I2CSlave>(m, "DACSlave")
166 0 : .def(py::init<const timing::I2CMasterNode*, uint8_t>()) // NOLINT(build/unsigned)
167 0 : .def("set_interal_ref", &timing::DACSlave::set_interal_ref)
168 0 : .def("set_dac", &timing::DACSlave::set_dac);
169 :
170 : // Wrap DACNode
171 0 : py::class_<timing::DACNode, timing::DACSlave, timing::I2CMasterNode>(m, "DACNode").def(py::init<const uhal::Node&>());
172 : // NOLINT(readability/fn_size)
173 :
174 0 : py::class_<timing::LTC2945Node, timing::I2CSlave>(m, "LTC2945Node")
175 0 : .def(py::init<const timing::I2CMasterNode*, uint8_t, double>()) // NOLINT(build/unsigned)
176 0 : .def("read_v_in", &timing::LTC2945Node::read_v_in)
177 0 : .def("read_delta_sense_v", &timing::LTC2945Node::read_delta_sense_v)
178 0 : .def("read_power", &timing::LTC2945Node::read_power)
179 : ;
180 :
181 : // Wrap I2C9546SwitchNode
182 0 : py::class_<timing::I2C9546SwitchSlave, timing::I2CSlave>(m, "I2C9546SwitchSlave")
183 0 : .def(py::init<const timing::I2CMasterNode*, uint8_t>()) // NOLINT(build/unsigned)
184 0 : .def("enable_channel", &timing::I2C9546SwitchSlave::enable_channel)
185 0 : .def("disable_channel", &timing::I2C9546SwitchSlave::disable_channel)
186 0 : .def("read_channels_states", &timing::I2C9546SwitchSlave::read_channels_states)
187 0 : .def("set_channels_states", &timing::I2C9546SwitchSlave::set_channels_states);
188 0 : }
189 :
190 : } // namespace python
191 : } // namespace timing
192 : } // namespace dunedaq
|