mirror of
https://codeberg.org/mclemens/ubitxv6.git
synced 2025-02-21 06:57:27 -05:00
Remove secondary pin from library
This commit is contained in:
parent
0fe54d054f
commit
da45643035
@ -8,12 +8,12 @@
|
||||
#include "toneAC2.h"
|
||||
|
||||
unsigned long _tAC2_time; // Used to track end note with timer when playing note in the background.
|
||||
volatile uint8_t *_pinMode1, *_pinMode2; // Pin modes.
|
||||
uint8_t _pinMask1 = 0, _pinMask2 = 0; // Bitmask for pins.
|
||||
volatile uint8_t *_pinOutput1, *_pinOutput2; // Output port registers for each pin.
|
||||
volatile uint8_t *_pinMode1; // Pin modes.
|
||||
uint8_t _pinMask1 = 0; // Bitmask for pins.
|
||||
volatile uint8_t *_pinOutput1; // Output port registers for each pin.
|
||||
int _tAC2_prescale[] = { 2, 16, 64, 128, 256, 512, 2048 }; // Prescaler.
|
||||
|
||||
void toneAC2(uint8_t pin1, uint8_t pin2, unsigned int frequency, unsigned long length, uint8_t background) {
|
||||
void toneAC2(uint8_t pin1, unsigned int frequency, unsigned long length, uint8_t background) {
|
||||
long top;
|
||||
uint8_t prescaler;
|
||||
|
||||
@ -27,13 +27,9 @@ void toneAC2(uint8_t pin1, uint8_t pin2, unsigned int frequency, unsigned long l
|
||||
|
||||
if (_pinMask1 == 0) { // This gets the port registers and bitmaps for the two pins and sets the pins to output mode.
|
||||
_pinMask1 = digitalPinToBitMask(pin1); // Get the port register bitmask for pin 1.
|
||||
_pinMask2 = digitalPinToBitMask(pin2); // Get the port register bitmask for pin 2.
|
||||
_pinOutput1 = portOutputRegister(digitalPinToPort(pin1)); // Get the output port register for pin 1.
|
||||
_pinOutput2 = portOutputRegister(digitalPinToPort(pin2)); // Get the output port register for pin 2.
|
||||
_pinMode1 = (uint8_t *) portModeRegister(digitalPinToPort(pin1)); // Get the port mode register for pin 1.
|
||||
_pinMode2 = (uint8_t *) portModeRegister(digitalPinToPort(pin2)); // Get the port mode register for pin 2.
|
||||
*_pinMode1 |= _pinMask1; // Set pin 1 to Output mode.
|
||||
*_pinMode2 |= _pinMask2; // Set pin 2 to Output mode.
|
||||
}
|
||||
|
||||
OCR2A = top; // Set the top.
|
||||
@ -41,8 +37,6 @@ void toneAC2(uint8_t pin1, uint8_t pin2, unsigned int frequency, unsigned long l
|
||||
TCCR2B = _BV(WGM22) | prescaler; // Set Fast PWM and prescaler.
|
||||
TCCR2A = _BV(WGM20) | _BV(WGM21); // Fast PWM and normal port operation, OC2A/OC2B disconnected.
|
||||
TIMSK2 &= ~_BV(OCIE2A); // Stop timer 2 interrupt while we set the pin states.
|
||||
if (*_pinOutput1 & _pinMask1) *_pinOutput2 &= ~_pinMask2; // Be sure pins are reversed.
|
||||
else *_pinOutput2 |= _pinMask2; // Other half of making sure pins are reversed.
|
||||
TIMSK2 |= _BV(OCIE2A); // Activate the timer interrupt.
|
||||
|
||||
if (length > 0 && !background) { delay(length); noToneAC2(); } // Just a simple delay, doesn't return control till finished.
|
||||
@ -53,12 +47,10 @@ void noToneAC2() {
|
||||
TCCR2B = _BV(CS22); // Default clock prescaler of 64.
|
||||
TCCR2A = _BV(WGM20); // Set to defaults so PWM can work like normal (PWM, phase corrected, 8bit).
|
||||
*_pinMode1 &= ~_pinMask1; // Set pin 1 to INPUT.
|
||||
*_pinMode2 &= ~_pinMask2; // Set pin 2 to INPUT.
|
||||
_pinMask1 = 0; // Flag so we know note is no longer playing.
|
||||
}
|
||||
|
||||
ISR(TIMER2_COMPA_vect) { // Timer interrupt vector.
|
||||
if (millis() > _tAC2_time) noToneAC2(); // Check to see if it's time for the note to end.
|
||||
*_pinOutput1 ^= _pinMask1; // Toggle the pin 1 state.
|
||||
*_pinOutput2 ^= _pinMask2; // Toggle the pin 2 state.
|
||||
}
|
@ -68,6 +68,6 @@
|
||||
#define TIMER2_COMPA_vect TIMER2_COMP_vect
|
||||
#endif
|
||||
|
||||
void toneAC2(uint8_t pin1, uint8_t pin2, unsigned int frequency = 0, unsigned long length = 0, uint8_t background = false);
|
||||
void toneAC2(uint8_t pin1, unsigned int frequency = 0, unsigned long length = 0, uint8_t background = false);
|
||||
void noToneAC2();
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user