Commit Diff


commit - 62a1e26c0eaaa5b8509bf43359406b09645caa8c
commit + 3efdc8f3ba0678f7899b957b16b3810d995695e5
blob - 059a25f25d7a6263f56548168965730f21182c6a
blob + 39f51736c51a55362d566435cf178f51d50e7482
--- Morse.cpp	
+++ Morse.cpp	
@@ -65,7 +65,6 @@ void			 dac_stop(void);
 void			 dac_handle_chars(void);
 void			 dac_handle_units(uint8_t c);
 
-void			 dac_cw_auto_configure(dac_channel_t);
 void			 dac_cw_start(void);
 void			 dac_cw_stop(void);
 
@@ -89,11 +88,11 @@ Morse::Morse(uint8_t type, uint8_t the_pin, uint8_t th
 		if (!dac_inited) {
 			dac_wpm = the_wpm;
 			dac_unit_t = UNIT_T(dac_wpm);
-			dac_cw_auto_configure(dac_channel);
-			/*
-			 * glad I put a scope on this. why in the world
-			 * don't they have an invert function in the api?
-			 */
+			dac_cw_config_t dac_cw_config;
+			// this func is broken and only gives 1/2 wave form  
+			/* dac_cw_config.en_ch = channel; */
+			dac_cw_config.freq = 1000;
+
 			switch (the_pin) {
 			case 1:
 				dac_channel = DAC_CHANNEL_1;
@@ -108,6 +107,8 @@ Morse::Morse(uint8_t type, uint8_t the_pin, uint8_t th
 			default:
 				break;
 			}
+
+			dac_cw_generator_config(&dac_cw_config);
 			dac_output_enable(dac_channel);
 			dac_inited = 1;
 		}
@@ -118,6 +119,25 @@ Morse::Morse(uint8_t type, uint8_t the_pin, uint8_t th
 	}
 }
 
+void
+Morse::dac_cw_setup(dac_cw_config_t *dac_cw_config)
+{
+	switch (dac_channel) {
+	case 1:
+		dac_channel = DAC_CHANNEL_1;
+		SET_PERI_REG_BITS(SENS_SAR_DAC_CTRL2_REG,
+		    SENS_DAC_INV1, 2, SENS_DAC_INV1_S);
+		break;
+	case 2:
+		dac_channel = DAC_CHANNEL_2;
+		SET_PERI_REG_BITS(SENS_SAR_DAC_CTRL2_REG,
+		    SENS_DAC_INV2, 2, SENS_DAC_INV2_S);
+		break;
+	}
+
+	dac_cw_generator_config(dac_cw_config);
+	dac_output_enable(dac_channel);
+}
 // gpio functions
 
 uint8_t
@@ -445,18 +465,6 @@ dac_stop(void)
 }
 
 void
-dac_cw_auto_configure(dac_channel_t channel)
-{
-	dac_cw_config_t dac_cw_config;
-
-	// this func is broken and only gives 1/2 wave form  
-	/* dac_cw_config.en_ch = channel; */
-	dac_cw_config.freq = 1000;
-
-	dac_cw_generator_config(&dac_cw_config);
-}
-
-void
 dac_cw_start(void)
 {
 	dac_cw_generator_enable();
blob - 5440aff2724cd4970a8af67036a7826b510c9423
blob + dc08d32c79a9603b5594b379560718e05b6ef2eb
--- Morse.h	
+++ Morse.h	
@@ -45,6 +45,8 @@ Morse
 		void dac_tx_stop(void);
 		void dac_watchdog(void);
 		void dac_cw_configure(dac_cw_config_t *);
+
+		void dac_cw_setup(dac_cw_config_t *);
 };
 
 enum
blob - 5ef8a819ab80ffb339d5646747fad1481c04a622
blob + d1d373b48acbfea8829ab5fc34ff014b1a94fb98
--- examples/LED_DAC/LED_DAC.ino	
+++ examples/LED_DAC/LED_DAC.ino	
@@ -36,7 +36,9 @@ setup(void)
 	dac_cw_config.phase = DAC_CW_PHASE_180;
 	dac_cw_config.freq = 550;
 
-	morse_dac.dac_cw_configure(&dac_cw_config);
+	// this can now be called multiple times if something overwrites
+	// the DAC, like switching between morse and dac_write(voice)
+	morse_dac.dac_cw_setup(&dac_cw_config);
 
 	// setup millis
 	start_gpio_millis = millis();