Skip to content

Commit

Permalink
DM: restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
deanm1278 committed May 7, 2018
1 parent 483d3cf commit 36e234c
Show file tree
Hide file tree
Showing 8 changed files with 385 additions and 273 deletions.
Empty file added adafruit_seesaw/__init__.py
Empty file.
37 changes: 37 additions & 0 deletions adafruit_seesaw/analoginput.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# The MIT License (MIT)
#
# Copyright (c) 2017 Dean Miller for Adafruit Industries
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

class AnalogInput:
def __init__(self, seesaw, pin):
self._seesaw = seesaw
self._pin = pin

def deinit(self):
pass

@property
def value(self):
return self._seesaw.analog_read(self._pin)

@property
def reference_voltage(self):
return 3.3
64 changes: 64 additions & 0 deletions adafruit_seesaw/crickit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# The MIT License (MIT)
#
# Copyright (c) 2017 Dean Miller for Adafruit Industries
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

_ADC_INPUT_0_PIN_CRICKIT = const(2)
_ADC_INPUT_1_PIN_CRICKIT = const(3)
_ADC_INPUT_2_PIN_CRICKIT = const(40)
_ADC_INPUT_3_PIN_CRICKIT = const(41)
_ADC_INPUT_4_PIN_CRICKIT = const(11)
_ADC_INPUT_5_PIN_CRICKIT = const(10)
_ADC_INPUT_6_PIN_CRICKIT = const(9)
_ADC_INPUT_7_PIN_CRICKIT = const(8)

_CRICKIT_S4 = const(14)
_CRICKIT_S3 = const(15)
_CRICKIT_S2 = const(16)
_CRICKIT_S1 = const(17)

_CRICKIT_M1_A1 = const(18)
_CRICKIT_M1_A2 = const(19)
_CRICKIT_M1_B1 = const(22)
_CRICKIT_M1_B2 = const(23)
_CRICKIT_DRIVE1 = const(42)
_CRICKIT_DRIVE2 = const(43)
_CRICKIT_DRIVE3 = const(12)
_CRICKIT_DRIVE4 = const(13)

_CRICKIT_CT1 = const(0)
_CRICKIT_CT2 = const(1)
_CRICKIT_CT3 = const(2)
_CRICKIT_CT4 = const(3)

class Crickit_Pinmap:
analog_pins = [_ADC_INPUT_0_PIN_CRICKIT, _ADC_INPUT_1_PIN_CRICKIT,
_ADC_INPUT_2_PIN_CRICKIT, _ADC_INPUT_3_PIN_CRICKIT,
_ADC_INPUT_4_PIN_CRICKIT, _ADC_INPUT_5_PIN_CRICKIT,
_ADC_INPUT_6_PIN_CRICKIT, _ADC_INPUT_7_PIN_CRICKIT]

pwm_width = 16

pwm_pins = [_CRICKIT_S4, _CRICKIT_S3, _CRICKIT_S2, _CRICKIT_S1,
_CRICKIT_M1_A1, _CRICKIT_M1_A2, _CRICKIT_M1_B1,
_CRICKIT_M1_B2, _CRICKIT_DRIVE1, _CRICKIT_DRIVE2,
_CRICKIT_DRIVE3, _CRICKIT_DRIVE4]

touch_pins = [_CRICKIT_CT1, _CRICKIT_CT2, _CRICKIT_CT3, _CRICKIT_CT4]
102 changes: 102 additions & 0 deletions adafruit_seesaw/digitalio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# The MIT License (MIT)
#
# Copyright (c) 2017 Dean Miller for Adafruit Industries
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

import digitalio

class DigitalIO:
def __init__(self, seesaw, pin):
self._seesaw = seesaw
self._pin = pin
self._drive_mode = digitalio.DriveMode.PUSH_PULL
self._direction = False
self._pull = None
self._value = False

def deinit(self):
pass

def switch_to_output(self, value=False, drive_mode=digitalio.DriveMode.PUSH_PULL):
self._seesaw.pin_mode(self._pin, self._seesaw.OUTPUT)
self._seesaw.digital_write(self._pin, value)
self._drive_mode = drive_mode
self._pull = None

def switch_to_input(self, pull=None):
if pull == digitalio.Pull.DOWN:
raise ValueError("Pull Down currently not supported")
elif pull == digitalio.Pull.UP:
self._seesaw.pin_mode(self._pin, self._seesaw.INPUT_PULLUP)
else:
self._seesaw.pin_mode(self._pin, self._seesaw.INPUT)
self._pull = pull

@property
def direction(self):
return self._direction

@direction.setter
def direction(self, value):
if value == digitalio.Direction.OUTPUT:
self.switch_to_output()
elif value == digitalio.Direction.INPUT:
self.switch_to_input()
else:
raise ValueError("Out of range")
self._direction = value

@property
def value(self):
if self._direction == digitalio.Direction.OUTPUT:
return self._value
return self._seesaw.digital_read(self._pin)

@value.setter
def value(self, val):
if not 0 <= val <= 1:
raise ValueError("Out of range")
self._seesaw.digital_write(self._pin, val)
self._value = val

@property
def drive_mode(self):
return self._drive_mode

@drive_mode.setter
def drive_mode(self, mode):
pass

@property
def pull(self):
return self._pull

@pull.setter
def pull(self, mode):
if self._direction == digitalio.Direction.OUTPUT:
raise AttributeError("cannot set pull on an output pin")
elif mode == digitalio.Pull.DOWN:
raise ValueError("Pull Down currently not supported")
elif mode == digitalio.Pull.UP:
self._seesaw.pin_mode(self._pin, self._seesaw.INPUT_PULLUP)
elif mode is None:
self._seesaw.pin_mode(self._pin, self._seesaw.INPUT)
else:
raise ValueError("Out of range")
74 changes: 74 additions & 0 deletions adafruit_seesaw/neopixel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# The MIT License (MIT)
#
# Copyright (c) 2017 Dean Miller for Adafruit Industries
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

class Neopixel:
def __init__(self, seesaw, pin, n, *, bpp=3, brightness=1.0, auto_write=True, pixel_order=None):
self._seesaw = seesaw
self._pin = pin
self._bpp = bpp
self._auto_write = auto_write
self._pixel_order = pixel_order
self._n = n
self._brightness = brightness

cmd = bytearray([pin])
self._seesaw.write(_NEOPIXEL_BASE, _NEOPIXEL_PIN, cmd)
cmd = struct.pack(">H", n*self._bpp)
self._seesaw.write(_NEOPIXEL_BASE, _NEOPIXEL_BUF_LENGTH, cmd)

@property
def brightness(self):
pass

@brightness.setter
def brightness(self, value):
pass

def deinit(self):
pass

def __len__(self):
return self._n

def __setitem__(self, key, value):
cmd = bytearray(6)
cmd[:2] = struct.pack(">H", key * self._bpp)
cmd[2:] = struct.pack(">I", value)
self._seesaw.write(_NEOPIXEL_BASE, _NEOPIXEL_BUF, cmd)
if self._auto_write:
self.show()

def __getitem__(self, key):
pass

def fill(self, color):
cmd = bytearray(self._n*self._bpp+2)
for i in range(self._n):
cmd[self._bpp*i+2:] = struct.pack(">I", color)

self._seesaw.write(_NEOPIXEL_BASE, _NEOPIXEL_BUF, cmd)

if self._auto_write:
self.show()

def show(self):
self._seesaw.write(_NEOPIXEL_BASE, _NEOPIXEL_SHOW)
52 changes: 52 additions & 0 deletions adafruit_seesaw/pwmout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# The MIT License (MIT)
#
# Copyright (c) 2017 Dean Miller for Adafruit Industries
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

class PWMOut:
"""A single seesaw channel that matches the :py:class:`~pulseio.PWMOut` API."""
def __init__(self, seesaw, pin):
self._seesaw = seesaw
self._pin = pin
self._dc = 0
self._frequency = 0

@property
def frequency(self):
"""The overall PWM frequency in herz."""
return self._frequency

@frequency.setter
def frequency(self, frequency):
self._seesaw.set_pwm_freq(self._pin, frequency)
self._frequency = frequency

@property
def duty_cycle(self):
"""16 bit value that dictates how much of one cycle is high (1) versus low (0). 0xffff will
always be high, 0 will always be low and 0x7fff will be half high and then half low."""
return self._dc

@duty_cycle.setter
def duty_cycle(self, value):
if not 0 <= value <= 0xffff:
raise ValueError("Out of range")
self._seesaw.analog_write(self._pin, value)
self._dc = value
41 changes: 41 additions & 0 deletions adafruit_seesaw/samd09.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# The MIT License (MIT)
#
# Copyright (c) 2017 Dean Miller for Adafruit Industries
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

_ADC_INPUT_0_PIN = const(0x02)
_ADC_INPUT_1_PIN = const(0x03)
_ADC_INPUT_2_PIN = const(0x04)
_ADC_INPUT_3_PIN = const(0x05)

_PWM_0_PIN = const(0x04)
_PWM_1_PIN = const(0x05)
_PWM_2_PIN = const(0x06)
_PWM_3_PIN = const(0x07)

class SAMD09_Pinmap:
analog_pins = [_ADC_INPUT_0_PIN, _ADC_INPUT_1_PIN,
_ADC_INPUT_2_PIN, _ADC_INPUT_3_PIN]

pwm_width = 8

pwm_pins = [_PWM_0_PIN, _PWM_1_PIN, _PWM_2_PIN, _PWM_3_PIN]

touch_pins = []

0 comments on commit 36e234c

Please sign in to comment.