From 5daef994293900260897ff9b97d2a0a82d95ff16 Mon Sep 17 00:00:00 2001 From: caternuson Date: Tue, 7 Nov 2023 14:28:20 -0800 Subject: [PATCH 1/2] fix set_pwm_freq for attinys --- adafruit_seesaw/attiny8x7.py | 3 ++- adafruit_seesaw/attinyx16.py | 3 ++- adafruit_seesaw/seesaw.py | 15 +++++++++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/adafruit_seesaw/attiny8x7.py b/adafruit_seesaw/attiny8x7.py index d8e59b4..ce96861 100644 --- a/adafruit_seesaw/attiny8x7.py +++ b/adafruit_seesaw/attiny8x7.py @@ -26,7 +26,8 @@ class ATtiny8x7_Pinmap: pwm_width = 16 # we dont actually use all 16 bits but whatever """The pins capable of PWM output""" - pwm_pins = (0, 1, 9, 12, 13) + pwm_pins = (0, 1, 9, 12, 13) # 8 bit PWM mode + pwm_pins += (6, 7, 8) # 16 bit PWM mode """No pins on this board are capable of touch input""" touch_pins = () diff --git a/adafruit_seesaw/attinyx16.py b/adafruit_seesaw/attinyx16.py index 3ff5de3..cc14cdf 100644 --- a/adafruit_seesaw/attinyx16.py +++ b/adafruit_seesaw/attinyx16.py @@ -25,7 +25,8 @@ class ATtinyx16_Pinmap: pwm_width = 16 # we dont actually use all 16 bits but whatever """The pins capable of PWM output""" - pwm_pins = (0, 1, 7, 11, 16) + pwm_pins = (0, 1, 7, 11, 16) # 8 bit PWM mode + pwm_pins += (4, 5, 6) # 16 bit PWM mode """No pins on this board are capable of touch input""" touch_pins = () diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 4857300..67e1d75 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -390,14 +390,17 @@ def get_temp(self): def set_pwm_freq(self, pin, freq): """Set the PWM frequency of a pin by number""" - if pin in self.pin_mapping.pwm_pins: - cmd = bytearray( - [self.pin_mapping.pwm_pins.index(pin), (freq >> 8), freq & 0xFF] - ) - self.write(_TIMER_BASE, _TIMER_FREQ, cmd) - else: + if pin not in self.pin_mapping.pwm_pins: raise ValueError("Invalid PWM pin") + if self.chip_id == _SAMD09_HW_ID_CODE: + offset = self.pin_mapping.pwm_pins.index(pin) + else: + offset = pin + + cmd = bytearray([offset, (freq >> 8), freq & 0xFF]) + self.write(_TIMER_BASE, _TIMER_FREQ, cmd) + def encoder_position(self, encoder=0): """The current position of the encoder""" buf = bytearray(4) From 4da237e6ed19f46f3b948e531b7b5f7c82b131b2 Mon Sep 17 00:00:00 2001 From: caternuson Date: Tue, 7 Nov 2023 14:55:12 -0800 Subject: [PATCH 2/2] black --- adafruit_seesaw/attiny8x7.py | 4 ++-- adafruit_seesaw/attinyx16.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/adafruit_seesaw/attiny8x7.py b/adafruit_seesaw/attiny8x7.py index ce96861..bdddf54 100644 --- a/adafruit_seesaw/attiny8x7.py +++ b/adafruit_seesaw/attiny8x7.py @@ -26,8 +26,8 @@ class ATtiny8x7_Pinmap: pwm_width = 16 # we dont actually use all 16 bits but whatever """The pins capable of PWM output""" - pwm_pins = (0, 1, 9, 12, 13) # 8 bit PWM mode - pwm_pins += (6, 7, 8) # 16 bit PWM mode + pwm_pins = (0, 1, 9, 12, 13) # 8 bit PWM mode + pwm_pins += (6, 7, 8) # 16 bit PWM mode """No pins on this board are capable of touch input""" touch_pins = () diff --git a/adafruit_seesaw/attinyx16.py b/adafruit_seesaw/attinyx16.py index cc14cdf..874ccd5 100644 --- a/adafruit_seesaw/attinyx16.py +++ b/adafruit_seesaw/attinyx16.py @@ -25,8 +25,8 @@ class ATtinyx16_Pinmap: pwm_width = 16 # we dont actually use all 16 bits but whatever """The pins capable of PWM output""" - pwm_pins = (0, 1, 7, 11, 16) # 8 bit PWM mode - pwm_pins += (4, 5, 6) # 16 bit PWM mode + pwm_pins = (0, 1, 7, 11, 16) # 8 bit PWM mode + pwm_pins += (4, 5, 6) # 16 bit PWM mode """No pins on this board are capable of touch input""" touch_pins = ()