Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix set_pwm_freq() for ATtinys #125

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion adafruit_seesaw/attiny8x7.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ()
3 changes: 2 additions & 1 deletion adafruit_seesaw/attinyx16.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ()
15 changes: 9 additions & 6 deletions adafruit_seesaw/seesaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down