# Path: src/uio/ti/eirq.py
# class EIrq( ctypes.Structure ):
#     _fields_ = [
#             ("enabled", ushort),    #rw
#             ("pending", ushort),    #r-
#             ("_clear",  ushort),    #-c
#             ("_set",    ushort),    #-s
#         ]
# 
#     def clear( self, bits, *, eoi=False ):
#         if eoi:
#             bits |= 1
#         self._clear = bits
#         self._clear  # ocp barrier
#         if bits & 1 and hasattr( self, 'uio' ):
#             self.uio.irq_enable()
# 
#     def set( self, bits ):
#         self._set = bits
# 
#     def enable( self, bits ):
#         self.enabled |= bits
#         if hasattr( self, 'uio' ):
#             self.uio.irq_enable()
# 
#     def disable( self, bits ):
#         self.enabled &= ~bits
# 
#     @property
#     def active( self ):
#         return self.enabled & self.pending
# 
#     def recv( self ):
#         if hasattr( self, 'uio' ):
#             self.uio.irq_recv()
#         events = self.active
#         self.clear( events, eoi=True )
#         return events
# 
#     def reset( self ):
#         self.enabled = 0
#         self.clear( 0xffff )


from uio.utils import fix_ctypes_struct
from ctypes import c_uint8 as ubyte, c_uint16 as ushort, c_uint32 as uint
from .eirq import EIrq
import ctypes

pos_t = uint    # position counter
tim_t = uint    # unit timer
wdt_t = ushort  # watchdog timer
imt_t = ushort  # interval measurement timer

@fix_ctypes_struct
class EQep( ctypes.Structure ):
    _fields_ = [
            #-------- position counter --------------------------------------------
            #
            ("position",        pos_t),     #<w
            ("ld_position",     pos_t),     #rw  loaded into position on strobe/index if enabled
            ("maximum",         pos_t),     #rw  = period - 1

# Path: src/uio/ti/eirq.py
# class EIrq( ctypes.Structure ):
#     _fields_ = [
#             ("enabled", ushort),    #rw
#             ("pending", ushort),    #r-
#             ("_clear",  ushort),    #-c
#             ("_set",    ushort),    #-s
#         ]
# 
#     def clear( self, bits, *, eoi=False ):
#         if eoi:
#             bits |= 1
#         self._clear = bits
#         self._clear  # ocp barrier
#         if bits & 1 and hasattr( self, 'uio' ):
#             self.uio.irq_enable()
# 
#     def set( self, bits ):
#         self._set = bits
# 
#     def enable( self, bits ):
#         self.enabled |= bits
#         if hasattr( self, 'uio' ):
#             self.uio.irq_enable()
# 
#     def disable( self, bits ):
#         self.enabled &= ~bits
# 
#     @property
#     def active( self ):
#         return self.enabled & self.pending
# 
#     def recv( self ):
#         if hasattr( self, 'uio' ):
#             self.uio.irq_recv()
#         events = self.active
#         self.clear( events, eoi=True )
#         return events
# 
#     def reset( self ):
#         self.enabled = 0
#         self.clear( 0xffff )


# Path: src/uio/ti/eqep.py
from uio.utils import fix_ctypes_struct
from ctypes import c_uint8 as ubyte, c_uint16 as ushort, c_uint32 as uint
from .eirq import EIrq
import ctypes


pos_t = uint    # position counter
tim_t = uint    # unit timer
wdt_t = ushort  # watchdog timer
imt_t = ushort  # interval measurement timer

@fix_ctypes_struct
class EQep( ctypes.Structure ):
    _fields_ = [
            #-------- position counter --------------------------------------------
            #
            ("position",        pos_t),     #<w
            ("ld_position",     pos_t),     #rw  loaded into position on strobe/index if enabled
            ("maximum",         pos_t),     #rw  = period - 1

            ("compare",         pos_t),     #rw  (may be ld_compare depending on config)