Update dependencies to latest versions

master
Levi Pearson 2022-02-28 20:51:41 -07:00
parent 5adbfdb8f5
commit 07882f56ed
4 changed files with 59 additions and 90 deletions

View File

@ -4,32 +4,20 @@ version = "0.1.0"
authors = ["Levi Pearson <levipearson@gmail.com>"] authors = ["Levi Pearson <levipearson@gmail.com>"]
description = "Crate for STM32F103 Blue Pill boards with peripherals" description = "Crate for STM32F103 Blue Pill boards with peripherals"
categories = ["embedded", "no-std"] categories = ["embedded", "no-std"]
edition = "2018" edition = "2021"
[dependencies] [dependencies]
cortex-m = "0.6.2" cortex-m = "0.7.4"
cortex-m-rt = "0.6.12" cortex-m-rt = "0.7.1"
embedded-hal = "0.2.3" embedded-hal = "0.2.3"
nb = "1.0.0" stm32f1xx-hal = { version = "0.8.0", features = ["rt", "stm32f103", "medium"] }
rtt-target = { version = "0.3.1", features = ["cortex-m"] }
panic-rtt-target = { version = "0.1.0", features = ["cortex-m"] } panic-rtt-target = { version = "0.1.0", features = ["cortex-m"] }
rtt-target = { version = "0.2.0", features = ["cortex-m"] } switch-hal = "0.4.0"
ssd1306 = "0.3.1" arrayvec = { version = "0.7.2", default-features = false }
switch-hal = "0.3.2" ssd1306 = "0.7.0"
embedded-graphics = "0.7.1"
[dependencies.arrayvec] either = { version = "1.5.3", default-features = false }
version = "0.5.1"
default-features = false
[dependencies.embedded-graphics]
version = "0.6.1"
[dependencies.stm32f1xx-hal]
version = "0.6.1"
features = ["rt", "stm32f103", "medium"]
[dependencies.either]
default-features = false
version = "1.5.3"
[[bin]] [[bin]]
name = "blue_pill_more" name = "blue_pill_more"

View File

@ -8,7 +8,7 @@
# The protocol to be used for communicating with the target. # The protocol to be used for communicating with the target.
protocol = "Swd" protocol = "Swd"
# The speed in kHz of the data link to the target. # The speed in kHz of the data link to the target.
# speed = 1337 # speed = 133
[default.flashing] [default.flashing]
# Whether or not the target should be flashed. # Whether or not the target should be flashed.

View File

@ -1,55 +1,38 @@
#![no_std] #![no_std]
#![cfg_attr(not(doc), no_main)] #![cfg_attr(not(doc), no_main)]
use core::{ use core::{cell::RefCell, fmt::Write};
cell::RefCell,
fmt::Write,
};
use rtt_target::{rprintln, rtt_init_print};
use panic_rtt_target as _; use panic_rtt_target as _;
use rtt_target::{rprintln, rtt_init_print};
use cortex_m_rt::entry; use cortex_m_rt::entry;
use cortex_m::{ use cortex_m::interrupt::Mutex;
interrupt::Mutex,
};
use stm32f1xx_hal::{ use stm32f1xx_hal::{
afio, afio,
device::{EXTI, NVIC},
delay::Delay, delay::Delay,
i2c::{BlockingI2c, DutyCycle, Mode}, device::{EXTI, NVIC},
gpio::{ gpio::{
Input,
Floating,
ExtiPin,
Edge,
gpioa::{PA8, PA9}, gpioa::{PA8, PA9},
Edge, ExtiPin, Floating, Input,
}, },
pac::{ i2c::{BlockingI2c, DutyCycle, Mode},
CorePeripherals, pac::{interrupt, CorePeripherals, Interrupt, Peripherals},
Peripherals,
Interrupt,
interrupt,
},
prelude::*, prelude::*,
}; };
use switch_hal::{IntoSwitch, InputSwitch, OutputSwitch, ToggleableOutputSwitch}; use switch_hal::{InputSwitch, IntoSwitch, OutputSwitch, ToggleableOutputSwitch};
use ssd1306::{ use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306};
prelude::*,
Builder,
};
use embedded_graphics::{ use embedded_graphics::{
fonts::{Font6x8, Text}, mono_font::{ascii::FONT_6X9, MonoTextStyleBuilder},
pixelcolor::BinaryColor, pixelcolor::BinaryColor,
prelude::*, prelude::*,
primitives::Circle, primitives::{Circle, PrimitiveStyle},
style::{PrimitiveStyle, TextStyle}, text::{Baseline, Text},
}; };
use arrayvec::ArrayString; use arrayvec::ArrayString;
@ -57,11 +40,11 @@ use arrayvec::ArrayString;
mod rotary; mod rotary;
use rotary::{Direction, Rotary}; use rotary::{Direction, Rotary};
type CLKPIN = PA8<Input<Floating>>; type ClkPin = PA8<Input<Floating>>;
type DTPIN = PA9<Input<Floating>>; type DtPin = PA9<Input<Floating>>;
static CLK_PIN: Mutex<RefCell<Option<CLKPIN>>> = Mutex::new(RefCell::new(None)); static CLK_PIN: Mutex<RefCell<Option<ClkPin>>> = Mutex::new(RefCell::new(None));
static DT_PIN: Mutex<RefCell<Option<DTPIN>>> = Mutex::new(RefCell::new(None)); static DT_PIN: Mutex<RefCell<Option<DtPin>>> = Mutex::new(RefCell::new(None));
static COUNT: Mutex<RefCell<i32>> = Mutex::new(RefCell::new(0)); static COUNT: Mutex<RefCell<i32>> = Mutex::new(RefCell::new(0));
#[entry] #[entry]
@ -77,9 +60,9 @@ fn main() -> ! {
// RCC is the primary clock control peripheral, but FLASH is also involved in setting // RCC is the primary clock control peripheral, but FLASH is also involved in setting
// up clock speed because the wait states must be increased at higher clock rates // up clock speed because the wait states must be increased at higher clock rates
let mut rcc = dev_periph.RCC.constrain(); let rcc = dev_periph.RCC.constrain();
let mut flash = dev_periph.FLASH.constrain(); let mut flash = dev_periph.FLASH.constrain();
let mut afio = dev_periph.AFIO.constrain(&mut rcc.apb2); let mut afio = dev_periph.AFIO.constrain();
// Peripherals often need to know the clock settings to be properly configured, so // Peripherals often need to know the clock settings to be properly configured, so
// we configure the clock and "freeze" the configuration so we can pass it // we configure the clock and "freeze" the configuration so we can pass it
@ -98,16 +81,15 @@ fn main() -> ! {
let mut delay = Delay::new(core_periph.SYST, clocks); let mut delay = Delay::new(core_periph.SYST, clocks);
// Acquire the necessary gpio peripherals // Acquire the necessary gpio peripherals
let mut gpioa = dev_periph.GPIOA.split(&mut rcc.apb2); let mut gpioa = dev_periph.GPIOA.split();
let mut gpiob = dev_periph.GPIOB.split(&mut rcc.apb2); let mut gpiob = dev_periph.GPIOB.split();
let mut gpioc = dev_periph.GPIOC.split(&mut rcc.apb2); let mut gpioc = dev_periph.GPIOC.split();
// Configure the rotary encoder pins A8, A9 and switch pin A10 // Configure the rotary encoder pins A8, A9 and switch pin A10
let clk = gpioa.pa8 let clk = gpioa.pa8.into_floating_input(&mut gpioa.crh);
.into_floating_input(&mut gpioa.crh); let dt = gpioa.pa9.into_floating_input(&mut gpioa.crh);
let dt = gpioa.pa9 let sw = gpioa
.into_floating_input(&mut gpioa.crh); .pa10
let sw = gpioa.pa10
.into_floating_input(&mut gpioa.crh) .into_floating_input(&mut gpioa.crh)
.into_active_low_switch(); .into_active_low_switch();
@ -115,7 +97,8 @@ fn main() -> ! {
init_encoder_pins(clk, dt, &mut afio, &dev_periph.EXTI); init_encoder_pins(clk, dt, &mut afio, &dev_periph.EXTI);
// Configure pin C13 to drive the "PC13" LED as an active-low switch // Configure pin C13 to drive the "PC13" LED as an active-low switch
let mut led = gpioc.pc13 let mut led = gpioc
.pc13
.into_push_pull_output(&mut gpioc.crh) .into_push_pull_output(&mut gpioc.crh)
.into_active_low_switch(); .into_active_low_switch();
@ -136,7 +119,6 @@ fn main() -> ! {
duty_cycle: DutyCycle::Ratio2to1, duty_cycle: DutyCycle::Ratio2to1,
}, },
clocks, clocks,
&mut rcc.apb1,
1000, 1000,
10, 10,
1000, 1000,
@ -144,10 +126,9 @@ fn main() -> ! {
); );
// Initialize the display // Initialize the display
let mut display: GraphicsMode<_> = Builder::new() let interface = I2CDisplayInterface::new(i2c);
.with_i2c_addr(0x3c) let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0)
.connect_i2c(i2c) .into_buffered_graphics_mode();
.into();
display.init().unwrap(); display.init().unwrap();
// Every set of commands to the display is buffered until we flush it // Every set of commands to the display is buffered until we flush it
@ -169,8 +150,11 @@ fn main() -> ! {
let mut cx = 20; let mut cx = 20;
let mut cy = 20; let mut cy = 20;
let t = Text::new("Hello Rust!", Point::new(20, 16)) let text_style = MonoTextStyleBuilder::new()
.into_styled(TextStyle::new(Font6x8, BinaryColor::On)); .font(&FONT_6X9)
.text_color(BinaryColor::On)
.build();
let t = Text::with_baseline("Hello Rust!", Point::new(20, 16), text_style, Baseline::Top);
// Turn the LED on via the OutputPin trait // Turn the LED on via the OutputPin trait
led.on().unwrap(); led.on().unwrap();
@ -192,10 +176,9 @@ fn main() -> ! {
.into_styled(PrimitiveStyle::with_fill(BinaryColor::On)); .into_styled(PrimitiveStyle::with_fill(BinaryColor::On));
// Show the position of the knob and thus the ball // Show the position of the knob and thus the ball
let mut textbuf = ArrayString::<[u8; 15]>::new(); let mut textbuf = ArrayString::<15>::new();
write!(&mut textbuf, "count: {}", counter).unwrap(); write!(&mut textbuf, "count: {}", counter).unwrap();
let count = Text::new(&textbuf, Point::new(20, 36)) let count = Text::with_baseline(&textbuf, Point::new(20, 36), text_style, Baseline::Top);
.into_styled(TextStyle::new(Font6x8, BinaryColor::On));
display.clear(); display.clear();
c.draw(&mut display).unwrap(); c.draw(&mut display).unwrap();
@ -207,8 +190,9 @@ fn main() -> ! {
cx = counter.max(C_RADIUS / 2).min(DISPLAY_W - C_RADIUS / 2); cx = counter.max(C_RADIUS / 2).min(DISPLAY_W - C_RADIUS / 2);
// Wrap the ball back to the top when it falls off the bottom // Wrap the ball back to the top when it falls off the bottom
cy += 1; cy += 1;
if cy > (DISPLAY_H + C_RADIUS) { cy = -C_RADIUS }; if cy > (DISPLAY_H + C_RADIUS) {
cy = -C_RADIUS
};
} }
} }
@ -220,7 +204,7 @@ fn init_encoder_pins(
) { ) {
cortex_m::interrupt::free(|cs| { cortex_m::interrupt::free(|cs| {
clk.make_interrupt_source(afio); clk.make_interrupt_source(afio);
clk.trigger_on_edge(exti, Edge::RISING_FALLING); clk.trigger_on_edge(exti, Edge::RisingFalling);
clk.enable_interrupt(exti); clk.enable_interrupt(exti);
CLK_PIN.borrow(cs).replace(Some(clk)); CLK_PIN.borrow(cs).replace(Some(clk));
@ -230,7 +214,7 @@ fn init_encoder_pins(
#[interrupt] #[interrupt]
fn EXTI9_5() { fn EXTI9_5() {
static mut ENC: Option<Rotary<CLKPIN, DTPIN>> = None; static mut ENC: Option<Rotary<ClkPin, DtPin>> = None;
let enc = ENC.get_or_insert_with(|| { let enc = ENC.get_or_insert_with(|| {
cortex_m::interrupt::free(|cs| { cortex_m::interrupt::free(|cs| {
@ -243,9 +227,7 @@ fn EXTI9_5() {
if enc.pin_a.check_interrupt() { if enc.pin_a.check_interrupt() {
match enc.update().unwrap() { match enc.update().unwrap() {
Direction::Clockwise => cortex_m::interrupt::free(|cs| { Direction::Clockwise => cortex_m::interrupt::free(|cs| {
COUNT COUNT.borrow(cs).replace_with(|count| count.wrapping_add(1));
.borrow(cs)
.replace_with(|count| count.wrapping_add(1));
}), }),
Direction::CounterClockwise => cortex_m::interrupt::free(|cs| { Direction::CounterClockwise => cortex_m::interrupt::free(|cs| {
COUNT COUNT

View File

@ -1,5 +1,5 @@
use embedded_hal as hal;
use either::Either; use either::Either;
use embedded_hal as hal;
use hal::digital::v2::InputPin; use hal::digital::v2::InputPin;
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Debug, Eq, PartialEq)]
@ -56,4 +56,3 @@ where
Ok(dir) Ok(dir)
} }
} }