Skip to content

Commit

Permalink
U8x8 version complete
Browse files Browse the repository at this point in the history
  • Loading branch information
45gfg9 committed Mar 6, 2024
1 parent 67af865 commit ba83b56
Show file tree
Hide file tree
Showing 7 changed files with 334 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "u8g2"]
path = u8g2
url = https://github.com/olikraus/u8g2.git
1 change: 1 addition & 0 deletions lib/u8g2
1 change: 1 addition & 0 deletions lib/u8g2_avr
15 changes: 11 additions & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env]
[env:prod]
platform = atmelavr
board = ATmega88P
board_build.f_cpu = 8000000L

[env:prod]
board = ATmega48
upload_protocol = usbasp
build_flags =
-DAVR_USE_HW_SPI
-DMOSI_DDR=DDRB
-DMOSI_BIT=3
-DMISO_DDR=DDRB
-DMISO_BIT=4
-DSCK_DDR=DDRB
-DSCK_BIT=5
155 changes: 155 additions & 0 deletions src/font.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
#include <u8x8.h>
/*
Fontname: -misc-spleen-medium-r-normal--32-320-72-72-C-160-ISO10646-1
Copyright: Copyright (c) 2018-2023, Frederic Cambus
Glyphs: 73/925
BBX Build Mode: 3
*/
const uint8_t rab_font[4676] U8X8_FONT_SECTION("rab_font") =
"\60x\2\4\0\0\0\200\300\300\300\300\300\300\300\300\200\0\0\0\0\0\377\377\1\0\0\200\300\340p\71"
"\377\377\0\0\0\0\377\377\234\16\7\3\1\0\0\200\377\377\0\0\0\0\0\1\3\3\3\3\3\3\3\3"
"\1\0\0\0\0\0\0\0\0\200\300\300\300\0\0\0\0\0\0\0\0\0\0\6\3\1\0\377\377\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\377\377\0\0\0\0\0\0\0\0\0\0\3\3\3\3\3\3\3\3\3"
"\3\0\0\0\0\0\0\200\300\300\300\300\300\300\300\300\200\0\0\0\0\0\3\3\1\0\0\0\0\200\300a"
"\77\37\0\0\0\0\300\340\60\30\14\6\3\1\0\0\300\300\0\0\0\0\3\3\3\3\3\3\3\3\3\3"
"\3\3\0\0\0\0\0\200\300\300\300\300\300\300\300\300\200\0\0\0\0\0\3\3\1\300\300\300\300\300\300\341"
"\77\37\0\0\0\0\300\300\200\0\0\0\0\0\0\201\377\376\0\0\0\0\0\1\3\3\3\3\3\3\3\3"
"\1\0\0\0\0\0\300\300\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\0\0\0\0\0\374\374"
"\0\0\0\0\0\0\17\17\14\14\14\14\14\14\377\377\14\14\0\0\0\0\0\0\0\0\0\0\0\0\3\3"
"\0\0\0\0\0\0\300\300\300\300\300\300\300\300\300\300\300\300\0\0\0\0\377\377\300\300\300\300\300\300\300\300"
"\203\3\0\0\0\0\300\300\200\0\0\0\0\0\0\201\377\377\0\0\0\0\0\1\3\3\3\3\3\3\3\3"
"\1\0\0\0\0\0\0\200\300\300\300\300\300\300\300\300\200\0\0\0\0\0\377\377\301\300\300\300\300\300\300\301"
"\203\3\0\0\0\0\377\377\200\0\0\0\0\0\0\201\377\377\0\0\0\0\0\1\3\3\3\3\3\3\3\3"
"\1\0\0\0\0\0\300\300\300\300\300\300\300\300\300\300\300\300\0\0\0\0\3\3\0\0\0\0\0\200\300`"
"\77\37\0\0\0\0\0\0\0\0\374\376\3\1\0\0\0\0\0\0\0\0\0\0\0\0\3\3\0\0\0\0"
"\0\0\0\0\0\0\0\200\300\300\300\300\300\300\300\300\200\0\0\0\0\0\37\77\341\300\300\300\300\300\300\341"
"\77\37\0\0\0\0\376\377\201\0\0\0\0\0\0\201\377\376\0\0\0\0\0\1\3\3\3\3\3\3\3\3"
"\1\0\0\0\0\0\0\200\300\300\300\300\300\300\300\300\200\0\0\0\0\0\377\377\201\0\0\0\0\0\0\1"
"\377\377\0\0\0\0\300\301\203\3\3\3\3\3\3\203\377\377\0\0\0\0\0\1\3\3\3\3\3\3\3\3"
"\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\340\340\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\200\200\0\0\0\0\0\0\0\0\0\0\0\0\0\0\3\3\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\340\340\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\300\300\0\0\0\0\0\0\0\0\0\0\0\0\14\16\7\3\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\200\300\300@\0\0\0\0\200\300\340p\70\34\16\7\3\1"
"\0\0\0\0\0\0\1\3\7\16\34\70p\340\300\200\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\3"
"\3\2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\60\60\60\60\60\60\60\60\60\60"
"\60\60\0\0\0\0\14\14\14\14\14\14\14\14\14\14\14\14\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0@\300\300\200\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\3\7\16\34\70p\340"
"\300\200\0\0\0\0\0\0\200\300\340p\70\34\16\7\3\1\0\0\0\0\2\3\3\1\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\200\300\300\300\300\300\300\300\300\200\0\0\0\0\0\3\3\1\0\0\0\200\300`\61"
"\37\17\0\0\0\0\0\0\0\0\0\216\217\1\0\0\0\0\0\0\0\0\0\0\0\0\0\3\3\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\376\7\3\3\343\343\343\3\7"
"\376\374\0\0\0\0\377\377\200\0\0\37\37\37\30\30\37\37\0\0\0\0\0\1\3\3\3\3\3\3\3\3"
"\3\0\0\0\0\0\0\200\300\300\300\300\300\300\300\300\200\0\0\0\0\0\377\377\201\200\200\200\200\200\200\201"
"\377\377\0\0\0\0\377\377\1\1\1\1\1\1\1\1\377\377\0\0\0\0\3\3\0\0\0\0\0\0\0\0"
"\3\3\0\0\0\0\300\300\300\300\300\300\300\300\300\300\200\0\0\0\0\0\377\377\300\300\300\300\300\300\300\341"
"\77\37\0\0\0\0\377\377\0\0\0\0\0\0\0\201\377\376\0\0\0\0\3\3\3\3\3\3\3\3\3\3"
"\1\0\0\0\0\0\0\200\300\300\300\300\300\300\300\300\300\300\0\0\0\0\377\377\1\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\377\377\200\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\3\3\3\3\3\3\3\3"
"\3\3\0\0\0\0\300\300\300\300\300\300\300\300\300\300\200\0\0\0\0\0\377\377\0\0\0\0\0\0\0\1"
"\377\377\0\0\0\0\377\377\0\0\0\0\0\0\0\200\377\377\0\0\0\0\3\3\3\3\3\3\3\3\3\3"
"\1\0\0\0\0\0\0\200\300\300\300\300\300\300\300\300\300\300\0\0\0\0\377\377\201\200\200\200\200\200\200\0"
"\0\0\0\0\0\0\377\377\201\1\1\1\1\1\1\0\0\0\0\0\0\0\0\1\3\3\3\3\3\3\3\3"
"\3\3\0\0\0\0\0\200\300\300\300\300\300\300\300\300\300\300\0\0\0\0\377\377\201\200\200\200\200\200\200\0"
"\0\0\0\0\0\0\377\377\1\1\1\1\1\1\1\0\0\0\0\0\0\0\3\3\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\200\300\300\300\300\300\300\300\300\300\300\0\0\0\0\377\377\1\0\0\0\200\200\200\200"
"\200\200\0\0\0\0\377\377\200\0\0\0\1\1\1\1\377\377\0\0\0\0\0\1\3\3\3\3\3\3\3\3"
"\3\3\0\0\0\0\300\300\0\0\0\0\0\0\0\0\300\300\0\0\0\0\377\377\200\200\200\200\200\200\200\200"
"\377\377\0\0\0\0\377\377\1\1\1\1\1\1\1\1\377\377\0\0\0\0\3\3\0\0\0\0\0\0\0\0"
"\3\3\0\0\0\0\0\300\300\300\300\300\300\300\300\300\300\0\0\0\0\0\0\0\0\0\0\377\377\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\377\377\0\0\0\0\0\0\0\0\0\0\3\3\3\3\3\3\3\3\3"
"\3\0\0\0\0\0\0\300\300\300\300\300\300\300\300\300\300\0\0\0\0\0\0\0\0\0\0\377\377\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\200\377\377\0\0\0\0\0\0\0\0\3\3\3\3\3\3\1\0\0\0\0"
"\0\0\0\0\0\0\300\300\0\0\0\0\0\0\0\0\300\300\0\0\0\0\377\377\200\200\200\200\200\300`\60"
"\37\17\0\0\0\0\377\377\1\1\1\1\1\3\6\14\370\360\0\0\0\0\3\3\0\0\0\0\0\0\0\0"
"\3\3\0\0\0\0\300\300\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\377\377\200\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\3\3\3\3\3\3\3\3"
"\3\3\0\0\0\0\300\300\200\0\0\0\0\0\0\200\300\300\0\0\0\0\377\377\3\7\16\34\34\16\7\3"
"\377\377\0\0\0\0\377\377\0\0\0\0\0\0\0\0\377\377\0\0\0\0\3\3\0\0\0\0\0\0\0\0"
"\3\3\0\0\0\0\300\300\0\0\0\0\0\0\0\0\300\300\0\0\0\0\377\377\17<\360\300\0\0\0\0"
"\377\377\0\0\0\0\377\377\0\0\0\3\17<\360\300\377\377\0\0\0\0\3\3\0\0\0\0\0\0\0\3"
"\3\3\0\0\0\0\0\200\300\300\300\300\300\300\300\300\200\0\0\0\0\0\377\377\1\0\0\0\0\0\0\1"
"\377\377\0\0\0\0\377\377\200\0\0\0\0\0\0\200\377\377\0\0\0\0\0\1\3\3\3\3\3\3\3\3"
"\1\0\0\0\0\0\300\300\300\300\300\300\300\300\300\300\200\0\0\0\0\0\377\377\200\200\200\200\200\200\200\301"
"\377\177\0\0\0\0\377\377\1\1\1\1\1\1\1\1\0\0\0\0\0\0\3\3\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\200\300\300\300\300\300\300\300\300\200\0\0\0\0\0\377\377\1\0\0\0\0\0\0\1"
"\377\377\0\0\0\0\377\377\200\0\0\60\360\300\0\200\377\377\0\0\0\0\0\1\3\3\3\3\3\3\17\77"
"\61\0\0\0\0\0\300\300\300\300\300\300\300\300\300\300\200\0\0\0\0\0\377\377\200\200\200\200\200\200\200\301"
"\177\77\0\0\0\0\377\377\1\1\1\1\1\1\1\3\376\374\0\0\0\0\3\3\0\0\0\0\0\0\0\0"
"\3\3\0\0\0\0\0\200\300\300\300\300\300\300\300\300\300\300\0\0\0\0\177\377\301\200\200\200\200\200\200\200"
"\0\0\0\0\0\0\0\0\1\1\1\1\1\1\1\203\377\376\0\0\0\0\3\3\3\3\3\3\3\3\3\3"
"\1\0\0\0\0\300\300\300\300\300\300\300\300\300\300\300\300\300\300\0\0\0\0\0\0\0\0\377\377\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\3\3\0\0\0"
"\0\0\0\0\0\0\300\300\0\0\0\0\0\0\0\0\300\300\0\0\0\0\377\377\0\0\0\0\0\0\0\0"
"\377\377\0\0\0\0\377\377\200\0\0\0\0\0\0\0\377\377\0\0\0\0\0\1\3\3\3\3\3\3\3\3"
"\3\3\0\0\0\0\300\300\0\0\0\0\0\0\0\0\300\300\0\0\0\0\377\377\0\0\0\0\0\0\0\0"
"\377\377\0\0\0\0\37\77p\340\300\200\200\300\340p\77\37\0\0\0\0\0\0\0\0\1\3\3\1\0\0"
"\0\0\0\0\0\0\300\300\0\0\0\0\0\0\0\0\300\300\0\0\0\0\377\377\0\0\0\0\0\0\0\0"
"\377\377\0\0\0\0\377\377\300\340p\70\70p\340\300\377\377\0\0\0\0\3\3\1\0\0\0\0\0\0\1"
"\3\3\0\0\0\0\300\300\0\0\0\0\0\0\0\0\300\300\0\0\0\0\37\77p\340\300\200\200\300\340p"
"\77\37\0\0\0\0\370\374\16\7\3\1\1\3\7\16\374\370\0\0\0\0\3\3\0\0\0\0\0\0\0\0"
"\3\3\0\0\0\0\300\300\0\0\0\0\0\0\0\0\300\300\0\0\0\0\177\377\300\200\200\200\200\200\200\200"
"\377\377\0\0\0\0\0\0\1\1\1\1\1\1\1\201\377\377\0\0\0\0\3\3\3\3\3\3\3\3\3\3"
"\1\0\0\0\0\0\300\300\300\300\300\300\300\300\300\300\300\300\0\0\0\0\0\0\0\0\0\0\200\300`\60"
"\37\17\0\0\0\0\340\360\30\14\6\3\1\0\0\0\0\0\0\0\0\0\3\3\3\3\3\3\3\3\3\3"
"\3\3\0\0\0\0\0\0\374\374\14\14\14\14\14\14\14\14\0\0\0\0\0\0\377\377\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\77\77\60\60\60\60\60\60"
"\60\60\0\0\0\30x\340\200\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\7\36x\340\200\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\1\7\36x\340\200\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1"
"\7\36\30\0\0\0\14\14\14\14\14\14\14\14\374\374\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\0\0\0\0\0\60\60\60\60\60\60\60\60\77\77"
"\0\0\0\0\0\0\0\0\200\300\340pp\340\300\200\0\0\0\0\0\14\16\7\3\1\0\0\0\0\1\3"
"\7\16\14\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\60\60\60\60\60\60\60\60\60\60\60"
"\60\60\60\0\0\0\0\0\0\60p\340\300\200\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\3\3\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\60\60\60\60\60\60\60\60p"
"\340\300\0\0\0\0\370\374\216\6\6\6\6\6\6\6\377\377\0\0\0\0\0\1\3\3\3\3\3\3\3\3"
"\3\3\0\0\0\0\300\300\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\60\60\60\60\60\60\60p"
"\340\300\0\0\0\0\377\377\0\0\0\0\0\0\0\200\377\377\0\0\0\0\3\3\3\3\3\3\3\3\3\3"
"\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\300\340p\60\60\60\60\60\60\60"
"\60\60\0\0\0\0\377\377\200\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\3\3\3\3\3\3\3\3"
"\3\3\0\0\0\0\0\0\0\0\0\0\0\0\0\0\300\300\0\0\0\0\300\340p\60\60\60\60\60\60\60"
"\377\377\0\0\0\0\377\377\200\0\0\0\0\0\0\0\377\377\0\0\0\0\0\1\3\3\3\3\3\3\3\3"
"\3\3\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\300\340p\60\60\60\60\60\60\60"
"\360\360\0\0\0\0\377\377\214\14\14\14\14\14\14\14\17\17\0\0\0\0\0\1\3\3\3\3\3\3\3\3"
"\3\3\0\0\0\0\0\0\0\0\200\300\300\300\300\300\300\0\0\0\0\0\0\300\300\377\377\301\300\300\300\0"
"\0\0\0\0\0\0\0\0\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\3\3\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\300\340p\60\60\60\60\60\60\60"
"\360\360\0\0\0\0\377\377\200\0\0\0\0\0\0\200\377\377\0\0\0\0\300\301\303\303\303\303\303\303\303\347"
"}\70\0\0\0\0\300\300\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\60\60\60\60\60\60\60p"
"\340\300\0\0\0\0\377\377\0\0\0\0\0\0\0\0\377\377\0\0\0\0\3\3\0\0\0\0\0\0\0\0"
"\3\3\0\0\0\0\0\0\0\0\0\300\300\0\0\0\0\0\0\0\0\0\0\0\0\60\60\361\361\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\3\3\3\3\0"
"\0\0\0\0\0\0\0\0\0\0\0\300\300\0\0\0\0\0\0\0\0\0\0\0\0\0\0\361\361\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\377\377\0\0\0\0\0\0\0\0\0\0\300\300\300\340\177\77\0\0\0"
"\0\0\0\0\0\0\0\300\300\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\0\200\300\340p\60"
"\0\0\0\0\0\0\0\377\377\6\17\37\71p\340\300\200\0\0\0\0\0\0\3\3\0\0\0\0\0\0\1"
"\3\3\0\0\0\0\0\0\0\300\300\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\377\377\200\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\3\3\3\3\3"
"\3\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\360\360\60\60\60\300\300\60\60p"
"\340\300\0\0\0\0\377\377\0\0\0\77\77\0\0\0\377\377\0\0\0\0\3\3\0\0\0\0\0\0\0\0"
"\3\3\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\360\360\60\60\60\60\60\60\60p"
"\340\300\0\0\0\0\377\377\0\0\0\0\0\0\0\0\377\377\0\0\0\0\3\3\0\0\0\0\0\0\0\0"
"\3\3\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\300\340p\60\60\60\60\60\60p"
"\340\300\0\0\0\0\377\377\200\0\0\0\0\0\0\200\377\377\0\0\0\0\0\1\3\3\3\3\3\3\3\3"
"\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\360\360\60\60\60\60\60\60\60p"
"\340\300\0\0\0\0\377\377\0\0\0\0\0\0\0\200\377\377\0\0\0\0\377\377\3\3\3\3\3\3\3\3"
"\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\300\340p\60\60\60\60\60\60\60"
"\360\360\0\0\0\0\377\377\200\0\0\0\0\0\0\0\377\377\0\0\0\0\0\1\3\3\3\3\3\3\3\3"
"\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\300\340p\60\60\60\60\60\60\60"
"\360\360\0\0\0\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\3\3\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\300\340p\60\60\60\60\60\60\60"
"\60\60\0\0\0\0\3\7\16\14\14\14\14\14\14\234\370\360\0\0\0\0\3\3\3\3\3\3\3\3\3\3"
"\1\0\0\0\0\0\0\0\0\300\300\0\0\0\0\0\0\0\0\0\0\0\0\60\60\377\377\60\60\60\60\0"
"\0\0\0\0\0\0\0\0\0\377\377\200\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\3\3\3\3\3"
"\3\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\360\360\0\0\0\0\0\0\0\0"
"\360\360\0\0\0\0\377\377\200\0\0\0\0\0\0\0\377\377\0\0\0\0\0\1\3\3\3\3\3\3\3\3"
"\3\3\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\360\360\0\0\0\0\0\0\0\0"
"\360\360\0\0\0\0\37\77p\340\300\200\200\300\340p\77\37\0\0\0\0\0\0\0\0\1\3\3\1\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\360\360\0\0\0\0\0\0\0\0"
"\360\360\0\0\0\0\377\377\200\0\0\377\377\0\0\0\377\377\0\0\0\0\0\1\3\3\3\0\0\3\3\3"
"\3\3\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\60p\340\300\200\0\0\200\300\340"
"p\60\0\0\0\0\200\340\360\71\37\17\17\37\71\360\340\200\0\0\0\0\3\3\0\0\0\0\0\0\0\0"
"\3\3\0";
164 changes: 162 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,166 @@
* as published by Sam Hocevar. See the LICENSE file for more details.
*/

int main(void) {
return 0;
#include <stdlib.h>
#include <avr/io.h>
#include <avr/power.h>
#include <avr/sleep.h>
#include <util/delay.h>
#include <u8x8_avr.h>

#ifndef ADC_PRESCALE_BITS
#if F_CPU >= 12800000L
#define ADC_PRESCALE_BITS (_BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0))
#elif F_CPU >= 6400000L
#define ADC_PRESCALE_BITS (_BV(ADPS2) | _BV(ADPS1))
#elif F_CPU >= 3200000L
#define ADC_PRESCALE_BITS (_BV(ADPS2) | _BV(ADPS0))
#elif F_CPU >= 1600000L
#define ADC_PRESCALE_BITS (_BV(ADPS2))
#elif F_CPU >= 800000L
#define ADC_PRESCALE_BITS (_BV(ADPS1) | _BV(ADPS0))
#else
#error "Define ADC_PRESCALE_BITS"
#endif
#endif

extern const uint8_t rab_font[] U8X8_FONT_SECTION("rab_font");

u8x8_t u8x8;

uint16_t adc_seedrand(void);
void u8x8_display_number(u8x8_t *u8g2, uint8_t val);
uint8_t u8x8_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);

int main() {
// shut down all peripherals except ADC
PRR = (__AVR_HAVE_PRR & ~_BV(PRADC));

// AVCC with external capacitor at AREF pin
// use ADC6
ADMUX = _BV(REFS0) | 6;

srand(adc_seedrand());

// shut down all peripherals except SPI
PRR = (__AVR_HAVE_PRR & ~_BV(PRSPI));

// SPI clock rate F_CPU/2
SPSR = _BV(SPI2X);

u8x8_Setup(&u8x8, u8x8_d_ssd1306_72x40_er, u8x8_cad_001, u8x8_byte_avr_hw_spi, u8x8_gpio_and_delay);
u8x8_InitDisplay(&u8x8);
u8x8_ClearDisplay(&u8x8);
u8x8_SetPowerSave(&u8x8, 0);
u8x8_SetFont(&u8x8, rab_font);

uint8_t rnd = rand();
u8x8_ClearDisplay(&u8x8);
u8x8_display_number(&u8x8, rnd);

SPCR = 0; // disable SPI

PRR = __AVR_HAVE_PRR; // shut down all peripherals

DDRD = 0xff;
PORTD = rnd;
// enable pull-ups on unused pins
DDRB = 0;
PORTB = 0xff;
DDRC = 0;
PORTC = 0xff;

SMCR = _BV(SM1) | _BV(SE); // enable sleep mode (power down)
while (1) {
sleep_cpu();
}
}

uint16_t adc_seedrand(void) {
// repeat 17 times, take LSB of each conversion, and discard the first one
uint16_t r = 0;

for (uint8_t i = CHAR_BIT * sizeof r + 1; i; i--) {
// start and wait for conversion to complete
ADCSRA = _BV(ADEN) | _BV(ADSC) | ADC_PRESCALE_BITS;
loop_until_bit_is_clear(ADCSRA, ADSC);
r = (r << 1) | (ADC & 1);
_delay_us(600);
}
ADCSRA = 0; // disable ADC

return r;
}

void u8x8_display_number(u8x8_t *u8g2, uint8_t val) {
char hex[5] = "0x";

hex[2] = val >> 4;
if (hex[2] > 9)
hex[2] += 'a' - 10;
else
hex[2] += '0';

hex[3] = val & 0xf;
if (hex[3] > 9)
hex[3] += 'a' - 10;
else
hex[3] += '0';

hex[4] = 0;

u8x8_DrawString(u8g2, 0, 1, hex);
}

#define CS_DDR DDRB
#define CS_PORT PORTB
#define CS_BIT 2

#define DC_DDR DDRB
#define DC_PORT PORTB
#define DC_BIT 1

#define RESET_DDR DDRB
#define RESET_PORT PORTB
#define RESET_BIT 0

uint8_t u8x8_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) {
// Re-use library for delays
if (u8x8_avr_delay(u8x8, msg, arg_int, arg_ptr))
return 1;

switch (msg) {
// called once during init phase of u8g2/u8x8
// can be used to setup pins
case U8X8_MSG_GPIO_AND_DELAY_INIT:
CS_DDR |= _BV(CS_BIT);
DC_DDR |= _BV(DC_BIT);
RESET_DDR |= _BV(RESET_BIT);
break;
// CS (chip select) pin: Output level in arg_int
case U8X8_MSG_GPIO_CS:
if (arg_int)
CS_PORT |= _BV(CS_BIT);
else
CS_PORT &= ~_BV(CS_BIT);
break;
// DC (data/cmd, A0, register select) pin: Output level in arg_int
case U8X8_MSG_GPIO_DC:
if (arg_int)
DC_PORT |= _BV(DC_BIT);
else
DC_PORT &= ~_BV(DC_BIT);
break;
// Reset pin: Output level in arg_int
case U8X8_MSG_GPIO_RESET:
if (arg_int)
RESET_PORT |= _BV(RESET_BIT);
else
RESET_PORT &= ~_BV(RESET_BIT);
break;
default:
u8x8_SetGPIOResult(u8x8, 1);
break;
}
return 1;
}
1 change: 1 addition & 0 deletions u8g2
Submodule u8g2 added at ec2559

0 comments on commit ba83b56

Please sign in to comment.