summaryrefslogtreecommitdiff
path: root/software/hhd70dongle/c1101lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'software/hhd70dongle/c1101lib.c')
-rw-r--r--software/hhd70dongle/c1101lib.c98
1 files changed, 57 insertions, 41 deletions
diff --git a/software/hhd70dongle/c1101lib.c b/software/hhd70dongle/c1101lib.c
index 79187b9..47a446a 100644
--- a/software/hhd70dongle/c1101lib.c
+++ b/software/hhd70dongle/c1101lib.c
@@ -34,13 +34,37 @@
#include "c1101lib.h"
#include "hhd70.h"
-#include "usb_rawhid.h"
#include "util.h"
/**** Helper Functions ****/
#define SPIC1101_MAX_WAIT 21
+
+
+/* ###### ######
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+//#include <LUFA/Drivers/Misc/RingBuffer.h>
+#include <LUFA/Drivers/USB/USB.h>
+
+ /* Global I/O Buffers: */
+//static RingBuffer_t SPItoUSB_Buffer;
+//static uint8_t SPItoUSB_Buffer_Data[8];
+
+/** LUFA CDC Class driver interface configuration and state information. This structure is
+ * passed to all CDC Class driver functions, so that multiple instances of the same class
+ * within a device can be differentiated from one another.
+ */
+extern USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface;
+/* ###### end LUFA CDC-ACM specific definitions ###### */
+
+
+
int16_t c1101_spi_write_byte_ok_get_status(char data)
{
//~ uint8_t debug_sb[6];
@@ -53,9 +77,9 @@ int16_t c1101_spi_write_byte_ok_get_status(char data)
// i.e. we won't get Fifo Byte count or overflow status on normal command and so on
// e.g. we only get TX Fifo Free Byte count while writing to TX Fifo
// thus it makes sense to only check for CHIP_RDY here
- //~ usb_rawhid_send((uint8_t*)"spi byte exchanged ",255);
+ //~ ((uint8_t*)"spi byte exchanged ",255);
//~ debug_sprint_int16hex(debug_sb, sb);
- //~ usb_rawhid_send(debug_sb,255);
+ //~ (debug_sb,255);
if (attempts++ > SPIC1101_MAX_WAIT)
return -1;
} while ( SPIC1101_SB_CHIP_NOT_RDY(sb) );
@@ -111,16 +135,16 @@ int16_t c1101_spi_write_register(char address, char byte)
void c1101_spi_dump_registers_to_usb(void)
{
int c = 0;
- uint8_t debug_sb[6];
+ char debug_sb[6];
hhd70_spi_cs_enable();
hhd70_c1101_wait_chip_rdy();
if (c1101_spi_write_byte_ok_get_status(0xC0) < 0)
return;
- usb_rawhid_send((uint8_t*)"dump all 46 registers:",255);
+ CDC_Device_SendString(&VirtualSerial_CDC_Interface,"dump all 46 registers:");
for (c=0; c<47; c++)
{
debug_sprint_int16hex(debug_sb, hhd70_spi_read_byte());
- usb_rawhid_send(debug_sb,255);
+ CDC_Device_SendString(&VirtualSerial_CDC_Interface, debug_sb);
}
hhd70_spi_cs_disable();
}
@@ -176,12 +200,8 @@ int c1101_spi_write_txfifo(char *buffer, int len)
sb = c1101_spi_write_byte_ok_get_status(SPIC1101_ADDR_FIFO_WRITE_BURST);
if (sb < 0)
return -1;
- //~ uint8_t debug_sb[6];
while (len-- > 0 && SPIC1101_SB_FIFO_BYTES_AVAILABLE(sb) > 2)
{
- //~ usb_rawhid_send((uint8_t*)"TXFifo bytes available",255);
- //~ debug_sprint_int16hex(debug_sb, SPIC1101_SB_FIFO_BYTES_AVAILABLE(sb));
- //~ usb_rawhid_send(debug_sb,255);
sb = c1101_spi_write_byte_ok_get_status(buffer[num_written++]);
}
hhd70_spi_cs_disable();
@@ -261,7 +281,6 @@ void c1101_setFrequency(uint32_t freq, uint8_t freq_offset, uint8_t if_freq)
sb = c1101_getStatus();
} while (! (SPIC1101_SB_IDLE(sb)));
//programm frequency
- usb_rawhid_send((uint8_t*)"setting frequency",255);
c1101_spi_write_register(SPIC1101_ADDR_FREQ0, freq & 0xFF);
c1101_spi_write_register(SPIC1101_ADDR_FREQ1, (freq >> 8) & 0xFF);
c1101_spi_write_register(SPIC1101_ADDR_FREQ2, (freq >> 16) & 0x3F);
@@ -298,13 +317,13 @@ void c1101_handleStatusByte(char sb)
if (SPIC1101_SB_RXFIFO_OVERFLOW(sb))
{
c1101_spi_strobe_command(SPIC1101_ADDR_SFRX);
- usb_rawhid_send((uint8_t*)"RX fifo flushed",255);
+ CDC_Device_SendString(&VirtualSerial_CDC_Interface,"RX fifo flushed");
}
//on TXFifo Overflow, Flush TX Fifo
if (SPIC1101_SB_TXFIFO_OVERFLOW(sb))
{
c1101_spi_strobe_command(SPIC1101_ADDR_SFTX);
- usb_rawhid_send((uint8_t*)"TX fifo flushed",255);
+ CDC_Device_SendString(&VirtualSerial_CDC_Interface,"TX fifo flushed");
}
}
@@ -316,10 +335,10 @@ char c1101_getStatus(void)
sb = c1101_spi_write_byte_ok_get_status(SPIC1101_ADDR_SNOP);
hhd70_spi_cs_disable();
//debug start
- uint8_t debug_sb[6];
- usb_rawhid_send((uint8_t*)"c1101 status:",255);
+ char debug_sb[6];
+ CDC_Device_SendString(&VirtualSerial_CDC_Interface,"c1101 status:");
debug_sprint_int16hex(debug_sb, sb);
- usb_rawhid_send(debug_sb,255);
+ CDC_Device_SendString(&VirtualSerial_CDC_Interface,debug_sb);
//debug end
c1101_handleStatusByte(sb);
return sb;
@@ -331,10 +350,10 @@ char c1101_getMARCState(void)
sb = c1101_spi_read_register(SPIC1101_ADDR_MARCSTATE);
sb &= 0x1F;
//debug start
- uint8_t debug_sb[6];
- usb_rawhid_send((uint8_t*)"c1101 MARCSate:",255);
+ char debug_sb[6];
+ CDC_Device_SendString(&VirtualSerial_CDC_Interface,"c1101 MARCSate:");
debug_sprint_int16hex(debug_sb, sb);
- usb_rawhid_send(debug_sb,255);
+ CDC_Device_SendString(&VirtualSerial_CDC_Interface,debug_sb);
//debug end
return sb;
}
@@ -346,7 +365,7 @@ uint8_t c1101_getNumBytesInTXFifo(void)
void c1101_transmitData(char *buffer, unsigned int len)
{
- uint8_t debug_sb[6];
+ //~ uint8_t debug_sb[6];
uint8_t num_written = 0;
//~ uint8_t mcsm1 = c1101_spi_read_register(SPIC1101_ADDR_MCSM1);
//~ //configure state machine to automatically go to IDLE, once packet was transmitted
@@ -355,9 +374,6 @@ void c1101_transmitData(char *buffer, unsigned int len)
//~ c1101_spi_write_register(SPIC1101_ADDR_PKTCTRL0, 0b0000000001); //crc disabled; use FIFOs; variable packet length mode (first TX FIFO byte must be length)
// flush TX FIFO
num_written = c1101_spi_strobe_command(SPIC1101_ADDR_SFTX);
- usb_rawhid_send((uint8_t*)"Flush TX Fifo",255);
- debug_sprint_int16hex(debug_sb, num_written);
- usb_rawhid_send(debug_sb,255);
num_written = (uint8_t) len;
//variable packet length: write length of packet to TX FIFO:
@@ -368,24 +384,24 @@ void c1101_transmitData(char *buffer, unsigned int len)
//~ buffer += num_written;
//~ len -= num_written;
- //~ usb_rawhid_send((uint8_t*)"TX num written",255);
+ //~ ((uint8_t*)"TX num written",255);
//~ debug_sprint_int16hex(debug_sb, num_written);
- //~ usb_rawhid_send(debug_sb,255);
- //~ usb_rawhid_send((uint8_t*)"TX len",255);
+ //~ (debug_sb,255);
+ //~ ((uint8_t*)"TX len",255);
//~ debug_sprint_int16hex(debug_sb, len);
- //~ usb_rawhid_send(debug_sb,255);
+ //~ (debug_sb,255);
//~ c1101_getStatus();
- //~ usb_rawhid_send((uint8_t*)"TX bytes",255);
+ //~ ((uint8_t*)"TX bytes",255);
//~ debug_sprint_int16hex(debug_sb, c1101_getNumBytesInTXFifo());
- //~ usb_rawhid_send(debug_sb,255);
+ //~ (debug_sb,255);
//start transmitting
//num_written = c1101_spi_strobe_command(SPIC1101_ADDR_STX);
//~ num_written = hhd70_spi_exchange_byte(SPIC1101_ADDR_STX);
- //~ usb_rawhid_send((uint8_t*)"Strobe STX",255);
+ //~ ((uint8_t*)"Strobe STX",255);
//~ debug_sprint_int16hex(debug_sb, num_written);
- //~ usb_rawhid_send(debug_sb,255);
+ //~ (debug_sb,255);
//enable Power Amplifier
hhd70_palna_txmode();
@@ -403,19 +419,19 @@ void c1101_transmitData(char *buffer, unsigned int len)
{
//from state IDLE or RX go to TX
num_written = c1101_spi_strobe_command(SPIC1101_ADDR_STX);
- //~ usb_rawhid_send((uint8_t*)"Strobe STX",255);
+ //~ ((uint8_t*)"Strobe STX",255);
//~ debug_sprint_int16hex(debug_sb, num_written);
- //~ usb_rawhid_send(debug_sb,255);
+ //~ (debug_sb,255);
}
- //~ usb_rawhid_send((uint8_t*)"TX2 num written",255);
+ //~ ((uint8_t*)"TX2 num written",255);
//~ debug_sprint_int16hex(debug_sb, num_written);
- //~ usb_rawhid_send(debug_sb,255);
- //~ usb_rawhid_send((uint8_t*)"TX2 len",255);
+ //~ (debug_sb,255);
+ //~ ((uint8_t*)"TX2 len",255);
//~ debug_sprint_int16hex(debug_sb, len);
- //~ usb_rawhid_send(debug_sb,255);
- //~ usb_rawhid_send((uint8_t*)"TX2 bytes",255);
+ //~ (debug_sb,255);
+ //~ ((uint8_t*)"TX2 bytes",255);
//~ debug_sprint_int16hex(debug_sb, c1101_getNumBytesInTXFifo());
- //~ usb_rawhid_send(debug_sb,255);
+ //~ (debug_sb,255);
} while (len > 0);
//disable Power Amplifier
@@ -447,8 +463,8 @@ void c1101_recieveData(void)
num_leave_in_fifo = (recv_data[0] - num_recv_total < 64)? 0 : 1;
} while (num_recv > 0);
recv_data[num_recv_total]=0;
- usb_rawhid_send((uint8_t*)"RX: Data Recieved:",255);
- usb_rawhid_send((uint8_t*)recv_data,255);
+ CDC_Device_SendString(&VirtualSerial_CDC_Interface,"RX: Data Recieved:");
+ CDC_Device_SendString(&VirtualSerial_CDC_Interface,recv_data);
c1101_getStatus(); // get status and handle possiblble RX Fifo Overflow
}