Update I2C _wakeup to come out of power_down

`_wakeup` also puts the pn532 back into normal mode.
This commit is contained in:
George Waters 2020-08-30 21:18:10 -04:00
parent 790340eec2
commit cdedaf16b9
No known key found for this signature in database
GPG key ID: D993F8B1CC21DB25

View file

@ -41,7 +41,7 @@ import time
import adafruit_bus_device.i2c_device as i2c_device import adafruit_bus_device.i2c_device as i2c_device
from digitalio import Direction from digitalio import Direction
from micropython import const from micropython import const
from adafruit_pn532.adafruit_pn532 import PN532, BusyError, _reset from adafruit_pn532.adafruit_pn532 import PN532, BusyError
_I2C_ADDRESS = const(0x24) _I2C_ADDRESS = const(0x24)
@ -55,23 +55,23 @@ class PN532_I2C(PN532):
reset pin and debugging output. reset pin and debugging output.
""" """
self.debug = debug self.debug = debug
self._irq = irq
self._req = req self._req = req
if reset:
_reset(reset)
self._i2c = i2c_device.I2CDevice(i2c, _I2C_ADDRESS) self._i2c = i2c_device.I2CDevice(i2c, _I2C_ADDRESS)
super().__init__(debug=debug, reset=reset) super().__init__(debug=debug, irq=irq, reset=reset)
def _wakeup(self): # pylint: disable=no-self-use def _wakeup(self): # pylint: disable=no-self-use
"""Send any special commands/data to wake up PN532""" """Send any special commands/data to wake up PN532"""
if self._reset_pin:
self._reset_pin.value = True
time.sleep(0.01)
if self._req: if self._req:
self._req.direction = Direction.OUTPUT self._req.direction = Direction.OUTPUT
self._req.value = True
time.sleep(0.1)
self._req.value = False self._req.value = False
time.sleep(0.1) time.sleep(0.01)
self._req.value = True self._req.value = True
time.sleep(0.5) time.sleep(0.01)
self.low_power = False
self.SAM_configuration() # Put the PN532 back in normal mode
def _wait_ready(self, timeout=1): def _wait_ready(self, timeout=1):
"""Poll PN532 if status byte is ready, up to `timeout` seconds""" """Poll PN532 if status byte is ready, up to `timeout` seconds"""
@ -82,11 +82,10 @@ class PN532_I2C(PN532):
with self._i2c: with self._i2c:
self._i2c.readinto(status) self._i2c.readinto(status)
except OSError: except OSError:
self._wakeup()
continue continue
if status == b"\x01": if status == b"\x01":
return True # No longer busy return True # No longer busy
time.sleep(0.05) # lets ask again soon! time.sleep(0.01) # lets ask again soon!
# Timed out! # Timed out!
return False return False
@ -101,8 +100,6 @@ class PN532_I2C(PN532):
i2c.readinto(frame) # ok get the data, plus statusbyte i2c.readinto(frame) # ok get the data, plus statusbyte
if self.debug: if self.debug:
print("Reading: ", [hex(i) for i in frame[1:]]) print("Reading: ", [hex(i) for i in frame[1:]])
else:
time.sleep(0.1)
return frame[1:] # don't return the status byte return frame[1:] # don't return the status byte
def _write_data(self, framebytes): def _write_data(self, framebytes):