Imported Upstream version 3.0
[debian/gnuradio] / gnuradio-core / src / lib / io / i2c_bbio_pp.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2001,2004 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 #include "i2c_bbio_pp.h"
24 #include "microtune_eval_board_defs.h"
25
26 i2c_bbio_pp::i2c_bbio_pp (ppio_sptr pp)
27 {
28   d_pp = pp;
29   d_pp->lock ();
30   d_pp->write_control (d_pp->read_control () & ~UT_CP_MUST_BE_ZERO);    // output, no interrupts
31   d_pp->unlock ();
32 }
33
34 i2c_bbio_sptr
35 make_i2c_bbio_pp (ppio_sptr pp)
36 {
37   return i2c_bbio_sptr (new i2c_bbio_pp (pp));
38 }
39
40 void
41 i2c_bbio_pp::set_scl (bool state)
42 {
43   int   r = d_pp->read_control();
44
45   if (!state){                                  // active low
46     d_pp->write_control (r | UT_CP_TUNER_SCL);
47   }
48   else {
49     d_pp->write_control (r & ~UT_CP_TUNER_SCL);
50   }
51   d_pp->read_control ();        // use for 1us delay
52   d_pp->read_control ();        // use for 1us delay
53 }
54
55 void
56 i2c_bbio_pp::set_sda (bool state)
57 {
58   int   r = d_pp->read_data ();
59
60   if (!state){                                  // active low
61     d_pp->write_data (r | UT_DP_TUNER_SDA_OUT);
62   }
63   else {
64     d_pp->write_data (r & ~UT_DP_TUNER_SDA_OUT);
65   }
66   d_pp->read_data ();   // use for 1us delay
67   d_pp->read_data ();   // use for 1us delay
68 }
69
70 bool
71 i2c_bbio_pp::get_sda ()
72 {
73   int   r = d_pp->read_status ();
74   return (r & UT_SP_TUNER_SDA_IN) == 0; // eval board has an inverter on it
75 }
76
77 void
78 i2c_bbio_pp::lock ()
79 {
80   d_pp->lock ();
81 }
82
83 void
84 i2c_bbio_pp::unlock ()
85 {
86   d_pp->unlock ();
87 }