Skip to content

fix: move the display's initial code to the app#78

Merged
CloudyPadmal merged 2 commits intofossasia:mainfrom
kienvo:dp-init
Jul 3, 2025
Merged

fix: move the display's initial code to the app#78
CloudyPadmal merged 2 commits intofossasia:mainfrom
kienvo:dp-init

Conversation

@kienvo
Copy link
Copy Markdown
Member

@kienvo kienvo commented Jun 30, 2025

Fixes #76

Summary by Sourcery

Abstract EPaper waveform handling and integrate it into the UC8253 driver, refactor the NFC Protocol to streamline tag communication, and relocate display initialization into the application to correct startup issues.

New Features:

  • Introduce waveform abstraction (Waveform and Lut) and add QuickLut implementation for the UC8253 driver
  • Implement init and setlut methods in Uc8253 to manage panel initialization and LUT loading

Bug Fixes:

Enhancements:

  • Refactor Protocol to store tagId internally and remove redundant tagId parameters from NFC operations
  • Simplify transceive/write flows and dynamic configuration commands in the Protocol
  • Move display initialization (power on and panel settings) into the app by calling epd.controller.init before frame transmission

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jun 30, 2025

Reviewer's Guide

This PR centralizes display initialization logic in the app by introducing waveform abstractions, extending the EPD driver interface, implementing a QuickLut for the UC8253 controller with init and LUT setup routines, and refactoring the Protocol class to manage tag IDs internally and streamline NFC operations.

Class diagram for new waveform abstractions and EPD driver interface

classDiagram
    class Lut {
        +int cmd
        +Uint8List data
    }
    class Waveform {
        <<abstract>>
        +String desc
        +int pll
        +List~Lut~ luts
    }
    class QuickLut {
        +desc
        +pll
        +luts
    }
    class Driver {
        <<abstract>>
        +String driverName
        +List~int~ transmissionLines
        +int refresh
        +int vcomLut
        +int wwLut
        +int bwLut
        +int wbLut
        +int bbLut
        +int panelSetting
        +int pllControl
        +WaveformList waveforms
        +Future<void> setlut(Protocol, Waveform)
        +Future<void> init(Protocol)
    }
    class Uc8253 {
        +refresh
        +vcomLut
        +wwLut
        +bwLut
        +wbLut
        +bbLut
        +panelSetting
        +pllControl
        +waveforms
        +driverName
        +transmissionLines
        +setlut(Protocol, Waveform)
        +init(Protocol)
    }
    QuickLut --|> Waveform
    Uc8253 --|> Driver
    WaveformList --> Waveform
Loading

Class diagram for relationships between Protocol and EPD driver

classDiagram
    class Protocol {
        +Epd epd
        +Future<void> writeImage(Uint8List image)
    }
    class Epd {
        +Driver controller
        +List<Uint8List> extractEpaperColorFrames(Uint8List image)
    }
    class Driver {
        <<abstract>>
        +Future<void> init(Protocol p)
        +Future<void> setlut(Protocol p, Waveform waveform)
        +List<int> transmissionLines
        +int refresh
    }
    Protocol --> Epd
    Epd --> Driver
    Driver <.. Protocol : uses
    Protocol ..> Driver : calls init, setlut
    Protocol ..> Epd : calls extractEpaperColorFrames
Loading

File-Level Changes

Change Details Files
Introduce Waveform and Lut abstractions for EPD drivers
  • Add Lut class to encapsulate command/data pairs
  • Define abstract Waveform with descriptor, PLL, and LUT list
  • Create WaveformList type alias
lib/util/epd/driver/waveform.dart
Extend Driver interface to support LUT and initialization
  • Add getters for vcomLut, wwLut, bwLut, wbLut, bbLut, panelSetting, pllControl
  • Define abstract setlut and init methods
  • Import waveform and protocol dependencies
lib/util/epd/driver/driver.dart
Implement QuickLut waveform and integrate into UC8253 driver
  • Create QuickLut subclass with detailed LUT data arrays
  • Add LUT command getters and waveforms list to Uc8253
  • Implement setlut to send PLL and LUT sequences over Protocol
  • Implement init method to power on display and apply panel settings
lib/util/epd/driver/uc8253.dart
Refactor Protocol class to manage tagId and simplify NFC method signatures
  • Introduce tagId field and assign on polling
  • Remove tagId parameter from _transceive, writeMsg, hasI2cGatheredMsg, enableEnergyHarvesting, and related methods
  • Update writeFrame and other flows to use internal tagId and unified writeMsg
  • Invoke epd.controller.init in the NFC handshake before frame transmission
lib/util/protocol.dart

Assessment against linked issues

Issue Objective Addressed Explanation
#76 Move the display's initial code from the firmware to the app.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @kienvo - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `lib/util/epd/driver/uc8253.dart:11` </location>
<code_context>
 // UC8253 commands/registers,
 // define in the epaper display controller (UC8253) reference manual
 class Uc8253 extends Driver {
   @override
   int get refresh => 0x12;
   @override
+  int get vcomLut => 0x20;
+  @override
+  int get wwLut => 0x21;
+  @override
+  int get bwLut => 0x22;
+  @override
+  int get wbLut => 0x23;
+  @override
+  int get bbLut => 0x24;
+  @override
+  int get panelSetting => 0x00;
+  @override
+  int get pllControl => 0x30;
+  @override
+  WaveformList waveforms = [QuickLut()];
+  @override
   get driverName => 'UC8253';
   @override
   List<int> get transmissionLines => [0x10, 0x13];
+
+  @override
+  Future<void> setlut(Protocol p, Waveform waveform) async {
+    await p.writeMsg(
+        Uint8List.fromList([p.fw.epdCmd, p.epd.controller.pllControl]));
</code_context>

<issue_to_address>
No error handling for protocol communication failures.

If writeMsg fails, setlut may throw and leave the device in an inconsistent state. Please add error handling or rollback logic to address partial updates.
</issue_to_address>

### Comment 2
<location> `lib/util/epd/driver/uc8253.dart:107` </location>
<code_context>
+  @override
+  int get pllControl => 0x30;
+  @override
+  WaveformList waveforms = [QuickLut()];
+  @override
   get driverName => 'UC8253';
</code_context>

<issue_to_address>
waveforms is mutable but likely intended to be constant.

Consider declaring waveforms as final to prevent reassignment if it is meant to remain constant.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
  @override
  WaveformList waveforms = [QuickLut()];
=======
  @override
  final WaveformList waveforms = [QuickLut()];
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +11 to +20
@override
String get desc => "Quick waveform for R_sense = 4R7 and PLL = 10Hz";
@override
int get pll => 0x01; // 10Hz
@override
List<Lut> get luts => [
Lut(
cmd: 0x20,
data: Uint8List.fromList([
// lut_vcom_quick
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): No error handling for protocol communication failures.

If writeMsg fails, setlut may throw and leave the device in an inconsistent state. Please add error handling or rollback logic to address partial updates.

Comment on lines +106 to +107
@override
WaveformList waveforms = [QuickLut()];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: waveforms is mutable but likely intended to be constant.

Consider declaring waveforms as final to prevent reassignment if it is meant to remain constant.

Suggested change
@override
WaveformList waveforms = [QuickLut()];
@override
final WaveformList waveforms = [QuickLut()];

await p.writeMsg(Uint8List.fromList([p.fw.epdSend, 0xCF, 0x8D]));
// 480x240, LUTs from register
// await p.writeMsg(Uint8List.fromList([p.fw.epdSend, 0xEF, 0x8D]));
// await setlut(p, waveforms[0]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented out code should usually not be committed. Is there a good reason to do it here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR depends on #70 and has already been explained there.

Copy link
Copy Markdown
Contributor

@Vishveshwara Vishveshwara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me , please just remove any unacessary comments like code which was used for debugging.

@CloudyPadmal CloudyPadmal merged commit 2ddd4dc into fossasia:main Jul 3, 2025
3 checks passed
@kienvo kienvo mentioned this pull request Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move the display's initial code to the app

5 participants