Editing Programming N800 FM radio receiver

Warning: You are not logged in. Your IP address will be recorded in this page's edit history.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
 +
== How to control the FM tuner chip in the N800 ==
 +
The [[Nokia N800|N800]] internet tablet features a tea5761 FM tuner chip for listening
The [[Nokia N800|N800]] internet tablet features a tea5761 FM tuner chip for listening
to FM radio. The kernel driver for this chip was written by Nokia and is GPL'd open source. You can look at it by downloading the Maemo kernel source code.
to FM radio. The kernel driver for this chip was written by Nokia and is GPL'd open source. You can look at it by downloading the Maemo kernel source code.
Line 4: Line 6:
The driver implements the V4L2 radio interface and is thus controlled like a V4L2 device.
The driver implements the V4L2 radio interface and is thus controlled like a V4L2 device.
-
== How to do it in Python ==
+
=== How to do it in Python ===
By using Python's <code>ioctl</code> function, you can directly talk to the driver, so there is no need for wrapping some C library.
By using Python's <code>ioctl</code> function, you can directly talk to the driver, so there is no need for wrapping some C library.
-
=== Prerequisites ===
+
==== Prerequisites ====
Let's first import the required modules:
Let's first import the required modules:
Line 72: Line 74:
</source>
</source>
-
=== Opening the device ===
+
==== Opening the device ====
You gain access to the radio driver by opening the <code>/dev/radio</code> device. Since you need a system FD instead of a native Python FD, we use <code>os.open</code> instead of the built-in function <code>open</code>:
You gain access to the radio driver by opening the <code>/dev/radio</code> device. Since you need a system FD instead of a native Python FD, we use <code>os.open</code> instead of the built-in function <code>open</code>:
Line 82: Line 84:
If there's no tuner chip available (for example, if you run this code on the [[Nokia 770|770]] or the [[Nokia N810|N810]]), this line will throw an <code>OSError</code>. Don't forget to catch it.
If there's no tuner chip available (for example, if you run this code on the [[Nokia 770|770]] or the [[Nokia N810|N810]]), this line will throw an <code>OSError</code>. Don't forget to catch it.
-
=== Retrieving information about the FM tuner ===
+
==== Retrieving information about the FM tuner ====
Now it's time to talk to the FM tuner. We do this by placing an <code>ioctl</code>'' call on the device. <code>ioctl</code> calls consist of a number (those we have defined above), and some argument. The argument is a pointer for passing a C structure to the driver. The driver may read from this structure or write into it.
Now it's time to talk to the FM tuner. We do this by placing an <code>ioctl</code>'' call on the device. <code>ioctl</code> calls consist of a number (those we have defined above), and some argument. The argument is a pointer for passing a C structure to the driver. The driver may read from this structure or write into it.
Line 113: Line 115:
We should save the <code>tuner_index</code> and <code>tuner_name</code> for later, because this is how we address that particular tuner.
We should save the <code>tuner_index</code> and <code>tuner_name</code> for later, because this is how we address that particular tuner.
-
=== Setting the frequency ===
+
==== Setting the frequency ====
Next, we are going to tune into a radio station. For this, we have to set a frequency on the tuner. This is done by the V4L2 <code>_VIDIOC_G_FREQUENCY</code> <code>ioctl</code> invokation.
Next, we are going to tune into a radio station. For this, we have to set a frequency on the tuner. This is done by the V4L2 <code>_VIDIOC_G_FREQUENCY</code> <code>ioctl</code> invokation.
Line 141: Line 143:
</source>
</source>
-
=== Unmuting the tuner and setting the volume ===
+
==== Unmuting the tuner and setting the volume ====
You still do not hear anything from the radio. This is because the tuner is muted and its volume is set to 0. Let's change this:
You still do not hear anything from the radio. This is because the tuner is muted and its volume is set to 0. Let's change this:
Line 180: Line 182:
Now you can listen to the radio.
Now you can listen to the radio.
-
=== Cleaning up ===
+
==== Cleaning up ====
When you have finished listening to the radio, you should clean up and  
When you have finished listening to the radio, you should clean up and  
Line 198: Line 200:
</source>
</source>
-
== Code ready for use ==
+
=== Code ready for use ===
There is a pure Python module available for controlling the FM tuner. It is based on the information here. You can get it from [http://pyfmradio.garage.maemo.org the PyFMRadio project page].
There is a pure Python module available for controlling the FM tuner. It is based on the information here. You can get it from [http://pyfmradio.garage.maemo.org the PyFMRadio project page].

Learn more about Contributing to the wiki.


Please note that all contributions to maemo.org wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see maemo.org wiki:Copyrights for details). Do not submit copyrighted work without permission!


Cancel | Editing help (opens in new window)