lpc8xx_hal/i2c/
interrupts.rs

1use super::Instance;
2
3macro_rules! interrupts {
4    (
5        $(
6            $doc:expr,
7            $field:ident,
8            $enable:ident,
9            $disable:ident;
10        )*
11    ) => {
12        /// Used to enable or disable I2C interrupts
13        ///
14        /// See [`I2C::enable_interrupts`] or [`I2C::disable_interrupts`].
15        ///
16        /// [`I2C::enable_interrupts`]: struct.I2C.html#method.enable_interrupts
17        /// [`I2C::disable_interrupts`]: struct.I2C.html#method.disable_interrupts
18        pub struct Interrupts {
19            $(
20                #[doc = $doc]
21                pub $field: bool,
22            )*
23        }
24
25        impl Interrupts {
26            pub(super) fn enable<I: Instance>(&self, i2c: &I) {
27                i2c.intenset.modify(|_, w| {
28                    $(
29                        if self.$field {
30                            w.$enable().enabled();
31                        }
32                    )*
33
34                    w
35                })
36            }
37
38            pub(super) fn disable<I: Instance>(&self, i2c: &I) {
39                i2c.intenclr.write(|w| {
40                    $(
41                        if self.$field {
42                            w.$disable().set_bit();
43                        }
44                    )*
45
46                    w
47                })
48            }
49        }
50
51        impl Default for Interrupts {
52            fn default() -> Self {
53                Self {
54                    $(
55                        $field: false,
56                    )*
57                }
58            }
59        }
60    };
61}
62
63interrupts!(
64    "Master Pending", master_pending,
65        mstpendingen, mstpendingclr;
66    "Master Arbitration Loss", master_arbitration_loss,
67        mstarblossen, mstarblossclr;
68    "Master Start/Stop Error", master_start_stop_error,
69        mstststperren, mstststperrclr;
70    "Slave Pending", slave_pending,
71        slvpendingen, slvpendingclr;
72    "Slave Not Stretching", slave_not_stretching,
73        slvnotstren, slvnotstrclr;
74    "Slave Deselect", slave_deselect,
75        slvdeselen, slvdeselclr;
76    "Monitor Ready", monitor_ready,
77        monrdyen, monrdyclr;
78    "Monitor Overrun", monitor_overrun,
79        monoven, monovclr;
80    "Monitor Idle", monitor_idle,
81        monidleen, monidleclr;
82    "Event Timeout", event_timeout,
83        eventtimeouten, eventtimeoutclr;
84    "SCL Timeout", scl_timeout,
85        scltimeouten, scltimeoutclr;
86);