Skip to content

Commit

Permalink
Update for new pac
Browse files Browse the repository at this point in the history
  • Loading branch information
usbalbin committed Dec 18, 2023
1 parent 6af2cef commit ac223dc
Show file tree
Hide file tree
Showing 21 changed files with 561 additions and 559 deletions.
2 changes: 1 addition & 1 deletion examples/flash_with_rtic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ mod app {

unsafe {
let mut flash = &(*stm32g4xx_hal::stm32::FLASH::ptr());
flash.acr.modify(|_, w| {
flash.acr().modify(|_, w| {
w.latency().bits(0b1000) // 8 wait states
});
}
Expand Down
194 changes: 97 additions & 97 deletions src/adc.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/can.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ where
{
Self::enable(&rcc.rb);

if rcc.rb.ccipr.read().fdcansel().is_hse() {
if rcc.rb.ccipr().read().fdcansel().is_hse() {
// Select P clock as FDCAN clock source
rcc.rb.ccipr.modify(|_, w| {
rcc.rb.ccipr().modify(|_, w| {
// This is sound, as `FdCanClockSource` only contains valid values for this field.
unsafe {
w.fdcansel().bits(FdCanClockSource::PCLK as u8);
Expand Down
8 changes: 4 additions & 4 deletions src/comparator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ macro_rules! impl_comp {
pub fn csr(&self) -> &$crate::stm32::comp::$reg_t {
// SAFETY: The COMP1 type is only constructed with logical ownership of
// these registers.
&unsafe { &*COMP::ptr() }.$reg
&unsafe { &*COMP::ptr() }.$reg()
}
}
)+};
Expand Down Expand Up @@ -541,11 +541,11 @@ type Comparators = (COMP1, COMP2, COMP3, COMP4, COMP5, COMP6, COMP7);
/// Enables the comparator peripheral, and splits the [`COMP`] into independent [`COMP1`] and [`COMP2`]
pub fn split(_comp: COMP, rcc: &mut Rcc) -> Comparators {
// Enable COMP, SYSCFG, VREFBUF clocks
rcc.rb.apb2enr.modify(|_, w| w.syscfgen().set_bit());
rcc.rb.apb2enr().modify(|_, w| w.syscfgen().set_bit());

// Reset COMP, SYSCFG, VREFBUF
rcc.rb.apb2rstr.modify(|_, w| w.syscfgrst().set_bit());
rcc.rb.apb2rstr.modify(|_, w| w.syscfgrst().clear_bit());
rcc.rb.apb2rstr().modify(|_, w| w.syscfgrst().set_bit());
rcc.rb.apb2rstr().modify(|_, w| w.syscfgrst().clear_bit());

(
COMP1 { _rb: PhantomData },
Expand Down
28 changes: 14 additions & 14 deletions src/dac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ macro_rules! dac_helper {
pub fn enable(self) -> $CX<MODE_BITS, Enabled> {
let dac = unsafe { &(*<$DAC>::ptr()) };

dac.dac_mcr.modify(|_, w| unsafe { w.$mode().bits(MODE_BITS) });
dac.dac_cr.modify(|_, w| w.$en().set_bit());
dac.dac_mcr().modify(|_, w| unsafe { w.$mode().bits(MODE_BITS) });
dac.dac_cr().modify(|_, w| w.$en().set_bit());

$CX {
_enabled: PhantomData,
Expand All @@ -204,8 +204,8 @@ macro_rules! dac_helper {
pub fn enable_generator(self, config: GeneratorConfig) -> $CX<MODE_BITS, WaveGenerator> {
let dac = unsafe { &(*<$DAC>::ptr()) };

dac.dac_mcr.modify(|_, w| unsafe { w.$mode().bits(MODE_BITS) });
dac.dac_cr.modify(|_, w| unsafe {
dac.dac_mcr().modify(|_, w| unsafe { w.$mode().bits(MODE_BITS) });
dac.dac_cr().modify(|_, w| unsafe {
w.$wave().bits(config.mode);
w.$ten().set_bit();
w.$mamp().bits(config.amp);
Expand Down Expand Up @@ -235,19 +235,19 @@ macro_rules! dac_helper {
T: DelayUs<u32>,
{
let dac = unsafe { &(*<$DAC>::ptr()) };
dac.dac_cr.modify(|_, w| w.$en().clear_bit());
dac.dac_mcr.modify(|_, w| unsafe { w.$mode().bits(0) });
dac.dac_cr.modify(|_, w| w.$cen().set_bit());
dac.dac_cr().modify(|_, w| w.$en().clear_bit());
dac.dac_mcr().modify(|_, w| unsafe { w.$mode().bits(0) });
dac.dac_cr().modify(|_, w| w.$cen().set_bit());
let mut trim = 0;
while true {
dac.dac_ccr.modify(|_, w| unsafe { w.$trim().bits(trim) });
dac.dac_ccr().modify(|_, w| unsafe { w.$trim().bits(trim) });
delay.delay_us(64_u32);
if dac.dac_sr.read().$cal_flag().bit() {
if dac.dac_sr().read().$cal_flag().bit() {
break;
}
trim += 1;
}
dac.dac_cr.modify(|_, w| w.$cen().clear_bit());
dac.dac_cr().modify(|_, w| w.$cen().clear_bit());

$CX {
_enabled: PhantomData,
Expand All @@ -257,7 +257,7 @@ macro_rules! dac_helper {
/// Disable the DAC channel
pub fn disable(self) -> $CX<MODE_BITS, Disabled> {
let dac = unsafe { &(*<$DAC>::ptr()) };
dac.dac_cr.modify(|_, w| unsafe {
dac.dac_cr().modify(|_, w| unsafe {
w.$en().clear_bit().$wave().bits(0).$ten().clear_bit()
});

Expand All @@ -272,20 +272,20 @@ macro_rules! dac_helper {
impl<const MODE_BITS: u8, ED> DacOut<u16> for $CX<MODE_BITS, ED> {
fn set_value(&mut self, val: u16) {
let dac = unsafe { &(*<$DAC>::ptr()) };
dac.$dhrx.write(|w| unsafe { w.bits(val as u32) });
dac.$dhrx().write(|w| unsafe { w.bits(val as u32) });
}

fn get_value(&mut self) -> u16 {
let dac = unsafe { &(*<$DAC>::ptr()) };
dac.$dac_dor.read().bits() as u16
dac.$dac_dor().read().bits() as u16
}
}

/// Wave generator state implementation
impl<const MODE_BITS: u8> $CX<MODE_BITS, WaveGenerator> {
pub fn trigger(&mut self) {
let dac = unsafe { &(*<$DAC>::ptr()) };
dac.dac_swtrgr.write(|w| { w.$swtrig().set_bit() });
dac.dac_swtrgr().write(|w| { w.$swtrig().set_bit() });
}
}
)+
Expand Down
Loading

0 comments on commit ac223dc

Please sign in to comment.