Skip to content

Commit

Permalink
h&v line
Browse files Browse the repository at this point in the history
  • Loading branch information
olikraus committed Jan 3, 2016
1 parent 1cffc7d commit e740446
Show file tree
Hide file tree
Showing 8 changed files with 471 additions and 38 deletions.
9 changes: 9 additions & 0 deletions csrc/u8g_dev_ssd1306_128x64.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,15 @@ uint8_t u8g_dev_sh1106_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
return 1;
case U8G_DEV_MSG_CONTRAST:
{
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x81);
u8g_WriteByte(u8g, dev, *(uint8_t *) arg);
u8g_SetChipSelect(u8g, dev, 0);
return 1;
}
}
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
}
Expand Down
2 changes: 1 addition & 1 deletion sys/arduino/GraphicsTest/GraphicsTest.pde
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
//U8GLIB_LC7981_240X128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=14 ,di=15,rw=17, reset = 16
//U8GLIB_ILI9325D_320x240 u8g(18,17,19,U8G_PIN_NONE,16 ); // 8Bit Com: D0..D7: 0,1,2,3,4,5,6,7 en=wr=18, cs=17, rs=19, rd=U8G_PIN_NONE, reset = 16
//U8GLIB_SBN1661_122X32 u8g(8,9,10,11,4,5,6,7,14,15, 17, U8G_PIN_NONE, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 cs1=14, cs2=15,di=17,rw=16,reset = 16
//U8GLIB_SSD1306_128X64 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_SSD1306_128X64 u8g(13, 11, 10, 9, 8); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_SSD1306_128X64 u8g(4, 5, 6, 7); // SW SPI Com: SCK = 4, MOSI = 5, CS = 6, A0 = 7 (new white HalTec OLED)
//U8GLIB_SSD1306_128X64 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0); // I2C / TWI
Expand Down
5 changes: 4 additions & 1 deletion u8g2/csrc/u8g2.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ extern "C" {

/*==========================================*/

typedef uint16_t u8g2_uint_t; /* for pixel position only */

typedef struct u8g2_struct u8g2_t;
typedef struct u8g2_cb_struct u8g2_cb_t;

Expand Down Expand Up @@ -264,7 +266,8 @@ void u8g2_Setup_SDL_128x64_4(u8g2_t *u8g2, const u8g2_cb_t *u8g2_cb);

/*==========================================*/
/* u8x8_d_tga.c */
void u8g2_Setup_TGA(u8g2_t *u8g2, const u8g2_cb_t *u8g2_cb);
void u8g2_Setup_TGA_DESC(u8g2_t *u8g2, const u8g2_cb_t *u8g2_cb);
void u8g2_Setup_TGA_LCD(u8g2_t *u8g2, const u8g2_cb_t *u8g2_cb);


/*==========================================*/
Expand Down
7 changes: 3 additions & 4 deletions u8g2/csrc/u8x8.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ extern "C" {
#endif

/*==========================================*/
/* U8G2 typedefs and data structures */

typedef uint16_t u8g2_uint_t; /* for pixel position only */
/* U8X8 typedefs and data structures */


typedef struct u8x8_struct u8x8_t;
Expand Down Expand Up @@ -442,7 +440,8 @@ int u8g_sdl_get_key(void);

/*==========================================*/
/* u8x8_d_tga.c */
void u8x8_Setup_TGA(u8x8_t *u8x8);
void u8x8_Setup_TGA_DESC(u8x8_t *u8x8);
void u8x8_Setup_TGA_LCD(u8x8_t *u8x8);
void tga_save(const char *name);

/*==========================================*/
Expand Down
205 changes: 174 additions & 31 deletions u8g2/sys/tga/common/u8x8_d_tga.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <string.h>

#define FACTOR 3
#define XOFFSET (FACTOR*32)
#define YOFFSET (FACTOR*32)
#define DEFAULT_WIDTH (FACTOR*128)
#define DEFAULT_HEIGHT (FACTOR*64)

Expand All @@ -16,6 +18,10 @@ uint8_t tga_r = 0;
uint8_t tga_g = 0;
uint8_t tga_b = 0;

uint8_t tga_desc_r = 0;
uint8_t tga_desc_g = 0;
uint8_t tga_desc_b = 255;

int tga_init(uint16_t w, uint16_t h)
{
tga_width = 0;
Expand All @@ -31,51 +37,70 @@ int tga_init(uint16_t w, uint16_t h)
return 1;
}

void tga_set_pixel(uint16_t x, uint16_t y)
void tga_set_pixel(uint16_t x, uint16_t y, uint16_t f)
{
uint8_t *p;
p = tga_data + (tga_height-y-1)*tga_width*3 + x*3;
*p++ = tga_b;
*p++ = tga_g;
*p++ = tga_r;
uint16_t xx,yy;
for( yy = y; yy < y+f; yy++ )
{
for( xx = x; xx < x+f; xx++ )
{
if ( yy < tga_height && xx < tga_width )
{
//printf ("(%d %d) ", xx, yy);
p = tga_data + (tga_height-yy-1)*tga_width*3 + xx*3;
*p++ = tga_b;
*p++ = tga_g;
*p++ = tga_r;
}
}
}
}

void tga_clr_pixel(uint16_t x, uint16_t y)
void tga_clr_pixel(uint16_t x, uint16_t y, uint16_t f)
{
uint8_t *p;
p = tga_data + (tga_height-y-1)*tga_width*3 + x*3;
*p++ = 255;
*p++ = 255;
*p++ = 255;
uint16_t xx,yy;
for( yy = y; yy < y+f; yy++ )
{
for( xx = x; xx < x+f; xx++ )
{

p = tga_data + (tga_height-yy-1)*tga_width*3 + xx*3;
*p++ = 255;
*p++ = 255;
*p++ = 255;
}
}
}

void tga_set_8pixel(int x, int y, uint8_t pixel)
void tga_set_8pixel(int x, int y, uint8_t pixel, uint16_t f)
{
int cnt = 8;
while( cnt > 0 )
{
if ( (pixel & 1) != 0 )
{
tga_set_pixel(x,y);
tga_set_pixel(x,y, f);
}
else
{
tga_clr_pixel(x,y);
tga_clr_pixel(x,y, f);
}
pixel >>= 1;
y++;
y+=f;
cnt--;
}
}

void tga_set_multiple_8pixel(int x, int y, int cnt, uint8_t *pixel)
void tga_set_multiple_8pixel(int x, int y, int cnt, uint8_t *pixel, uint16_t f)
{
uint8_t b;
while( cnt > 0 )
{
b = *pixel;
tga_set_8pixel(x, y, b);
x++;
tga_set_8pixel(x, y, b, f);
x+=f;
pixel++;
cnt--;
}
Expand All @@ -100,6 +125,8 @@ void tga_save(const char *name)
if ( tga_data == NULL )
return;

printf("tga_save: File %s with %dx%d pixel\n", name, tga_width, tga_height);

fp = fopen(name, "wb");
if ( fp != NULL )
{
Expand All @@ -125,8 +152,11 @@ void tga_save(const char *name)
}
}

/*==========================================*/
/* tga description procedures */


static const u8x8_display_info_t u8x8_tga_128x64_info =
static const u8x8_display_info_t u8x8_tga_desc_info =
{
/* chip_enable_level = */ 0,
/* chip_disable_level = */ 1,
Expand All @@ -141,8 +171,8 @@ static const u8x8_display_info_t u8x8_tga_128x64_info =
/* i2c_bus_clock_100kHz = */ 0,
/* data_setup_time_ns = */ 0,
/* write_pulse_width_ns = */ 0,
/* tile_width = */ 16,
/* tile_hight = */ 8,
/* tile_width = */ (2*XOFFSET+DEFAULT_WIDTH)/8,
/* tile_hight = */ (2*YOFFSET+DEFAULT_HEIGHT)/8,
#if U8X8_DEFAULT_FLIP_MODE == 0
/* default_x_offset = */ 0,
#else
Expand All @@ -151,19 +181,19 @@ static const u8x8_display_info_t u8x8_tga_128x64_info =
};


uint8_t u8x8_d_tga(u8x8_t *u8g2, uint8_t msg, uint8_t arg_int, void *arg_ptr)
uint8_t u8x8_d_tga_desc(u8x8_t *u8g2, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
uint8_t x, y, c;
u8g2_uint_t x, y, c;
uint8_t *ptr;
switch(msg)
{
case U8X8_MSG_DISPLAY_SETUP:
u8x8_d_helper_display_setup(u8g2, &u8x8_tga_128x64_info);
u8x8_d_helper_display_setup(u8g2, &u8x8_tga_desc_info);
break;
case U8X8_MSG_DISPLAY_INIT:
u8x8_d_helper_display_init(u8g2);
if ( tga_data == NULL )
tga_init(DEFAULT_WIDTH, DEFAULT_HEIGHT);
tga_init(2*XOFFSET+DEFAULT_WIDTH, 2*YOFFSET+DEFAULT_HEIGHT);
break;
case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
break;
Expand All @@ -172,18 +202,25 @@ uint8_t u8x8_d_tga(u8x8_t *u8g2, uint8_t msg, uint8_t arg_int, void *arg_ptr)
case U8X8_MSG_DISPLAY_SET_CONTRAST:
break;
case U8X8_MSG_DISPLAY_DRAW_TILE:

tga_r = tga_desc_r;
tga_g = tga_desc_g;
tga_b = tga_desc_b;

x = ((u8x8_tile_t *)arg_ptr)->x_pos;
//printf("U8X8_MSG_DISPLAY_DRAW_TILE x=%d, ", x);
x *= 8;
x += u8g2->x_offset;

y = ((u8x8_tile_t *)arg_ptr)->y_pos;
//printf("y=%d, c=%d\n", y, ((u8x8_tile_t *)arg_ptr)->cnt);
y *= 8;

do
{
c = ((u8x8_tile_t *)arg_ptr)->cnt;
ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
tga_set_multiple_8pixel(x, y, c*8, ptr);
tga_set_multiple_8pixel(x, y, c*8, ptr, 1);
arg_int--;
} while( arg_int > 0 );

Expand All @@ -195,23 +232,129 @@ uint8_t u8x8_d_tga(u8x8_t *u8g2, uint8_t msg, uint8_t arg_int, void *arg_ptr)
}


void u8x8_Setup_TGA(u8x8_t *u8x8)
void u8x8_Setup_TGA_DESC(u8x8_t *u8x8)
{
/* setup defaults */
u8x8_SetupDefaults(u8x8);

/* setup specific callbacks */
u8x8->display_cb = u8x8_d_tga;
u8x8->display_cb = u8x8_d_tga_desc;

/* setup display info */
u8x8_display_Setup(u8x8);
}

void u8g2_Setup_TGA(u8g2_t *u8g2, const u8g2_cb_t *u8g2_cb)
void u8g2_Setup_TGA_DESC(u8g2_t *u8g2, const u8g2_cb_t *u8g2_cb)
{
static uint8_t buf[(XOFFSET+DEFAULT_WIDTH)*8];

static uint8_t buf[128*8];
u8x8_Setup_TGA_DESC(u8g2_GetU8x8(u8g2));
u8g2_Setup(u8g2, buf, 1, u8g2_cb);
}

/*==========================================*/
/* tga LCD procedures */


static const u8x8_display_info_t u8x8_tga_lcd_info =
{
/* chip_enable_level = */ 0,
/* chip_disable_level = */ 1,

u8x8_Setup_TGA(u8g2_GetU8x8(u8g2));
u8g2_Setup(u8g2, buf, 8, u8g2_cb);
/* post_chip_enable_wait_ns = */ 0,
/* pre_chip_disable_wait_ns = */ 0,
/* reset_pulse_width_ms = */ 0,
/* post_reset_wait_ms = */ 0,
/* sda_setup_time_ns = */ 0,
/* sck_pulse_width_ns = */ 0,
/* sck_takeover_edge = */ 1,
/* i2c_bus_clock_100kHz = */ 0,
/* data_setup_time_ns = */ 0,
/* write_pulse_width_ns = */ 0,
/* tile_width = */ (DEFAULT_WIDTH)/FACTOR/8,
/* tile_hight = */ (DEFAULT_HEIGHT)/FACTOR/8,
#if U8X8_DEFAULT_FLIP_MODE == 0
/* default_x_offset = */ 0,
#else
/* default_x_offset = */ 0,
#endif
};


uint8_t u8x8_d_tga_lcd(u8x8_t *u8g2, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
u8g2_uint_t x, y, c;
uint8_t *ptr;
switch(msg)
{
case U8X8_MSG_DISPLAY_SETUP:
u8x8_d_helper_display_setup(u8g2, &u8x8_tga_lcd_info);
break;
case U8X8_MSG_DISPLAY_INIT:
u8x8_d_helper_display_init(u8g2);
if ( tga_data == NULL )
tga_init(2*XOFFSET+DEFAULT_WIDTH, 2*YOFFSET+DEFAULT_HEIGHT);
break;
case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
break;
case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
break;
case U8X8_MSG_DISPLAY_SET_CONTRAST:
break;
case U8X8_MSG_DISPLAY_DRAW_TILE:

tga_r = 0;
tga_g = 0;
tga_b = 0;

x = ((u8x8_tile_t *)arg_ptr)->x_pos;
//printf("U8X8_MSG_DISPLAY_DRAW_TILE x=%d, ", x);
x *= 8;
x += u8g2->x_offset;
x *= FACTOR;
x += XOFFSET;

y = ((u8x8_tile_t *)arg_ptr)->y_pos;
//printf("y=%d, c=%d\n", y, ((u8x8_tile_t *)arg_ptr)->cnt);
y *= 8;
y *= FACTOR;
y += YOFFSET;

do
{
c = ((u8x8_tile_t *)arg_ptr)->cnt;
ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
tga_set_multiple_8pixel(x, y, c*8, ptr, FACTOR);
arg_int--;
} while( arg_int > 0 );

break;
default:
return 0;
}
return 1;
}


void u8x8_Setup_TGA_LCD(u8x8_t *u8x8)
{
/* setup defaults */
u8x8_SetupDefaults(u8x8);

/* setup specific callbacks */
u8x8->display_cb = u8x8_d_tga_lcd;

/* setup display info */
u8x8_display_Setup(u8x8);
}

void u8g2_Setup_TGA_LCD(u8g2_t *u8g2, const u8g2_cb_t *u8g2_cb)
{
static uint8_t buf[(DEFAULT_WIDTH/FACTOR)*8];

u8x8_Setup_TGA_LCD(u8g2_GetU8x8(u8g2));
u8g2_Setup(u8g2, buf, 1, u8g2_cb);
}



Loading

0 comments on commit e740446

Please sign in to comment.