summaryrefslogtreecommitdiff
path: root/software/hhd70dongle/hhd70.c
diff options
context:
space:
mode:
Diffstat (limited to 'software/hhd70dongle/hhd70.c')
-rw-r--r--software/hhd70dongle/hhd70.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/software/hhd70dongle/hhd70.c b/software/hhd70dongle/hhd70.c
index e8c973b..2461c29 100644
--- a/software/hhd70dongle/hhd70.c
+++ b/software/hhd70dongle/hhd70.c
@@ -33,6 +33,29 @@
#include "hhd70.h"
+#define BIAS_VAL OCR1BL
+
+static void hhd70_bias_init(void)
+{
+ DDRB |= (1<<PB6);
+ TCCR1B = 0;
+ TCNT1 = 0;
+ OCR1B = 0;
+ TCCR1A = (1<<COM1B1) | (1<<WGM10);
+ TCCR1B = (1<<WGM12);
+}
+
+static inline void hhd70_bias_on(void)
+{
+ TCCR1B = (TCCR1B & 0xF8) | (1<<CS10);
+}
+
+static inline void hhd70_bias_off(void)
+{
+ TCCR1B = (TCCR1B & 0xF8);
+ TCNT1 = 0;
+}
+
void hhd70_init(void)
{
//configure Direction of SS / PB0 , MOSI and SCLK as Output to drive CS of CC1101
@@ -42,6 +65,7 @@ void hhd70_init(void)
// SPSR = (0<<SPI2X) // f_osc/4
// SPSR = (1<<SPI2X) // f_osc/2
// SPSR = (1<<SPI2X); (4MHz vs. 8MHz)
+ hhd70_bias_init();
}
void hhd70_config_GDO0_OOK_output(bool output_mode)
@@ -111,16 +135,19 @@ char hhd70_spi_read_byte(void)
void hhd70_palna_txmode(void)
{
SPI_PORT |= (1<<TE);
+ hhd70_bias_on();
}
void hhd70_palna_rxmode(void)
{
SPI_PORT &= ~(1<<TE);
+ hhd70_bias_off();
}
void hhd70_palna_off(void)
{
SPI_PORT |= (1<<TE);
+ hhd70_bias_off();
}
int8_t hhd70_rx_data_available(void)
@@ -128,3 +155,24 @@ int8_t hhd70_rx_data_available(void)
//check if GDO2 pin has been pulled low by c1101
return (SPI_PINB_REG & (1 << GDO2)) == 0;
}
+
+void hhd70_bias_set(uint8_t val)
+{
+ BIAS_VAL = val;
+}
+
+uint8_t hhd70_bias_get(void)
+{
+ return BIAS_VAL;
+}
+
+void hhd70_bias_inc(void)
+{
+ BIAS_VAL = (BIAS_VAL < 253) ? BIAS_VAL + 2 : 255;
+}
+
+void hhd70_bias_dec(void)
+{
+ BIAS_VAL = (BIAS_VAL > 2) ? BIAS_VAL - 2 : 0;
+}
+