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.
Committer:
dkato
Date:
Tue Mar 07 05:04:28 2017 +0000
Revision:
5:1eaa4942db53
Parent:
1:fc1b3db025d6
Added range check to Erase function.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:99222c303e8f 1 /*******************************************************************************
dkato 0:99222c303e8f 2 * DISCLAIMER
dkato 0:99222c303e8f 3 * This software is supplied by Renesas Electronics Corporation and is only
dkato 0:99222c303e8f 4 * intended for use with Renesas products. No other uses are authorized. This
dkato 0:99222c303e8f 5 * software is owned by Renesas Electronics Corporation and is protected under
dkato 0:99222c303e8f 6 * all applicable laws, including copyright laws.
dkato 0:99222c303e8f 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
dkato 0:99222c303e8f 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
dkato 0:99222c303e8f 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
dkato 0:99222c303e8f 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
dkato 0:99222c303e8f 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
dkato 0:99222c303e8f 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
dkato 0:99222c303e8f 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
dkato 0:99222c303e8f 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
dkato 0:99222c303e8f 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
dkato 0:99222c303e8f 16 * Renesas reserves the right, without notice, to make changes to this software
dkato 0:99222c303e8f 17 * and to discontinue the availability of this software. By using this software,
dkato 0:99222c303e8f 18 * you agree to the additional terms and conditions found by accessing the
dkato 0:99222c303e8f 19 * following link:
dkato 0:99222c303e8f 20 * http://www.renesas.com/disclaimer
dkato 0:99222c303e8f 21 *
dkato 1:fc1b3db025d6 22 * Copyright (C) 2014 Renesas Electronics Corporation. All rights reserved.
dkato 0:99222c303e8f 23 *******************************************************************************/
dkato 0:99222c303e8f 24 /*******************************************************************************
dkato 0:99222c303e8f 25 * File Name : ascii.c
dkato 1:fc1b3db025d6 26 * Device(s) : RZ/A1H (R7S721001)
dkato 1:fc1b3db025d6 27 * Tool-Chain : GNUARM-NONEv14.02-EABI
dkato 0:99222c303e8f 28 * H/W Platform : RSK+RZA1H CPU Board
dkato 0:99222c303e8f 29 * Description : Defines ascii font table
dkato 0:99222c303e8f 30 *******************************************************************************/
dkato 0:99222c303e8f 31 /*******************************************************************************
dkato 0:99222c303e8f 32 * History : DD.MM.YYYY Version Description
dkato 1:fc1b3db025d6 33 * : 21.10.2014 1.00
dkato 0:99222c303e8f 34 *******************************************************************************/
dkato 1:fc1b3db025d6 35
dkato 0:99222c303e8f 36 /*******************************************************************************
dkato 0:99222c303e8f 37 * User Includes (Project Level Includes)
dkato 0:99222c303e8f 38 *******************************************************************************/
dkato 1:fc1b3db025d6 39 /* ASCII header */
dkato 0:99222c303e8f 40 #include "ascii.h"
dkato 0:99222c303e8f 41
dkato 0:99222c303e8f 42 /*******************************************************************************
dkato 0:99222c303e8f 43 * Global Tables
dkato 0:99222c303e8f 44 *******************************************************************************/
dkato 1:fc1b3db025d6 45 /* Bytes after this pre-processor are 1-byte aligned */
dkato 0:99222c303e8f 46 #pragma pack(1)
dkato 0:99222c303e8f 47
dkato 1:fc1b3db025d6 48 const char g_ascii_table[][6] =
dkato 0:99222c303e8f 49 {
dkato 0:99222c303e8f 50 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* ' '*/
dkato 0:99222c303e8f 51 { 0x00, 0x00, 0x79, 0x00, 0x00, 0x00}, /* ! */
dkato 0:99222c303e8f 52 { 0x00, 0x70, 0x00, 0x70, 0x00, 0x00}, /* " */
dkato 0:99222c303e8f 53 { 0x22, 0x7F, 0x22, 0x7F, 0x22, 0x00}, /* # */
dkato 0:99222c303e8f 54 { 0x12, 0x2A, 0x7F, 0x2A, 0x24, 0x00}, /* $ */
dkato 0:99222c303e8f 55 { 0x62, 0x64, 0x08, 0x13, 0x23, 0x00}, /* % */
dkato 0:99222c303e8f 56 { 0x36, 0x49, 0x55, 0x22, 0x05, 0x00}, /* & */
dkato 0:99222c303e8f 57 { 0x00, 0x00, 0x60, 0x00, 0x00, 0x00}, /* ' */
dkato 0:99222c303e8f 58 { 0x00, 0x1C, 0x22, 0x41, 0x00, 0x00}, /* ( */
dkato 0:99222c303e8f 59 { 0x00, 0x41, 0x22, 0x1C, 0x00, 0x00}, /* ) */
dkato 0:99222c303e8f 60 { 0x24, 0x18, 0x7E, 0x18, 0x24, 0x00}, /* * */
dkato 0:99222c303e8f 61 { 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00}, /* + */
dkato 0:99222c303e8f 62 { 0x00, 0x05, 0x06, 0x00, 0x00, 0x00}, /* , */
dkato 0:99222c303e8f 63 { 0x08, 0x08, 0x08, 0x08, 0x08, 0x00}, /* - */
dkato 0:99222c303e8f 64 { 0x00, 0x03, 0x03, 0x00, 0x00, 0x00}, /* . */
dkato 0:99222c303e8f 65 { 0x02, 0x04, 0x08, 0x10, 0x20, 0x00}, /* / */
dkato 0:99222c303e8f 66 { 0x3E, 0x45, 0x49, 0x51, 0x3E, 0x00}, /* 0 */
dkato 0:99222c303e8f 67 { 0x00, 0x21, 0x7F, 0x01, 0x00, 0x00}, /* 1 */
dkato 0:99222c303e8f 68 { 0x21, 0x43, 0x45, 0x49, 0x71, 0x00}, /* 2 */
dkato 0:99222c303e8f 69 { 0x42, 0x41, 0x51, 0x69, 0x46, 0x00}, /* 3 */
dkato 0:99222c303e8f 70 { 0x0C, 0x14, 0x24, 0x7F, 0x04, 0x00}, /* 4 */
dkato 0:99222c303e8f 71 { 0x72, 0x51, 0x51, 0x51, 0x4E, 0x00}, /* 5 */
dkato 0:99222c303e8f 72 { 0x1E, 0x29, 0x49, 0x49, 0x06, 0x00}, /* 6 */
dkato 0:99222c303e8f 73 { 0x40, 0x47, 0x48, 0x50, 0x60, 0x00}, /* 7 */
dkato 0:99222c303e8f 74 { 0x36, 0x49, 0x49, 0x49, 0x36, 0x00}, /* 8 */
dkato 0:99222c303e8f 75 { 0x30, 0x49, 0x49, 0x4A, 0x3C, 0x00}, /* 9 */
dkato 0:99222c303e8f 76 { 0x00, 0x66, 0x66, 0x00, 0x00, 0x00}, /* : */
dkato 0:99222c303e8f 77 { 0x00, 0x35, 0x36, 0x00, 0x00, 0x00}, /* ; */
dkato 0:99222c303e8f 78 { 0x08, 0x14, 0x22, 0x41, 0x00, 0x00}, /* < */
dkato 0:99222c303e8f 79 { 0x14, 0x14, 0x14, 0x14, 0x14, 0x00}, /* = */
dkato 0:99222c303e8f 80 { 0x00, 0x41, 0x22, 0x14, 0x08, 0x00}, /* > */
dkato 0:99222c303e8f 81 { 0x20, 0x40, 0x45, 0x48, 0x30, 0x00}, /* ? */
dkato 0:99222c303e8f 82 { 0x38, 0x45, 0x5D, 0x59, 0x3E, 0x00}, /* @ */
dkato 0:99222c303e8f 83 { 0x1F, 0x24, 0x44, 0x24, 0x1F, 0x00}, /* A */
dkato 0:99222c303e8f 84 { 0x7F, 0x49, 0x49, 0x49, 0x36, 0x00}, /* B */
dkato 0:99222c303e8f 85 { 0x3E, 0x41, 0x41, 0x41, 0x22, 0x00}, /* C */
dkato 0:99222c303e8f 86 { 0x7F, 0x41, 0x41, 0x22, 0x1C, 0x00}, /* D */
dkato 0:99222c303e8f 87 { 0x7F, 0x49, 0x49, 0x49, 0x41, 0x00}, /* E */
dkato 0:99222c303e8f 88 { 0x7F, 0x48, 0x48, 0x48, 0x40, 0x00}, /* F */
dkato 0:99222c303e8f 89 { 0x3E, 0x41, 0x49, 0x49, 0x2F, 0x00}, /* G */
dkato 0:99222c303e8f 90 { 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00}, /* H */
dkato 0:99222c303e8f 91 { 0x00, 0x41, 0x7F, 0x41, 0x00, 0x00}, /* I */
dkato 0:99222c303e8f 92 { 0x02, 0x01, 0x41, 0x7E, 0x40, 0x00}, /* J */
dkato 0:99222c303e8f 93 { 0x7F, 0x08, 0x14, 0x22, 0x41, 0x00}, /* K */
dkato 0:99222c303e8f 94 { 0x7F, 0x01, 0x01, 0x01, 0x01, 0x00}, /* L */
dkato 0:99222c303e8f 95 { 0x7F, 0x20, 0x18, 0x20, 0x7F, 0x00}, /* M */
dkato 0:99222c303e8f 96 { 0x7F, 0x10, 0x08, 0x04, 0x7F, 0x00}, /* N */
dkato 0:99222c303e8f 97 { 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00}, /* O */
dkato 0:99222c303e8f 98 { 0x7F, 0x48, 0x48, 0x48, 0x30, 0x00}, /* P */
dkato 0:99222c303e8f 99 { 0x3E, 0x41, 0x45, 0x42, 0x3D, 0x00}, /* Q */
dkato 0:99222c303e8f 100 { 0x7F, 0x48, 0x4C, 0x4A, 0x31, 0x00}, /* R */
dkato 0:99222c303e8f 101 { 0x32, 0x49, 0x49, 0x49, 0x26, 0x00}, /* S */
dkato 0:99222c303e8f 102 { 0x40, 0x40, 0x7F, 0x40, 0x40, 0x00}, /* T */
dkato 0:99222c303e8f 103 { 0x7E, 0x01, 0x01, 0x01, 0x7E, 0x00}, /* U */
dkato 0:99222c303e8f 104 { 0x7C, 0x02, 0x01, 0x02, 0x7C, 0x00}, /* V */
dkato 0:99222c303e8f 105 { 0x7E, 0x01, 0x0E, 0x01, 0x7E, 0x00}, /* W */
dkato 0:99222c303e8f 106 { 0x63, 0x14, 0x08, 0x14, 0x63, 0x00}, /* X */
dkato 0:99222c303e8f 107 { 0x70, 0x08, 0x07, 0x08, 0x70, 0x00}, /* Y */
dkato 0:99222c303e8f 108 { 0x43, 0x45, 0x49, 0x51, 0x61, 0x00}, /* Z */
dkato 0:99222c303e8f 109 { 0x00, 0x7F, 0x41, 0x00, 0x00, 0x00}, /* [ */
dkato 0:99222c303e8f 110 { 0x20, 0x10, 0x08, 0x04, 0x02, 0x00}, /* "\" */
dkato 0:99222c303e8f 111 { 0x00, 0x00, 0x41, 0x7F, 0x00, 0x00}, /* ] */
dkato 0:99222c303e8f 112 { 0x00, 0x20, 0x40, 0x20, 0x00, 0x00}, /* ^ */
dkato 0:99222c303e8f 113 { 0x01, 0x01, 0x01, 0x01, 0x01, 0x00}, /* _ */
dkato 0:99222c303e8f 114 { 0x00, 0x40, 0x20, 0x00, 0x00, 0x00}, /* ' */
dkato 0:99222c303e8f 115 { 0x02, 0x15, 0x15, 0x0F, 0x01, 0x00}, /* a */
dkato 0:99222c303e8f 116 { 0x00, 0x7F, 0x11, 0x11, 0x0E, 0x00}, /* b */
dkato 0:99222c303e8f 117 { 0x00, 0x0E, 0x11, 0x11, 0x11, 0x00}, /* c */
dkato 0:99222c303e8f 118 { 0x0E, 0x11, 0x11, 0x7F, 0x00, 0x00}, /* d */
dkato 0:99222c303e8f 119 { 0x0E, 0x15, 0x15, 0x15, 0x0C, 0x00}, /* e */
dkato 0:99222c303e8f 120 { 0x00, 0x10, 0x3F, 0x50, 0x50, 0x00}, /* f */
dkato 0:99222c303e8f 121 { 0x08, 0x15, 0x15, 0x15, 0x1E, 0x00}, /* g */
dkato 0:99222c303e8f 122 { 0x00, 0x7F, 0x10, 0x10, 0x0F, 0x00}, /* h */
dkato 0:99222c303e8f 123 { 0x00, 0x11, 0x5F, 0x01, 0x00, 0x00}, /* i */
dkato 0:99222c303e8f 124 { 0x02, 0x01, 0x01, 0x5E, 0x00, 0x00}, /* j */
dkato 0:99222c303e8f 125 { 0x00, 0x7F, 0x04, 0x0A, 0x11, 0x00}, /* k */
dkato 0:99222c303e8f 126 { 0x00, 0x41, 0x7F, 0x01, 0x00, 0x00}, /* l */
dkato 0:99222c303e8f 127 { 0x1F, 0x10, 0x0F, 0x10, 0x0F, 0x00}, /* m */
dkato 0:99222c303e8f 128 { 0x00, 0x1F, 0x10, 0x10, 0x0F, 0x00}, /* n */
dkato 0:99222c303e8f 129 { 0x0E, 0x11, 0x11, 0x11, 0x0E, 0x00}, /* 0 */
dkato 0:99222c303e8f 130 { 0x1F, 0x14, 0x14, 0x14, 0x08, 0x00}, /* p */
dkato 0:99222c303e8f 131 { 0x08, 0x14, 0x14, 0x14, 0x1F, 0x00}, /* q */
dkato 0:99222c303e8f 132 { 0x00, 0x1F, 0x08, 0x10, 0x10, 0x00}, /* r */
dkato 0:99222c303e8f 133 { 0x09, 0x15, 0x15, 0x15, 0x12, 0x00}, /* s */
dkato 0:99222c303e8f 134 { 0x00, 0x10, 0x7E, 0x11, 0x01, 0x00}, /* t */
dkato 0:99222c303e8f 135 { 0x00, 0x1E, 0x01, 0x01, 0x1F, 0x00}, /* u */
dkato 0:99222c303e8f 136 { 0x1C, 0x02, 0x01, 0x02, 0x1C, 0x00}, /* v */
dkato 0:99222c303e8f 137 { 0x1E, 0x01, 0x06, 0x01, 0x1E, 0x00}, /* w */
dkato 0:99222c303e8f 138 { 0x11, 0x0A, 0x04, 0x0A, 0x11, 0x00}, /* x */
dkato 0:99222c303e8f 139 { 0x18, 0x05, 0x05, 0x1E, 0x00, 0x00}, /* y */
dkato 0:99222c303e8f 140 { 0x11, 0x13, 0x15, 0x19, 0x11, 0x00}, /* z */
dkato 0:99222c303e8f 141 { 0x00, 0x08, 0x36, 0x41, 0x00, 0x00}, /* { */
dkato 0:99222c303e8f 142 { 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00}, /* | */
dkato 0:99222c303e8f 143 { 0x00, 0x41, 0x36, 0x08, 0x00, 0x00}, /* } */
dkato 0:99222c303e8f 144 { 0x00, 0x20, 0x40, 0x20, 0x40, 0x00} /* ~ */
dkato 0:99222c303e8f 145 };
dkato 0:99222c303e8f 146
dkato 1:fc1b3db025d6 147 /* Bytes after this pre-processor are 4-byte aligned */
dkato 0:99222c303e8f 148 #pragma pack(4)
dkato 0:99222c303e8f 149