0413:6a03 Leadtek Research, Inc. RTL2832 WinFast DTV Dongle

Main forum to discuss RTL-SDR related topics.
Post Reply
radiotap
Posts: 3
Joined: Mon Dec 16, 2013 10:28 am

0413:6a03 Leadtek Research, Inc. RTL2832 WinFast DTV Dongle

Post by radiotap » Mon Dec 16, 2013 10:47 am

I have that stick for long time. I was trying to run SDR in past, but unsuccesfuly. When i was looking at osmocom cgit changelog i was insterested in tuner TUA9001 stick addition. That this stick contains too. Tried to add VID:PID to sourcecode and crossed fingers. No luck. Anz advice how to run that cursed stick ?

Its that orange stick. Contains RTL2832U.
Image

I also disassemble cover and take PCB shot.

Code: Select all

lsusb -v
Bus 002 Device 002: ID 0413:6a03 Leadtek Research, Inc. RTL2832 [WinFast DTV Dongle Mini]
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x0413 Leadtek Research, Inc.
  idProduct          0x6a03 RTL2832 [WinFast DTV Dongle Mini]
  bcdDevice            1.00
  iManufacturer           1 realtek
  iProduct                2 usbtv
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           25
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          4 USB2.0-Bulk&Iso
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              500mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass    255 Vendor Specific Subclass
      bInterfaceProtocol    255 Vendor Specific Protocol
      iInterface              5 Bulk-In, Interface
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
Device Qualifier (for other device speed):
  bLength                10
  bDescriptorType         6
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  bNumConfigurations      2
Device Status:     0x0000
  (Bus Powered)

Attachments
back.jpg
Back PCB
back.jpg (461.42 KiB) Viewed 16155 times
front.jpg
Front PCB
front.jpg (489.49 KiB) Viewed 16155 times

rtlsdrblog
Site Admin
Posts: 2743
Joined: Mon Nov 19, 2012 11:54 pm

Re: 0413:6a03 Leadtek Research, Inc. RTL2832 WinFast DTV Don

Post by rtlsdrblog » Wed Dec 18, 2013 10:38 pm

I don't think that tuner is supported. On the patch it says in the comments "The TUA9001 tuner it uses is unsupported at the moment, though.", so I think they just added it into the device list with the hope that in the future smoeone would get that tuner working.

geo
Posts: 3
Joined: Sat Jan 18, 2014 2:51 pm

Re: 0413:6a03 Leadtek Research, Inc. RTL2832 WinFast DTV Don

Post by geo » Sat Jan 18, 2014 7:55 pm

Started porting tuner driver for this device. It's pretty similar to fc2580 (I mean coding style, function names, comments, ...). Dvb-t Linux driver is working correctly, detecting Infineon TUA9001 tuner without problems. So I got the "magic" number for the tuner from the Linux driver.

Code: Select all

#define TUA9001_I2C_ADDR	0xc0
#define TUA9001_CHECK_ADDR 0x7e
#define TUA9001_CHECK_VAL	0x2328
Modified the check loop, and it doesn't work (I noticed that it's written for uint8, so I mean it returned 0 not the part of CHECK_VAL.). Furthermore I scanned the I2C bus, and found demod on addr. 0x20 and something on 0xa0 0xa1.

In my opinion, there is some part of initialization (in my opinion content of set_tuner_power function from Lin. driver) before tuner scan omitted.

For completeness, at the morning it was: 0413:0x6a03 Leadtek Research, Inc. RTL2832 [WinFast DTV Dongle Mini], but playing with I2C transformed it back to generic 0bda:2832 Realtek Semiconductor Corp. RTL2832U DVB-T. :) (And it still works correctly).

---edit
I went through the mailing list and found out, that

Code: Select all

		r = rtlsdr_write_array(dev, IICB, addr, &reg, 1);
		r = rtlsdr_read_array(dev, IICB, addr, &rreg, 1);
returns 1 for addr=TUA9001_I2C_ADDR, but for any reg, the rreg is alaways 0.

matgiani
Posts: 2
Joined: Tue Mar 11, 2014 10:47 pm

Re: 0413:6a03 Leadtek Research, Inc. RTL2832 WinFast DTV Don

Post by matgiani » Tue Mar 11, 2014 11:13 pm

Hello,

I noticed this thread and was wondering if there had been any progress.
I have a potentially very similar stick.
Physically mine is black plastic but the size, layout of the IR receiver and the antenna connector make it seem like it could be a near-rebadge of this orange one.

Its (original) output on lsusb was:

Code: Select all

1b80:d396 Afatech UB396-T [RTL2832U]
Kernel driver was not loading, however encouraged by lsusb reporting it as a RTL2832 device I tried adding vid:pid to librtlsdr and compiling.
At this point rtl_sdr picked it up and rtl_test works, albeit saying "No supported tuner found" and thus defaulting to direct sampling mode.

rtl_eeprom was able to read the original eeprom, which looked like this:

Code: Select all

Found 1 device(s):
  0:  Hamlet eXagerate XDVBT900BK

Using device 0: Hamlet eXagerate XDVBT900BK
No supported tuner found
Enabled direct sampling mode, input 1

Current configuration:
__________________________________________
Vendor ID:		0x1b80
Product ID:		0xd396
Manufacturer:		realtek
Product:		usbtv
Serial number:		0010
Serial number enabled:	no
IR endpoint enabled:	no
Remote wakeup enabled:	no
__________________________________________
After seeing this I simply tried to write a reference RTL2832U configuration to it, to at least get it to be picked up by the kernel driver. Went smoothly and kernel driver is now reporting it has a TUA9001 tuner.

Any luck in fiddling with the tuner in rtl_sdr?

Many thanks

Matteo

matgiani
Posts: 2
Joined: Tue Mar 11, 2014 10:47 pm

Re: 0413:6a03 Leadtek Research, Inc. RTL2832 WinFast DTV Don

Post by matgiani » Wed Mar 12, 2014 10:55 pm

geo wrote: Modified the check loop, and it doesn't work (I noticed that it's written for uint8, so I mean it returned 0 not the part of CHECK_VAL.). Furthermore I scanned the I2C bus, and found demod on addr. 0x20 and something on 0xa0 0xa1.
geo wrote:

Code: Select all

		r = rtlsdr_write_array(dev, IICB, addr, &reg, 1);
		r = rtlsdr_read_array(dev, IICB, addr, &rreg, 1);
returns 1 for addr=TUA9001_I2C_ADDR, but for any reg, the rreg is alaways 0.
Hi
I had a look at the tuner identification code in the dvb_usb_rtl28xxu kernel driver.
I believe I figured out why the rtlsdr_i2c_[write|read] do not work with this tuner. As far as I understood, this tuner has 2-byte registers which require a different way of accessing the i2c bus to be read properly. I was getting all zeroes as well with the method used for the other tuners.

However, looking at the kernel driver, I noticed it also switches to an alternate method for multi-byte reads from i2c and thus tried this:

Code: Select all

r = rtlsdr_read_array(dev, TUNB /* corresponds to CMD_I2C_RD in kernel module */, 0x7ec0 /* register address << 8 | i2c address */, buffer, 2);
This seems to work on my stick and reads 0x2328 from register 0x7e, as expected for this tuner, which can be used for identification.
Hope this helps.

geo
Posts: 3
Joined: Sat Jan 18, 2014 2:51 pm

Re: 0413:6a03 Leadtek Research, Inc. RTL2832 WinFast DTV Don

Post by geo » Mon Mar 31, 2014 6:00 pm

Hi,
thank you. It works. :)

geo
Posts: 3
Joined: Sat Jan 18, 2014 2:51 pm

Re: 0413:6a03 Leadtek Research, Inc. RTL2832 WinFast DTV Don

Post by geo » Fri Apr 04, 2014 7:14 pm

And here goes the patch.

(sorry for long snapshot, but .patch files are not allowed as attachements)

Code: Select all

From 473abf543919782019bae352529fbadd47e66c58 Mon Sep 17 00:00:00 2001
From: Jiri Luznicky <[email protected]>
Date: Fri, 4 Apr 2014 20:41:07 +0200
Subject: [PATCH] Added port of Infineon TUA9001 tuner.

---
 include/rtl-sdr.h       |    3 +-
 include/rtlsdr_i2c.h    |    3 +
 include/tuner_tua9001.h |   15 +++++
 rtl-sdr.rules           |    6 ++
 src/CMakeLists.txt      |    2 +
 src/librtlsdr.c         |   62 ++++++++++++++++++++-
 src/tuner_tua9001.c     |  139 +++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 226 insertions(+), 4 deletions(-)
 create mode 100644 include/tuner_tua9001.h
 create mode 100644 src/tuner_tua9001.c

diff --git a/include/rtl-sdr.h b/include/rtl-sdr.h
index 489e117..c13e60c 100644
--- a/include/rtl-sdr.h
+++ b/include/rtl-sdr.h
@@ -176,7 +176,8 @@ enum rtlsdr_tuner {
 	RTLSDR_TUNER_FC0013,
 	RTLSDR_TUNER_FC2580,
 	RTLSDR_TUNER_R820T,
-	RTLSDR_TUNER_R828D
+	RTLSDR_TUNER_R828D,
+	RTLSDR_TUNER_TUA9001
 };
 
 /*!
diff --git a/include/rtlsdr_i2c.h b/include/rtlsdr_i2c.h
index 7676689..f45b83c 100644
--- a/include/rtlsdr_i2c.h
+++ b/include/rtlsdr_i2c.h
@@ -5,4 +5,7 @@ uint32_t rtlsdr_get_tuner_clock(void *dev);
 int rtlsdr_i2c_write_fn(void *dev, uint8_t addr, uint8_t *buf, int len);
 int rtlsdr_i2c_read_fn(void *dev, uint8_t addr, uint8_t *buf, int len);
 
+int rtlsdr_i2c_tunb_write_fn(void *dev, uint8_t addr, uint8_t *buf, int len);
+void rtlsdr_set_gpio_bit_fn(void *dev, uint8_t gpio, int val);
+
 #endif
diff --git a/include/tuner_tua9001.h b/include/tuner_tua9001.h
new file mode 100644
index 0000000..5c16995
--- /dev/null
+++ b/include/tuner_tua9001.h
@@ -0,0 +1,15 @@
+#ifndef __TUNER_TUA9001_H
+#define __TUNER_TUA9001_H
+
+#define TUA9001_I2C_ADDR	0xc0
+#define TUA9001_CHECK_ADDR	0x7e
+#define TUA9001_CHECK_VAL	0x2328
+
+#define TUA9001_RESETN_PIN  3
+#define TUA9001_RXEN_PIN    1
+
+int tua9001_init(void *dev);
+int tua9001_release(void *dev);
+int tua9001_set_params(void *dev, uint32_t frequency_hz, uint32_t bandwidth_hz);
+
+#endif /* __TUNER_TUA9001_H */
\ No newline at end of file
diff --git a/rtl-sdr.rules b/rtl-sdr.rules
index 4213454..94f11dc 100644
--- a/rtl-sdr.rules
+++ b/rtl-sdr.rules
@@ -24,6 +24,9 @@ SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="2838", MODE:="066
 # DigitalNow Quad DVB-T PCI-E card (4x FC0012?)
 SUBSYSTEMS=="usb", ATTRS{idVendor}=="0413", ATTRS{idProduct}=="6680", MODE:="0666"
 
+# Leadtek Research, Inc. RTL2832 [WinFast DTV Dongle Mini] (TUA9001)
+SUBSYSTEMS=="usb", ATTRS{idVendor}=="0413", ATTRS{idProduct}=="6a03", MODE:="0666"
+
 # Leadtek WinFast DTV Dongle mini D (FC0012)
 SUBSYSTEMS=="usb", ATTRS{idVendor}=="0413", ATTRS{idProduct}=="6f0f", MODE:="0666"
 
@@ -90,6 +93,9 @@ SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d394", MODE:="066
 # Peak 102569AGPK (FC0012)
 SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d395", MODE:="0666"
 
+# Hamlet eXagerate XDVBT900BK (TUA9001)
+SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d396", MODE:="0666"
+
 # KWorld KW-UB450-T USB DVB-T Pico TV (TUA9001)
 SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d397", MODE:="0666"
 
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 77e1dc4..df73116 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -27,6 +27,7 @@ add_library(rtlsdr_shared SHARED
     tuner_fc0013.c
     tuner_fc2580.c
     tuner_r82xx.c
+    tuner_tua9001.c
 )
 
 target_link_libraries(rtlsdr_shared
@@ -45,6 +46,7 @@ add_library(rtlsdr_static STATIC
     tuner_fc0013.c
     tuner_fc2580.c
     tuner_r82xx.c
+    tuner_tua9001.c
 )
 
 add_library(convenience_static STATIC
diff --git a/src/librtlsdr.c b/src/librtlsdr.c
index 9a3ebcd..4b7271a 100644
--- a/src/librtlsdr.c
+++ b/src/librtlsdr.c
@@ -54,6 +54,7 @@
 #include "tuner_fc0013.h"
 #include "tuner_fc2580.h"
 #include "tuner_r82xx.h"
+#include "tuner_tua9001.h"
 
 typedef struct rtlsdr_tuner_iface {
 	/* tuner interface */
@@ -248,6 +249,15 @@ int r820t_set_gain_mode(void *dev, int manual) {
 	return r82xx_set_gain(&devt->r82xx_p, manual, 0);
 }
 
+int tua9001_set_freq(void *dev, uint32_t freq) {
+	return tua9001_set_params(dev,freq,8000000);
+}
+int tua9001_set_bw(void *dev, int bw_hz) {
+	return tua9001_set_params(dev,0,8000000);
+}
+int tua9001_set_gain(void *dev, int gain) { return 0; }
+int tua9001_set_gain_mode(void *dev, int manual) { return 0; }
+
 /* definition order must match enum rtlsdr_tuner */
 static rtlsdr_tuner_iface_t tuners[] = {
 	{
@@ -283,6 +293,11 @@ static rtlsdr_tuner_iface_t tuners[] = {
 		r820t_set_freq, r820t_set_bw, r820t_set_gain, NULL,
 		r820t_set_gain_mode
 	},
+	{
+		tua9001_init, tua9001_release,
+		tua9001_set_freq, tua9001_set_bw, tua9001_set_gain, NULL,
+		tua9001_set_gain_mode
+	}
 };
 
 typedef struct rtlsdr_dongle {
@@ -298,6 +313,7 @@ static rtlsdr_dongle_t known_devices[] = {
 	{ 0x0bda, 0x2832, "Generic RTL2832U" },
 	{ 0x0bda, 0x2838, "Generic RTL2832U OEM" },
 	{ 0x0413, 0x6680, "DigitalNow Quad DVB-T PCI-E card" },
+	{ 0x0413, 0x6a03, "Leadtek Research, Inc. RTL2832 [WinFast DTV Dongle Mini]"},
 	{ 0x0413, 0x6f0f, "Leadtek WinFast DTV Dongle mini D" },
 	{ 0x0458, 0x707f, "Genius TVGo DVB-T03 USB dongle (Ver. B)" },
 	{ 0x0ccd, 0x00a9, "Terratec Cinergy T Stick Black (rev 1)" },
@@ -320,6 +336,7 @@ static rtlsdr_dongle_t known_devices[] = {
 	{ 0x1b80, 0xd393, "GIGABYTE GT-U7300" },
 	{ 0x1b80, 0xd394, "DIKOM USB-DVBT HD" },
 	{ 0x1b80, 0xd395, "Peak 102569AGPK" },
+	{ 0x1b80, 0xd396, "Hamlet eXagerate XDVBT900BK"},
 	{ 0x1b80, 0xd397, "KWorld KW-UB450-T USB DVB-T Pico TV" },
 	{ 0x1b80, 0xd398, "Zaapa ZT-MINDVBZP" },
 	{ 0x1b80, 0xd39d, "SVEON STV20 DVB-T USB & FM" },
@@ -335,7 +352,7 @@ static rtlsdr_dongle_t known_devices[] = {
 	{ 0x1f4d, 0xb803, "GTek T803" },
 	{ 0x1f4d, 0xc803, "Lifeview LV5TDeluxe" },
 	{ 0x1f4d, 0xd286, "MyGica TD312" },
-	{ 0x1f4d, 0xd803, "PROlectrix DV107669" },
+	{ 0x1f4d, 0xd803, "PROlectrix DV107669" }
 };
 
 #define DEFAULT_BUF_NUMBER	15
@@ -436,6 +453,14 @@ uint8_t rtlsdr_i2c_read_reg(rtlsdr_dev_t *dev, uint8_t i2c_addr, uint8_t reg)
 	return data;
 }
 
+uint16_t rtlsdr_i2c_tunb_read_reg(rtlsdr_dev_t *dev, uint8_t i2c_addr, int8_t reg)
+{
+	uint8_t data[2] = {0,0};
+	rtlsdr_read_array(dev, TUNB, reg << 8 | i2c_addr, (uint8_t *) &data, 2);
+	
+	return data[0]<<8 | data[1];
+}
+  
 int rtlsdr_i2c_write(rtlsdr_dev_t *dev, uint8_t i2c_addr, uint8_t *buffer, int len)
 {
 	uint16_t addr = i2c_addr;
@@ -446,6 +471,16 @@ int rtlsdr_i2c_write(rtlsdr_dev_t *dev, uint8_t i2c_addr, uint8_t *buffer, int l
 	return rtlsdr_write_array(dev, IICB, addr, buffer, len);
 }
 
+int rtlsdr_i2c_tunb_write(rtlsdr_dev_t *dev, uint8_t i2c_addr, uint8_t *buffer, int len)
+{
+	uint16_t addr = (buffer[0] << 8) | i2c_addr ;
+
+	if (!dev)
+		return -1;
+
+	return rtlsdr_write_array(dev, TUNB, addr, &(buffer[1]), len);
+}
+
 int rtlsdr_i2c_read(rtlsdr_dev_t *dev, uint8_t i2c_addr, uint8_t *buffer, int len)
 {
 	uint16_t addr = i2c_addr;
@@ -1396,7 +1431,7 @@ int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index)
 	libusb_device *device = NULL;
 	uint32_t device_count = 0;
 	struct libusb_device_descriptor dd;
-	uint8_t reg;
+	uint16_t reg;
 	ssize_t cnt;
 
 	dev = malloc(sizeof(rtlsdr_dev_t));
@@ -1511,6 +1546,15 @@ int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index)
 		dev->tuner_type = RTLSDR_TUNER_R828D;
 		goto found;
 	}
+	
+	reg = rtlsdr_i2c_tunb_read_reg(dev, TUA9001_I2C_ADDR, TUA9001_CHECK_ADDR);
+	if (reg == TUA9001_CHECK_VAL) {
+		fprintf(stderr, "Found Infineon TUA9001 tuner\n");
+		//rtlsdr_set_gpio_output(dev, 1);
+		//rtlsdr_set_gpio_output(dev, 4);
+		dev->tuner_type = RTLSDR_TUNER_TUA9001;
+		goto found;
+	}
 
 	/* initialise GPIOs */
 	rtlsdr_set_gpio_output(dev, 5);
@@ -1533,7 +1577,7 @@ int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index)
 		dev->tuner_type = RTLSDR_TUNER_FC0012;
 		goto found;
 	}
-
+	
 found:
 	/* use the rtl clock value by default */
 	dev->tun_xtal = dev->rtl_xtal;
@@ -1885,3 +1929,15 @@ int rtlsdr_i2c_read_fn(void *dev, uint8_t addr, uint8_t *buf, int len)
 
 	return -1;
 }
+
+int rtlsdr_i2c_tunb_write_fn(void *dev, uint8_t addr, uint8_t *buf, int len)
+{
+	if (dev)
+		return rtlsdr_i2c_tunb_write(((rtlsdr_dev_t *)dev), addr, buf, len);
+
+	return -1;
+}
+
+void rtlsdr_set_gpio_bit_fn(rtlsdr_dev_t *dev, uint8_t gpio, int val){
+  rtlsdr_set_gpio_bit(dev, gpio, val);
+}
\ No newline at end of file
diff --git a/src/tuner_tua9001.c b/src/tuner_tua9001.c
new file mode 100644
index 0000000..e1bd725
--- /dev/null
+++ b/src/tuner_tua9001.c
@@ -0,0 +1,139 @@
+#include <stdint.h>
+#include <stdio.h>
+
+#include <unistd.h>
+
+#include "rtlsdr_i2c.h"
+#include "tuner_tua9001.h"
+
+#define RETURN_OK  0
+#define RETURN_ERR -1
+
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
+#define SYS_DVBT 0 /* as we know only one */
+
+struct reg_val {
+	uint8_t reg;
+	uint16_t val;
+};
+
+/* write register */
+int tua9001_wr_reg(void *dev, uint8_t reg, uint16_t val)
+{
+	int ret;
+	uint8_t buf[3] = { reg, (val >> 8) & 0xff, (val >> 0) & 0xff };
+
+	ret = rtlsdr_i2c_tunb_write_fn(dev, TUA9001_I2C_ADDR, buf, 2);
+	if (ret < 0) {
+		fprintf(stderr, "%s: i2c wr failed=%d reg=%02x\n","tuner_tua9001.c", ret, reg);
+	}
+
+	return ret;
+}
+
+int tua9001_release(void *dev)
+{
+	return 0;
+}
+
+int tua9001_init(void *dev)
+{
+	int ret = 0;
+	uint8_t i;
+	struct reg_val data[] = {
+		{ 0x1e, 0x6512 },
+		{ 0x25, 0xb888 },
+		{ 0x39, 0x5460 },
+		{ 0x3b, 0x00c0 },
+		{ 0x3a, 0xf000 },
+		{ 0x08, 0x0000 },
+		{ 0x32, 0x0030 },
+		{ 0x41, 0x703a },
+		{ 0x40, 0x1c78 },
+		{ 0x2c, 0x1c00 },
+		{ 0x36, 0xc013 },
+		{ 0x37, 0x6f18 },
+		{ 0x27, 0x0008 },
+		{ 0x2a, 0x0001 },
+		{ 0x34, 0x0a40 },
+	};
+	
+	rtlsdr_set_gpio_bit_fn(dev,TUA9001_RESETN_PIN,0);
+
+	for (i = 0; i < ARRAY_SIZE(data); i++) {
+		ret = tua9001_wr_reg(dev, data[i].reg, data[i].val);
+	        if (ret < 0)
+			goto err;
+	}
+err:
+	if (ret < 0)
+		fprintf(stderr, "%s: failed=%d\n","tua9001_init", ret);
+
+	return RETURN_OK;
+}
+
+int tua9001_set_params(void *dev, uint32_t frequency_hz, uint32_t bandwidth_hz)
+{
+	int ret = 0; 
+	unsigned int i;
+	uint16_t val;
+	uint32_t frequency;
+	struct reg_val data[2];
+	
+	uint8_t delivery_system = SYS_DVBT;
+
+	//fprintf(stderr, "%s: delivery_system=%d frequency=%d bandwidth_hz=%d\n", "tua9001_set_params", delivery_system ,frequency_hz, bandwidth_hz);
+
+	switch (SYS_DVBT) {
+	case SYS_DVBT:
+		switch (bandwidth_hz) {
+		case 8000000:
+			val  = 0x0000;
+			break;
+		case 7000000:
+			val  = 0x1000;
+			break;
+		case 6000000:
+			val  = 0x2000;
+			break;
+		case 5000000:
+			val  = 0x3000;
+			break;
+		default:
+			ret = -1;
+			goto err;
+		}
+		break;
+	default:
+		ret = -1;
+		goto err;
+	}
+
+	data[0].reg = 0x04;
+	data[0].val = val;
+
+	frequency = (frequency_hz - 150000000);
+	frequency /= 100;
+	frequency *= 48;
+	frequency /= 10000;
+
+	data[1].reg = 0x1f;
+	data[1].val = frequency;
+
+	rtlsdr_set_gpio_bit_fn(dev,TUA9001_RXEN_PIN,0);
+
+	for (i = 0; i < ARRAY_SIZE(data); i++) {
+		ret = tua9001_wr_reg(dev, data[i].reg, data[i].val);
+		if (ret < 0)
+			goto err;
+	}
+	
+	rtlsdr_set_gpio_bit_fn(dev,TUA9001_RXEN_PIN,1);
+	
+err:
+	if (ret < 0)
+		fprintf(stderr, "%s: failed=%d\n", "tua9001_set_params", ret);
+
+	return ret;
+}
\ No newline at end of file
-- 
1.7.10.4



Post Reply