summary refs log tree commit diff
path: root/quantum
diff options
context:
space:
mode:
Diffstat (limited to 'quantum')
-rw-r--r--quantum/dynamic_macro.h27
-rw-r--r--quantum/fauxclicky.c15
-rw-r--r--quantum/fauxclicky.h10
3 files changed, 25 insertions, 27 deletions
diff --git a/quantum/dynamic_macro.h b/quantum/dynamic_macro.h
index 64093f293e..9e7845c992 100644
--- a/quantum/dynamic_macro.h
+++ b/quantum/dynamic_macro.h
@@ -40,6 +40,7 @@
 enum dynamic_macro_keycodes {
     DYN_REC_START1 = DYNAMIC_MACRO_RANGE,
     DYN_REC_START2,
+    DYN_REC_STOP,
     DYN_MACRO_PLAY1,
     DYN_MACRO_PLAY2,
 };
@@ -96,24 +97,29 @@ void dynamic_macro_play(
 /**
  * Record a single key in a dynamic macro.
  *
+ * @param macro_buffer[in] The start of the used macro buffer.
  * @param macro_pointer[in,out] The current buffer position.
- * @param macro_end2[in] The end of the other macro which shouldn't be overwritten.
+ * @param macro2_end[in] The last buffer element it is safe to use before overwriting the other macro.
  * @param direction[in]  Either +1 or -1, which way to iterate the buffer.
  * @param record[in]     The current keypress.
  */
 void dynamic_macro_record_key(
+    keyrecord_t *macro_buffer,
     keyrecord_t **macro_pointer,
-    keyrecord_t *macro_end2,
+    keyrecord_t *macro2_end,
     int8_t direction,
     keyrecord_t *record)
 {
-    if (*macro_pointer + direction != macro_end2) {
+    /* If we've just started recording, ignore all the key releases. */
+    if (!record->event.pressed && *macro_pointer == macro_buffer) {
+        return;
+    }
+
+    if (*macro_pointer - direction != macro2_end) {
         **macro_pointer = *record;
         *macro_pointer += direction;
     } else {
-        /* Notify about the end of buffer. The blinks are paired
-         * because they should happen on both down and up events. */
-        backlight_toggle();
+        dynamic_macro_led_blink();
     }
 }
 
@@ -209,9 +215,8 @@ bool process_record_dynamic_macro(uint16_t keycode, keyrecord_t *record)
     } else {
         /* A macro is being recorded right now. */
         switch (keycode) {
-        case MO(_DYN):
-            /* Use the layer key used to access the macro recording as
-             * a stop button. */
+        case DYN_REC_STOP:
+            /* Stop the macro recording. */
             if (record->event.pressed) { /* Ignore the initial release
                                           * just after the recoding
                                           * starts. */
@@ -230,10 +235,10 @@ bool process_record_dynamic_macro(uint16_t keycode, keyrecord_t *record)
             /* Store the key in the macro buffer and process it normally. */
             switch (macro_id) {
             case 1:
-                dynamic_macro_record_key(&macro_pointer, r_macro_end, +1, record);
+                dynamic_macro_record_key(macro_buffer, &macro_pointer, r_macro_end, +1, record);
                 break;
             case 2:
-                dynamic_macro_record_key(&macro_pointer, macro_end, -1, record);
+                dynamic_macro_record_key(r_macro_buffer, &macro_pointer, macro_end, -1, record);
                 break;
             }
             return true;
diff --git a/quantum/fauxclicky.c b/quantum/fauxclicky.c
index 13273e7058..c3341ca332 100644
--- a/quantum/fauxclicky.c
+++ b/quantum/fauxclicky.c
@@ -20,13 +20,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <stdbool.h>
 #include <musical_notes.h>
 
-__attribute__ ((weak))
-float fauxclicky_pressed_note[2] = MUSICAL_NOTE(_F3, 2);
-__attribute__ ((weak))
-float fauxclicky_released_note[2] = MUSICAL_NOTE(_A3, 2);
-__attribute__ ((weak))
-float fauxclicky_beep_note[2] = MUSICAL_NOTE(_C3, 2);
-
 bool fauxclicky_enabled = true;
 uint16_t note_start = 0;
 bool note_playing = false;
@@ -48,13 +41,13 @@ void fauxclicky_stop()
     note_playing = false;
 }
 
-void fauxclicky_play(float note[2]) {
+void fauxclicky_play(float note[]) {
     if (!fauxclicky_enabled) return;
     if (note_playing) fauxclicky_stop();
-    FAUXCLICKY_TIMER_PERIOD = (uint16_t)(((float)F_CPU) / (note[0] * FAUXCLICKY_CPU_PRESCALER));
-    FAUXCLICKY_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (note[0] * FAUXCLICKY_CPU_PRESCALER)) / 2);
+    FAUXCLICKY_TIMER_PERIOD = (uint16_t)(((float)F_CPU) / (note[0] * (float)FAUXCLICKY_CPU_PRESCALER));
+    FAUXCLICKY_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (note[0] * (float)FAUXCLICKY_CPU_PRESCALER)) / (float)2);
     note_playing = true;
-    note_period = (note[1] / 16) * (60 / (float)FAUXCLICKY_TEMPO) * 100;   // check this
+    note_period = (note[1] / (float)16) * ((float)60 / (float)FAUXCLICKY_TEMPO) * 1000;
     note_start = timer_read();
     FAUXCLICKY_ENABLE_OUTPUT;
 }
diff --git a/quantum/fauxclicky.h b/quantum/fauxclicky.h
index 109bd0d83e..1a8e188dd5 100644
--- a/quantum/fauxclicky.h
+++ b/quantum/fauxclicky.h
@@ -21,11 +21,11 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "stdbool.h"
 
 __attribute__ ((weak))
-float fauxclicky_pressed_note[2];
+float fauxclicky_pressed_note[2] = MUSICAL_NOTE(_D4, 0.25);
 __attribute__ ((weak))
-float fauxclicky_released_note[2];
+float fauxclicky_released_note[2] = MUSICAL_NOTE(_C4, 0.125);
 __attribute__ ((weak))
-float fauxclicky_beep_note[2];
+float fauxclicky_beep_note[2] = MUSICAL_NOTE(_C4, 0.25);
 
 bool fauxclicky_enabled;
 
@@ -73,11 +73,11 @@ bool fauxclicky_enabled;
 #endif
 
 #ifndef FAUXCLICKY_ENABLE_OUTPUT
-#define FAUXCLICKY_ENABLE_OUTPUT TCCR3A |= _BV(COM3A1);
+#define FAUXCLICKY_ENABLE_OUTPUT TCCR3A |= _BV(COM3A1)
 #endif
 
 #ifndef FAUXCLICKY_DISABLE_OUTPUT
-#define FAUXCLICKY_DISABLE_OUTPUT TCCR3A &= ~(_BV(COM3A1) | _BV(COM3A0));
+#define FAUXCLICKY_DISABLE_OUTPUT TCCR3A &= ~(_BV(COM3A1) | _BV(COM3A0))
 #endif
 
 #ifndef FAUXCLICKY_TIMER_PERIOD