Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
00fd294bde | ||
|
|
1b1c9b3f80 | ||
|
|
467765d892 | ||
|
|
844bb6b8c6 | ||
|
|
f7c76eb1ad | ||
|
|
76a92a882f | ||
|
|
7427b426b1 | ||
|
|
6b05b7754d | ||
|
|
6c891c9f32 | ||
|
|
d65877ad29 | ||
|
|
dc93752730 | ||
|
|
220bd8aa28 |
@@ -101,7 +101,7 @@ void program_pl_tx() {
|
||||
long pl_tx = atof(pl_tx_buffer);
|
||||
Serial.print(" Which is FLOAT of ");
|
||||
Serial.println(pl_tx,DEC);
|
||||
radio.setCtcssEncoder(pl_tx);
|
||||
radio.setCtcss(pl_tx);
|
||||
}
|
||||
|
||||
void pl_tone_rx() {
|
||||
@@ -128,7 +128,7 @@ void program_pl_rx() {
|
||||
long pl_rx = atof(pl_rx_buffer);
|
||||
Serial.print(" Which is FLOAT of ");
|
||||
Serial.println(pl_rx,DEC);
|
||||
radio.setCtcssDecoder(pl_rx);
|
||||
radio.setCtcss(pl_rx);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/* Hamshield
|
||||
* Example: DTMF
|
||||
* This is a simple example to demonstrate how to ues DTMF.
|
||||
* This is a simple example to demonstrate how to use DTMF.
|
||||
*
|
||||
* Connect the HamShield to your Arduino. Screw the antenna
|
||||
* into the HamShield RF jack.
|
||||
* Connect the Arduino to wall power and then to your computer
|
||||
* via USB. After uploading this program to your Arduino, open
|
||||
* the Serial Monitor. Press the button on the HamShield to
|
||||
* the Serial Monitor. Press the switch on the HamShield to
|
||||
* begin setup. After setup is complete, type in a DTMF value
|
||||
* (0-9, A, B, C, D, *, #) and hit enter. The corresponding
|
||||
* DTMF tones will be transmitted. The sketch will also print
|
||||
@@ -45,7 +45,7 @@ void setup() {
|
||||
|
||||
while (digitalRead(SWITCH_PIN));
|
||||
|
||||
// let the AU ot of reset
|
||||
// now we let the AU ot of reset
|
||||
digitalWrite(RESET_PIN, HIGH);
|
||||
delay(5); // wait for device to come up
|
||||
|
||||
@@ -56,7 +56,7 @@ void setup() {
|
||||
Serial.println(radio.testConnection() ? "HamShield connection successful" : "HamShield connection failed");
|
||||
|
||||
// initialize device
|
||||
radio.initialize(); // initializes automatically for UHF 12.5kHz channel
|
||||
radio.initialize();
|
||||
|
||||
Serial.println("setting default Radio configuration");
|
||||
|
||||
@@ -71,11 +71,11 @@ void setup() {
|
||||
radio.setSQOn();
|
||||
//radio.setSQOff();
|
||||
|
||||
Serial.println("changing frequency");
|
||||
Serial.println("setting frequency to: ");
|
||||
freq = 420000;
|
||||
radio.frequency(freq);
|
||||
Serial.print("new frequency: ");
|
||||
Serial.println(radio.getFrequency());
|
||||
Serial.print(radio.getFrequency());
|
||||
Serial.println("kHz");
|
||||
|
||||
// set RX volume to minimum to reduce false positives on DTMF rx
|
||||
radio.setVolume1(6);
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
// create object for radio
|
||||
HamShield radio;
|
||||
// To use non-standard pins, use the following initialization
|
||||
//HamShield radio(ncs_pin, clk_pin, dat_pin);
|
||||
|
||||
#define LED_PIN 13
|
||||
#define RSSI_REPORT_RATE_MS 5000
|
||||
@@ -50,9 +52,10 @@ void setup() {
|
||||
|
||||
// initialize serial communication
|
||||
Serial.begin(9600);
|
||||
Serial.println("press the switch to begin...");
|
||||
Serial.println("press the switch or send any character to begin...");
|
||||
|
||||
while (digitalRead(SWITCH_PIN));
|
||||
while (digitalRead(SWITCH_PIN) && !Serial.available());
|
||||
Serial.read(); // flush
|
||||
|
||||
// let the AU ot of reset
|
||||
digitalWrite(RESET_PIN, HIGH);
|
||||
|
||||
@@ -8,6 +8,11 @@
|
||||
* power and then to your computer via USB. Issue commands
|
||||
* via the KISS equipment.
|
||||
*
|
||||
* You can also just use the serial terminal to send and receive
|
||||
* APRS packets, but keep in mind that several fields in the packet
|
||||
* are bit-shifted from standard ASCII (so if you're receiving,
|
||||
* you won't get human readable callsigns or paths).
|
||||
*
|
||||
* To use the KISS example with YAAC:
|
||||
* 1. open the configure YAAC wizard
|
||||
* 2. follow the prompts and enter in your details until you get to the "Add and Configure Interfaces" window
|
||||
@@ -55,9 +60,9 @@ void setup() {
|
||||
radio.setVolume2(0xFF);
|
||||
radio.setSQHiThresh(-100);
|
||||
radio.setSQLoThresh(-100);
|
||||
radio.setSQOn();
|
||||
//radio.setSQOn();
|
||||
radio.frequency(144390);
|
||||
//radio.bypassPreDeEmph();
|
||||
radio.bypassPreDeEmph();
|
||||
|
||||
dds.start();
|
||||
afsk.start(&dds);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name=HamShield
|
||||
version=1.1.0
|
||||
version=1.1.2
|
||||
author=Morgan Redfield <morgan@enhancedradio.com>, Casey Halverson <casey@enhancedradio.com>
|
||||
maintainer=Morgan Redfield <morgan@enhancedradio.com>
|
||||
sentence=A library for use with HamShield by Enhanced Radio Devices.
|
||||
|
||||
@@ -3,16 +3,21 @@
|
||||
// 11/22/2013 by Morgan Redfield <redfieldm@gmail.com>
|
||||
// 04/26/2015 various changes Casey Halverson <spaceneedle@gmail.com>
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "HamShield.h"
|
||||
#include <avr/wdt.h>
|
||||
#include "stdint.h"
|
||||
#include "math.h"
|
||||
|
||||
#if defined(__AVR__)
|
||||
#include <avr/pgmspace.h>
|
||||
// #include <PCM.h>
|
||||
#define MORSE_TABLE_PROGMEM
|
||||
#else
|
||||
// get rid of progmem for now and just put these tables in flash/program space
|
||||
#define PROGMEM
|
||||
#endif
|
||||
|
||||
|
||||
/* don't change this regulatory value, use dangerMode() and safeMode() instead */
|
||||
|
||||
bool restrictions = true;
|
||||
HamShield *HamShield::sHamShield = NULL;
|
||||
|
||||
/* channel lookup tables */
|
||||
|
||||
@@ -33,7 +38,6 @@ unsigned int morse_dot_millis = 100;
|
||||
// It will occupy 108 bytes of memory (or program memory if defined)
|
||||
|
||||
#define MORSE_TABLE_LENGTH 54
|
||||
#define MORSE_TABLE_PROGMEM
|
||||
#ifndef MORSE_TABLE_PROGMEM
|
||||
const struct asciiMorse {
|
||||
char ascii;
|
||||
@@ -115,45 +119,20 @@ const unsigned char AFSK_mark[] PROGMEM = { 154, 249, 91, 11, 205, 216, 25, 68,
|
||||
const unsigned char AFSK_space[] PROGMEM = { 140, 228, 250, 166, 53, 0, 53, 166, 249, 230, 128, 24, 7, 88, 203, 255, 203, 88, 7, 24, 128, 230, 249, 167, 53, 0, 53, 167, 249, 230, 128, 24, 6, 88, 202, 255, 202, 88, 6, 24, 127, 231, 249, 167, 52, 0, 52, 167, 248, 231, 127, 25, 6, 89, 202, 255, 202, 89, 6, 25, 127, 231, 248, 167, 53, 0, 54, 165, 251, 227, 133, 14};
|
||||
|
||||
|
||||
/* Aux button variables */
|
||||
|
||||
volatile int ptt = false;
|
||||
volatile long bouncer = 0;
|
||||
|
||||
/** Default constructor, uses default I2C address.
|
||||
* @see A1846S_DEFAULT_ADDRESS
|
||||
*/
|
||||
HamShield::HamShield() {
|
||||
devAddr = A1; // devAddr is the chip select pin used by the HamShield
|
||||
sHamShield = this;
|
||||
|
||||
pinMode(devAddr, OUTPUT);
|
||||
digitalWrite(devAddr, HIGH);
|
||||
pinMode(CLK, OUTPUT);
|
||||
digitalWrite(CLK, HIGH);
|
||||
pinMode(DAT, OUTPUT);
|
||||
digitalWrite(DAT, HIGH);
|
||||
}
|
||||
|
||||
/** Specific address constructor.
|
||||
* @param chip select pin for HamShield
|
||||
* @see A1846S_DEFAULT_ADDRESS
|
||||
* @see A1846S_ADDRESS_AD0_LOW
|
||||
* @see A1846S_ADDRESS_AD0_HIGH
|
||||
*/
|
||||
HamShield::HamShield(uint8_t cs_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;
|
||||
|
||||
pinMode(devAddr, OUTPUT);
|
||||
digitalWrite(devAddr, HIGH);
|
||||
pinMode(CLK, OUTPUT);
|
||||
digitalWrite(CLK, HIGH);
|
||||
pinMode(DAT, OUTPUT);
|
||||
digitalWrite(DAT, HIGH);
|
||||
HSsetPins(cs_pin, clk_pin, dat_pin);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Power on and prepare for general usage.
|
||||
*
|
||||
*/
|
||||
@@ -221,13 +200,13 @@ void HamShield::initialize(bool narrowBand) {
|
||||
// calibration
|
||||
tx_data = 0x00A4;
|
||||
HSwriteWord(devAddr, 0x30, tx_data);
|
||||
delay(100);
|
||||
HSdelay(100);
|
||||
tx_data = 0x00A6;
|
||||
HSwriteWord(devAddr, 0x30, tx_data);
|
||||
delay(100);
|
||||
HSdelay(100);
|
||||
tx_data = 0x0006;
|
||||
HSwriteWord(devAddr, 0x30, tx_data);
|
||||
delay(100);
|
||||
HSdelay(100);
|
||||
|
||||
|
||||
// set band width
|
||||
@@ -237,7 +216,7 @@ void HamShield::initialize(bool narrowBand) {
|
||||
setupWideBand();
|
||||
}
|
||||
|
||||
delay(100);
|
||||
HSdelay(100);
|
||||
|
||||
/*
|
||||
// setup default values
|
||||
@@ -425,15 +404,9 @@ bool HamShield::testConnection() {
|
||||
* to 7FH, and then write value to the address subtracted by
|
||||
* 80H. Finally write 0x0000 to 7FH
|
||||
* Example: writing 85H register address is 0x001F .
|
||||
* Move 7FH 0x0001{
|
||||
|
||||
}
|
||||
* Move 05H 0x001F{
|
||||
|
||||
} 05H=85H-80H
|
||||
* Move 7FH 0x0000{
|
||||
|
||||
}
|
||||
* Move 7FH 0x0001{}
|
||||
* Move 05H 0x001F{} 05H=85H-80H
|
||||
* Move 7FH 0x0000{}
|
||||
*/
|
||||
|
||||
uint16_t HamShield::readCtlReg() {
|
||||
@@ -444,7 +417,7 @@ uint16_t HamShield::readCtlReg() {
|
||||
void HamShield::softReset() {
|
||||
uint16_t tx_data = 0x1;
|
||||
HSwriteWord(devAddr, A1846S_CTL_REG, tx_data);
|
||||
delay(100); // Note: see A1846S setup info for timing guidelines
|
||||
HSdelay(100); // Note: see A1846S setup info for timing guidelines
|
||||
tx_data = 0x4;
|
||||
HSwriteWord(devAddr, A1846S_CTL_REG, tx_data);
|
||||
}
|
||||
@@ -568,7 +541,7 @@ void HamShield::setTX(bool on_noff){
|
||||
//setGpioHi(4); // V1
|
||||
|
||||
|
||||
delay(50); // delay required by AU1846
|
||||
HSdelay(50); // delay required by AU1846
|
||||
}
|
||||
|
||||
HSwriteBitW(devAddr, A1846S_CTL_REG, A1846S_TX_MODE_BIT, on_noff);
|
||||
@@ -590,7 +563,7 @@ void HamShield::setRX(bool on_noff){
|
||||
setGpioLow(4); // V1
|
||||
setGpioLow(5); // V2
|
||||
|
||||
delay(50); // delay required by AU1846
|
||||
HSdelay(50); // delay required by AU1846
|
||||
}
|
||||
|
||||
HSwriteBitW(devAddr, A1846S_CTL_REG, A1846S_RX_MODE_BIT, on_noff);
|
||||
@@ -938,20 +911,19 @@ bool HamShield::getVoxOn(){
|
||||
// Vox Threshold
|
||||
void HamShield::setVoxOpenThresh(uint16_t vox_open_thresh){
|
||||
// When vssi > th_h_vox, then vox will be 1(unit mV )
|
||||
HSwriteWord(devAddr, A1846S_TH_H_VOX_REG, vox_open_thresh);
|
||||
HSwriteBitsW(devAddr, A1846S_TH_H_VOX_REG, A1846S_TH_H_VOX_BIT, A1846S_TH_H_VOX_LEN, vox_open_thresh);
|
||||
|
||||
}
|
||||
uint16_t HamShield::getVoxOpenThresh(){
|
||||
HSreadWord(devAddr, A1846S_TH_H_VOX_REG, radio_i2c_buf);
|
||||
|
||||
HSreadBitsW(devAddr, A1846S_TH_H_VOX_REG, A1846S_TH_H_VOX_BIT, A1846S_TH_H_VOX_LEN, radio_i2c_buf);
|
||||
return radio_i2c_buf[0];
|
||||
}
|
||||
void HamShield::setVoxShutThresh(uint16_t vox_shut_thresh){
|
||||
// When vssi < th_l_vox && time delay meet, then vox will be 0 (unit mV )
|
||||
HSwriteWord(devAddr, A1846S_TH_L_VOX_REG, vox_shut_thresh);
|
||||
HSwriteBitsW(devAddr, A1846S_TH_L_VOX_REG, A1846S_TH_L_VOX_BIT, A1846S_TH_L_VOX_LEN, vox_shut_thresh);
|
||||
}
|
||||
uint16_t HamShield::getVoxShutThresh(){
|
||||
HSreadWord(devAddr, A1846S_TH_L_VOX_REG, radio_i2c_buf);
|
||||
|
||||
HSreadBitsW(devAddr, A1846S_TH_L_VOX_REG, A1846S_TH_L_VOX_BIT, A1846S_TH_L_VOX_LEN, radio_i2c_buf);
|
||||
return radio_i2c_buf[0];
|
||||
}
|
||||
|
||||
@@ -1095,10 +1067,10 @@ void HamShield::lookForTone(uint16_t t_hz) {
|
||||
float tone_hz = (float) t_hz;
|
||||
float Fs = 6400000/1024;
|
||||
float k = floor(tone_hz/Fs*127 + 0.5);
|
||||
uint16_t t = (uint16_t) (round(2.0*cos(2.0*PI*k/127)*1024));
|
||||
uint16_t t = (uint16_t) (round(2.0*cos(2.0*M_PI*k/127)*1024));
|
||||
|
||||
float k2 = floor(2*tone_hz/Fs*127+0.5);
|
||||
uint16_t h = (uint16_t) (round(2.0*cos(2.0*PI*k2/127)*1024));
|
||||
uint16_t h = (uint16_t) (round(2.0*cos(2.0*M_PI*k2/127)*1024));
|
||||
// set tone
|
||||
HSwriteWord(devAddr, 0x68, t);
|
||||
|
||||
@@ -1295,9 +1267,14 @@ int16_t HamShield::readRSSI(){
|
||||
return rssi;
|
||||
}
|
||||
uint16_t HamShield::readVSSI(){
|
||||
HSreadWord(devAddr, A1846S_VSSI_REG, radio_i2c_buf);
|
||||
HSreadBitsW(devAddr, A1846S_VSSI_REG, A1846S_VSSI_BIT, A1846S_VSSI_LENGTH, radio_i2c_buf);
|
||||
|
||||
return radio_i2c_buf[0] & 0x7FF; // only need lowest 10 bits
|
||||
return radio_i2c_buf[0];
|
||||
}
|
||||
uint16_t HamShield::readMSSI(){
|
||||
HSreadBitsW(devAddr, A1846S_VSSI_REG, A1846S_MSSI_BIT, A1846S_MSSI_LENGTH, radio_i2c_buf);
|
||||
|
||||
return radio_i2c_buf[0];
|
||||
}
|
||||
|
||||
|
||||
@@ -1343,7 +1320,7 @@ bool HamShield::frequency(uint32_t freq_khz) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HamShield::frequency(float freq_khz) {
|
||||
bool HamShield::frequency_float(float freq_khz) {
|
||||
|
||||
if((freq_khz >= 134000) && (freq_khz <= 174000)) {
|
||||
setTxBand2m();
|
||||
@@ -1395,7 +1372,11 @@ bool HamShield::frequency(float freq_khz) {
|
||||
|
||||
bool HamShield::setFRSChannel(uint8_t channel) {
|
||||
if(channel < 15) {
|
||||
#if defined(__AVR__)
|
||||
setFrequency(pgm_read_dword_near(FRS + channel));
|
||||
#else
|
||||
setFrequency(FRS[channel]);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -1406,11 +1387,19 @@ bool HamShield::setFRSChannel(uint8_t channel) {
|
||||
bool HamShield::setGMRSChannel(uint8_t channel) {
|
||||
if((channel > 8) & (channel < 16)) {
|
||||
channel = channel - 7; // we start with 0, to try to avoid channel 8 being nothing
|
||||
setFrequency(pgm_read_dword_near(FRS + channel));
|
||||
#if defined(__AVR__)
|
||||
setFrequency(pgm_read_dword_near(FRS + channel));
|
||||
#else
|
||||
setFrequency(FRS[channel]);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
if(channel < 9) {
|
||||
setFrequency(pgm_read_dword_near(GMRS + channel));
|
||||
#if defined(__AVR__)
|
||||
setFrequency(pgm_read_dword_near(GMRS + channel));
|
||||
#else
|
||||
setFrequency(GMRS[channel]);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -1420,7 +1409,11 @@ bool HamShield::setGMRSChannel(uint8_t channel) {
|
||||
|
||||
bool HamShield::setMURSChannel(uint8_t channel) {
|
||||
if(channel < 6) {
|
||||
setFrequency(pgm_read_dword_near(MURS + channel));
|
||||
#if defined(__AVR__)
|
||||
setFrequency(pgm_read_dword_near(MURS + channel));
|
||||
#else
|
||||
setFrequency(MURS[channel]);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1429,7 +1422,11 @@ bool HamShield::setMURSChannel(uint8_t channel) {
|
||||
|
||||
bool HamShield::setWXChannel(uint8_t channel) {
|
||||
if(channel < 8) {
|
||||
setFrequency(pgm_read_dword_near(WX + channel));
|
||||
#if defined(__AVR__)
|
||||
setFrequency(pgm_read_dword_near(WX + channel));
|
||||
#else
|
||||
setFrequency(WX[channel]);
|
||||
#endif
|
||||
setModeReceive();
|
||||
// turn off squelch?
|
||||
// channel bandwidth?
|
||||
@@ -1445,7 +1442,7 @@ uint8_t HamShield::scanWXChannel() {
|
||||
int16_t toprssi = 0;
|
||||
for(int x = 0; x < 8; x++) {
|
||||
setWXChannel(x);
|
||||
delay(100);
|
||||
HSdelay(100);
|
||||
int16_t rssi = readRSSI();
|
||||
if(rssi > toprssi) { toprssi = rssi; channel = x; }
|
||||
}
|
||||
@@ -1537,39 +1534,6 @@ uint32_t HamShield::findWhitespaceChannels(uint32_t buffer[],uint8_t buffsize, u
|
||||
}
|
||||
|
||||
|
||||
/* Setup the auxiliary button input mode and register the ISR */
|
||||
void HamShield::buttonMode(uint8_t mode) {
|
||||
pinMode(HAMSHIELD_AUX_BUTTON,INPUT); // set the pin mode to input
|
||||
digitalWrite(HAMSHIELD_AUX_BUTTON,HIGH); // turn on internal pull up
|
||||
if(mode == PTT_MODE) { attachInterrupt(HAMSHIELD_AUX_BUTTON, HamShield::isr_ptt, CHANGE); }
|
||||
if(mode == RESET_MODE) { attachInterrupt(HAMSHIELD_AUX_BUTTON, HamShield::isr_reset, CHANGE); }
|
||||
}
|
||||
|
||||
/* Interrupt routines */
|
||||
|
||||
/* handle aux button to reset condition */
|
||||
|
||||
void HamShield::isr_reset() {
|
||||
wdt_enable(WDTO_15MS);
|
||||
while(1) { }
|
||||
}
|
||||
|
||||
/* Transmit on press, receive on release. We need debouncing !! */
|
||||
|
||||
void HamShield::isr_ptt() {
|
||||
if((bouncer + 200) > millis()) {
|
||||
if(ptt == false) {
|
||||
ptt = true;
|
||||
sHamShield->setModeTransmit();
|
||||
bouncer = millis();
|
||||
}
|
||||
if(ptt == true) {
|
||||
ptt = false;
|
||||
sHamShield->setModeReceive();
|
||||
bouncer = millis();
|
||||
} }
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Radio etiquette function: Wait for empty channel.
|
||||
@@ -1584,13 +1548,13 @@ Does not take in account the millis() overflow
|
||||
bool HamShield::waitForChannel(long timeout = 0, long breakwindow = 0, int setRSSI = HAMSHIELD_EMPTY_CHANNEL_RSSI) {
|
||||
int16_t rssi = 0; // Set RSSI to max received signal
|
||||
for(int x = 0; x < 20; x++) { rssi = readRSSI(); } // "warm up" to get past RSSI hysteresis
|
||||
long timer = millis() + timeout; // Setup the timeout value
|
||||
long timer = HSmillis() + timeout; // Setup the timeout value
|
||||
if(timeout == 0) { timer = 4294967295; } // If we want to wait forever, set it to the max millis()
|
||||
while(timer > millis()) { // while our timer is not timed out.
|
||||
while(timer > HSmillis()) { // while our timer is not timed out.
|
||||
rssi = readRSSI(); // Read signal strength
|
||||
if(rssi < setRSSI) { // If the channel is empty, lets see if anyone breaks in.
|
||||
timer = millis() + breakwindow;
|
||||
while(timer > millis()) {
|
||||
timer = HSmillis() + breakwindow;
|
||||
while(timer > HSmillis()) {
|
||||
rssi = readRSSI();
|
||||
if(rssi > setRSSI) { return false; } // Someone broke into the channel, abort.
|
||||
} return true; // It passed the test...channel is open.
|
||||
@@ -1634,13 +1598,13 @@ void HamShield::morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]) {
|
||||
// We delay by 4 here, if we previously sent a symbol. Otherwise 7.
|
||||
// This could probably just be always 7 and go relatively unnoticed.
|
||||
if(prev == 0 || prev == ' '){
|
||||
//tone(HAMSHIELD_PWM_PIN, 6000, morse_dot_millis * 7);
|
||||
noTone(HAMSHIELD_PWM_PIN);
|
||||
delay(morse_dot_millis*7);
|
||||
//tone(hs_pwm_pin, 6000, morse_dot_millis * 7);
|
||||
HSnoTone(hs_pwm_pin);
|
||||
HSdelay(morse_dot_millis*7);
|
||||
} else {
|
||||
//tone(HAMSHIELD_PWM_PIN, 6000, morse_dot_millis * 4);
|
||||
noTone(HAMSHIELD_PWM_PIN);
|
||||
delay(morse_dot_millis*4);
|
||||
//tone(hs_pwm_pin, 6000, morse_dot_millis * 4);
|
||||
HSnoTone(hs_pwm_pin);
|
||||
HSdelay(morse_dot_millis*4);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -1649,22 +1613,24 @@ void HamShield::morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]) {
|
||||
if(bits) { // If it is a valid character...
|
||||
do {
|
||||
if(bits & 1) {
|
||||
tone(HAMSHIELD_PWM_PIN, morse_freq, morse_dot_millis * 3);
|
||||
delay(morse_dot_millis*3);
|
||||
HStone(hs_pwm_pin, morse_freq); //, morse_dot_millis * 3);
|
||||
HSdelay(morse_dot_millis*3);
|
||||
HSnoTone(hs_pwm_pin);
|
||||
} else {
|
||||
tone(HAMSHIELD_PWM_PIN, morse_freq, morse_dot_millis);
|
||||
delay(morse_dot_millis);
|
||||
HStone(hs_pwm_pin, morse_freq); //, morse_dot_millis);
|
||||
HSdelay(morse_dot_millis);
|
||||
HSnoTone(hs_pwm_pin);
|
||||
}
|
||||
//tone(HAMSHIELD_PWM_PIN, 6000, morse_dot_millis);
|
||||
noTone(HAMSHIELD_PWM_PIN);
|
||||
delay(morse_dot_millis);
|
||||
//tone(hs_pwm_pin, 6000, morse_dot_millis);
|
||||
HSnoTone(hs_pwm_pin);
|
||||
HSdelay(morse_dot_millis);
|
||||
bits >>= 1; // Shift into the next symbol
|
||||
} while(bits != 1); // Wait for 1 termination to be all we have left
|
||||
}
|
||||
// End of character
|
||||
//tone(HAMSHIELD_PWM_PIN, 6000, morse_dot_millis * 3);
|
||||
noTone(HAMSHIELD_PWM_PIN);
|
||||
delay(morse_dot_millis * 3);
|
||||
//tone(hs_pwm_pin, 6000, morse_dot_millis * 3);
|
||||
HSnoTone(hs_pwm_pin);
|
||||
HSdelay(morse_dot_millis * 3);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -1731,7 +1697,7 @@ void HamShield::SSTVVISCode(int code) {
|
||||
toneWait(1900,300);
|
||||
toneWait(1200,30);
|
||||
for(int x = 0; x < 7; x++) {
|
||||
if(bitRead(code,x)) { toneWait(1100,30); } else { toneWait(1300,30); }
|
||||
if(code&(1<<x)) { toneWait(1100,30); } else { toneWait(1300,30); }
|
||||
}
|
||||
if(parityCalc(code)) { toneWait(1300,30); } else { toneWait(1100,30); }
|
||||
toneWait(1200,30);
|
||||
@@ -1794,19 +1760,20 @@ void HamShield::SSTVTestPattern(int code) {
|
||||
/* wait for tone to complete */
|
||||
|
||||
void HamShield::toneWait(uint16_t freq, long timer) {
|
||||
tone(HAMSHIELD_PWM_PIN,freq,timer);
|
||||
delay(timer);
|
||||
HStone(hs_pwm_pin,freq); //,timer);
|
||||
HSdelay(timer);
|
||||
HSnoTone(hs_pwm_pin);
|
||||
}
|
||||
|
||||
/* wait microseconds for tone to complete */
|
||||
|
||||
void HamShield::toneWaitU(uint16_t freq, long timer) {
|
||||
if(freq < 16383) {
|
||||
tone(HAMSHIELD_PWM_PIN,freq);
|
||||
delayMicroseconds(timer); noTone(HAMSHIELD_PWM_PIN); return;
|
||||
HStone(hs_pwm_pin,freq);
|
||||
HSdelayMicroseconds(timer); HSnoTone(hs_pwm_pin); return;
|
||||
}
|
||||
tone(HAMSHIELD_PWM_PIN,freq);
|
||||
delay(timer / 1000); noTone(HAMSHIELD_PWM_PIN); return;
|
||||
HStone(hs_pwm_pin,freq);
|
||||
HSdelay(timer / 1000); HSnoTone(hs_pwm_pin); return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1822,21 +1789,3 @@ bool HamShield::parityCalc(int code) {
|
||||
|
||||
return parity;
|
||||
}
|
||||
/*
|
||||
void HamShield::AFSKOut(char buffer[80]) {
|
||||
for(int x = 0; x < 65536; x++) {
|
||||
startPlayback(AFSK_mark, sizeof(AFSK_mark)); delay(8);
|
||||
startPlayback(AFSK_space, sizeof(AFSK_space)); delay(8); }
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
// This is the ADC timer handler. When enabled, we'll see what we're supposed
|
||||
// to be reading/handling, and trigger those on the main object.
|
||||
/*ISR(ADC_vect) {
|
||||
TIFR1 = _BV(ICF1); // Clear the timer flag
|
||||
|
||||
if(HamShield::sHamShield->afsk.enabled()) {
|
||||
HamShield::sHamShield->afsk.timer();
|
||||
}
|
||||
}*/
|
||||
|
||||
@@ -9,22 +9,12 @@
|
||||
#define _HAMSHIELD_H_
|
||||
|
||||
#include "HamShield_comms.h"
|
||||
//#include "SimpleFIFO.h"
|
||||
//#include "AFSK.h"
|
||||
//#include "DDS.h"
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
// HamShield constants
|
||||
|
||||
#define HAMSHIELD_MORSE_BUFFER_SIZE 80 // Char buffer size for morse code text
|
||||
#define HAMSHIELD_AUX_BUTTON 2 // Pin assignment for AUX button
|
||||
#define HAMSHIELD_PWM_PIN 3 // Pin assignment for PWM output
|
||||
#define HAMSHIELD_EMPTY_CHANNEL_RSSI -110 // Default threshold where channel is considered "clear"
|
||||
|
||||
// button modes
|
||||
#define PTT_MODE 1
|
||||
#define RESET_MODE 2
|
||||
|
||||
// Device Registers
|
||||
#define A1846S_CTL_REG 0x30 // control register
|
||||
#define A1846S_CLK_MODE_REG 0x04 // clk_mode
|
||||
@@ -38,8 +28,8 @@
|
||||
//#define A1846S_ADCLK_FREQ_REG 0x2C // adclk_freq<15:0>
|
||||
#define A1846S_INT_MODE_REG 0x2D // interrupt enables
|
||||
#define A1846S_TX_VOICE_REG 0x3A // tx voice control reg
|
||||
#define A1846S_TH_H_VOX_REG 0x41 // register holds vox high (open) threshold bits
|
||||
#define A1846S_TH_L_VOX_REG 0x42 // register holds vox low (shut) threshold bits
|
||||
#define A1846S_TH_H_VOX_REG 0x64 // register holds vox high (open) threshold bits
|
||||
#define A1846S_TH_L_VOX_REG 0x64 // register holds vox low (shut) threshold bits
|
||||
#define A1846S_FM_DEV_REG 0x43 // register holds fm deviation settings
|
||||
#define A1846S_RX_VOLUME_REG 0x44 // register holds RX volume settings
|
||||
#define A1846S_SQ_OPEN_THRESH_REG 0x48 // see sq
|
||||
@@ -115,7 +105,7 @@
|
||||
#define A1846S_TXON_RF_INT_BIT 7 // txon_rf_uint16_t enable
|
||||
#define A1846S_CTCSS_PHASE_INT_BIT 5 // ctcss phase shift detect uint16_t enable
|
||||
#define A1846S_IDLE_TIMEOUT_INT_BIT 4 // idle state time out uint16_t enable
|
||||
#define A1846S_RXON_RF_TIMeOUT_INT_BIT 3 // rxon_rf timerout uint16_t enable
|
||||
#define A1846S_RXON_RF_TIMEOUT_INT_BIT 3 // rxon_rf timerout uint16_t enable
|
||||
#define A1846S_SQ_INT_BIT 2 // sq uint16_t enable
|
||||
#define A1846S_TXON_RF_TIMEOUT_INT_BIT 1 // txon_rf time out uint16_t enable
|
||||
#define A1846S_VOX_INT_BIT 0 // vox uint16_t enable
|
||||
@@ -126,8 +116,12 @@
|
||||
#define A1846S_CTCSS_DET_BIT 5
|
||||
|
||||
// Bitfields for A1846S_TH_H_VOX_REG
|
||||
#define A1846S_TH_H_VOX_BIT 14 // th_h_vox<14:0>
|
||||
#define A1846S_TH_H_VOX_LENGTH 15
|
||||
#define A1846S_TH_H_VOX_BIT 13 // th_h_vox<13:7>
|
||||
#define A1846S_TH_H_VOX_LEN 7
|
||||
|
||||
// Bitfields for A1846S_TH_L_VOX_REG
|
||||
#define A1846S_TH_L_VOX_BIT 6 // th_l_vox<6:0>
|
||||
#define A1846S_TH_L_VOX_LEN 7
|
||||
|
||||
// Bitfields for A1846S_FM_DEV_REG
|
||||
#define A1846S_FM_DEV_VOICE_BIT 12 // CTCSS/CDCSS and voice deviation <6:0>
|
||||
@@ -182,8 +176,10 @@
|
||||
#define A1846S_RSSI_LENGTH 8
|
||||
|
||||
// Bitfields for A1846S_VSSI_REG
|
||||
#define A1846S_VSSI_BIT 14 // voice signal strength indicator <14:0> (unit mV)
|
||||
#define A1846S_VSSI_LENGTH 15
|
||||
#define A1846S_VSSI_BIT 15 // voice signal strength indicator <7:0> (unit 0.5dB)
|
||||
#define A1846S_VSSI_LENGTH 8
|
||||
#define A1846S_MSSI_BIT 7 // mic signal strength <7:0> (unit 0.5 dB)
|
||||
#define A1846S_MSSI_LENGTH 8
|
||||
|
||||
// Bitfields for A1846S_DTMF_ENABLE_REG
|
||||
#define A1846S_DTMF_ENABLE_BIT 15
|
||||
@@ -224,11 +220,7 @@
|
||||
|
||||
class HamShield {
|
||||
public:
|
||||
// public singleton for ISRs to reference
|
||||
static HamShield *sHamShield; // HamShield singleton, used for ISRs mostly
|
||||
|
||||
HamShield();
|
||||
HamShield(uint8_t cs_pin);
|
||||
HamShield(uint8_t cs_pin = nSEN, uint8_t clk_pin = CLK, uint8_t dat_pin = DAT, uint8_t pwm_pin = HAMSHIELD_PWM_PIN);
|
||||
|
||||
void initialize(); // defaults to 12.5kHz
|
||||
void initialize(bool narrowBand); // select 12.5kHz if true or 25kHz if false
|
||||
@@ -245,16 +237,18 @@ class HamShield {
|
||||
void safeMode();
|
||||
|
||||
bool frequency(uint32_t freq_khz);
|
||||
bool frequency(float freq_khz);
|
||||
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
|
||||
@@ -273,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
|
||||
@@ -285,6 +280,7 @@ class HamShield {
|
||||
// 1111111:3.13V
|
||||
void setPABiasVoltage(uint16_t voltage);
|
||||
uint16_t getPABiasVoltage();
|
||||
*/
|
||||
|
||||
// Subaudio settings
|
||||
|
||||
@@ -466,6 +462,7 @@ class HamShield {
|
||||
// Read Only Status Registers
|
||||
int16_t readRSSI();
|
||||
uint16_t readVSSI();
|
||||
uint16_t readMSSI();
|
||||
|
||||
// set output power of radio
|
||||
void setRfPower(uint8_t pwr);
|
||||
@@ -482,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();
|
||||
@@ -503,6 +498,7 @@ class HamShield {
|
||||
|
||||
private:
|
||||
uint8_t devAddr;
|
||||
uint8_t hs_pwm_pin;
|
||||
uint16_t radio_i2c_buf[4];
|
||||
bool tx_active;
|
||||
bool rx_active;
|
||||
|
||||
@@ -4,6 +4,28 @@
|
||||
|
||||
#include "HamShield_comms.h"
|
||||
|
||||
uint8_t ncs_pin = nSEN;
|
||||
uint8_t clk_pin = CLK;
|
||||
uint8_t dat_pin = DAT;
|
||||
|
||||
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);
|
||||
pinMode(clk_pin, OUTPUT);
|
||||
digitalWrite(clk_pin, HIGH);
|
||||
pinMode(dat_pin, OUTPUT);
|
||||
digitalWrite(dat_pin, HIGH);
|
||||
|
||||
}
|
||||
|
||||
int8_t HSreadBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data)
|
||||
{
|
||||
uint16_t b;
|
||||
@@ -33,22 +55,22 @@ int8_t HSreadWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data)
|
||||
uint16_t temp_dat;
|
||||
// bitbang for great justice!
|
||||
*data = 0;
|
||||
pinMode(DAT, OUTPUT);
|
||||
pinMode(dat_pin, OUTPUT);
|
||||
regAddr = regAddr | (1 << 7);
|
||||
|
||||
digitalWrite(devAddr, 0); //PORTC &= ~(1<<1); //devAddr used as chip select
|
||||
for (int i = 0; i < 8; i++) {
|
||||
temp = ((regAddr & (0x80 >> i)) != 0);
|
||||
digitalWrite(CLK, 0); //PORTC &= ~(1<<5); //
|
||||
digitalWrite(DAT, temp);
|
||||
digitalWrite(CLK, 1); //PORTC |= (1<<5); //
|
||||
digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); //
|
||||
digitalWrite(dat_pin, temp);
|
||||
digitalWrite(clk_pin, 1); //PORTC |= (1<<5); //
|
||||
}
|
||||
// change direction of DAT
|
||||
pinMode(DAT, INPUT); // DDRC &= ~(1<<4); //
|
||||
// change direction of dat_pin
|
||||
pinMode(dat_pin, INPUT); // DDRC &= ~(1<<4); //
|
||||
for (int i = 15; i >= 0; i--) {
|
||||
digitalWrite(CLK, 0); //PORTC &= ~(1<<5); //
|
||||
digitalWrite(CLK, 1); //PORTC |= (1<<5); //
|
||||
temp_dat = digitalRead(DAT); //((PINC & (1<<4)) != 0);
|
||||
digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); //
|
||||
digitalWrite(clk_pin, 1); //PORTC |= (1<<5); //
|
||||
temp_dat = digitalRead(dat_pin); //((PINC & (1<<4)) != 0);
|
||||
temp_dat = temp_dat << i;
|
||||
*data |= temp_dat;
|
||||
}
|
||||
@@ -91,24 +113,51 @@ bool HSwriteWord(uint8_t devAddr, uint8_t regAddr, uint16_t data)
|
||||
//digitalWrite(13, HIGH);
|
||||
|
||||
// bitbang for great justice!
|
||||
pinMode(DAT, OUTPUT);
|
||||
pinMode(dat_pin, OUTPUT);
|
||||
regAddr = regAddr & ~(1 << 7);
|
||||
|
||||
digitalWrite(devAddr, 0); // PORTC &= ~(1<<1); //CS
|
||||
for (int i = 0; i < 8; i++) {
|
||||
temp_reg = ((regAddr & (0x80 >> i)) != 0);
|
||||
digitalWrite(CLK, 0); //PORTC &= ~(1<<5); //
|
||||
digitalWrite(DAT, regAddr & (0x80 >> i));
|
||||
digitalWrite(CLK, 1); // PORTC |= (1<<5); //
|
||||
digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); //
|
||||
digitalWrite(dat_pin, regAddr & (0x80 >> i));
|
||||
digitalWrite(clk_pin, 1); // PORTC |= (1<<5); //
|
||||
}
|
||||
for (int i = 0; i < 16; i++) {
|
||||
temp_dat = ((data & (0x8000 >> i)) != 0);
|
||||
digitalWrite(CLK, 0); //PORTC &= ~(1<<5); //
|
||||
digitalWrite(DAT, temp_dat);
|
||||
digitalWrite(CLK, 1); // PORTC |= (1<<5); //
|
||||
digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); //
|
||||
digitalWrite(dat_pin, temp_dat);
|
||||
digitalWrite(clk_pin, 1); // PORTC |= (1<<5); //
|
||||
}
|
||||
|
||||
digitalWrite(devAddr, 1); //PORTC |= (1<<1); //CS
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Hardware abstraction
|
||||
unsigned long HSmillis(){
|
||||
return millis();
|
||||
}
|
||||
void HSdelay(unsigned long ms) {
|
||||
delay(ms);
|
||||
}
|
||||
void HSdelayMicroseconds(unsigned int us) {
|
||||
delayMicroseconds(us);
|
||||
}
|
||||
|
||||
void HStone(uint8_t pin, unsigned int frequency) {
|
||||
#if defined(ARDUINO)
|
||||
tone(pin, frequency);
|
||||
#else
|
||||
softToneCreate(pin);
|
||||
softToneWrite(pin, frequency);
|
||||
#endif
|
||||
}
|
||||
void HSnoTone(uint8_t pin) {
|
||||
#if defined(ARDUINO)
|
||||
noTone(pin);
|
||||
#else
|
||||
softToneWrite(pin, 0);
|
||||
#endif
|
||||
}
|
||||
@@ -4,12 +4,27 @@
|
||||
#ifndef _HAMSHIELD_COMMS_H_
|
||||
#define _HAMSHIELD_COMMS_H_
|
||||
|
||||
#include "Arduino.h"
|
||||
//#include "I2Cdev.h"
|
||||
|
||||
#define nSEN A1
|
||||
#define CLK A5
|
||||
#define DAT A4
|
||||
#if defined(ARDUINO)
|
||||
#include "Arduino.h"
|
||||
|
||||
#define nSEN A1 //15 //
|
||||
#define CLK A5 //19 //
|
||||
#define DAT A4 //18 //
|
||||
#define HAMSHIELD_PWM_PIN 3
|
||||
#else // assume Raspberry Pi
|
||||
#include "stdint.h"
|
||||
#include <wiringPi.h>
|
||||
#include <softTone.h>
|
||||
|
||||
#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
|
||||
|
||||
|
||||
void HSsetPins(uint8_t ncs, uint8_t clk, uint8_t dat);
|
||||
|
||||
int8_t HSreadBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data);
|
||||
int8_t HSreadBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data);
|
||||
@@ -19,4 +34,15 @@ bool HSwriteBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data
|
||||
bool HSwriteBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t data);
|
||||
bool HSwriteWord(uint8_t devAddr, uint8_t regAddr, uint16_t data);
|
||||
|
||||
|
||||
// hardware abstraction layer
|
||||
|
||||
unsigned long HSmillis();
|
||||
void HSdelay(unsigned long ms);
|
||||
void HSdelayMicroseconds(unsigned int us);
|
||||
|
||||
void HStone(uint8_t pin, unsigned int frequency);
|
||||
void HSnoTone(uint8_t pin);
|
||||
|
||||
|
||||
#endif /* _HAMSHIELD_COMMS_H_ */
|
||||
Reference in New Issue
Block a user