-
Notifications
You must be signed in to change notification settings - Fork 2
/
Arduboy.h
205 lines (156 loc) · 6.4 KB
/
Arduboy.h
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
#ifndef Arduboy_h
#define Arduboy_h
#include "utility/core.h"
#include <SPI.h>
#include <Print.h>
#include <limits.h>
// EEPROM settings
#define EEPROM_VERSION 0
#define EEPROM_BRIGHTNESS 1
#define EEPROM_AUDIO_ON_OFF 2
// we reserve the first 16 byte of EEPROM for system use
#define EEPROM_STORAGE_SPACE_START 16 // and onward
// eeprom settings above are neded for audio
#include "utility/audio.h"
#define PIXEL_SAFE_MODE
// compare Vcc to 1.1 bandgap
#define ADC_VOLTAGE (_BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1))
// compare temperature to 2.5 internal reference and _BV(MUX5)
#define ADC_TEMP (_BV(REFS0) | _BV(REFS1) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0))
class Arduboy : public Print, public ArduboyCore
{
public:
Arduboy();
/// Returns true if the button mask passed in is pressed.
/**
* if (pressed(LEFT_BUTTON + A_BUTTON))
*/
boolean pressed(uint8_t buttons);
/// Returns true if the button mask passed in not pressed.
/**
* if (notPressed(LEFT_BUTTON))
*/
boolean notPressed(uint8_t buttons);
/// Initializes the hardware
void begin();
/// Initializes the hardware (but with no boot logo)
void beginNoLogo();
void start() __attribute__ ((deprecated, warning("use begin() instead")));
/// Scrolls in the Arduboy logo
void bootLogo();
/// Boot utils such as flashlight, etc
void inline bootUtils() __attribute__((always_inline));
/// Clears display.
void clear();
void clearDisplay() __attribute__ ((deprecated, warning("use clear() instead")));
/// Copies the contents of the screen buffer to the screen.
/**
* X and Y positions on the display are from the top left corner, thus a Y of 64
* is the bottom of the screen and an X of 128 is the right side of the screen.
* "Color" or "value" means choosing whether a pixel is lit or not - if color is
* 0, the pixel is off (black), if color is 1, the pixel is on (white).
*/
void display();
/// Sets a single pixel on the screen buffer to white or black.
void drawPixel(int x, int y, uint8_t color);
uint8_t getPixel(uint8_t x, uint8_t y);
/// Draw a circle of a defined radius.
/**
* Draws a circle in white or black. X and Y are the center point of the circle.
*/
void drawCircle(int16_t x0, int16_t y0, uint8_t r, uint8_t color);
/// Draws one or more "corners" of a circle.
void drawCircleHelper(int16_t x0, int16_t y0, uint8_t r, uint8_t cornername, uint8_t color);
/// Draws a filled-in circle.
void fillCircle(int16_t x0, int16_t y0, uint8_t r, uint8_t color);
/// Draws one or both vertical halves of a filled-in circle.
void fillCircleHelper(int16_t x0, int16_t y0, uint8_t r, uint8_t cornername, int16_t delta, uint8_t color);
/// Draws a line between two points.
/**
* Uses Bresenham's algorithm.
*/
void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint8_t color);
/// Draws a rectangle of a width and height.
void drawRect(int16_t x, int16_t y, uint8_t w, uint8_t h, uint8_t color);
/// Draws vertical line.
void drawFastVLine(int16_t x, int16_t y, uint8_t h, uint8_t color);
/// Draws a horizontal line.
void drawFastHLine(int16_t x, int16_t y, uint8_t w, uint8_t color);
/// Draws a filled-in rectangle.
void fillRect(int16_t x, int16_t y, uint8_t w, uint8_t h, uint8_t color);
/// Fills the screen buffer with white or black.
void fillScreen(uint8_t color);
/// Draws a rectangle with rounded edges.
void drawRoundRect(int16_t x, int16_t y, uint8_t w, uint8_t h, uint8_t r, uint8_t color);
/// Draws a filled-in rectangle with rounded edges.
void fillRoundRect(int16_t x, int16_t y, uint8_t w, uint8_t h, uint8_t r, uint8_t color);
/// Draws the outline of a triangle.
void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color);
/// Draws a filled-in triangle.
void fillTriangle (int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color);
/// Draws a bitmap from program memory to a specific X/Y
void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t w, uint8_t h, uint8_t color);
/// Draws images that are bit-oriented horizontally.
/**
* This requires a lot of additional CPU power and will draw images slower
* than drawBitmap, where the images are stored in a format that
* allows them to be directly written to the screen. It is
* recommended you use drawBitmap when possible.
*/
void drawSlowXYBitmap(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t w, uint8_t h, uint8_t color);
/// Draws an ASCII character at a point.
void drawChar(int16_t x, int16_t y, unsigned char c, uint8_t color, uint8_t bg, uint8_t size);
/// Sets the location of the screen cursor.
void setCursor(int16_t x, int16_t y);
/// Set text size
/**
* As mentioned in drawChar(), individual ASCII characters are 6x8 pixels
* (5x7 with spacing on two edges). The size is a pixel multiplier,
* so a size of 2 means each character will be 12x16, etc.
*/
void setTextSize(uint8_t s);
/// Sets whether text will wrap at screen edges.
void setTextWrap(boolean w);
unsigned char* getBuffer();
/// Writes a single ASCII character to the screen.
virtual size_t write(uint8_t);
/// Seeds the random number generator with entropy from the temperature, voltage reading, and microseconds since boot.
/**
* This method is still most effective when called semi-randomly such
* as after a user hits a button to start a game or other semi-random
* events
*/
void initRandomSeed();
/// Swap the references of two pointers.
void swap(int16_t& a, int16_t& b);
ArduboyTunes tunes;
ArduboyAudio audio;
void setFrameRate(uint8_t rate);
bool nextFrame();
bool everyXFrames(uint8_t frames);
/// Returns the load on the CPU as a percentage.
/**
* This is based on how much of the time your app is spends rendering
* frames. This number can be higher than 100 if your app is rendering
* really slowly.
*/
int cpuLoad();
uint8_t frameRate;
uint16_t frameCount;
uint8_t eachFrameMillis;
long lastFrameStart;
long nextFrameStart;
bool post_render;
uint8_t lastFrameDurationMs;
/// useful for getting raw approximate voltage values
uint16_t rawADC(byte adc_bits);
protected:
unsigned char sBuffer[(HEIGHT*WIDTH)/8];
// Adafruit stuff
protected:
int16_t cursor_x;
int16_t cursor_y;
uint8_t textsize;
boolean wrap; // If set, 'wrap' text at right edge of display
};
#endif