Skip to content

Commit

Permalink
better, still chasing a shift
Browse files Browse the repository at this point in the history
  • Loading branch information
bwhitman committed Jan 20, 2024
1 parent 39b1911 commit 88ca1f6
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 136 deletions.
5 changes: 2 additions & 3 deletions docs/tulip_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,8 @@ tulip.frame_callback() # disables the callback
# Sets the screen brightness, from 1-9 (9 max brightness.) 5 is default.
tulip.brightness(5)

# Show a log of the GPU usage (frames per second, time spent in GPU) to the stderr log
tulip.gpu_log_start()
tulip.gpu_log_stop()
# Show the GPU usage (frames per second, time spent in GPU) at the next GPU epoch (100 frames) in stderr
tulip.gpu_log()
```

## Graphics background plane
Expand Down
25 changes: 10 additions & 15 deletions tulip/esp32s3/esp32s3_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ static bool IRAM_ATTR display_frame_done(esp_lcd_panel_handle_t panel_io, const
}


bool esp32s3_display_bounce_empty(esp_lcd_panel_handle_t panel_io, void *bounce_buf, int pos_px, int len_bytes, void *user_ctx) {
return display_bounce_empty(bounce_buf, pos_px, len_bytes, user_ctx);
}

#include "tasks.h"
void esp32s3_display_timings(uint32_t t0,uint32_t t1,uint32_t t2,uint32_t t3,uint32_t t4,uint32_t t5,uint32_t t6,uint32_t t7,uint32_t t8,uint32_t t9,uint32_t t10,uint32_t t11) {
void esp32s3_display_timings(uint32_t t0,uint32_t t1,uint32_t t2,uint32_t t3,uint32_t t4,uint32_t t5,uint32_t t6,uint32_t t7,uint32_t t8,uint32_t t9) {
fprintf(stderr, "Stopping display task\n");
display_stop();
//vTaskDelete(display_handle);
Expand All @@ -39,17 +36,15 @@ void esp32s3_display_timings(uint32_t t0,uint32_t t1,uint32_t t2,uint32_t t3,uin
V_RES = t1;
OFFSCREEN_X_PX = t2;
OFFSCREEN_Y_PX = t3;
H_RES_D = t4;
V_RES_D = t5;
HSYNC_BACK_PORCH = t6;
HSYNC_FRONT_PORCH = t7;
HSYNC_PULSE_WIDTH = t8;
VSYNC_BACK_PORCH = t9;
VSYNC_FRONT_PORCH = t10;
VSYNC_PULSE_WIDTH = t11;

TFB_ROWS = (V_RES_D/FONT_HEIGHT);
TFB_COLS = (H_RES_D/FONT_WIDTH);
HSYNC_BACK_PORCH = t4;
HSYNC_FRONT_PORCH = t5;
HSYNC_PULSE_WIDTH = t6;
VSYNC_BACK_PORCH = t7;
VSYNC_FRONT_PORCH = t8;
VSYNC_PULSE_WIDTH = t9;

TFB_ROWS = (V_RES/FONT_HEIGHT);
TFB_COLS = (H_RES/FONT_WIDTH);

// Init the BG, TFB and sprite and UI layers
//display_reset_bg();
Expand Down
2 changes: 1 addition & 1 deletion tulip/esp32s3/esp32s3_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "tasks.h"

void run_esp32s3_display();
void esp32s3_display_timings(uint32_t t0,uint32_t t1,uint32_t t2,uint32_t t3,uint32_t t4,uint32_t t5,uint32_t t6,uint32_t t7,uint32_t t8,uint32_t t9,uint32_t t10,uint32_t t11);
void esp32s3_display_timings(uint32_t t0,uint32_t t1,uint32_t t2,uint32_t t3,uint32_t t4,uint32_t t5,uint32_t t6,uint32_t t7,uint32_t t8,uint32_t t9);
void display_brightness(uint8_t amount);
void esp_display_set_clock(uint8_t mhz) ;

Expand Down
58 changes: 32 additions & 26 deletions tulip/shared/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ uint8_t *TFB;//[TFB_ROWS][TFB_COLS];
uint8_t *TFBfg;//[TFB_ROWS][TFB_COLS];
uint8_t *TFBbg;//[TFB_ROWS][TFB_COLS];
uint8_t *TFBf;//[TFB_ROWS][TFB_COLS];
uint16_t *TFB_pxlen;
int16_t *x_offsets;//[V_RES];
int16_t *y_offsets;//[V_RES];
int16_t *x_speeds;//[V_RES];
Expand All @@ -51,8 +52,6 @@ uint32_t **bg_lines;//[V_RES];
// Defaults for runtime display params
uint16_t H_RES = DEFAULT_H_RES;
uint16_t V_RES = DEFAULT_V_RES;
uint16_t H_RES_D = DEFAULT_H_RES;
uint16_t V_RES_D = DEFAULT_V_RES;
uint16_t OFFSCREEN_X_PX = DEFAULT_OFFSCREEN_X_PX;
uint16_t OFFSCREEN_Y_PX = DEFAULT_OFFSCREEN_Y_PX;
uint16_t PIXEL_CLOCK_MHZ = DEFAULT_PIXEL_CLOCK_MHZ;
Expand Down Expand Up @@ -161,8 +160,8 @@ uint16_t * line_data_ptr= NULL;
// Two buffers are filled by this function, one gets filled while the other is drawn (via GDMA to the LCD.)
// Each call fills a certain number of lines, set by BOUNCE_BUFFER_SIZE_PX in setup (it's currently 12 lines / 1 row of text)

bool display_bounce_empty(void *bounce_buf, int pos_px, int len_bytes, void *user_ctx) {
int64_t tic=get_time_us(); // start the timer
IRAM_ATTR static bool display_bounce_empty(void *bounce_buf, int pos_px, int len_bytes, void *user_ctx) {
//int64_t tic=get_time_us(); // start the timer
// Which pixel row and TFB row is this

uint16_t starting_display_row_px = pos_px / H_RES;
Expand All @@ -181,20 +180,14 @@ uint16_t * line_data_ptr= NULL;
// 416uS per call at 12 lines RGB565
for(uint8_t rows_relative_px=0;rows_relative_px<bounce_total_rows_px;rows_relative_px++) {
uint8_t * b_ptr = b+(H_RES*rows_relative_px);
/*
uint16_t y = (starting_display_row_px+rows_relative_px) % V_RES;
memcpy(
b_ptr,
bg_lines[(starting_display_row_px+rows_relative_px) % V_RES],
bg_lines[y],
H_RES
);
*/
// copy the TFB bitmap in
uint16_t y = (starting_display_row_px+rows_relative_px);
for(uint16_t x=0;x<H_RES;x++) {
b_ptr[x] = bg_lines[(y % V_RES)][x] | bg_tfb[y * H_RES + x];
}

// Copy the TFB bg ontop only as many px as it has (maybe this should be per row)
memcpy(b_ptr, bg_tfb + (y * H_RES),TFB_pxlen[y]);
}


Expand Down Expand Up @@ -305,17 +298,24 @@ uint16_t * line_data_ptr= NULL;
} // for each sprite
#endif
//} // per each row
bounce_time += (get_time_us() - tic); // stop timer
bounce_count++;
//bounce_time += (get_time_us() - tic); // stop timer
//bounce_count++;

return false;
}


void display_tfb_update() {
// set tfb_row_hint to -1 for everything
void display_tfb_update(int8_t tfb_row_hint) {
if(!tfb_active) { return; }

for(uint16_t bounce_row_px=0;bounce_row_px<V_RES;bounce_row_px++) {
uint16_t bounce_row_start = 0;
uint16_t bounce_row_end = V_RES;
if(tfb_row_hint >= 0) {
bounce_row_start = tfb_row_hint * FONT_HEIGHT;
bounce_row_end = bounce_row_start + FONT_HEIGHT;
}
for(uint16_t bounce_row_px=bounce_row_start;bounce_row_px<bounce_row_end;bounce_row_px++) {
memset(bg_tfb + (bounce_row_px*H_RES), 0, H_RES);

uint8_t tfb_row = bounce_row_px / FONT_HEIGHT;
Expand Down Expand Up @@ -385,6 +385,7 @@ void display_tfb_update() {
}
tfb_col++;
}
TFB_pxlen[bounce_row_px] = tfb_col*FONT_WIDTH;
}

}
Expand All @@ -409,22 +410,20 @@ void display_reset_bg() {
void display_reset_tfb() {
// Clear out the TFB
tfb_fg_pal_color = color_332(255,255,255);
tfb_bg_pal_color = ALPHA;
tfb_bg_pal_color = TULIP_TEAL;
for(uint i=0;i<TFB_ROWS*TFB_COLS;i++) {
TFB[i]=0;
TFBfg[i]=tfb_fg_pal_color;
TFBbg[i]=tfb_bg_pal_color;
TFBf[i]=0;
}
for(uint16_t i=0;i<V_RES;i++) TFB_pxlen[i] = 0;
tfb_y_row = 0;
tfb_x_col = 0;
ansi_active_format = -1; // no override
ansi_active_fg_color = tfb_fg_pal_color;
ansi_active_bg_color = tfb_bg_pal_color;
tfb_active = 1;
//display_tfb_update();


}

void display_reset_sprites() {
Expand Down Expand Up @@ -688,8 +687,11 @@ void display_tfb_new_row() {
TFBfg[tfb_y_row*TFB_COLS+i] = tfb_fg_pal_color;
TFBbg[tfb_y_row*TFB_COLS+i] = tfb_bg_pal_color;
}
// update the whole screen
display_tfb_update(-1);
} else {
// Still got space, just increase the row counter
display_tfb_update(tfb_y_row);
tfb_y_row++;
}
// No matter what, go back to 0 on cols
Expand Down Expand Up @@ -884,7 +886,7 @@ void display_tfb_str(char*str, uint16_t len, uint8_t format, uint8_t fg_color, u
}
// Update the cursor
display_tfb_cursor(tfb_x_col, tfb_y_row);
display_tfb_update();
display_tfb_update(tfb_y_row);
}


Expand All @@ -903,6 +905,7 @@ void display_teardown(void) {
fprintf(stderr, "freeing bg\n");
free_caps(bg); bg = NULL;
free_caps(bg_tfb); bg_tfb = NULL;
free_caps(TFB_pxlen); TFB_pxlen = NULL;
free_caps(sprite_ids);
free_caps(sprite_ram); sprite_ram = NULL;
free_caps(sprite_x_px); sprite_x_px = NULL;
Expand All @@ -925,16 +928,16 @@ void display_teardown(void) {


void display_init(void) {
TFB_ROWS = (V_RES_D/FONT_HEIGHT);
TFB_COLS = (H_RES_D/FONT_WIDTH);
TFB_ROWS = (V_RES/FONT_HEIGHT);
TFB_COLS = (H_RES/FONT_WIDTH);
// 12 divides into 600, 480, 240
BOUNCE_BUFFER_SIZE_PX = (H_RES*12) ;
// Create the background FB
bg = (uint8_t*)calloc_caps(32, 1, (H_RES+OFFSCREEN_X_PX)*(V_RES+OFFSCREEN_Y_PX)*BYTES_PER_PIXEL, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
bg_tfb = (uint8_t*)calloc_caps(32, 1, (H_RES*V_RES), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);

// And various ptrs
sprite_ids = (uint8_t*)malloc_caps(H_RES_D * sizeof(uint8_t), MALLOC_CAP_INTERNAL);
sprite_ids = (uint8_t*)malloc_caps(H_RES * sizeof(uint8_t), MALLOC_CAP_INTERNAL);
sprite_ram = (uint8_t*)malloc_caps(SPRITE_RAM_BYTES*sizeof(uint8_t), MALLOC_CAP_INTERNAL);
sprite_x_px = (uint16_t*)malloc_caps(SPRITES*sizeof(uint16_t), MALLOC_CAP_INTERNAL);
sprite_y_px = (uint16_t*)malloc_caps(SPRITES*sizeof(uint16_t), MALLOC_CAP_INTERNAL);
Expand All @@ -943,12 +946,15 @@ void display_init(void) {
sprite_vis = (uint8_t*)malloc_caps(SPRITES*sizeof(uint8_t), MALLOC_CAP_INTERNAL);
sprite_mem = (uint32_t*)malloc_caps(SPRITES*sizeof(uint32_t), MALLOC_CAP_INTERNAL);
collision_bitfield = (uint8_t*)malloc_caps(128, MALLOC_CAP_INTERNAL);
TFB_pxlen = (uint16_t*)malloc_caps(V_RES*sizeof(uint16_t), MALLOC_CAP_INTERNAL);


TFB = (uint8_t*)malloc_caps(TFB_ROWS*TFB_COLS*sizeof(uint8_t), MALLOC_CAP_INTERNAL);
TFBf = (uint8_t*)malloc_caps(TFB_ROWS*TFB_COLS*sizeof(uint8_t), MALLOC_CAP_INTERNAL);
TFBfg = (uint8_t*)malloc_caps(TFB_ROWS*TFB_COLS*sizeof(uint8_t), MALLOC_CAP_INTERNAL);
TFBbg = (uint8_t*)malloc_caps(TFB_ROWS*TFB_COLS*sizeof(uint8_t), MALLOC_CAP_INTERNAL);


x_offsets = (int16_t*)malloc_caps(V_RES*sizeof(uint16_t), MALLOC_CAP_INTERNAL);
y_offsets = (int16_t*)malloc_caps(V_RES*sizeof(uint16_t), MALLOC_CAP_INTERNAL);
x_speeds = (int16_t*)malloc_caps(V_RES*sizeof(int16_t), MALLOC_CAP_INTERNAL);
Expand Down
13 changes: 7 additions & 6 deletions tulip/shared/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extern uint8_t tfb_log;
void display_reset_sprites();
void display_reset_tfb();
void display_reset_bg();
void display_tfb_update();
void display_tfb_update(int8_t tfb_row_hint);
void display_set_clock(uint8_t mhz) ;

void display_set_bg_pixel_pal(uint16_t x, uint16_t y, uint8_t pal_idx);
Expand Down Expand Up @@ -76,7 +76,7 @@ void display_brightness(uint8_t amount);
void unpack_rgb_332(uint8_t px0, uint8_t *r, uint8_t *g, uint8_t *b);
void unpack_pal_idx(uint16_t pal_idx, uint8_t *r, uint8_t *g, uint8_t *b);
void unpack_ansi_idx(uint8_t ansi_idx, uint8_t *r, uint8_t *g, uint8_t *b);
bool display_bounce_empty(void *bounce_buf, int pos_px, int len_bytes, void *user_ctx);
//IRAM_ATTR static bool display_bounce_empty(void *bounce_buf, int pos_px, int len_bytes, void *user_ctx);
bool display_frame_done_generic();
void display_swap();

Expand All @@ -103,12 +103,12 @@ extern const unsigned char portfolio_glyph_bitmap[1792];
#define DEFAULT_V_RES 600 //600
#endif

#define DEFAULT_OFFSCREEN_X_PX 1024
#define DEFAULT_OFFSCREEN_X_PX 150
#define DEFAULT_OFFSCREEN_Y_PX 150
#define DEFAULT_PIXEL_CLOCK_MHZ 22
#define DEFAULT_PIXEL_CLOCK_MHZ 28


extern uint16_t H_RES, V_RES, H_RES_D, V_RES_D, TFB_COLS, TFB_ROWS, BOUNCE_BUFFER_SIZE_PX, OFFSCREEN_X_PX, OFFSCREEN_Y_PX, PIXEL_CLOCK_MHZ;
extern uint16_t H_RES, V_RES, TFB_COLS, TFB_ROWS, BOUNCE_BUFFER_SIZE_PX, OFFSCREEN_X_PX, OFFSCREEN_Y_PX, PIXEL_CLOCK_MHZ;
// Use this to set workable ... no, use a py func...
//#define H_RES 800//1024
//#define V_RES 480//600
Expand Down Expand Up @@ -170,6 +170,7 @@ extern uint8_t *collision_bitfield;
extern uint8_t *sprite_ids; // IRAM
extern uint8_t *sprite_ram; // in IRAM
extern uint8_t * bg; // in SPIRAM
extern uint8_t * bg_tfb; // in SPIRAM
extern uint16_t *sprite_x_px;//[SPRITES];
extern uint16_t *sprite_y_px;//[SPRITES];
extern uint16_t *sprite_w_px;//[SPRITES];
Expand All @@ -185,5 +186,5 @@ extern int16_t *y_offsets;//[V_RES];
extern int16_t *x_speeds;//[V_RES];
extern int16_t *y_speeds;//[V_RES];
extern uint32_t **bg_lines;//[V_RES];

extern uint16_t *TFB_pxlen;
#endif
8 changes: 7 additions & 1 deletion tulip/shared/editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void paint_tfb(uint16_t start_at_y) {
clear_row(y);
}
}
display_tfb_update();
display_tfb_update(-1);
}


Expand All @@ -173,6 +173,7 @@ void paint_tfb(uint16_t start_at_y) {
void move_cursor(int16_t x, int16_t y) {
// Undo old cursor
TFBf[cursor_y*TFB_COLS+cursor_x] = 0;
display_tfb_update(cursor_y);

// Move viewport up/down (TFB_ROWS-1) / 2
// Move cursor to next/prev line (which would now be in the middle of the screen)
Expand Down Expand Up @@ -206,13 +207,17 @@ void move_cursor(int16_t x, int16_t y) {

if(TFB[cursor_y*TFB_COLS+cursor_x]==0) TFB[cursor_y*TFB_COLS+cursor_x] = 32;

display_tfb_update(y);

// Update status bar
char status[TFB_COLS];
// TODO, padding better
float percent = ((float)(cursor_y+y_offset+1) / (float)lines) * 100.0;
sprintf(status, "%04d / %04d [%02.2f%%] %3d %s", cursor_y+y_offset+1, lines, percent, cursor_x, fn);
string_at_row(status, strlen(status), TFB_ROWS-1);
format_at_row(FORMAT_INVERSE, -1, TFB_ROWS-1);
display_tfb_update(TFB_ROWS-1);


}

Expand Down Expand Up @@ -282,6 +287,7 @@ void restore_tfb() {
display_set_bg_pixel_pal(x,y,bg_pal_color);
}
}
display_tfb_update(-1);
}

void editor_new_file() {
Expand Down
Loading

0 comments on commit 88ca1f6

Please sign in to comment.