commit 81efedb6f139d02f9d7bb00a8fb12743af7278b8 from: Tracey Emery date: Fri Mar 11 21:47:49 2022 UTC change to use internal cw generator, as it was always intended commit - 3b42f58cd27a48d7a73f4d4e37fa80e4f1586449 commit + 81efedb6f139d02f9d7bb00a8fb12743af7278b8 blob - a746fd8596057553993a7f26552dbdbe9506d436 blob + ce9cb77824a664695df3427037641d5df39dbc6b --- Morse.cpp +++ Morse.cpp @@ -14,7 +14,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ - #include "Morse.h" #define DIT 1.0 @@ -49,10 +48,8 @@ uint8_t dac_this_index = 0, dac_next_index = 0; uint8_t dac_handle_unit, dac_unit_handled, dac_bit; uint8_t dac_digraph = 0, dac_inited = 0, dac_on = 0; -uint8_t adc_inited; +uint8_t adc_inited, dac_cw_configured = 0; -float dac_i = 0.0, dac_max = 6.283; - unsigned long gpio_tx_start_millis, gpio_tx_current_millis; unsigned long gpio_handle_unit_millis; @@ -61,6 +58,8 @@ unsigned long dac_handle_unit_millis; uint8_t ctob(uint8_t c); +dac_channel_t dac_channel; + void gpio_stop(void); void gpio_handle_chars(void); void gpio_handle_units(uint8_t c); @@ -69,6 +68,10 @@ 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); + Morse::Morse(uint8_t type, uint8_t the_pin) { if (type != M_ADC) @@ -91,8 +94,19 @@ Morse::Morse(uint8_t type, uint8_t the_pin, uint8_t th case M_DAC: if (!dac_inited) { dac_wpm = the_wpm; - dac_tx_pin = the_pin; + switch (the_pin) { + case 1: + dac_channel = DAC_CHANNEL_1; + break; + case 2: + dac_channel = DAC_CHANNEL_2; + break; + default: + break; + } dac_unit_t = UNIT_T(dac_wpm); + dac_cw_auto_configure(dac_channel); + dac_output_enable(dac_channel); dac_inited = 1; } break; @@ -282,12 +296,10 @@ Morse::dac_watchdog(void) { if (dac_inited) { dac_handle_chars(); - if (dac_on) { - dac_i += dac_max / 30; - if (dac_i >= dac_max) - dac_i = 0.0; - dacWrite(dac_tx_pin, sin(dac_i) * MAX_RAD + MAX_RAD); - } + if (dac_on) + dac_cw_start(); + else + dac_cw_stop(); } } @@ -299,7 +311,16 @@ Morse::dac_tx(String tx) return; // start by setting our tx pin low - digitalWrite(dac_tx_pin, LOW); + switch(dac_tx_pin) { + case 1: + digitalWrite(25, LOW); + break; + case 2: + digitalWrite(26, LOW); + break; + default: + break; + } // gather our starting variables dac_tx_sending = 1; @@ -316,6 +337,13 @@ Morse::dac_tx(String tx) } void +Morse::dac_cw_configure(dac_cw_config_t *dac_cw_config) +{ + dac_cw_generator_config(dac_cw_config); + dac_cw_configured = 1; +} + +void dac_handle_chars(void) { dac_tx_current_millis = millis(); @@ -421,6 +449,31 @@ dac_stop(void) dac_next_index = 0; } +void +dac_cw_auto_configure(dac_channel_t channel) +{ + if (!dac_cw_configured) { + dac_cw_config_t dac_cw_config; + + 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(); +} + +void +dac_cw_stop(void) +{ + dac_cw_generator_disable(); +} + uint8_t ctob(uint8_t c) { blob - 363392aff0252a5265a2352d94626d3c695f0421 blob + 5440aff2724cd4970a8af67036a7826b510c9423 --- Morse.h +++ Morse.h @@ -17,27 +17,34 @@ #ifndef _MORSE_H #define _MORSE_H +#include "soc/rtc_io_reg.h" +#include "soc/rtc_cntl_reg.h" +#include "soc/sens_reg.h" +#include "soc/rtc.h" + +#include "driver/dac.h" + #include "Arduino.h" class Morse { - // we've no rx code yet public: Morse(uint8_t type, uint8_t the_pin); Morse(uint8_t type, uint8_t the_pin, uint8_t the_wpm); uint8_t gpio_transmitting(void); + void gpio_tx(String tx); void gpio_tx_stop(void); void gpio_watchdog(void); uint8_t dac_transmitting(void); + void dac_tx(String tx); void dac_tx_stop(void); void dac_watchdog(void); - - // private: + void dac_cw_configure(dac_cw_config_t *); }; enum blob - 6b8ba38c53f55a61e3cd2e5082d65f8a68dce6fe (mode 644) blob + /dev/null --- examples/Blink_LED/Blink_LED.ino +++ /dev/null @@ -1,45 +0,0 @@ -#include "Morse/Morse.h" - -#define WPM 17 -#define LEDP 2 -#define SECS 2000 // seconds between transmittions - -unsigned long current_millis, start_millis; -void setup(void); -void loop(void); - -Morse morse(WPM, LEDP); - -// backticks will toggle digraph sending - -String tx = "k7su de k7tle k `ar`"; - -void -setup(void) -{ - Serial.begin(115200); - - pinMode(LEDP, OUTPUT); - digitalWrite(LEDP, LOW); - - start_millis = millis(); - current_millis = millis(); - - // send first without 2 second pause - delay(1000); - morse.tx_gpio(tx); -} - -void -loop(void) -{ - current_millis = millis(); - morse.watchdog(); - - // it's up to the programmer to properly space transmissions - if (!morse.transmitting() && - (current_millis - start_millis >= SECS)) { - morse.tx_gpio(tx); - } else if (morse.transmitting()) - start_millis = current_millis; -} blob - /dev/null blob + 004080552534a230865d5ec24a47c9b99c84c14b (mode 644) --- /dev/null +++ examples/LED_DAC/LED_DAC.ino @@ -0,0 +1,74 @@ +#include "Morse.h" + +#define WPM 17 +#define LEDP 2 +#define GSECS 2000 // seconds between transmittions +#define DSECS 4000 +#define DAC_CHANNEL 2 + +unsigned long current_gpio_millis, start_gpio_millis; +unsigned long current_dac_millis, start_dac_millis; +void setup(void); +void loop(void); + + +Morse morse(M_GPIO, LEDP); // WPM is auto selected +Morse morse_dac(M_DAC, DAC_CHANNEL, WPM); // use DAC channel 2 + +// backticks will toggle digraph sending + +String tx = "ab7cd de a7bcd k `ar`"; + +void +setup(void) +{ + Serial.begin(115200); + + pinMode(LEDP, OUTPUT); + digitalWrite(LEDP, LOW); + + // configure our DAC if we want to + dac_cw_config_t dac_cw_config; + + dac_cw_config.en_ch = DAC_CHANNEL_2; + dac_cw_config.scale = DAC_CW_SCALE_2; + dac_cw_config.phase = DAC_CW_PHASE_180; + dac_cw_config.freq = 550; + + morse_dac.dac_cw_configure(&dac_cw_config); + + // setup millis + start_gpio_millis = millis(); + current_gpio_millis = millis(); + + start_dac_millis = millis(); + current_dac_millis = millis(); + + delay(2000); + Serial.printf("LED and DAC %d setup\r\n", DAC_CHANNEL); +} + +void +loop(void) +{ + current_gpio_millis = millis(); + current_dac_millis = millis(); + + morse.gpio_watchdog(); + morse_dac.dac_watchdog(); + + // it's up to the programmer to properly space transmissions + if (!morse.gpio_transmitting() && + (current_gpio_millis - start_gpio_millis >= GSECS)) { + Serial.println("Transmit via LED"); + morse.gpio_tx(tx); + } else if (morse.gpio_transmitting()) + start_gpio_millis = current_gpio_millis; + + if (!morse.dac_transmitting() && + (current_dac_millis - start_dac_millis >= DSECS)) { + Serial.println("Transmit via DAC"); + morse_dac.dac_tx(tx); + } else if (morse.dac_transmitting()) + start_dac_millis = current_dac_millis; +}