Commits

Trammell Hudson committed dae33bb

Use the uart to generate 45.45N52 data

Comments (0)

Files changed (1)

 
 #undef F_CPU
 #define F_CPU  2000000UL
+#define CONFIG_UART
 
 #include <avr/io.h>
 #include <avr/pgmspace.h>
 }
 
 
+#if 1
+#define BAUDOT(a,b,c,d,e,m) ( \
+	((!a) << 0) | \
+	((!b) << 1) | \
+	((!c) << 2) | \
+	((!d) << 3) | \
+	((!e) << 4) | \
+	(m << 5) | \
+	0 )
+#else
 #define BAUDOT(a,b,c,d,e,m) ( \
 	(a << 0) | \
 	(b << 1) | \
 	(e << 4) | \
 	(m << 5) | \
 	0 )
+#endif
 
 #define BAUDOT_LC(a,b,c,d,e) BAUDOT(a,b,c,d,e,0x1)
 #define BAUDOT_UC(a,b,c,d,e) BAUDOT(a,b,c,d,e,0x2)
 	[2] = BAUDOT_BOTH(0,0,1,0,0),
 };
 
+//#define BIT_CLOCK 22
+#define BIT_CLOCK 22000
+#define one_advance 0
+#define TX_PIN 0xD3
+
 
 static void
 tty_out_raw(
 	uint8_t c
 )
 {
+#ifdef CONFIG_UART
+	while (bit_is_clear(UCSR1A, UDRE1))
+		;
+	UDR1 = c;
+#else
 	uint8_t ocr_one = OCR1C;
 	uint8_t ocr_zero = OCR1C;
 
-//#define BIT_CLOCK 22
-#define BIT_CLOCK 22000
-#define one_advance 0
-
 
 	// start bit
-	out(0xD7, 0);
+	out(TX_PIN, 0);
 	OCR1C = ocr_zero;
 
 	_delay_us(BIT_CLOCK - 1000);
 		if (!x)
 		{
 			OCR1C = ocr_one;
-			out(0xD7, 1);
+			out(TX_PIN, 1);
 			_delay_us(100);
 		} else {
 			OCR1C = ocr_zero;
-			out(0xD7, 0);
+			out(TX_PIN, 0);
 		}
 
 		_delay_us(BIT_CLOCK);
 
 	// And now send 1.5 stop bits
 	OCR1C = ocr_one;
-	out(0xD7, 1);
+	out(TX_PIN, 1);
 
 	_delay_us(BIT_CLOCK);
 	_delay_us(BIT_CLOCK/2); // 1.42 stop bits
 	_delay_us(BIT_CLOCK); // give it a few bits, slow but reliable
 	_delay_us(BIT_CLOCK); // give it a few bits, slow but reliable
 	_delay_us(BIT_CLOCK); // give it a few bits, slow but reliable
+#endif
 }
 
 
 	// Disable the ADC
 	ADMUX = 0;
 
-	ddr(0xD7, 1);
-	out(0xD7, 1);
+	ddr(TX_PIN, 1);
+	out(TX_PIN, 1);
 
 #define CONFIG_BOOST
 #ifdef CONFIG_BOOST
 	out(0xB7, 1);
 #endif
 
+#ifdef CONFIG_UART
+	// UBRR is 12 bits, max 4096.  So we run at 2 MHz
+	// to keep UBRR0 in range.
+	UBRR1 = 2749; // = 45.45 / (16 * 2 MHz) - 1
+	UCSR1B = 0
+		| (1 << RXEN1)
+		| (1 << TXEN1)
+		;
+
+	UCSR1C = 0
+		| (0 << UPM11) // no parity
+		| (0 << UPM10)
+		| (0 << UCSZ12) // 5 data bits
+		| (0 << UCSZ11)
+		| (0 << UCSZ10)
+		| (1 << USBS1) // 2 stop bits
+		;
+#endif
+
 	// initialize the USB, and then wait for the host
 	// to set configuration.  If the Teensy is powered
 	// without a PC connected to the USB port, this