1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#![no_std]

use core::convert::Into;

/// NEC protocol
pub use protocols::nec;
/// Rc5 Protocol
pub use protocols::rc5;
/// Rc6 Protocol
pub use protocols::rc6;

pub mod trace;

/// Remote controls
pub mod remote;
pub use remote::RemoteControl;

mod protocols;

#[derive(PartialEq)]
/// Protocol decoder state
pub enum ReceiverState<CMD, ERR> {
    Idle,
    Receiving,
    Done(CMD),
    Err(ERR),
    Disabled,
}

/// Receiver trait
pub trait Receiver {
    /// The resulting command type
    type Command;
    /// Receive Error
    type ReceiveError;

    /// Register new event
    fn event(
        &mut self,
        pinvalue: bool,
        timestamp: u32,
    ) -> ReceiverState<Self::Command, Self::ReceiveError>;
    /// Reset receiver
    fn reset(&mut self);
    /// Disable receiver
    fn disable(&mut self);
}

pub enum TransmitterState {
    /// Transmitter is ready for transmitting
    Idle,
    /// Transmitting
    Transmit(bool),
    /// Error state
    Err,
}

pub trait Transmitter {
    /// Initialize transfer
    fn init<CMD: Into<u32>>(&mut self, cmd: CMD);

    /// Step the transfer loop
    fn step(&mut self, ts: u32) -> TransmitterState;

    /// Reset the transmitter
    fn reset(&mut self);
}