use crate::{command::WriteCommand, instr::Instr};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct NvmProgramSetting {
pa: u8,
pin: u8,
}
impl NvmProgramSetting {
pub const DEFAULT: Self = Self { pa: 0, pin: 0 };
pub const fn new(pa: u8, pin: u8) -> Self {
assert!(pa >> 6 == 0, "PA out of range");
Self { pa, pin }
}
const fn bytes(&self) -> [u8; 2] {
[self.pa, self.pin]
}
}
impl Default for NvmProgramSetting {
fn default() -> Self {
Self::DEFAULT
}
}
impl WriteCommand for NvmProgramSetting {
const OPCODE: Instr = Instr::NVMCTRL2;
type Params = [u8; 2];
fn params(&self) -> Self::Params {
self.bytes()
}
}
const _: () = assert!(matches!(NvmProgramSetting::DEFAULT.bytes(), [0x00, 0x00]));
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct NvmProgramEnable;
impl NvmProgramEnable {
const fn bytes(&self) -> [u8; 2] {
[0x29, 0xA5]
}
}
impl WriteCommand for NvmProgramEnable {
const OPCODE: Instr = Instr::NVMPROM;
type Params = [u8; 2];
fn params(&self) -> Self::Params {
self.bytes()
}
}
const _: () = assert!(matches!(NvmProgramEnable.bytes(), [0x29, 0xA5]));
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Id1Setting {
id: u8,
}
impl Id1Setting {
pub const DEFAULT: Self = Self { id: 0 };
pub const fn new(id: u8) -> Self {
Self { id }
}
}
impl Default for Id1Setting {
fn default() -> Self {
Self::DEFAULT
}
}
impl WriteCommand for Id1Setting {
const OPCODE: Instr = Instr::ID1SET;
type Params = [u8; 1];
fn params(&self) -> Self::Params {
[self.id]
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Id2Setting {
id: u8,
}
impl Id2Setting {
pub const DEFAULT: Self = Self { id: 0 };
pub const fn new(id: u8) -> Self {
Self { id }
}
}
impl Default for Id2Setting {
fn default() -> Self {
Self::DEFAULT
}
}
impl WriteCommand for Id2Setting {
const OPCODE: Instr = Instr::ID2SET;
type Params = [u8; 1];
fn params(&self) -> Self::Params {
[self.id]
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Id3Setting {
id: u8,
}
impl Id3Setting {
pub const DEFAULT: Self = Self { id: 0 };
pub const fn new(id: u8) -> Self {
Self { id }
}
}
impl Default for Id3Setting {
fn default() -> Self {
Self::DEFAULT
}
}
impl WriteCommand for Id3Setting {
const OPCODE: Instr = Instr::ID3SET;
type Params = [u8; 1];
fn params(&self) -> Self::Params {
[self.id]
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct ExtbControl {
extb_ctrl: ExtbCtrl,
}
impl ExtbControl {
pub const DEFAULT: Self = Self {
extb_ctrl: ExtbCtrl::Vdd,
};
pub const fn new(extb_ctrl: ExtbCtrl) -> Self {
Self { extb_ctrl }
}
const fn bytes(&self) -> [u8; 1] {
[self.extb_ctrl as u8]
}
}
impl Default for ExtbControl {
fn default() -> Self {
Self::DEFAULT
}
}
impl WriteCommand for ExtbControl {
const OPCODE: Instr = Instr::EXTBCTRL;
type Params = [u8; 1];
fn params(&self) -> Self::Params {
self.bytes()
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ExtbCtrl {
Vdd = 0x5A,
Vss = 0xA5,
}
const _: () = assert!(matches!(ExtbControl::DEFAULT.bytes(), [0x5A]));