Coverage for tropicsquare / config / gpo.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-03-27 21:24 +0000

1"""GPO configuration (CFG_GPO @ 0x14)""" 

2 

3from tropicsquare.config.base import BaseConfig 

4from tropicsquare.config.constants import GPO_FUNC_MASK, GPO_FUNC_POS 

5 

6 

7class GpoConfig(BaseConfig): 

8 """General Purpose Output configuration register. 

9 

10 Controls the function of the GPO pin. 

11 

12 Fields: 

13 gpo_func: GPO function selection (bits 2-0, 3-bit value) 

14 """ 

15 

16 @property 

17 def gpo_func(self) -> int: 

18 """GPO function selection (3-bit value). 

19 

20 :returns: Function code (0-7) 

21 """ 

22 return (self._value >> GPO_FUNC_POS) & GPO_FUNC_MASK 

23 

24 @gpo_func.setter 

25 def gpo_func(self, value: int) -> None: 

26 """Set GPO function. 

27 

28 :param value: Function code (0-7) 

29 

30 :raises ValueError: If value is out of range 

31 """ 

32 if not 0 <= value <= 7: 

33 raise ValueError("gpo_func must be 0-7, got {}".format(value)) 

34 # Clear existing bits and set new value 

35 self._value = (self._value & ~(GPO_FUNC_MASK << GPO_FUNC_POS)) | (value << GPO_FUNC_POS) 

36 

37 def to_dict(self) -> dict: 

38 """Export fields as dictionary. 

39 

40 :returns: Configuration fields and their values 

41 """ 

42 return { 

43 'gpo_func': self.gpo_func 

44 } 

45 

46 def __str__(self) -> str: 

47 """Human-readable representation.""" 

48 return "GpoConfig(gpo_func={})".format(self.gpo_func)