<commit_before>/**
 * @file Cosa/TWI.hh
 * @version 1.0
 *
 * @section License
 * Copyright (C) 2012-2013, <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library 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
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General
 * Public License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA  02111-1307  USA
 *
 * This file is part of the Arduino Che Cosa project.
 */

#ifndef __COSA_TWI_HH__
#define __COSA_TWI_HH__

#include "Cosa/Types.h"
#if defined(__ARDUINO_TINY__)
#include "Cosa/USI/TWI.hh"
#else
#include "Cosa/Event.hh"

/**
 * Two wire library. Support for the I2C/TWI bus Master and Slave
 * device drivers. Single-ton, twi, holds bus interaction state.
 * Supporting classes TWI::Driver for device drivers, TWI::Slave
 * for slave devices. 
 */
class TWI {
  friend void TWI_vect(void);
public:
  /**
   * Device drivers are friends and may have callback/event handler
   * for completion events. 
   */
  class Driver : public Event::Handler {
    friend class TWI;
    friend void TWI_vect(void);
  protected:
    /** Device bus address */
    uint8_t m_addr;

  public:
    /**
     * Construct TWI driver with given bus address.
     * @param[in] addr bus address (7-bit LSB).
     */
    Driver(uint8_t addr) : m_addr(addr << 1) {}
  };

  /**
   * Slave device abstraction. Should set up buffers for request and
   * response and handle incoming requests. See also USI/TWI.hh for
   * definition for ATtiny devices.
   */
  class Slave : public Driver {
    friend class TWI;<commit_msg>Adding explicit call of Event::Handler constructor in TWI::Driver.<commit_after>/**
 * @file Cosa/TWI.hh
 * @version 1.0
 *
 * @section License
 * Copyright (C) 2012-2013, <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library 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
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General
 * Public License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA  02111-1307  USA
 *
 * This file is part of the Arduino Che Cosa project.
 */

#ifndef __COSA_TWI_HH__
#define __COSA_TWI_HH__

#include "Cosa/Types.h"
#if defined(__ARDUINO_TINY__)
#include "Cosa/USI/TWI.hh"
#else
#include "Cosa/Event.hh"

/**
 * Two wire library. Support for the I2C/TWI bus Master and Slave
 * device drivers. Single-ton, twi, holds bus interaction state.
 * Supporting classes TWI::Driver for device drivers, TWI::Slave
 * for slave devices. 
 */
class TWI {
  friend void TWI_vect(void);
public:
  /**
   * Device drivers are friends and may have callback/event handler
   * for completion events. 
   */
  class Driver : public Event::Handler {
    friend class TWI;
    friend void TWI_vect(void);
  protected:
    /** Device bus address */
    uint8_t m_addr;

  public:
    /**
     * Construct TWI driver with given bus address.
     * @param[in] addr bus address (7-bit LSB).
     */
    Driver(uint8_t addr) : Event::Handler(), m_addr(addr << 1) {}
  };

  /**
   * Slave device abstraction. Should set up buffers for request and
   * response and handle incoming requests. See also USI/TWI.hh for
   * definition for ATtiny devices.
   */
  class Slave : public Driver {
    friend class TWI;
{'fraction_non_alphanumeric': 0.0884109916367981, 'fraction_numerical': 0.014814814814814815, 'mean_word_length': 3.3154639175257734, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6574901', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1237, 'n_words': 529}