dap_rs/
swo.rs

1use num_enum::TryFromPrimitive;
2
3#[derive(Copy, Clone, Debug, TryFromPrimitive)]
4#[cfg_attr(feature = "defmt", derive(defmt::Format))]
5#[repr(u8)]
6pub enum SwoTransport {
7    None = 0,
8    DAPCommand = 1,
9    USBEndpoint = 2,
10}
11
12#[derive(Copy, Clone, Debug, TryFromPrimitive)]
13#[cfg_attr(feature = "defmt", derive(defmt::Format))]
14#[repr(u8)]
15pub enum SwoMode {
16    Off = 0,
17    UART = 1,
18    Manchester = 2,
19}
20
21#[derive(Copy, Clone, Debug, TryFromPrimitive)]
22#[cfg_attr(feature = "defmt", derive(defmt::Format))]
23#[repr(u8)]
24pub enum SwoControl {
25    Stop = 0,
26    Start = 1,
27}
28
29#[derive(Copy, Clone, Debug)]
30#[cfg_attr(feature = "defmt", derive(defmt::Format))]
31pub struct SwoSupport {
32    pub uart: bool,
33    pub manchester: bool,
34}
35
36#[derive(Copy, Clone, Debug)]
37#[cfg_attr(feature = "defmt", derive(defmt::Format))]
38pub struct SwoStatus {
39    pub active: bool,
40    pub trace_error: bool,
41    pub trace_overrun: bool,
42    pub bytes_available: u32,
43}
44
45#[cfg_attr(test, mockall::automock)]
46pub trait Swo {
47    fn set_transport(&mut self, transport: SwoTransport);
48    fn set_mode(&mut self, mode: SwoMode);
49    fn set_baudrate(&mut self, baudrate: u32) -> u32;
50    fn set_control(&mut self, control: SwoControl);
51    fn polling_data(&mut self, buf: &mut [u8]) -> u32;
52    fn streaming_data(&mut self); //  -> SomeBufferFromStreaming; // TODO: What is a good interface?
53    fn is_active(&self) -> bool;
54    fn bytes_available(&self) -> u32;
55    fn buffer_size(&self) -> u32;
56    fn support(&self) -> SwoSupport;
57    fn status(&mut self) -> SwoStatus;
58}