-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGLYPH.h
More file actions
262 lines (204 loc) · 7.73 KB
/
GLYPH.h
File metadata and controls
262 lines (204 loc) · 7.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#ifndef GLYPH_H
#define GLYPH_H
#include <avr/io.h>
#define F_CPU 16000000
#define ever ;;
#define TRUE 0x01
#define FALSE 0x00
#define SND 5 // PORTD
#define SNDA 5 // PORTD
#define SNDB 4 // PORTD
/* Display Pins (PORTB) */
#define CS 1
#define DC 3
#define RST 2
#define SCK 0
/* Display Pins (PORTD) */
#define MOSI 1
/* Button Pins (PORTC) */
#define UP_BTN_PIN 4
#define DOWN_BTN_PIN 5
#define LEFT_BTN_PIN 6
#define RIGHT_BTN_PIN 7
#define A_BTN_PIN 0
#define B_BTN_PIN 1
#define C_BTN_PIN 2
#define D_BTN_PIN 3
#define read_buttons() ( ~PINC )
/* Button Masks */
#define BTN_UP 1 << UP_BTN_PIN
#define BTN_DOWN 1 << DOWN_BTN_PIN
#define BTN_LEFT 1 << LEFT_BTN_PIN
#define BTN_RIGHT 1 << RIGHT_BTN_PIN
#define BTN_A 1 << A_BTN_PIN
#define BTN_B 1 << B_BTN_PIN
#define BTN_C 1 << C_BTN_PIN
#define BTN_D 1 << D_BTN_PIN
/* LEDs (PORTD) */
#define LED_1_PIN 6
#define LED_2_PIN 7
/* BATTERY MONITOR */
#define BATMON_PIN 7 // PORTA
#define SPLASH_DELAY 1500
#define BATTERY_DELAY 500
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define HALF_SCREEN_WIDTH SCREEN_WIDTH/2
#define HALF_SCREEN_HEIGHT SCREEN_HEIGHT/2
#define SCREEN_COLUMNS 16
#define SCREEN_ROWS 8
#define NOTE_DURATION_MULTIPLIER 15 // ~1ms
typedef unsigned char bool;
// http://www.soundoctor.com/freq.htm
// OCR1A FREQ.(Hz) Note
static const __flash uint16_t NOTES[] = {
0,
2273, // 440, Concert A(4)
2146, // 466, Bb(4)
2024, // 494, B(4)
1912, // 523, C(5)
1805, // 554, C#(5)
1703, // 587, D(5)
1608, // 622, D#(5)
1518, // 659, E(5)
1433, // 698, F(5)
1351, // 740, F#(5)
1337, // 748, G(5)
1203, // 831, G#(5)
1250, // 800, A(5)
1073, // 932, Bb(5)
1012, // 988, B(5)
142, // 7040, A(8)
71, // 14080 A(9)
};
#define _RST 0x0
#define _A4 0x1
#define _Bb4 0x2
#define _B4 0x3
#define _C5 0x4
#define _Cs5 0x5
#define _D5 0x6
#define _Ds5 0x7
#define _E5 0x8
#define _F5 0x9
#define _Fs5 0xA
#define _G5 0xB
#define _Gs5 0xC
#define _A5 0xD
#define _Bb5 0xE
#define _B5 0xF
#define _A8 16
#define _A9 17
static const __flash uint8_t BEATS[8] = {
64, // SEMIBREVE
48, // DOTTED MINIM
32, // MINIM
16, // CROTCHET
8, // QUAVER
4, // SEMI QUAVER
2, // DEMI SEMI QUAVER
1, // HEMI DEMI SEMI QUAVER
};
#define SEMIBREVE 0 << 4
#define DMINIM 1 << 4
#define MINIM 2 << 4
#define CROTCHET 3 << 4
#define QUAVER 4 << 4
#define SQUAVER 5 << 4
#define DSQUAVER 6 << 4
#define HDSQUAVER 7 << 4
// Starting at 128 BPM
#define BEAT_ATOM 8 * 4 * NOTE_DURATION_MULTIPLIER // 32 Milliseconds
typedef struct Tune {
uint16_t length;
uint8_t score[];
} Tune;
static const __flash Tune STARTUP_CHIME = {
.length = 3,
.score = {
DSQUAVER | _A4, DSQUAVER | _C5, SQUAVER | _E5,
},
};
uint8_t buffer[SCREEN_WIDTH * SCREEN_ROWS];
typedef struct Image {
uint8_t height;
uint8_t width;
uint8_t data[];
} Image;
static const __flash Image LOGO = {
.height = 24,
.width = 96,
.data = {
0x00, 0x00, 0x00, 0x00, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xe8, 0x18, 0x18, 0x18, 0x18, 0x08, 0x10, 0x18, 0x18, 0x18, 0x18, 0x08, 0x00, 0x00, 0x00, 0xf0, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xe8, 0x18, 0x18, 0x18, 0x18, 0x08, 0x10, 0x18, 0x18, 0x18, 0x18, 0xe8, 0xf0, 0x00, 0x00, 0xf0, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xf0, 0x00,
0x00, 0x00, 0x10, 0x18, 0x99, 0xdb, 0xdb, 0x08, 0x10, 0xdb, 0xdb, 0x99, 0x18, 0x10, 0x00, 0x00, 0x00, 0xef, 0xc7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x18, 0x18, 0x18, 0x18, 0xd0, 0xe0, 0x00, 0x00, 0xef, 0xc7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0xe0, 0xc0, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xef, 0xd7, 0x18, 0x18, 0x18, 0x18, 0x08, 0x10, 0x18, 0x18, 0x18, 0x18, 0x17, 0x0f, 0x00, 0x00, 0xef, 0xd7, 0x18, 0x18, 0x18, 0x18, 0x08, 0x10, 0x18, 0x18, 0x18, 0x18, 0xd7, 0xef, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x17, 0x18, 0x18, 0x18, 0x18, 0x08, 0x10, 0x18, 0x18, 0x18, 0x18, 0x17, 0x0f, 0x00, 0x00, 0x0f, 0x17, 0x18, 0x18, 0x18, 0x18, 0x08, 0x10, 0x18, 0x18, 0x18, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x0f, 0x00,
},
};
static const __flash uint8_t BLOCK_MASKS[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xe7, 0xc3, 0x81, 0x00, 0x00, 0x81, 0xc3, 0xe7,
};
#define OPAQUE 0
#define TRANSPARENT 8
#define BUTTON_GLYPH 16
static const __flash uint8_t BATTERY_GLYPHS[] = {
0x42, 0x2a, 0x22, 0x2a, 0x42, 0x02, 0x3c, 0x18, // SAD
0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x18, // EMPTY
0x7e, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x18,
0x7e, 0x7e, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x18,
0x7e, 0x7e, 0x7e, 0x42, 0x42, 0x42, 0x3c, 0x18,
0x7e, 0x7e, 0x7e, 0x7e, 0x42, 0x42, 0x3c, 0x18,
0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x42, 0x3c, 0x18, //FULL
0x7e, 0x66, 0x66, 0x42, 0x5a, 0x7e, 0x3c, 0x18, //CHARGING
};
#define BAT_CHG 7*8
#define BAT_FUL 6*8
#define BAT_EMT 1*8
#define BAT_SAD 0*8
static const __flash uint8_t BUTTON_GLYPHS[] = {
0x18, 0x24, 0x4a, 0xbd, 0x89, 0x42, 0x24, 0x18, //Up
0x18, 0x24, 0x4a, 0x89, 0x9d, 0x4a, 0x24, 0x18, //Right
0x18, 0x24, 0x42, 0x91, 0xbd, 0x52, 0x24, 0x18, //Down
0x18, 0x24, 0x52, 0xb9, 0x91, 0x52, 0x24, 0x18, //Left
0x18, 0x24, 0x5a, 0xa5, 0xa5, 0x42, 0x24, 0x18, //C
0x18, 0x24, 0x42, 0xbd, 0xa5, 0x5a, 0x24, 0x18, //D
0x18, 0x24, 0x42, 0xbd, 0xad, 0x52, 0x24, 0x18, //B
0x18, 0x24, 0x7a, 0x95, 0xb9, 0x42, 0x24, 0x18, //A
};
#define BTN_GLYPH_A 7*8
#define BTN_GLYPH_B 6*8
#define BTN_GLYPH_C 4*8
#define BTN_GLYPH_D 5*8
#define rngM 251
#define rngA 11
#define rngC 3
uint8_t rng( void );
void delay_ms( uint32_t ms );
// http://www.oz4.us/2015/12/recoding-bare-millis-clock-on-avr.html
// https://github.com/sourceperl/millis/blob/master/millis.c
// https://www.avrfreaks.net/forum/tut-c-newbies-guide-avr-timers?page=all
void initialise( void );
uint32_t millis( void );
/* OLED Function */
void shift_out_byte(uint8_t val);
void initialise_oled(void);
typedef enum { NORMAL, INVERTED } mode_t;
void display_mode(mode_t mode);
void clear_buffer(void);
void draw(void);
/* Draw Functions */
void draw_pixel(int16_t x, int16_t y);
void draw_tile(const uint8_t __flash *glyph, const uint8_t __flash *mask, int16_t x, int16_t y, bool flipped);
void draw_image(const __flash Image *img, int16_t x, int16_t y);
void draw_string(const __memx char *string, int16_t x, int16_t y);
void draw_int(int n, uint8_t width, int16_t x, int16_t y);
void note(uint8_t note, uint16_t dur);
void click( void );
void play_tune(const __memx Tune *t);
void stop_tune();
void draw_battery();
/* LEDs */
typedef enum { BOTH, LEFT, RIGHT } LED;
void set_LED_brightness(LED led, uint8_t value);
#endif