|
40 | 40 |
|
41 | 41 | _ADDR2 = const(0x14) |
42 | 42 |
|
| 43 | +_USE_INTERRUPTS = False # Interrupt handler based? Or just polling? |
43 | 44 |
|
44 | 45 | class GT911(pointer_framework.PointerDriver): |
45 | 46 |
|
@@ -88,8 +89,10 @@ def __init__( |
88 | 89 | if isinstance(reset_pin, int): |
89 | 90 | reset_pin = machine.Pin(reset_pin, machine.Pin.OUT) |
90 | 91 |
|
91 | | - if isinstance(interrupt_pin, int): |
| 92 | + if isinstance(interrupt_pin, int) and _USE_INTERRUPTS: |
92 | 93 | interrupt_pin = machine.Pin(interrupt_pin, machine.Pin.IN) |
| 94 | + else: |
| 95 | + interrupt_pin = machine.Pin(interrupt_pin, machine.Pin.OUT) |
93 | 96 |
|
94 | 97 | self._reset_pin = reset_pin |
95 | 98 | self._interrupt_pin = interrupt_pin |
@@ -119,7 +122,7 @@ def hw_reset(self): |
119 | 122 | if self._interrupt_pin: |
120 | 123 | self._interrupt_pin(0) |
121 | 124 | time.sleep_ms(50) # NOQA |
122 | | - if self._interrupt_pin: |
| 125 | + if self._interrupt_pin and _USE_INTERRUPTS: |
123 | 126 | self._interrupt_pin.init(mode=self._interrupt_pin.IN) |
124 | 127 | time.sleep_ms(50) # NOQA |
125 | 128 |
|
@@ -150,7 +153,7 @@ def hw_reset(self): |
150 | 153 | print(f'Touch resolution: width={x}, height={y}') |
151 | 154 |
|
152 | 155 | # Set up interrupt handler if interrupt pin is available |
153 | | - if self._interrupt_pin: |
| 156 | + if self._interrupt_pin and _USE_INTERRUPTS: |
154 | 157 | self._interrupt_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler=self._interrupt_handler) |
155 | 158 | # Setting _MODULE_SWITCH_1 will "hang" the touch input after a second or 2 of initial swipe |
156 | 159 | #self._write_reg(_MODULE_SWITCH_1, _CMD_INT_FALLING_EDGE) # stops working |
@@ -181,11 +184,11 @@ def firmware_config(self): |
181 | 184 |
|
182 | 185 | def _get_coords(self): |
183 | 186 | # If interrupt pin is available, only fetch data when interrupt flag is set |
184 | | - if self._interrupt_pin and not self._interrupt_flag: |
| 187 | + if self._interrupt_pin and not self._interrupt_flag and _USE_INTERRUPTS: |
185 | 188 | return self.__last_state, self.__x, self.__y |
186 | 189 |
|
187 | 190 | # Clear interrupt flag before reading |
188 | | - if self._interrupt_pin: |
| 191 | + if self._interrupt_pin and _USE_INTERRUPTS: |
189 | 192 | self._interrupt_flag = False |
190 | 193 | #self._write_reg(_MODULE_SWITCH_1, _CMD_INT_FALLING_EDGE) |
191 | 194 | #print("[GT911] Interrupt-triggered read") |
|
0 commit comments