Draw the character of the ASCII code.

Dependents:   mbed-os_Watson-IoT_ZXing_sample mbed-os_Watson-IoT_ZXing_sample MovPlayer GR-PEACH_HVC-P2_sample_client ... more

Fork of AsciiFont by Daiki Kato

AsciiFont

This is a library to draw the ASCII font characters.

Example

#include "mbed.h"
#include "AsciiFont.h"

#define WIDTH           (12)
#define HEIGHT          (16)
#define BYTE_PER_PIXEL  (1u)
#define STRIDE          (((WIDTH * BYTE_PER_PIXEL) + 7u) & ~7u) //multiple of 8

uint8_t text_field[STRIDE * HEIGHT];

//for debug
void print_text_field() {
    int idx = 0;

    for (int i = 0; i < HEIGHT; i++) {
        for (int j = 0; j < STRIDE; j++) {
            printf("%02x", text_field[idx++]);
        }
        printf("\r\n");
    }
    printf("\r\n");
}

int main() {
    AsciiFont ascii_font(text_field, WIDTH, HEIGHT, STRIDE, BYTE_PER_PIXEL);

    ascii_font.Erase(0xcc);
    ascii_font.DrawStr("AB", 0, 0, 0x11, 1);
    ascii_font.DrawChar('C', AsciiFont::CHAR_PIX_WIDTH,
                        AsciiFont::CHAR_PIX_HEIGHT, 0x22, 1);
    print_text_field(); //debug print

    ascii_font.Erase();
    ascii_font.DrawStr("D", 0, 0, 0xef, 2);
    print_text_field(); //debug print

    ascii_font.Erase(0x11, 6, 0, 6, 8);
    print_text_field(); //debug print
}


API

Import library

Public Member Functions

AsciiFont (uint8_t *p_buf, int width, int height, int stride, int byte_per_pixel, uint32_t const colour=0)
Constructor: Initializes AsciiFont .
void Erase ()
Erase text field.
void Erase (uint32_t const colour)
Erase text field.
void Erase (uint32_t const colour, int x, int y, int width, int height)
Erase text field.
int DrawStr (char *str, int x, int y, uint32_t const colour, int font_size=1, uint16_t const max_char_num=0xffff)
Draw a string.
bool DrawChar (char c, int x, int y, uint32_t const colour, int font_size=1)
Draw a character.

Static Public Attributes

static const int CHAR_PIX_WIDTH = 6
The pixel width of a character.
static const int CHAR_PIX_HEIGHT = 8
The pixel height of a character.

Files at this revision

API Documentation at this revision

Comitter:
dkato
Date:
Mon Oct 03 02:20:49 2016 +0000
Parent:
0:99222c303e8f
Child:
2:d0bc8c2974e0
Commit message:
Update ascii.c.

Changed in this revision

AsciiFont.cpp Show annotated file Show diff for this revision Revisions of this file
ascii.c Show annotated file Show diff for this revision Revisions of this file
ascii.h Show annotated file Show diff for this revision Revisions of this file
--- a/AsciiFont.cpp	Tue Sep 27 07:03:20 2016 +0000
+++ b/AsciiFont.cpp	Mon Oct 03 02:20:49 2016 +0000
@@ -70,9 +70,9 @@
     }
 
     if ((c >= 0x20) && (c <= 0x7e)) {
-        p_pattern = (char *)&ASCII_TABLE[c - 0x20][0];
+        p_pattern = (char *)&g_ascii_table[c - 0x20][0];
     } else {
-        p_pattern = (char *)&ASCII_TABLE[10][0]; /* '*' */
+        p_pattern = (char *)&g_ascii_table[10][0]; /* '*' */
     }
     idx_base = (x * pixel_num) + (buf_stride * y);
 
--- a/ascii.c	Tue Sep 27 07:03:20 2016 +0000
+++ b/ascii.c	Mon Oct 03 02:20:49 2016 +0000
@@ -19,29 +19,33 @@
 * following link:
 * http://www.renesas.com/disclaimer
 *
+* Copyright (C) 2014 Renesas Electronics Corporation. All rights reserved.
 *******************************************************************************/
-/* Copyright (C) 2013 Renesas Electronics Corporation. All rights reserved.   */
 /*******************************************************************************
 * File Name     : ascii.c
-* Device(s)     : RZ/A1H RSK+RZA1H
+* Device(s)     : RZ/A1H (R7S721001)
+* Tool-Chain    : GNUARM-NONEv14.02-EABI
 * H/W Platform  : RSK+RZA1H CPU Board
 * Description   : Defines ascii font table
 *******************************************************************************/
 /*******************************************************************************
 * History       : DD.MM.YYYY Version Description
-*               : 18.06.2013 1.00
+*               : 21.10.2014 1.00
 *******************************************************************************/
+
 /*******************************************************************************
 * User Includes (Project Level Includes)
 *******************************************************************************/
+/* ASCII header */
 #include "ascii.h"
 
 /*******************************************************************************
 * Global Tables
 *******************************************************************************/
+/* Bytes after this pre-processor are 1-byte aligned */
 #pragma pack(1)
 
-char ASCII_TABLE[][6] =
+const char g_ascii_table[][6] =
 {
   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},      /* ' '*/
   { 0x00, 0x00, 0x79, 0x00, 0x00, 0x00},      /* ! */
@@ -140,5 +144,6 @@
   { 0x00, 0x20, 0x40, 0x20, 0x40, 0x00}       /* ~ */
   };
 
+/* Bytes after this pre-processor are 4-byte aligned */
 #pragma pack(4)
 
--- a/ascii.h	Tue Sep 27 07:03:20 2016 +0000
+++ b/ascii.h	Mon Oct 03 02:20:49 2016 +0000
@@ -19,18 +19,19 @@
 * following link:
 * http://www.renesas.com/disclaimer
 *
-* Copyright (C) 2013 Renesas Electronics Corporation. All rights reserved.
-******************************************************************************/
-/******************************************************************************
-* File Name    : ascii.h
-* Device(s)    : R7S721001
-* Tool-Chain   : GNUARM-RZv13.01-EABI
+* Copyright (C) 2014 Renesas Electronics Corporation. All rights reserved.
+*******************************************************************************/
+/*******************************************************************************
+* File Name     : ascii.h
+* Device(s)     : RZ/A1H (R7S721001)
+* Tool-Chain    : GNUARM-NONEv14.02-EABI
+* H/W Platform  : RSK+RZA1H CPU Board
 * Description  : This Header file contains the Macro Definitions & prototypes
 *                for the functions used in lcd.c
 *******************************************************************************/
 /*******************************************************************************
 * History       : DD.MM.YYYY Version Description
-*               : 18.06.2013 1.00
+*               : 21.10.2014 1.00
 *******************************************************************************/
 
 /* Multiple inclusion prevention macro */
@@ -40,8 +41,9 @@
 /******************************************************************************
 Macro Definitions
 ******************************************************************************/
-extern char ASCII_TABLE[][6];
+extern const char g_ascii_table[][6];
 
-#endif  /* ASCII_H */
+/* ASCII_H */
+#endif