Don't discard status return values
Bug: 357090965
Change-Id: I516c6bbfb134a1420bf0f42b5b8ed6cf1b6cf5bc
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/experimental/+/227452
Reviewed-by: Wyatt Hepler <hepler@google.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Commit-Queue: Ted Pudlik <tpudlik@google.com>
diff --git a/pw_display_driver_st7789/display_driver.cc b/pw_display_driver_st7789/display_driver.cc
index 592d441..9a467eb 100644
--- a/pw_display_driver_st7789/display_driver.cc
+++ b/pw_display_driver_st7789/display_driver.cc
@@ -84,26 +84,26 @@
DisplayDriverST7789::DisplayDriverST7789(const Config& config)
: config_(config) {}
-void DisplayDriverST7789::SetMode(Mode mode) {
+Status DisplayDriverST7789::SetMode(Mode mode) {
// Set the D/CX pin to indicate data or command values.
if (mode == Mode::kData) {
// Set data command pin to 1
- config_.data_cmd_gpio.SetState(State::kActive);
+ return config_.data_cmd_gpio.SetState(State::kActive);
} else {
// Set data command pin to 0
- config_.data_cmd_gpio.SetState(State::kInactive);
+ return config_.data_cmd_gpio.SetState(State::kInactive);
}
}
Status DisplayDriverST7789::WriteCommand(Device::Transaction& transaction,
const Command& command) {
- SetMode(Mode::kCommand);
+ PW_TRY(SetMode(Mode::kCommand));
byte buff[1]{static_cast<byte>(command.command)};
auto s = transaction.Write(buff);
if (!s.ok())
return s;
- SetMode(Mode::kData);
+ PW_TRY(SetMode(Mode::kData));
if (command.command_data.empty()) {
return OkStatus();
}
@@ -114,58 +114,63 @@
auto transaction = config_.spi_device_8_bit.StartTransaction(
ChipSelectBehavior::kPerWriteRead);
- WriteCommand(transaction, {ST7789_SWRESET, kEmptyArray}); // Software reset
+ PW_TRY(WriteCommand(transaction,
+ {ST7789_SWRESET, kEmptyArray})); // Software reset
pw::this_thread::sleep_for(pw::chrono::SystemClock::for_at_least(100ms));
- WriteCommand(transaction, {ST7789_TEON, kEmptyArray});
- WriteCommand(transaction, {ST7789_COLMOD, array<byte, 1>{byte{0x05}}});
+ PW_TRY(WriteCommand(transaction, {ST7789_TEON, kEmptyArray}));
+ PW_TRY(
+ WriteCommand(transaction, {ST7789_COLMOD, array<byte, 1>{byte{0x05}}}));
- WriteCommand(transaction,
- {ST7789_PORCTRL,
- array<byte, 5>{
- byte{0x0c},
- byte{0x0c},
- byte{0x00},
- byte{0x33},
- byte{0x33},
- }});
- WriteCommand(transaction, {ST7789_LCMCTRL, array<byte, 1>{byte{0x2c}}});
- WriteCommand(transaction, {ST7789_VDVVRHEN, array<byte, 1>{byte{0x01}}});
- WriteCommand(transaction, {ST7789_VRHS, array<byte, 1>{byte{0x12}}});
- WriteCommand(transaction, {ST7789_VDVS, array<byte, 1>{byte{0x20}}});
- WriteCommand(transaction,
- {ST7789_PWCTRL1,
- array<byte, 2>{
- byte{0xa4},
- byte{0xa1},
- }});
- WriteCommand(transaction, {ST7789_FRCTRL2, array<byte, 1>{byte{0x0f}}});
+ PW_TRY(WriteCommand(transaction,
+ {ST7789_PORCTRL,
+ array<byte, 5>{
+ byte{0x0c},
+ byte{0x0c},
+ byte{0x00},
+ byte{0x33},
+ byte{0x33},
+ }}));
+ PW_TRY(
+ WriteCommand(transaction, {ST7789_LCMCTRL, array<byte, 1>{byte{0x2c}}}));
+ PW_TRY(
+ WriteCommand(transaction, {ST7789_VDVVRHEN, array<byte, 1>{byte{0x01}}}));
+ PW_TRY(WriteCommand(transaction, {ST7789_VRHS, array<byte, 1>{byte{0x12}}}));
+ PW_TRY(WriteCommand(transaction, {ST7789_VDVS, array<byte, 1>{byte{0x20}}}));
+ PW_TRY(WriteCommand(transaction,
+ {ST7789_PWCTRL1,
+ array<byte, 2>{
+ byte{0xa4},
+ byte{0xa1},
+ }}));
+ PW_TRY(
+ WriteCommand(transaction, {ST7789_FRCTRL2, array<byte, 1>{byte{0x0f}}}));
- WriteCommand(transaction, {ST7789_INVON, kEmptyArray});
- WriteCommand(transaction, {ST7789_SLPOUT, kEmptyArray});
- WriteCommand(transaction, {ST7789_DISPON, kEmptyArray});
+ PW_TRY(WriteCommand(transaction, {ST7789_INVON, kEmptyArray}));
+ PW_TRY(WriteCommand(transaction, {ST7789_SLPOUT, kEmptyArray}));
+ PW_TRY(WriteCommand(transaction, {ST7789_DISPON, kEmptyArray}));
// Landscape drawing Column Address Set
const uint16_t kMaxColumn = config_.screen_width - 1;
- WriteCommand(transaction,
- {ST7789_CASET,
- array<byte, 4>{
- byte{0x0},
- byte{0x0},
- byte{static_cast<uint8_t>(kMaxColumn >> 8)},
- byte{static_cast<uint8_t>(kMaxColumn & 0xff)},
- }});
+ PW_TRY(WriteCommand(transaction,
+ {ST7789_CASET,
+ array<byte, 4>{
+ byte{0x0},
+ byte{0x0},
+ byte{static_cast<uint8_t>(kMaxColumn >> 8)},
+ byte{static_cast<uint8_t>(kMaxColumn & 0xff)},
+ }}));
// Page Address Set
const uint16_t kMaxRow = config_.screen_height - 1;
- WriteCommand(transaction,
- {ST7789_RASET,
- array<byte, 4>{
- byte{0x0},
- byte{0x0},
- byte{static_cast<uint8_t>(kMaxRow >> 8)},
- byte{static_cast<uint8_t>(kMaxRow & 0xff)},
- }});
+ PW_TRY(WriteCommand(transaction,
+ {ST7789_RASET,
+ array<byte, 4>{
+ byte{0x0},
+ byte{0x0},
+ byte{static_cast<uint8_t>(kMaxRow >> 8)},
+ byte{static_cast<uint8_t>(kMaxRow & 0xff)},
+ }}));
uint8_t madctl = 0;
bool rotate_180 = false;
@@ -181,7 +186,8 @@
madctl |= ST7789_MADCTL_SWAP_XY | ST7789_MADCTL_SCAN_ORDER;
}
- WriteCommand(transaction, {ST7789_MADCTL, array<byte, 1>{byte{madctl}}});
+ PW_TRY(
+ WriteCommand(transaction, {ST7789_MADCTL, array<byte, 1>{byte{madctl}}}));
pw::this_thread::sleep_for(pw::chrono::SystemClock::for_at_least(50ms));
@@ -232,25 +238,25 @@
const uint16_t max_col_idx =
std::max(config_.screen_width - 1,
col_idx + static_cast<int>(row_pixels.size()));
- WriteCommand(transaction,
- {ST7789_CASET,
- std::array<std::byte, 4>{
- std::byte{HighByte(col_idx)},
- std::byte{LowByte(col_idx)},
- std::byte{HighByte(max_col_idx)},
- std::byte{LowByte(max_col_idx)},
- }});
+ PW_TRY(WriteCommand(transaction,
+ {ST7789_CASET,
+ std::array<std::byte, 4>{
+ std::byte{HighByte(col_idx)},
+ std::byte{LowByte(col_idx)},
+ std::byte{HighByte(max_col_idx)},
+ std::byte{LowByte(max_col_idx)},
+ }}));
// Page Address Set
uint16_t max_row_idx = row_idx;
- WriteCommand(transaction,
- {ST7789_RASET,
- std::array<std::byte, 4>{
- std::byte{HighByte(row_idx)},
- std::byte{LowByte(row_idx)},
- std::byte{HighByte(max_row_idx)},
- std::byte{LowByte(max_row_idx)},
- }});
+ PW_TRY(WriteCommand(transaction,
+ {ST7789_RASET,
+ std::array<std::byte, 4>{
+ std::byte{HighByte(row_idx)},
+ std::byte{LowByte(row_idx)},
+ std::byte{HighByte(max_row_idx)},
+ std::byte{LowByte(max_row_idx)},
+ }}));
PW_TRY(WriteCommand(transaction, {ST7789_RAMWR, kEmptyArray}));
}
diff --git a/pw_display_driver_st7789/public/pw_display_driver_st7789/display_driver.h b/pw_display_driver_st7789/public/pw_display_driver_st7789/display_driver.h
index b3b079a..69904f5 100644
--- a/pw_display_driver_st7789/public/pw_display_driver_st7789/display_driver.h
+++ b/pw_display_driver_st7789/public/pw_display_driver_st7789/display_driver.h
@@ -80,7 +80,7 @@
Status Reset();
// Set the command/data mode of the display controller.
- void SetMode(Mode mode);
+ Status SetMode(Mode mode);
// Write the command to the display controller.
Status WriteCommand(pw::spi::Device::Transaction& transaction,
const Command& command);