Refactoring to make explicit D-to-A and PTT pins & ports, and turning on and

off PTT. This should also help to make porting to another chip easier.
This commit is contained in:
Paul Kronenwetter 2015-10-02 17:39:33 -04:00
parent 373e4d8274
commit a7a167c19b
3 changed files with 38 additions and 15 deletions

View File

@ -38,8 +38,17 @@
#define DAC_DDR DDRD
#define LED_PORT PORTB
#define LED_DDR DDRB
#define PTT_PORT PORTD
#define PTT_DDR DDRD
#define ADC_PORT PORTC
#define ADC_DDR DDRC
// Pins 3-7 on Port D = Arduino D3 - D7
#define DAC_HIGH _BV(7)
#define DAC_PINS _BV(7)&_BV(6)&_BV(5)&_BV(4)
#define LED_TX 1 // Arduino D9
#define LED_RX 2 // Arduino D10
#define PTT_TX 3 // Arduino D11
#define ADC_NO 0 // Arduino A0
#endif
#endif

View File

@ -38,9 +38,9 @@ void AFSK_hw_init(void) {
ADMUX = 0;
}
ADC_DDR &= ~_BV(0);
ADC_PORT &= ~_BV(0);
DIDR0 |= _BV(0);
ADC_DDR &= ~_BV(ADC_NO);
ADC_PORT &= ~_BV(ADC_NO);
DIDR0 |= _BV(ADC_NO);
ADCSRB = _BV(ADTS2) |
_BV(ADTS1) |
_BV(ADTS0);
@ -51,6 +51,7 @@ void AFSK_hw_init(void) {
_BV(ADPS2);
AFSK_DAC_INIT();
PTT_INIT();
LED_TX_INIT();
LED_RX_INIT();
}
@ -84,6 +85,7 @@ static void AFSK_txStart(Afsk *afsk) {
afsk->phaseAcc = 0;
afsk->bitstuffCount = 0;
afsk->sending = true;
PTT_TX_ON();
LED_TX_ON();
afsk->preambleLength = DIV_ROUND(custom_preamble * BITRATE, 8000);
AFSK_DAC_IRQ_START();
@ -121,6 +123,7 @@ uint8_t AFSK_dac_isr(Afsk *afsk) {
if (fifo_isempty(&afsk->txFifo) && afsk->tailLength == 0) {
AFSK_DAC_IRQ_STOP();
afsk->sending = false;
PTT_TX_OFF();
LED_TX_OFF();
return 0;
} else {
@ -141,6 +144,7 @@ uint8_t AFSK_dac_isr(Afsk *afsk) {
if (fifo_isempty(&afsk->txFifo)) {
AFSK_DAC_IRQ_STOP();
afsk->sending = false;
PTT_TX_OFF();
LED_TX_OFF();
return 0;
} else {
@ -499,9 +503,12 @@ ISR(ADC_vect) {
TIFR1 = _BV(ICF1);
AFSK_adc_isr(AFSK_modem, ((int16_t)((ADC) >> 2) - 128));
if (hw_afsk_dac_isr) {
DAC_PORT = (AFSK_dac_isr(AFSK_modem) & 0xF0) | _BV(3);
// Set DAC pin(s) according to position in SIN wave.
DAC_PORT |= (AFSK_dac_isr(AFSK_modem) & DAC_PINS);
} else {
DAC_PORT = 128;
// Set DAC pin(s) to the zero point in the SIN wave.
// This is represented by setting only the high-bit.
DAC_PORT = (DAC_PORT & (~DAC_PINS)) | DAC_HIGH;
}
++_clock;
}

View File

@ -142,20 +142,27 @@ typedef struct Afsk
#define AFSK_DAC_IRQ_START() do { extern bool hw_afsk_dac_isr; hw_afsk_dac_isr = true; } while (0)
#define AFSK_DAC_IRQ_STOP() do { extern bool hw_afsk_dac_isr; hw_afsk_dac_isr = false; } while (0)
#define AFSK_DAC_INIT() do { DAC_DDR |= 0xF8; } while (0)
// DAC_PINS equals b11111000 which on port D on Arduino sets D3, D4, D5, D6, D7
// to be outputs.
#define AFSK_DAC_INIT() do { DAC_DDR |= DAC_PINS; } while (0)
// Here's some macros for controlling the RX/TX LEDs
// THE _INIT() functions writes to the DDRB register
// to configure the pins as output pins, and the _ON()
// and _OFF() functions writes to the PORT registers
// to turn the pins on or off.
#define LED_TX_INIT() do { LED_DDR |= _BV(1); } while (0)
#define LED_TX_ON() do { LED_PORT |= _BV(1); } while (0)
#define LED_TX_OFF() do { LED_PORT &= ~_BV(1); } while (0)
#define LED_TX_INIT() do { LED_DDR |= _BV(LED_TX); } while (0)
#define LED_TX_ON() do { LED_PORT |= _BV(LED_TX); } while (0)
#define LED_TX_OFF() do { LED_PORT &= ~_BV(LED_TX); } while (0)
#define LED_RX_INIT() do { LED_DDR |= _BV(2); } while (0)
#define LED_RX_ON() do { LED_PORT |= _BV(2); } while (0)
#define LED_RX_OFF() do { LED_PORT &= ~_BV(2); } while (0)
#define LED_RX_INIT() do { LED_DDR |= _BV(LED_RX); } while (0)
#define LED_RX_ON() do { LED_PORT |= _BV(LED_RX); } while (0)
#define LED_RX_OFF() do { LED_PORT &= ~_BV(LED_RX); } while (0)
// Along the same lines, these initialize and control the PTT signal
#define PTT_INIT() do { PTT_DDR |= _BV(PTT_TX); } while (0)
#define PTT_TX_ON() do { PTT_PORT |= _BV(PTT_TX); } while (0)
#define PTT_TX_OFF() do { PTT_PORT &= ~_BV(PTT_TX); } while (0)
void AFSK_init(Afsk *afsk);
void AFSK_transmit(char *buffer, size_t size);