etp 0.0.1-alpha

Embedded Tester Library (ETP). Control embedded devices from host!
Documentation
/// Utility functions for the project

/// Convert a vector of u32 values to a vector of bytes (little-endian)
/// For example, if the input is [1, 2, 3],
/// the output will be [1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0]
pub(crate) fn u32_vec_to_le_bytes(values: &[u32]) -> Vec<u8> {
    let mut result = Vec::new();
    for &value in values {
        result.extend_from_slice(&value.to_le_bytes());
    }
    result
}

/// Convert a mask to a vector of bits
/// For example, if the mask is 0b00000000000000000000000000001111,
/// the output will be [0, 1, 2, 3]
pub(crate) fn mask_to_bits(mask: u32) -> Vec<u8> {
    let mut bits = Vec::new();
    for i in 0..32 {
        if (mask >> i) & 1 == 1 {
            bits.push(i as u8);
        }
    }
    bits
}