【RTT大赛作品连载】AB32VG1开发板之OLED屏

描述

       AB32VG1开发板外设资源丰富,此次来分享一下AB32VG1开发板驱动OLED屏的具体步骤。板上预留了IIC接口,可通过杜邦线连接IIC接口的OLED模块,连接好OLED模块后进行软件上的设置。

OLED

   打开“RT Thread setting”点击添加按钮,搜索框输入“SSD1306”

OLED

    组件成功添加,,如下图所示:

OLED

       点击右键,选择详细配置,软件包选项卡配置如下:

OLED

    硬件选项使能IIC接口

OLED

     然后保存所勾选的配置,这样成功得将SSD1306模块所封装的库函数添加进工程中,所在目录“RT-ThreadStudio\workspace\open_OLED\packages\ssd1306-latest”

OLED

       加载完成后,可以查看驱动SSD1306的源代码

#include 
#include 
#include 

#include 
#include 
#include "ssd1306.h"
#include "ssd1306_tests.h"

void ssd1306_TestBorder()
{
    ssd1306_Fill(Black);

    uint32_t start = rt_tick_get();
    uint32_t end = start;
    uint8_t x = 0;
    uint8_t y = 0;
    do {
        ssd1306_DrawPixel(x, y, Black);

        if((y == 0) && (x < 127))
            x++;
        else if((x == 127) && (y < 63))
            y++;
        else if((y == 63) && (x > 0)) 
            x--;
        else
            y--;

        ssd1306_DrawPixel(x, y, White);
        ssd1306_UpdateScreen();
    
        rt_thread_mdelay(5);
        end = rt_tick_get();
    } while((end - start) < 8000);
   
    rt_thread_mdelay(1000);
}

void ssd1306_TestFonts()
{
    ssd1306_Fill(Black);
    ssd1306_SetCursor(2, 0);
    ssd1306_WriteString("Font 16x26", Font_16x26, White);
    ssd1306_SetCursor(2, 26);
    ssd1306_WriteString("Font 11x18", Font_11x18, White);
    ssd1306_SetCursor(2, 26+18);
    ssd1306_WriteString("Font 7x10", Font_7x10, White);
    ssd1306_SetCursor(2, 26+18+10);
    ssd1306_WriteString("Font 6x8", Font_6x8, White);
    ssd1306_UpdateScreen();
}

void ssd1306_TestFPS()
{
    ssd1306_Fill(White);
   
    uint32_t start = rt_tick_get();
    uint32_t end = start;
    int fps = 0;
    char message[] = "ABCDEFGHIJK";
   
    ssd1306_SetCursor(2,0);
    ssd1306_WriteString("Testing...", Font_11x18, Black);
   
    do {
        ssd1306_SetCursor(2, 18);
        ssd1306_WriteString(message, Font_11x18, Black);
        ssd1306_UpdateScreen();
       
        char ch = message[0];
        memmove(message, message+1, sizeof(message)-2);
        message[sizeof(message)-2] = ch;

        fps++;
        end = rt_tick_get();
    } while((end - start) < 5000);
   
    rt_thread_mdelay(1000);

    char buff[64];
    fps = (float)fps / ((end - start) / 1000.0);
    snprintf(buff, sizeof(buff), "~%d FPS", fps);
   
    ssd1306_Fill(White);
    ssd1306_SetCursor(2, 18);
    ssd1306_WriteString(buff, Font_11x18, Black);
    ssd1306_UpdateScreen();
}

void ssd1306_TestLine()
{
    ssd1306_Line(1,1,SSD1306_WIDTH - 1,SSD1306_HEIGHT - 1,White);
    ssd1306_Line(SSD1306_WIDTH - 1,1,1,SSD1306_HEIGHT - 1,White);
    ssd1306_UpdateScreen();
    return;
}

void ssd1306_TestRectangle()
{
    uint32_t delta;

    for(delta = 0; delta < 5; delta ++) 
    {
        ssd1306_DrawRectangle(1 + (5*delta),1 + (5*delta) ,SSD1306_WIDTH-1 - (5*delta),SSD1306_HEIGHT-1 - (5*delta),White);
    }
    ssd1306_UpdateScreen();
    return;
}

void ssd1306_TestCircle()
{
    uint32_t delta;

    for(delta = 0; delta < 5; delta ++) 
    {
        ssd1306_DrawCircle(20* delta+30, 30, 10, White);
    }
    ssd1306_UpdateScreen();
    return;
}

void ssd1306_TestArc()
{
    ssd1306_DrawArc(30, 30, 30, 20, 270, White);
    ssd1306_UpdateScreen();
    return;
}

void ssd1306_TestPolyline()
{
    SSD1306_VERTEX loc_vertex[] =
    {
        {35,40},
        {40,20},
        {45,28},
        {50,10},
        {45,16},
        {50,10},
        {53,16}
    };

    ssd1306_Polyline(loc_vertex,sizeof(loc_vertex)/sizeof(loc_vertex[0]),White);
    ssd1306_UpdateScreen();
    return;
}

void ssd1306_TestAll()
{
    ssd1306_Init();

    ssd1306_TestFPS();
    rt_thread_mdelay(1000);

    ssd1306_TestBorder();

    ssd1306_TestFonts();
    rt_thread_mdelay(1000);

    ssd1306_Fill(Black);
    ssd1306_TestRectangle();
    ssd1306_TestLine();
    rt_thread_mdelay(1000);

    ssd1306_Fill(Black);
    ssd1306_TestPolyline();
    rt_thread_mdelay(1000);

    ssd1306_Fill(Black);
    ssd1306_TestArc();
    rt_thread_mdelay(1000);

    ssd1306_Fill(Black);
    ssd1306_TestCircle();
    rt_thread_mdelay(1000);
}

#ifdef FINSH_USING_MSH
MSH_CMD_EXPORT(ssd1306_TestAll, test ssd1306 oled driver);
#endif

       编译完成后,使用“Downloader.exe”下载器按照如下图所示的步骤,将生成的.dcf文件下载进开发板中

OLED

     终端中输入“ssd1306_TestAll”,即可启动检测OLED模块的线程,检测的效果如下:

OLED

     此次体验了RT- Thread Studio的强大便捷之处,支持的软件包组件更方便了IDE的外设驱动,的确不错。

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分