]> Repositories - Adafruit_Blinka-hackapet.git/commitdiff
Run black check with target-version=py35
authorFrancis Guevarra <francis@binho.io>
Mon, 29 Jun 2020 00:06:13 +0000 (17:06 -0700)
committerFrancis Guevarra <francis@binho.io>
Mon, 29 Jun 2020 00:06:13 +0000 (17:06 -0700)
src/adafruit_blinka/microcontroller/nova/i2c.py
src/adafruit_blinka/microcontroller/nova/spi.py

index 5c1ecb1b4612f1f14d057f0b646e3f9e14450fd9..f05660817b3f36eba990b8c1d6fd1eeb59cbe95d 100644 (file)
@@ -5,6 +5,7 @@ from adafruit_blinka.microcontroller.nova import Connection
 
 class I2C:
     """Custom I2C Class for Binho Nova"""
+
     WHR_PAYLOAD_MAX_LENGTH = 1024
 
     def __init__(self, *, frequency=400000):
@@ -47,21 +48,20 @@ class I2C:
             for i in range(chunks):
                 chunk_start = start + i * self.WHR_PAYLOAD_MAX_LENGTH
                 chunk_end = chunk_start + self.WHR_PAYLOAD_MAX_LENGTH
-                self._nova.writeToReadFromI2C(0,
-                                              address<<1,
-                                              stop,
-                                              readBytes,
-                                              chunk_end-chunk_start,
-                                              buffer[chunk_start:chunk_end])
+                self._nova.writeToReadFromI2C(
+                    0,
+                    address << 1,
+                    stop,
+                    readBytes,
+                    chunk_end - chunk_start,
+                    buffer[chunk_start:chunk_end],
+                )
             if rest:
-                self._nova.writeToReadFromI2C(0,
-                                              address<<1,
-                                              stop,
-                                              readBytes,
-                                              rest,
-                                              buffer[-1*rest:])
+                self._nova.writeToReadFromI2C(
+                    0, address << 1, stop, readBytes, rest, buffer[-1 * rest :]
+                )
         else:
-            self._nova.startI2C(0, address<<1)
+            self._nova.startI2C(0, address << 1)
 
             for i in range(start, end):
                 self._nova.writeByteI2C(0, buffer[i])
@@ -88,16 +88,16 @@ class I2C:
             )
 
     def writeto_then_readfrom(
-            self,
-            address,
-            buffer_out,
-            buffer_in,
-            *,
-            out_start=0,
-            out_end=None,
-            in_start=0,
-            in_end=None,
-            stop=False
+        self,
+        address,
+        buffer_out,
+        buffer_in,
+        *,
+        out_start=0,
+        out_end=None,
+        in_start=0,
+        in_end=None,
+        stop=False
     ):
         """Write data from buffer_out to an address and then
         read data from an address and into buffer_in
@@ -124,18 +124,15 @@ class I2C:
                     numOutBytes = totalOut
 
                 # setup the buffer out chunk offset
-                buffer = '0'
+                buffer = "0"
                 if numOutBytes > 0:
                     chunk_start = out_start + i * self.WHR_PAYLOAD_MAX_LENGTH
                     chunk_end = chunk_start + numOutBytes
                     buffer = buffer_out[chunk_start:chunk_end]
 
-                result = self._nova.writeToReadFromI2C(0,
-                                                       address<<1,
-                                                       stop,
-                                                       numInBytes,
-                                                       numOutBytes,
-                                                       buffer)
+                result = self._nova.writeToReadFromI2C(
+                    0, address << 1, stop, numInBytes, numOutBytes, buffer
+                )
                 totalIn -= numInBytes
                 totalOut -= numOutBytes
 
@@ -145,13 +142,15 @@ class I2C:
                         resp = resp[2]
 
                         for j in range(numInBytes):
-                            buffer_in[in_start+i*self.WHR_PAYLOAD_MAX_LENGTH+j] = \
-                                                                     int(resp[j*2]+resp[j*2+1], 16)
+                            buffer_in[
+                                in_start + i * self.WHR_PAYLOAD_MAX_LENGTH + j
+                            ] = int(resp[j * 2] + resp[j * 2 + 1], 16)
                 else:
-                    raise RuntimeError("Received error response from Binho Nova, result = " + \
-                                       result)
+                    raise RuntimeError(
+                        "Received error response from Binho Nova, result = " + result
+                    )
         else:
-            self._nova.startI2C(0, address<<1)
+            self._nova.startI2C(0, address << 1)
 
             for i in range(out_start, out_end):
                 self._nova.writeByteI2C(0, buffer_out[i])
@@ -161,15 +160,19 @@ class I2C:
             else:
                 self._nova.endI2C(0, True)
 
-            result = self._nova.readBytesI2C(0, address<<1, len(buffer_in[in_start:in_end]))
+            result = self._nova.readBytesI2C(
+                0, address << 1, len(buffer_in[in_start:in_end])
+            )
 
             if result != "-NG":
                 resp = result.split(" ")
 
                 for i in range(len(buffer_in[in_start:in_end])):
-                    buffer_in[in_start+i] = int(resp[2+i])
+                    buffer_in[in_start + i] = int(resp[2 + i])
             else:
                 raise RuntimeError(
                     "Received error response from Binho Nova, result = " + result
                 )
+
+
 # pylint: enable=unused-argument
index d22be37aefe77fce093459d5bd7bab42c9046b0e..c9f49a441ed1ff1a157bb27a64f449cf0c5b27bd 100644 (file)
@@ -37,15 +37,15 @@ class SPI:
 
     # pylint: disable=too-many-arguments,unused-argument
     def init(
-            self,
-            baudrate=1000000,
-            polarity=0,
-            phase=0,
-            bits=8,
-            firstbit=MSB,
-            sck=None,
-            mosi=None,
-            miso=None,
+        self,
+        baudrate=1000000,
+        polarity=0,
+        phase=0,
+        bits=8,
+        firstbit=MSB,
+        sck=None,
+        mosi=None,
+        miso=None,
     ):
         """Initialize the Port"""
         self._nova.setClockSPI(0, baudrate)
@@ -75,11 +75,9 @@ class SPI:
             chunk_start = start + i * payloadMaxLength
             chunk_end = chunk_start + payloadMaxLength
             if int(self._novaCMDVer) >= 1:
-                self._nova.writeToReadFromSPI(0,
-                                              True,
-                                              False,
-                                              chunk_end - chunk_start,
-                                              buf[chunk_start:chunk_end])
+                self._nova.writeToReadFromSPI(
+                    0, True, False, chunk_end - chunk_start, buf[chunk_start:chunk_end]
+                )
             else:
                 self._nova.clearBuffer(0)
                 self._nova.writeToBuffer(0, 0, buf[chunk_start:chunk_end])
@@ -101,43 +99,49 @@ class SPI:
             for i in range(chunks):
                 chunk_start = start + i * self.WHR_PAYLOAD_MAX_LENGTH
                 chunk_end = chunk_start + self.WHR_PAYLOAD_MAX_LENGTH
-                result = self._nova.writeToReadFromSPI(0,
-                                                       False,
-                                                       True,
-                                                       chunk_end - chunk_start,
-                                                       write_value)
+                result = self._nova.writeToReadFromSPI(
+                    0, False, True, chunk_end - chunk_start, write_value
+                )
                 if result != "-NG":
                     resp = result.split(" ")
                     resp = resp[2]
                     # loop over half of resp len as we're reading 2 chars at a time to form a byte
-                    loops = int(len(resp)/2)
+                    loops = int(len(resp) / 2)
                     for j in range(loops):
-                        buf[(i*self.WHR_PAYLOAD_MAX_LENGTH)+start+j] = \
-                                                        int(resp[j*2]+resp[j*2+1], 16)
+                        buf[(i * self.WHR_PAYLOAD_MAX_LENGTH) + start + j] = int(
+                            resp[j * 2] + resp[j * 2 + 1], 16
+                        )
                 else:
-                    raise RuntimeError("Received error response from Binho Nova, result = " + \
-                                       result)
+                    raise RuntimeError(
+                        "Received error response from Binho Nova, result = " + result
+                    )
             if rest:
-                result = self._nova.writeToReadFromSPI(0, False, True, rest, write_value)
+                result = self._nova.writeToReadFromSPI(
+                    0, False, True, rest, write_value
+                )
                 if result != "-NG":
                     resp = result.split(" ")
                     resp = resp[2]
 
                     # loop over half of resp len as we're reading 2 chars at a time to form a byte
-                    loops = int(len(resp)/2)
+                    loops = int(len(resp) / 2)
                     for j in range(loops):
-                        buf[(i*self.WHR_PAYLOAD_MAX_LENGTH)+start+j] = \
-                                                         int(resp[j*2]+resp[j*2+1], 16)
+                        buf[(i * self.WHR_PAYLOAD_MAX_LENGTH) + start + j] = int(
+                            resp[j * 2] + resp[j * 2 + 1], 16
+                        )
                 else:
-                    raise RuntimeError("Received error response from Binho Nova, result = " + \
-                                       result)
+                    raise RuntimeError(
+                        "Received error response from Binho Nova, result = " + result
+                    )
         else:
             for i in range(start, end):
-                buf[start+i] = int(self.get_received_data(self._nova.transferSPI(0, write_value)))
+                buf[start + i] = int(
+                    self.get_received_data(self._nova.transferSPI(0, write_value))
+                )
 
     # pylint: disable=too-many-arguments
     def write_readinto(
-            self, buffer_out, buffer_in, out_start=0, out_end=None, in_start=0, in_end=None
+        self, buffer_out, buffer_in, out_start=0, out_end=None, in_start=0, in_end=None
     ):
         """Perform a half-duplex write from buffer_out and then
         read data into buffer_in
@@ -158,43 +162,54 @@ class SPI:
             for i in range(chunks):
                 chunk_start = out_start + i * self.WHR_PAYLOAD_MAX_LENGTH
                 chunk_end = chunk_start + self.WHR_PAYLOAD_MAX_LENGTH
-                result = self._nova.writeToReadFromSPI(0,
-                                                       True,
-                                                       True,
-                                                       chunk_end-chunk_start,
-                                                       buffer_out[chunk_start:chunk_end])
+                result = self._nova.writeToReadFromSPI(
+                    0,
+                    True,
+                    True,
+                    chunk_end - chunk_start,
+                    buffer_out[chunk_start:chunk_end],
+                )
 
                 if result != "-NG":
                     resp = result.split(" ")
                     resp = resp[2]
 
                     # loop over half of resp len as we're reading 2 chars at a time to form a byte
-                    loops = int(len(resp)/2)
+                    loops = int(len(resp) / 2)
                     for j in range(loops):
-                        buffer_in[(i*self.WHR_PAYLOAD_MAX_LENGTH)+in_start+j] = \
-                                                                 int(resp[j*2]+resp[j*2+1], 16)
+                        buffer_in[
+                            (i * self.WHR_PAYLOAD_MAX_LENGTH) + in_start + j
+                        ] = int(resp[j * 2] + resp[j * 2 + 1], 16)
                 else:
-                    raise RuntimeError("Received error response from Binho Nova, result = " + \
-                                       result)
+                    raise RuntimeError(
+                        "Received error response from Binho Nova, result = " + result
+                    )
             if rest:
-                result = self._nova.writeToReadFromSPI(0, True, True, rest, buffer_out[-1*rest:])
+                result = self._nova.writeToReadFromSPI(
+                    0, True, True, rest, buffer_out[-1 * rest :]
+                )
                 if result != "-NG":
                     resp = result.split(" ")
                     resp = resp[2]
 
                     # loop over half of resp len as we're reading 2 chars at a time to form a byte
-                    loops = int(len(resp)/2)
+                    loops = int(len(resp) / 2)
                     for j in range(loops):
-                        buffer_in[(i*self.WHR_PAYLOAD_MAX_LENGTH)+in_start+j] = \
-                                                                 int(resp[j*2]+resp[j*2+1], 16)
+                        buffer_in[
+                            (i * self.WHR_PAYLOAD_MAX_LENGTH) + in_start + j
+                        ] = int(resp[j * 2] + resp[j * 2 + 1], 16)
                 else:
-                    raise RuntimeError("Received error response from Binho Nova, result = " + \
-                                       result)
+                    raise RuntimeError(
+                        "Received error response from Binho Nova, result = " + result
+                    )
             print(buffer_in)
         else:
             for data_out in buffer_out:
-                data_in = int(self.get_received_data(self._nova.transferSPI(0, data_out)))
+                data_in = int(
+                    self.get_received_data(self._nova.transferSPI(0, data_out))
+                )
                 if i < readlen:
-                    buffer_in[in_start+i] = data_in
+                    buffer_in[in_start + i] = data_in
                 i += 1
+
     # pylint: enable=too-many-arguments