Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use fugit::Rate types instead of custom #401

Merged
merged 2 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ nb = "1"
stm32f1 = "0.14.0"
embedded-dma = "0.1.2"
bxcan = "0.6"
cast = { default-features = false, version = "0.3.0" }
void = { default-features = false, version = "1.0.2" }
embedded-hal = { features = ["unproven"], version = "0.2.6" }
fugit = "0.3.0"
fugit = "0.3.5"
rtic-monotonic = { version = "1.0", optional = true }

[dependencies.stm32-usbd]
Expand Down
2 changes: 1 addition & 1 deletion examples/adc-dma-circ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn main() -> ! {
// clock is configurable. So its frequency may be tweaked to meet certain
// practical needs. User specified value is be approximated using supported
// prescaler values 2/4/6/8.
let clocks = rcc.cfgr.adcclk(2.mhz()).freeze(&mut flash.acr);
let clocks = rcc.cfgr.adcclk(2.MHz()).freeze(&mut flash.acr);

let dma_ch1 = p.DMA1.split().1;

Expand Down
2 changes: 1 addition & 1 deletion examples/adc-dma-rx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn main() -> ! {
// clock is configurable. So its frequency may be tweaked to meet certain
// practical needs. User specified value is be approximated using supported
// prescaler values 2/4/6/8.
let clocks = rcc.cfgr.adcclk(2.mhz()).freeze(&mut flash.acr);
let clocks = rcc.cfgr.adcclk(2.MHz()).freeze(&mut flash.acr);

let dma_ch1 = p.DMA1.split().1;

Expand Down
4 changes: 2 additions & 2 deletions examples/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ fn main() -> ! {
// clock is configurable. So its frequency may be tweaked to meet certain
// practical needs. User specified value is be approximated using supported
// prescaler values 2/4/6/8.
let clocks = rcc.cfgr.adcclk(2.mhz()).freeze(&mut flash.acr);
hprintln!("adc freq: {}", clocks.adcclk().0).unwrap();
let clocks = rcc.cfgr.adcclk(2.MHz()).freeze(&mut flash.acr);
hprintln!("adc freq: {}", clocks.adcclk()).unwrap();

// Setup ADC
let mut adc1 = adc::Adc::adc1(p.ADC1, clocks);
Expand Down
12 changes: 6 additions & 6 deletions examples/adc_temperature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ fn main() -> ! {

let clocks = rcc
.cfgr
.use_hse(8.mhz())
.sysclk(56.mhz())
.pclk1(28.mhz())
.adcclk(14.mhz())
.use_hse(8.MHz())
.sysclk(56.MHz())
.pclk1(28.MHz())
.adcclk(14.MHz())
.freeze(&mut flash.acr);
/*
// Alternative configuration using dividers and multipliers directly
Expand All @@ -34,8 +34,8 @@ fn main() -> ! {
usbpre: rcc::UsbPre::DIV1_5,
adcpre: rcc::AdcPre::DIV2,
}, &mut flash.acr);*/
hprintln!("sysclk freq: {}", clocks.sysclk().0).unwrap();
hprintln!("adc freq: {}", clocks.adcclk().0).unwrap();
hprintln!("sysclk freq: {}", clocks.sysclk()).unwrap();
hprintln!("adc freq: {}", clocks.adcclk()).unwrap();

// Setup ADC
let mut adc = adc::Adc::adc1(p.ADC1, clocks);
Expand Down
2 changes: 1 addition & 1 deletion examples/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn main() -> ! {
// in order to configure the port. For pins 0-7, crl should be passed instead.
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
// Configure the syst timer to trigger an update every second
let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(1.hz());
let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(1.Hz());

// Wait for the timer to trigger an update and change the state of the LED
loop {
Expand Down
2 changes: 1 addition & 1 deletion examples/blinky_generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() -> ! {
let mut gpioc = dp.GPIOC.split();

// Configure the syst timer to trigger an update every second
let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(1.hz());
let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(1.Hz());

// Create an array of LEDS to blink
let mut leds = [
Expand Down
6 changes: 3 additions & 3 deletions examples/blinky_timer_irq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ fn main() -> ! {
let mut flash = dp.FLASH.constrain();
let clocks = rcc
.cfgr
.sysclk(8.mhz())
.pclk1(8.mhz())
.sysclk(8.MHz())
.pclk1(8.MHz())
.freeze(&mut flash.acr);

// Configure PC13 pin to blink LED
Expand All @@ -86,7 +86,7 @@ fn main() -> ! {
cortex_m::interrupt::free(|cs| *G_LED.borrow(cs).borrow_mut() = Some(led));

// Set up a timer expiring after 1s
let mut timer = Timer::new(dp.TIM2, &clocks).start_count_down(1.hz());
let mut timer = Timer::new(dp.TIM2, &clocks).start_count_down(1.Hz());

// Generate an interrupt when the timer expires
timer.listen(Event::Update);
Expand Down
2 changes: 1 addition & 1 deletion examples/can-echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() -> ! {
// To meet CAN clock accuracy requirements an external crystal or ceramic
// resonator must be used. The blue pill has a 8MHz external crystal.
// Other boards might have a crystal with another frequency or none at all.
rcc.cfgr.use_hse(8.mhz()).freeze(&mut flash.acr);
rcc.cfgr.use_hse(8.MHz()).freeze(&mut flash.acr);

let mut afio = dp.AFIO.constrain();

Expand Down
2 changes: 1 addition & 1 deletion examples/can-loopback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn main() -> ! {

// To meet CAN clock accuracy requirements, an external crystal or ceramic
// resonator must be used.
rcc.cfgr.use_hse(8.mhz()).freeze(&mut flash.acr);
rcc.cfgr.use_hse(8.MHz()).freeze(&mut flash.acr);

#[cfg(not(feature = "connectivity"))]
let can = Can::new(dp.CAN1, dp.USB);
Expand Down
10 changes: 5 additions & 5 deletions examples/can-rtic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ mod app {

let _clocks = rcc
.cfgr
.use_hse(8.mhz())
.sysclk(64.mhz())
.hclk(64.mhz())
.pclk1(16.mhz())
.pclk2(64.mhz())
.use_hse(8.MHz())
.sysclk(64.MHz())
.hclk(64.MHz())
.pclk1(16.MHz())
.pclk2(64.MHz())
.freeze(&mut flash.acr);

#[cfg(not(feature = "connectivity"))]
Expand Down
2 changes: 1 addition & 1 deletion examples/dynamic_gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn main() -> ! {

let mut pin = gpioc.pc13.into_dynamic(&mut gpioc.crh);
// Configure the syst timer to trigger an update every second
let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(1.hz());
let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(1.Hz());

// Wait for the timer to trigger an update and change the state of the LED
loop {
Expand Down
2 changes: 1 addition & 1 deletion examples/enc28j60-coap.rs.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn main() -> ! {
(sck, miso, mosi),
&mut afio.mapr,
enc28j60::MODE,
1.mhz(),
1.MHz(),
clocks,
);

Expand Down
2 changes: 1 addition & 1 deletion examples/enc28j60.rs.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn main() -> ! {
(sck, miso, mosi),
&mut afio.mapr,
enc28j60::MODE,
1.mhz(),
1.MHz(),
clocks,
);

Expand Down
10 changes: 5 additions & 5 deletions examples/i2c-bme280/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ fn main() -> ! {
// Freeze the configuration of all the clocks in the system and store the frozen frequencies in
// `clocks`
let clocks = if 1 == 1 {
rcc.cfgr.use_hse(8.mhz()).freeze(&mut flash.acr)
rcc.cfgr.use_hse(8.MHz()).freeze(&mut flash.acr)
} else {
// My blue pill with a stm32f103 clone dose not seem to respect rcc so will not compensate its pulse legths
// with a faster clock like this. And so the sensor dose not have time to respond to the START pulse.
// I would be interested if others with real stm32f103's can use this program with the faster clocks.
rcc.cfgr
.use_hse(8.mhz())
.sysclk(48.mhz())
.pclk1(6.mhz())
.use_hse(8.MHz())
.sysclk(48.MHz())
.pclk1(6.MHz())
.freeze(&mut flash.acr)
};

Expand All @@ -68,7 +68,7 @@ fn main() -> ! {
(scl, sda),
&mut afio.mapr,
Mode::Fast {
frequency: 400_000.hz(),
frequency: 400.kHz(),
duty_cycle: DutyCycle::Ratio16to9,
},
clocks,
Expand Down
2 changes: 1 addition & 1 deletion examples/mfrc522.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn main() -> ! {
(sck, miso, mosi),
&mut afio.mapr,
mfrc522::MODE,
1.mhz(),
1.MHz(),
clocks,
);

Expand Down
2 changes: 1 addition & 1 deletion examples/motor.rs.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn main() -> ! {
let pwm = p.TIM2.pwm(
gpioa.pa0.into_alternate_push_pull(&mut gpioa.crl),
&mut afio.mapr,
1.khz(),
1.kHz(),
clocks,
);

Expand Down
2 changes: 1 addition & 1 deletion examples/mpu9250.rs.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn main() -> ! {
(sck, miso, mosi),
&mut afio.mapr,
mpu9250::MODE,
1.mhz(),
1.MHz(),
clocks,
);

Expand Down
2 changes: 1 addition & 1 deletion examples/multi_mode_gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn main() -> ! {

let mut pin = gpioc.pc13.into_floating_input(&mut gpioc.crh);
// Configure the syst timer to trigger an update every second
let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(1.hz());
let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(1.Hz());

// Wait for the timer to trigger an update and change the state of the LED
loop {
Expand Down
8 changes: 4 additions & 4 deletions examples/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use stm32f1xx_hal::{
pac,
prelude::*,
pwm::Channel,
time::U32Ext,
time::ms,
timer::{Tim2NoRemap, Timer},
};

Expand Down Expand Up @@ -52,7 +52,7 @@ fn main() -> ! {
// let c4 = gpiob.pb9.into_alternate_push_pull(&mut gpiob.crh);

let mut pwm =
Timer::new(p.TIM2, &clocks).pwm::<Tim2NoRemap, _, _, _>(pins, &mut afio.mapr, 1.khz());
Timer::new(p.TIM2, &clocks).pwm::<Tim2NoRemap, _, _>(pins, &mut afio.mapr, 1.kHz());

// Enable clock on each of the channels
pwm.enable(Channel::C1);
Expand All @@ -62,12 +62,12 @@ fn main() -> ! {
//// Operations affecting all defined channels on the Timer

// Adjust period to 0.5 seconds
pwm.set_period(500.ms());
pwm.set_period(ms(500).into_rate());

asm::bkpt();

// Return to the original frequency
pwm.set_period(1.khz());
pwm.set_period(1.kHz());

asm::bkpt();

Expand Down
2 changes: 1 addition & 1 deletion examples/pwm_custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn main() -> ! {
let p0 = pb4.into_alternate_push_pull(&mut gpiob.crl);
let p1 = gpiob.pb5.into_alternate_push_pull(&mut gpiob.crl);

let pwm = Timer::new(p.TIM3, &clocks).pwm((p0, p1), &mut afio.mapr, 1.khz());
let pwm = Timer::new(p.TIM3, &clocks).pwm((p0, p1), &mut afio.mapr, 1.kHz());

let max = pwm.get_max_duty();

Expand Down
2 changes: 1 addition & 1 deletion examples/pwm_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn main() -> ! {
(pb4, pb5),
&mut afio.mapr,
&mut dbg,
Configuration::Frequency(10.khz()),
Configuration::Frequency(10.kHz()),
);

loop {
Expand Down
2 changes: 1 addition & 1 deletion examples/spi-dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn main() -> ! {
polarity: Polarity::IdleLow,
phase: Phase::CaptureOnFirstTransition,
};
let spi = Spi::spi2(dp.SPI2, pins, spi_mode, 100.khz(), clocks);
let spi = Spi::spi2(dp.SPI2, pins, spi_mode, 100.kHz(), clocks);

// Set up the DMA device
let dma = dp.DMA1.split();
Expand Down
2 changes: 1 addition & 1 deletion examples/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn setup() -> (
(sck, miso, mosi),
&mut afio.mapr,
MODE,
1_u32.mhz(),
1.MHz(),
clocks,
);

Expand Down
6 changes: 3 additions & 3 deletions examples/timer-interrupt-rtic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mod app {
.pc13
.into_push_pull_output_with_state(&mut gpioc.crh, PinState::High);
// Configure the syst timer to trigger an update every second and enables interrupt
let mut timer = Timer::new(cx.device.TIM1, &clocks).start_count_down(1.hz());
let mut timer = Timer::new(cx.device.TIM1, &clocks).start_count_down(1.Hz());
timer.listen(Event::Update);

// Init the static resources to use them later through RTIC
Expand Down Expand Up @@ -93,9 +93,9 @@ mod app {

if *cx.local.count == 4 {
// Changes timer update frequency
cx.local.timer_handler.start(2.hz());
cx.local.timer_handler.start(2.Hz());
} else if *cx.local.count == 12 {
cx.local.timer_handler.start(1.hz());
cx.local.timer_handler.start(1.Hz());
*cx.local.count = 0;
}

Expand Down
8 changes: 4 additions & 4 deletions examples/usb_serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ fn main() -> ! {

let clocks = rcc
.cfgr
.use_hse(8.mhz())
.sysclk(48.mhz())
.pclk1(24.mhz())
.use_hse(8.MHz())
.sysclk(48.MHz())
.pclk1(24.MHz())
.freeze(&mut flash.acr);

assert!(clocks.usbclk_valid());
Expand All @@ -47,7 +47,7 @@ fn main() -> ! {
// will not reset your device when you upload new firmware.
let mut usb_dp = gpioa.pa12.into_push_pull_output(&mut gpioa.crh);
usb_dp.set_low();
delay(clocks.sysclk().0 / 100);
delay(clocks.sysclk().raw() / 100);

let usb = Peripheral {
usb: dp.USB,
Expand Down
8 changes: 4 additions & 4 deletions examples/usb_serial_interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ fn main() -> ! {

let clocks = rcc
.cfgr
.use_hse(8.mhz())
.sysclk(48.mhz())
.pclk1(24.mhz())
.use_hse(8.MHz())
.sysclk(48.MHz())
.pclk1(24.MHz())
.freeze(&mut flash.acr);

assert!(clocks.usbclk_valid());
Expand All @@ -41,7 +41,7 @@ fn main() -> ! {
// will not reset your device when you upload new firmware.
let mut usb_dp = gpioa.pa12.into_push_pull_output(&mut gpioa.crh);
usb_dp.set_low();
delay(clocks.sysclk().0 / 100);
delay(clocks.sysclk().raw() / 100);

let usb_dm = gpioa.pa11;
let usb_dp = usb_dp.into_floating_input(&mut gpioa.crh);
Expand Down
8 changes: 4 additions & 4 deletions examples/usb_serial_rtic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ mod app {

let clocks = rcc
.cfgr
.use_hse(8.mhz())
.sysclk(48.mhz())
.pclk1(24.mhz())
.use_hse(8.MHz())
.sysclk(48.MHz())
.pclk1(24.MHz())
.freeze(&mut flash.acr);

assert!(clocks.usbclk_valid());
Expand All @@ -46,7 +46,7 @@ mod app {
// will not reset your device when you upload new firmware.
let mut usb_dp = gpioa.pa12.into_push_pull_output(&mut gpioa.crh);
usb_dp.set_low();
delay(clocks.sysclk().0 / 100);
delay(clocks.sysclk().raw() / 100);

let usb_dm = gpioa.pa11;
let usb_dp = usb_dp.into_floating_input(&mut gpioa.crh);
Expand Down
Loading