diff --git a/.vscode/arduino.json b/.vscode/arduino.json new file mode 100644 index 0000000..8dd95a9 --- /dev/null +++ b/.vscode/arduino.json @@ -0,0 +1,5 @@ +{ + "board": "esp8266:esp8266:huzzah", + "configuration": "xtal=80,vt=flash,exception=disabled,eesz=4M,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=115200", + "port": "COM8" +} \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..c2d540a --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,14 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "C:\\Users\\luni\\AppData\\Local\\Arduino15\\packages\\esp8266\\tools\\**", + "C:\\Users\\luni\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.5.0-beta3\\**" + ], + "forcedInclude": [], + "intelliSenseMode": "msvc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/examples/VGADemo14Bit/VGADemo14Bit.ino b/examples/VGADemo14Bit/VGADemo14Bit.ino new file mode 100644 index 0000000..af99556 --- /dev/null +++ b/examples/VGADemo14Bit/VGADemo14Bit.ino @@ -0,0 +1,50 @@ +#include +#include + +//pin configuration +const int redPins[] = {2, 4, 12, 13, 14}; +const int greenPins[] = {15, 16, 17, 18, 19}; +const int bluePins[] = {21, 22, 23, 27}; +const int hsyncPin = 0; +const int vsyncPin = 5; + +//VGA Device +VGA14Bit vga; + +void setup() +{ + //initializing i2s vga and frame buffers + vga.init(vga.MODE200x150, redPins, greenPins, bluePins, hsyncPin, vsyncPin); +} + +int heat(VGA14Bit::Color c) +{ + if (vga.B(c)) + return vga.B(c) + 512; + if (vga.G(c)) + return vga.G(c) + 256; + return vga.R(c); +} + +VGA14Bit::Color color(int heat) +{ + if (heat >= 512) + return vga.RGB(255, 255, heat - 512); + if (heat >= 256) + return vga.RGB(255, heat - 256, 0); + return vga.RGB(heat, 0, 0); +} + +void loop() +{ + float p = millis() * 0.001f; + vga.fillCircle(vga.xres / 2 + sin(p) * vga.xres / 3, vga.yres / 2 + cos(p * 1.34f) * vga.yres / 3, (rand() & 1) + 3, vga.RGB(255, 255, 255)); + for (int y = 0; y < vga.yres - 1; y++) + for (int x = 1; x < vga.xres - 1; x++) + { + int h = (heat(vga.get(x, y)) + (heat(vga.get(x - 1, y + 1)) + heat(vga.get(x + 1, y + 1))) / 2 + heat(vga.get(x, y + 1))) / 3; + vga.dotFast(x, y, color(h)); + } + for (int x = 0; x < vga.xres; x++) + vga.dotFast(x, vga.yres - 1, (rand() & 3 == 3) ? color(767) : 0); +} \ No newline at end of file diff --git a/examples/WiFiTextToVGA/WiFiTextToVGA.ino b/examples/WiFiTextToVGA/WiFiTextToVGA.ino index c77239d..62c55af 100644 --- a/examples/WiFiTextToVGA/WiFiTextToVGA.ino +++ b/examples/WiFiTextToVGA/WiFiTextToVGA.ino @@ -1,9 +1,10 @@ #include #include -#include #include -//AP credentials +//true: creates an access point, false: connects to an existing wifi +const bool AccessPointMode = true; +//wifi credentials const char *ssid = "VGA"; const char *password = ""; @@ -33,23 +34,51 @@ void sendPage() void text() { server.send(200, "text/plain", "ok"); - vga.println(server.args()); + vga.println(server.arg(0).c_str()); } void setup() { - WiFi.softAP(ssid, password, 6, 0); + Serial.begin(115200); + if (AccessPointMode) + WiFi.softAP(ssid, password, 6, 0); + else + { + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) + { + delay(500); + Serial.print("."); + } + } server.on("/", sendPage); server.on("/text", text); server.begin(); + //initializing i2s vga and frame buffers vga.init(vga.MODE360x400, redPin, greenPin, bluePin, hsyncPin, vsyncPin); - vga.clear(); + vga.clear(4); + vga.backColor = 4; vga.setFont(Font6x8); + vga.println("----------------------"); vga.println("bitluni's VGA Terminal"); - vga.print("Try SSID: "); - vga.println(ssid); + if (AccessPointMode) + { + vga.print("SSID: "); + vga.println(ssid); + if (strlen(password)) + { + vga.print("password: "); + vga.println(password); + } + vga.println("http://192.168.4.1"); + } + else + { + vga.print("http://"); + vga.println(WiFi.localIP().toString().c_str()); + } vga.println("----------------------"); } diff --git a/examples/WiFiTextToVGA/page.h b/examples/WiFiTextToVGA/page.h index fec4393..401eff2 100644 --- a/examples/WiFiTextToVGA/page.h +++ b/examples/WiFiTextToVGA/page.h @@ -1,43 +1,92 @@ R"( + + -bitluni's VGA text terminal - - + function send() { + var e = document.querySelector('#in'); + var xhr = new XMLHttpRequest(); + xhr.open('POST', '/text'); + xhr.send(e.value); + document.querySelector("#log").innerHTML = e.value + "\n" + document.querySelector("#log").innerHTML; + e.value = ''; + } + + - -

bitluni's VGA text terminal

-
- -
- -)" + + +

bitluni's VGA text terminal

+ + + + + + + + +
+ +
+ + + + + +)" \ No newline at end of file diff --git a/library.json b/library.json index 3d9053c..dc19361 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "bitluni ESP32Lib", - "keywords": "VGA, audio, I2S, 3d, game, engine, mesh, gamepad, controller, NES, SNES, input, output, graphics, font, arduino, esp32, driver, display", + "keywords": "VGA, audio, I2S, 3d, game, engine, mesh, gamepad, controller, NES, SNES, input, output, graphics, font, arduino, esp32, driver, display, bitluni", "description": "Provides VGA, Game Controller (NES, SNES), Audio support for the ESP32. The graphics engine supports sprites, animations and 3d meshes.", "repository": { @@ -16,7 +16,7 @@ "maintainer": true } ], - "version": "0.0.4", + "version": "0.0.5", "frameworks": "arduino", "platforms": "espressif32" } \ No newline at end of file diff --git a/library.properties b/library.properties index 3c52f54..6b3ed40 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=bitluni ESP32Lib -version=0.0.4 +version=0.0.5 author=bitluni maintainer=bitluni sentence=Multimedia library for the ESP32 diff --git a/src/Graphics/Graphics.h b/src/Graphics/Graphics.h index 80e472f..d7331c3 100644 --- a/src/Graphics/Graphics.h +++ b/src/Graphics/Graphics.h @@ -44,6 +44,23 @@ class Graphics virtual void dotMix(int x, int y, Color color) = 0; virtual char get(int x, int y) = 0; virtual Color** allocateFrameBuffer() = 0; + virtual Color RGBA(int r, int g, int b, int a = 255) const = 0; + virtual int R(Color c) const = 0; + virtual int G(Color c) const = 0; + virtual int B(Color c) const = 0; + virtual int A(Color c) const = 0; + Color RGB(unsigned long rgb) const + { + return RGBA(rgb & 255, (rgb >> 8) & 255, (rgb >> 16) & 255); + } + Color RGBA(unsigned long rgba) const + { + return RGBA(rgba & 255, (rgba >> 8) & 255, (rgba >> 16) & 255, rgba >> 24); + } + Color RGB(int r, int g, int b) const + { + return RGBA(r, g, b); + } void setFrameBufferCount(unsigned char i) { diff --git a/src/Graphics/GraphicsR1G1B1A1.h b/src/Graphics/GraphicsR1G1B1A1.h index acc8ffc..36f8198 100644 --- a/src/Graphics/GraphicsR1G1B1A1.h +++ b/src/Graphics/GraphicsR1G1B1A1.h @@ -22,6 +22,28 @@ class GraphicsR1G1B1A1: public Graphics frontColor = 0xf; } + virtual int R(Color c) const + { + return (c & 1) * 255; + } + virtual int G(Color c) const + { + return (c & 2) ? 255 : 0; + } + virtual int B(Color c) const + { + return (c & 4) ? 255 : 0; + } + virtual int A(Color c) const + { + return (c & 8) ? 255 : 0; + } + + virtual Color RGBA(int r, int g, int b, int a = 255) const + { + return ((r >> 7) & 1) | ((g >> 6) & 2) | ((b >> 5) & 4) | ((a >> 4) & 8); + } + virtual void dotFast(int x, int y, Color color) { if(x & 1) @@ -80,7 +102,11 @@ class GraphicsR1G1B1A1: public Graphics { Color** frame = (Color **)malloc(yres * sizeof(Color *)); for (int y = 0; y < yres; y++) + { frame[y] = (Color *)malloc(xres / 2 * sizeof(Color)); + for (int x = 0; x < xres / 2; x++) + frame[y][x] = 0; + } return frame; } }; \ No newline at end of file diff --git a/src/Graphics/GraphicsR5G5B4A2.h b/src/Graphics/GraphicsR5G5B4A2.h index 5910566..d5000f2 100644 --- a/src/Graphics/GraphicsR5G5B4A2.h +++ b/src/Graphics/GraphicsR5G5B4A2.h @@ -23,6 +23,28 @@ class GraphicsR5G5B4A2: public Graphics frontColor = 0xffff; } + virtual int R(Color c) const + { + return (((c << 1) & 0x3e) * 255 + 1) / 0x3e; + } + virtual int G(Color c) const + { + return (((c >> 4) & 0x3e) * 255 + 1) / 0x3e; + } + virtual int B(Color c) const + { + return (((c >> 9) & 0x1e) * 255 + 1) / 0x1e; + } + virtual int A(Color c) const + { + return (((c >> 13) & 6) * 255 + 1) / 6; + } + + virtual Color RGBA(int r, int g, int b, int a = 255) const + { + return ((r >> 3) & 0b11111) | ((g << 2) & 0b1111100000) | ((b << 6) & 0b11110000000000) | ((a << 8) & 0b110000000000000000); + } + virtual void dotFast(int x, int y, Color color) { backBuffer[y][x] = color; @@ -76,7 +98,11 @@ class GraphicsR5G5B4A2: public Graphics { Color** frame = (Color **)malloc(yres * sizeof(Color *)); for (int y = 0; y < yres; y++) + { frame[y] = (Color *)malloc(xres * sizeof(Color)); + for (int x = 0; x < xres; x++) + frame[y][x] = 0; + } return frame; } }; \ No newline at end of file