Skip to content

Commit b29670c

Browse files
ci(pre-commit): Apply automatic fixes
1 parent bf961e1 commit b29670c

File tree

2 files changed

+87
-87
lines changed

2 files changed

+87
-87
lines changed
Lines changed: 80 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define TwoWire TwoWireInternal
2-
#define Wire WireInternal
3-
#define Wire1 WireInternal1
2+
#define Wire WireInternal
3+
#define Wire1 WireInternal1
44

55
#include "pins_arduino.h"
66
#include "../../libraries/Wire/src/Wire.h"
@@ -10,110 +10,110 @@ static bool wireInitialized = false;
1010

1111
// From https://www.diodes.com/datasheet/download/PI4IOE5V6408.pdf
1212
static void writeRegister(uint8_t address, uint8_t reg, uint8_t value) {
13-
WireInternal.beginTransmission(address);
14-
WireInternal.write(reg);
15-
WireInternal.write(value);
16-
WireInternal.endTransmission();
13+
WireInternal.beginTransmission(address);
14+
WireInternal.write(reg);
15+
WireInternal.write(value);
16+
WireInternal.endTransmission();
1717
}
1818

1919
static uint8_t readRegister(uint8_t address, uint8_t reg) {
20-
WireInternal.beginTransmission(address);
21-
WireInternal.write(reg);
22-
WireInternal.endTransmission(false);
23-
WireInternal.requestFrom(address, 1);
24-
return WireInternal.read();
20+
WireInternal.beginTransmission(address);
21+
WireInternal.write(reg);
22+
WireInternal.endTransmission(false);
23+
WireInternal.requestFrom(address, 1);
24+
return WireInternal.read();
2525
}
2626

2727
static void writeBitRegister(uint8_t address, uint8_t reg, uint8_t bit, uint8_t value) {
28-
uint8_t val = readRegister(address, reg);
29-
if (value) {
30-
writeRegister(address, reg, val | (1 << bit));
31-
} else {
32-
writeRegister(address, reg, val & ~(1 << bit));
33-
}
28+
uint8_t val = readRegister(address, reg);
29+
if (value) {
30+
writeRegister(address, reg, val | (1 << bit));
31+
} else {
32+
writeRegister(address, reg, val & ~(1 << bit));
33+
}
3434
}
3535

3636
static bool readBitRegister(uint8_t address, uint8_t reg, uint8_t bit) {
37-
uint8_t val = readRegister(address, reg);
38-
return ((val & (1 << bit)) > 0);
37+
uint8_t val = readRegister(address, reg);
38+
return ((val & (1 << bit)) > 0);
3939
}
4040

4141
void pinMode(ExpanderPin pin, uint8_t mode) {
42-
if (!wireInitialized) {
43-
WireInternal.begin(SDA, SCL);
44-
wireInitialized = true;
45-
// reset all registers to default state
46-
writeRegister(pin.address, 0x1, 0x1);
47-
// set all pins as high as default state
48-
writeRegister(pin.address, 0x9, 0xFF);
49-
// interrupt mask to all pins
50-
writeRegister(pin.address, 0x11, 0xFF);
51-
// all input
52-
writeRegister(pin.address, 0x3, 0);
53-
}
54-
writeBitRegister(pin.address, 0x3, pin.pin, mode == OUTPUT);
55-
if (mode == OUTPUT) {
56-
// remove high impedence
57-
writeBitRegister(pin.address, 0x7, pin.pin, false);
58-
} else if (mode == INPUT_PULLUP) {
59-
// set pull-up resistor
60-
writeBitRegister(pin.address, 0xB, pin.pin, true);
61-
writeBitRegister(pin.address, 0xD, pin.pin, true);
62-
} else if (mode == INPUT_PULLDOWN) {
63-
// disable pull-up resistor
64-
writeBitRegister(pin.address, 0xB, pin.pin, true);
65-
writeBitRegister(pin.address, 0xD, pin.pin, false);
66-
} else if (mode == INPUT) {
67-
// disable pull selector resistor
68-
writeBitRegister(pin.address, 0xB, pin.pin, false);
69-
}
42+
if (!wireInitialized) {
43+
WireInternal.begin(SDA, SCL);
44+
wireInitialized = true;
45+
// reset all registers to default state
46+
writeRegister(pin.address, 0x1, 0x1);
47+
// set all pins as high as default state
48+
writeRegister(pin.address, 0x9, 0xFF);
49+
// interrupt mask to all pins
50+
writeRegister(pin.address, 0x11, 0xFF);
51+
// all input
52+
writeRegister(pin.address, 0x3, 0);
53+
}
54+
writeBitRegister(pin.address, 0x3, pin.pin, mode == OUTPUT);
55+
if (mode == OUTPUT) {
56+
// remove high impedence
57+
writeBitRegister(pin.address, 0x7, pin.pin, false);
58+
} else if (mode == INPUT_PULLUP) {
59+
// set pull-up resistor
60+
writeBitRegister(pin.address, 0xB, pin.pin, true);
61+
writeBitRegister(pin.address, 0xD, pin.pin, true);
62+
} else if (mode == INPUT_PULLDOWN) {
63+
// disable pull-up resistor
64+
writeBitRegister(pin.address, 0xB, pin.pin, true);
65+
writeBitRegister(pin.address, 0xD, pin.pin, false);
66+
} else if (mode == INPUT) {
67+
// disable pull selector resistor
68+
writeBitRegister(pin.address, 0xB, pin.pin, false);
69+
}
7070
}
7171

7272
void digitalWrite(ExpanderPin pin, uint8_t val) {
73-
if (!wireInitialized) {
74-
WireInternal.begin(SDA, SCL);
75-
wireInitialized = true;
76-
}
77-
writeBitRegister(pin.address, 0x5, pin.pin, val == HIGH);
73+
if (!wireInitialized) {
74+
WireInternal.begin(SDA, SCL);
75+
wireInitialized = true;
76+
}
77+
writeBitRegister(pin.address, 0x5, pin.pin, val == HIGH);
7878
}
7979

8080
int digitalRead(ExpanderPin pin) {
81-
if (!wireInitialized) {
82-
WireInternal.begin(SDA, SCL);
83-
wireInitialized = true;
84-
}
85-
return readBitRegister(pin.address, 0xF, pin.pin);
81+
if (!wireInitialized) {
82+
WireInternal.begin(SDA, SCL);
83+
wireInitialized = true;
84+
}
85+
return readBitRegister(pin.address, 0xF, pin.pin);
8686
}
8787

8888
void NessoBattery::enableCharge() {
89-
// AW32001E - address 0x49
90-
// set CEB bit low (charge enable)
91-
if (!wireInitialized) {
92-
WireInternal.begin(SDA, SCL);
93-
wireInitialized = true;
94-
}
95-
writeBitRegister(0x49, 0x1, 3, false);
89+
// AW32001E - address 0x49
90+
// set CEB bit low (charge enable)
91+
if (!wireInitialized) {
92+
WireInternal.begin(SDA, SCL);
93+
wireInitialized = true;
94+
}
95+
writeBitRegister(0x49, 0x1, 3, false);
9696
}
9797

9898
float NessoBattery::getVoltage() {
99-
// BQ27220 - address 0x55
100-
if (!wireInitialized) {
101-
WireInternal.begin(SDA, SCL);
102-
wireInitialized = true;
103-
}
104-
uint16_t voltage = (readRegister(0x55, 0x9) << 8) | readRegister(0x55, 0x8);
105-
return (float)voltage / 1000.0f;
99+
// BQ27220 - address 0x55
100+
if (!wireInitialized) {
101+
WireInternal.begin(SDA, SCL);
102+
wireInitialized = true;
103+
}
104+
uint16_t voltage = (readRegister(0x55, 0x9) << 8) | readRegister(0x55, 0x8);
105+
return (float)voltage / 1000.0f;
106106
}
107107

108108
uint16_t NessoBattery::getChargeLevel() {
109-
// BQ27220 - address 0x55
110-
if (!wireInitialized) {
111-
WireInternal.begin(SDA, SCL);
112-
wireInitialized = true;
113-
}
114-
uint16_t current_capacity = readRegister(0x55, 0x11) << 8 | readRegister(0x55, 0x10);
115-
uint16_t total_capacity = readRegister(0x55, 0x13) << 8 | readRegister(0x55, 0x12);
116-
return (current_capacity * 100) / total_capacity;
109+
// BQ27220 - address 0x55
110+
if (!wireInitialized) {
111+
WireInternal.begin(SDA, SCL);
112+
wireInitialized = true;
113+
}
114+
uint16_t current_capacity = readRegister(0x55, 0x11) << 8 | readRegister(0x55, 0x10);
115+
uint16_t total_capacity = readRegister(0x55, 0x13) << 8 | readRegister(0x55, 0x12);
116+
return (current_capacity * 100) / total_capacity;
117117
}
118118

119119
ExpanderPin LORA_LNA_ENABLE(5);
@@ -126,4 +126,4 @@ ExpanderPin LCD_RESET((1 << 8) | 1);
126126
ExpanderPin GROVE_POWER_EN((1 << 8) | 2);
127127
ExpanderPin VIN_DETECT((1 << 8) | 5);
128128
ExpanderPin LCD_BACKLIGHT((1 << 8) | 6);
129-
ExpanderPin LED_BUILTIN((1 << 8) | 7);
129+
ExpanderPin LED_BUILTIN((1 << 8) | 7);

variants/arduino_nesso_n1/pins_arduino.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ static const uint8_t LCD_RS = 16;
4444
/* address: 0x43/0x44 */
4545
class ExpanderPin {
4646
public:
47-
ExpanderPin(uint16_t _pin) : pin(_pin & 0xFF), address(_pin & 0x100 ? 0x44 : 0x43) {};
48-
uint8_t pin;
49-
uint8_t address;
47+
ExpanderPin(uint16_t _pin) : pin(_pin & 0xFF), address(_pin & 0x100 ? 0x44 : 0x43){};
48+
uint8_t pin;
49+
uint8_t address;
5050
};
5151

5252
class NessoBattery {
5353
public:
54-
NessoBattery() {};
55-
void enableCharge(); // enable charging
56-
float getVoltage(); // get battery voltage in Volts
57-
uint16_t getChargeLevel(); // get battery charge level in percents
54+
NessoBattery(){};
55+
void enableCharge(); // enable charging
56+
float getVoltage(); // get battery voltage in Volts
57+
uint16_t getChargeLevel(); // get battery charge level in percents
5858
};
5959

6060
extern ExpanderPin LORA_LNA_ENABLE;

0 commit comments

Comments
 (0)