Update dependencies to latest versions
parent
5adbfdb8f5
commit
07882f56ed
32
Cargo.toml
32
Cargo.toml
|
@ -4,32 +4,20 @@ version = "0.1.0"
|
|||
authors = ["Levi Pearson <levipearson@gmail.com>"]
|
||||
description = "Crate for STM32F103 Blue Pill boards with peripherals"
|
||||
categories = ["embedded", "no-std"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
cortex-m = "0.6.2"
|
||||
cortex-m-rt = "0.6.12"
|
||||
cortex-m = "0.7.4"
|
||||
cortex-m-rt = "0.7.1"
|
||||
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"] }
|
||||
rtt-target = { version = "0.2.0", features = ["cortex-m"] }
|
||||
ssd1306 = "0.3.1"
|
||||
switch-hal = "0.3.2"
|
||||
|
||||
[dependencies.arrayvec]
|
||||
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"
|
||||
switch-hal = "0.4.0"
|
||||
arrayvec = { version = "0.7.2", default-features = false }
|
||||
ssd1306 = "0.7.0"
|
||||
embedded-graphics = "0.7.1"
|
||||
either = { version = "1.5.3", default-features = false }
|
||||
|
||||
[[bin]]
|
||||
name = "blue_pill_more"
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
# The protocol to be used for communicating with the target.
|
||||
protocol = "Swd"
|
||||
# The speed in kHz of the data link to the target.
|
||||
# speed = 1337
|
||||
# speed = 133
|
||||
|
||||
[default.flashing]
|
||||
# Whether or not the target should be flashed.
|
||||
|
|
112
src/main.rs
112
src/main.rs
|
@ -1,55 +1,38 @@
|
|||
#![no_std]
|
||||
#![cfg_attr(not(doc), no_main)]
|
||||
|
||||
use core::{
|
||||
cell::RefCell,
|
||||
fmt::Write,
|
||||
};
|
||||
use core::{cell::RefCell, fmt::Write};
|
||||
|
||||
use rtt_target::{rprintln, rtt_init_print};
|
||||
use panic_rtt_target as _;
|
||||
|
||||
use rtt_target::{rprintln, rtt_init_print};
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
|
||||
use cortex_m::{
|
||||
interrupt::Mutex,
|
||||
};
|
||||
use cortex_m::interrupt::Mutex;
|
||||
|
||||
use stm32f1xx_hal::{
|
||||
afio,
|
||||
device::{EXTI, NVIC},
|
||||
delay::Delay,
|
||||
i2c::{BlockingI2c, DutyCycle, Mode},
|
||||
device::{EXTI, NVIC},
|
||||
gpio::{
|
||||
Input,
|
||||
Floating,
|
||||
ExtiPin,
|
||||
Edge,
|
||||
gpioa::{PA8, PA9},
|
||||
Edge, ExtiPin, Floating, Input,
|
||||
},
|
||||
pac::{
|
||||
CorePeripherals,
|
||||
Peripherals,
|
||||
Interrupt,
|
||||
interrupt,
|
||||
},
|
||||
i2c::{BlockingI2c, DutyCycle, Mode},
|
||||
pac::{interrupt, CorePeripherals, Interrupt, Peripherals},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
use switch_hal::{IntoSwitch, InputSwitch, OutputSwitch, ToggleableOutputSwitch};
|
||||
use switch_hal::{InputSwitch, IntoSwitch, OutputSwitch, ToggleableOutputSwitch};
|
||||
|
||||
use ssd1306::{
|
||||
prelude::*,
|
||||
Builder,
|
||||
};
|
||||
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306};
|
||||
|
||||
use embedded_graphics::{
|
||||
fonts::{Font6x8, Text},
|
||||
mono_font::{ascii::FONT_6X9, MonoTextStyleBuilder},
|
||||
pixelcolor::BinaryColor,
|
||||
prelude::*,
|
||||
primitives::Circle,
|
||||
style::{PrimitiveStyle, TextStyle},
|
||||
primitives::{Circle, PrimitiveStyle},
|
||||
text::{Baseline, Text},
|
||||
};
|
||||
|
||||
use arrayvec::ArrayString;
|
||||
|
@ -57,11 +40,11 @@ use arrayvec::ArrayString;
|
|||
mod rotary;
|
||||
use rotary::{Direction, Rotary};
|
||||
|
||||
type CLKPIN = PA8<Input<Floating>>;
|
||||
type DTPIN = PA9<Input<Floating>>;
|
||||
type ClkPin = PA8<Input<Floating>>;
|
||||
type DtPin = PA9<Input<Floating>>;
|
||||
|
||||
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 CLK_PIN: Mutex<RefCell<Option<ClkPin>>> = 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));
|
||||
|
||||
#[entry]
|
||||
|
@ -77,9 +60,9 @@ fn main() -> ! {
|
|||
|
||||
// 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
|
||||
let mut rcc = dev_periph.RCC.constrain();
|
||||
let rcc = dev_periph.RCC.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
|
||||
// we configure the clock and "freeze" the configuration so we can pass it
|
||||
|
@ -87,9 +70,9 @@ fn main() -> ! {
|
|||
.cfgr
|
||||
.use_hse(8.mhz()) // Use High Speed External 8Mhz crystal oscillator
|
||||
.sysclk(72.mhz()) // Use the PLL to multiply SYSCLK to 72MHz
|
||||
.hclk(72.mhz()) // Leave AHB prescaler at /1
|
||||
.pclk1(36.mhz()) // Use the APB1 prescaler to divide the clock to 36MHz (max supported)
|
||||
.pclk2(72.mhz()) // Leave the APB2 prescaler at /1
|
||||
.hclk(72.mhz()) // Leave AHB prescaler at /1
|
||||
.pclk1(36.mhz()) // Use the APB1 prescaler to divide the clock to 36MHz (max supported)
|
||||
.pclk2(72.mhz()) // Leave the APB2 prescaler at /1
|
||||
.adcclk(12.mhz()) // ADC prescaler of /6 (max speed of 14MHz, but /4 gives 18MHz)
|
||||
.freeze(&mut flash.acr);
|
||||
|
||||
|
@ -98,16 +81,15 @@ fn main() -> ! {
|
|||
let mut delay = Delay::new(core_periph.SYST, clocks);
|
||||
|
||||
// Acquire the necessary gpio peripherals
|
||||
let mut gpioa = dev_periph.GPIOA.split(&mut rcc.apb2);
|
||||
let mut gpiob = dev_periph.GPIOB.split(&mut rcc.apb2);
|
||||
let mut gpioc = dev_periph.GPIOC.split(&mut rcc.apb2);
|
||||
let mut gpioa = dev_periph.GPIOA.split();
|
||||
let mut gpiob = dev_periph.GPIOB.split();
|
||||
let mut gpioc = dev_periph.GPIOC.split();
|
||||
|
||||
// Configure the rotary encoder pins A8, A9 and switch pin A10
|
||||
let clk = gpioa.pa8
|
||||
.into_floating_input(&mut gpioa.crh);
|
||||
let dt = gpioa.pa9
|
||||
.into_floating_input(&mut gpioa.crh);
|
||||
let sw = gpioa.pa10
|
||||
let clk = gpioa.pa8.into_floating_input(&mut gpioa.crh);
|
||||
let dt = gpioa.pa9.into_floating_input(&mut gpioa.crh);
|
||||
let sw = gpioa
|
||||
.pa10
|
||||
.into_floating_input(&mut gpioa.crh)
|
||||
.into_active_low_switch();
|
||||
|
||||
|
@ -115,7 +97,8 @@ fn main() -> ! {
|
|||
init_encoder_pins(clk, dt, &mut afio, &dev_periph.EXTI);
|
||||
|
||||
// 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_active_low_switch();
|
||||
|
||||
|
@ -136,7 +119,6 @@ fn main() -> ! {
|
|||
duty_cycle: DutyCycle::Ratio2to1,
|
||||
},
|
||||
clocks,
|
||||
&mut rcc.apb1,
|
||||
1000,
|
||||
10,
|
||||
1000,
|
||||
|
@ -144,10 +126,9 @@ fn main() -> ! {
|
|||
);
|
||||
|
||||
// Initialize the display
|
||||
let mut display: GraphicsMode<_> = Builder::new()
|
||||
.with_i2c_addr(0x3c)
|
||||
.connect_i2c(i2c)
|
||||
.into();
|
||||
let interface = I2CDisplayInterface::new(i2c);
|
||||
let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0)
|
||||
.into_buffered_graphics_mode();
|
||||
display.init().unwrap();
|
||||
|
||||
// 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 cy = 20;
|
||||
|
||||
let t = Text::new("Hello Rust!", Point::new(20, 16))
|
||||
.into_styled(TextStyle::new(Font6x8, BinaryColor::On));
|
||||
let text_style = MonoTextStyleBuilder::new()
|
||||
.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
|
||||
led.on().unwrap();
|
||||
|
@ -192,10 +176,9 @@ fn main() -> ! {
|
|||
.into_styled(PrimitiveStyle::with_fill(BinaryColor::On));
|
||||
|
||||
// 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();
|
||||
let count = Text::new(&textbuf, Point::new(20, 36))
|
||||
.into_styled(TextStyle::new(Font6x8, BinaryColor::On));
|
||||
let count = Text::with_baseline(&textbuf, Point::new(20, 36), text_style, Baseline::Top);
|
||||
|
||||
display.clear();
|
||||
c.draw(&mut display).unwrap();
|
||||
|
@ -204,11 +187,12 @@ fn main() -> ! {
|
|||
display.flush().unwrap();
|
||||
|
||||
// Control the horizontal position with the knob
|
||||
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
|
||||
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| {
|
||||
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_PIN.borrow(cs).replace(Some(clk));
|
||||
|
@ -230,7 +214,7 @@ fn init_encoder_pins(
|
|||
|
||||
#[interrupt]
|
||||
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(|| {
|
||||
cortex_m::interrupt::free(|cs| {
|
||||
|
@ -243,9 +227,7 @@ fn EXTI9_5() {
|
|||
if enc.pin_a.check_interrupt() {
|
||||
match enc.update().unwrap() {
|
||||
Direction::Clockwise => cortex_m::interrupt::free(|cs| {
|
||||
COUNT
|
||||
.borrow(cs)
|
||||
.replace_with(|count| count.wrapping_add(1));
|
||||
COUNT.borrow(cs).replace_with(|count| count.wrapping_add(1));
|
||||
}),
|
||||
Direction::CounterClockwise => cortex_m::interrupt::free(|cs| {
|
||||
COUNT
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use embedded_hal as hal;
|
||||
use either::Either;
|
||||
use embedded_hal as hal;
|
||||
use hal::digital::v2::InputPin;
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
|
@ -56,4 +56,3 @@ where
|
|||
Ok(dir)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue