rp2350 0.1.0

Hardware Abstraction Layer for RP2350 microcontrollers
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
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
//! Hardware Interpolator (INTERP) driver for RP2350
//!
//! Each core has two interpolators (INTERP0 and INTERP1) that accelerate
//! fixed-point linear interpolation in hardware. Each interpolator has two
//! lanes (lane 0 and lane 1) that can operate independently or together.
//!
//! # Data Path
//!
//! Each lane computes per cycle:
//!
//! ```text
//! raw     = (accumulator >>> SHIFT) & mask[MASK_LSB..MASK_MSB]
//! result  = BASE + sign_extend(raw)
//! ```
//!
//! The key feature is the **POP** operation: reading a lane result
//! automatically writes both lane results back to the accumulators,
//! enabling iterative computation without CPU intervention.
//!
//! # Special Modes
//!
//! - **INTERP0 lane 0**: BLEND mode — linear interpolation between BASE0 and
//!   BASE1, controlled by lane 1's low 8 bits.
//! - **INTERP1 lane 0**: CLAMP mode — result is clamped to [BASE0, BASE1].
//!
//! # RP2350 vs RP2040
//!
//! On RP2350 the SHIFT operation is a **right rotate**. On RP2040 it is a
//! logical right shift.
//!
//! # Usage
//!
//! ```ignore
//! use rp2350::interp::{Interp0, Config};
//!
//! let interp0 = Interp0::init();
//!
//! // Configure lane 0: no shift, all bits pass, signed
//! let mut cfg = Config::new();
//! cfg.set_shift(0).set_mask(0, 31).set_signed(true);
//! interp0.lane0().configure(&cfg);
//!
//! // Set up a linear ramp
//! interp0.set_base(0, 0);
//! interp0.set_accumulator(0, 0);
//!
//! // Each POP advances via result feedback
//! let v0 = interp0.pop_lane(0); // → 0
//! let v1 = interp0.pop_lane(0); // → 1
//! ```

use crate::Steal;

// ============================================================================
// Interp0 / Interp1 handles
// ============================================================================

/// Handle to INTERP0 (interpolator 0) on the current core.
///
/// INTERP0 lane 0 supports **BLEND** mode for hardware linear interpolation.
///
/// Obtain a handle through [`Interp0::init()`] (main context) or
/// [`Interp0::steal()`] (ISR context).
pub struct Interp0 {
    _private: (),
}

/// Handle to INTERP1 (interpolator 1) on the current core.
///
/// INTERP1 lane 0 supports **CLAMP** mode for hardware value clamping.
///
/// Obtain a handle through [`Interp1::init()`] (main context) or
/// [`Interp1::steal()`] (ISR context).
pub struct Interp1 {
    _private: (),
}

impl Interp0 {
    /// Create an INTERP0 handle.
    ///
    /// The interpolator is part of SIO and requires no reset sequence.
    /// This constructor is safe.
    #[inline]
    pub fn init() -> Self {
        Interp0 { _private: () }
    }

    /// Obtain an INTERP0 handle without runtime checks.
    ///
    /// # Safety
    ///
    /// The caller must ensure no other code concurrently accesses the same
    /// interpolator registers. Typically called once at startup before
    /// interrupts are enabled.
    #[inline]
    pub unsafe fn steal() -> Steal<Interp0> {
        Steal(Interp0::init())
    }
}

impl Interp1 {
    /// Create an INTERP1 handle.
    ///
    /// The interpolator is part of SIO and requires no reset sequence.
    /// This constructor is safe.
    #[inline]
    pub fn init() -> Self {
        Interp1 { _private: () }
    }

    /// Obtain an INTERP1 handle without runtime checks.
    ///
    /// # Safety
    ///
    /// The caller must ensure no other code concurrently accesses the same
    /// interpolator registers. Typically called once at startup before
    /// interrupts are enabled.
    #[inline]
    pub unsafe fn steal() -> Steal<Interp1> {
        Steal(Interp1::init())
    }
}

// ============================================================================
// Trait for shared Interp0/Interp1 dispatch
// ============================================================================

pub trait InterpIndex {
    fn index() -> usize;
}

impl InterpIndex for Interp0 {
    #[inline]
    fn index() -> usize {
        0
    }
}
impl InterpIndex for Interp1 {
    #[inline]
    fn index() -> usize {
        1
    }
}

// ============================================================================
// Macro: dispatch to the correct PAC register for (interp_idx, lane)
// ============================================================================

/// Dispatches (interp, lane) → correct PAC register field and runs the
/// expression `$expr` with the register bound to `reg`.
///
/// Each PAC register type (Interp0Accum0, Interp0Accum1, Interp1Accum0, …)
/// is a distinct Rust type, but they all implement `Deref<Target =
/// VolatileCell<u32>>` so `reg.read_bits()` / `reg.write_bits(val)` works
/// uniformly.
macro_rules! with_interp_reg {
    // Accumulator registers (2 interps × 2 lanes = 4 variants)
    ($idx:expr, $lane:expr, accum, $reg:ident, $expr:expr) => {{
        let r = unsafe { &*crate::sio::REGS };
        debug_assert!(matches!($idx, 0 | 1), "interp index must be 0 or 1");
        debug_assert!(matches!($lane, 0 | 1), "interp lane must be 0 or 1");
        match ($idx, $lane) {
            (0, 0) => {
                let $reg = &r.interp0_accum0;
                $expr
            }
            (0, 1) => {
                let $reg = &r.interp0_accum1;
                $expr
            }
            (1, 0) => {
                let $reg = &r.interp1_accum0;
                $expr
            }
            _ => {
                let $reg = &r.interp1_accum1;
                $expr
            }
        }
    }};
    // Base registers (2 interps × 3 bases = 6 variants)
    ($idx:expr, $base:expr, base, $reg:ident, $expr:expr) => {{
        let r = unsafe { &*crate::sio::REGS };
        debug_assert!(matches!($idx, 0 | 1), "interp index must be 0 or 1");
        debug_assert!(matches!($base, 0..=2), "interp base must be 0..=2");
        match ($idx, $base) {
            (0, 0) => {
                let $reg = &r.interp0_base0;
                $expr
            }
            (0, 1) => {
                let $reg = &r.interp0_base1;
                $expr
            }
            (0, _) => {
                let $reg = &r.interp0_base2;
                $expr
            }
            (1, 0) => {
                let $reg = &r.interp1_base0;
                $expr
            }
            (1, 1) => {
                let $reg = &r.interp1_base1;
                $expr
            }
            _ => {
                let $reg = &r.interp1_base2;
                $expr
            }
        }
    }};
    // Pop lane (2 interps × 2 lanes = 4)
    ($idx:expr, $lane:expr, pop_lane, $reg:ident, $expr:expr) => {{
        let r = unsafe { &*crate::sio::REGS };
        debug_assert!(matches!($idx, 0 | 1), "interp index must be 0 or 1");
        debug_assert!(matches!($lane, 0 | 1), "interp lane must be 0 or 1");
        match ($idx, $lane) {
            (0, 0) => {
                let $reg = &r.interp0_pop_lane0;
                $expr
            }
            (0, 1) => {
                let $reg = &r.interp0_pop_lane1;
                $expr
            }
            (1, 0) => {
                let $reg = &r.interp1_pop_lane0;
                $expr
            }
            _ => {
                let $reg = &r.interp1_pop_lane1;
                $expr
            }
        }
    }};
    // Peek lane (2 interps × 2 lanes = 4)
    ($idx:expr, $lane:expr, peek_lane, $reg:ident, $expr:expr) => {{
        let r = unsafe { &*crate::sio::REGS };
        debug_assert!(matches!($idx, 0 | 1), "interp index must be 0 or 1");
        debug_assert!(matches!($lane, 0 | 1), "interp lane must be 0 or 1");
        match ($idx, $lane) {
            (0, 0) => {
                let $reg = &r.interp0_peek_lane0;
                $expr
            }
            (0, 1) => {
                let $reg = &r.interp0_peek_lane1;
                $expr
            }
            (1, 0) => {
                let $reg = &r.interp1_peek_lane0;
                $expr
            }
            _ => {
                let $reg = &r.interp1_peek_lane1;
                $expr
            }
        }
    }};
    // Pop full (2 interps)
    ($idx:expr, pop_full, $reg:ident, $expr:expr) => {{
        let r = unsafe { &*crate::sio::REGS };
        debug_assert!(matches!($idx, 0 | 1), "interp index must be 0 or 1");
        match $idx {
            0 => {
                let $reg = &r.interp0_pop_full;
                $expr
            }
            _ => {
                let $reg = &r.interp1_pop_full;
                $expr
            }
        }
    }};
    // Peek full (2 interps)
    ($idx:expr, peek_full, $reg:ident, $expr:expr) => {{
        let r = unsafe { &*crate::sio::REGS };
        debug_assert!(matches!($idx, 0 | 1), "interp index must be 0 or 1");
        match $idx {
            0 => {
                let $reg = &r.interp0_peek_full;
                $expr
            }
            _ => {
                let $reg = &r.interp1_peek_full;
                $expr
            }
        }
    }};
    // Control registers (2 interps × 2 lanes = 4)
    ($idx:expr, $lane:expr, ctrl, $reg:ident, $expr:expr) => {{
        let r = unsafe { &*crate::sio::REGS };
        debug_assert!(matches!($idx, 0 | 1), "interp index must be 0 or 1");
        debug_assert!(matches!($lane, 0 | 1), "interp lane must be 0 or 1");
        match ($idx, $lane) {
            (0, 0) => {
                let $reg = &r.interp0_ctrl_lane0;
                $expr
            }
            (0, 1) => {
                let $reg = &r.interp0_ctrl_lane1;
                $expr
            }
            (1, 0) => {
                let $reg = &r.interp1_ctrl_lane0;
                $expr
            }
            _ => {
                let $reg = &r.interp1_ctrl_lane1;
                $expr
            }
        }
    }};
    // Add raw registers (2 interps × 2 lanes = 4)
    ($idx:expr, $lane:expr, add_raw, $reg:ident, $expr:expr) => {{
        let r = unsafe { &*crate::sio::REGS };
        debug_assert!(matches!($idx, 0 | 1), "interp index must be 0 or 1");
        debug_assert!(matches!($lane, 0 | 1), "interp lane must be 0 or 1");
        match ($idx, $lane) {
            (0, 0) => {
                let $reg = &r.interp0_accum0_add;
                $expr
            }
            (0, 1) => {
                let $reg = &r.interp0_accum1_add;
                $expr
            }
            (1, 0) => {
                let $reg = &r.interp1_accum0_add;
                $expr
            }
            _ => {
                let $reg = &r.interp1_accum1_add;
                $expr
            }
        }
    }};
}

// ============================================================================
// Common interpolator operations (Interp0 / Interp1)
// ============================================================================

/// Operations common to both INTERP0 and INTERP1.
pub trait InterpOps: InterpIndex {
    /// Access lane 0 of this interpolator.
    #[inline]
    fn lane0(&self) -> Lane {
        Lane {
            interp: Self::index(),
            lane: 0,
        }
    }

    /// Access lane 1 of this interpolator.
    #[inline]
    fn lane1(&self) -> Lane {
        Lane {
            interp: Self::index(),
            lane: 1,
        }
    }

    /// Set the accumulator for a lane (0 or 1).
    #[inline]
    fn set_accumulator(&self, lane: usize, value: u32) {
        with_interp_reg!(Self::index(), lane, accum, reg, reg.write_bits(value));
    }

    /// Get the current accumulator value for a lane.
    #[inline]
    fn accumulator(&self, lane: usize) -> u32 {
        with_interp_reg!(Self::index(), lane, accum, reg, reg.read_bits())
    }

    /// Set a base register (0=BASE0, 1=BASE1, 2=BASE2).
    #[inline]
    fn set_base(&self, base_idx: usize, value: u32) {
        with_interp_reg!(Self::index(), base_idx, base, reg, reg.write_bits(value));
    }

    /// Get the current value of a base register.
    #[inline]
    fn base(&self, base_idx: usize) -> u32 {
        with_interp_reg!(Self::index(), base_idx, base, reg, reg.read_bits())
    }

    /// Set BASE0 (lower 16 bits) and BASE1 (upper 16 bits) simultaneously.
    /// Each half is sign-extended to 32 bits if that lane's SIGNED flag is set.
    #[inline]
    fn set_base_both(&self, value: u32) {
        let r = unsafe { &*crate::sio::REGS };
        if Self::index() == 0 {
            r.interp0_base_1and0.write_bits(value);
        } else {
            r.interp1_base_1and0.write_bits(value);
        }
    }

    /// Pop lane result — reads the result and feeds it back to both accumulators.
    #[inline]
    fn pop_lane(&self, lane: usize) -> u32 {
        with_interp_reg!(Self::index(), lane, pop_lane, reg, reg.read_bits())
    }

    /// Peek lane result — reads without altering internal state.
    #[inline]
    fn peek_lane(&self, lane: usize) -> u32 {
        with_interp_reg!(Self::index(), lane, peek_lane, reg, reg.read_bits())
    }

    /// Pop FULL result: `BASE2 + lane0_raw + lane1_raw`, with feedback.
    #[inline]
    fn pop_full(&self) -> u32 {
        with_interp_reg!(Self::index(), pop_full, reg, reg.read_bits())
    }

    /// Peek FULL result: read without feedback.
    #[inline]
    fn peek_full(&self) -> u32 {
        with_interp_reg!(Self::index(), peek_full, reg, reg.read_bits())
    }

    /// Atomically add a value to a lane's accumulator.
    #[inline]
    fn add_accumulator(&self, lane: usize, value: u32) {
        with_interp_reg!(Self::index(), lane, add_raw, reg, reg.write_bits(value));
    }

    /// Get the raw shift+mask value for a lane (BASE not added).
    #[inline]
    fn raw(&self, lane: usize) -> u32 {
        with_interp_reg!(Self::index(), lane, add_raw, reg, reg.read_bits())
    }

    /// Save the full interpolator state for later restore.
    #[inline]
    fn save(&self) -> State {
        State {
            accum: [self.accumulator(0), self.accumulator(1)],
            base: [self.base(0), self.base(1), self.base(2)],
            ctrl: [
                with_interp_reg!(Self::index(), 0, ctrl, reg, reg.read_bits()),
                with_interp_reg!(Self::index(), 1, ctrl, reg, reg.read_bits()),
            ],
        }
    }

    /// Restore previously saved state.
    #[inline]
    fn restore(&self, state: &State) {
        self.set_accumulator(0, state.accum[0]);
        self.set_accumulator(1, state.accum[1]);
        self.set_base(0, state.base[0]);
        self.set_base(1, state.base[1]);
        self.set_base(2, state.base[2]);
        with_interp_reg!(Self::index(), 0, ctrl, reg, reg.write_bits(state.ctrl[0]));
        with_interp_reg!(Self::index(), 1, ctrl, reg, reg.write_bits(state.ctrl[1]));
    }

    /// Set the FORCE_MSB bits for a lane (ORed into result bits 29:28 on bus).
    #[inline]
    fn set_force_bits(&self, lane: usize, bits: u8) {
        assert!(bits <= 3);
        const MASK: u32 = rp2350_pac::sio::Interp0CtrlLane0::FORCE_MSB_MASK;
        const OFFSET: u32 = rp2350_pac::sio::Interp0CtrlLane0::FORCE_MSB_OFFSET;
        with_interp_reg!(Self::index(), lane, ctrl, reg, {
            let val = reg.read_bits();
            reg.write_bits((val & !MASK) | (((bits as u32) << OFFSET) & MASK));
        });
    }
}

impl InterpOps for Interp0 {}
impl InterpOps for Interp1 {}

// ============================================================================
// Saved state
// ============================================================================

/// Snapshot of an interpolator's complete register state.
#[derive(Clone, Debug)]
pub struct State {
    pub accum: [u32; 2],
    pub base: [u32; 3],
    pub ctrl: [u32; 2],
}

// ============================================================================
// Lane-level operations
// ============================================================================

/// Accessor for a single lane of an interpolator.
pub struct Lane {
    interp: usize,
    lane: usize,
}

impl Lane {
    /// Get this lane's index (0 or 1).
    #[inline]
    pub fn index(&self) -> usize {
        self.lane
    }

    /// Apply configuration to this lane.
    ///
    /// # Panics
    ///
    /// Panics if BLEND is set on a non-INTERP0 lane 0, or CLAMP is set on a
    /// non-INTERP1 lane 0.
    #[inline]
    pub fn configure(&self, config: &Config) {
        if config.ctrl & rp2350_pac::sio::Interp0CtrlLane0::BLEND != 0 {
            assert!(
                self.interp == 0 && self.lane == 0,
                "BLEND only valid on INTERP0 lane 0"
            );
        }
        if config.ctrl & rp2350_pac::sio::Interp1CtrlLane0::CLAMP != 0 {
            assert!(
                self.interp == 1 && self.lane == 0,
                "CLAMP only valid on INTERP1 lane 0"
            );
        }
        with_interp_reg!(
            self.interp,
            self.lane,
            ctrl,
            reg,
            reg.write_bits(config.ctrl)
        );
    }

    /// Read the current control register value.
    #[inline]
    pub fn read_ctrl(&self) -> u32 {
        with_interp_reg!(self.interp, self.lane, ctrl, reg, reg.read_bits())
    }
}

// ============================================================================
// Configuration
// ============================================================================

/// Interpolator lane configuration.
///
/// Build with [`Config::new()`], then apply with [`Lane::configure()`].
#[derive(Clone, Debug)]
pub struct Config {
    ctrl: u32,
}

impl Config {
    /// Create a default configuration (all 32 bits pass through, no shift).
    #[inline]
    pub fn new() -> Self {
        let mut c = Config { ctrl: 0 };
        c.set_mask(0, 31);
        c
    }

    /// Set the right-rotate shift applied to the accumulator before masking.
    /// RP2350 uses right **rotate** (not logical shift like RP2040).
    #[inline]
    pub fn set_shift(&mut self, shift: u8) -> &mut Self {
        assert!(shift < 32);
        const M: u32 = rp2350_pac::sio::Interp0CtrlLane0::SHIFT_MASK;
        const O: u32 = rp2350_pac::sio::Interp0CtrlLane0::SHIFT_OFFSET;
        self.ctrl = (self.ctrl & !M) | (((shift as u32) << O) & M);
        self
    }

    #[inline]
    pub fn set_mask(&mut self, mask_lsb: u8, mask_msb: u8) -> &mut Self {
        assert!(mask_msb < 32 && mask_lsb <= mask_msb);
        const LM: u32 = rp2350_pac::sio::Interp0CtrlLane0::MASK_LSB_MASK;
        const LO: u32 = rp2350_pac::sio::Interp0CtrlLane0::MASK_LSB_OFFSET;
        const MM: u32 = rp2350_pac::sio::Interp0CtrlLane0::MASK_MSB_MASK;
        const MO: u32 = rp2350_pac::sio::Interp0CtrlLane0::MASK_MSB_OFFSET;
        self.ctrl = (self.ctrl & !(LM | MM))
            | (((mask_lsb as u32) << LO) & LM)
            | (((mask_msb as u32) << MO) & MM);
        self
    }

    #[inline]
    pub fn set_signed(&mut self, signed: bool) -> &mut Self {
        if signed {
            self.ctrl |= rp2350_pac::sio::Interp0CtrlLane0::SIGNED;
        } else {
            self.ctrl &= !rp2350_pac::sio::Interp0CtrlLane0::SIGNED;
        }
        self
    }

    #[inline]
    pub fn set_cross_input(&mut self, cross: bool) -> &mut Self {
        if cross {
            self.ctrl |= rp2350_pac::sio::Interp0CtrlLane0::CROSS_INPUT;
        } else {
            self.ctrl &= !rp2350_pac::sio::Interp0CtrlLane0::CROSS_INPUT;
        }
        self
    }

    #[inline]
    pub fn set_cross_result(&mut self, cross: bool) -> &mut Self {
        if cross {
            self.ctrl |= rp2350_pac::sio::Interp0CtrlLane0::CROSS_RESULT;
        } else {
            self.ctrl &= !rp2350_pac::sio::Interp0CtrlLane0::CROSS_RESULT;
        }
        self
    }

    #[inline]
    pub fn set_add_raw(&mut self, add_raw: bool) -> &mut Self {
        if add_raw {
            self.ctrl |= rp2350_pac::sio::Interp0CtrlLane0::ADD_RAW;
        } else {
            self.ctrl &= !rp2350_pac::sio::Interp0CtrlLane0::ADD_RAW;
        }
        self
    }

    /// Enable BLEND mode (**INTERP0 lane 0 only**).
    #[inline]
    pub fn set_blend(&mut self, blend: bool) -> &mut Self {
        if blend {
            self.ctrl |= rp2350_pac::sio::Interp0CtrlLane0::BLEND;
        } else {
            self.ctrl &= !rp2350_pac::sio::Interp0CtrlLane0::BLEND;
        }
        self
    }

    /// Enable CLAMP mode (**INTERP1 lane 0 only**).
    #[inline]
    pub fn set_clamp(&mut self, clamp: bool) -> &mut Self {
        if clamp {
            self.ctrl |= rp2350_pac::sio::Interp1CtrlLane0::CLAMP;
        } else {
            self.ctrl &= !rp2350_pac::sio::Interp1CtrlLane0::CLAMP;
        }
        self
    }

    /// Set FORCE_MSB bits (ORed into result bits 29:28 on the bus).
    #[inline]
    pub fn set_force_bits(&mut self, bits: u8) -> &mut Self {
        assert!(bits <= 3);
        const M: u32 = rp2350_pac::sio::Interp0CtrlLane0::FORCE_MSB_MASK;
        const O: u32 = rp2350_pac::sio::Interp0CtrlLane0::FORCE_MSB_OFFSET;
        self.ctrl = (self.ctrl & !M) | (((bits as u32) << O) & M);
        self
    }
}

impl Default for Config {
    #[inline]
    fn default() -> Self {
        Config::new()
    }
}