Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

display driver for T3W1 #4415

Merged
merged 4 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions core/embed/io/display/fb_queue/fb_queue.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#ifdef KERNEL_MODE

#include <trezor_rtl.h>

#include <sys/irq.h>

#include "fb_queue.h"

// Initializes the queue and make it empty
// Clear peeked flag
void fb_queue_reset(fb_queue_t* queue) {
memset(queue, 0, sizeof(fb_queue_t));
for (int i = 0; i < FRAME_BUFFER_COUNT; i++) {
queue->entries[i].index = -1;
}
}

// Inserts a new element to the tail of the queue
bool fb_queue_put(fb_queue_t* queue, int16_t index) {
irq_key_t irq_key = irq_lock();

// check if the queue is full
if (queue->entries[queue->wix].index != -1) {
irq_unlock(irq_key);
return false;
}

queue->entries[queue->wix].index = index;
queue->wix = (queue->wix + 1) % FRAME_BUFFER_COUNT;

irq_unlock(irq_key);

return true;
}

// Removes an element from the queue head, returns -1 if the queue is empty
// Clear peeked flag
int16_t fb_queue_take(fb_queue_t* queue) {
irq_key_t irq_key = irq_lock();

if (queue->entries[queue->rix].index == -1) {
irq_unlock(irq_key);
return -1;
}

queue->peaked = false;
int16_t index = queue->entries[queue->rix].index;
queue->entries[queue->rix].index = -1;
queue->rix = (queue->rix + 1) % FRAME_BUFFER_COUNT;

irq_unlock(irq_key);
return index;
}
// Returns true if the queue is empty
bool fb_queue_empty(fb_queue_t* queue) {
irq_key_t irq_key = irq_lock();

if (queue->entries[queue->rix].index == -1) {
irq_unlock(irq_key);
return true;
}

irq_unlock(irq_key);
return false;
}

// Waits until the queue is not empty
void fb_queue_wait(fb_queue_t* queue) {
while (fb_queue_empty(queue))
;
}

// Returns the head of the queue (or -1 if the queue is empty)
// Set peeked flag if the queue is not empty
int16_t fb_queue_peek(fb_queue_t* queue) {
irq_key_t irq_key = irq_lock();

if (queue->entries[queue->rix].index == -1) {
irq_unlock(irq_key);
return -1;
}

int16_t index = queue->entries[queue->rix].index;
queue->peaked = true;

irq_unlock(irq_key);

return index;
}

// Return if the head was already peeked
bool fb_queue_peeked(fb_queue_t* queue) {
irq_key_t key = irq_lock();
bool peeked = queue->peaked;
irq_unlock(key);
return peeked;
}

#endif
71 changes: 71 additions & 0 deletions core/embed/io/display/fb_queue/fb_queue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* This file is part of the Trezor project, https://trezor.io/
*
* Copyright (c) SatoshiLabs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <trezor_types.h>

// Number of frame buffers used (1 or 2)
// If 1 buffer is selected, some animations may not
// be so smooth but the memory usage is lower.
#define FRAME_BUFFER_COUNT 2

// Each frame buffer can be in one of the following states:
typedef struct {
int16_t index;
} fb_queue_entry;

typedef struct {
// Queue entries
fb_queue_entry entries[FRAME_BUFFER_COUNT];

// Read index
// (accessed & updated in the context of the interrupt handlers
uint8_t rix;
// Write index
// (accessed & updated in context of the main thread)
uint8_t wix;

// Flag indicating that the head of the queue has been peaked
bool peaked;

} fb_queue_t;

// Initializes the queue and make it empty
// Clear peeked flag
void fb_queue_reset(fb_queue_t* queue);

// Inserts a new element to the tail of the queue
bool fb_queue_put(fb_queue_t* queue, int16_t index);

// Removes an element from the queue head, returns -1 if the queue is empty
// Clear peeked flag
int16_t fb_queue_take(fb_queue_t* queue);
// Returns true if the queue is empty
bool fb_queue_empty(fb_queue_t* queue);

// Waits until the queue is not empty
void fb_queue_wait(fb_queue_t* queue);

// Returns the head of the queue (or -1 if the queue is empty)
// Set peeked flag if the queue is not empty
int16_t fb_queue_peek(fb_queue_t* queue);

// Return if the head was already peeked
bool fb_queue_peeked(fb_queue_t* queue);
Loading
Loading