opentitanlib/test_utils/bitbanging/
mod.rs

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
// Copyright lowRISC contributors (OpenTitan project).
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

pub mod i2c;
pub mod pwm;
pub mod spi;
pub mod uart;

use serde::{Deserialize, Serialize};

#[repr(u8)]
#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize)]
pub enum Bit {
    Low = 0,
    High = 1,
}

impl From<bool> for Bit {
    fn from(val: bool) -> Self {
        if val { Self::High } else { Self::Low }
    }
}

impl From<u8> for Bit {
    fn from(val: u8) -> Self {
        match val {
            0x00 => Self::Low,
            _ => Self::High,
        }
    }
}