u8log, issue #560

This commit is contained in:
kraus 2018-04-22 11:15:27 +02:00
parent c72a07507a
commit cc8777898a
5 changed files with 159 additions and 1 deletions

View File

@ -204,3 +204,51 @@ void u8log_WriteChar(u8log_t *u8log, uint8_t c)
}
}
void u8log_WriteString(u8log_t *u8log, const char *s)
{
while( *s != '\0' )
{
u8log_WriteChar(u8log, *s);
s++;
}
}
static void u8log_WriteHexHalfByte(u8log_t *u8log, uint8_t b) U8X8_NOINLINE;
static void u8log_WriteHexHalfByte(u8log_t *u8log, uint8_t b)
{
b &= 0x0f;
if ( b < 10 )
u8log_WriteChar(u8log, b+'0');
else
u8log_WriteChar(u8log, b+'a'-10);
}
void u8log_WriteHex8(u8log_t *u8log, uint8_t b)
{
u8log_WriteHexHalfByte(u8log, b >> 4);
u8log_WriteHexHalfByte(u8log, b);
}
void u8log_WriteHex16(u8log_t *u8log, uint16_t v)
{
u8log_WriteHex8(u8log, v>>8);
u8log_WriteHex8(u8log, v);
}
void u8log_WriteHex32(u8log_t *u8log, uint32_t v)
{
u8log_WriteHex16(u8log, v>>16);
u8log_WriteHex16(u8log, v);
}
/* v = value, d = number of digits (1..3) */
void u8log_WriteDec8(u8log_t *u8log, uint8_t v, uint8_t d)
{
u8log_WriteString(u8log, u8x8_u8toa(v, d));
}
/* v = value, d = number of digits (1..5) */
void u8log_WriteDec16(u8log_t *u8log, uint8_t v, uint8_t d)
{
u8log_WriteString(u8log, u8x8_u16toa(v, d));
}

View File

@ -35,3 +35,41 @@
*/
#include "u8x8.h"
static void u8x8_DrawLogLine(u8x8_t *u8x8, uint8_t disp_x, uint8_t disp_y, uint8_t buf_y, u8log_t *u8log) U8X8_NOINLINE;
static void u8x8_DrawLogLine(u8x8_t *u8x8, uint8_t disp_x, uint8_t disp_y, uint8_t buf_y, u8log_t *u8log)
{
uint8_t buf_x;
uint8_t c;
for( buf_x = 0; buf_x < u8log->width; buf_x++ )
{
c = u8log->screen_buffer[buf_y * u8log->width + buf_x];
u8x8_DrawGlyph(u8x8, disp_x, disp_y, c);
disp_x++;
}
}
void u8x8_DrawLog(u8x8_t *u8x8, uint8_t x, uint8_t y, u8log_t *u8log)
{
uint8_t buf_y;
for( buf_y = 0; buf_y < u8log->height; buf_y++ )
{
u8x8_DrawLogLine(u8x8, x, y, buf_y, u8log);
y++;
}
}
void u8log_u8x8_cb(u8log_t * u8log)
{
u8x8_t *u8x8 = (u8x8_t *)(u8log->aux_data);
if ( u8log->is_redraw_all )
{
u8x8_DrawLog(u8x8, 0, 0, u8log);
}
else if ( u8log->is_redraw_line )
{
u8x8_DrawLogLine(u8x8, 0, u8log->redraw_line, u8log->redraw_line, u8log);
}
}

View File

@ -959,8 +959,18 @@ void u8log_Init(u8log_t *u8log, uint8_t width, uint8_t height, uint8_t *buf);
void u8log_SetCallback(u8log_t *u8log, u8log_cb cb, void *aux_data);
void u8log_SetRedrawMode(u8log_t *u8log, uint8_t is_redraw_line_for_each_char);
void u8log_SetLineHeightOffset(u8log_t *u8log, int8_t line_height_offset);
void u8log_WriteChar(u8log_t *u8log, uint8_t c);
void u8log_WriteString(u8log_t *u8log, const char *s) U8X8_NOINLINE;
void u8log_WriteChar(u8log_t *u8log, uint8_t c) U8X8_NOINLINE;
void u8log_WriteHex8(u8log_t *u8log, uint8_t b) U8X8_NOINLINE;
void u8log_WriteHex16(u8log_t *u8log, uint16_t v);
void u8log_WriteHex32(u8log_t *u8log, uint32_t v);
void u8log_WriteDec8(u8log_t *u8log, uint8_t v, uint8_t d);
void u8log_WriteDec16(u8log_t *u8log, uint8_t v, uint8_t d);
/*==========================================*/
/* u8log_u8x8.c */
void u8x8_DrawLog(u8x8_t *u8x8, uint8_t x, uint8_t y, u8log_t *u8log);
void u8log_u8x8_cb(u8log_t * u8log);
/*==========================================*/

View File

@ -0,0 +1,12 @@
CFLAGS = -g -Wall -I../../../csrc/. `sdl2-config --cflags`
SRC = $(shell ls ../../../csrc/*.c) $(shell ls ../common/*.c ) main.c
OBJ = $(SRC:.c=.o)
helloworld: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) `sdl2-config --libs` -o u8g2_sdl
clean:
-rm $(OBJ) u8g2_sdl

50
sys/sdl/u8log_u8x8/main.c Normal file
View File

@ -0,0 +1,50 @@
#include "u8x8.h"
#include <stdio.h>
#include <time.h>
u8x8_t u8x8;
u8log_t u8log;
#define U8LOG_WIDTH 16
#define U8LOG_HEIGHT 8
uint8_t u8log_buf[U8LOG_WIDTH*U8LOG_HEIGHT];
int main(void)
{
int k;
clock_t t;
uint8_t c;
u8x8_Setup_SDL_128x64(&u8x8);
u8x8_InitDisplay(&u8x8);
u8x8_SetFont(&u8x8, u8x8_font_amstrad_cpc_extended_f);
u8log_Init(&u8log, U8LOG_WIDTH, U8LOG_HEIGHT, u8log_buf);
u8log_SetCallback(&u8log, u8log_u8x8_cb, &u8x8);
u8log_SetRedrawMode(&u8log, /* is_redraw_line_for_each_char = */ 1);
//u8log_SetRedrawMode(&u8log, /* is_redraw_line_for_each_char = */ 0);
t = clock()+CLOCKS_PER_SEC/10;
for(;;)
{
if ( t < clock() )
{
c = (t % 10) + '0';
if ( c == '0' )
c = '\n';
u8log_WriteChar(&u8log, c);
t = clock()+CLOCKS_PER_SEC/10;
}
k = u8g_sdl_get_key();
if ( k == 'q' ) break;
}
return 0;
}