From 844bb6b8c602875629810430aa66463cd6fa6d0d Mon Sep 17 00:00:00 2001 From: morgan Date: Sat, 2 Feb 2019 21:13:21 +0000 Subject: [PATCH 1/4] finish abstraction for RPi --- src/HamShield.cpp | 2 +- src/HamShield_comms.cpp | 20 +++++++++++++------- src/HamShield_comms.h | 15 +++++++++++++-- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/HamShield.cpp b/src/HamShield.cpp index 1c8c196..0a9b5cb 100644 --- a/src/HamShield.cpp +++ b/src/HamShield.cpp @@ -125,7 +125,7 @@ const unsigned char AFSK_space[] PROGMEM = { 140, 228, 250, 166, 53, 0, 53, 166, * @see A1846S_ADDRESS_AD0_LOW * @see A1846S_ADDRESS_AD0_HIGH */ -HamShield::HamShield(uint8_t cs_pin = nSEN, uint8_t clk_pin = CLK, uint8_t dat_pin = DAT, uint8_t pwm_pin = HAMSHIELD_PWM_PIN) { +HamShield::HamShield(uint8_t cs_pin, uint8_t clk_pin, uint8_t dat_pin, uint8_t pwm_pin) { devAddr = cs_pin; hs_pwm_pin = pwm_pin; diff --git a/src/HamShield_comms.cpp b/src/HamShield_comms.cpp index 9738d37..5b1889b 100644 --- a/src/HamShield_comms.cpp +++ b/src/HamShield_comms.cpp @@ -4,10 +4,6 @@ #include "HamShield_comms.h" - -#include "Arduino.h" -//#include "I2Cdev.h" - uint8_t ncs_pin = nSEN; uint8_t clk_pin = CLK; uint8_t dat_pin = DAT; @@ -16,6 +12,10 @@ void HSsetPins(uint8_t ncs, uint8_t clk, uint8_t dat) { ncs_pin = ncs; clk_pin = clk; dat_pin = dat; + +#if !defined(ARDUINO) + wiringPiSetup(); +#endif pinMode(ncs_pin, OUTPUT); digitalWrite(ncs_pin, HIGH); @@ -147,11 +147,17 @@ void HSdelayMicroseconds(unsigned int us) { } void HStone(uint8_t pin, unsigned int frequency) { +#if defined(ARDUINO) tone(pin, frequency); -} -void HStone(uint8_t pin, unsigned int frequency, unsigned long duration) { - tone(pin, frequency, duration); +#else + softToneCreate(pin); + softToneWrite(pin, frequency); +#endif } void HSnoTone(uint8_t pin) { +#if defined(ARDUINO) noTone(pin); +#else + softToneWrite(pin, 0); +#endif } \ No newline at end of file diff --git a/src/HamShield_comms.h b/src/HamShield_comms.h index 8993a28..8406228 100644 --- a/src/HamShield_comms.h +++ b/src/HamShield_comms.h @@ -4,13 +4,24 @@ #ifndef _HAMSHIELD_COMMS_H_ #define _HAMSHIELD_COMMS_H_ -#include "stdint.h" +#if defined(ARDUINO) #include "Arduino.h" + #define nSEN A1 //15 // #define CLK A5 //19 // #define DAT A4 //18 // -#define HAMSHIELD_PWM_PIN 3 // Pin assignment for PWM output +#define HAMSHIELD_PWM_PIN 3 +#else // assume Raspberry Pi +#include "stdint.h" +#include +#include + +#define nSEN 17 // +#define CLK 22 // +#define DAT 27 // +#define HAMSHIELD_PWM_PIN 18 +#endif void HSsetPins(uint8_t ncs, uint8_t clk, uint8_t dat); From 467765d89246918badef3fa909a95c0562c1614d Mon Sep 17 00:00:00 2001 From: morgan Date: Sat, 2 Feb 2019 21:16:33 +0000 Subject: [PATCH 2/4] update tone calls --- src/HamShield.cpp | 9 ++++++--- src/HamShield_comms.h | 3 +-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/HamShield.cpp b/src/HamShield.cpp index 0a9b5cb..20c15ef 100644 --- a/src/HamShield.cpp +++ b/src/HamShield.cpp @@ -1613,11 +1613,13 @@ void HamShield::morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]) { if(bits) { // If it is a valid character... do { if(bits & 1) { - HStone(hs_pwm_pin, morse_freq, morse_dot_millis * 3); + HStone(hs_pwm_pin, morse_freq); //, morse_dot_millis * 3); HSdelay(morse_dot_millis*3); + HSnoTone(); } else { - HStone(hs_pwm_pin, morse_freq, morse_dot_millis); + HStone(hs_pwm_pin, morse_freq); //, morse_dot_millis); HSdelay(morse_dot_millis); + HSnoTone(); } //tone(hs_pwm_pin, 6000, morse_dot_millis); HSnoTone(hs_pwm_pin); @@ -1758,8 +1760,9 @@ void HamShield::SSTVTestPattern(int code) { /* wait for tone to complete */ void HamShield::toneWait(uint16_t freq, long timer) { - HStone(hs_pwm_pin,freq,timer); + HStone(hs_pwm_pin,freq); //,timer); HSdelay(timer); + HSnoTone(); } /* wait microseconds for tone to complete */ diff --git a/src/HamShield_comms.h b/src/HamShield_comms.h index 8406228..6fabc18 100644 --- a/src/HamShield_comms.h +++ b/src/HamShield_comms.h @@ -42,8 +42,7 @@ void HSdelay(unsigned long ms); void HSdelayMicroseconds(unsigned int us); void HStone(uint8_t pin, unsigned int frequency); -void HStone(uint8_t pin, unsigned int frequency, unsigned long duration); void HSnoTone(uint8_t pin); -#endif /* _HAMSHIELD_COMMS_H_ */ \ No newline at end of file +#endif /* _HAMSHIELD_COMMS_H_ */ From 1b1c9b3f80141a77af5ac3504b7370ac4e93a13d Mon Sep 17 00:00:00 2001 From: morgan Date: Sat, 2 Feb 2019 21:22:37 +0000 Subject: [PATCH 3/4] fix noTone calls --- src/HamShield.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/HamShield.cpp b/src/HamShield.cpp index 20c15ef..b9f6354 100644 --- a/src/HamShield.cpp +++ b/src/HamShield.cpp @@ -1615,11 +1615,11 @@ void HamShield::morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]) { if(bits & 1) { HStone(hs_pwm_pin, morse_freq); //, morse_dot_millis * 3); HSdelay(morse_dot_millis*3); - HSnoTone(); + HSnoTone(hs_pwm_pin); } else { HStone(hs_pwm_pin, morse_freq); //, morse_dot_millis); HSdelay(morse_dot_millis); - HSnoTone(); + HSnoTone(hs_pwm_pin); } //tone(hs_pwm_pin, 6000, morse_dot_millis); HSnoTone(hs_pwm_pin); @@ -1762,7 +1762,7 @@ void HamShield::SSTVTestPattern(int code) { void HamShield::toneWait(uint16_t freq, long timer) { HStone(hs_pwm_pin,freq); //,timer); HSdelay(timer); - HSnoTone(); + HSnoTone(hs_pwm_pin); } /* wait microseconds for tone to complete */ From 00fd294bde3b9aaa09971977b65280a0e8b8e269 Mon Sep 17 00:00:00 2001 From: morgan Date: Mon, 4 Feb 2019 21:28:59 +0000 Subject: [PATCH 4/4] working with RPi --- src/HamShield.h | 12 +++++++----- src/HamShield_comms.h | 8 ++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/HamShield.h b/src/HamShield.h index 5cfdd7e..8d059f7 100644 --- a/src/HamShield.h +++ b/src/HamShield.h @@ -240,14 +240,16 @@ class HamShield { bool frequency_float(float freq_khz); uint32_t getFrequency(); float getFrequency_float(); - + + /* ToDo // channel mode // 11 - 25kHz channel // 00 - 12.5kHz channel // 10,01 - reserved void setChanMode(uint16_t mode); uint16_t getChanMode(); - + */ + void setModeTransmit(); // turn off rx, turn on tx void setModeReceive(); // turn on rx, turn off tx void setModeOff(); // turn off rx, turn off tx, set pwr_dwn bit @@ -265,6 +267,7 @@ class HamShield { void setTxSourceNone(); uint16_t getTxSource(); + /* // PA bias voltage is unused (maybe remove this) // set PA_bias voltage // 000000: 1.01V @@ -277,6 +280,7 @@ class HamShield { // 1111111:3.13V void setPABiasVoltage(uint16_t voltage); uint16_t getPABiasVoltage(); + */ // Subaudio settings @@ -475,9 +479,7 @@ class HamShield { uint32_t findWhitespace(uint32_t start,uint32_t stop, uint8_t dwell, uint16_t step, uint16_t threshold); uint32_t scanChannels(uint32_t buffer[],uint8_t buffsize, uint8_t speed, uint16_t threshold); uint32_t findWhitespaceChannels(uint32_t buffer[],uint8_t buffsize, uint8_t dwell, uint16_t threshold); - void buttonMode(uint8_t mode); - static void isr_ptt(); - static void isr_reset(); + unsigned int getMorseFreq(); void setMorseFreq(unsigned int morse_freq_hz); unsigned int getMorseDotMillis(); diff --git a/src/HamShield_comms.h b/src/HamShield_comms.h index 6fabc18..09b81d2 100644 --- a/src/HamShield_comms.h +++ b/src/HamShield_comms.h @@ -17,10 +17,10 @@ #include #include -#define nSEN 17 // -#define CLK 22 // -#define DAT 27 // -#define HAMSHIELD_PWM_PIN 18 +#define nSEN 0 //BCM17, HW pin 11 +#define CLK 3 //BCM22, HW pin 15 +#define DAT 2 //BCM27, HW pin 13 +#define HAMSHIELD_PWM_PIN 1 //BCM18, HW pin 12 #endif