Compare commits
1 Commits
noblock-te
...
414e7f0041
| Author | SHA1 | Date | |
|---|---|---|---|
| 414e7f0041 |
@@ -14,4 +14,4 @@ rustflags = [
|
|||||||
target = "xtensa-esp32-none-elf"
|
target = "xtensa-esp32-none-elf"
|
||||||
|
|
||||||
[unstable]
|
[unstable]
|
||||||
build-std = ["core"]
|
build-std = ["alloc", "core"]
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,7 +2,6 @@
|
|||||||
# will have compiled files and executables
|
# will have compiled files and executables
|
||||||
debug/
|
debug/
|
||||||
target/
|
target/
|
||||||
Cargo.lock
|
|
||||||
|
|
||||||
# These are backup files generated by rustfmt
|
# These are backup files generated by rustfmt
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
|
|||||||
40
src/main.rs
40
src/main.rs
@@ -1,6 +1,7 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
use esp_backtrace as _;
|
use esp_backtrace as _;
|
||||||
|
|
||||||
use embedded_hal::serial::Read;
|
use embedded_hal::serial::Read;
|
||||||
@@ -11,7 +12,8 @@ use hal::{
|
|||||||
timer::{self, TimerIFace},
|
timer::{self, TimerIFace},
|
||||||
HighSpeed, LEDC,
|
HighSpeed, LEDC,
|
||||||
},
|
},
|
||||||
uart, Delay, Uart, IO,
|
uart, Uart, /*Delay*/
|
||||||
|
IO,
|
||||||
};
|
};
|
||||||
|
|
||||||
use si5351::{Si5351, Si5351Device};
|
use si5351::{Si5351, Si5351Device};
|
||||||
@@ -19,10 +21,11 @@ use si5351::{Si5351, Si5351Device};
|
|||||||
#[entry]
|
#[entry]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
let peripherals = Peripherals::take();
|
let peripherals = Peripherals::take();
|
||||||
|
//let uart = peripherals.UART0;
|
||||||
let mut system = peripherals.DPORT.split();
|
let mut system = peripherals.DPORT.split();
|
||||||
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||||
let clocks = ClockControl::max(system.clock_control).freeze();
|
let clocks = ClockControl::max(system.clock_control).freeze();
|
||||||
let delay = Delay::new(&clocks);
|
//let mut delay = Delay::new(&clocks);
|
||||||
|
|
||||||
let serial = { uart::Uart::new(peripherals.UART0, &mut system.peripheral_clock_control) };
|
let serial = { uart::Uart::new(peripherals.UART0, &mut system.peripheral_clock_control) };
|
||||||
|
|
||||||
@@ -32,6 +35,7 @@ fn main() -> ! {
|
|||||||
// this requires a clean rebuild because of https://github.com/rust-lang/cargo/issues/10358
|
// this requires a clean rebuild because of https://github.com/rust-lang/cargo/issues/10358
|
||||||
esp_println::logger::init_logger_from_env();
|
esp_println::logger::init_logger_from_env();
|
||||||
log::info!("Logger is setup");
|
log::info!("Logger is setup");
|
||||||
|
//println!("Hello world!");
|
||||||
|
|
||||||
let i2c = I2C::new(
|
let i2c = I2C::new(
|
||||||
peripherals.I2C0,
|
peripherals.I2C0,
|
||||||
@@ -43,12 +47,13 @@ fn main() -> ! {
|
|||||||
);
|
);
|
||||||
log::info!("I2C Initialized");
|
log::info!("I2C Initialized");
|
||||||
|
|
||||||
|
//i2c.write(0b0110_0000, &[0x64]);
|
||||||
|
|
||||||
let mut clock = Si5351Device::new_adafruit_module(i2c);
|
let mut clock = Si5351Device::new_adafruit_module(i2c);
|
||||||
match clock.init_adafruit_module() {
|
match clock.init_adafruit_module() {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
log::info!("Si5351 Initialized succesfully");
|
log::info!("Si5351 Initialized succesfully");
|
||||||
clock.set_freq(1_000_000).unwrap();
|
main_loop(clock, serial);
|
||||||
main_loop(clock, serial, delay);
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
match e {
|
match e {
|
||||||
@@ -84,18 +89,14 @@ fn main() -> ! {
|
|||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
main_loop(ledc, serial, delay);
|
main_loop(ledc, serial);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main_loop<T: Clockable, U: _esp_hal_uart_Instance>(
|
fn main_loop<T: Clockable, U: _esp_hal_uart_Instance>(mut clock: T, mut serial: Uart<'_, U>) -> ! {
|
||||||
mut clock: T,
|
|
||||||
mut serial: Uart<'_, U>,
|
|
||||||
mut delay: Delay,
|
|
||||||
) -> ! {
|
|
||||||
loop {
|
loop {
|
||||||
let freq = read_freq(&mut serial, &mut delay);
|
let freq = read_freq(&mut serial);
|
||||||
log::info!("Got Freq: {}", freq);
|
log::info!("Got Freq: {}", freq);
|
||||||
match clock.set_freq(freq) {
|
match clock.set_freq(freq) {
|
||||||
Ok(_) => log::info!("Set frequency to {}", freq),
|
Ok(_) => log::info!("Set frequency to {}", freq),
|
||||||
@@ -136,6 +137,13 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
struct Dummy;
|
||||||
|
impl Clockable for Dummy {
|
||||||
|
fn set_freq(&mut self, freq: u32) -> Result<(), ()> {
|
||||||
|
log::info!("Dummy set freq: {}", freq);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// bool inval = false;
|
// bool inval = false;
|
||||||
// char c = serial.read();
|
// char c = serial.read();
|
||||||
@@ -155,12 +163,11 @@ where
|
|||||||
// return freq;
|
// return freq;
|
||||||
|
|
||||||
// fn rf<T: embedded_hal::serial::Read<u8>>(serial: &mut T) -> u32 { 0 }
|
// fn rf<T: embedded_hal::serial::Read<u8>>(serial: &mut T) -> u32 { 0 }
|
||||||
fn read_freq<T: _esp_hal_uart_Instance>(serial: &mut Uart<'_, T>, delay: &mut Delay) -> u32 {
|
fn read_freq<T: _esp_hal_uart_Instance>(serial: &mut Uart<'_, T>) -> u32 {
|
||||||
let mut freq = 0;
|
let mut freq = 0;
|
||||||
let mut invalid = false;
|
let mut invalid = false;
|
||||||
loop {
|
loop {
|
||||||
//match nb::block!(serial.read()) {
|
match nb::block!(serial.read()) {
|
||||||
match serial.read() {
|
|
||||||
Ok(input) if input >= b'0' && input <= b'9' => {
|
Ok(input) if input >= b'0' && input <= b'9' => {
|
||||||
log::debug!("Got char: {}", char::from(input));
|
log::debug!("Got char: {}", char::from(input));
|
||||||
freq = (freq * 10) + (input - b'0') as u32;
|
freq = (freq * 10) + (input - b'0') as u32;
|
||||||
@@ -182,12 +189,9 @@ fn read_freq<T: _esp_hal_uart_Instance>(serial: &mut Uart<'_, T>, delay: &mut De
|
|||||||
log::debug!("Got inval: {}", char::from(input));
|
log::debug!("Got inval: {}", char::from(input));
|
||||||
invalid = true;
|
invalid = true;
|
||||||
}
|
}
|
||||||
Err(nb::Error::Other(e)) => {
|
Err(e) => {
|
||||||
log::debug!("Got error: {:?}", e);
|
log::debug!("Got error: {:?}", e);
|
||||||
}
|
}
|
||||||
Err(nb::Error::WouldBlock) => {
|
|
||||||
delay.delay(10);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user