Ultimaker2Malin函数详解——lcd_lib_draw_gfx(0, 22, ultimakerTextGfx); 

3D打印技术 /[固件]
2016-12-05 10:16
Ultimaker2Marlin函数详解.jpg

位置:UltiLCD2_low_lib.c函数引用:lcd_lib_draw_gfx(0, 22, ultimakerTextGfx);
函数功能:开机显示Ultimaker logo
              显示位置是第22行第0列开始
             该函数把ultimakerTextGfx数组里面的logo数据写进lcd_buffer数组里面,然后在一直在lcd_update函数里面更新显示。
函数原型:
void lcd_lib_draw_gfx(uint8_t x, uint8_t y,const uint8_t* gfx)
{
    uint8_tw = pgm_read_byte(gfx++); //w=128
    uint8_th = (pgm_read_byte(gfx++) + 7) / 8; //h=3
    uint8_tshift = y % 8; //shift=6
    uint8_tshift2 = 8 - shift; //shift2=2
    y /= 8;//y=2
                                        //x=0


    for(;h; h--)
   {
       if (y >= LCD_GFX_HEIGHT /8) break;


       uint8_t* dst0 = lcd_buffer +x + y * LCD_GFX_WIDTH;
       uint8_t* dst1 = lcd_buffer +x + y * LCD_GFX_WIDTH + LCD_GFX_WIDTH;
       for(uint8_t _w = w; _w;_w--)
       {
          uint8_t c = pgm_read_byte(gfx++);
          *dst0++ |= c << shift;
          if (shift && y < 7)
              *dst1++ |=c >> shift2;
       }
       y++;
   }
}


测试代码:
环境:vc++6.0 EasyX 库


//ultimakerTextGfx转成lcd_buffer数据格式
#include
#include
#include
#include "common.h"

const uint8_t ultimakerTextGfx[]= {
    128, 21, //size
   0x6,0x6,0x6,0x6,0xfe,0xfe,0xfe,0xfe,0xfc,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
   0xfc,0xfe,0xfe,0xfe,0xfc,0x0,0x0,0x0,0xe,0xfe,0xfe,0xfe,0xfe,0x0,0x0,0xe0,
   0xfc,0xfe,0xfe,0xfc,0xe0,0xe0,0x0,0x0,0x0,0xce,0xce,0xce,0x0,0x0,0x0,0xc0,
   0xc0,0xc0,0xc0,0xc0,0xc0,0x80,0x0,0x0,0x0,0x0,0x0,0x0,0x80,0xc0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xf,0xf,0xf,0x0,0x0,0x6,0xf,
   0xf,0x7,0x1,0x0,0x0,0x0,0x1,0x7,0xf,0xf,0x7,0x1,0x0,0x0,0x0,0x1,
   0x7,0xf,0xf,0x6,0x0,0x0,0x3,0x7,0xf,0xf,0xe,0xe,0x6,0x7,0x3,0x7,
   0xf,0xf,0x7,0x0,0x0,0x0,0x7,0xf,0xf,0x7,0x0,0x0,0x0,0x0,0x3,0xf,
   0xf,0xf,0x6,0x0,0x0,0x0,0x3,0x7,0x7,0xf,0xe,0xe,0xe,0xe,0xe,0xe,
   0x6,0x0,0x0,0x0,0x0,0xf,0xf,0xf,0xf,0x0,0x0,0x0,0x0,0x0,0x0,0x0
};

#define LCD_GFX_WIDTH 128
#define LCD_GFX_HEIGHT 64
uint8_t lcd_buffer[LCD_GFX_WIDTH * LCD_GFX_HEIGHT / 8];

static inline uint8_t pgm_read_byte(const void* ptr)
{
    return *(constuint8_t*)ptr;
}

//lcd_lib_draw_gfx(0, 22, ultimakerTextGfx);
void lcd_lib_draw_gfx(uint8_t x, uint8_t y, const uint8_t*gfx)
{
    uint8_t w =pgm_read_byte(gfx++); // w=128 总列数 X
    uint8_t h =(pgm_read_byte(gfx++) + 7) / 8; //(21+7)/8 h=3 总行数 Y
    uint8_t shift = y % 8; //22%8shift=6   左移位数
    uint8_t shift2 = 8 - shift;//8-2   shift2=2   右移位数
    y /= 8; //22/8      y=2  显示的行位置
                                         //          x=0  显示的列位置

    for(; h; h--)//3行
    {
       if (y >= LCD_GFX_HEIGHT / 8)break;//判断行数y值是否超出屏幕的行数,y最大是8

       uint8_t* dst0 = lcd_buffer + x + y *LCD_GFX_WIDTH;//指向数组[0+2*128]的位置,第3行第一个位置(3->4->5)
       uint8_t* dst1 = lcd_buffer + x + y *LCD_GFX_WIDTH +LCD_GFX_WIDTH;//指向数组[0+2*128+128]的位置,第4行第一个位置(4->5->6)
       for(uint8_t _w = w; _w; _w--)//128列
       {
           uint8_t c= pgm_read_byte(gfx++);//把数组的值赋给变量c(一个字节)
           *dst0++ |=c << shift;//低2位
//第3行字节最低的2位变为高2位,即把整个数组网上挪了2个位
//或等于的作用是保留原来lcd_buffer数组里面的其他区域的值
                 //本来是在ultimakerTextGfx数组的低2位数据和高6位数据拆开,分别赋值到上下两个字节,
//比如第二行的高2位是ultimakerTextGfx数组的低2位数据,第三行低6位是ultimakerTextGfx数组的高6位数据
           if (shift&& y <7)//shift==0是不需要挪动,y<7作用是限定在一个字节里面,如果等于7,那么dst就指向了别的字节
              *dst1++ |= c >>shift2;//高6位,和dst0同理,分别指向一个字节的高位和低位
                  
       }
       y++;//2->3->4
    }
}

void main()
{
unsigned int i,j,k;
char c='#';
initgraph(8*128, 16*64);
lcd_lib_draw_gfx(0, 22, ultimakerTextGfx);

for(i=0;i<8;i++)//8行扫描
{
for(k=0;k<8;k++)//字节8位扫描
{
for(j=0;j<128;j++)//128列扫描
{
if( lcd_buffer[i*128+j]&(0x01<<k) )
{      
outtextxy(j*8, (i*8+k)*16, c);
}
}
}
}
getch();
closegraph();
}
声明:3D打印资源库(3dzyk)内网友所发表的所有内容及言论仅代表其本人,并不代表3D打印资源库(3dzyk)观点和立场;如对文章有异议或投诉,请联系kefu@3dzyk.cn。
Ultimaker2Malin函数详解——lcd_lib_draw_gfx(0, 22, ultimakerTextGfx); 
快速回复 返回顶部 返回列表