|
| 1 | +from enum import Enum, unique |
| 2 | +from edgepi.reg_helper.reg_helper import OpCode |
| 3 | + |
| 4 | +@unique |
| 5 | +class GpioExpanderAdreess(Enum): |
| 6 | + EXP_ONE = 32 |
| 7 | + EXP_TWO = 33 |
| 8 | + |
| 9 | +@unique |
| 10 | +class GPIOAddresses(Enum): |
| 11 | + # Read addresses |
| 12 | + INPUT_PORT_0 = 0x00 |
| 13 | + INPUT_PORT_1 = 0x01 |
| 14 | + OUTPUT_PORT_0 = 0x02 |
| 15 | + OUTPUT_PORT_1 = 0x03 |
| 16 | + POLARITY_INVERSION_PORT_0 = 0x04 |
| 17 | + POLARITY_INVERSION_PORT_1 = 0x05 |
| 18 | + CONFIGURATION_PORT_0 = 0x06 |
| 19 | + CONFIGURATION_PORT_1 = 0x07 |
| 20 | + |
| 21 | +class BitMask(Enum): |
| 22 | + BIT0 = 0xFE |
| 23 | + BIT1 = 0xFD |
| 24 | + BIT2 = 0xFB |
| 25 | + BIT3 = 0xF7 |
| 26 | + BIT4 = 0xEF |
| 27 | + BIT5 = 0xDF |
| 28 | + BIT6 = 0xBF |
| 29 | + BIT7 = 0x7F |
| 30 | + BYTE = 0x00 |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +@unique |
| 35 | +class GpioAOutputSet(Enum): |
| 36 | + SET_OUTPUT_1 = OpCode(0x01, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT0.value) |
| 37 | + SET_OUTPUT_2 = OpCode(0x02, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT1.value) |
| 38 | + SET_OUTPUT_3 = OpCode(0x04, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT2.value) |
| 39 | + SET_OUTPUT_4 = OpCode(0x08, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT3.value) |
| 40 | + SET_OUTPUT_5 = OpCode(0x10, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT4.value) |
| 41 | + SET_OUTPUT_6 = OpCode(0x20, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT5.value) |
| 42 | + SET_OUTPUT_7 = OpCode(0x40, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT6.value) |
| 43 | + SET_OUTPUT_8 = OpCode(0x80, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT7.value) |
| 44 | + SET_OUTPUT_ALL = OpCode(0xFF, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BYTE.value) |
| 45 | + |
| 46 | + |
| 47 | +@unique |
| 48 | +class GpioAOutputClear(Enum): |
| 49 | + CLEAR_OUTPUT_1 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT0.value) |
| 50 | + CLEAR_OUTPUT_2 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT1.value) |
| 51 | + CLEAR_OUTPUT_3 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT2.value) |
| 52 | + CLEAR_OUTPUT_4 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT3.value) |
| 53 | + CLEAR_OUTPUT_5 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT4.value) |
| 54 | + CLEAR_OUTPUT_6 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT5.value) |
| 55 | + CLEAR_OUTPUT_7 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT6.value) |
| 56 | + CLEAR_OUTPUT_8 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT7.value) |
| 57 | + CLEAR_OUTPUT_ALL = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BYTE.value) |
| 58 | + |
| 59 | + |
| 60 | +@unique |
| 61 | +class GpioBOutputSet(Enum): |
| 62 | + SET_OUTPUT_1 = OpCode(0x01, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT0.value) |
| 63 | + SET_OUTPUT_2 = OpCode(0x02, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT1.value) |
| 64 | + SET_OUTPUT_3 = OpCode(0x04, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT2.value) |
| 65 | + SET_OUTPUT_4 = OpCode(0x08, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT3.value) |
| 66 | + SET_OUTPUT_5 = OpCode(0x10, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT4.value) |
| 67 | + SET_OUTPUT_6 = OpCode(0x20, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT5.value) |
| 68 | + SET_OUTPUT_7 = OpCode(0x40, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT6.value) |
| 69 | + SET_OUTPUT_8 = OpCode(0x80, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT7.value) |
| 70 | + SET_OUTPUT_ALL = OpCode(0xFF, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BYTE.value) |
| 71 | + |
| 72 | +@unique |
| 73 | +class GpioBOutputClear(Enum): |
| 74 | + CLEAR_OUTPUT_1 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT0.value) |
| 75 | + CLEAR_OUTPUT_2 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT1.value) |
| 76 | + CLEAR_OUTPUT_3 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT2.value) |
| 77 | + CLEAR_OUTPUT_4 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT3.value) |
| 78 | + CLEAR_OUTPUT_5 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT4.value) |
| 79 | + CLEAR_OUTPUT_6 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT5.value) |
| 80 | + CLEAR_OUTPUT_7 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT6.value) |
| 81 | + CLEAR_OUTPUT_8 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT7.value) |
| 82 | + CLEAR_OUTPUT_ALL = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BYTE.value) |
| 83 | + |
| 84 | +@unique |
| 85 | +class GpioAPinDir(Enum): |
| 86 | + PIN1_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT0.value) |
| 87 | + PIN2_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT1.value) |
| 88 | + PIN3_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT2.value) |
| 89 | + PIN4_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT3.value) |
| 90 | + PIN5_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT4.value) |
| 91 | + PIN6_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT5.value) |
| 92 | + PIN7_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT6.value) |
| 93 | + PIN8_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT7.value) |
| 94 | + ALL_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BYTE.value) |
| 95 | + |
| 96 | + PIN1_DIR_IN = OpCode(0x01, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT0.value) |
| 97 | + PIN2_DIR_IN = OpCode(0x02, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT1.value) |
| 98 | + PIN3_DIR_IN = OpCode(0x04, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT2.value) |
| 99 | + PIN4_DIR_IN = OpCode(0x08, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT3.value) |
| 100 | + PIN5_DIR_IN = OpCode(0x10, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT4.value) |
| 101 | + PIN6_DIR_IN = OpCode(0x20, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT5.value) |
| 102 | + PIN7_DIR_IN = OpCode(0x40, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT6.value) |
| 103 | + PIN8_DIR_IN = OpCode(0x80, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT7.value) |
| 104 | + ALL_DIR_IN = OpCode(0xFF, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BYTE.value) |
| 105 | + |
| 106 | +@unique |
| 107 | +class GpioBPinDir(Enum): |
| 108 | + PIN1_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT0.value) |
| 109 | + PIN2_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT1.value) |
| 110 | + PIN3_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT2.value) |
| 111 | + PIN4_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT3.value) |
| 112 | + PIN5_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT4.value) |
| 113 | + PIN6_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT5.value) |
| 114 | + PIN7_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT6.value) |
| 115 | + PIN8_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT7.value) |
| 116 | + ALL_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BYTE.value) |
| 117 | + |
| 118 | + |
| 119 | + PIN1_DIR_IN = OpCode(0x01, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT0.value) |
| 120 | + PIN2_DIR_IN = OpCode(0x02, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT1.value) |
| 121 | + PIN3_DIR_IN = OpCode(0x04, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT2.value) |
| 122 | + PIN4_DIR_IN = OpCode(0x08, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT3.value) |
| 123 | + PIN5_DIR_IN = OpCode(0x10, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT4.value) |
| 124 | + PIN6_DIR_IN = OpCode(0x20, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT5.value) |
| 125 | + PIN7_DIR_IN = OpCode(0x40, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT6.value) |
| 126 | + PIN8_DIR_IN = OpCode(0x80, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT7.value) |
| 127 | + ALL_DIR_IN = OpCode(0xFF, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BYTE.value) |
0 commit comments