1use crate::pwm::PwmChip;
2
3impl PwmChip {
4    pub fn dump_registers(&self, mut callback: impl FnMut(&str, &[(&str, &str)])) {
5        callback(
6            "$4030 / $A15130",
7            &[
8                ("L channel output", &self.control.l_out.to_string()),
9                ("R channel output", &self.control.r_out.to_string()),
10                ("DREQ 1 enabled", bool_str(self.control.dreq1_enabled)),
11                ("Timer interval", &self.control.effective_timer_interval().to_string()),
12            ],
13        );
14
15        let sample_rate = 53_693_175.0 * 3.0
16            / 7.0
17            / f64::from(self.cycle_register.wrapping_sub(1) & ((1 << 12) - 1));
18        callback(
19            "$4032 / $A15132",
20            &[
21                ("Cycle register", &self.cycle_register.to_string()),
22                ("Sample rate", &format!("{:.0} Hz", sample_rate.round())),
23            ],
24        );
25    }
26}
27
28fn bool_str(b: bool) -> &'static str {
29    if b { "true" } else { "false" }
30}