Compare commits
4 Commits
414e7f0041
...
quadrature
| Author | SHA1 | Date | |
|---|---|---|---|
| 603113d9ed | |||
| 15fc7d5602 | |||
| 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"
|
||||
si5351 = { git = "http://192.168.1.41:3000/lks/si5351.git" }
|
||||
embedded-hal = "0.2.7"
|
||||
|
||||
31
src/main.rs
31
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;
|
||||
@@ -19,20 +17,8 @@ use hal::{
|
||||
|
||||
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();
|
||||
@@ -108,10 +94,11 @@ fn main() -> ! {
|
||||
}
|
||||
|
||||
fn main_loop<T: Clockable, U: _esp_hal_uart_Instance>(mut clock: T, mut serial: Uart<'_, U>) -> ! {
|
||||
clock.set_freq(1_000_000).unwrap();
|
||||
loop {
|
||||
let freq = read_freq(&mut serial);
|
||||
log::info!("Got Freq: {}", freq);
|
||||
match clock.set_freq(freq) {
|
||||
match clock.set_quad(freq) {
|
||||
Ok(_) => log::info!("Set frequency to {}", freq),
|
||||
Err(_) => log::warn!("Could not set frequency to {}", freq),
|
||||
}
|
||||
@@ -120,9 +107,13 @@ fn main_loop<T: Clockable, U: _esp_hal_uart_Instance>(mut clock: T, mut serial:
|
||||
|
||||
trait Clockable {
|
||||
fn set_freq(&mut self, freq: u32) -> Result<(), ()>;
|
||||
fn set_quad(&mut self, freq: u32) -> Result<f32, ()>;
|
||||
}
|
||||
|
||||
impl Clockable for LEDC<'_> {
|
||||
fn set_quad(&mut self, _freq: u32) -> Result<f32, ()> {
|
||||
Err(())
|
||||
}
|
||||
fn set_freq(&mut self, freq: u32) -> Result<(), ()> {
|
||||
let mut hstimer0 = self.get_timer::<HighSpeed>(timer::Number::Timer0);
|
||||
|
||||
@@ -143,6 +134,9 @@ impl<T> Clockable for Si5351Device<T>
|
||||
where
|
||||
Si5351Device<T>: Si5351,
|
||||
{
|
||||
fn set_quad(&mut self, freq: u32) -> Result<f32, ()> {
|
||||
Si5351::set_quad(self, freq).map_err(|_| ())
|
||||
}
|
||||
fn set_freq(&mut self, freq: u32) -> Result<(), ()> {
|
||||
match self.set_frequency(si5351::PLL::A, si5351::ClockOutput::Clk0, freq) {
|
||||
Ok(_) => Ok(()),
|
||||
@@ -150,13 +144,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();
|
||||
|
||||
Reference in New Issue
Block a user