summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Daniel <cd@maintech.de>2012-06-01 00:17:33 +0200
committerChristian Daniel <cd@maintech.de>2012-06-01 00:17:33 +0200
commit4eed4e78708fe7d3e9ad167de4841a684dfe0538 (patch)
tree83d872cabb3b1c373bbd2f563079245dd208ab58
parent35355c704c4ea5e52c1567133437b75bbb208da5 (diff)
provide accessors for expanded USB API
-rw-r--r--software/libosmosdr/include/osmosdr.h26
-rw-r--r--software/libosmosdr/src/libosmosdr.c145
2 files changed, 170 insertions, 1 deletions
diff --git a/software/libosmosdr/include/osmosdr.h b/software/libosmosdr/include/osmosdr.h
index 9b4fa43..396fe36 100644
--- a/software/libosmosdr/include/osmosdr.h
+++ b/software/libosmosdr/include/osmosdr.h
@@ -141,6 +141,15 @@ OSMOSDR_API int osmosdr_get_tuner_gain(osmosdr_dev_t *dev);
*/
OSMOSDR_API int osmosdr_set_tuner_gain_mode(osmosdr_dev_t *dev, int manual);
+/* set LNA gain in hdB */
+OSMOSDR_API int osmosdr_set_tuner_lna_gain(osmosdr_dev_t *dev, int gain);
+/* set mixer gain in hdB */
+OSMOSDR_API int osmosdr_set_tuner_mixer_gain(osmosdr_dev_t *dev, int gain);
+/* set mixer enhancement */
+OSMOSDR_API int osmosdr_set_tuner_mixer_enh(osmosdr_dev_t *dev, int enh);
+/* set IF stages gain */
+OSMOSDR_API int osmosdr_set_tuner_if_gain(osmosdr_dev_t *dev, int stage, int gain);
+
/* this will select the baseband filters according to the requested sample rate */
OSMOSDR_API int osmosdr_set_sample_rate(osmosdr_dev_t *dev, uint32_t rate);
@@ -152,6 +161,23 @@ OSMOSDR_API int osmosdr_set_sample_rate(osmosdr_dev_t *dev, uint32_t rate);
*/
OSMOSDR_API uint32_t osmosdr_get_sample_rate(osmosdr_dev_t *dev);
+/* this allows direct access to the FPGA register bank */
+OSMOSDR_API int osmosdr_set_fpga_reg(osmosdr_dev_t *dev, uint8_t reg, uint32_t value);
+
+/* more access to OsmoSDR functions */
+
+/* set decimation (0 = off, 1 = 1:2, 2 = 1:4, 3 = 1:8, ... 6 = 1:64) */
+OSMOSDR_API int osmosdr_set_fpga_decimation(osmosdr_dev_t *dev, int dec);
+
+/* set i/q swap / spectrum inversion (0 = off, 1 = on) */
+OSMOSDR_API int osmosdr_set_fpga_iq_swap(osmosdr_dev_t *dev, int sw);
+
+/* configure scaling of i and q channel (scaled_i = (orig_i * igain) / 32768) */
+OSMOSDR_API int osmosdr_set_fpga_iq_gain(osmosdr_dev_t *dev, uint16_t igain, uint16_t qgain);
+
+/* configure i and q offset correction (corrected_i = orig_i + iofs */
+OSMOSDR_API int osmosdr_set_fpga_iq_ofs(osmosdr_dev_t *dev, int16_t iofs, int16_t qofs);
+
/* streaming functions */
OSMOSDR_API int osmosdr_reset_buffer(osmosdr_dev_t *dev);
diff --git a/software/libosmosdr/src/libosmosdr.c b/software/libosmosdr/src/libosmosdr.c
index 10e15d7..de0b56c 100644
--- a/software/libosmosdr/src/libosmosdr.c
+++ b/software/libosmosdr/src/libosmosdr.c
@@ -122,15 +122,23 @@ int e4k_exit(void *dev) { return 0; }
int e4k_set_freq(void *dev, uint32_t freq) {
osmosdr_dev_t* devt = (osmosdr_dev_t*)dev;
uint8_t buffer[4];
+ int res;
buffer[0] = (uint8_t)(freq >> 24);
buffer[1] = (uint8_t)(freq >> 16);
buffer[2] = (uint8_t)(freq >> 8);
buffer[3] = (uint8_t)(freq >> 0);
- return libusb_control_transfer(devt->devh, CTRL_OUT, 0x07,
+ res = libusb_control_transfer(devt->devh, CTRL_OUT, 0x07,
FUNC(3, 5), 0,
buffer, 4, CTRL_TIMEOUT);
+
+ if (res == 4) {
+ res = libusb_control_transfer(devt->devh, CTRL_OUT, 0x07,
+ FUNC(3, 9), 0,
+ NULL, 0, CTRL_TIMEOUT);
+ }
+ return res;
}
int e4k_set_bw(void *dev, int bw) { return 0; }
@@ -365,6 +373,65 @@ int osmosdr_set_tuner_gain_mode(osmosdr_dev_t *dev, int mode)
return r;
}
+int osmosdr_set_tuner_lna_gain(osmosdr_dev_t *dev, int gain)
+{
+ osmosdr_dev_t* devt = (osmosdr_dev_t*)dev;
+ uint8_t buffer[4];
+
+ buffer[0] = (gain >> 24);
+ buffer[1] = (gain >> 16);
+ buffer[2] = (gain >> 8);
+ buffer[3] = (gain >> 0);
+
+ return libusb_control_transfer(devt->devh, CTRL_OUT, 0x07,
+ FUNC(3, 0x0b), 0,
+ buffer, 4, CTRL_TIMEOUT);
+}
+
+int osmosdr_set_tuner_mixer_gain(osmosdr_dev_t *dev, int gain)
+{
+ osmosdr_dev_t* devt = (osmosdr_dev_t*)dev;
+ uint8_t buffer[1];
+
+ buffer[0] = gain / 10;
+
+ return libusb_control_transfer(devt->devh, CTRL_OUT, 0x07,
+ FUNC(3, 0x03), 0,
+ buffer, 1, CTRL_TIMEOUT);
+}
+
+int osmosdr_set_tuner_mixer_enh(osmosdr_dev_t *dev, int enh)
+{
+ osmosdr_dev_t* devt = (osmosdr_dev_t*)dev;
+ uint8_t buffer[4];
+
+ buffer[0] = (enh >> 24);
+ buffer[1] = (enh >> 16);
+ buffer[2] = (enh >> 8);
+ buffer[3] = (enh >> 0);
+
+ return libusb_control_transfer(devt->devh, CTRL_OUT, 0x07,
+ FUNC(3, 0x0d), 0,
+ buffer, 4, CTRL_TIMEOUT);
+}
+
+int osmosdr_set_tuner_if_gain(osmosdr_dev_t *dev, int stage, int gain)
+{
+ osmosdr_dev_t* devt = (osmosdr_dev_t*)dev;
+ uint8_t buffer[5];
+
+ buffer[0] = stage;
+ gain /= 10;
+ buffer[1] = (gain >> 24);
+ buffer[2] = (gain >> 16);
+ buffer[3] = (gain >> 8);
+ buffer[4] = (gain >> 0);
+
+ return libusb_control_transfer(devt->devh, CTRL_OUT, 0x07,
+ FUNC(3, 0x02), 0,
+ buffer, 5, CTRL_TIMEOUT);
+}
+
int osmosdr_set_sample_rate(osmosdr_dev_t *dev, uint32_t samp_rate)
{
uint16_t r = 0;
@@ -396,6 +463,82 @@ uint32_t osmosdr_get_sample_rate(osmosdr_dev_t *dev)
return dev->rate;
}
+int osmosdr_set_fpga_reg(osmosdr_dev_t *dev, uint8_t reg, uint32_t value)
+{
+ osmosdr_dev_t* devt = (osmosdr_dev_t*)dev;
+ uint8_t buffer[5];
+
+ buffer[0] = reg;
+ buffer[1] = (uint8_t)(value >> 24);
+ buffer[2] = (uint8_t)(value >> 16);
+ buffer[3] = (uint8_t)(value >> 8);
+ buffer[4] = (uint8_t)(value >> 0);
+
+ return libusb_control_transfer(devt->devh, CTRL_OUT, 0x07,
+ FUNC(1, 0x01), 0,
+ buffer, 5, CTRL_TIMEOUT);
+}
+
+int osmosdr_set_fpga_decimation(osmosdr_dev_t *dev, int dec)
+{
+ osmosdr_dev_t* devt = (osmosdr_dev_t*)dev;
+ uint8_t buffer[1];
+
+ if((dec < 0) || (dec > 6))
+ return -1;
+
+ buffer[0] = dec;
+
+ return libusb_control_transfer(devt->devh, CTRL_OUT, 0x07,
+ FUNC(1, 0x02), 0,
+ buffer, 1, CTRL_TIMEOUT);
+}
+
+int osmosdr_set_fpga_iq_swap(osmosdr_dev_t *dev, int sw)
+{
+ osmosdr_dev_t* devt = (osmosdr_dev_t*)dev;
+ uint8_t buffer[1];
+
+ if((sw < 0) || (sw > 1))
+ return -1;
+
+ buffer[0] = sw;
+
+ return libusb_control_transfer(devt->devh, CTRL_OUT, 0x07,
+ FUNC(1, 0x03), 0,
+ buffer, 1, CTRL_TIMEOUT);
+}
+
+int osmosdr_set_fpga_iq_gain(osmosdr_dev_t *dev, uint16_t igain, uint16_t qgain)
+{
+ osmosdr_dev_t* devt = (osmosdr_dev_t*)dev;
+ uint8_t buffer[4];
+
+ buffer[0] = (uint8_t)(igain >> 8);
+ buffer[1] = (uint8_t)(igain >> 0);
+ buffer[2] = (uint8_t)(qgain >> 8);
+ buffer[3] = (uint8_t)(qgain >> 0);
+
+ return libusb_control_transfer(devt->devh, CTRL_OUT, 0x07,
+ FUNC(1, 0x04), 0,
+ buffer, 4, CTRL_TIMEOUT);
+}
+
+int osmosdr_set_fpga_iq_ofs(osmosdr_dev_t *dev, int16_t iofs, int16_t qofs)
+{
+ osmosdr_dev_t* devt = (osmosdr_dev_t*)dev;
+ uint8_t buffer[4];
+
+ buffer[0] = (uint8_t)(iofs >> 8);
+ buffer[1] = (uint8_t)(iofs >> 0);
+ buffer[2] = (uint8_t)(qofs >> 8);
+ buffer[3] = (uint8_t)(qofs >> 0);
+
+ return libusb_control_transfer(devt->devh, CTRL_OUT, 0x07,
+ FUNC(1, 0x05), 0,
+ buffer, 4, CTRL_TIMEOUT);
+}
+
osmosdr_dongle_t *find_known_device(uint16_t vid, uint16_t pid)
{
unsigned int i;