diff options
| author | Miguel <m.i@gmx.at> | 2018-10-13 17:18:49 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-10-13 17:18:49 +0200 |
| commit | 5aeab1c853e487aa0042d5c32200d623efe908d3 (patch) | |
| tree | 51c810e0ce95c2b031b69999be2c0ab4244b2749 /userspace/fonts/tinyfont.c | |
| parent | 279f3336a8f6b31ca38bdd272c73aebd68fa88fe (diff) | |
fontstuff et al.
Diffstat (limited to 'userspace/fonts/tinyfont.c')
| -rw-r--r-- | userspace/fonts/tinyfont.c | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/userspace/fonts/tinyfont.c b/userspace/fonts/tinyfont.c new file mode 100644 index 0000000..f1afcdf --- /dev/null +++ b/userspace/fonts/tinyfont.c @@ -0,0 +1,160 @@ +// https://hackaday.io/project/6309-vga-graphics-over-spi-and-serial-vgatonic/log/20759-a-tiny-4x6-pixel-font-that-will-fit-on-almost-any-microcontroller-license-mit +// https://robey.lag.net/2010/01/23/tiny-monospace-font.html + +// ultrasmall 3x5 font! + + +#include <stdio.h> +#include <stdint.h> + +// Font Definition +const uint8_t font4x6 [96][2] = { + { 0x00 , 0x00 }, /*SPACE*/ + { 0x49 , 0x08 }, /*'!'*/ + { 0xb4 , 0x00 }, /*'"'*/ + { 0xbe , 0xf6 }, /*'#'*/ + { 0x7b , 0x7a }, /*'$'*/ + { 0xa5 , 0x94 }, /*'%'*/ + { 0x55 , 0xb8 }, /*'&'*/ + { 0x48 , 0x00 }, /*'''*/ + { 0x29 , 0x44 }, /*'('*/ + { 0x44 , 0x2a }, /*')'*/ + { 0x15 , 0xa0 }, /*'*'*/ + { 0x0b , 0x42 }, /*'+'*/ + { 0x00 , 0x50 }, /*','*/ + { 0x03 , 0x02 }, /*'-'*/ + { 0x00 , 0x08 }, /*'.'*/ + { 0x25 , 0x90 }, /*'/'*/ + { 0x76 , 0xba }, /*'0'*/ + { 0x59 , 0x5c }, /*'1'*/ + { 0xc5 , 0x9e }, /*'2'*/ + { 0xc5 , 0x38 }, /*'3'*/ + { 0x92 , 0xe6 }, /*'4'*/ + { 0xf3 , 0x3a }, /*'5'*/ + { 0x73 , 0xba }, /*'6'*/ + { 0xe5 , 0x90 }, /*'7'*/ + { 0x77 , 0xba }, /*'8'*/ + { 0x77 , 0x3a }, /*'9'*/ + { 0x08 , 0x40 }, /*':'*/ + { 0x08 , 0x50 }, /*';'*/ + { 0x2a , 0x44 }, /*'<'*/ + { 0x1c , 0xe0 }, /*'='*/ + { 0x88 , 0x52 }, /*'>'*/ + { 0xe5 , 0x08 }, /*'?'*/ + { 0x56 , 0x8e }, /*'@'*/ + { 0x77 , 0xb6 }, /*'A'*/ + { 0x77 , 0xb8 }, /*'B'*/ + { 0x72 , 0x8c }, /*'C'*/ + { 0xd6 , 0xba }, /*'D'*/ + { 0x73 , 0x9e }, /*'E'*/ + { 0x73 , 0x92 }, /*'F'*/ + { 0x72 , 0xae }, /*'G'*/ + { 0xb7 , 0xb6 }, /*'H'*/ + { 0xe9 , 0x5c }, /*'I'*/ + { 0x64 , 0xaa }, /*'J'*/ + { 0xb7 , 0xb4 }, /*'K'*/ + { 0x92 , 0x9c }, /*'L'*/ + { 0xbe , 0xb6 }, /*'M'*/ + { 0xd6 , 0xb6 }, /*'N'*/ + { 0x56 , 0xaa }, /*'O'*/ + { 0xd7 , 0x92 }, /*'P'*/ + { 0x76 , 0xee }, /*'Q'*/ + { 0x77 , 0xb4 }, /*'R'*/ + { 0x71 , 0x38 }, /*'S'*/ + { 0xe9 , 0x48 }, /*'T'*/ + { 0xb6 , 0xae }, /*'U'*/ + { 0xb6 , 0xaa }, /*'V'*/ + { 0xb6 , 0xf6 }, /*'W'*/ + { 0xb5 , 0xb4 }, /*'X'*/ + { 0xb5 , 0x48 }, /*'Y'*/ + { 0xe5 , 0x9c }, /*'Z'*/ + { 0x69 , 0x4c }, /*'['*/ + { 0x91 , 0x24 }, /*'\'*/ + { 0x64 , 0x2e }, /*']'*/ + { 0x54 , 0x00 }, /*'^'*/ + { 0x00 , 0x1c }, /*'_'*/ + { 0x44 , 0x00 }, /*'`'*/ + { 0x0e , 0xae }, /*'a'*/ + { 0x9a , 0xba }, /*'b'*/ + { 0x0e , 0x8c }, /*'c'*/ + { 0x2e , 0xae }, /*'d'*/ + { 0x0e , 0xce }, /*'e'*/ + { 0x56 , 0xd0 }, /*'f'*/ + { 0x55 , 0x3B }, /*'g'*/ + { 0x93 , 0xb4 }, /*'h'*/ + { 0x41 , 0x44 }, /*'i'*/ + { 0x41 , 0x51 }, /*'j'*/ + { 0x97 , 0xb4 }, /*'k'*/ + { 0x49 , 0x44 }, /*'l'*/ + { 0x17 , 0xb6 }, /*'m'*/ + { 0x1a , 0xb6 }, /*'n'*/ + { 0x0a , 0xaa }, /*'o'*/ + { 0xd6 , 0xd3 }, /*'p'*/ + { 0x76 , 0x67 }, /*'q'*/ + { 0x17 , 0x90 }, /*'r'*/ + { 0x0f , 0x38 }, /*'s'*/ + { 0x9a , 0x8c }, /*'t'*/ + { 0x16 , 0xae }, /*'u'*/ + { 0x16 , 0xba }, /*'v'*/ + { 0x16 , 0xf6 }, /*'w'*/ + { 0x15 , 0xb4 }, /*'x'*/ + { 0xb5 , 0x2b }, /*'y'*/ + { 0x1c , 0x5e }, /*'z'*/ + { 0x6b , 0x4c }, /*'{'*/ + { 0x49 , 0x48 }, /*'|'*/ + { 0xc9 , 0x5a }, /*'}'*/ + { 0x54 , 0x00 }, /*'~'*/ + { 0x56 , 0xe2 } /*''*/ +}; + +uint8_t pgm_read_byte(uint8_t *x) +{ + return *x; +} + +// Font retreival function - ugly, but needed. +unsigned char getFontLine(unsigned char data, int line_num) { + const uint8_t index = (data-32); + unsigned char pixel = 0; + if (pgm_read_byte(&font4x6[index][1]) & 1 == 1) line_num -= 1; + if (line_num == 0) { + pixel = (pgm_read_byte(&font4x6[index][0])) >> 4; + } else if (line_num == 1) { + pixel = (pgm_read_byte(&font4x6[index][0])) >> 1; + } else if (line_num == 2) { + // Split over 2 bytes + return (((pgm_read_byte(&font4x6[index][0])) & 0x03) << 2) | (((pgm_read_byte(&font4x6[index][1])) & 0x02)); + } else if (line_num == 3) { + pixel = (pgm_read_byte(&font4x6[index][1])) >> 4; + } else if (line_num == 4) { + pixel = (pgm_read_byte(&font4x6[index][1])) >> 1; + } + return pixel & 0xE; +} + +int main() +{ + printf("3\n"); + printf("5\n"); + + for(int c=0;c<95;c++) + { + printf("\n"); + char cc=c+32; + // printf("// char [%c]\n",cc); + printf("\n"); + + for(int l=0;l<5;l++) + { + uint8_t v=getFontLine(cc,l); + for(int p=0;p<3;p++) + { + if(v&(1<<(3-p)))printf("X"); + else printf("_"); + //else printf(" "); + } + printf("\n"); + } + } +} + |
