Progress towards firmware

This commit is contained in:
2022-04-22 21:04:40 +02:00
parent ccf36b6b73
commit 895b403633
5 changed files with 127 additions and 23 deletions

View File

@@ -35,3 +35,5 @@ rp2040-hal = { version="0.4.0", features=["rt"] }
rp2040-boot2 = {version="0.2.0", optional = true }
# Film scanner-specific stuff
jerk_control = { path = "../jerk_control" }

View File

@@ -4,6 +4,7 @@
use defmt_rtt as _;
use panic_probe as _;
mod fmt;
#[rtic::app(device = rp_pico::hal::pac, peripherals = true)]
@@ -11,6 +12,7 @@ mod app {
use crate::fmt::Wrapper;
use core::fmt::Write;
use core::num::Wrapping;
use embedded_hal::digital::v2::OutputPin;
use embedded_time::duration::Extensions;
@@ -24,6 +26,8 @@ mod app {
// USB Communications Class Device support
use usbd_serial::SerialPort;
use jerk_control::{planner, executor};
// Blinck time 5 seconds
const SCAN_TIME_US: u32 = 5000000; // 200000; // 5000000; // 1000000; // 200000;
@@ -49,11 +53,27 @@ mod app {
// Mathias
// https://github.com/mgottschlag/rp2040-usb-sound-card/blob/b8078b57361c1b08755e5ab5f9992c56457ec18b/src/main.rs#L188
//
//
// Global Static variable, has to be written inside unsafe blocks.
// A reference can be obtained with as_ref() method.
/// A profile that is to be loaded at a certain point in time
struct PlannedProfile {
pub apply_time: Wrapping<u32>,
pub profile: planner::Profile,
}
/// Manages communication with the execution interrupt
struct StepperComm {
pub position_steps: Wrapping<u32>,
pub position_substep: Wrapping<u32>,
pub cur_time: Wrapping<u32>,
pub next_profile: Option<PlannedProfile>,
pub active: bool,
}
pub struct StepperProcess<Pin> {
pub executor: executor::CommandQueue,
pub pin: Pin,
}
#[shared]
struct Shared {
@@ -70,7 +90,9 @@ mod app {
}
#[local]
struct Local {}
struct Local {
executor1: StepperProcess<rp_pico::hal::gpio::Pin<hal::gpio::pin::bank0::>>,
}
#[init(local = [usb_bus: Option<usb_device::bus::UsbBusAllocator<hal::usb::UsbBus>> = None])]
fn init(c: init::Context) -> (Shared, Local, init::Monotonics) {
@@ -164,7 +186,7 @@ mod app {
/// Task that blinks the rp-pico onboard LED and that send a message "LED ON!" and "LED OFF!" do USB-Serial.
#[task(
binds = TIMER_IRQ_0,
priority = 1,
priority = 4,
shared = [timer, alarm, serial],
local = [tog: bool = true],
)]

View File

@@ -1,5 +1,6 @@
use std::cmp::Ordering;
use std::num::Wrapping;
use core::cmp::Ordering;
use core::num::Wrapping;
use core::option::Option;
use crate::planner::{Profile, Segment};
#[derive(Default, Debug)]
@@ -75,4 +76,4 @@ impl CommandQueue {
pub fn time(&self) -> u32 {
self.cur_time.0
}
}
}

View File

@@ -3,7 +3,7 @@
//! Note that the equations in this file are rather complex and non-obvious.
//! All of their derivations can be found in the motion-control.ipynb file.
use std::num::Wrapping;
use core::num::Wrapping;
pub struct Config {
/// Max jerk, in mm/s^3
@@ -244,4 +244,4 @@ impl Planner {
pub fn step_size(&self) -> u32 { self.step_size }
}
}