diff options
Diffstat (limited to 'software/hhd70dongle/c1101lib.c')
-rw-r--r-- | software/hhd70dongle/c1101lib.c | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/software/hhd70dongle/c1101lib.c b/software/hhd70dongle/c1101lib.c index 30bb94c..61780d5 100644 --- a/software/hhd70dongle/c1101lib.c +++ b/software/hhd70dongle/c1101lib.c @@ -134,6 +134,8 @@ int spi_c1101_read_rxfifo(int leave_num_bytes, char *buffer, int maxlen) if (spi_c1101_write_byte_ok_get_status(SPIC1101_ADDR_RXBYTES) < 0) return -1; num_available = spi_read_byte(); + if (num_available == 0) + return 0; if (spi_c1101_write_byte_ok_get_status(SPIC1101_ADDR_FIFO_READ_BURST) < 0) return -1; while (maxlen-- > 0 && num_available - num_read > leave_num_bytes) @@ -202,8 +204,8 @@ void c1101_init(void) spi_c1101_dump_registers_to_usb(); //enable analog temperature sensor on GDO0 spi_c1101_write_register(SPIC1101_ADDR_IOCFG0, 0x80); - //enable RX FIFO interrupt (i.e. GPO1 pulls high if >= FIFOTHR bytes are in RX FIFO) - spi_c1101_write_register(SPIC1101_ADDR_IOCFG1, 0); + //enable RX FIFO interrupt (i.e. GPO2 pulls high if >= FIFOTHR bytes are in RX FIFO) + spi_c1101_write_register(SPIC1101_ADDR_IOCFG2, 0); // FIFOTHR RX FIFO and TX FIFO Thresholds // pull GPO high (interrupt) if more than 12 bytes in rx buffer (or less than 53 in tx) spi_c1101_write_register(SPIC1101_ADDR_FIFOTHR, 2); @@ -268,16 +270,6 @@ void c1101_setFrequency(uint32_t freq, uint8_t freq_offset, uint8_t if_freq) spi_c1101_write_register(SPIC1101_ADDR_CHANNR, 0); } -char c1101_getVersion(void) -{ - return spi_c1101_read_register(SPIC1101_ADDR_VERSION); -} - -char c1101_getPartNum(void) -{ - return spi_c1101_read_register(SPIC1101_ADDR_PARTNUM); -} - char c1101_putToSleep(void) { return spi_c1101_strobe_command(SPIC1101_ADDR_SPWD); @@ -425,7 +417,28 @@ void c1101_transmitData(char *buffer, unsigned int len) //disable Power Amplifier hhd70_pa_disable(); + hhd70_lna_enable(); +} +void c1101_recieveData(void) +{ + uint8_t const max_len=255; + char recv_data[256]; + uint8_t num_recv = 0; + uint8_t num_recv_total = 0; + uint8_t num_leave_in_fifo = 1; + do + { + num_recv = spi_c1101_read_rxfifo( num_leave_in_fifo, recv_data+num_recv_total, max_len - num_recv_total); + num_recv_total += num_recv; + + //variable packet length: + //don't read last byte in fifo unless packet has finished receiving + 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); } //max returned: 64 bytes |