Skip to content

Commit 20e5685

Browse files
committed
style: use std:: everywhere
1 parent 05bf69b commit 20e5685

File tree

4 files changed

+44
-39
lines changed

4 files changed

+44
-39
lines changed

src/AT24CM02.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
#include <algorithm>
44

5-
constexpr static uint32_t kAddrMask{(1U << 18U) - 1U};
5+
constexpr static std::uint32_t kAddrMask{(1U << 18U) - 1U};
66

7-
AT24CM02::AT24CM02(i2c_inst_t* i2c, bool addr_pin) noexcept
7+
AT24CM02::AT24CM02(::i2c_inst_t* i2c, bool addr_pin) noexcept
88
: i2c_{i2c}, addr_pin_(addr_pin ? 1U : 0U) {}
99

10-
bool AT24CM02::Write(uint32_t addr, const uint8_t* buf,
11-
size_t len) const noexcept {
10+
bool AT24CM02::Write(std::uint32_t addr, const std::uint8_t* buf,
11+
std::size_t len) const noexcept {
1212
if (!i2c_ || !buf || len == 0 || (addr & ~kAddrMask)) {
1313
return false;
1414
}
@@ -17,15 +17,16 @@ bool AT24CM02::Write(uint32_t addr, const uint8_t* buf,
1717
return false;
1818
}
1919

20-
size_t page_remain = kBytesPerPage - (addr % kBytesPerPage);
20+
std::size_t page_remain = kBytesPerPage - (addr % kBytesPerPage);
2121

2222
if (len < page_remain) {
2323
page_remain = len;
2424
}
2525

2626
while (len > 0) {
27-
const uint8_t i2c_addr = (0xA0 | (addr_pin_ << 3U) | (addr >> 15U)) >> 1U;
28-
uint8_t addr_bytes[2];
27+
const std::uint8_t i2c_addr =
28+
(0xA0 | (addr_pin_ << 3U) | (addr >> 15U)) >> 1U;
29+
std::uint8_t addr_bytes[2];
2930

3031
addr_bytes[0] = (addr & 0x0FF00) >> 8;
3132
addr_bytes[1] = addr & 0x000FF;
@@ -54,7 +55,8 @@ bool AT24CM02::Write(uint32_t addr, const uint8_t* buf,
5455
return true;
5556
}
5657

57-
bool AT24CM02::Read(uint32_t addr, uint8_t* buf, size_t len) const noexcept {
58+
bool AT24CM02::Read(std::uint32_t addr, std::uint8_t* buf,
59+
std::size_t len) const noexcept {
5860
if (!i2c_ || !buf || len == 0 || (addr & ~kAddrMask)) {
5961
return false;
6062
}
@@ -63,8 +65,9 @@ bool AT24CM02::Read(uint32_t addr, uint8_t* buf, size_t len) const noexcept {
6365
return false;
6466
}
6567

66-
const uint8_t i2c_addr = (0xA0 | (addr_pin_ << 3U) | (addr >> 15U)) >> 1U;
67-
uint8_t addr_bytes[2];
68+
const std::uint8_t i2c_addr =
69+
(0xA0 | (addr_pin_ << 3U) | (addr >> 15U)) >> 1U;
70+
std::uint8_t addr_bytes[2];
6871

6972
addr_bytes[0] = (addr & 0x0FF00) >> 8;
7073
addr_bytes[1] = addr & 0x000FF;

src/AT24CM02.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
#ifndef PICO_IDENT_SRC_AT24CM02_H
22
#define PICO_IDENT_SRC_AT24CM02_H
33

4-
#include "hardware/i2c.h"
5-
64
#include <cstddef>
75
#include <cstdint>
86

7+
#include "hardware/i2c.h"
8+
99
class AT24CM02 {
1010
public:
11-
static constexpr size_t kPages{1024U};
12-
static constexpr size_t kBytesPerPage{256U};
11+
static constexpr std::size_t kPages{1024U};
12+
static constexpr std::size_t kBytesPerPage{256U};
1313

14-
explicit AT24CM02(i2c_inst_t* i2c, bool addr_pin) noexcept;
14+
explicit AT24CM02(::i2c_inst_t* i2c, bool addr_pin) noexcept;
1515

1616
explicit AT24CM02(std::nullptr_t, bool) = delete;
1717

18-
bool Write(uint32_t addr, const uint8_t* buf, size_t len) const noexcept;
18+
bool Write(std::uint32_t addr, const std::uint8_t* buf,
19+
std::size_t len) const noexcept;
1920

20-
bool Read(uint32_t addr, uint8_t* buf, size_t len) const noexcept;
21+
bool Read(std::uint32_t addr, std::uint8_t* buf,
22+
std::size_t len) const noexcept;
2123

2224
private:
23-
const uint8_t addr_pin_;
24-
i2c_inst_t* i2c_;
25+
const std::uint8_t addr_pin_;
26+
::i2c_inst_t* i2c_;
2527
};
2628

27-
#endif /* PICO_IDENT_SRC_AT24CM02_H */
29+
#endif /* PICO_IDENT_SRC_AT24CM02_H */

src/DeviceInfo.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ struct DeviceInfoString {
3838
return sv;
3939
}
4040

41-
[[nodiscard]] uint8_t Sum() const noexcept {
42-
uint8_t sum{};
41+
[[nodiscard]] std::uint8_t Sum() const noexcept {
42+
std::uint8_t sum{};
4343
for (char c : data) {
44-
sum += static_cast<uint8_t>(c);
44+
sum += static_cast<std::uint8_t>(c);
4545
}
4646
return sum;
4747
}
@@ -67,7 +67,7 @@ struct DeviceInfoBlock {
6767
// This checksum field is calculated by summing up all of the previous bytes
6868
// in this structure. It's crude, but should be good enough for such a basic
6969
// device.
70-
uint8_t checksum;
70+
std::uint8_t checksum;
7171

7272
// If any field was not valid and was updated, returns false.
7373
[[nodiscard]] bool Validate() noexcept {
@@ -86,8 +86,8 @@ struct DeviceInfoBlock {
8686
}
8787

8888
// Computes (but does not update!) the checksum.
89-
[[nodiscard]] uint8_t ComputeChecksum() const noexcept {
90-
uint8_t sum{};
89+
[[nodiscard]] std::uint8_t ComputeChecksum() const noexcept {
90+
std::uint8_t sum{};
9191
sum += mfg.Sum();
9292
sum += name.Sum();
9393
sum += ver.Sum();

src/main.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535

3636
#define I2C_INST i2c0
3737

38-
static constexpr uint32_t kDeviceInfoAddr{0x0};
39-
static constexpr uint32_t kEdgeCountAddr{0x800};
38+
static constexpr std::uint32_t kDeviceInfoAddr{0x0};
39+
static constexpr std::uint32_t kEdgeCountAddr{0x800};
4040

4141
// Board ID (this is set only once and stored here).
4242
static char board_id[PICO_UNIQUE_BOARD_ID_SIZE_BYTES * 2 + 1];
@@ -47,8 +47,8 @@ static DeviceInfoBlock data;
4747
// EEPROM peripheral.
4848
static AT24CM02 eeprom{I2C_INST, true};
4949

50-
static volatile uint32_t edgecount;
51-
static uint32_t last_edgecount;
50+
static volatile std::uint32_t edgecount;
51+
static std::uint32_t last_edgecount;
5252
static volatile ::absolute_time_t last_edge_time;
5353

5454
[[noreturn]] static void Panic() noexcept {
@@ -59,14 +59,15 @@ static volatile ::absolute_time_t last_edge_time;
5959
}
6060

6161
static void StoreDeviceInfo() noexcept {
62-
if (!eeprom.Write(kDeviceInfoAddr, reinterpret_cast<const uint8_t*>(&data),
62+
if (!eeprom.Write(kDeviceInfoAddr,
63+
reinterpret_cast<const std::uint8_t*>(&data),
6364
sizeof(data))) {
6465
Panic();
6566
}
6667
}
6768

6869
static void LoadDeviceInfo() noexcept {
69-
if (!eeprom.Read(kDeviceInfoAddr, reinterpret_cast<uint8_t*>(&data),
70+
if (!eeprom.Read(kDeviceInfoAddr, reinterpret_cast<std::uint8_t*>(&data),
7071
sizeof(data))) {
7172
Panic();
7273
}
@@ -81,16 +82,16 @@ static void ValidateDeviceInfo() noexcept {
8182
}
8283
}
8384

84-
static void StoreEdgeCount(uint32_t ec) noexcept {
85-
if (!eeprom.Write(kEdgeCountAddr, reinterpret_cast<const uint8_t*>(&ec),
85+
static void StoreEdgeCount(std::uint32_t ec) noexcept {
86+
if (!eeprom.Write(kEdgeCountAddr, reinterpret_cast<const std::uint8_t*>(&ec),
8687
sizeof(ec))) {
8788
Panic();
8889
}
8990
}
9091

9192
static void LoadEdgeCount() noexcept {
92-
uint32_t ec;
93-
if (!eeprom.Read(kEdgeCountAddr, reinterpret_cast<uint8_t*>(&ec),
93+
std::uint32_t ec;
94+
if (!eeprom.Read(kEdgeCountAddr, reinterpret_cast<std::uint8_t*>(&ec),
9495
sizeof(ec))) {
9596
Panic();
9697
}
@@ -217,8 +218,7 @@ int main(void) {
217218

218219
// Falling edges increase the edge count.
219220
::gpio_set_irq_enabled_with_callback(
220-
PIN_SWITCH, GPIO_IRQ_EDGE_FALL, true,
221-
[](uint, uint32_t) {
221+
PIN_SWITCH, GPIO_IRQ_EDGE_FALL, true, [](::uint, std::uint32_t) {
222222
const auto now = ::get_absolute_time();
223223
const auto diff = ::absolute_time_diff_us(last_edge_time, now);
224224
// 50ms debounce
@@ -229,7 +229,7 @@ int main(void) {
229229
});
230230

231231
char rdbuf[512] = {0};
232-
size_t idx = 0;
232+
std::size_t idx = 0;
233233
int c;
234234
while (1) {
235235
c = ::getchar_timeout_us(10);

0 commit comments

Comments
 (0)