]> Repositories - Adafruit_Blinka-hackapet.git/blobdiff - src/adafruit_blinka/microcontroller/generic_agnostic_board/pin.py
add pixels
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / generic_agnostic_board / pin.py
index fbe74ec056f088af7599bf45fb2a2af0ea1589fa..5830c30ef601bf17f6f52b6ef3892c0fdf082b99 100644 (file)
@@ -4,7 +4,7 @@
 """generic_agnostic_board pin interface"""
 import random
 
-# Values for sine wave analog output
+# Values for sine wave
 # (data points = 20, amplitude=100, frequency=1)
 sine_wave = [
     0,
@@ -29,31 +29,32 @@ sine_wave = [
     -31,
 ]
 
-# Values for a square wave analog output
+# Values for a sawtooth wave
 # (data points = 20, amplitude=100)
-square_wave_int = [
-    100,
-    -100,
-    100,
-    -100,
-    100,
-    -100,
-    100,
-    -100,
-    100,
+sawtooth_wave = [
     -100,
-    100,
-    -100,
-    100,
-    -100,
-    100,
-    -100,
-    100,
+    -80,
+    -60,
+    -40,
+    -20,
+    0,
+    20,
+    40,
+    60,
+    80,
     -100,
-    100,
-    -100
+    -80,
+    -60,
+    -40,
+    -20,
+    0,
+    20,
+    40,
+    60,
+    80,
 ]
 
+
 class Pin:
     """A basic Pin class for use with generic_agnostic_board"""
 
@@ -70,6 +71,8 @@ class Pin:
     PULL_UP = 1
     PULL_DOWN = 2
 
+    # pylint: disable=no-self-use
+
     def return_toggle(self):
         """Returns the pin's expected value, toggling between True and False"""
         toggle_state = not self.previous_value
@@ -99,13 +102,13 @@ class Pin:
             self._wave_idx = (self._wave_idx + 1) % len(sine_wave)
         return sine_wave[self._wave_idx]
 
-    def return_square_wave(self):
-        """Returns the next value in the square wave"""
+    def return_sawtooth_wave(self):
+        """Returns the next value in the sawtooth wave"""
         if self._wave_idx is None:
             self._wave_idx = 0
         else:
-            self._wave_idx = (self._wave_idx + 1) % len(square_wave_int)
-        return square_wave_int[self._wave_idx]
+            self._wave_idx = (self._wave_idx + 1) % len(sawtooth_wave)
+        return sawtooth_wave[self._wave_idx]
 
     def __init__(self, pin_id=None):
         self.id = pin_id
@@ -124,9 +127,9 @@ class Pin:
             4: self.return_true,  # Dx_OUTPUT
             7: self.return_random_int,  # Ax_INPUT_RAND_INT
             8: self.return_fixed_int_pi,  # Ax_INPUT_FIXED_INT_PI
-            9: self.return_sine_wave,  # Ax_OUTPUT_WAVE_SINE
-            10: self.return_square_wave,  # Ax_OUTPUT_WAVE_SAWTOOTH
-            11: self.return_toggle  # Dx_INPUT_TOGGLE
+            9: self.return_sine_wave,  # Ax_INPUT_WAVE_SINE
+            10: self.return_sawtooth_wave,  # Ax_INPUT_WAVE_SAW
+            11: self.return_toggle,  # Dx_INPUT_TOGGLE
         }
 
     def init(self, mode=IN, pull=None):
@@ -149,10 +152,10 @@ class Pin:
         self.current_value = self.pin_behavior.get(self.id)()
 
         # is pin a pull up and pin is LOW?
-        if self._pull == Pin.PULL_UP and self.current_value == False:
+        if self._pull == Pin.PULL_UP and self.current_value is False:
             self.current_value = False
         # is pin a pull down and pin is HIGH?
-        if self._pull == Pin.PULL_DOWN and self.current_value == True:
+        if self._pull == Pin.PULL_DOWN and self.current_value is True:
             self.current_value = False
         return self.current_value
 
@@ -177,8 +180,8 @@ class Pin:
         # Analog Out
         if self._mode == Pin.DAC:
             if val is None:
-                # write only
-                raise AttributeError("unreadable attribute")
+                self.previous_value = self.current_value
+                return self.current_value
             self.write(val)
             return None
         raise RuntimeError(
@@ -199,8 +202,12 @@ A0 = Pin(7)
 A1 = Pin(8)
 A2 = Pin(9)
 A3 = Pin(10)
+A4 = Pin(12)
 
+# Special digital pins for pixels
 D7 = Pin(11)
+D8 = Pin(13)
+D9 = Pin(14)
 
 # I2C pins
 SDA = Pin()
@@ -213,6 +220,9 @@ MOSI = Pin()
 MISO = Pin()
 CS = Pin()
 
+spiPorts = ((0, SCK, MOSI, MISO),)
+
+
 # UART pins
 UART_TX = Pin()
 UART_RX = Pin()