use core::convert::Infallible;
use regiface::{register, FromByteArray, ReadableRegister, ToByteArray, WritableRegister};
#[register(0x06B8u16)]
#[derive(Debug, Clone, Copy, ReadableRegister, WritableRegister)]
pub struct WhiteningInitialValue {
pub value: u16,
}
impl Default for WhiteningInitialValue {
fn default() -> Self {
Self { value: 0x0100 }
}
}
#[register(0x06BCu16)]
#[derive(Debug, Clone, Copy, ReadableRegister, WritableRegister)]
pub struct CrcInitialValue {
pub value: u16,
}
impl Default for CrcInitialValue {
fn default() -> Self {
Self { value: 0x1D0F }
}
}
#[register(0x06BEu16)]
#[derive(Debug, Clone, Copy, ReadableRegister, WritableRegister)]
pub struct CrcPolynomial {
pub value: u16,
}
impl Default for CrcPolynomial {
fn default() -> Self {
Self { value: 0x1021 }
}
}
#[register(0x06C0u16)]
#[derive(Debug, Clone, Copy, ReadableRegister, WritableRegister)]
pub struct SyncWord {
pub value: [u8; 8],
}
#[register(0x06CDu16)]
#[derive(Debug, Clone, Copy, ReadableRegister, WritableRegister, Default)]
pub struct NodeAddress {
pub address: u8,
}
#[register(0x06CEu16)]
#[derive(Debug, Clone, Copy, ReadableRegister, WritableRegister, Default)]
pub struct BroadcastAddress {
pub address: u8,
}
#[register(0x0736u16)]
#[derive(Debug, Clone, Copy, ReadableRegister, WritableRegister, Default)]
pub struct IqPolaritySetup {
pub inverted_iq: bool,
}
#[register(0x0740u16)]
#[derive(Debug, Clone, Copy, ReadableRegister, WritableRegister)]
pub struct LoraSyncWord {
pub value: u16,
}
impl Default for LoraSyncWord {
fn default() -> Self {
Self { value: 0x1424 }
}
}
impl FromByteArray for WhiteningInitialValue {
type Error = Infallible;
type Array = [u8; 2];
fn from_bytes(bytes: Self::Array) -> Result<Self, Self::Error> {
Ok(Self {
value: u16::from_be_bytes(bytes),
})
}
}
impl ToByteArray for WhiteningInitialValue {
type Error = Infallible;
type Array = [u8; 2];
fn to_bytes(self) -> Result<Self::Array, Self::Error> {
Ok(self.value.to_be_bytes())
}
}
impl FromByteArray for CrcInitialValue {
type Error = Infallible;
type Array = [u8; 2];
fn from_bytes(bytes: Self::Array) -> Result<Self, Self::Error> {
Ok(Self {
value: u16::from_be_bytes(bytes),
})
}
}
impl ToByteArray for CrcInitialValue {
type Error = Infallible;
type Array = [u8; 2];
fn to_bytes(self) -> Result<Self::Array, Self::Error> {
Ok(self.value.to_be_bytes())
}
}
impl FromByteArray for CrcPolynomial {
type Error = Infallible;
type Array = [u8; 2];
fn from_bytes(bytes: Self::Array) -> Result<Self, Self::Error> {
Ok(Self {
value: u16::from_be_bytes(bytes),
})
}
}
impl ToByteArray for CrcPolynomial {
type Error = Infallible;
type Array = [u8; 2];
fn to_bytes(self) -> Result<Self::Array, Self::Error> {
Ok(self.value.to_be_bytes())
}
}
impl FromByteArray for SyncWord {
type Error = Infallible;
type Array = [u8; 8];
fn from_bytes(bytes: Self::Array) -> Result<Self, Self::Error> {
Ok(Self { value: bytes })
}
}
impl ToByteArray for SyncWord {
type Error = Infallible;
type Array = [u8; 8];
fn to_bytes(self) -> Result<Self::Array, Self::Error> {
Ok(self.value)
}
}
impl FromByteArray for NodeAddress {
type Error = Infallible;
type Array = [u8; 1];
fn from_bytes(bytes: Self::Array) -> Result<Self, Self::Error> {
Ok(Self { address: bytes[0] })
}
}
impl ToByteArray for NodeAddress {
type Error = Infallible;
type Array = [u8; 1];
fn to_bytes(self) -> Result<Self::Array, Self::Error> {
Ok([self.address])
}
}
impl FromByteArray for BroadcastAddress {
type Error = Infallible;
type Array = [u8; 1];
fn from_bytes(bytes: Self::Array) -> Result<Self, Self::Error> {
Ok(Self { address: bytes[0] })
}
}
impl ToByteArray for BroadcastAddress {
type Error = Infallible;
type Array = [u8; 1];
fn to_bytes(self) -> Result<Self::Array, Self::Error> {
Ok([self.address])
}
}
impl FromByteArray for IqPolaritySetup {
type Error = Infallible;
type Array = [u8; 1];
fn from_bytes(bytes: Self::Array) -> Result<Self, Self::Error> {
Ok(Self {
inverted_iq: bytes[0] & 0x01 != 0,
})
}
}
impl ToByteArray for IqPolaritySetup {
type Error = Infallible;
type Array = [u8; 1];
fn to_bytes(self) -> Result<Self::Array, Self::Error> {
Ok([self.inverted_iq as u8])
}
}
impl FromByteArray for LoraSyncWord {
type Error = Infallible;
type Array = [u8; 2];
fn from_bytes(bytes: Self::Array) -> Result<Self, Self::Error> {
Ok(Self {
value: u16::from_be_bytes(bytes),
})
}
}
impl ToByteArray for LoraSyncWord {
type Error = Infallible;
type Array = [u8; 2];
fn to_bytes(self) -> Result<Self::Array, Self::Error> {
Ok(self.value.to_be_bytes())
}
}