wireport.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Gunar Schorcht
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
55 #ifndef WIREPORT_HPP
56 #define WIREPORT_HPP
57 
58 #include <inttypes.h>
59 #include <stddef.h>
60 
62 #ifndef ARDUINO_I2C_DEV
63 #define ARDUINO_I2C_DEV (I2C_DEV(0))
64 #endif
65 
67 #define WIREPORT_BUFFER_LENGTH 32
68 
70 class TwoWire
71 {
72  private:
73 
74  static uint8_t rxBuffer[];
75  static uint8_t rxBufferIndex;
76  static uint8_t rxBufferLength;
78  static uint8_t txAddress;
79  static uint8_t txBuffer[];
80  static uint8_t txBufferIndex;
81  static uint8_t txBufferLength;
82  static uint8_t txError;
84  static uint8_t transmitting;
87  public:
88 
92  TwoWire(void);
93 
97  void begin(void);
98 
107  void begin(uint8_t addr);
108 
119  void setClock(uint32_t clk);
120 
132  void beginTransmission(uint8_t addr);
133 
149  uint8_t endTransmission(void);
150 
168  uint8_t endTransmission(uint8_t stop);
169 
184  uint8_t requestFrom(uint8_t addr, uint8_t size);
185 
201  uint8_t requestFrom(uint8_t addr, uint8_t size, uint8_t stop);
202 
215  virtual size_t write(uint8_t data);
216 
230  virtual size_t write(const uint8_t *data, size_t size);
231 
242  virtual int available(void);
243 
254  virtual int read(void);
255 
267  virtual size_t readBytes(uint8_t *buffer, size_t length);
281  virtual int peek(void);
282 
291  virtual void flush(void);
292 };
293 
294 extern TwoWire Wire;
295 
296 #endif /* WIREPORT_HPP */
297 
TwoWire::write
virtual size_t write(uint8_t data)
Queue a byte for transmission from a master to slave device.
TwoWire::endTransmission
uint8_t endTransmission(void)
End a transmission to a I2C slave device.
TwoWire::setClock
void setClock(uint32_t clk)
Set the clock speed of the I2C device defined by ARDUINO_I2C_DEV.
TwoWire::flush
virtual void flush(void)
Flush the RX and TX buffer.
TwoWire::begin
void begin(void)
Initializes the I2C device defined by ARDUINO_I2C_DEV as master.
TwoWire::peek
virtual int peek(void)
Peeks one byte transmitted from slave device to the master.
TwoWire::TwoWire
TwoWire(void)
Constructor.
TwoWire::requestFrom
uint8_t requestFrom(uint8_t addr, uint8_t size)
Request bytes from a I2C slave device.
TwoWire::beginTransmission
void beginTransmission(uint8_t addr)
Begin a transmission to a I2C slave device.
inttypes.h
Adds include for missing inttype definitions.
TwoWire::read
virtual int read(void)
Reads one byte transmitted from slave device to the master.
TwoWire
Class definition for the Arduino Wire library implementation.
Definition: wireport.hpp:70
TwoWire::readBytes
virtual size_t readBytes(uint8_t *buffer, size_t length)
Read bytes transmitted from slave device to the master.
TwoWire::available
virtual int available(void)
Return the number of bytes available for retrieval.