Compare commits
3 Commits
414e7f0041
...
noblock-te
| Author | SHA1 | Date | |
|---|---|---|---|
| e6127bcf84 | |||
| 6d09ce7bc1 | |||
| 0f2d455a42 |
@@ -14,4 +14,4 @@ rustflags = [
|
||||
target = "xtensa-esp32-none-elf"
|
||||
|
||||
[unstable]
|
||||
build-std = ["alloc", "core"]
|
||||
build-std = ["core"]
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,6 +2,7 @@
|
||||
# will have compiled files and executables
|
||||
debug/
|
||||
target/
|
||||
Cargo.lock
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
|
||||
@@ -10,6 +10,5 @@ hal = { package = "esp32-hal", version = "0.15.0" }
|
||||
esp-backtrace = { version = "0.8.0", features = ["esp32", "panic-handler", "exception-handler", "print-uart"] }
|
||||
esp-println = { version = "0.6.0", features = ["esp32","log"] }
|
||||
log = { version = "0.4.18" }
|
||||
esp-alloc = { version = "0.3.0" }
|
||||
si5351 = "0.2.0"
|
||||
embedded-hal = "0.2.7"
|
||||
|
||||
53
src/main.rs
53
src/main.rs
@@ -1,8 +1,6 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate alloc;
|
||||
use core::mem::MaybeUninit;
|
||||
use esp_backtrace as _;
|
||||
|
||||
use embedded_hal::serial::Read;
|
||||
@@ -13,32 +11,18 @@ use hal::{
|
||||
timer::{self, TimerIFace},
|
||||
HighSpeed, LEDC,
|
||||
},
|
||||
uart, Uart, /*Delay*/
|
||||
IO,
|
||||
uart, Delay, Uart, IO,
|
||||
};
|
||||
|
||||
use si5351::{Si5351, Si5351Device};
|
||||
|
||||
#[global_allocator]
|
||||
static ALLOCATOR: esp_alloc::EspHeap = esp_alloc::EspHeap::empty();
|
||||
|
||||
fn init_heap() {
|
||||
const HEAP_SIZE: usize = 32 * 1024;
|
||||
static mut HEAP: MaybeUninit<[u8; HEAP_SIZE]> = MaybeUninit::uninit();
|
||||
|
||||
unsafe {
|
||||
ALLOCATOR.init(HEAP.as_mut_ptr() as *mut u8, HEAP_SIZE);
|
||||
}
|
||||
}
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
init_heap();
|
||||
let peripherals = Peripherals::take();
|
||||
//let uart = peripherals.UART0;
|
||||
let mut system = peripherals.DPORT.split();
|
||||
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
let clocks = ClockControl::max(system.clock_control).freeze();
|
||||
//let mut delay = Delay::new(&clocks);
|
||||
let delay = Delay::new(&clocks);
|
||||
|
||||
let serial = { uart::Uart::new(peripherals.UART0, &mut system.peripheral_clock_control) };
|
||||
|
||||
@@ -48,7 +32,6 @@ fn main() -> ! {
|
||||
// this requires a clean rebuild because of https://github.com/rust-lang/cargo/issues/10358
|
||||
esp_println::logger::init_logger_from_env();
|
||||
log::info!("Logger is setup");
|
||||
//println!("Hello world!");
|
||||
|
||||
let i2c = I2C::new(
|
||||
peripherals.I2C0,
|
||||
@@ -60,13 +43,12 @@ fn main() -> ! {
|
||||
);
|
||||
log::info!("I2C Initialized");
|
||||
|
||||
//i2c.write(0b0110_0000, &[0x64]);
|
||||
|
||||
let mut clock = Si5351Device::new_adafruit_module(i2c);
|
||||
match clock.init_adafruit_module() {
|
||||
Ok(_) => {
|
||||
log::info!("Si5351 Initialized succesfully");
|
||||
main_loop(clock, serial);
|
||||
clock.set_freq(1_000_000).unwrap();
|
||||
main_loop(clock, serial, delay);
|
||||
}
|
||||
Err(e) => {
|
||||
match e {
|
||||
@@ -102,14 +84,18 @@ fn main() -> ! {
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
main_loop(ledc, serial);
|
||||
main_loop(ledc, serial, delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main_loop<T: Clockable, U: _esp_hal_uart_Instance>(mut clock: T, mut serial: Uart<'_, U>) -> ! {
|
||||
fn main_loop<T: Clockable, U: _esp_hal_uart_Instance>(
|
||||
mut clock: T,
|
||||
mut serial: Uart<'_, U>,
|
||||
mut delay: Delay,
|
||||
) -> ! {
|
||||
loop {
|
||||
let freq = read_freq(&mut serial);
|
||||
let freq = read_freq(&mut serial, &mut delay);
|
||||
log::info!("Got Freq: {}", freq);
|
||||
match clock.set_freq(freq) {
|
||||
Ok(_) => log::info!("Set frequency to {}", freq),
|
||||
@@ -150,13 +136,6 @@ 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;
|
||||
// char c = serial.read();
|
||||
@@ -176,11 +155,12 @@ impl Clockable for Dummy {
|
||||
// return freq;
|
||||
|
||||
// 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>) -> u32 {
|
||||
fn read_freq<T: _esp_hal_uart_Instance>(serial: &mut Uart<'_, T>, delay: &mut Delay) -> u32 {
|
||||
let mut freq = 0;
|
||||
let mut invalid = false;
|
||||
loop {
|
||||
match nb::block!(serial.read()) {
|
||||
//match nb::block!(serial.read()) {
|
||||
match serial.read() {
|
||||
Ok(input) if input >= b'0' && input <= b'9' => {
|
||||
log::debug!("Got char: {}", char::from(input));
|
||||
freq = (freq * 10) + (input - b'0') as u32;
|
||||
@@ -202,9 +182,12 @@ fn read_freq<T: _esp_hal_uart_Instance>(serial: &mut Uart<'_, T>) -> u32 {
|
||||
log::debug!("Got inval: {}", char::from(input));
|
||||
invalid = true;
|
||||
}
|
||||
Err(e) => {
|
||||
Err(nb::Error::Other(e)) => {
|
||||
log::debug!("Got error: {:?}", e);
|
||||
}
|
||||
Err(nb::Error::WouldBlock) => {
|
||||
delay.delay(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user