Rust newbie question.
I'm working on a board using the stm32h7xx hal and need to solve a particularly hairy problem.
The board comprises of several components that are controlled via an SPI peripheral. However, there is also another device that needs to be driven by a GPIO connected to the MOSI line of the SPI peripheral.
I've done the basic skeleton of the driver in question. The sections marked TODO are the bits I'm struggling with.
use cortex_m::prelude::_embedded_hal_blocking_spi_Write;
use stm32h7xx_hal::{spi::Enabled, gpio::{Output, Pin, PushPull}, pac::SPI3, spi::Spi};
pub struct ShiftRegSelector {
up_ciod_sh_reg_sel0: Pin<'D', 10, Output<PushPull>>,
up_ciod_sh_reg_sel1: Pin<'D', 11, Output<PushPull>>,
up_ciod_sh_reg_n_latch: Pin<'E', 10, Output<PushPull>>,
up_ciod_sh_reg_n_rst: Pin<'E', 15, Output<PushPull>>,
spi: Spi<SPI3, Enabled>,
}
impl ShiftRegSelector {
pub fn new(
up_ciod_sh_reg_sel0: Pin<'D', 10, Output<PushPull>>,
up_ciod_sh_reg_sel1: Pin<'D', 11, Output<PushPull>>,
up_ciod_sh_reg_n_latch: Pin<'E', 10, Output<PushPull>>,
up_ciod_sh_reg_n_rst: Pin<'E', 15, Output<PushPull>>,
spi: Spi<SPI3, Enabled>,
) -> Self {
Self {
up_ciod_sh_reg_sel0,
up_ciod_sh_reg_sel1,
up_ciod_sh_reg_n_latch,
up_ciod_sh_reg_n_rst,
spi,
}
}
pub fn psu_13v8_ctrl(&mut self, _enable: bool) {
// TODO: Reconfigure spi.mosi as GPIO output
self.reset_mux();
if _enable {
// TODO: Drive GPIO line high"
} else {
// TODO: Drive GPIO line low
}
self.latch_mux();
self.reset_mux();
// TODO: Restore SPI configuration
}
fn latch_mux(&mut self) {
self.up_ciod_sh_reg_sel0.set_high();
self.up_ciod_sh_reg_sel1.set_high();
self.up_ciod_sh_reg_n_latch.set_low();
}
fn reset_mux(&mut self) {
self.up_ciod_sh_reg_n_rst.set_high();
self.up_ciod_sh_reg_n_latch.set_high();
}
pub fn something(&mut self) {
self.spi.write(&[0x11u8, 0x22, 0x33]).unwrap();
}
}
How should the IO/peripheral reconfigration be done in psu_13v8_ctrl
?