lcdfont.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "input.xbm"
  4. int main(int argc, char** argv) {
  5. FILE* f = 0;
  6. if (argc>1) f = fopen(argv[1],"w");
  7. int pitch = 192;
  8. if (f) {
  9. // expand bits to bytes
  10. unsigned char* expanded = malloc(sizeof(input_bits)*8);
  11. for (int i=0; i<sizeof(input_bits); i++) {
  12. if (i%24==0) printf("\n");
  13. for (int j=0; j<8; j++) {
  14. expanded[i*8+j] = (input_bits[i]&(1<<j)) ? 1 : 0;
  15. if (expanded[i*8+j]) {
  16. printf("#");
  17. } else {
  18. printf(".");
  19. }
  20. }
  21. }
  22. printf("\n");
  23. fprintf(f, "#include <avr/pgmspace.h>\n\n");
  24. fprintf(f, "const unsigned char font[] PROGMEM = {\n");
  25. for (int c=0; c<0x100; c++) {
  26. int y = c/32;
  27. int x = c%32;
  28. for (int j=0; j<6; j++) {
  29. unsigned char bt = 0;
  30. for (int i=0; i<8; i++) {
  31. bt |= expanded[(y*8+i)*pitch + x*6 + j]<<(i);
  32. }
  33. fprintf(f, "0x%02x, ", bt);
  34. }
  35. fprintf(f, "\n");
  36. }
  37. fprintf(f, "\n};\n");
  38. fclose(f);
  39. free(expanded);
  40. } else {
  41. printf("error: couldn't open output file.\n");
  42. return 1;
  43. }
  44. return 0;
  45. }