Browse Source

Fixed timer2 colission with arduino framework around "tone" function.

Robert Pelnar 5 years ago
parent
commit
93d4128163
5 changed files with 39 additions and 19 deletions
  1. 14 14
      Firmware/Marlin_main.cpp
  2. 4 0
      Firmware/system_timer.h
  3. 13 1
      Firmware/timer02.c
  4. 4 0
      Firmware/timer02.h
  5. 4 4
      Firmware/util.cpp

+ 14 - 14
Firmware/Marlin_main.cpp

@@ -2325,9 +2325,9 @@ void refresh_cmd_timeout(void)
 
 void trace() {
 //if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
-    tone(BEEPER, 440);
+    _tone(BEEPER, 440);
     _delay(25);
-    noTone(BEEPER);
+    _noTone(BEEPER);
     _delay(20);
 }
 /*
@@ -3124,9 +3124,9 @@ void gcode_M701()
 		load_filament_final_feed(); //slow sequence
 		st_synchronize();
 
-		if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) tone(BEEPER, 500);
+		if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) _tone(BEEPER, 500);
 		delay_keep_alive(50);
-		noTone(BEEPER);
+		_noTone(BEEPER);
 
 		if (!farm_mode && loading_flag) {
 			lcd_load_filament_color_check();
@@ -3189,9 +3189,9 @@ static void gcode_PRUSA_SN()
         putchar('\n');
 #if 0
         for (int b = 0; b < 3; b++) {
-            tone(BEEPER, 110);
+            _tone(BEEPER, 110);
             _delay(50);
-            noTone(BEEPER);
+            _noTone(BEEPER);
             _delay(50);
         }
 #endif
@@ -6268,9 +6268,9 @@ Sigma_Exit:
       {
         #if BEEPER > 0
 if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
-          tone(BEEPER, beepS);
+          _tone(BEEPER, beepS);
           _delay(beepP);
-          noTone(BEEPER);
+          _noTone(BEEPER);
         #endif
       }
       else
@@ -7494,9 +7494,9 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument s
 					if (degHotend0() > EXTRUDE_MINTEMP)
 					{
 						if ((eSoundMode == e_SOUND_MODE_LOUD) || (eSoundMode == e_SOUND_MODE_ONCE))
-							tone(BEEPER, 1000);
+							_tone(BEEPER, 1000);
 						delay_keep_alive(50);
-						noTone(BEEPER);
+						_noTone(BEEPER);
 						loading_flag = true;
 						enquecommand_front_P((PSTR("M701")));
 					}
@@ -9227,9 +9227,9 @@ void M600_load_filament() {
 		if (fsensor_check_autoload())
 		{
 if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
-			tone(BEEPER, 1000);
+			_tone(BEEPER, 1000);
 			delay_keep_alive(50);
-			noTone(BEEPER);
+			_noTone(BEEPER);
 			break;
 		}
 #endif //FILAMENT_SENSOR
@@ -9246,9 +9246,9 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
 	M600_load_filament_movements();
 
 if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
-	tone(BEEPER, 500);
+	_tone(BEEPER, 500);
 	delay_keep_alive(50);
-	noTone(BEEPER);
+	_noTone(BEEPER);
 
 #ifdef FSENSOR_QUALITY
 	fsensor_oq_meassure_stop();

+ 4 - 0
Firmware/system_timer.h

@@ -11,10 +11,14 @@
 #define _millis millis2
 #define _micros micros2
 #define _delay delay2
+#define _tone tone2
+#define _noTone noTone2
 #else //SYSTEM_TIMER_2
 #define _millis millis
 #define _micros micros
 #define _delay delay
+#define _tone tone
+#define _noTone noTone
 #define timer02_set_pwm0(pwm0)
 #endif //SYSTEM_TIMER_2
 

+ 13 - 1
Firmware/timer02.c

@@ -4,8 +4,10 @@
 // original OVF handler is disabled
 #include <avr/io.h>
 #include <avr/interrupt.h>
-#include <Arduino.h>
+#include "Arduino.h"
+#include "io_atmega2560.h"
 
+#define BEEPER              84
 
 uint8_t timer02_pwm0 = 0;
 
@@ -154,3 +156,13 @@ void delay2(unsigned long ms)
 		}
 	}
 }
+
+void tone2(uint8_t _pin, unsigned int frequency/*, unsigned long duration*/)
+{
+	PIN_SET(BEEPER);
+}
+
+void noTone2(uint8_t _pin)
+{
+	PIN_CLR(BEEPER);
+}

+ 4 - 0
Firmware/timer02.h

@@ -24,6 +24,10 @@ extern unsigned long micros2(void);
 
 extern void delay2(unsigned long ms);
 
+extern void tone2(uint8_t _pin, unsigned int frequency/*, unsigned long duration*/);
+
+extern void noTone2(uint8_t _pin);
+
 
 #if defined(__cplusplus)
 }

+ 4 - 4
Firmware/util.cpp

@@ -296,14 +296,14 @@ bool show_upgrade_dialog_if_version_newer(const char *version_string)
             lcd_putc(*c);
         lcd_puts_at_P(0, 3, _i("Please upgrade."));////MSG_NEW_FIRMWARE_PLEASE_UPGRADE c=20 r=0
 if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
-        tone(BEEPER, 1000);
+        _tone(BEEPER, 1000);
         delay_keep_alive(50);
-        noTone(BEEPER);
+        _noTone(BEEPER);
         delay_keep_alive(500);
 if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
-        tone(BEEPER, 1000);
+        _tone(BEEPER, 1000);
         delay_keep_alive(50);
-        noTone(BEEPER);
+        _noTone(BEEPER);
         lcd_wait_for_click();
         lcd_update_enable(true);
         lcd_clear();