document and rearrange some stuff
This commit is contained in:
@ -128,7 +128,7 @@ class Charon:
|
||||
self.sdr.rx_hardwaregain_chan1 = 10
|
||||
self.sdr.tx_hardwaregain_chan0 = -10
|
||||
|
||||
# # switch control
|
||||
# switch control
|
||||
ctx = iio.Context(uri)
|
||||
self.ctrl = ctx.find_device("ad9361-phy")
|
||||
# raw ad9361 register accesss:
|
||||
@ -136,10 +136,13 @@ class Charon:
|
||||
# https://www.analog.com/media/cn/technical-documentation/user-guides/ad9364_register_map_reference_manual_ug-672.pdf # noqa: E501
|
||||
self.ctrl.reg_write(AD9361Register.EXTERNAL_LNA_CONTROL, 0x90) # bit 7: AuxDAC Manual, bit 4: GPO Manual
|
||||
self.ctrl.reg_write(AD9361Register.AUXDAC_ENABLE_CONTROL, 0x3F)
|
||||
|
||||
# initialize switch control outputs
|
||||
self._set_gpo(0b0000)
|
||||
self._set_dac_code(value=0, channel=1)
|
||||
self._set_dac_code(value=0, channel=2)
|
||||
|
||||
# set default switch state
|
||||
self.set_switches(a=0, b=0)
|
||||
|
||||
def get_config(self) -> Dict[str, Any]:
|
||||
@ -170,20 +173,15 @@ class Charon:
|
||||
def _set_gpo(self, value: int) -> None:
|
||||
self.ctrl.reg_write(AD9361Register.GPO_FORCE_AND_INIT, (value & 0x0F) << 4) # bits 7-4: GPO3-0
|
||||
|
||||
def _set_dac_voltage(self, voltage: float, channel: Literal[1, 2]):
|
||||
raise NotImplementedError()
|
||||
def _get_dac_code(self, channel: Literal[1, 2]) -> Tuple[float, AD9361DacVref, AD9361DacStepFactor]:
|
||||
word = self.ctrl.reg_read(AD9361Register.__getitem__(f"AUXDAC{channel}_WORD"))
|
||||
config = self.ctrl.reg_read(AD9361Register.__getitem__(f"AUXDAC{channel}_CONFIG"))
|
||||
|
||||
def set_switches(self, a: int, b: int, excitation: int | None = None):
|
||||
if excitation is None:
|
||||
excitation = a
|
||||
value = (word << 2) + (config & 0x3)
|
||||
vref = AD9361DacVref((config >> 2) & 0x3)
|
||||
step_factor = AD9361DacStepFactor((config >> 4) & 0x1)
|
||||
|
||||
val = 0
|
||||
|
||||
val |= int(bool(excitation)) << 0 # exc = GPO0
|
||||
val |= int(bool(a)) << 2 # a = GPO2
|
||||
val |= int(bool(b)) << 1 # b = GPO1
|
||||
|
||||
self._set_gpo(val)
|
||||
return (value, vref, step_factor)
|
||||
|
||||
def _set_dac_code(
|
||||
self,
|
||||
@ -217,18 +215,17 @@ class Charon:
|
||||
(value & 0x3) | (vref.value << 2) | (step_factor << 4),
|
||||
)
|
||||
|
||||
def _get_dac_code(self, channel: Literal[1, 2]) -> Tuple[float, AD9361DacVref, AD9361DacStepFactor]:
|
||||
word = self.ctrl.reg_read(AD9361Register.__getitem__(f"AUXDAC{channel}_WORD"))
|
||||
config = self.ctrl.reg_read(AD9361Register.__getitem__(f"AUXDAC{channel}_CONFIG"))
|
||||
def set_switches(self, b: int, a: int, excitation: int | None = None):
|
||||
if excitation is None:
|
||||
excitation = a
|
||||
|
||||
value = (word << 2) + (config & 0x3)
|
||||
vref = AD9361DacVref((config >> 2) & 0x3)
|
||||
step_factor = AD9361DacStepFactor((config >> 4) & 0x1)
|
||||
val = 0
|
||||
|
||||
return (value, vref, step_factor)
|
||||
val |= int(bool(excitation)) << 0 # exc = GPO0
|
||||
val |= int(bool(a)) << 2 # a = GPO2
|
||||
val |= int(bool(b)) << 1 # b = GPO1
|
||||
|
||||
def _get_dac_voltage(self) -> float:
|
||||
raise NotImplementedError()
|
||||
self._set_gpo(val)
|
||||
|
||||
def set_output_power(self, power: float):
|
||||
pout = xr.DataArray(
|
||||
@ -320,7 +317,7 @@ class Charon:
|
||||
s.loc[dict(frequency=frequency)] = self.get_b_over_a(frequency=frequency)
|
||||
return s
|
||||
|
||||
def vna_capture(self, frequency: npt.ArrayLike, callback: Callable[int, int] | None):
|
||||
def vna_capture(self, frequency: npt.ArrayLike, callback: Callable[int, int] | None = None):
|
||||
s = xr.DataArray(
|
||||
np.empty(len(frequency), dtype=np.complex128),
|
||||
dims=["frequency"],
|
||||
|
Reference in New Issue
Block a user