Skip to content

Commit

Permalink
Adds rotation to SDL driver
Browse files Browse the repository at this point in the history
  • Loading branch information
kdschlosser committed Dec 23, 2024
1 parent 1718aa6 commit af666b6
Show file tree
Hide file tree
Showing 13 changed files with 501 additions and 450 deletions.
29 changes: 17 additions & 12 deletions api_drivers/common_api_drivers/display/sdl_display/sdl_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,10 @@ def __init__(
buffer_size = lv.color_format_get_size(color_space)
buffer_size *= display_width * display_height

self.__buf_size = buffer_size

if frame_buffer1 is None:
frame_buffer1 = data_bus.allocate_framebuffer(buffer_size, 0)

if frame_buffer2 is None:
frame_buffer2 = data_bus.allocate_framebuffer(buffer_size, 0)
else:
if buffer_size != len(frame_buffer1):
raise RuntimeError('frame buffer is not large enough')
Expand Down Expand Up @@ -159,7 +158,8 @@ def __init__(
cf,
False,
8,
8
8,
True
)

self._disp_drv.set_flush_cb(self._flush_cb)
Expand All @@ -180,6 +180,7 @@ def __init__(

self._disp_drv.add_event_cb(
self._res_chg_event_cb, lv.EVENT.RESOLUTION_CHANGED, None) # NOQA

self._disp_drv.add_event_cb(
self._release_disp_cb, lv.EVENT.DELETE, None) # NOQA

Expand All @@ -199,22 +200,26 @@ def _quit_cb(self):
self._disp_drv.delete()

def _res_chg_event_cb(self, _):
self._rotation = self._disp_drv.get_rotation()
bpp = lv.color_format_get_size(self._disp_drv.get_color_format())

hor_res = self._disp_drv.get_horizontal_resolution()
ver_res = self._disp_drv.get_vertical_resolution()

buf_size = int(hor_res * ver_res * bpp)

self._frame_buffer1 = self._data_bus.realloc_buffer(buf_size, 1) # NOQA
self._frame_buffer2 = self._data_bus.realloc_buffer(buf_size, 2) # NOQA
if self.__buf_size != buf_size:
self.__buf_size = buf_size

self._disp_drv.set_buffers(
self._frame_buffer1,
self._frame_buffer2,
len(self._frame_buffer1),
lv.DISPLAY_RENDER_MODE.DIRECT # NOQA
)
self._frame_buffer1 = self._data_bus.realloc_buffer(buf_size, 1) # NOQA
self._frame_buffer2 = self._data_bus.realloc_buffer(buf_size, 2) # NOQA

self._disp_drv.set_buffers(
self._frame_buffer1,
self._frame_buffer2,
len(self._frame_buffer1),
lv.DISPLAY_RENDER_MODE.DIRECT # NOQA
)

self._data_bus.set_window_size(
hor_res, ver_res, self._cf, self._ignore_size_chg)
Expand Down
26 changes: 5 additions & 21 deletions ext_mod/lcd_bus/esp32_include/rotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#include "rotate.h"


#ifndef __ROTATION_H__
#define __ROTATION_H__

#define ROTATION_0 (0)
#define ROTATION_90 (1)
#define ROTATION_180 (2)
#define ROTATION_270 (3)

typedef struct _rotation_task_t {
bus_lock_t lock;
bus_event_t exit;
Expand All @@ -42,27 +39,13 @@
mp_rom_error_text_t msg;
} rotation_init_err_t;


typedef struct _rotation_data_t {
int x_start;
int y_start;
int x_end;
int y_end;

uint16_t width;
uint16_t height;

uint8_t rotation: 2;
uint8_t bytes_per_pixel: 2;
uint8_t last_update: 1;

typedef struct _rotation_param_data_t {
uint8_t tx_param_count;
int param_cmd[24];
void *param[24];
size_t param_size[24];
bool param_last_cmd[24];

} rotation_data_t;
} rotation_param_data_t;


typedef int (*init_func_cb_t)(void *self_in);
Expand All @@ -73,6 +56,7 @@
rotation_buffer_t buf;
rotation_data_t data;
rotation_init_err_t init_err;
rotation_param_data_t param_data;
int lcd_cmd;

init_func_cb_t init_func;
Expand Down
14 changes: 7 additions & 7 deletions ext_mod/lcd_bus/esp32_src/i2c_bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,17 +232,17 @@ mp_lcd_err_t i2c_tx_param(mp_obj_t obj, int lcd_cmd, void *param, size_t param_s
} else {
bus_lock_acquire(&self->rotation->task.tx_param_lock, -1);

if (self->rotation->data.tx_param_count == 24) {
if (self->rotation->param_data.tx_param_count == 24) {
bus_lock_release(&self->rotation->task.tx_param_lock);
mp_raise_msg(&mp_type_MemoryError, MP_ERROR_TEXT("tx_parameter overflow."));
} else {
uint8_t tx_param_count = self->rotation->data.tx_param_count;
uint8_t tx_param_count = self->rotation->param_data.tx_param_count;

self->rotation->data.param_cmd[tx_param_count] = lcd_cmd;
self->rotation->data.param[tx_param_count] = param;
self->rotation->data.param_size[tx_param_count] = param_size;
self->rotation->data.param_last_cmd[tx_param_count] = last_flush_cmd;
self->rotation->data.tx_param_count++;
self->rotation->param_data.param_cmd[tx_param_count] = lcd_cmd;
self->rotation->param_data.param[tx_param_count] = param;
self->rotation->param_data.param_size[tx_param_count] = param_size;
self->rotation->param_data.param_last_cmd[tx_param_count] = last_flush_cmd;
self->rotation->param_data.tx_param_count++;

bus_lock_release(&self->rotation->task.tx_param_lock);
}
Expand Down
14 changes: 7 additions & 7 deletions ext_mod/lcd_bus/esp32_src/i80_bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,17 @@
} else {
bus_lock_acquire(&self->rotation->task.tx_param_lock, -1);

if (self->rotation->data.tx_param_count == 24) {
if (self->rotation->param_data.tx_param_count == 24) {
bus_lock_release(&self->rotation->task.tx_param_lock);
mp_raise_msg(&mp_type_MemoryError, MP_ERROR_TEXT("tx_parameter overflow."));
} else {
uint8_t tx_param_count = self->rotation->data.tx_param_count;
uint8_t tx_param_count = self->rotation->param_data.tx_param_count;

self->rotation->data.param_cmd[tx_param_count] = lcd_cmd;
self->rotation->data.param[tx_param_count] = param;
self->rotation->data.param_size[tx_param_count] = param_size;
self->rotation->data.param_last_cmd[tx_param_count] = last_flush_cmd;
self->rotation->data.tx_param_count++;
self->rotation->param_data.param_cmd[tx_param_count] = lcd_cmd;
self->rotation->param_data.param[tx_param_count] = param;
self->rotation->param_data.param_size[tx_param_count] = param_size;
self->rotation->param_data.param_last_cmd[tx_param_count] = last_flush_cmd;
self->rotation->param_data.tx_param_count++;

bus_lock_release(&self->rotation->task.tx_param_lock);
}
Expand Down
Loading

0 comments on commit af666b6

Please sign in to comment.