FastArduino  v1.9 alpha
C++ library to build fast but small Arduino/AVR projects
i2c.cpp
1 // Copyright 2016-2022 Jean-Francois Poilpret
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "i2c.h"
16 
17 namespace i2c
18 {
20  streams::ostream& operator<<(streams::ostream& out, Status s)
21  {
22  switch (s)
23  {
24  case Status::OK:
25  out << F("OK");
26  break;
27 
29  out << F("START_TRANSMITTED");
30  break;
31 
33  out << F("REPEAT_START_TRANSMITTED");
34  break;
35 
37  out << F("SLA_W_TRANSMITTED_ACK");
38  break;
39 
41  out << F("SLA_W_TRANSMITTED_NACK");
42  break;
43 
45  out << F("DATA_TRANSMITTED_ACK");
46  break;
47 
49  out << F("DATA_TRANSMITTED_NACK");
50  break;
51 
53  out << F("ARBITRATION_LOST");
54  break;
55 
57  out << F("SLA_R_TRANSMITTED_ACK");
58  break;
59 
61  out << F("SLA_R_TRANSMITTED_NACK");
62  break;
63 
65  out << F("DATA_RECEIVED_ACK");
66  break;
67 
69  out << F("DATA_RECEIVED_NACK");
70  break;
71 
72  default:
73  out << F("UNKNOWN[") << streams::hex << uint8_t(s) << ']';
74  break;
75  }
76  return out << streams::flush;
77  }
79 }
Output stream wrapper to provide formatted output API, a la C++.
Definition: streams.h:61
#define F(ptr)
Force string constant to be stored as flash storage.
Definition: flash.h:118
I2C API common definitions.
Define API to define and manage I2C devices.
Definition: i2c.cpp:18
Status
Transmission status codes.
Definition: i2c.h:66
@ START_TRANSMITTED
[Transmitter/Receiver modes] A START condition has been transmitted.
@ ARBITRATION_LOST
[Transmitter mode] Abitration lost in SLA+W or data bytes.
@ REPEAT_START_TRANSMITTED
[Transmitter/Receiver modes] A repeated START condition has been transmitted.
@ DATA_TRANSMITTED_ACK
[Transmitter mode] Data byte has been transmitted; ACK has been received.
@ SLA_W_TRANSMITTED_ACK
[Transmitter mode] SLA+W has been transmitted; ACK has been received.
@ DATA_TRANSMITTED_NACK
[Transmitter mode] Data byte has been transmitted; NOT ACK has been received.
@ DATA_RECEIVED_ACK
[Receiver mode] Data byte has been transmitted; ACK has been returned.
@ SLA_W_TRANSMITTED_NACK
[Transmitter mode] SLA+W has been transmitted; NOT ACK has been received.
@ DATA_RECEIVED_NACK
[Receiver mode] Data byte has been transmitted; NOT ACK has been returned.
@ SLA_R_TRANSMITTED_NACK
[Receiver mode] SLA+R has been transmitted; NOT ACK has been received.
@ SLA_R_TRANSMITTED_ACK
[Receiver mode] SLA+R has been transmitted; ACK has been received.
@ OK
Code indicating the last called method executed as expected without any issue.
void flush(FSTREAM &stream)
Manipulator for an output stream, which will flush the stream buffer.
Definition: streams.h:716
void hex(FSTREAM &stream)
Manipulator for an output or input stream, which will set the base, used to represent (output) or int...
Definition: ios.h:774