Skip to content

Commit

Permalink
finish spinning
Browse files Browse the repository at this point in the history
  • Loading branch information
HenoHyj committed Oct 17, 2024
1 parent 842891f commit 25dfb5f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions firmware/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ bleps = { git = "https://github.com/bjoernQ/bleps", package = "bleps", rev = "a5
"async",
] }
esp-alloc = "0.4.0"
fugit = "0.3.7"

[[bin]]
name = "firmware"
Expand Down
29 changes: 25 additions & 4 deletions firmware/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ use embassy_executor::Spawner;
use embassy_time::Timer;
use esp_backtrace as _;
use esp_hal::{
gpio::{Io, Level, Output},
timer::timg::TimerGroup,
clock::Clocks, gpio::{Io, Level, Output}, mcpwm::PeripheralClockConfig, timer::timg::TimerGroup
};
use esp_println::println;
use fugit::RateExtU32;
use esp_hal::mcpwm::McPwm;
use esp_hal::mcpwm::timer::PwmWorkingMode;
use esp_hal::mcpwm::operator::PwmPinConfig;

#[esp_hal_embassy::main]
async fn main(_spawner: Spawner) {
Expand All @@ -22,8 +25,26 @@ async fn main(_spawner: Spawner) {

let mut led = Output::new(io.pins.gpio18, Level::Low);
// add these
let motor_hi = Output::new(io.pins.gpio13, Level::High);
let motor_lo = Output::new(io.pins.gpio14, Level::Low);
let motor_hi_pin = io.pins.gpio13;
let motor_lo_pin = io.pins.gpio14;

let clocks = Clocks::get();
//println!("src clock: {}", clocks.crypto_pwm_clock);
let clock_cfg = PeripheralClockConfig::with_frequency(32.MHz()).unwrap(); //let mut mcpwm = McPwm::new(peripherals.MCPWM0, clock_cfg);
let mut mcpwm = McPwm::new(peripherals.MCPWM0, clock_cfg);
mcpwm.operator0.set_timer(&mcpwm.timer0);
let timer_clock_cfg = clock_cfg.timer_clock_with_frequency(u8::MAX as u16, PwmWorkingMode::Increase, 20.kHz()).unwrap();
mcpwm.timer0.start(timer_clock_cfg);

let (mut motor_hi, mut motor_lo) = mcpwm.operator0.with_pins(
motor_hi_pin,
PwmPinConfig::UP_ACTIVE_HIGH,
motor_lo_pin,
PwmPinConfig::UP_ACTIVE_HIGH,
);

// motor_hi.set_timestamp(180);
// motor_lo.set_timestamp(0);

loop {
println!("Hello, World!");
Expand Down

0 comments on commit 25dfb5f

Please sign in to comment.