diff --git a/HamShield.cpp b/HamShield.cpp index 543fed9..62c0f9b 100644 --- a/HamShield.cpp +++ b/HamShield.cpp @@ -122,10 +122,12 @@ HamShield::HamShield() { devAddr = A1; // devAddr is the chip select pin used by the HamShield sHamShield = this; - pinMode(A1, OUTPUT); - digitalWrite(A1, HIGH); - pinMode(A4, OUTPUT); - pinMode(A5, OUTPUT); + pinMode(devAddr, OUTPUT); + digitalWrite(devAddr, HIGH); + pinMode(CLK, OUTPUT); + digitalWrite(CLK, HIGH); + pinMode(DAT, OUTPUT); + digitalWrite(DAT, HIGH); } /** Specific address constructor. @@ -137,10 +139,12 @@ HamShield::HamShield() { HamShield::HamShield(uint8_t cs_pin) { devAddr = cs_pin; - pinMode(A1, OUTPUT); - digitalWrite(A1, HIGH); - pinMode(A4, OUTPUT); - pinMode(A5, OUTPUT); + pinMode(devAddr, OUTPUT); + digitalWrite(devAddr, HIGH); + pinMode(CLK, OUTPUT); + digitalWrite(CLK, HIGH); + pinMode(DAT, OUTPUT); + digitalWrite(DAT, HIGH); } /** Power on and prepare for general usage. diff --git a/HamShield.h b/HamShield.h index 57d3852..825cb43 100644 --- a/HamShield.h +++ b/HamShield.h @@ -9,9 +9,9 @@ #define _HAMSHIELD_H_ #include "HamShield_comms.h" -#include "SimpleFIFO.h" -#include "AFSK.h" -#include "DDS.h" +//#include "SimpleFIFO.h" +//#include "AFSK.h" +//#include "DDS.h" #include // HamShield constants @@ -491,15 +491,17 @@ class HamShield { void toneWait(uint16_t freq, long timer); void toneWaitU(uint16_t freq, long timer); bool parityCalc(int code); - // void AFSKOut(char buffer[80]); - + + + + //TODO: split AFSK out so it can be left out // AFSK routines - bool AFSKStart(); - bool AFSKEnabled() { return afsk.enabled(); } - bool AFSKStop(); - bool AFSKOut(const char *); + //bool AFSKStart(); + //bool AFSKEnabled() { return afsk.enabled(); } + //bool AFSKStop(); + //bool AFSKOut(const char *); - class AFSK afsk; + //class AFSK afsk; private: uint8_t devAddr; diff --git a/HamShield_comms.cpp b/HamShield_comms.cpp index bbf1381..d3c173d 100644 --- a/HamShield_comms.cpp +++ b/HamShield_comms.cpp @@ -33,54 +33,27 @@ int8_t HSreadWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data) uint16_t temp_dat; // bitbang for great justice! *data = 0; - cli(); - DDRC |= ((1<<5) | (1<<4)); // set direction to output - sei(); + pinMode(DAT, OUTPUT); regAddr = regAddr | (1 << 7); - //cli(); digitalWrite(devAddr, 0); //PORTC &= ~(1<<1); //devAddr used as chip select - //sei(); for (int i = 0; i < 8; i++) { temp = ((regAddr & (0x80 >> i)) != 0); - cli(); - PORTC &= ~(1<<5); //digitalWrite(CLK, 0); - sei(); - //digitalWrite(DAT, regAddr & (0x80 >> i)); - temp = (PORTC & ~(1<<4)) + (temp << 4); - cli(); - PORTC = temp; - sei(); - delayMicroseconds(9); - cli(); - PORTC |= (1<<5); //digitalWrite(CLK, 1); - sei(); - delayMicroseconds(9); + digitalWrite(CLK, 0); //PORTC &= ~(1<<5); // + digitalWrite(DAT, temp); + digitalWrite(CLK, 1); //PORTC |= (1<<5); // } // change direction of DAT - cli(); - DDRC &= ~(1<<4); //pinMode(DAT, INPUT); - sei(); + pinMode(DAT, INPUT); // DDRC &= ~(1<<4); // for (int i = 15; i >= 0; i--) { - cli(); - PORTC &= ~(1<<5); //digitalWrite(CLK, 0); - sei(); - delayMicroseconds(9); - cli(); - PORTC |= (1<<5); //digitalWrite(CLK, 1); - sei(); - cli(); - temp_dat = ((PINC & (1<<4)) != 0); - sei(); + digitalWrite(CLK, 0); //PORTC &= ~(1<<5); // + digitalWrite(CLK, 1); //PORTC |= (1<<5); // + temp_dat = digitalRead(DAT); //((PINC & (1<<4)) != 0); temp_dat = temp_dat << i; - *data |= temp_dat; // digitalRead(DAT); - delayMicroseconds(9); + *data |= temp_dat; } digitalWrite(devAddr, 1); //PORTC |= (1<<1);// CS - cli(); - DDRC &= ~((1<<5) | (1<<4)); // set direction all input (for ADC) - sei(); return 1; } @@ -118,52 +91,24 @@ bool HSwriteWord(uint8_t devAddr, uint8_t regAddr, uint16_t data) //digitalWrite(13, HIGH); // bitbang for great justice! - cli(); - DDRC |= ((1<<5) | (1<<4)); // set direction all output - //PORTC |= (1<<5) & (1<<4); - sei(); + pinMode(DAT, OUTPUT); regAddr = regAddr & ~(1 << 7); - //cli(); digitalWrite(devAddr, 0); // PORTC &= ~(1<<1); //CS - //sei(); for (int i = 0; i < 8; i++) { temp_reg = ((regAddr & (0x80 >> i)) != 0); - cli(); - PORTC &= ~(1<<5); //digitalWrite(CLK, 0); - sei(); - //digitalWrite(DAT, regAddr & (0x80 >> i)); - temp_reg = (PORTC & ~(1<<4)) + (temp_reg << 4); - cli(); - PORTC = temp_reg; - sei(); - delayMicroseconds(8); - cli(); - PORTC |= (1<<5); //digitalWrite(CLK, 1); - sei(); - delayMicroseconds(10); + digitalWrite(CLK, 0); //PORTC &= ~(1<<5); // + digitalWrite(DAT, regAddr & (0x80 >> i)); + digitalWrite(CLK, 1); // PORTC |= (1<<5); // } for (int i = 0; i < 16; i++) { temp_dat = ((data & (0x8000 >> i)) != 0); - cli(); - PORTC &= ~(1<<5); //digitalWrite(CLK, 0); - sei(); - //digitalWrite(DAT, data & (0x80000 >> i)); - temp_reg = (PORTC & ~(1<<4)) + (temp_dat << 4); - cli(); - PORTC = temp_reg; - sei(); - delayMicroseconds(7); - cli(); - PORTC |= (1<<5); //digitalWrite(CLK, 1); - sei(); - delayMicroseconds(10); + digitalWrite(CLK, 0); //PORTC &= ~(1<<5); // + digitalWrite(DAT, temp_dat); + digitalWrite(CLK, 1); // PORTC |= (1<<5); // } digitalWrite(devAddr, 1); //PORTC |= (1<<1); //CS - cli(); - DDRC &= ~((1<<5) | (1<<4)); // set direction to input for ADC - sei(); return true; } \ No newline at end of file diff --git a/AFSK.cpp b/inProgress/AFSK.cpp similarity index 100% rename from AFSK.cpp rename to inProgress/AFSK.cpp diff --git a/AFSK.h b/inProgress/AFSK.h similarity index 100% rename from AFSK.h rename to inProgress/AFSK.h diff --git a/DDS.cpp b/inProgress/DDS.cpp similarity index 100% rename from DDS.cpp rename to inProgress/DDS.cpp diff --git a/DDS.h b/inProgress/DDS.h similarity index 100% rename from DDS.h rename to inProgress/DDS.h diff --git a/KISS.cpp b/inProgress/KISS.cpp similarity index 100% rename from KISS.cpp rename to inProgress/KISS.cpp diff --git a/KISS.h b/inProgress/KISS.h similarity index 100% rename from KISS.h rename to inProgress/KISS.h