Skip to content

Conversation

NickeZ
Copy link
Collaborator

@NickeZ NickeZ commented Sep 18, 2025

Create a new module called "canvas" which is responsible for double buffering. Double buffering is required to enable asynchronous transfer of the frame buffer. While the "active" frame buffer is being transferred to the oled in the background, the ui will render to a "working" frame buffer. When the rendering is complete the buffers are flipped with "canvas_commit".

I tested with both ssd1312 and sh1107 screens.

@NickeZ NickeZ requested a review from benma September 18, 2025 08:57
@NickeZ NickeZ force-pushed the maint/oled-double-buf branch 3 times, most recently from a4a1968 to 8bdd80f Compare September 18, 2025 09:27
@NickeZ NickeZ marked this pull request as ready for review September 18, 2025 09:39
Copy link
Collaborator

@benma benma left a comment

Choose a reason for hiding this comment

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

Slightly uncomfortable with the removal of the screen clearing before rendering/flushing, as it's a bit hard to reason about if the working buffer is really clean (from a previous commit) in all these cases.

src/ui/canvas.c Outdated

void canvas_commit(void)
{
_canvas_active = (_canvas_active + 1) % 2;
Copy link
Collaborator

Choose a reason for hiding this comment

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

DeepSeek


Potential Race Conditions:

  • The volatile _canvas_active switch isn't atomic. On 32-bit MCUs, this could cause torn buffer states if interrupted during update. Consider using atomic operations or disabling interrupts briefly during canvas_commit().

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

deepseek can fight gemini
Screenshot 2025-09-22 at 11 44 48

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, you are not just writing the value, you are reading it too.

/*
* Initialize canvases
*/
void canvas_init(void);
Copy link
Collaborator

Choose a reason for hiding this comment

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

DeepSeek:


Buffer Initialization:

  • canvas_init() is declared in canvas.h but not implemented.

src/ui/canvas.c Outdated
@@ -0,0 +1,47 @@
// Copyright 2025 Shift Cryptosecurity AG
Copy link
Collaborator

Choose a reason for hiding this comment

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

wrong name 🤓

src/ui/canvas.c Outdated
#include <string.h>
#include <ui/canvas.h>

// This is sometimes updated from interrupts :( to be undone eventually
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you know what "sometimes" means exactly, please specify for clarity. BIP39 unlock? More?

"to be undone" you mean the volatile qualifier right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yup, volatile can be removed when we simplify all interrupts to just set flags.

src/ui/canvas.h Outdated
@@ -0,0 +1,58 @@
// Copyright 2025 Shift Cryptosecurity AG
Copy link
Collaborator

Choose a reason for hiding this comment

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

same

@@ -0,0 +1,15 @@
// Copyright 2025 Shift Cryptosecurity AG
Copy link
Collaborator

Choose a reason for hiding this comment

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

same

@NickeZ
Copy link
Collaborator Author

NickeZ commented Sep 22, 2025

Slightly uncomfortable with the removal of the screen clearing before rendering/flushing, as it's a bit hard to reason about if the working buffer is really clean (from a previous commit) in all these cases.

I guess I could return a dirty buffer and keep all the clears instead. I have no strong opinion, just thought it would be nicer like this.

(if you didn't commit/switch the buffers the current buffer will never be drawn, so I guess it would be hard to miss?)

@NickeZ NickeZ force-pushed the maint/oled-double-buf branch 6 times, most recently from 1a6936f to edfe7fe Compare September 26, 2025 13:19
@NickeZ NickeZ requested a review from benma September 26, 2025 13:24
Create a new module called "canvas" which is responsible for double
buffering. Double buffering is required to enable asynchronous transfer
of the frame buffer. While the "active" frame buffer is being
transferred to the oled in the background, the ui will render to a
"working" frame buffer. When the rendering is complete the buffers are
flipped with "canvas_commit".
@NickeZ NickeZ force-pushed the maint/oled-double-buf branch from edfe7fe to 5f7bb4f Compare September 26, 2025 13:27
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.

2 participants