00001 /* -*-C++-*- 00002 ******************************************************************************* 00003 * 00004 * File: i2c.h 00005 * Description: 00006 * 00007 ******************************************************************************* 00008 */ 00009 00010 /* 00011 * Copyright 2001 Free Software Foundation, Inc. 00012 * 00013 * This file is part of GNU Radio 00014 * 00015 * GNU Radio is free software; you can redistribute it and/or modify 00016 * it under the terms of the GNU General Public License as published by 00017 * the Free Software Foundation; either version 2, or (at your option) 00018 * any later version. 00019 * 00020 * GNU Radio is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * You should have received a copy of the GNU General Public License 00026 * along with GNU Radio; see the file COPYING. If not, write to 00027 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00028 * Boston, MA 02111-1307, USA. 00029 */ 00030 00031 #ifndef _I2C_H_ 00032 #define _I2C_H_ 00033 00034 #include "i2cio.h" 00035 00039 class i2c { 00040 public: 00041 00043 i2c (i2cio *io); 00044 ~i2c () {}; 00045 00047 bool write (int addr, const unsigned char *buf, int nbytes); 00048 00050 int read (int addr, unsigned char *buf, int max_bytes); 00051 00052 00053 private: 00054 void start (); 00055 void stop (); 00056 void write_bit (bool bit); 00057 bool write_byte (char byte); 00058 00059 void set_sda (bool bit) { d_io->set_sda (bit); } 00060 void set_scl (bool bit) { d_io->set_scl (bit); } 00061 bool get_sda () { return d_io->get_sda (); } 00062 00063 i2cio *d_io; 00064 }; 00065 00066 #endif /* _I2C_H_ */