FastArduino  v1.8
C++ library to build fast but small Arduino/AVR projects
i2c.cpp
1 // Copyright 2016-2021 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 
28  case Status::START_TRANSMITTED:
29  out << F("START_TRANSMITTED");
30  break;
31 
32  case Status::REPEAT_START_TRANSMITTED:
33  out << F("REPEAT_START_TRANSMITTED");
34  break;
35 
36  case Status::SLA_W_TRANSMITTED_ACK:
37  out << F("SLA_W_TRANSMITTED_ACK");
38  break;
39 
40  case Status::SLA_W_TRANSMITTED_NACK:
41  out << F("SLA_W_TRANSMITTED_NACK");
42  break;
43 
44  case Status::DATA_TRANSMITTED_ACK:
45  out << F("DATA_TRANSMITTED_ACK");
46  break;
47 
48  case Status::DATA_TRANSMITTED_NACK:
49  out << F("DATA_TRANSMITTED_NACK");
50  break;
51 
52  case Status::ARBITRATION_LOST:
53  out << F("ARBITRATION_LOST");
54  break;
55 
56  case Status::SLA_R_TRANSMITTED_ACK:
57  out << F("SLA_R_TRANSMITTED_ACK");
58  break;
59 
60  case Status::SLA_R_TRANSMITTED_NACK:
61  out << F("SLA_R_TRANSMITTED_NACK");
62  break;
63 
64  case Status::DATA_RECEIVED_ACK:
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 }
streams::ostream
Output stream wrapper to provide formatted output API, a la C++.
Definition: streams.h:61
streams::hex
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
i2c::Status::OK
@ OK
Code indicating the last called method executed as expected without any issue.
i2c::Status
Status
Transmission status codes.
Definition: i2c.h:66
i2c
Define API to define and manage I2C devices.
Definition: i2c.cpp:18
F
#define F(ptr)
Force string constant to be stored as flash storage.
Definition: flash.h:118
i2c.h
I2C API common definitions.
streams::flush
void flush(FSTREAM &stream)
Manipulator for an output stream, which will flush the stream buffer.
Definition: streams.h:713