From ac1e451aa1365d8aa1608861b28a2b3b8576fdf3 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 23 Feb 2026 18:52:23 +0800 Subject: [PATCH] add routines for setting/updating i2c clocks in anticipation for frequency scaling support --- libs/bao1x-hal/src/udma/i2c.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libs/bao1x-hal/src/udma/i2c.rs b/libs/bao1x-hal/src/udma/i2c.rs index 4092adcd4..8ab0fa830 100644 --- a/libs/bao1x-hal/src/udma/i2c.rs +++ b/libs/bao1x-hal/src/udma/i2c.rs @@ -75,7 +75,10 @@ pub struct I2cDriver<'a> { #[allow(dead_code)] // used in bao1x channel: I2cChannel, divider: u16, + // cached value of perclk perclk_freq: u32, + // cached value of our clock setting + i2c_freq: u32, pub ifram: IframRange, tx_buf: &'static mut [u8], tx_buf_phys: &'static mut [u8], @@ -197,6 +200,7 @@ impl<'a> I2cDriver<'a> { seq_len: 0, pending: I2cPending::Idle, perclk_freq, + i2c_freq, }; i2c.send_cmd_list(&[I2cCmd::Config(divider)]); i2c @@ -205,6 +209,12 @@ impl<'a> I2cDriver<'a> { pub fn set_freq(&mut self, freq_hz: u32) { // divide-by-4 is an empirical observation self.divider = ((self.perclk_freq / (freq_hz * 4)).min(u16::MAX as u32)) as u16; + self.i2c_freq = freq_hz; + } + + pub fn update_perclk(&mut self, perclk_freq: u32) { + self.perclk_freq = perclk_freq; + self.set_freq(self.i2c_freq); } // always blocks