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.c43
1 files changed, 36 insertions, 7 deletions
diff --git a/software/hhd70dongle/c1101lib.c b/software/hhd70dongle/c1101lib.c
index 26d5fb9..8f9f5a7 100644
--- a/software/hhd70dongle/c1101lib.c
+++ b/software/hhd70dongle/c1101lib.c
@@ -29,25 +29,43 @@
* along with mur.sat. If not, see <http://www.gnu.org/licenses/>.
*
*/
-#include "avr/io.h"
-#include "util/delay.h"
+#include <avr/io.h>
+#include <util/delay.h>
#include "c1101lib.h"
#include "spi.h"
-//#include "usb_rawhid.h"
+#include "usb_rawhid.h"
+#include "util.h"
/**** Helper Functions ****/
+#define SPIC1101_MAX_WAIT 1024
+unsigned int attempts = 0;
char spi_c1101_exchange(char *data, int len)
{
+ char sb;
+ uint8_t debug_sb[6];
char rbyte;
spi_cs_enable();
- while (len--)
+ attempts = 0;
+ while (len-- > 0)
{
- while ( ! (SPIC1101_SB_CHIPRDY(spi_read_byte())));
+ //~ while ( ! (SPIC1101_SB_CHIPRDY(spi_read_byte())));
spi_write_byte(*(data++));
+ usb_rawhid_send((uint8_t*)"spi byte written",255);
+ do
+ {
+ usb_rawhid_send((uint8_t*)"wait chipready",255);
+ sb = spi_read_byte();
+ debug_sprint_int16hex(debug_sb, sb);
+ usb_rawhid_send(debug_sb,255);
+ if (attempts++ > SPIC1101_MAX_WAIT)
+ return -1;
+ } while ( ! (SPIC1101_SB_CHIPRDY(sb)));
+ usb_rawhid_send((uint8_t*)"spi chipready",255);
}
rbyte = spi_read_byte();
+ usb_rawhid_send((uint8_t*)"spi byte read",255);
spi_cs_disable();
return rbyte;
}
@@ -133,8 +151,19 @@ int spi_c1101_write_txfifo(char *buffer, int len)
/**** External Functions ****/
+char c1101_getVersion(void)
+{
+ return spi_c1101_read_register(SPIC1101_ADDR_VERSION);
+}
+
+char c1101_getPartNum(void)
+{
+ return spi_c1101_read_register(SPIC1101_ADDR_PARTNUM);
+}
+
+
//max len: 64 bytes
-void writeTXFifo(char *buffer, unsigned int len)
+void c1101_writeTXFifo(char *buffer, unsigned int len)
{
//check TXBYTES.NUM_TXBYTES
// never write more bytes than avaiblabe or doom ensues
@@ -143,7 +172,7 @@ void writeTXFifo(char *buffer, unsigned int len)
}
//max returned: 64 bytes
-int readRXFifo(char *buffer)
+int c1101_readRXFifo(char *buffer)
{
//check RXBYTES.NUM_RXBYTES
// never read more bytes than avaiblabe or we will read garbage