Library(Beta) for Gameduino 2
GD2.h@0:9c211972beb2, 2014-04-11 (annotated)
- Committer:
- aluqard
- Date:
- Fri Apr 11 07:24:23 2014 +0000
- Revision:
- 0:9c211972beb2
Initial release for Gameduino 2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aluqard | 0:9c211972beb2 | 1 | #ifndef _GAMEDUINO2_H_ |
aluqard | 0:9c211972beb2 | 2 | #define _GAMEDUINO2_H_ |
aluqard | 0:9c211972beb2 | 3 | |
aluqard | 0:9c211972beb2 | 4 | #include "mbed.h" |
aluqard | 0:9c211972beb2 | 5 | #include "arduino.h" |
aluqard | 0:9c211972beb2 | 6 | #include "GDTransport.h" |
aluqard | 0:9c211972beb2 | 7 | |
aluqard | 0:9c211972beb2 | 8 | #define PROTO 1 |
aluqard | 0:9c211972beb2 | 9 | #define STORAGE 1 |
aluqard | 0:9c211972beb2 | 10 | #define CALIBRATION 0 |
aluqard | 0:9c211972beb2 | 11 | #define DUMP_INPUTS 0 |
aluqard | 0:9c211972beb2 | 12 | #define VERBOSE 0 |
aluqard | 0:9c211972beb2 | 13 | |
aluqard | 0:9c211972beb2 | 14 | #define RGB(r, g, b) ((uint32_t)((((r) & 0xffL) << 16) | (((g) & 0xffL) << 8) | ((b) & 0xffL))) |
aluqard | 0:9c211972beb2 | 15 | #define F8(x) (int((x) * 256L)) |
aluqard | 0:9c211972beb2 | 16 | #define F16(x) ((int32_t)((x) * 65536L)) |
aluqard | 0:9c211972beb2 | 17 | |
aluqard | 0:9c211972beb2 | 18 | #define GD_CALIBRATE 1 |
aluqard | 0:9c211972beb2 | 19 | #define GD_TRIM 2 |
aluqard | 0:9c211972beb2 | 20 | #define GD_STORAGE 4 |
aluqard | 0:9c211972beb2 | 21 | |
aluqard | 0:9c211972beb2 | 22 | #define REG_TRIM 0x10256C |
aluqard | 0:9c211972beb2 | 23 | #define LOW_FREQ_BOUND 47040000UL |
aluqard | 0:9c211972beb2 | 24 | |
aluqard | 0:9c211972beb2 | 25 | class sdcard; |
aluqard | 0:9c211972beb2 | 26 | |
aluqard | 0:9c211972beb2 | 27 | class GDClass |
aluqard | 0:9c211972beb2 | 28 | { |
aluqard | 0:9c211972beb2 | 29 | public: |
aluqard | 0:9c211972beb2 | 30 | GDClass(PinName mosi, PinName miso, PinName sclk, PinName graphic_cs, PinName sdcard_cs); |
aluqard | 0:9c211972beb2 | 31 | |
aluqard | 0:9c211972beb2 | 32 | GDTransport GDTR; |
aluqard | 0:9c211972beb2 | 33 | sdcard *SD; |
aluqard | 0:9c211972beb2 | 34 | AnalogIn *accel[3]; |
aluqard | 0:9c211972beb2 | 35 | PinName _sdcard_cs; |
aluqard | 0:9c211972beb2 | 36 | |
aluqard | 0:9c211972beb2 | 37 | sdcard* getSD() { return SD; } |
aluqard | 0:9c211972beb2 | 38 | void begin(unsigned char options = (GD_CALIBRATE | GD_TRIM | GD_STORAGE)); |
aluqard | 0:9c211972beb2 | 39 | |
aluqard | 0:9c211972beb2 | 40 | unsigned short random(); |
aluqard | 0:9c211972beb2 | 41 | unsigned short random(unsigned short n); |
aluqard | 0:9c211972beb2 | 42 | void seed(unsigned short n); |
aluqard | 0:9c211972beb2 | 43 | short rsin(short r, unsigned short th); |
aluqard | 0:9c211972beb2 | 44 | short rcos(short r, unsigned short th); |
aluqard | 0:9c211972beb2 | 45 | void polar(int &x, int &y, short r, unsigned short th); |
aluqard | 0:9c211972beb2 | 46 | unsigned short atan2(short y, short x); |
aluqard | 0:9c211972beb2 | 47 | |
aluqard | 0:9c211972beb2 | 48 | void copy(const unsigned char *src, int count); |
aluqard | 0:9c211972beb2 | 49 | void copyram(unsigned char *src, int count); |
aluqard | 0:9c211972beb2 | 50 | |
aluqard | 0:9c211972beb2 | 51 | void self_calibrate(void); |
aluqard | 0:9c211972beb2 | 52 | |
aluqard | 0:9c211972beb2 | 53 | void swap(void); |
aluqard | 0:9c211972beb2 | 54 | void flush(void); |
aluqard | 0:9c211972beb2 | 55 | void finish(void); |
aluqard | 0:9c211972beb2 | 56 | |
aluqard | 0:9c211972beb2 | 57 | void play(unsigned char instrument, unsigned char note = 0); |
aluqard | 0:9c211972beb2 | 58 | void sample(unsigned int start, unsigned int len, unsigned short freq, unsigned short format, int loop = 0); |
aluqard | 0:9c211972beb2 | 59 | |
aluqard | 0:9c211972beb2 | 60 | void get_inputs(void); |
aluqard | 0:9c211972beb2 | 61 | void get_accel(int &x, int &y, int &z); |
aluqard | 0:9c211972beb2 | 62 | struct { |
aluqard | 0:9c211972beb2 | 63 | unsigned short track_tag; |
aluqard | 0:9c211972beb2 | 64 | unsigned short track_val; |
aluqard | 0:9c211972beb2 | 65 | unsigned short rz; |
aluqard | 0:9c211972beb2 | 66 | unsigned short __dummy_1; |
aluqard | 0:9c211972beb2 | 67 | short y; |
aluqard | 0:9c211972beb2 | 68 | short x; |
aluqard | 0:9c211972beb2 | 69 | short tag_y; |
aluqard | 0:9c211972beb2 | 70 | short tag_x; |
aluqard | 0:9c211972beb2 | 71 | unsigned char tag; |
aluqard | 0:9c211972beb2 | 72 | unsigned char ptag; |
aluqard | 0:9c211972beb2 | 73 | } inputs; |
aluqard | 0:9c211972beb2 | 74 | |
aluqard | 0:9c211972beb2 | 75 | void AlphaFunc(unsigned char func, unsigned char ref); |
aluqard | 0:9c211972beb2 | 76 | void Begin(unsigned char prim); |
aluqard | 0:9c211972beb2 | 77 | void BitmapHandle(unsigned char handle); |
aluqard | 0:9c211972beb2 | 78 | void BitmapLayout(unsigned char format, unsigned short linestride, unsigned short height); |
aluqard | 0:9c211972beb2 | 79 | void BitmapSize(unsigned char filter, unsigned char wrapx, unsigned char wrapy, unsigned short width, unsigned short height); |
aluqard | 0:9c211972beb2 | 80 | void BitmapSource(unsigned int addr); |
aluqard | 0:9c211972beb2 | 81 | void BitmapTransformA(int a); |
aluqard | 0:9c211972beb2 | 82 | void BitmapTransformB(int b); |
aluqard | 0:9c211972beb2 | 83 | void BitmapTransformC(int c); |
aluqard | 0:9c211972beb2 | 84 | void BitmapTransformD(int d); |
aluqard | 0:9c211972beb2 | 85 | void BitmapTransformE(int e); |
aluqard | 0:9c211972beb2 | 86 | void BitmapTransformF(int f); |
aluqard | 0:9c211972beb2 | 87 | void BlendFunc(unsigned char src, unsigned char dst); |
aluqard | 0:9c211972beb2 | 88 | void Call(unsigned short dest); |
aluqard | 0:9c211972beb2 | 89 | void Cell(unsigned char cell); |
aluqard | 0:9c211972beb2 | 90 | void ClearColorA(unsigned char alpha); |
aluqard | 0:9c211972beb2 | 91 | void ClearColorRGB(unsigned char red, unsigned char green, unsigned char blue); |
aluqard | 0:9c211972beb2 | 92 | void ClearColorRGB(unsigned int rgb); |
aluqard | 0:9c211972beb2 | 93 | void Clear(unsigned char c, unsigned char s, unsigned char t); |
aluqard | 0:9c211972beb2 | 94 | void Clear(void); |
aluqard | 0:9c211972beb2 | 95 | void ClearStencil(unsigned char s); |
aluqard | 0:9c211972beb2 | 96 | void ClearTag(unsigned char s); |
aluqard | 0:9c211972beb2 | 97 | void ColorA(unsigned char alpha); |
aluqard | 0:9c211972beb2 | 98 | void ColorMask(unsigned char r, unsigned char g, unsigned char b, unsigned char a); |
aluqard | 0:9c211972beb2 | 99 | void ColorRGB(unsigned char red, unsigned char green, unsigned char blue); |
aluqard | 0:9c211972beb2 | 100 | void ColorRGB(unsigned int rgb); |
aluqard | 0:9c211972beb2 | 101 | void Display(void); |
aluqard | 0:9c211972beb2 | 102 | void End(void); |
aluqard | 0:9c211972beb2 | 103 | void Jump(unsigned short dest); |
aluqard | 0:9c211972beb2 | 104 | void LineWidth(unsigned short width); |
aluqard | 0:9c211972beb2 | 105 | void Macro(unsigned char m); |
aluqard | 0:9c211972beb2 | 106 | void PointSize(unsigned short size); |
aluqard | 0:9c211972beb2 | 107 | void RestoreContext(void); |
aluqard | 0:9c211972beb2 | 108 | void Return(void); |
aluqard | 0:9c211972beb2 | 109 | void SaveContext(void); |
aluqard | 0:9c211972beb2 | 110 | void ScissorSize(unsigned short width, unsigned short height); |
aluqard | 0:9c211972beb2 | 111 | void ScissorXY(unsigned short x, unsigned short y); |
aluqard | 0:9c211972beb2 | 112 | void StencilFunc(unsigned char func, unsigned char ref, unsigned char mask); |
aluqard | 0:9c211972beb2 | 113 | void StencilMask(unsigned char mask); |
aluqard | 0:9c211972beb2 | 114 | void StencilOp(unsigned char sfail, unsigned char spass); |
aluqard | 0:9c211972beb2 | 115 | void TagMask(unsigned char mask); |
aluqard | 0:9c211972beb2 | 116 | void Tag(unsigned char s); |
aluqard | 0:9c211972beb2 | 117 | void Vertex2f(short x, short y); |
aluqard | 0:9c211972beb2 | 118 | void Vertex2ii(unsigned short x, unsigned short y, unsigned char handle = 0, unsigned char cell = 0); |
aluqard | 0:9c211972beb2 | 119 | |
aluqard | 0:9c211972beb2 | 120 | // Higher-level graphics commands |
aluqard | 0:9c211972beb2 | 121 | |
aluqard | 0:9c211972beb2 | 122 | void cmd_append(unsigned int ptr, unsigned int num); |
aluqard | 0:9c211972beb2 | 123 | void cmd_bgcolor(unsigned int c); |
aluqard | 0:9c211972beb2 | 124 | void cmd_button(short x, short y, unsigned short w, unsigned short h, unsigned char font, unsigned short options, const char *s); |
aluqard | 0:9c211972beb2 | 125 | void cmd_calibrate(void); |
aluqard | 0:9c211972beb2 | 126 | void cmd_clock(short x, short y, short r, unsigned short options, unsigned short h, unsigned short m, unsigned short s, unsigned short ms); |
aluqard | 0:9c211972beb2 | 127 | void cmd_coldstart(void); |
aluqard | 0:9c211972beb2 | 128 | void cmd_dial(short x, short y, short r, unsigned short options, unsigned short val); |
aluqard | 0:9c211972beb2 | 129 | void cmd_dlstart(void); |
aluqard | 0:9c211972beb2 | 130 | void cmd_fgcolor(unsigned int c); |
aluqard | 0:9c211972beb2 | 131 | void cmd_gauge(short x, short y, short r, unsigned short options, unsigned short major, unsigned short minor, unsigned short val, unsigned short range); |
aluqard | 0:9c211972beb2 | 132 | void cmd_getmatrix(void); |
aluqard | 0:9c211972beb2 | 133 | void cmd_getprops(unsigned int &ptr, unsigned int &w, unsigned int &h); |
aluqard | 0:9c211972beb2 | 134 | void cmd_getptr(void); |
aluqard | 0:9c211972beb2 | 135 | void cmd_gradcolor(unsigned int c); |
aluqard | 0:9c211972beb2 | 136 | void cmd_gradient(short x0, short y0, unsigned int rgb0, short x1, short y1, unsigned int rgb1); |
aluqard | 0:9c211972beb2 | 137 | void cmd_inflate(unsigned int ptr); |
aluqard | 0:9c211972beb2 | 138 | void cmd_interrupt(unsigned int ms); |
aluqard | 0:9c211972beb2 | 139 | void cmd_keys(short x, short y, short w, short h, unsigned char font, unsigned short options, const char*s); |
aluqard | 0:9c211972beb2 | 140 | void cmd_loadidentity(void); |
aluqard | 0:9c211972beb2 | 141 | void cmd_loadimage(unsigned int ptr, int options); |
aluqard | 0:9c211972beb2 | 142 | void cmd_memcpy(unsigned int dest, unsigned int src, unsigned int num); |
aluqard | 0:9c211972beb2 | 143 | void cmd_memset(unsigned int ptr, unsigned char value, unsigned int num); |
aluqard | 0:9c211972beb2 | 144 | unsigned int cmd_memcrc(unsigned int ptr, unsigned int num); |
aluqard | 0:9c211972beb2 | 145 | void cmd_memwrite(unsigned int ptr, unsigned int num); |
aluqard | 0:9c211972beb2 | 146 | void cmd_regwrite(unsigned int ptr, unsigned int val); |
aluqard | 0:9c211972beb2 | 147 | void cmd_number(short x, short y, unsigned char font, unsigned short options, unsigned int n); |
aluqard | 0:9c211972beb2 | 148 | void cmd_progress(short x, short y, short w, short h, unsigned short options, unsigned short val, unsigned short range); |
aluqard | 0:9c211972beb2 | 149 | void cmd_regread(unsigned int ptr); |
aluqard | 0:9c211972beb2 | 150 | void cmd_rotate(int a); |
aluqard | 0:9c211972beb2 | 151 | void cmd_scale(int sx, int sy); |
aluqard | 0:9c211972beb2 | 152 | void cmd_screensaver(void); |
aluqard | 0:9c211972beb2 | 153 | void cmd_scrollbar(short x, short y, short w, short h, unsigned short options, unsigned short val, unsigned short size, unsigned short range); |
aluqard | 0:9c211972beb2 | 154 | void cmd_setfont(unsigned char font, unsigned int ptr); |
aluqard | 0:9c211972beb2 | 155 | void cmd_setmatrix(void); |
aluqard | 0:9c211972beb2 | 156 | void cmd_sketch(short x, short y, unsigned short w, unsigned short h, unsigned int ptr, unsigned short format); |
aluqard | 0:9c211972beb2 | 157 | void cmd_slider(short x, short y, unsigned short w, unsigned short h, unsigned short options, unsigned short val, unsigned short range); |
aluqard | 0:9c211972beb2 | 158 | void cmd_snapshot(unsigned int ptr); |
aluqard | 0:9c211972beb2 | 159 | void cmd_spinner(short x, short y, unsigned char style, unsigned char scale); |
aluqard | 0:9c211972beb2 | 160 | void cmd_stop(void); |
aluqard | 0:9c211972beb2 | 161 | void cmd_swap(void); |
aluqard | 0:9c211972beb2 | 162 | void cmd_text(short x, short y, unsigned char font, unsigned short options, const char *s); |
aluqard | 0:9c211972beb2 | 163 | void cmd_toggle(short x, short y, short w, unsigned char font, unsigned short options, unsigned short state, const char *s); |
aluqard | 0:9c211972beb2 | 164 | void cmd_track(short x, short y, unsigned short w, unsigned short h, unsigned char tag); |
aluqard | 0:9c211972beb2 | 165 | void cmd_translate(int tx, int ty); |
aluqard | 0:9c211972beb2 | 166 | |
aluqard | 0:9c211972beb2 | 167 | unsigned char rd(unsigned int addr); |
aluqard | 0:9c211972beb2 | 168 | void wr(unsigned int addr, unsigned char v); |
aluqard | 0:9c211972beb2 | 169 | unsigned short rd16(unsigned int addr); |
aluqard | 0:9c211972beb2 | 170 | void wr16(unsigned int addr, unsigned short v); |
aluqard | 0:9c211972beb2 | 171 | unsigned int rd32(unsigned int addr); |
aluqard | 0:9c211972beb2 | 172 | void wr32(unsigned int addr, unsigned int v); |
aluqard | 0:9c211972beb2 | 173 | void wr_n(unsigned int addr, unsigned char *src, unsigned int n); |
aluqard | 0:9c211972beb2 | 174 | |
aluqard | 0:9c211972beb2 | 175 | void cmd32(unsigned int b); |
aluqard | 0:9c211972beb2 | 176 | |
aluqard | 0:9c211972beb2 | 177 | void bulkrd(unsigned int a); |
aluqard | 0:9c211972beb2 | 178 | void resume(void); |
aluqard | 0:9c211972beb2 | 179 | void __end(void); |
aluqard | 0:9c211972beb2 | 180 | void reset(void); |
aluqard | 0:9c211972beb2 | 181 | |
aluqard | 0:9c211972beb2 | 182 | void dumpscreen(void); |
aluqard | 0:9c211972beb2 | 183 | unsigned char load(const char *filename, void (*progress)(long, long) = NULL); |
aluqard | 0:9c211972beb2 | 184 | void safeload(const char *filename); |
aluqard | 0:9c211972beb2 | 185 | |
aluqard | 0:9c211972beb2 | 186 | void storage(void); |
aluqard | 0:9c211972beb2 | 187 | void tune(void); |
aluqard | 0:9c211972beb2 | 188 | |
aluqard | 0:9c211972beb2 | 189 | private: |
aluqard | 0:9c211972beb2 | 190 | void cFFFFFF(unsigned char v); |
aluqard | 0:9c211972beb2 | 191 | void cI(unsigned int); |
aluqard | 0:9c211972beb2 | 192 | void ci(int); |
aluqard | 0:9c211972beb2 | 193 | void cH(unsigned short); |
aluqard | 0:9c211972beb2 | 194 | void ch(short); |
aluqard | 0:9c211972beb2 | 195 | void cs(const char *); |
aluqard | 0:9c211972beb2 | 196 | void fmtcmd(const char *fmt, ...); |
aluqard | 0:9c211972beb2 | 197 | |
aluqard | 0:9c211972beb2 | 198 | void align(unsigned char n); |
aluqard | 0:9c211972beb2 | 199 | void cmdbyte(unsigned char b); |
aluqard | 0:9c211972beb2 | 200 | |
aluqard | 0:9c211972beb2 | 201 | unsigned int measure_freq(void); |
aluqard | 0:9c211972beb2 | 202 | |
aluqard | 0:9c211972beb2 | 203 | unsigned short lfsr, lcg; |
aluqard | 0:9c211972beb2 | 204 | }; |
aluqard | 0:9c211972beb2 | 205 | #endif |