From d4107fb0d958f870e79421f507908be5f20d13e2 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Tue, 26 Feb 2013 00:14:44 +0100 Subject: digital/ucoolib/ucoolib/hal/i2c: add host implementation --- digital/ucoolib/ucoolib/hal/i2c/i2c.host.hh | 66 +++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 digital/ucoolib/ucoolib/hal/i2c/i2c.host.hh (limited to 'digital/ucoolib/ucoolib/hal/i2c/i2c.host.hh') diff --git a/digital/ucoolib/ucoolib/hal/i2c/i2c.host.hh b/digital/ucoolib/ucoolib/hal/i2c/i2c.host.hh new file mode 100644 index 00000000..47a802b9 --- /dev/null +++ b/digital/ucoolib/ucoolib/hal/i2c/i2c.host.hh @@ -0,0 +1,66 @@ +#ifndef ucoolib_hal_i2c_i2c_host_hh +#define ucoolib_hal_i2c_i2c_host_hh +// ucoolib - Microcontroller object oriented library. {{{ +// +// Copyright (C) 2013 Nicolas Schodet +// +// APBTeam: +// Web: http://apbteam.org/ +// Email: team AT apbteam DOT org +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// }}} +#include "ucoolib/intf/i2c.hh" +#include "ucoolib/arch/host/host.hh" + +namespace ucoo { + +class I2cHostShared; + +/// I2C interface, host version. +class I2cHost : public I2c +{ + public: + /// Initialise the Nth I2C. + I2cHost (Host &host, int n); + /// See I2cMaster::send. + void send (uint8_t addr, const char *buf, int count); + /// See I2cMaster::recv. + void recv (uint8_t addr, char *buf, int count); + /// See I2cMaster::status. + int status (); + /// See I2cMaster::wait. + int wait (); + /// See I2cSlave::register_data. + void register_data (uint8_t addr, DataHandler &data_handler); + private: + /// I2C number. + int n_; + /// Slave address. + uint8_t slave_addr_; + /// Handler called to source or sink data for slave exchanges. + DataHandler *slave_data_handler_; + /// Current master transfer status. + int master_status_; + /// Shared context. + static I2cHostShared *shared_; + friend class I2cHostShared; +}; + +} // namespace ucoo + + +#endif // ucoolib_hal_i2c_i2c_host_hh -- cgit v1.2.3