use crate::yellow_blocks::Address;
use casperfpga_derive::address;
use packed_struct::prelude::*;
#[derive(Debug, PackedStruct, Default, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x00)]
pub struct Reset {
#[packed_field(bits = "0")]
pub(crate) reset: bool,
}
#[derive(Debug, PackedStruct, Default, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x0F)]
pub struct SleepPd {
#[packed_field(bits = "0..=3")]
pub(crate) sleep4: [bool; 4],
#[packed_field(bits = "4..=5")]
pub(crate) sleep2: [bool; 2],
#[packed_field(bits = "6")]
pub(crate) sleep1: bool,
#[packed_field(bits = "8")]
pub(crate) sleep: bool,
#[packed_field(bits = "9")]
pub(crate) pd: bool,
#[packed_field(bits = "10..=11", ty = "enum")]
pub(crate) pd_pin_cfg: PdPinCfg,
}
#[derive(Debug, PrimitiveEnum, Default, Copy, Clone)]
pub enum PdPinCfg {
SleepChannel = 1,
DeepSleep = 2,
#[default]
PowerDown = 0,
}
#[derive(Debug, PackedStruct, Default, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x12)]
pub struct LvdsDrives {
#[packed_field(bits = "0..=2", ty = "enum")]
pub(crate) ilvds_lclk: LvdsDriveStrength,
#[packed_field(bits = "4..=6", ty = "enum")]
pub(crate) ilvds_frame: LvdsDriveStrength,
#[packed_field(bits = "8..=10", ty = "enum")]
pub(crate) ilvds_dat: LvdsDriveStrength,
}
#[derive(Debug, PrimitiveEnum, Default, Copy, Clone)]
pub enum LvdsDriveStrength {
#[default]
_3_5 = 0,
_2_5 = 1,
_1_5 = 2,
_0_5 = 3,
_7_5 = 4,
_6_5 = 5,
_5_5 = 6,
_4_5 = 7,
}
#[derive(Debug, PackedStruct, Default, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x11)]
pub struct LvdsTerminations {
#[packed_field(bits = "14")]
pub(crate) en_lvds_term: bool,
#[packed_field(bits = "0..=2", ty = "enum")]
pub(crate) term_lclk: LvdsTermination,
#[packed_field(bits = "4..=6", ty = "enum")]
pub(crate) term_frame: LvdsTermination,
#[packed_field(bits = "8..=10", ty = "enum")]
pub(crate) term_dat: LvdsTermination,
}
#[derive(Debug, PrimitiveEnum, Default, Copy, Clone)]
pub enum LvdsTermination {
#[default]
Disabled = 0,
_260 = 1,
_150 = 2,
_94 = 3,
_125 = 4,
_80 = 5,
_66 = 6,
_55 = 7,
}
#[derive(Debug, PackedStruct, Default, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x24)]
pub struct InvertCtl {
#[packed_field(bits = "0..=3")]
pub(crate) invert4: [bool; 4],
#[packed_field(bits = "4..=5")]
pub(crate) invert2: [bool; 2],
#[packed_field(bits = "6")]
pub(crate) intert1: bool,
}
#[derive(Debug, PackedStruct, Default, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x25)]
pub struct PatternCtl {
#[packed_field(bits = "4..=6", ty = "enum")]
pub(crate) pattern: Pattern,
}
#[derive(Debug, PrimitiveEnum, Default, Copy, Clone)]
pub enum Pattern {
#[default]
Disabled = 0,
Ramp = 0b100,
DualCustom = 0b010,
SingleCustom = 0b001,
}
#[derive(Debug, PackedStruct, Default, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x26)]
pub struct CustomPattern1 {
#[packed_field(bits = "8..=15")]
pub(crate) bits_custom1: [bool; 8],
}
#[derive(Debug, PackedStruct, Default, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x27)]
pub struct CustomPattern2 {
#[packed_field(bits = "8..=15")]
pub(crate) bits_custom2: [bool; 8],
}
#[derive(Debug, PackedStruct, Default, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x2A)]
pub struct QuadCoarseGains {
#[packed_field(bits = "0..=3", ty = "enum")]
pub(crate) cgain4_ch1: CoarseGain,
#[packed_field(bits = "4..=7", ty = "enum")]
pub(crate) cgain4_ch2: CoarseGain,
#[packed_field(bits = "8..=11", ty = "enum")]
pub(crate) cgain4_ch3: CoarseGain,
#[packed_field(bits = "12..=15", ty = "enum")]
pub(crate) cgain4_ch4: CoarseGain,
}
#[derive(Debug, PackedStruct, Default, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x2B)]
pub struct DualCoarseGains {
#[packed_field(bits = "0..=3", ty = "enum")]
pub(crate) cgain2_ch1: CoarseGain,
#[packed_field(bits = "4..=7", ty = "enum")]
pub(crate) cgain2_ch2: CoarseGain,
#[packed_field(bits = "8..=11", ty = "enum")]
pub(crate) cgain1_ch1: CoarseGain,
}
#[derive(Debug, PrimitiveEnum, Default, Copy, Clone)]
pub enum CoarseGain {
#[default]
_0 = 0,
_1 = 1,
_2 = 2,
_3 = 3,
_4 = 4,
_5 = 5,
_6 = 6,
_7 = 7,
_8 = 8,
_9 = 9,
_10 = 10,
_11 = 11,
_12 = 12,
X50 = 13,
}
#[derive(Debug, PackedStruct, Default, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x30)]
pub struct JitterCtl {
#[packed_field(bits = "0..=7", ty = "enum")]
pub(crate) jitter_ctrl: Jitter,
}
#[derive(Debug, PrimitiveEnum, Default, Copy, Clone)]
pub enum Jitter {
_0 = 0,
#[default]
_1 = 0b0000_0001,
_2 = 0b0000_0011,
_3 = 0b0000_0111,
_4 = 0b0000_1111,
_5 = 0b0001_1111,
_6 = 0b0011_1111,
_7 = 0b0111_1111,
_8 = 0b1111_1111,
}
#[derive(Debug, PackedStruct, Default, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x31)]
pub struct ChanNumClkDiv {
#[packed_field(bits = "0..=2", ty = "enum")]
pub(crate) channel_num: ChannelNum,
#[packed_field(bits = "8..=9", ty = "enum")]
pub(crate) clk_divide: ClockDivide,
}
#[derive(Debug, PrimitiveEnum, Default, Copy, Clone)]
pub enum ChannelNum {
Single = 0b001,
Dual = 0b010,
#[default]
Quad = 0b100,
}
#[derive(Debug, PrimitiveEnum, Default, Copy, Clone)]
pub enum ClockDivide {
#[default]
_1 = 0,
_2 = 1,
_4 = 2,
_8 = 3,
}
#[derive(Debug, PackedStruct, Default, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x33)]
pub struct GainCtl {
#[packed_field(bits = "0")]
pub(crate) coarse_gain_cfg: bool,
#[packed_field(bits = "1")]
pub(crate) fine_gain_en: bool,
}
#[derive(Debug, PackedStruct, Default, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x34)]
pub struct FineGain12 {
#[packed_field(bits = "0..=6")]
pub(crate) fgain_branch1: Integer<i8, packed_bits::Bits<7>>,
#[packed_field(bits = "8..=14")]
pub(crate) fgain_branch2: Integer<i8, packed_bits::Bits<7>>,
}
#[derive(Debug, PackedStruct, Default, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x35)]
pub struct FineGain34 {
#[packed_field(bits = "0..=6")]
pub(crate) fgain_branch3: Integer<i8, packed_bits::Bits<7>>,
#[packed_field(bits = "8..=14")]
pub(crate) fgain_branch4: Integer<i8, packed_bits::Bits<7>>,
}
#[derive(Debug, PackedStruct, Default, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x36)]
pub struct FineGain56 {
#[packed_field(bits = "0..=6")]
pub(crate) fgain_branch5: Integer<i8, packed_bits::Bits<7>>,
#[packed_field(bits = "8..=14")]
pub(crate) fgain_branch6: Integer<i8, packed_bits::Bits<7>>,
}
#[derive(Debug, PackedStruct, Default, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x37)]
pub struct FineGain78 {
#[packed_field(bits = "0..=6")]
pub(crate) fgain_branch7: Integer<i8, packed_bits::Bits<7>>,
#[packed_field(bits = "8..=14")]
pub(crate) fgain_branch8: Integer<i8, packed_bits::Bits<7>>,
}
#[derive(Debug, PackedStruct, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x3A)]
pub struct InputSelect12 {
#[packed_field(bits = "0..=4", ty = "enum")]
pub(crate) inp_sel_adc1: InputSelect,
#[packed_field(bits = "8..=12", ty = "enum")]
pub(crate) inp_sel_adc2: InputSelect,
}
impl Default for InputSelect12 {
fn default() -> Self {
Self {
inp_sel_adc1: InputSelect::_1,
inp_sel_adc2: InputSelect::_2,
}
}
}
#[derive(Debug, PackedStruct, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x3B)]
pub struct InputSelect34 {
#[packed_field(bits = "0..=4", ty = "enum")]
pub(crate) inp_sel_adc3: InputSelect,
#[packed_field(bits = "8..=12", ty = "enum")]
pub(crate) inp_sel_adc4: InputSelect,
}
impl Default for InputSelect34 {
fn default() -> Self {
Self {
inp_sel_adc3: InputSelect::_3,
inp_sel_adc4: InputSelect::_4,
}
}
}
#[derive(Debug, PrimitiveEnum, Default, Copy, Clone)]
pub enum InputSelect {
#[default]
_1 = 0b00010,
_2 = 0b00100,
_3 = 0b01000,
_4 = 0b10000,
}
#[derive(Debug, PackedStruct, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x42)]
pub struct LclkPhase {
#[packed_field(bits = "5..=6", ty = "enum")]
pub(crate) phase_ddr: PhaseDdr,
}
#[derive(Debug, PrimitiveEnum, Default, Copy, Clone)]
pub enum PhaseDdr {
#[default]
_90 = 2,
_270 = 0,
_180 = 1,
_0 = 3,
}
#[derive(Debug, PackedStruct, Copy, Clone, Default)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x45)]
pub struct DeskewSyncPattern {
#[packed_field(bits = "0..=1", ty = "enum")]
pub(crate) pat_deskew_sync: DeskewSyncMode,
}
#[derive(Debug, PrimitiveEnum, Default, Copy, Clone)]
pub enum DeskewSyncMode {
#[default]
Disabled = 0,
Deskew = 1,
Sync = 2,
}
#[derive(Debug, PackedStruct, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x46)]
pub struct OutputMode {
#[packed_field(bits = "2")]
pub(crate) btc_mode: bool,
#[packed_field(bits = "3")]
pub(crate) msb_first: bool,
}
#[derive(Debug, PackedStruct, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x50)]
pub struct AdcCurrentVcmDrive {
#[packed_field(bits = "0..=2", ty = "enum")]
pub(crate) adc_curr: AdcCurrentControl,
#[packed_field(bits = "5..=6", ty = "enum")]
pub(crate) ext_vcm_bc: VcmBufferDrive,
}
#[derive(Debug, PrimitiveEnum, Default, Copy, Clone)]
pub enum AdcCurrentControl {
_40 = 0b100,
_30 = 0b101,
_20 = 0b110,
_10 = 0b111,
#[default]
_0 = 0b000,
}
#[derive(Debug, PrimitiveEnum, Default, Copy, Clone)]
pub enum VcmBufferDrive {
Off = 0b00,
#[default]
Pm20 = 0b01,
Pm400 = 0b10,
Pm700 = 0b11,
}
#[derive(Debug, PackedStruct, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x52)]
pub struct LvdsPowerDown {
#[packed_field(bits = "0")]
pub(crate) lvds_pd_mode: bool,
}
#[derive(Debug, PackedStruct, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x53)]
pub struct LvdsOutputControl {
#[packed_field(bits = "3")]
pub(crate) low_clk_freq: bool,
#[packed_field(bits = "4..=5", ty = "enum")]
pub(crate) lvds_shift: LvdsShift,
}
#[derive(Debug, PrimitiveEnum, Default, Copy, Clone)]
pub enum LvdsShift {
#[default]
Disabled = 0,
Delay = 0b10,
Advance = 0b01,
}
#[derive(Debug, PackedStruct, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x55)]
pub struct FullScaleRangeControl {
#[packed_field(bits = "0..=5")]
pub(crate) fs_cntrl: Integer<i8, packed_bits::Bits<6>>,
}
#[derive(Debug, PackedStruct, Copy, Clone)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "2")]
#[address(0x56)]
pub struct StartupControl {
#[packed_field(bits = "0..=2", ty = "enum")]
pub(crate) startup_ctrl: StartupTiming,
}
#[derive(Debug, PrimitiveEnum, Default, Copy, Clone)]
pub enum StartupTiming {
#[default]
Default = 0,
_100 = 0b100,
_001 = 0b001,
_101 = 0b101,
_011 = 0b011,
}