Ejemplo n.º 1
0
/*
  Description:
    Find the starting point of the glyph data.
  Args:
    encoding: Encoding (ASCII code) of the glyph
  Return:
    Address of the glyph data or NULL, if the encoding is not avialable in the font.
*/
const uint8_t* ICACHE_FLASH_ATTR ucg_font_get_glyph_data(ucg_t *ucg, uint8_t encoding)
{
  const uint8_t *font = ucg->font;
  font += UCG_FONT_DATA_STRUCT_SIZE;
  
  if ( encoding >= 'a' )
  {
    font += ucg->font_info.start_pos_lower_a;
  }
  else if ( encoding >= 'A' )
  {
    font += ucg->font_info.start_pos_upper_A;
  }
  
  for(;;)
  {
    if ( ucg_pgm_read( ((ucg_pgm_uint8_t *)font) + 1 ) == 0 )
    {
      break;
    }
    if ( ucg_pgm_read( (ucg_pgm_uint8_t *)font ) == encoding )
    {
      return font;
    }
    font += ucg_pgm_read( ((ucg_pgm_uint8_t *)font) + 1 );
  }
  return NULL;
}
Ejemplo n.º 2
0
/* optimized */
uint8_t ICACHE_FLASH_ATTR ucg_font_decode_get_unsigned_bits(ucg_font_decode_t *f, uint8_t cnt) 
{
  uint8_t val;
  uint8_t bit_pos = f->decode_bit_pos;
  uint8_t bit_pos_plus_cnt;
  
  //val = *(f->decode_ptr);
  val = ucg_pgm_read( (ucg_pgm_uint8_t *)(f->decode_ptr) );  
  
  val >>= bit_pos;
  bit_pos_plus_cnt = bit_pos;
  bit_pos_plus_cnt += cnt;
  if ( bit_pos_plus_cnt >= 8 )
  {
    uint8_t s = 8;
    s -= bit_pos;
    f->decode_ptr++;
    //val |= *(f->decode_ptr) << (8-bit_pos);
    val |= ucg_pgm_read( (ucg_pgm_uint8_t *)(f->decode_ptr) ) << (s);
    //bit_pos -= 8;
    bit_pos_plus_cnt -= 8;
  }
  val &= (1U<<cnt)-1;
  //bit_pos += cnt;
  
  f->decode_bit_pos = bit_pos_plus_cnt;
  return val;
}
Ejemplo n.º 3
0
static ucg_int_t ucg_handle_ld50t6160_l90tc(ucg_t *ucg)
{
  if ( ucg_clip_l90tc(ucg) != 0 )
  {
    uint8_t buf[3];
    ucg_int_t dx, dy;
    ucg_int_t i;
    const uint8_t *seq;
    unsigned char pixmap;
    uint8_t bitcnt;
    ucg_com_SetCSLineStatus(ucg, 0);		/* enable chip */
    switch(ucg->arg.dir)
    {
      case 0: 
	dx = 1; dy = 0; 
	seq = ucg_ld50t6160_set_pos_dir0_seq;
	break;
      case 1: 
	dx = 0; dy = 1; 
	seq = ucg_ld50t6160_set_pos_dir1_seq;
	break;
      case 2: 
	dx = -1; dy = 0; 
	seq = ucg_ld50t6160_set_pos_dir2_seq;
	break;
      case 3: 
      default:
	dx = 0; dy = -1; 
	seq = ucg_ld50t6160_set_pos_dir3_seq;
	break;
    }
    pixmap = ucg_pgm_read(ucg->arg.bitmap);
    bitcnt = ucg->arg.pixel_skip;
    pixmap <<= bitcnt;
    buf[0] = ucg->arg.pixel.rgb.color[0]>>2;
    buf[1] = ucg->arg.pixel.rgb.color[1]>>2;
    buf[2] = ucg->arg.pixel.rgb.color[2]>>2;
    
    for( i = 0; i < ucg->arg.len; i++ )
    {
      if ( (pixmap & 128) != 0 )
      {
	ucg_com_SendCmdSeq(ucg, seq);	
	ucg_com_SendRepeat3Bytes(ucg, 1, buf);
      }
      pixmap<<=1;
      ucg->arg.pixel.pos.x+=dx;
      ucg->arg.pixel.pos.y+=dy;
      bitcnt++;
      if ( bitcnt >= 8 )
      {
	ucg->arg.bitmap++;
	pixmap = ucg_pgm_read(ucg->arg.bitmap);
	bitcnt = 0;
      }
    }
    ucg_com_SetCSLineStatus(ucg, 1);		/* disable chip */
    return 1;
  }
Ejemplo n.º 4
0
static uint16_t ucg_font_get_word(const ucg_fntpgm_uint8_t *font, uint8_t offset)
{
    uint16_t pos;
    font += offset;
    pos = ucg_pgm_read( (ucg_pgm_uint8_t *)font );
    font++;
    pos <<= 8;
    pos += ucg_pgm_read( (ucg_pgm_uint8_t *)font);
    return pos;
}
Ejemplo n.º 5
0
/*
  handle UCG_MSG_DRAW_L90FB message and make calls to "dev_cb" with UCG_MSG_DRAW_PIXEL
  return 1 if something has been drawn
*/
ucg_int_t ICACHE_FLASH_ATTR ucg_handle_l90bf(ucg_t *ucg, ucg_dev_fnptr dev_cb)
{
  if ( ucg_clip_l90tc(ucg) != 0 )
  {
    ucg_int_t dx, dy;
    ucg_int_t i, y;
    unsigned char pixmap;
    uint8_t bitcnt;
    switch(ucg->arg.dir)
    {
      case 0: dx = 1; dy = 0; break;
      case 1: dx = 0; dy = 1; break;
      case 2: dx = -1; dy = 0; break;
      case 3: dx = 0; dy = -1; break;
      default: dx = 1; dy = 0; break;	/* avoid compiler warning */
    }
    pixmap = ucg_pgm_read(ucg->arg.bitmap);
    bitcnt = ucg->arg.pixel_skip;
    pixmap <<= bitcnt;
    for( i = 0; i < ucg->arg.len; i++ )
    {
      for( y = 0; y < ucg->arg.scale; y++ )
      {
	if ( (pixmap & 128) == 0 )
	{
	  ucg->arg.pixel.rgb = ucg->arg.rgb[1];
	  dev_cb(ucg, UCG_MSG_DRAW_PIXEL, NULL);
	}
	else
	{
	  ucg->arg.pixel.rgb = ucg->arg.rgb[0];
	  dev_cb(ucg, UCG_MSG_DRAW_PIXEL, NULL);
	}
	ucg->arg.pixel.pos.x+=dx;
	ucg->arg.pixel.pos.y+=dy;
      }
      pixmap<<=1;
      bitcnt++;
      if ( bitcnt >= 8 )
      {
	ucg->arg.bitmap++;
	pixmap = ucg_pgm_read(ucg->arg.bitmap);
	bitcnt = 0;
      }
    }
    return 1;
  }
  return 0;
}
Ejemplo n.º 6
0
/* calculate the overall length of the font, only used to create the picture for the google wiki */
size_t ICACHE_FLASH_ATTR ucg_font_GetSize(const void *font_arg)
{
  const uint8_t *font = font_arg;
  font += UCG_FONT_DATA_STRUCT_SIZE;
  
  for(;;)
  {
    if ( ucg_pgm_read( ((ucg_pgm_uint8_t *)font) + 1 ) == 0 )
      break;
    font += ucg_pgm_read( ((ucg_pgm_uint8_t *)font) + 1 );
  }
  
  return (font - (const uint8_t *)font_arg) + 2;
  
}
Ejemplo n.º 7
0
uint8_t ICACHE_FLASH_ATTR ucg_font_GetFontEndEncoding(const void *font_arg)
{
  uint8_t encoding = 0;
  const uint8_t *font = font_arg;
  font += UCG_FONT_DATA_STRUCT_SIZE;
  
  for(;;)
  {
    if ( ucg_pgm_read( ((ucg_pgm_uint8_t *)font) + 1 ) == 0 )
      break;
    encoding = ucg_pgm_read( ((ucg_pgm_uint8_t *)font)  );
    font += ucg_pgm_read( ((ucg_pgm_uint8_t *)font) + 1 );
  }
  
  return encoding;  
}
Ejemplo n.º 8
0
static void ucg_CopyGlyphDataToCache(ucg_t *ucg, ucg_glyph_t g)
{
  uint8_t tmp;
  switch( ucg_font_GetFormat(ucg->font) )
  {
    case 0:
    case 2:
  /*
    format 0
    glyph information 
    offset
    0             BBX width                                       unsigned
    1             BBX height                                      unsigned
    2             data size                                          unsigned    (BBX width + 7)/8 * BBX height
    3             DWIDTH                                          signed
    4             BBX xoffset                                    signed
    5             BBX yoffset                                    signed
  byte 0 == 255 indicates empty glyph
  */
      ucg->glyph_width =  ucg_pgm_read( ((ucg_pgm_uint8_t *)g) + 0 );
      ucg->glyph_height =  ucg_pgm_read( ((ucg_pgm_uint8_t *)g) + 1 );
      ucg->glyph_dx =  ucg_pgm_read( ((ucg_pgm_uint8_t *)g) + 3 );
      ucg->glyph_x =  ucg_pgm_read( ((ucg_pgm_uint8_t *)g) + 4 );
      ucg->glyph_y =  ucg_pgm_read( ((ucg_pgm_uint8_t *)g) + 5 );
      break;
    case 1:
    default:
      /*
format 1
  0             BBX xoffset                                    signed   --> upper 4 Bit
  0             BBX yoffset                                    signed --> lower 4 Bit
  1             BBX width                                       unsigned --> upper 4 Bit
  1             BBX height                                      unsigned --> lower 4 Bit
  2             data size                                           unsigned -(BBX width + 7)/8 * BBX height  --> lower 4 Bit
  2             DWIDTH                                          signed --> upper  4 Bit
  byte 0 == 255 indicates empty glyph
      */
    
      tmp = ucg_pgm_read( ((ucg_pgm_uint8_t *)g) + 0 );
      ucg->glyph_y =  tmp & 15;
      ucg->glyph_y-=2;
      tmp >>= 4;
      ucg->glyph_x =  tmp;
    
      tmp = ucg_pgm_read( ((ucg_pgm_uint8_t *)g) + 1 );
      ucg->glyph_height =  tmp & 15;
      tmp >>= 4;
      ucg->glyph_width =  tmp;
      
      tmp = ucg_pgm_read( ((ucg_pgm_uint8_t *)g) + 2 );
      tmp >>= 4;
      ucg->glyph_dx = tmp;
    
      
      break;
  }
}
Ejemplo n.º 9
0
void ICACHE_FLASH_ATTR ucg_handle_l90rl(ucg_t *ucg, ucg_dev_fnptr dev_cb)
{
  ucg_int_t dx, dy;
  uint8_t i, cnt;
  uint8_t rl_code;
  ucg_int_t skip;
  
  switch(ucg->arg.dir)
  {
    case 0: dx = 1; dy = 0; break;
    case 1: dx = 0; dy = 1; break;
    case 2: dx = -1; dy = 0; break;
    case 3: dx = 0; dy = -1; break;
    default: dx = 1; dy = 0; break;	/* avoid compiler warning */
  }
    
  cnt = ucg_pgm_read(ucg->arg.bitmap);
  cnt &= 63;
  ucg->arg.bitmap++;
  for( i = 0; i < cnt; i++ )
  {
    rl_code = ucg_pgm_read(ucg->arg.bitmap);
    if ( rl_code == 0 )
      break;
    
    skip = (ucg_int_t)(rl_code >> 4);
    switch(ucg->arg.dir)
    {
      case 0: ucg->arg.pixel.pos.x+=skip; break;
      case 1: ucg->arg.pixel.pos.y+=skip; break;
      case 2: ucg->arg.pixel.pos.x-=skip; break;
      default:
      case 3: ucg->arg.pixel.pos.y-=skip; break;
    }

    rl_code &= 15;
    while( rl_code )
    {
      dev_cb(ucg, UCG_MSG_DRAW_PIXEL, NULL);
      ucg->arg.pixel.pos.x+=dx;
      ucg->arg.pixel.pos.y+=dy;
      rl_code--;
    }
    ucg->arg.bitmap++;
  }
}
Ejemplo n.º 10
0
/* calculate the overall length of the font, only used to create the picture for the google wiki */
size_t ucg_font_GetSize(const void *font)
{
  uint8_t *p = (uint8_t *)(font);
  uint8_t font_format = ucg_font_GetFormat(font);
  uint8_t data_structure_size = ucg_font_GetFontGlyphStructureSize(font);
  uint8_t start, end;
  uint8_t i;
  uint8_t mask = 255;
  
  start = ucg_font_GetFontStartEncoding(font);
  end = ucg_font_GetFontEndEncoding(font);

  if ( font_format == 1 )
    mask = 15;

  p += UCG_FONT_DATA_STRUCT_SIZE;       /* skip font general information */  

  i = start;  
  for(;;)
  {
    if ( ucg_pgm_read((ucg_pgm_uint8_t *)(p)) == 255 )
    {
      p += 1;
    }
    else
    {
      p += ucg_pgm_read( ((ucg_pgm_uint8_t *)(p)) + 2 ) & mask;
      p += data_structure_size;
    }
    if ( i == end )
      break;
    i++;
  }
    
  return p - (uint8_t *)font;
}
Ejemplo n.º 11
0
/* with CmdDataSequence */ 
ucg_int_t ICACHE_FLASH_ATTR ucg_handle_st7735_l90tc(ucg_t *ucg)
{
  if ( ucg_clip_l90tc(ucg) != 0 )
  {
    uint8_t buf[16];
    ucg_int_t dx, dy;
    ucg_int_t i;
    unsigned char pixmap;
    uint8_t bitcnt;
    ucg_com_SetCSLineStatus(ucg, 0);		/* enable chip */
    ucg_com_SendCmdSeq(ucg, ucg_st7735_set_pos_seq);	

    buf[0] = 0x001;	// change to 0 (cmd mode)
    buf[1] = 0x02a;	// set x
    buf[2] = 0x002;	// change to 1 (arg mode)
    buf[3] = 0x000;	// upper part x
    buf[4] = 0x000;	// no change
    buf[5] = 0x000;	// will be overwritten by x value
    buf[6] = 0x001;	// change to 0 (cmd mode)
    buf[7] = 0x02c;	// write data
    buf[8] = 0x002;	// change to 1 (data mode)
    buf[9] = 0x000;	// red value
    buf[10] = 0x000;	// no change
    buf[11] = 0x000;	// green value
    buf[12] = 0x000;	// no change
    buf[13] = 0x000;	// blue value      
    
    switch(ucg->arg.dir)
    {
      case 0: 
	dx = 1; dy = 0; 
	buf[1] = 0x02a;	// set x
	break;
      case 1: 	
	dx = 0; dy = 1; 
        buf[1] = 0x02b;	// set y
	break;
      case 2: 
	dx = -1; dy = 0; 
        buf[1] = 0x02a;	// set x
	break;
      case 3: 
      default:
	dx = 0; dy = -1; 
        buf[1] = 0x02b;	// set y
	break;
    }
    pixmap = ucg_pgm_read(ucg->arg.bitmap);
    bitcnt = ucg->arg.pixel_skip;
    pixmap <<= bitcnt;
    buf[9] = ucg->arg.pixel.rgb.color[0];
    buf[11] = ucg->arg.pixel.rgb.color[1];
    buf[13] = ucg->arg.pixel.rgb.color[2];
    //ucg_com_SetCSLineStatus(ucg, 0);		/* enable chip */
    
    for( i = 0; i < ucg->arg.len; i++ )
    {
      if ( (pixmap & 128) != 0 )
      {
	if ( (ucg->arg.dir&1) == 0 )
	{
	  buf[5] = ucg->arg.pixel.pos.x;
	}
	else
	{
	  buf[3] = ucg->arg.pixel.pos.y>>8;
	  buf[5] = ucg->arg.pixel.pos.y&255;
	}
	ucg_com_SendCmdDataSequence(ucg, 7, buf, 0);
      }
      pixmap<<=1;
      ucg->arg.pixel.pos.x+=dx;
      ucg->arg.pixel.pos.y+=dy;
      bitcnt++;
      if ( bitcnt >= 8 )
      {
	ucg->arg.bitmap++;
	pixmap = ucg_pgm_read(ucg->arg.bitmap);
	bitcnt = 0;
      }
    }
    ucg_com_SetCSLineStatus(ucg, 1);		/* disable chip */
    return 1;
  }
Ejemplo n.º 12
0
//static uint8_t ucg_font_get_byte(const ucg_fntpgm_uint8_t *font, uint8_t offset) UCG_NOINLINE;
static uint8_t ucg_font_get_byte(const ucg_fntpgm_uint8_t *font, uint8_t offset)
{
  font += offset;
  return ucg_pgm_read( (ucg_pgm_uint8_t *)font );  
}
Ejemplo n.º 13
0
/*
  Find (with some speed optimization) and return a pointer to the glyph data structure
  Also uncompress (format 1) and copy the content of the data structure to the u8g structure
*/
ucg_glyph_t ucg_GetGlyph(ucg_t *ucg, uint8_t requested_encoding)
{
  uint8_t *p = (uint8_t *)(ucg->font);
  uint8_t font_format;
  uint8_t data_structure_size;
  uint8_t start, end;
  uint16_t pos;
  uint8_t i;
  uint8_t mask = 255;
  
  if ( p == NULL )
    return NULL;
  
  font_format = ucg_font_GetFormat(ucg->font);
  data_structure_size = ucg_font_GetFontGlyphStructureSize(ucg->font);

  if ( font_format == 1 )
    mask = 15;
  
  start = ucg_font_GetFontStartEncoding(ucg->font);
  end = ucg_font_GetFontEndEncoding(ucg->font);

  pos = ucg_font_GetEncoding97Pos(ucg->font);
  if ( requested_encoding >= 97 && pos > 0 )
  {
    p+= pos;
    start = 97;
  }
  else 
  {
    pos = ucg_font_GetEncoding65Pos(ucg->font);
    if ( requested_encoding >= 65 && pos > 0 )
    {
      p+= pos;
      start = 65;
    }
    else
      p += UCG_FONT_DATA_STRUCT_SIZE;       /* skip font general information */  
  }
  
  if ( requested_encoding > end )
  {
    ucg_FillEmptyGlyphCache(ucg);
    return NULL;                      /* not found */
  }
  
  i = start;
  if ( i <= end )
  {
    for(;;)
    {
      if ( ucg_pgm_read((ucg_pgm_uint8_t *)(p)) == 255 )
      {
        p += 1;
      }
      else
      {
        if ( i == requested_encoding )
        {
          ucg_CopyGlyphDataToCache(ucg, p);
          return p;
        }
        p += ucg_pgm_read( ((ucg_pgm_uint8_t *)(p)) + 2 ) & mask;
        p += data_structure_size;
      }
      if ( i == end )
        break;
      i++;
    }
  }
  
  ucg_FillEmptyGlyphCache(ucg);
    
  return NULL;
}
Ejemplo n.º 14
0
uint8_t ICACHE_FLASH_ATTR ucg_font_GetFontStartEncoding(const void *font_arg)
{
  const uint8_t *font = font_arg;
  font += UCG_FONT_DATA_STRUCT_SIZE;
  return ucg_pgm_read( ((ucg_pgm_uint8_t *)font) );
}