1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-12-24 11:21:24 +03:00

Migrate from astyle to clang-format (#8464)

This commit is contained in:
Maxim Prokhorov
2022-02-20 19:23:33 +03:00
committed by Max Prokhorov
parent 46190b61f1
commit 19b7a29720
241 changed files with 15925 additions and 16197 deletions

View File

@@ -22,7 +22,8 @@
Modified January 2017 by Bjorn Hammarberg (bjoham@esp8266.com) - i2c slave support
*/
extern "C" {
extern "C"
{
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
@@ -31,9 +32,8 @@ extern "C" {
#include "twi.h"
#include "Wire.h"
//Some boards don't have these pins available, and hence don't support Wire.
//Check here for compile-time error.
// Some boards don't have these pins available, and hence don't support Wire.
// Check here for compile-time error.
#if !defined(PIN_WIRE_SDA) || !defined(PIN_WIRE_SCL)
#error Wire library is not supported on this board
#endif
@@ -41,13 +41,13 @@ extern "C" {
// Initialize Class Variables //////////////////////////////////////////////////
uint8_t TwoWire::rxBuffer[I2C_BUFFER_LENGTH];
size_t TwoWire::rxBufferIndex = 0;
size_t TwoWire::rxBufferLength = 0;
size_t TwoWire::rxBufferIndex = 0;
size_t TwoWire::rxBufferLength = 0;
uint8_t TwoWire::txAddress = 0;
uint8_t TwoWire::txBuffer[I2C_BUFFER_LENGTH];
size_t TwoWire::txBufferIndex = 0;
size_t TwoWire::txBufferLength = 0;
size_t TwoWire::txBufferIndex = 0;
size_t TwoWire::txBufferLength = 0;
uint8_t TwoWire::transmitting = 0;
void (*TwoWire::user_onRequest)(void);
@@ -58,7 +58,7 @@ static int default_scl_pin = SCL;
// Constructors ////////////////////////////////////////////////////////////////
TwoWire::TwoWire() {}
TwoWire::TwoWire() { }
// Public Methods //////////////////////////////////////////////////////////////
@@ -126,8 +126,8 @@ size_t TwoWire::requestFrom(uint8_t address, size_t size, bool sendStop)
{
size = I2C_BUFFER_LENGTH;
}
size_t read = (twi_readFrom(address, rxBuffer, size, sendStop) == 0) ? size : 0;
rxBufferIndex = 0;
size_t read = (twi_readFrom(address, rxBuffer, size, sendStop) == 0) ? size : 0;
rxBufferIndex = 0;
rxBufferLength = read;
return read;
}
@@ -149,14 +149,15 @@ uint8_t TwoWire::requestFrom(int address, int quantity)
uint8_t TwoWire::requestFrom(int address, int quantity, int sendStop)
{
return requestFrom(static_cast<uint8_t>(address), static_cast<size_t>(quantity), static_cast<bool>(sendStop));
return requestFrom(static_cast<uint8_t>(address), static_cast<size_t>(quantity),
static_cast<bool>(sendStop));
}
void TwoWire::beginTransmission(uint8_t address)
{
transmitting = 1;
txAddress = address;
txBufferIndex = 0;
transmitting = 1;
txAddress = address;
txBufferIndex = 0;
txBufferLength = 0;
}
@@ -167,10 +168,10 @@ void TwoWire::beginTransmission(int address)
uint8_t TwoWire::endTransmission(uint8_t sendStop)
{
int8_t ret = twi_writeTo(txAddress, txBuffer, txBufferLength, sendStop);
txBufferIndex = 0;
int8_t ret = twi_writeTo(txAddress, txBuffer, txBufferLength, sendStop);
txBufferIndex = 0;
txBufferLength = 0;
transmitting = 0;
transmitting = 0;
return ret;
}
@@ -199,7 +200,7 @@ size_t TwoWire::write(uint8_t data)
return 1;
}
size_t TwoWire::write(const uint8_t *data, size_t quantity)
size_t TwoWire::write(const uint8_t* data, size_t quantity)
{
if (transmitting)
{
@@ -255,9 +256,9 @@ int TwoWire::peek(void)
void TwoWire::flush(void)
{
rxBufferIndex = 0;
rxBufferIndex = 0;
rxBufferLength = 0;
txBufferIndex = 0;
txBufferIndex = 0;
txBufferLength = 0;
}
@@ -283,7 +284,7 @@ void TwoWire::onReceiveService(uint8_t* inBytes, size_t numBytes)
}
// set rx iterator vars
rxBufferIndex = 0;
rxBufferIndex = 0;
rxBufferLength = numBytes;
// alert user program
@@ -300,7 +301,7 @@ void TwoWire::onRequestService(void)
// reset tx buffer iterator vars
// !!! this will kill any pending pre-master sendTo() activity
txBufferIndex = 0;
txBufferIndex = 0;
txBufferLength = 0;
// alert user program
@@ -312,7 +313,7 @@ void TwoWire::onReceive(void (*function)(int))
// arduino api compatibility fixer:
// really hope size parameter will not exceed 2^31 :)
static_assert(sizeof(int) == sizeof(size_t), "something is wrong in Arduino kingdom");
user_onReceive = reinterpret_cast<void(*)(size_t)>(function);
user_onReceive = reinterpret_cast<void (*)(size_t)>(function);
}
void TwoWire::onReceive(void (*function)(size_t))

View File

@@ -27,45 +27,45 @@
#include <inttypes.h>
#include "Stream.h"
#ifndef I2C_BUFFER_LENGTH
// DEPRECATED: Do not use BUFFER_LENGTH, prefer I2C_BUFFER_LENGTH
#define BUFFER_LENGTH 128
#define I2C_BUFFER_LENGTH BUFFER_LENGTH
#endif
class TwoWire : public Stream
class TwoWire: public Stream
{
private:
static uint8_t rxBuffer[];
static size_t rxBufferIndex;
static size_t rxBufferLength;
static size_t rxBufferIndex;
static size_t rxBufferLength;
static uint8_t txAddress;
static uint8_t txBuffer[];
static size_t txBufferIndex;
static size_t txBufferLength;
static size_t txBufferIndex;
static size_t txBufferLength;
static uint8_t transmitting;
static void (*user_onRequest)(void);
static void (*user_onReceive)(size_t);
static void onRequestService(void);
static void onReceiveService(uint8_t*, size_t);
public:
TwoWire();
void begin(int sda, int scl);
void begin(int sda, int scl, uint8_t address);
void pins(int sda, int scl) __attribute__((deprecated)); // use begin(sda, scl) in new code
void begin();
void begin(uint8_t);
void begin(int);
void setClock(uint32_t);
void setClockStretchLimit(uint32_t);
void beginTransmission(uint8_t);
void beginTransmission(int);
void begin(int sda, int scl);
void begin(int sda, int scl, uint8_t address);
void pins(int sda, int scl) __attribute__((deprecated)); // use begin(sda, scl) in new code
void begin();
void begin(uint8_t);
void begin(int);
void setClock(uint32_t);
void setClockStretchLimit(uint32_t);
void beginTransmission(uint8_t);
void beginTransmission(int);
uint8_t endTransmission(void);
uint8_t endTransmission(uint8_t);
size_t requestFrom(uint8_t address, size_t size, bool sendStop);
size_t requestFrom(uint8_t address, size_t size, bool sendStop);
uint8_t status();
uint8_t requestFrom(uint8_t, uint8_t);
@@ -74,14 +74,14 @@ public:
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)); // arduino api
void onReceive(void (*)(size_t)); // legacy esp8266 backward compatibility
void onRequest(void (*)(void));
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)); // arduino api
void onReceive(void (*)(size_t)); // legacy esp8266 backward compatibility
void onRequest(void (*)(void));
using Print::write;
};
@@ -91,4 +91,3 @@ extern TwoWire Wire;
#endif
#endif

View File

@@ -18,8 +18,8 @@ const int16_t I2C_MASTER = 0x42;
const int16_t I2C_SLAVE = 0x08;
void setup() {
Serial.begin(115200); // start serial for output
Wire.begin(SDA_PIN, SCL_PIN, I2C_MASTER); // join i2c bus (address optional for master)
Serial.begin(115200); // start serial for output
Wire.begin(SDA_PIN, SCL_PIN, I2C_MASTER); // join i2c bus (address optional for master)
}
void loop() {
@@ -27,11 +27,11 @@ void loop() {
static periodic nextPing(1000);
if (nextPing) {
Wire.requestFrom(I2C_SLAVE, 6); // request 6 bytes from slave device #8
Wire.requestFrom(I2C_SLAVE, 6); // request 6 bytes from slave device #8
while (Wire.available()) { // slave may send less than requested
char c = Wire.read(); // receive a byte as character
Serial.print(c); // print the character
while (Wire.available()) { // slave may send less than requested
char c = Wire.read(); // receive a byte as character
Serial.print(c); // print the character
}
}
}

View File

@@ -18,7 +18,7 @@ const int16_t I2C_MASTER = 0x42;
const int16_t I2C_SLAVE = 0x08;
void setup() {
Wire.begin(SDA_PIN, SCL_PIN, I2C_MASTER); // join i2c bus (address optional for master)
Wire.begin(SDA_PIN, SCL_PIN, I2C_MASTER); // join i2c bus (address optional for master)
}
byte x = 0;
@@ -28,10 +28,10 @@ void loop() {
static periodic nextPing(1000);
if (nextPing) {
Wire.beginTransmission(I2C_SLAVE); // transmit to device #8
Wire.write("x is "); // sends five bytes
Wire.write(x); // sends one byte
Wire.endTransmission(); // stop transmitting
Wire.beginTransmission(I2C_SLAVE); // transmit to device #8
Wire.write("x is "); // sends five bytes
Wire.write(x); // sends one byte
Wire.endTransmission(); // stop transmitting
x++;
}

View File

@@ -18,24 +18,23 @@ const int16_t I2C_MASTER = 0x42;
const int16_t I2C_SLAVE = 0x08;
void setup() {
Serial.begin(115200); // start serial for output
Serial.begin(115200); // start serial for output
Wire.begin(SDA_PIN, SCL_PIN, I2C_SLAVE); // new syntax: join i2c bus (address required for slave)
Wire.onReceive(receiveEvent); // register event
Wire.begin(SDA_PIN, SCL_PIN, I2C_SLAVE); // new syntax: join i2c bus (address required for slave)
Wire.onReceive(receiveEvent); // register event
}
void loop() {
}
void loop() {}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(size_t howMany) {
(void) howMany;
while (1 < Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
(void)howMany;
while (1 < Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
}

View File

@@ -17,16 +17,15 @@ const int16_t I2C_MASTER = 0x42;
const int16_t I2C_SLAVE = 0x08;
void setup() {
Wire.begin(SDA_PIN, SCL_PIN, I2C_SLAVE); // join i2c bus with address #8
Wire.onRequest(requestEvent); // register event
Wire.begin(SDA_PIN, SCL_PIN, I2C_SLAVE); // join i2c bus with address #8
Wire.onRequest(requestEvent); // register event
}
void loop() {
}
void loop() {}
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
Wire.write("hello\n"); // respond with message of 6 bytes
Wire.write("hello\n"); // respond with message of 6 bytes
// as expected by master
}