]> Repositories - Adafruit_Blinka-hackapet.git/blob - src/adafruit_blinka/microcontroller/generic_micropython/i2c.py
Fix mpsse/pin.py formatting
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / generic_micropython / i2c.py
1 """I2C Class for Generic MicroPython"""
2 from machine import I2C as _I2C
3
4
5 class I2C:
6     """I2C Class for Generic MicroPython"""
7
8     MASTER = 0
9
10     # pylint: disable=unused-argument
11     def __init__(self, portId, *, mode=MASTER, baudrate=100000):
12         self._i2c = _I2C(portId, freq=baudrate)
13
14     def scan(self):
15         """Perform an I2C Device Scan"""
16         return self._i2c.scan()
17
18     def writeto(self, address, buffer, *, stop=True):
19         """Write the data from the buffer to the address"""
20         return self._i2c.writeto(address, buffer)
21
22     def readfrom_into(self, address, buffer, *, stop=True):
23         """Read data from an address and into the buffer"""
24         return self._i2c.readfrom_into(address, buffer)
25
26     def writeto_then_readfrom(
27         self,
28         address,
29         buffer_out,
30         buffer_in,
31         *,
32         out_start=0,
33         out_end=None,
34         in_start=0,
35         in_end=None,
36         stop=False
37     ):
38         """Write data from buffer_out to an address and then
39         read data from an address and into buffer_in
40         """
41         self._i2c.writeto_then_readfrom(
42             address,
43             buffer_out,
44             buffer_in,
45             out_start=out_start,
46             out_end=out_end,
47             in_start=in_start,
48             in_end=in_end,
49         )
50
51     # pylint: enable=unused-argument