更新UCD-API库及文档
This commit is contained in:
2
UniTAP/dev/ports/modules/earc/__init__.py
Normal file
2
UniTAP/dev/ports/modules/earc/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from .earc_types import EarcMode
|
||||
from .earc_tx import EarcTx
|
||||
83
UniTAP/dev/ports/modules/earc/earc_tx.py
Normal file
83
UniTAP/dev/ports/modules/earc/earc_tx.py
Normal file
@@ -0,0 +1,83 @@
|
||||
from ctypes import c_ubyte
|
||||
|
||||
from UniTAP.dev.ports.modules.ag.earc import AudioGeneratorEARC
|
||||
from UniTAP.dev.modules.memory_manager import MemoryManager
|
||||
from UniTAP.libs.lib_tsi.tsi_io import PortIO
|
||||
|
||||
import UniTAP.libs.lib_tsi.tsi_private_types as p_ci
|
||||
import UniTAP.libs.lib_tsi.tsi_types as ci
|
||||
|
||||
from .earc_types import EarcControl, EarcMode, EarcStatus, EarcState, EarcHearthbeatState, EarcRxStatus
|
||||
|
||||
class EarcTx:
|
||||
__MAX_EARC_EDID_SIZE = 128
|
||||
|
||||
def __init__(self, port_io: PortIO, memory_manager: MemoryManager) -> None:
|
||||
self.__io = port_io
|
||||
self.__earc_ag = AudioGeneratorEARC(port_io, memory_manager)
|
||||
self.__control = self.__io.get(ci.TSI_HDRX_EARC_CTRL, EarcControl)[1]
|
||||
|
||||
def configure(self, mode: EarcMode, latency: int, bypass: bool = False) -> None:
|
||||
self.__control.mode = mode
|
||||
self.__control.bypass = bypass
|
||||
self.__apply_control()
|
||||
self.__set_audio_latency(latency)
|
||||
|
||||
def get_status(self) -> EarcStatus:
|
||||
"""
|
||||
Get eARC transmitter status.
|
||||
|
||||
Returns:
|
||||
object of `EarcStatus` type.
|
||||
"""
|
||||
return self.__io.get(ci.TSI_HDRX_EARC_STS_R, EarcStatus)[1]
|
||||
|
||||
def get_latency(self) -> int:
|
||||
"""
|
||||
Get current audio latency for eARC transmitter.
|
||||
|
||||
Returns:
|
||||
object of `int` type.
|
||||
"""
|
||||
return self.__io.get(ci.TSI_HDRX_EARC_LATENCY, int)[1]
|
||||
|
||||
def get_edid(self) -> bytearray:
|
||||
"""
|
||||
Get EDID data from eARC receiver.
|
||||
|
||||
Returns:
|
||||
object of `bytearray` type.
|
||||
"""
|
||||
result, edid_data, size = self.__io.get(ci.TSI_HDRX_EARC_EDID_DATA, c_ubyte, self.__MAX_EARC_EDID_SIZE)
|
||||
if result > 0:
|
||||
return bytearray(edid_data[:result])
|
||||
else:
|
||||
return bytearray()
|
||||
|
||||
@property
|
||||
def ag(self) -> AudioGeneratorEARC:
|
||||
"""
|
||||
Get audio generator for eARC transmitter.
|
||||
|
||||
Returns:
|
||||
object of `AudioGeneratorEARC` type.
|
||||
"""
|
||||
return self.__earc_ag
|
||||
|
||||
def __apply_control(self):
|
||||
"""
|
||||
Apply eARC control settings.
|
||||
"""
|
||||
self.__io.set(ci.TSI_HDRX_EARC_CTRL, self.__control)
|
||||
|
||||
def __set_audio_latency(self, latency: int):
|
||||
"""
|
||||
Set audio latency request for eARC transmitter.
|
||||
|
||||
Args:
|
||||
latency (int) - latency value to set
|
||||
"""
|
||||
self.__io.set(ci.TSI_HDRX_EARC_LATENCY_REQ, latency)
|
||||
|
||||
|
||||
|
||||
112
UniTAP/dev/ports/modules/earc/earc_types.py
Normal file
112
UniTAP/dev/ports/modules/earc/earc_types.py
Normal file
@@ -0,0 +1,112 @@
|
||||
from enum import IntEnum
|
||||
from ctypes import c_uint32, Structure
|
||||
|
||||
from UniTAP.utils.bit_ops import get_bitfield, set_bitfield
|
||||
|
||||
class EarcMode(IntEnum):
|
||||
"""
|
||||
Describes possible eArc modes.
|
||||
"""
|
||||
Disabled = 0
|
||||
eArc = 1
|
||||
Legacy = 2
|
||||
eArcNone = 3
|
||||
|
||||
class EarcState(IntEnum):
|
||||
"""
|
||||
Describes possible eArc states.
|
||||
"""
|
||||
H14bARC = 0
|
||||
IDLE1 = 1
|
||||
IDLE2 = 2
|
||||
DISC1 = 3
|
||||
DISC2 = 4
|
||||
EARC = 5
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.name
|
||||
|
||||
class EarcHearthbeatState(IntEnum):
|
||||
"""
|
||||
Describes possible eArc states.
|
||||
"""
|
||||
LOST = 0
|
||||
SUCCESS = 1
|
||||
FAIL = 2
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.name
|
||||
|
||||
class EarcRxStatus(IntEnum):
|
||||
"""
|
||||
Describes possible eArc RX statuses.
|
||||
"""
|
||||
INVALID = 0
|
||||
STAT_CHNG = 1
|
||||
CAP_CHNG = 2
|
||||
EARC_HPD = 4
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.name
|
||||
|
||||
class EarcStatus(Structure):
|
||||
__EARC_STATE_OFFSET = 0
|
||||
__EARC_STATE_MASK = 0xF << __EARC_STATE_OFFSET
|
||||
|
||||
__EARC_HEARTHBEAT_OFFSET = 4
|
||||
__EARC_HEARTHBEAT_MASK = 0xF << __EARC_HEARTHBEAT_OFFSET
|
||||
|
||||
__EARC_RX_STATUS_OFFSET = 8
|
||||
__EARC_RX_STATUS_MASK = 0xF << __EARC_RX_STATUS_OFFSET
|
||||
|
||||
_fields_ = [
|
||||
('data', c_uint32, 32)
|
||||
]
|
||||
|
||||
def __init__(self, value: int) -> None:
|
||||
self.data = value
|
||||
|
||||
@property
|
||||
def earc_state(self) -> EarcState:
|
||||
return EarcState(get_bitfield(self.data, self.__EARC_STATE_MASK, self.__EARC_STATE_OFFSET))
|
||||
|
||||
@property
|
||||
def earc_hearthbeat(self) -> EarcHearthbeatState:
|
||||
return EarcHearthbeatState(get_bitfield(self.data, self.__EARC_HEARTHBEAT_MASK, self.__EARC_HEARTHBEAT_OFFSET))
|
||||
|
||||
@property
|
||||
def earc_rx_status(self) -> EarcRxStatus:
|
||||
return EarcRxStatus(get_bitfield(self.data, self.__EARC_RX_STATUS_MASK, self.__EARC_RX_STATUS_OFFSET))
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"EarcStatus(state={self.earc_state}, heartbeat={self.earc_hearthbeat}, rx_status={self.earc_rx_status})"
|
||||
|
||||
class EarcControl(Structure):
|
||||
__EARC_MODE_OFFSET = 0
|
||||
__EARC_MODE_MASK = 0x7 << __EARC_MODE_OFFSET
|
||||
|
||||
__EARC_BYPASS_OFFSET = 3
|
||||
__EARC_BYPASS_MASK = 0x1 << __EARC_BYPASS_OFFSET
|
||||
|
||||
_fields_ = [
|
||||
('data', c_uint32, 32)
|
||||
]
|
||||
|
||||
def __init__(self, value: int) -> None:
|
||||
self.data = value
|
||||
|
||||
@property
|
||||
def mode(self) -> EarcMode:
|
||||
return EarcMode(get_bitfield(self.data, self.__EARC_MODE_MASK, self.__EARC_MODE_OFFSET))
|
||||
|
||||
@mode.setter
|
||||
def mode(self, value: EarcMode):
|
||||
self.data = set_bitfield(self.data, self.__EARC_MODE_MASK, self.__EARC_MODE_OFFSET, value.value)
|
||||
|
||||
@property
|
||||
def bypass(self) -> bool:
|
||||
return bool(get_bitfield(self.data, self.__EARC_BYPASS_MASK, self.__EARC_BYPASS_OFFSET))
|
||||
|
||||
@bypass.setter
|
||||
def bypass(self, value: bool):
|
||||
self.data = set_bitfield(self.data, self.__EARC_BYPASS_MASK, self.__EARC_BYPASS_OFFSET, int(value))
|
||||
Reference in New Issue
Block a user