va416xx-hal 0.7.0

HAL for the Vorago VA416xx family of MCUs
Documentation
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
//! API for the DMA peripheral
use arbitrary_int::{u3, u10};
use vorago_shared_hal::{PeripheralSelect, enable_peripheral_clock, reset_peripheral_for_cycles};

use crate::{enable_nvic_interrupt, pac};

const MAX_DMA_TRANSFERS_PER_CYCLE: usize = 1024;
const BASE_PTR_ADDR_MASK: u32 = 0b1111111;

/// DMA cycle control values.
///
/// Refer to chapter 6.3.1 and 6.6.3 of the datasheet for more details.
#[bitbybit::bitenum(u3, exhaustive = true)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum CycleControl {
    /// Indicates that the data structure is invalid.
    Stop = 0b000,
    /// The controller must receive a new request prior to entering the arbitration
    /// process, to enable the DMA cycle to complete. This means that the DMA will only
    /// continue to do transfers as long as a trigger signal is still active. Therefore,
    /// this should not be used for momentary triggers like a timer.
    Basic = 0b001,
    /// The controller automatically inserts a request for the appropriate channel during the
    /// arbitration process. This means that the initial request is sufficient to enable the
    /// DMA cycle to complete.
    Auto = 0b010,
    /// This is used to support continuous data flow. Both primary and alternate data structure
    /// are used. The primary data structure is used first. When the first transfer is complete, an
    /// interrupt can be generated, and the DMA switches to the alternate data structure. When the
    /// second transfer is complete, the primary data structure is used. This pattern continues
    /// until software disables the channel.
    PingPong = 0b011,
    MemScatterGatherPrimary = 0b100,
    MemScatterGatherAlternate = 0b101,
    PeriphScatterGatherPrimary = 0b110,
    PeriphScatterGatherAlternate = 0b111,
}

#[bitbybit::bitenum(u2, exhaustive = true)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum AddrIncrement {
    Byte = 0b00,
    Halfword = 0b01,
    Word = 0b10,
    None = 0b11,
}

#[bitbybit::bitenum(u2, exhaustive = false)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum DataSize {
    Byte = 0b00,
    Halfword = 0b01,
    Word = 0b10,
}

/// This configuration controls how many DMA transfers can occur before the controller arbitrates.
#[bitbybit::bitenum(u4, exhaustive = true)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum RPower {
    EachTransfer = 0b0000,
    Every2 = 0b0001,
    Every4 = 0b0010,
    Every8 = 0b0011,
    Every16 = 0b0100,
    Every32 = 0b0101,
    Every64 = 0b0110,
    Every128 = 0b0111,
    Every256 = 0b1000,
    Every512 = 0b1001,
    Every1024 = 0b1010,
    Every1024Alt0 = 0b1011,
    Every1024Alt1 = 0b1100,
    Every1024Alt2 = 0b1101,
    Every1024Alt3 = 0b1110,
    Every1024Alt4 = 0b1111,
}

#[derive(Debug, PartialEq, Eq, thiserror::Error)]
#[error("Invalid DMA control block address")]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct InvalidCtrlBlockAddrError;

#[bitbybit::bitfield(u32, default = 0x0, debug, defmt_fields(feature = "defmt"))]
pub struct ChannelConfig {
    #[bits(30..=31, rw)]
    dst_inc: AddrIncrement,
    #[bits(28..=29, rw)]
    dst_size: Option<DataSize>,
    #[bits(26..=27, rw)]
    src_inc: AddrIncrement,
    #[bits(24..=25, rw)]
    src_size: Option<DataSize>,
    #[bits(21..=23, rw)]
    dest_prot_ctrl: u3,
    #[bits(18..=20, rw)]
    src_prot_ctrl: u3,
    #[bits(14..=17, rw)]
    r_power: RPower,
    #[bits(4..=13, rw)]
    n_minus_1: u10,
    #[bit(3, rw)]
    next_useburst: bool,
    #[bits(0..=2, rw)]
    cycle_ctrl: CycleControl,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct DmaChannelControl {
    pub src_end_ptr: u32,
    pub dest_end_ptr: u32,
    pub cfg: ChannelConfig,
    padding: u32,
}

impl DmaChannelControl {
    const fn new() -> Self {
        Self {
            src_end_ptr: 0,
            dest_end_ptr: 0,
            cfg: ChannelConfig::new_with_raw_value(0),
            padding: 0,
        }
    }
}
impl Default for DmaChannelControl {
    fn default() -> Self {
        Self::new()
    }
}
#[repr(C)]
#[repr(align(128))]
pub struct DmaCtrlBlock {
    pub pri: [DmaChannelControl; 4],
    pub alt: [DmaChannelControl; 4],
}

impl DmaCtrlBlock {
    pub const fn new() -> Self {
        Self {
            pri: [DmaChannelControl::new(); 4],
            alt: [DmaChannelControl::new(); 4],
        }
    }
}
impl Default for DmaCtrlBlock {
    fn default() -> Self {
        Self::new()
    }
}

impl DmaCtrlBlock {
    /// This function creates a DMA control block at the specified memory address.
    ///
    /// The passed address must be 128-byte aligned. The user must also take care of specifying
    /// a valid memory address for the DMA control block which is accessible by the system as well.
    /// For example, the control block can be placed in the SRAM1.
    pub fn new_at_addr(addr: u32) -> Result<*mut DmaCtrlBlock, InvalidCtrlBlockAddrError> {
        if addr & BASE_PTR_ADDR_MASK > 0 {
            return Err(InvalidCtrlBlockAddrError);
        }
        let ctrl_block_ptr = addr as *mut DmaCtrlBlock;
        unsafe { core::ptr::write(ctrl_block_ptr, DmaCtrlBlock::default()) }
        Ok(ctrl_block_ptr)
    }
}

pub struct Dma {
    dma: pac::Dma,
    ctrl_block: *mut DmaCtrlBlock,
}

#[derive(Debug, Clone, Copy, thiserror::Error)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum DmaTransferInitError {
    #[error("source and destination buffer length mismatch: {src_len} != {dest_len}")]
    SourceDestLenMissmatch { src_len: usize, dest_len: usize },
    /// Overflow when calculating the source or destination end address.
    #[error("address overflow")]
    AddrOverflow,
    /// Transfer size larger than 1024 units.
    #[error("transfer size too large: {0}, 1024 is the allowed maximum")]
    TransferSizeTooLarge(usize),
}

#[derive(Debug, Clone, Copy, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct DmaConfig {
    pub bufferable: bool,
    pub cacheable: bool,
    pub privileged: bool,
}

pub struct DmaChannel {
    channel: u8,
    done_interrupt: pac::Interrupt,
    active_interrupt: pac::Interrupt,
    pub dma: pac::Dma,
    pub ch_ctrl_pri: &'static mut DmaChannelControl,
    pub ch_ctrl_alt: &'static mut DmaChannelControl,
}

impl DmaChannel {
    #[inline(always)]
    pub fn channel(&self) -> u8 {
        self.channel
    }

    #[inline(always)]
    pub fn enable(&mut self) {
        self.dma
            .chnl_enable_set()
            .write(|w| unsafe { w.bits(1 << self.channel) });
    }

    #[inline(always)]
    pub fn is_enabled(&mut self) -> bool {
        ((self.dma.chnl_enable_set().read().bits() >> self.channel) & 0b1) != 0
    }

    #[inline(always)]
    pub fn disable(&mut self) {
        self.dma
            .chnl_enable_clr()
            .write(|w| unsafe { w.bits(1 << self.channel) });
    }

    #[inline(always)]
    pub fn trigger_with_sw_request(&mut self) {
        self.dma
            .chnl_sw_request()
            .write(|w| unsafe { w.bits(1 << self.channel) });
    }

    #[inline(always)]
    pub fn state_raw(&self) -> u8 {
        self.dma.status().read().state().bits()
    }

    #[inline(always)]
    pub fn select_primary_structure(&self) {
        self.dma
            .chnl_pri_alt_clr()
            .write(|w| unsafe { w.bits(1 << self.channel) });
    }

    #[inline(always)]
    pub fn select_alternate_structure(&self) {
        self.dma
            .chnl_pri_alt_set()
            .write(|w| unsafe { w.bits(1 << self.channel) });
    }

    /// Enables the DMA_DONE interrupt for the DMA channel.
    ///
    /// # Safety
    ///
    /// This function is `unsafe` because it can break mask-based critical sections.
    pub unsafe fn enable_done_interrupt(&mut self) {
        unsafe { enable_nvic_interrupt(self.done_interrupt) };
    }

    /// Enables the DMA_ACTIVE interrupt for the DMA channel.
    ///
    /// # Safety
    ///
    /// This function is `unsafe` because it can break mask-based critical sections.
    pub unsafe fn enable_active_interrupt(&mut self) {
        unsafe { enable_nvic_interrupt(self.active_interrupt) };
    }

    /// Prepares a 8-bit DMA transfer from memory to memory.
    ///
    /// This function does not enable the DMA channel and interrupts and only prepares
    /// the DMA control block parameters for the transfer. It configures the primary channel control
    /// structure to perform the transfer.
    ///
    /// You can use [Self::enable], [Self::enable_done_interrupt], [Self::enable_active_interrupt]
    /// to finish the transfer preparation and then use [Self::trigger_with_sw_request] to
    /// start the DMA transfer.
    ///
    /// # Safety
    ///
    /// You must ensure that the destination buffer is safe for DMA writes and the source buffer
    /// is safe for DMA reads. The specific requirements can be read here:
    ///
    ///  - [DMA source buffer](https://docs.rs/embedded-dma/latest/embedded_dma/trait.ReadBuffer.html)
    ///  - [DMA destination buffer](https://docs.rs/embedded-dma/latest/embedded_dma/trait.WriteBuffer.html)
    ///
    /// More specifically, you must ensure that the passed slice remains valid while the DMA is
    /// active or until the DMA is stopped.
    pub unsafe fn prepare_mem_to_mem_transfer_8_bit(
        &mut self,
        source: &[u8],
        dest: &mut [u8],
    ) -> Result<(), DmaTransferInitError> {
        let len = Self::common_mem_transfer_checks(source.len(), dest.len())?;
        self.generic_mem_to_mem_transfer_init(
            len,
            (source.as_ptr() as u32)
                .checked_add(len as u32)
                .ok_or(DmaTransferInitError::AddrOverflow)?,
            (dest.as_ptr() as u32)
                .checked_add(len as u32)
                .ok_or(DmaTransferInitError::AddrOverflow)?,
            DataSize::Byte,
            AddrIncrement::Byte,
        );
        Ok(())
    }

    /// Prepares a 16-bit DMA transfer from memory to memory.
    ///
    /// This function does not enable the DMA channel and interrupts and only prepares
    /// the DMA control block parameters for the transfer. It configures the primary channel control
    /// structure to perform the transfer.
    ///
    /// You can use [Self::enable], [Self::enable_done_interrupt], [Self::enable_active_interrupt]
    /// to finish the transfer preparation and then use [Self::trigger_with_sw_request] to
    /// start the DMA transfer.
    ///
    /// # Safety
    ///
    /// You must ensure that the destination buffer is safe for DMA writes and the source buffer
    /// is safe for DMA reads. The specific requirements can be read here:
    ///
    ///  - [DMA source buffer](https://docs.rs/embedded-dma/latest/embedded_dma/trait.ReadBuffer.html)
    ///  - [DMA destination buffer](https://docs.rs/embedded-dma/latest/embedded_dma/trait.WriteBuffer.html)
    ///
    /// More specifically, you must ensure that the passed slice remains valid while the DMA is
    /// active or until the DMA is stopped.
    pub unsafe fn prepare_mem_to_mem_transfer_16_bit(
        &mut self,
        source: &[u16],
        dest: &mut [u16],
    ) -> Result<(), DmaTransferInitError> {
        let len = Self::common_mem_transfer_checks(source.len(), dest.len())?;
        self.generic_mem_to_mem_transfer_init(
            len,
            (source.as_ptr() as u32)
                .checked_add(len as u32 * core::mem::size_of::<u16>() as u32)
                .ok_or(DmaTransferInitError::AddrOverflow)?,
            (dest.as_ptr() as u32)
                .checked_add(len as u32 * core::mem::size_of::<u16>() as u32)
                .ok_or(DmaTransferInitError::AddrOverflow)?,
            DataSize::Halfword,
            AddrIncrement::Halfword,
        );
        Ok(())
    }

    /// Prepares a 32-bit DMA transfer from memory to memory.
    ///
    /// This function does not enable the DMA channel and interrupts and only prepares
    /// the DMA control block parameters for the transfer. It configures the primary channel control
    /// structure to perform the transfer.
    ///
    /// You can use [Self::enable], [Self::enable_done_interrupt], [Self::enable_active_interrupt]
    /// to finish the transfer preparation and then use [Self::trigger_with_sw_request] to
    /// start the DMA transfer.
    ///
    /// # Safety
    ///
    /// You must ensure that the destination buffer is safe for DMA writes and the source buffer
    /// is safe for DMA reads. The specific requirements can be read here:
    ///
    ///  - [DMA source buffer](https://docs.rs/embedded-dma/latest/embedded_dma/trait.ReadBuffer.html)
    ///  - [DMA destination buffer](https://docs.rs/embedded-dma/latest/embedded_dma/trait.WriteBuffer.html)
    ///
    /// More specifically, you must ensure that the passed slice remains valid while the DMA is
    /// active or until the DMA is stopped.
    pub unsafe fn prepare_mem_to_mem_transfer_32_bit(
        &mut self,
        source: &[u32],
        dest: &mut [u32],
    ) -> Result<(), DmaTransferInitError> {
        let len = Self::common_mem_transfer_checks(source.len(), dest.len())?;
        self.generic_mem_to_mem_transfer_init(
            len,
            (source.as_ptr() as u32)
                .checked_add(len as u32 * core::mem::size_of::<u32>() as u32)
                .ok_or(DmaTransferInitError::AddrOverflow)?,
            (dest.as_ptr() as u32)
                .checked_add(len as u32 * core::mem::size_of::<u32>() as u32)
                .ok_or(DmaTransferInitError::AddrOverflow)?,
            DataSize::Word,
            AddrIncrement::Word,
        );
        Ok(())
    }

    /// Prepares a 8-bit DMA transfer from memory to a peripheral.
    ///
    /// It is assumed that a peripheral with a 16-byte FIFO is used here and that the
    /// transfer is activated by an IRQ trigger when the half-full interrupt of the peripheral
    /// is fired. Therefore, this function configured the DMA in [CycleControl::Basic] mode with
    /// rearbitration happening every 8 DMA cycles. It also configures the primary channel control
    /// structure to perform the transfer.
    ///
    /// # Safety
    ///
    /// You must ensure that the source buffer is safe for DMA reads. The specific requirements
    /// can be read here:
    ///
    ///  - [DMA source buffer](https://docs.rs/embedded-dma/latest/embedded_dma/trait.ReadBuffer.html)
    ///
    /// More specifically, you must ensure that the passed slice remains valid while the DMA is
    /// active or until the DMA is stopped.
    ///
    /// The destination address must be the pointer address of a peripheral FIFO register address.
    /// You must also ensure that the regular synchronous transfer API of the peripheral is NOT
    /// used to perform transfers.
    pub unsafe fn prepare_mem_to_periph_transfer_8_bit(
        &mut self,
        source: &[u8],
        dest: *mut u32,
    ) -> Result<(), DmaTransferInitError> {
        if source.len() > MAX_DMA_TRANSFERS_PER_CYCLE {
            return Err(DmaTransferInitError::TransferSizeTooLarge(source.len()));
        }
        let len = source.len() - 1;
        self.ch_ctrl_pri.cfg = ChannelConfig::new_with_raw_value(0);
        self.ch_ctrl_pri.src_end_ptr = (source.as_ptr() as u32)
            .checked_add(len as u32)
            .ok_or(DmaTransferInitError::AddrOverflow)?;
        self.ch_ctrl_pri.dest_end_ptr = dest as u32;
        self.ch_ctrl_pri.cfg.set_cycle_ctrl(CycleControl::Basic);
        self.ch_ctrl_pri.cfg.set_src_size(DataSize::Byte);
        self.ch_ctrl_pri.cfg.set_src_inc(AddrIncrement::Byte);
        self.ch_ctrl_pri.cfg.set_dst_size(DataSize::Byte);
        self.ch_ctrl_pri.cfg.set_dst_inc(AddrIncrement::None);
        self.ch_ctrl_pri.cfg.set_n_minus_1(u10::new(len as u16));
        self.ch_ctrl_pri.cfg.set_r_power(RPower::Every8);
        self.select_primary_structure();
        Ok(())
    }

    // This function performs common checks and returns the source length minus one which is
    // relevant for further configuration of the DMA. This is because the DMA API expects N minus
    // 1 and the source and end pointer need to point to the last transfer address.
    fn common_mem_transfer_checks(
        src_len: usize,
        dest_len: usize,
    ) -> Result<usize, DmaTransferInitError> {
        if src_len != dest_len {
            return Err(DmaTransferInitError::SourceDestLenMissmatch { src_len, dest_len });
        }
        if src_len > MAX_DMA_TRANSFERS_PER_CYCLE {
            return Err(DmaTransferInitError::TransferSizeTooLarge(src_len));
        }
        Ok(src_len - 1)
    }

    fn generic_mem_to_mem_transfer_init(
        &mut self,
        n_minus_one: usize,
        src_end_ptr: u32,
        dest_end_ptr: u32,
        data_size: DataSize,
        addr_incr: AddrIncrement,
    ) {
        self.ch_ctrl_pri.cfg = ChannelConfig::new_with_raw_value(0);
        self.ch_ctrl_pri.src_end_ptr = src_end_ptr;
        self.ch_ctrl_pri.dest_end_ptr = dest_end_ptr;
        self.ch_ctrl_pri.cfg.set_cycle_ctrl(CycleControl::Auto);
        self.ch_ctrl_pri.cfg.set_src_size(data_size);
        self.ch_ctrl_pri.cfg.set_src_inc(addr_incr);
        self.ch_ctrl_pri.cfg.set_dst_size(data_size);
        self.ch_ctrl_pri.cfg.set_dst_inc(addr_incr);
        self.ch_ctrl_pri
            .cfg
            .set_n_minus_1(u10::new(n_minus_one as u16));
        self.ch_ctrl_pri.cfg.set_r_power(RPower::Every4);
        self.select_primary_structure();
    }
}

impl Dma {
    /// Create a new DMA instance.
    ///
    /// You can also place the [DmaCtrlBlock] statically using a global static mutable
    /// instance and the [DmaCtrlBlock::new] const constructor This also allows to place the control
    /// block in a memory section using the [link_section](https://doc.rust-lang.org/reference/abi.html#the-link_section-attribute)
    /// attribute and then creating a mutable pointer to it using [core::ptr::addr_of_mut].
    ///
    /// Alternatively, the [DmaCtrlBlock::new_at_addr] function can be used to create the DMA
    /// control block at a specific address.
    pub fn new(
        dma: pac::Dma,
        cfg: DmaConfig,
        ctrl_block: *mut DmaCtrlBlock,
    ) -> Result<Self, InvalidCtrlBlockAddrError> {
        // The conversion to u32 is safe here because we are on a 32-bit system.
        let raw_addr = ctrl_block as u32;
        if raw_addr & BASE_PTR_ADDR_MASK > 0 {
            return Err(InvalidCtrlBlockAddrError);
        }
        enable_peripheral_clock(PeripheralSelect::Dma);
        reset_peripheral_for_cycles(PeripheralSelect::Dma, 2);
        let dma = Dma { dma, ctrl_block };
        dma.dma
            .ctrl_base_ptr()
            .write(|w| unsafe { w.bits(raw_addr) });
        dma.set_protection_bits(&cfg);
        dma.enable();
        Ok(dma)
    }

    #[inline(always)]
    pub fn enable(&self) {
        self.dma.cfg().write(|w| w.master_enable().set_bit());
    }

    #[inline(always)]
    pub fn disable(&self) {
        self.dma.cfg().write(|w| w.master_enable().clear_bit());
    }

    #[inline(always)]
    pub fn set_protection_bits(&self, cfg: &DmaConfig) {
        self.dma.cfg().write(|w| unsafe {
            w.chnl_prot_ctrl().bits(
                cfg.privileged as u8 | ((cfg.bufferable as u8) << 1) | ((cfg.cacheable as u8) << 2),
            )
        });
    }

    /// Split the DMA instance into four DMA channels which can be used individually. This allows
    /// using the inidividual DMA channels in separate tasks.
    pub fn split(self) -> (DmaChannel, DmaChannel, DmaChannel, DmaChannel) {
        // Safety: The DMA channel API only operates on its respective channels.
        (
            DmaChannel {
                channel: 0,
                done_interrupt: pac::Interrupt::DMA_DONE0,
                active_interrupt: pac::Interrupt::DMA_ACTIVE0,
                dma: unsafe { pac::Dma::steal() },
                ch_ctrl_pri: unsafe { &mut (*self.ctrl_block).pri[0] },
                ch_ctrl_alt: unsafe { &mut (*self.ctrl_block).alt[0] },
            },
            DmaChannel {
                channel: 1,
                done_interrupt: pac::Interrupt::DMA_DONE1,
                active_interrupt: pac::Interrupt::DMA_ACTIVE1,
                dma: unsafe { pac::Dma::steal() },
                ch_ctrl_pri: unsafe { &mut (*self.ctrl_block).pri[1] },
                ch_ctrl_alt: unsafe { &mut (*self.ctrl_block).alt[1] },
            },
            DmaChannel {
                channel: 2,
                done_interrupt: pac::Interrupt::DMA_DONE2,
                active_interrupt: pac::Interrupt::DMA_ACTIVE2,
                dma: unsafe { pac::Dma::steal() },
                ch_ctrl_pri: unsafe { &mut (*self.ctrl_block).pri[2] },
                ch_ctrl_alt: unsafe { &mut (*self.ctrl_block).alt[2] },
            },
            DmaChannel {
                channel: 3,
                done_interrupt: pac::Interrupt::DMA_DONE3,
                active_interrupt: pac::Interrupt::DMA_ACTIVE3,
                dma: unsafe { pac::Dma::steal() },
                ch_ctrl_pri: unsafe { &mut (*self.ctrl_block).pri[3] },
                ch_ctrl_alt: unsafe { &mut (*self.ctrl_block).alt[3] },
            },
        )
    }
}