Arduino  1.8.10
TwoWire クラス

#include <Wire.h>

TwoWire の継承関係図
Stream Print

公開メンバ関数

 TwoWire ()
 
void begin ()
 
void begin (uint8_t)
 
void begin (int)
 
void end ()
 
void setClock (uint32_t)
 
void beginTransmission (uint8_t)
 
void beginTransmission (int)
 
uint8_t endTransmission (void)
 
uint8_t endTransmission (uint8_t)
 
uint8_t requestFrom (uint8_t, uint8_t)
 
uint8_t requestFrom (uint8_t, uint8_t, uint8_t)
 
uint8_t requestFrom (uint8_t, uint8_t, uint32_t, uint8_t, uint8_t)
 
uint8_t requestFrom (int, int)
 
uint8_t requestFrom (int, int, int)
 
virtual size_t write (uint8_t)
 
virtual size_t write (const uint8_t *, size_t)
 
virtual int available (void)
 
virtual int read (void)
 
virtual int peek (void)
 
virtual void flush (void)
 
void onReceive (void(*)(int))
 
void onRequest (void(*)(void))
 
size_t write (unsigned long n)
 
size_t write (long n)
 
size_t write (unsigned int n)
 
size_t write (int n)
 
virtual size_t write (uint8_t)=0
 
size_t write (const char *str)
 
virtual size_t write (const uint8_t *buffer, size_t size)
 
size_t write (const char *buffer, size_t size)
 
- 基底クラス Stream に属する継承公開メンバ関数
 Stream ()
 
void setTimeout (unsigned long timeout)
 
unsigned long getTimeout (void)
 
bool find (char *target)
 
bool find (uint8_t *target)
 
bool find (char *target, size_t length)
 
bool find (uint8_t *target, size_t length)
 
bool find (char target)
 
bool findUntil (char *target, char *terminator)
 
bool findUntil (uint8_t *target, char *terminator)
 
bool findUntil (char *target, size_t targetLen, char *terminate, size_t termLen)
 
bool findUntil (uint8_t *target, size_t targetLen, char *terminate, size_t termLen)
 
long parseInt (LookaheadMode lookahead=SKIP_ALL, char ignore=NO_IGNORE_CHAR)
 
float parseFloat (LookaheadMode lookahead=SKIP_ALL, char ignore=NO_IGNORE_CHAR)
 
size_t readBytes (char *buffer, size_t length)
 
size_t readBytes (uint8_t *buffer, size_t length)
 
size_t readBytesUntil (char terminator, char *buffer, size_t length)
 
size_t readBytesUntil (char terminator, uint8_t *buffer, size_t length)
 
String readString ()
 
String readStringUntil (char terminator)
 
- 基底クラス Print に属する継承公開メンバ関数
 Print ()
 
int getWriteError ()
 
void clearWriteError ()
 
size_t write (const char *str)
 
size_t write (const char *buffer, size_t size)
 
virtual int availableForWrite ()
 
size_t print (const __FlashStringHelper *)
 
size_t print (const String &)
 
size_t print (const char[])
 
size_t print (char)
 
size_t print (unsigned char, int=DEC)
 
size_t print (int, int=DEC)
 
size_t print (unsigned int, int=DEC)
 
size_t print (long, int=DEC)
 
size_t print (unsigned long, int=DEC)
 
size_t print (double, int=2)
 
size_t print (const Printable &)
 
size_t println (const __FlashStringHelper *)
 
size_t println (const String &s)
 
size_t println (const char[])
 
size_t println (char)
 
size_t println (unsigned char, int=DEC)
 
size_t println (int, int=DEC)
 
size_t println (unsigned int, int=DEC)
 
size_t println (long, int=DEC)
 
size_t println (unsigned long, int=DEC)
 
size_t println (double, int=2)
 
size_t println (const Printable &)
 
size_t println (void)
 

その他の継承メンバ

- 基底クラス Stream に属する継承限定公開メンバ関数
int timedRead ()
 
int timedPeek ()
 
int peekNextDigit (LookaheadMode lookahead, bool detectDecimal)
 
long parseInt (char ignore)
 
float parseFloat (char ignore)
 
int findMulti (struct MultiTarget *targets, int tCount)
 
- 基底クラス Print に属する継承限定公開メンバ関数
void setWriteError (int err=1)
 
- 基底クラス Stream に属する継承限定公開変数類
unsigned long _timeout
 
unsigned long _startMillis
 

詳解

Wire.h33 行目に定義があります。

構築子と解体子

◆ TwoWire()

TwoWire::TwoWire ( )

Wire.cpp49 行目に定義があります。

50 {
51 }

関数詳解

◆ available()

int TwoWire::available ( void  )
virtual

Streamを実装しています。

Wire.cpp236 行目に定義があります。

237 {
238  return rxBufferLength - rxBufferIndex;
239 }

◆ begin() [1/3]

void TwoWire::begin ( void  )

Wire.cpp55 行目に定義があります。

56 {
57  rxBufferIndex = 0;
58  rxBufferLength = 0;
59 
60  txBufferIndex = 0;
61  txBufferLength = 0;
62 
63  twi_init();
64  twi_attachSlaveTxEvent(onRequestService); // default callback must exist
65  twi_attachSlaveRxEvent(onReceiveService); // default callback must exist
66 }
void twi_init(void)
Definition: twi.c:68
void twi_attachSlaveRxEvent(void(*function)(uint8_t *, int))
Definition: twi.c:331
void twi_attachSlaveTxEvent(void(*function)(void))
Definition: twi.c:342

◆ begin() [2/3]

void TwoWire::begin ( uint8_t  address)

Wire.cpp68 行目に定義があります。

69 {
70  begin();
72 }
void begin()
Definition: Wire.cpp:55
void twi_setAddress(uint8_t address)
Definition: twi.c:115
union address_union address

◆ begin() [3/3]

void TwoWire::begin ( int  address)

Wire.cpp74 行目に定義があります。

75 {
76  begin((uint8_t)address);
77 }
void begin()
Definition: Wire.cpp:55
union address_union address

◆ beginTransmission() [1/2]

void TwoWire::beginTransmission ( uint8_t  address)

Wire.cpp141 行目に定義があります。

142 {
143  // indicate that we are transmitting
144  transmitting = 1;
145  // set address of targeted slave
146  txAddress = address;
147  // reset tx buffer iterator vars
148  txBufferIndex = 0;
149  txBufferLength = 0;
150 }
union address_union address

◆ beginTransmission() [2/2]

void TwoWire::beginTransmission ( int  address)

Wire.cpp152 行目に定義があります。

153 {
154  beginTransmission((uint8_t)address);
155 }
union address_union address
void beginTransmission(uint8_t)
Definition: Wire.cpp:141

◆ end()

void TwoWire::end ( void  )

Wire.cpp79 行目に定義があります。

80 {
81  twi_disable();
82 }
void twi_disable(void)
Definition: twi.c:99

◆ endTransmission() [1/2]

uint8_t TwoWire::endTransmission ( void  )

Wire.cpp185 行目に定義があります。

186 {
187  return endTransmission(true);
188 }
uint8_t endTransmission(void)
Definition: Wire.cpp:185

◆ endTransmission() [2/2]

uint8_t TwoWire::endTransmission ( uint8_t  sendStop)

Wire.cpp170 行目に定義があります。

171 {
172  // transmit buffer (blocking)
173  uint8_t ret = twi_writeTo(txAddress, txBuffer, txBufferLength, 1, sendStop);
174  // reset tx buffer iterator vars
175  txBufferIndex = 0;
176  txBufferLength = 0;
177  // indicate that we are done transmitting
178  transmitting = 0;
179  return ret;
180 }
uint8_t twi_writeTo(uint8_t address, uint8_t *data, uint8_t length, uint8_t wait, uint8_t sendStop)
Definition: twi.c:226

◆ flush()

void TwoWire::flush ( void  )
virtual

Printを再実装しています。

Wire.cpp271 行目に定義があります。

272 {
273  // XXX: to be implemented.
274 }

◆ onReceive()

void TwoWire::onReceive ( void(*)(int)  function)

Wire.cpp317 行目に定義があります。

318 {
319  user_onReceive = function;
320 }

◆ onRequest()

void TwoWire::onRequest ( void(*)(void)  function)

Wire.cpp323 行目に定義があります。

324 {
325  user_onRequest = function;
326 }

◆ peek()

int TwoWire::peek ( void  )
virtual

Streamを実装しています。

Wire.cpp260 行目に定義があります。

261 {
262  int value = -1;
263 
264  if(rxBufferIndex < rxBufferLength){
265  value = rxBuffer[rxBufferIndex];
266  }
267 
268  return value;
269 }

◆ read()

int TwoWire::read ( void  )
virtual

Streamを実装しています。

Wire.cpp244 行目に定義があります。

245 {
246  int value = -1;
247 
248  // get each successive byte on each call
249  if(rxBufferIndex < rxBufferLength){
250  value = rxBuffer[rxBufferIndex];
251  ++rxBufferIndex;
252  }
253 
254  return value;
255 }

◆ requestFrom() [1/5]

uint8_t TwoWire::requestFrom ( uint8_t  address,
uint8_t  quantity 
)

Wire.cpp126 行目に定義があります。

127 {
128  return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)true);
129 }
union address_union address
uint8_t requestFrom(uint8_t, uint8_t)
Definition: Wire.cpp:126

◆ requestFrom() [2/5]

uint8_t TwoWire::requestFrom ( uint8_t  address,
uint8_t  quantity,
uint8_t  sendStop 
)

Wire.cpp122 行目に定義があります。

122  {
123  return requestFrom((uint8_t)address, (uint8_t)quantity, (uint32_t)0, (uint8_t)0, (uint8_t)sendStop);
124 }
union address_union address
uint8_t requestFrom(uint8_t, uint8_t)
Definition: Wire.cpp:126

◆ requestFrom() [3/5]

uint8_t TwoWire::requestFrom ( uint8_t  address,
uint8_t  quantity,
uint32_t  iaddress,
uint8_t  isize,
uint8_t  sendStop 
)

Wire.cpp89 行目に定義があります。

90 {
91  if (isize > 0) {
92  // send internal address; this mode allows sending a repeated start to access
93  // some devices' internal registers. This function is executed by the hardware
94  // TWI module on other processors (for example Due's TWI_IADR and TWI_MMR registers)
95 
97 
98  // the maximum size of internal address is 3 bytes
99  if (isize > 3){
100  isize = 3;
101  }
102 
103  // write internal register address - most significant byte first
104  while (isize-- > 0)
105  write((uint8_t)(iaddress >> (isize*8)));
106  endTransmission(false);
107  }
108 
109  // clamp to buffer length
110  if(quantity > BUFFER_LENGTH){
111  quantity = BUFFER_LENGTH;
112  }
113  // perform blocking read into buffer
114  uint8_t read = twi_readFrom(address, rxBuffer, quantity, sendStop);
115  // set rx buffer iterator vars
116  rxBufferIndex = 0;
117  rxBufferLength = read;
118 
119  return read;
120 }
uint8_t endTransmission(void)
Definition: Wire.cpp:185
union address_union address
uint8_t twi_readFrom(uint8_t address, uint8_t *data, uint8_t length, uint8_t sendStop)
Definition: twi.c:147
void beginTransmission(uint8_t)
Definition: Wire.cpp:141
#define BUFFER_LENGTH
Definition: Wire.h:28
virtual size_t write(uint8_t)
Definition: Wire.cpp:193
virtual int read(void)
Definition: Wire.cpp:244

◆ requestFrom() [4/5]

uint8_t TwoWire::requestFrom ( int  address,
int  quantity 
)

Wire.cpp131 行目に定義があります。

132 {
133  return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)true);
134 }
union address_union address
uint8_t requestFrom(uint8_t, uint8_t)
Definition: Wire.cpp:126

◆ requestFrom() [5/5]

uint8_t TwoWire::requestFrom ( int  address,
int  quantity,
int  sendStop 
)

Wire.cpp136 行目に定義があります。

137 {
138  return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)sendStop);
139 }
union address_union address
uint8_t requestFrom(uint8_t, uint8_t)
Definition: Wire.cpp:126

◆ setClock()

void TwoWire::setClock ( uint32_t  clock)

Wire.cpp84 行目に定義があります。

85 {
87 }
clock_t clock(void)
void twi_setFrequency(uint32_t frequency)
Definition: twi.c:127

◆ write() [1/10]

size_t TwoWire::write ( uint8_t  data)
virtual

Printを実装しています。

Wire.cpp193 行目に定義があります。

194 {
195  if(transmitting){
196  // in master transmitter mode
197  // don't bother if buffer is full
198  if(txBufferLength >= BUFFER_LENGTH){
199  setWriteError();
200  return 0;
201  }
202  // put byte in tx buffer
203  txBuffer[txBufferIndex] = data;
204  ++txBufferIndex;
205  // update amount in buffer
206  txBufferLength = txBufferIndex;
207  }else{
208  // in slave send mode
209  // reply to master
210  twi_transmit(&data, 1);
211  }
212  return 1;
213 }
uint8_t twi_transmit(const uint8_t *data, uint8_t length)
Definition: twi.c:302
void setWriteError(int err=1)
Definition: Print.h:44
#define BUFFER_LENGTH
Definition: Wire.h:28

◆ write() [2/10]

size_t TwoWire::write ( const uint8_t *  data,
size_t  quantity 
)
virtual

Printを再実装しています。

Wire.cpp218 行目に定義があります。

219 {
220  if(transmitting){
221  // in master transmitter mode
222  for(size_t i = 0; i < quantity; ++i){
223  write(data[i]);
224  }
225  }else{
226  // in slave send mode
227  // reply to master
228  twi_transmit(data, quantity);
229  }
230  return quantity;
231 }
uint8_t twi_transmit(const uint8_t *data, uint8_t length)
Definition: twi.c:302
uint8_t i
virtual size_t write(uint8_t)
Definition: Wire.cpp:193

◆ write() [3/10]

size_t TwoWire::write ( unsigned long  n)
inline

Wire.h75 行目に定義があります。

75 { return write((uint8_t)n); }
virtual size_t write(uint8_t)
Definition: Wire.cpp:193

◆ write() [4/10]

size_t TwoWire::write ( long  n)
inline

Wire.h76 行目に定義があります。

76 { return write((uint8_t)n); }
virtual size_t write(uint8_t)
Definition: Wire.cpp:193

◆ write() [5/10]

size_t TwoWire::write ( unsigned int  n)
inline

Wire.h77 行目に定義があります。

77 { return write((uint8_t)n); }
virtual size_t write(uint8_t)
Definition: Wire.cpp:193

◆ write() [6/10]

size_t TwoWire::write ( int  n)
inline

Wire.h78 行目に定義があります。

78 { return write((uint8_t)n); }
virtual size_t write(uint8_t)
Definition: Wire.cpp:193

◆ write() [7/10]

size_t Print::write

Print.cpp34 行目に定義があります。

35 {
36  size_t n = 0;
37  while (size--) {
38  if (write(*buffer++)) n++;
39  else break;
40  }
41  return n;
42 }
char buffer[42]
virtual size_t write(uint8_t)
Definition: Wire.cpp:193

◆ write() [8/10]

virtual size_t Print::write

◆ write() [9/10]

size_t Print::write
inline

Print.h57 行目に定義があります。

57  {
58  return write((const uint8_t *)buffer, size);
59  }
char buffer[42]
virtual size_t write(uint8_t)
Definition: Wire.cpp:193

◆ write() [10/10]

size_t Print::write
inline

Print.h52 行目に定義があります。

52  {
53  if (str == NULL) return 0;
54  return write((const uint8_t *)str, strlen(str));
55  }
const char * str
Definition: console.c:41
size_t strlen(const char *) __ATTR_PURE__
Calculate the length of a string.
virtual size_t write(uint8_t)
Definition: Wire.cpp:193
#define NULL
Definition: def.h:44

このクラス詳解は次のファイルから抽出されました: