Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use XtalClock as UART source and adapt interrupt binding #57

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 98 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ categories = ["embedded", "no-std"]

[dependencies]
critical-section = "1.1.2"
esp-hal = { version = "0.16.0" }
heapless = { version = "0.8.0", default-features = false }
esp-hal = { git = "https://github.com/esp-rs/esp-hal", rev = "8f2ee88" }
SergioGasquez marked this conversation as resolved.
Show resolved Hide resolved
heapless = { version = "0.8.0", default-features = false }
static_cell = "2.0.0"

[dev-dependencies]
Expand Down
17 changes: 11 additions & 6 deletions src/io/uart.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
use super::{UartMarker, RX_QUEUE};
use crate::{
hal::{macros::interrupt, peripherals::UART0, uart::Instance, Uart},
hal::{
peripherals::UART0,
prelude::handler,
uart::{Instance, Uart},
Blocking,
},
protocol::InputIO,
};

impl<T> InputIO for Uart<'_, T>
impl<T> InputIO for Uart<'_, T, Blocking>
where
T: Instance,
{
Expand All @@ -20,10 +25,10 @@ where
}
}

impl<T> UartMarker for Uart<'_, T> where T: Instance {}
impl<T> UartMarker for Uart<'_, T, Blocking> where T: Instance {}

#[interrupt]
fn UART0() {
#[handler]
pub fn uart0_hanlder() {
SergioGasquez marked this conversation as resolved.
Show resolved Hide resolved
let uart = unsafe { &*UART0::ptr() };

while uart.status().read().rxfifo_cnt().bits() > 0 {
Expand All @@ -41,5 +46,5 @@ fn UART0() {
unsafe { RX_QUEUE.push_back(data).unwrap() };
}

uart.int_clr().write(|w| w.rxfifo_full_int_clr().set_bit());
uart.int_clr().write(|w| w.rxfifo_full().clear_bit_by_one());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
13 changes: 7 additions & 6 deletions src/io/usb_serial_jtag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ use super::{UsbSerialJtagMarker, RX_QUEUE};
use crate::{
hal::{
peripherals::USB_DEVICE,
prelude::interrupt,
prelude::handler,
usb_serial_jtag::{Instance, UsbSerialJtag},
Blocking,
},
protocol::InputIO,
};

impl InputIO for UsbSerialJtag<'_> {
impl InputIO for UsbSerialJtag<'_, Blocking> {
fn recv(&mut self) -> u8 {
unsafe {
while critical_section::with(|_| RX_QUEUE.is_empty()) {}
Expand All @@ -21,10 +22,10 @@ impl InputIO for UsbSerialJtag<'_> {
}
}

impl UsbSerialJtagMarker for UsbSerialJtag<'_> {}
impl UsbSerialJtagMarker for UsbSerialJtag<'_, Blocking> {}

#[interrupt]
unsafe fn USB_DEVICE() {
#[handler]
pub fn usb_device_handler() {
let reg_block = USB_DEVICE::register_block();

while reg_block
Expand All @@ -42,5 +43,5 @@ unsafe fn USB_DEVICE() {

reg_block
.int_clr()
.write(|w| w.serial_out_recv_pkt_int_clr().set_bit());
.write(|w| w.serial_out_recv_pkt().clear_bit_by_one());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub mod targets;
pub use esp_hal as hal;

use self::{
hal::{peripherals::UART0, Uart},
hal::{peripherals::UART0, uart::Uart, Blocking},
io::Noop,
};

Expand Down Expand Up @@ -80,21 +80,21 @@ impl TransportMethod {
// TODO this sucks, but default generic parameters are not used when inference
// fails, meaning that we _have_ to specifiy the types here Seems like work on this has stalled: https://github.com/rust-lang/rust/issues/27336, note that I tried the feature and it didn't work.
#[cfg(not(any(usb_device, usb0)))]
pub type Transport = io::Transport<&'static mut Uart<'static, UART0>, Noop, Noop>;
pub type Transport = io::Transport<&'static mut Uart<'static, UART0, Blocking>, Noop, Noop>;

#[cfg(all(usb_device, not(usb0)))]
pub type Transport = io::Transport<
&'static mut Uart<'static, UART0>,
&'static mut crate::hal::UsbSerialJtag<'static>,
&'static mut Uart<'static, UART0, Blocking>,
&'static mut crate::hal::usb_serial_jtag::UsbSerialJtag<'static, Blocking>,
Noop,
>;

#[cfg(all(not(usb_device), usb0))]
pub type Transport = io::Transport<&'static mut Uart<'static, UART0>, Noop, Noop>; // TODO replace Noop with usb type later
pub type Transport = io::Transport<&'static mut Uart<'static, UART0, Blocking>, Noop, Noop>; // TODO replace Noop with usb type later

#[cfg(all(usb_device, usb0))]
pub type Transport = io::Transport<
&'static mut Uart<'static, UART0>,
&'static mut crate::hal::UsbSerialJtag<'static>,
&'static mut Uart<'static, UART0, Blocking>,
&'static mut crate::hal::usb_serial_jtag::UsbSerialJtag<'static, Blocking>,
Noop, // TODO replace Noop with usb type later
>;
Loading