1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! Driver for the XY7025 programmable buck converter (and protocol-compatible
//! siblings via `Model::Custom`).
//!
//! These modules share a common Modbus-RTU register layout — see the
//! crate's `README.md` for the full protocol reference.
//!
//! ```no_run
//! # use xy_modbus::{ModbusTransport, RtuError};
//! # struct MyTransport;
//! # impl ModbusTransport for MyTransport {
//! # fn read_holding(&mut self, _: u8, _: u16, _: &mut [u16]) -> Result<(), RtuError> { unimplemented!() }
//! # fn write_single_holding(&mut self, _: u8, _: u16, _: u16) -> Result<(), RtuError> { unimplemented!() }
//! # fn write_multiple_holdings(&mut self, _: u8, _: u16, _: &[u16]) -> Result<(), RtuError> { unimplemented!() }
//! # }
//! # fn main() -> Result<(), RtuError> {
//! # let my_transport = MyTransport;
//! use xy_modbus::{Model, Xy, SafetyLimits};
//!
//! let mut xy = Xy::new(my_transport, Model::Xy7025);
//! xy.set_protection(SafetyLimits { lvp_v: 22.0, ovp_v: 15.0, ocp_a: 15.0 })?;
//! xy.set_voltage(13.5)?;
//! xy.set_current_limit(10.0)?;
//! xy.set_output(true)?;
//!
//! let s = xy.read_status()?;
//! println!("{:.2} V @ {:.2} A", s.v_out, s.i_out);
//! # Ok(())
//! # }
//! ```
//!
//! The crate is `no_std`. With the default `embedded-io` feature, the
//! [`uart`] module provides a ready-to-use [`ModbusTransport`] over any
//! `embedded-io` UART. To use a different transport, disable default
//! features and implement [`ModbusTransport`] yourself; the [`framing`]
//! module exposes the on-wire codec.
//!
//! For `esp-idf-hal` users, the `esp-idf-hal` feature ships a convenience
//! constructor so you don't need to write a UART wrapper:
//!
//! ```ignore
//! use xy_modbus::{Model, Xy};
//!
//! let mut xy = Xy::from_esp_uart(uart, Model::Xy7025);
//! xy.set_voltage(13.5)?;
//! ```
// ─── Modules ─────────────────────────────────────────────────────────────────
pub
// `esp-idf-hal` itself is target-conditional (only present when targeting
// `target_os = "espidf"`), so this module is too — enabling the feature on
// host builds is harmless.
// ─── Re-exports ──────────────────────────────────────────────────────────────
pub use Xy;
pub use FrameError;
pub use ;
pub use ;
pub use UartTransport;