From b1e058c81375f8ba955a86d0423fc42d718548ad Mon Sep 17 00:00:00 2001 From: Vladisslav P Date: Thu, 7 Apr 2022 00:35:21 +0300 Subject: [PATCH] add bias tee support (purple dongle) --- include/mirisdr.h | 2 ++ src/libmirisdr.c | 1 + src/soft.c | 22 +++++++++++++++++++++- src/structs.h | 2 ++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/include/mirisdr.h b/include/mirisdr.h index b5c91a2..31b8b52 100644 --- a/include/mirisdr.h +++ b/include/mirisdr.h @@ -124,6 +124,8 @@ MIRISDR_API int mirisdr_get_mixer_gain (mirisdr_dev_t *p); /* extra MIRISDR_API int mirisdr_get_mixbuffer_gain (mirisdr_dev_t *p); /* extra */ MIRISDR_API int mirisdr_get_lna_gain (mirisdr_dev_t *p); /* extra */ MIRISDR_API int mirisdr_get_baseband_gain (mirisdr_dev_t *p); /* extra */ +MIRISDR_API int mirisdr_set_bias (mirisdr_dev_t *p, int bias); /* extra */ +MIRISDR_API int mirisdr_get_bias (mirisdr_dev_t *p); /* extra */ #ifdef __cplusplus } diff --git a/src/libmirisdr.c b/src/libmirisdr.c index ecc7bd6..9e375ef 100644 --- a/src/libmirisdr.c +++ b/src/libmirisdr.c @@ -147,6 +147,7 @@ int mirisdr_open (mirisdr_dev_t **p, uint32_t index) { dev->format_auto = MIRISDR_FORMAT_AUTO_ON; dev->bandwidth = MIRISDR_BW_8MHZ; dev->xtal = MIRISDR_XTAL_24M; + dev->bias = 0; dev->hw_flavour = MIRISDR_HW_DEFAULT; diff --git a/src/soft.c b/src/soft.c index 1df4f34..d008b02 100644 --- a/src/soft.c +++ b/src/soft.c @@ -58,6 +58,13 @@ hw_switch_freq_plan_t *hw_switch_freq_plan[2] = { hw_switch_freq_plan_sdrplay }; +#define BIAS_GPIO 3 + +void update_reg_8(mirisdr_dev_t *p) +{ + mirisdr_write_reg(p, 0x08, p->reg8|(p->bias?(1<<(BIAS_GPIO+8)):0)); +} + int mirisdr_set_soft(mirisdr_dev_t *p) { uint32_t reg0 = 0, reg2 = 2, reg5 = 5, reg3 = 3; @@ -313,7 +320,9 @@ int mirisdr_set_soft(mirisdr_dev_t *p) // mirisdr_write_reg(p, 0x08, band_select[i]); // } - mirisdr_write_reg(p, 0x08, switch_plan.band_select_word); + //mirisdr_write_reg(p, 0x08, switch_plan.band_select_word); + p->reg8=switch_plan.band_select_word; + update_reg_8(p); mirisdr_write_reg(p, 0x09, 0x0e); mirisdr_write_reg(p, 0x09, reg3); @@ -590,3 +599,14 @@ mirisdr_band_t mirisdr_get_band (mirisdr_dev_t *p) return p->band; } +int mirisdr_set_bias (mirisdr_dev_t *p, int bias) +{ + p->bias=bias; + update_reg_8(p); + return 0; +} + +int mirisdr_get_bias (mirisdr_dev_t *p) +{ + return p->bias; +} diff --git a/src/structs.h b/src/structs.h index 150dcae..b0ab7c4 100644 --- a/src/structs.h +++ b/src/structs.h @@ -96,5 +96,7 @@ struct mirisdr_dev { unsigned char *xfer_out; uint32_t addr; int driver_active; + int bias; + int reg8; };