Skip to content

Commit

Permalink
Merge pull request #235 from jeancf/change_spi_bus_freq
Browse files Browse the repository at this point in the history
Add method to change SPI bus frequency
  • Loading branch information
bjoernQ authored Oct 28, 2022
2 parents 3e4710b + a7d561e commit 79e1465
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions esp-hal-common/src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ where
spi
}

pub fn change_bus_frequency(&mut self, frequency: HertzU32, clocks: &Clocks) {
self.spi.ch_bus_freq(frequency, clocks);
}

/// Return the raw interface to the underlying peripheral instance
pub fn free(self) -> T {
self.spi
Expand Down Expand Up @@ -1331,6 +1335,34 @@ pub trait Instance {
self
}

fn ch_bus_freq(&mut self, frequency: HertzU32, clocks: &Clocks) {

// Disable clock source
#[cfg(not(any(feature = "esp32", feature = "esp32s2")))]
self.register_block().clk_gate.modify(|_, w| {
w.clk_en()
.clear_bit()
.mst_clk_active()
.clear_bit()
.mst_clk_sel()
.clear_bit()
});

// Change clock frequency
self.setup(frequency, clocks);

// Enable clock source
#[cfg(not(any(feature = "esp32", feature = "esp32s2")))]
self.register_block().clk_gate.modify(|_, w| {
w.clk_en()
.set_bit()
.mst_clk_active()
.set_bit()
.mst_clk_sel()
.set_bit()
});
}

fn read_byte(&mut self) -> nb::Result<u8, Error> {
let reg_block = self.register_block();

Expand Down

0 comments on commit 79e1465

Please sign in to comment.