From d711506e3d0ee2db7114fc6b6fdec964475929d8 Mon Sep 17 00:00:00 2001 From: "Mr.Blinky" Date: Wed, 23 Feb 2022 01:47:00 +0100 Subject: [PATCH] Update Arduboy FX library and examples Update FX::begin() Now includes FX:disableOLED() Added FX::display() FX replacement for arduboy.display() --- .../ArduboyFX/drawballs/drawballs.ino | 179 ++++++++++++++++++ .../examples/basic-example/basic-example.ino | 103 +++++----- .../basic-example/{ => fxdata}/fxdata.bin | Bin .../basic-example/{ => fxdata}/fxdata.h | 2 +- .../basic-example/{ => fxdata}/fxdata.txt | 2 +- .../ArduboyFX/examples/chompies/chompies.ino | 27 +-- .../examples/chompies/{ => fxdata}/fxdata.bin | Bin .../examples/chompies/{ => fxdata}/fxdata.h | 2 +- .../examples/chompies/{ => fxdata}/fxdata.txt | 4 +- .../examples/drawballs/assets/tiles_16x16.png | Bin 221 -> 252 bytes .../examples/drawballs/drawballs.ino | 23 +-- .../drawballs/{ => fxdata}/fxdata.bin | Bin .../examples/drawballs/{ => fxdata}/fxdata.h | 2 +- .../drawballs/{ => fxdata}/fxdata.txt | 6 +- .../libraries/ArduboyFX/library.properties | 2 +- .../libraries/ArduboyFX/src/ArduboyFX.cpp | 33 +++- .../libraries/ArduboyFX/src/ArduboyFX.h | 6 +- 17 files changed, 297 insertions(+), 94 deletions(-) create mode 100644 board-package-source/libraries/ArduboyFX/drawballs/drawballs.ino rename board-package-source/libraries/ArduboyFX/examples/basic-example/{ => fxdata}/fxdata.bin (100%) rename board-package-source/libraries/ArduboyFX/examples/basic-example/{ => fxdata}/fxdata.h (74%) rename board-package-source/libraries/ArduboyFX/examples/basic-example/{ => fxdata}/fxdata.txt (95%) rename board-package-source/libraries/ArduboyFX/examples/chompies/{ => fxdata}/fxdata.bin (100%) rename board-package-source/libraries/ArduboyFX/examples/chompies/{ => fxdata}/fxdata.h (76%) rename board-package-source/libraries/ArduboyFX/examples/chompies/{ => fxdata}/fxdata.txt (93%) rename board-package-source/libraries/ArduboyFX/examples/drawballs/{ => fxdata}/fxdata.bin (100%) rename board-package-source/libraries/ArduboyFX/examples/drawballs/{ => fxdata}/fxdata.h (79%) rename board-package-source/libraries/ArduboyFX/examples/drawballs/{ => fxdata}/fxdata.txt (93%) diff --git a/board-package-source/libraries/ArduboyFX/drawballs/drawballs.ino b/board-package-source/libraries/ArduboyFX/drawballs/drawballs.ino new file mode 100644 index 0000000..e54548a --- /dev/null +++ b/board-package-source/libraries/ArduboyFX/drawballs/drawballs.ino @@ -0,0 +1,179 @@ +/* ***************************************************************************** + * FX draw balls test v1.16 by Mr.Blinky May 2019 Feb 2022 licenced under CC0 + * ***************************************************************************** + * + * Before this example sketch is uploaded and run on the Arduboy FX, make sure + * the fxdata this sketch has been build and uploaded to the Arduboy FX. + * + * If the Arduboy FX Arduino plugin has been installed you can simply choose the + * 'Build and upload Arduboy FX data' from the Arduino IDE Tools menu. + * + * Alternatively the fxdata.txt script file can be build using the fxdata-build.py + * Phyton script and the fxdata.bin file can be uploaded using the uploader-gui.py, + * fxdata-upload.py or flash-writer.py Python script using the -d switch. + * + * This demo draws a moving background tilemap with a bunch of bouncing ball sprites. + * + * Button controls: + * + * A - increase the number of bounching balls up to MAX_BALLS + * B - decrease the number of balls down to zero + * + * D-Pad - scroll the background + * + */ + +#include +#include // Required library for accessing the FX flash chip +#include "fxdata.h" // this file contains all the references to FX data + // Check out fxdata.txt to see how this is done. +#define FRAME_RATE 60 + +#define MAX_BALLS 55 // 55 Balls possible at 60fps 155 at 30fps +#define CIRCLE_POINTS 84 +#define VISABLE_TILES_PER_COLUMN 5 // the maximum number of tiles visable vertically +#define VISABLE_TILES_PER_ROW 9 // the maximum number of tiles visable horizontally + +//datafile offsets +constexpr uint8_t ballWidth = 16; +constexpr uint8_t ballHeight = 16; +constexpr uint8_t tilemapWidth = 16; // number of tiles in a tilemap row +constexpr uint8_t tileWidth = 16; +constexpr uint8_t tileHeight = 16; + +Arduboy2 arduboy; + +Point circlePoints[CIRCLE_POINTS] = // all the points of a circle with radius 15 used for the circling background effect +{ + {-15,0}, {-15,1}, {-15,2}, {-15,3}, {-15,4}, {-14,5}, {-14,6}, {-13,7}, {-13,8}, {-12,9}, {-11,10}, {-10,11}, {-9,12}, {-8,13}, {-7,13}, {-6,14}, + {-5,14}, {-4,14}, {-3,15}, {-2,15}, {-1,15}, {0,15}, {1,15}, {2,15}, {3,15}, {4,14}, {5,14}, {6,14}, {7,13}, {8,13}, {9,12}, {10,11}, + {11,10}, {12,9}, {12,8}, {13,7}, {13,6}, {14,5}, {14,4}, {14,3}, {14,2}, {14,1}, {15,0}, {15,-1}, {15,-2}, {15,-3}, {15,-4}, {14,-5}, + {14,-6}, {13,-7}, {13,-8}, {12,-9}, {11,-10}, {10,-11}, {9,-12}, {8,-13}, {7,-13}, {6,-14}, {5,-14}, {4,-14}, {3,-15}, {2,-15}, {1,-15}, {0,-15}, + {-1,-15}, {-2,-15}, {-3,-15}, {-4,-14}, {-5,-14}, {-6,-14}, {-7,-13}, {-8,-13}, {-9,-12}, {-10,-11}, {-11,-10}, {-12,-9}, {-12,-8}, {-13,-7}, {-13,-6}, {-14,-5}, + {-14,-4}, {-14,-3}, {-14,-2}, {-14,-1} +}; + +Point camera; +Point mapLocation = {16,16}; + +struct Ball +{ + int8_t x; + int8_t y; + int8_t xspeed; + int8_t yspeed; +}; + +Ball ball[MAX_BALLS]; +uint8_t ballsVisible = MAX_BALLS; + +uint8_t pos; + +void setup() { + arduboy.begin(); + arduboy.setFrameRate(FRAME_RATE); + FX::begin(FX_DATA_PAGE); // wakeup external flash chip, initialize datapage, detect presence of external flash chip + + for (uint8_t i=0; i < MAX_BALLS; i++) // initialize ball sprites + { + ball[i].x = random(113); + ball[i].y = random(49); + ball[i].xspeed = 1;//random(1,3); + if (random(100) > 49) ball[i].xspeed = -ball[i].xspeed; + ball[i].yspeed = 1; //random(1,3); + if (random(100) > 49) ball[i].yspeed = -ball[i].yspeed; + } +} + +uint8_t tilemapBuffer[VISABLE_TILES_PER_ROW]; // a small buffer to store one horizontal row of tiles from the tilemap + +void loop() { + if (!arduboy.nextFrame()) return; // return until it's time to draw a new frame + + arduboy.pollButtons(); // pollButtons required for the justPressed() function + if ((arduboy.justPressed(A_BUTTON) && ballsVisible < MAX_BALLS)) ballsVisible++; // Pressing A button increases the number of visible balls until the maximum has been reached + if ((arduboy.justPressed(B_BUTTON) && ballsVisible > 0)) ballsVisible--; // Pressing B reduces the number of visible balls until none are visible + if (arduboy.pressed(UP_BUTTON) && mapLocation.y > 16) mapLocation.y--; // Pressing directional buttons will scroll the tilemap + if (arduboy.pressed(DOWN_BUTTON) && mapLocation.y < 176) mapLocation.y++; + if (arduboy.pressed(LEFT_BUTTON) && mapLocation.x > 16) mapLocation.x--; + if (arduboy.pressed(RIGHT_BUTTON) && mapLocation.x < 112) mapLocation.x++; + + camera.x = mapLocation.x + circlePoints[pos].x; // circle around a fixed point + camera.y = mapLocation.y + circlePoints[pos].y; + + //draw tilemap + for (int8_t y = 0; y < VISABLE_TILES_PER_COLUMN; y++) + { + FX::readDataArray(FX_DATA_TILEMAP, // read the visible tiles on a horizontal row from the tilemap in external flash + y + camera.y / tileHeight, // the tilemap row + camera.x / tileWidth, // the column within tilemap row + tilemapWidth, // use the width of tilemap as array element size + tilemapBuffer, // reading tiles into a small buffer is faster then reading each tile individually + VISABLE_TILES_PER_ROW); + + for (uint8_t x = 0; x < VISABLE_TILES_PER_ROW; x++) + { + FX::drawBitmap(x * tileWidth - camera.x % tileWidth, // we're substracting the tile width and height modulus for scrolling effect + y * tileHeight - camera.y % tileHeight, // + FX_DATA_TILES, // the tilesheet bitmap offset in external flash + tilemapBuffer[x], // tile index + dbmNormal); // draw a row of normal tiles + } + } + if (arduboy.notPressed(UP_BUTTON | DOWN_BUTTON | LEFT_BUTTON | RIGHT_BUTTON)) pos = ++pos % CIRCLE_POINTS; //only circle around when no directional buttons are pressed + + //draw balls + for (uint8_t i=0; i < ballsVisible; i++) + FX::drawBitmap(ball[i].x, // although this function is called drawBitmap it can also draw masked sprites + ball[i].y, + FX_DATA_BALLS, // the ball sprites masked bitmap offset in external flash memory + 0, // the fxdata was build using the single ball sprite.png image so there's only frame 0 + //i % 16, // comment above and uncomment this one if the fxdata is rebuild using the ball_16x16.png image + dbmMasked /* | dbmReverse */ ); // remove the '/*' and '/*' to reverse the balls into white balls + + //when uploading the drawballs-singe-datafile.bin into the development area, + //you can replace the "0" value in the drawBitmap function above with "i % 16" without the quotes to display 16 different balls + + //update ball movements + for (uint8_t i=0; i < ballsVisible; i++) + { + if (ball[i].xspeed > 0) // Moving right + { + ball[i].x += ball[i].xspeed; + if (ball[i].x > WIDTH - ballWidth) //off the right + { + ball[i].x = WIDTH - ballWidth; + ball[i].xspeed = - ball[i].xspeed; + } + } + else // moving left + { + ball[i].x += ball[i].xspeed; + if (ball[i].x < 0) // off the left + { + ball[i].x = 0; + ball[i].xspeed = - ball[i].xspeed; + } + } + if (ball[i].yspeed > 0) // moving down + { + ball[i].y += ball[i].yspeed; + if (ball[i].y > HEIGHT - tileHeight) // off the bottom + { + ball[i].y = HEIGHT - tileHeight; + ball[i].yspeed = - ball[i].yspeed; + } + } + else // moving up + { + ball[i].y += ball[i].yspeed; + if (ball[i].y < 0) // off the top + { + ball[i].y = 0; + ball[i].yspeed = - ball[i].yspeed; + } + } + } + + FX::display(CLEAR_BUFFER); // Using CLEAR_BUFFER will clear the display buffer after it is displayed +} diff --git a/board-package-source/libraries/ArduboyFX/examples/basic-example/basic-example.ino b/board-package-source/libraries/ArduboyFX/examples/basic-example/basic-example.ino index f10f05c..962849d 100644 --- a/board-package-source/libraries/ArduboyFX/examples/basic-example/basic-example.ino +++ b/board-package-source/libraries/ArduboyFX/examples/basic-example/basic-example.ino @@ -1,52 +1,53 @@ -/* ***************************************************************************** - * FX basic example v1.0 by Mr.Blinky May 2021 licenced under CC0 - * ***************************************************************************** - * - * This is a basic example that shows how you can draw a image from FX external - * flash memory. It will draw the Arduboy FX logo and move it around the screen. - * - * This test depend on the file fxdata.bin being uploaded to the external FX flash - * chip using the uploader-gui.py or flash-writer.py Python script in the - * development area. When using the flash writer script. Use the following command: - * - * python flash-writer.py -d fxdata.bin - * - ******************************************************************************/ - -#include // required to build for Arduboy -#include // required to access the FX external flash -#include "fxdata.h" // this file contains all references to FX data - -//constant values -constexpr uint8_t FXlogoWidth = 115; -constexpr uint8_t FXlogoHeight = 16; - -Arduboy2 arduboy; - -//assign values; -int16_t x = (WIDTH - FXlogoWidth) / 2; -int16_t y = 25; -int8_t xDir = 1; -int8_t yDir = 1; - -void setup() { - arduboy.begin(); // normal initialisation with Arduboy startup logo - //arduboy.setFrameRate(60); // Only needed when frameRate != 60 - FX::disableOLED(); // OLED must be disabled before external flash is accessed. OLED display should only be enabled prior updating the display. - FX::begin(FX_DATA_PAGE); // external flash chip may be in power down mode so wake it up (Cathy bootloader puts chip into powerdown mode) -} - -void loop() { - if (!arduboy.nextFrame()) return; // Do nothing until it's time for the next frame - - //program code - FX::drawBitmap(x, y, FXlogo, 0, dbmNormal); - x += xDir; - y += yDir; - if (x == 0 || x == WIDTH - FXlogoWidth) xDir = -xDir; - if (y == 0 || y == HEIGHT - FXlogoHeight) yDir = -yDir; - - FX::enableOLED(); // only enable OLED for updating the display - arduboy.display(CLEAR_BUFFER); // Using CLEAR_BUFFER will clear the display buffer after it is displayed - FX::disableOLED(); // disable display again so external flash can be accessed at any time +/* ***************************************************************************** + * FX basic example v1.02 by Mr.Blinky May 2021 - Feb 2022 licenced under CC0 + * ***************************************************************************** + * + * This is a basic example that shows how you can draw a image from FX external + * flash memory. It will draw the Arduboy FX logo and move it around the screen. + * +* Before this example sketch is uploaded and run on the Arduboy FX, make sure + * the fxdata this sketch has been build and uploaded to the Arduboy FX. + * + * If the Arduboy FX Arduino plugin has been installed you can simply choose the + * 'Build and upload Arduboy FX data' from the Arduino IDE Tools menu. + * + * Alternatively the fxdata.txt script file can be build using the fxdata-build.py + * Phyton script and the fxdata.bin file can be uploaded using the uploader-gui.py, + * fxdata-upload.py or flash-writer.py Python script using the -d switch. + * + ******************************************************************************/ + +#include // required to build for Arduboy +#include // required to access the FX external flash +#include "fxdata/fxdata.h" // this file contains all references to FX data + +//constant values +constexpr uint8_t FXlogoWidth = 115; +constexpr uint8_t FXlogoHeight = 16; + +Arduboy2 arduboy; + +//assign values; +int16_t x = (WIDTH - FXlogoWidth) / 2; +int16_t y = 25; +int8_t xDir = 1; +int8_t yDir = 1; + +void setup() { + arduboy.begin(); // normal initialisation with Arduboy startup logo + //arduboy.setFrameRate(60); // Only needed when frameRate != 60 + FX::begin(FX_DATA_PAGE); // initialise FX chip +} + +void loop() { + if (!arduboy.nextFrame()) return; // Do nothing until it's time for the next frame + + //program code + FX::drawBitmap(x, y, FXlogo, 0, dbmNormal); + x += xDir; + y += yDir; + if (x == 0 || x == WIDTH - FXlogoWidth) xDir = -xDir; + if (y == 0 || y == HEIGHT - FXlogoHeight) yDir = -yDir; + + FX::display(CLEAR_BUFFER); // Using CLEAR_BUFFER will clear the display buffer after it is displayed } diff --git a/board-package-source/libraries/ArduboyFX/examples/basic-example/fxdata.bin b/board-package-source/libraries/ArduboyFX/examples/basic-example/fxdata/fxdata.bin similarity index 100% rename from board-package-source/libraries/ArduboyFX/examples/basic-example/fxdata.bin rename to board-package-source/libraries/ArduboyFX/examples/basic-example/fxdata/fxdata.bin diff --git a/board-package-source/libraries/ArduboyFX/examples/basic-example/fxdata.h b/board-package-source/libraries/ArduboyFX/examples/basic-example/fxdata/fxdata.h similarity index 74% rename from board-package-source/libraries/ArduboyFX/examples/basic-example/fxdata.h rename to board-package-source/libraries/ArduboyFX/examples/basic-example/fxdata/fxdata.h index a8c9646..f3c591c 100644 --- a/board-package-source/libraries/ArduboyFX/examples/basic-example/fxdata.h +++ b/board-package-source/libraries/ArduboyFX/examples/basic-example/fxdata/fxdata.h @@ -1,6 +1,6 @@ #pragma once -/**** FX data header generated by fx-data.py tool version 1.00 ****/ +/**** FX data header generated by fxdata-build.py tool version 1.01 ****/ using uint24_t = __uint24; diff --git a/board-package-source/libraries/ArduboyFX/examples/basic-example/fxdata.txt b/board-package-source/libraries/ArduboyFX/examples/basic-example/fxdata/fxdata.txt similarity index 95% rename from board-package-source/libraries/ArduboyFX/examples/basic-example/fxdata.txt rename to board-package-source/libraries/ArduboyFX/examples/basic-example/fxdata/fxdata.txt index f922a61..1a95bfb 100644 --- a/board-package-source/libraries/ArduboyFX/examples/basic-example/fxdata.txt +++ b/board-package-source/libraries/ArduboyFX/examples/basic-example/fxdata/fxdata.txt @@ -62,4 +62,4 @@ // Arduboy FX logo image: -image_t FXlogo = "assets/FXlogo.png" +image_t FXlogo = "../assets/FXlogo.png" diff --git a/board-package-source/libraries/ArduboyFX/examples/chompies/chompies.ino b/board-package-source/libraries/ArduboyFX/examples/chompies/chompies.ino index 6034578..0103b69 100644 --- a/board-package-source/libraries/ArduboyFX/examples/chompies/chompies.ino +++ b/board-package-source/libraries/ArduboyFX/examples/chompies/chompies.ino @@ -1,15 +1,19 @@ /* ***************************************************************************** - * FX drawBitmap test v1.3 by Mr.Blinky Apr 2019-May 2021 licenced under CC0 + * FX drawBitmap test v1.31 by Mr.Blinky Apr 2019-Feb 2022 licenced under CC0 * ***************************************************************************** * * The map and whale images used in this example were made by 2bitcrook and are * licenced under CC-BY-NC-SA licence. - * This test depend on the file fxdata.bin being uploaded to the external FX flash - * chip using the uploader-gui.py or flash-writer.py Python script in the - * development area. When using the flash writer script. Use the following command: + * Before this example sketch is uploaded and run on the Arduboy FX, make sure + * the fxdata this sketch has been build and uploaded to the Arduboy FX. * - * python flash-writer.py -d fxdata.bin + * If the Arduboy FX Arduino plugin has been installed you can simply choose the + * 'Build and upload Arduboy FX data' from the Arduino IDE Tools menu. + * + * Alternatively the fxdata.txt script file can be build using the fxdata-build.py + * Phyton script and the fxdata.bin file can be uploaded using the uploader-gui.py, + * fxdata-upload.py or flash-writer.py Python script using the -d switch. * * This example uses a 816 by 368 pixel image as background and a * 107 x 69 image for masked sprite. Both can be moved around using the button combos @@ -24,9 +28,9 @@ * ******************************************************************************/ -#include // required to build for Arduboy -#include // required to access the FX external flash -#include "fxdata.h" // this file contains all references to FX data +#include // required to build for Arduboy +#include // required to access the FX external flash +#include "fxdata/fxdata.h" // this file contains all references to FX data #define FRAME_RATE 120 @@ -39,8 +43,7 @@ int y [2]; void setup() { arduboy.begin(); arduboy.setFrameRate(FRAME_RATE); - FX::disableOLED(); // OLED must be disabled before external flash is accessed. OLED display should only be enabled prior updating the display. - FX::begin(FX_DATA_PAGE); //external flash chip may be in power down mode so wake it up (Cathy bootloader puts chip into powerdown mode) + FX::begin(FX_DATA_PAGE); // initialise FX chip } void loop() { @@ -79,7 +82,5 @@ void loop() { arduboy.setCursor(0,8); arduboy.print(y[select]); } - FX::enableOLED(); // only enable OLED for updating the display - arduboy.display(CLEAR_BUFFER); // Using CLEAR_BUFFER will clear the display buffer after it is displayed - FX::disableOLED(); // disable display again so external flash can be accessed at any time + FX::display(CLEAR_BUFFER); // Using CLEAR_BUFFER will clear the display buffer after it is displayed } diff --git a/board-package-source/libraries/ArduboyFX/examples/chompies/fxdata.bin b/board-package-source/libraries/ArduboyFX/examples/chompies/fxdata/fxdata.bin similarity index 100% rename from board-package-source/libraries/ArduboyFX/examples/chompies/fxdata.bin rename to board-package-source/libraries/ArduboyFX/examples/chompies/fxdata/fxdata.bin diff --git a/board-package-source/libraries/ArduboyFX/examples/chompies/fxdata.h b/board-package-source/libraries/ArduboyFX/examples/chompies/fxdata/fxdata.h similarity index 76% rename from board-package-source/libraries/ArduboyFX/examples/chompies/fxdata.h rename to board-package-source/libraries/ArduboyFX/examples/chompies/fxdata/fxdata.h index eac1377..c995ceb 100644 --- a/board-package-source/libraries/ArduboyFX/examples/chompies/fxdata.h +++ b/board-package-source/libraries/ArduboyFX/examples/chompies/fxdata/fxdata.h @@ -1,6 +1,6 @@ #pragma once -/**** FX data header generated by fx-data.py tool version 1.00 ****/ +/**** FX data header generated by fxdata-build.py tool version 1.01 ****/ using uint24_t = __uint24; diff --git a/board-package-source/libraries/ArduboyFX/examples/chompies/fxdata.txt b/board-package-source/libraries/ArduboyFX/examples/chompies/fxdata/fxdata.txt similarity index 93% rename from board-package-source/libraries/ArduboyFX/examples/chompies/fxdata.txt rename to board-package-source/libraries/ArduboyFX/examples/chompies/fxdata/fxdata.txt index a56e68d..ab1ccf8 100644 --- a/board-package-source/libraries/ArduboyFX/examples/chompies/fxdata.txt +++ b/board-package-source/libraries/ArduboyFX/examples/chompies/fxdata/fxdata.txt @@ -62,8 +62,8 @@ // A large map background image: -image_t map = "assets/map.png" +image_t mapGfx = "../assets/map.png" // chompies masked sprite image: -image_t whale = "assets/whale.png" +image_t whaleGfx = "../assets/whale.png" diff --git a/board-package-source/libraries/ArduboyFX/examples/drawballs/assets/tiles_16x16.png b/board-package-source/libraries/ArduboyFX/examples/drawballs/assets/tiles_16x16.png index b857549ccfd039a2b396b1050c99e0d44df78b3a..2a3e8e95f4a139c88571d075fbbc3893397ee5f8 100644 GIT binary patch delta 186 zcmV;r07d`Z0sH}w83+ad000|__{@|+PR1p)NEY@U;;%ON8RIV>cBV8a&Qo3=OBYR$f6Fi+~c6a^Ctp+ oUZEkLtt;P+<WrLP&HRDF%R!xyQ>&S2+N1#c7~~oVR%c*qyyGKwU!PF0 zwG9elFQ8y+8x$x|pkx#%d@bl+4*Xovr2*#rR5Jse5gyUn4FKKEPbJQPfdBvi00>D% JPDHLkV1m*7LZJWv diff --git a/board-package-source/libraries/ArduboyFX/examples/drawballs/drawballs.ino b/board-package-source/libraries/ArduboyFX/examples/drawballs/drawballs.ino index ef398da..f1b62db 100644 --- a/board-package-source/libraries/ArduboyFX/examples/drawballs/drawballs.ino +++ b/board-package-source/libraries/ArduboyFX/examples/drawballs/drawballs.ino @@ -1,12 +1,16 @@ /* ***************************************************************************** - * FX draw balls test v1.15 by Mr.Blinky May 2019 May2021 licenced under CC0 + * FX draw balls test v1.16 by Mr.Blinky May 2019 Feb 2022 licenced under CC0 * ***************************************************************************** * - * This test depend on the file fxdata.bin being uploaded to the external FX flash - * chip using the uploader-gui.py or flash-writer.py Python script in the - * development area. When using the flash writer script. Use the following command: + * Before this example sketch is uploaded and run on the Arduboy FX, make sure + * the fxdata this sketch has been build and uploaded to the Arduboy FX. * - * python flash-writer.py -d fxdata.bin + * If the Arduboy FX Arduino plugin has been installed you can simply choose the + * 'Build and upload Arduboy FX data' from the Arduino IDE Tools menu. + * + * Alternatively the fxdata.txt script file can be build using the fxdata-build.py + * Phyton script and the fxdata.bin file can be uploaded using the uploader-gui.py, + * fxdata-upload.py or flash-writer.py Python script using the -d switch. * * This demo draws a moving background tilemap with a bunch of bouncing ball sprites around * @@ -21,7 +25,7 @@ #include #include // Required library for accessing the FX flash chip -#include "fxdata.h" // this file contains all the references to FX data +#include "fxdata/fxdata.h" // this file contains all the references to FX data // Check out fxdata.txt to see how this is done. #define FRAME_RATE 60 @@ -68,8 +72,7 @@ uint8_t pos; void setup() { arduboy.begin(); arduboy.setFrameRate(FRAME_RATE); - FX::disableOLED(); // OLED must be disabled before cart can be used. OLED display should only be enabled prior updating the display. - FX::begin(FX_DATA_PAGE); // wakeup external flash chip, initialize datapage, detect presence of external flash chip + FX::begin(FX_DATA_PAGE); // // initialise FX chip for (uint8_t i=0; i < MAX_BALLS; i++) // initialize ball sprites { @@ -172,7 +175,5 @@ void loop() { } } - FX::enableOLED();// only enable OLED for updating the display - arduboy.display(CLEAR_BUFFER); // Using CLEAR_BUFFER will clear the display buffer after it is displayed - FX::disableOLED();// disable display again so external flash can be accessed at any time + FX::display(CLEAR_BUFFER); // Using CLEAR_BUFFER will clear the display buffer after it is displayed } diff --git a/board-package-source/libraries/ArduboyFX/examples/drawballs/fxdata.bin b/board-package-source/libraries/ArduboyFX/examples/drawballs/fxdata/fxdata.bin similarity index 100% rename from board-package-source/libraries/ArduboyFX/examples/drawballs/fxdata.bin rename to board-package-source/libraries/ArduboyFX/examples/drawballs/fxdata/fxdata.bin diff --git a/board-package-source/libraries/ArduboyFX/examples/drawballs/fxdata.h b/board-package-source/libraries/ArduboyFX/examples/drawballs/fxdata/fxdata.h similarity index 79% rename from board-package-source/libraries/ArduboyFX/examples/drawballs/fxdata.h rename to board-package-source/libraries/ArduboyFX/examples/drawballs/fxdata/fxdata.h index 4a57231..91b773e 100644 --- a/board-package-source/libraries/ArduboyFX/examples/drawballs/fxdata.h +++ b/board-package-source/libraries/ArduboyFX/examples/drawballs/fxdata/fxdata.h @@ -1,6 +1,6 @@ #pragma once -/**** FX data header generated by fx-data.py tool version 1.00 ****/ +/**** FX data header generated by fxdata-build.py tool version 1.01 ****/ using uint24_t = __uint24; diff --git a/board-package-source/libraries/ArduboyFX/examples/drawballs/fxdata.txt b/board-package-source/libraries/ArduboyFX/examples/drawballs/fxdata/fxdata.txt similarity index 93% rename from board-package-source/libraries/ArduboyFX/examples/drawballs/fxdata.txt rename to board-package-source/libraries/ArduboyFX/examples/drawballs/fxdata/fxdata.txt index 64bb6f9..d0f8209 100644 --- a/board-package-source/libraries/ArduboyFX/examples/drawballs/fxdata.txt +++ b/board-package-source/libraries/ArduboyFX/examples/drawballs/fxdata/fxdata.txt @@ -62,7 +62,7 @@ // Background tiles graphics -image_t FX_DATA_TILES = "assets/tiles_16x16.png" +image_t FX_DATA_TILES = "../assets/tiles_16x16.png" // 16 x 16 tilemap @@ -93,5 +93,5 @@ uint8_t FX_DATA_TILEMAP[] = { // masked ball sprite graphics -image_t FX_DATA_BALLS = "assets/ball.png" -//image_t FX_DATA_BALLS = "assets/ball_16x16.png" +image_t FX_DATA_BALLS = "../assets//ball.png" +//image_t FX_DATA_BALLS = "../assets/ball_16x16.png" diff --git a/board-package-source/libraries/ArduboyFX/library.properties b/board-package-source/libraries/ArduboyFX/library.properties index e27f607..7655a90 100644 --- a/board-package-source/libraries/ArduboyFX/library.properties +++ b/board-package-source/libraries/ArduboyFX/library.properties @@ -1,5 +1,5 @@ name=ArduboyFX -version=1.0.0 +version=1.0.1 author=Mr.Blinky maintainer=mstr.blinky@gmail.com sentence=The Arduboy FX library. diff --git a/board-package-source/libraries/ArduboyFX/src/ArduboyFX.cpp b/board-package-source/libraries/ArduboyFX/src/ArduboyFX.cpp index 2db325c..10a9204 100644 --- a/board-package-source/libraries/ArduboyFX/src/ArduboyFX.cpp +++ b/board-package-source/libraries/ArduboyFX/src/ArduboyFX.cpp @@ -20,12 +20,14 @@ uint8_t FX::readByte() void FX::begin() { + disableOLED(); wakeUp(); } void FX::begin(uint16_t developmentDataPage) { + disableOLED(); if (pgm_read_word(FX_DATA_VECTOR_KEY_POINTER) == FX_VECTOR_KEY_VALUE) { programDataPage = (pgm_read_byte(FX_DATA_VECTOR_PAGE_POINTER) << 8) | pgm_read_byte(FX_DATA_VECTOR_PAGE_POINTER + 1); @@ -40,6 +42,7 @@ void FX::begin(uint16_t developmentDataPage) void FX::begin(uint16_t developmentDataPage, uint16_t developmentSavePage) { + disableOLED(); if (pgm_read_word(FX_DATA_VECTOR_KEY_POINTER) == FX_VECTOR_KEY_VALUE) { programDataPage = (pgm_read_byte(FX_DATA_VECTOR_PAGE_POINTER) << 8) | pgm_read_byte(FX_DATA_VECTOR_PAGE_POINTER + 1); @@ -85,7 +88,7 @@ void FX::noFXReboot() { if (*(uint8_t *)&timer0_millis & 0x80) bitSet(PORTB, RED_LED_BIT); else bitClear(PORTB, RED_LED_BIT); - } + } while (bitRead(DOWN_BUTTON_PORTIN, DOWN_BUTTON_BIT)); // wait for DOWN button to enter bootloader Arduboy2Core::exitToBootloader(); } @@ -170,7 +173,7 @@ void FX::seekDataArray(uint24_t address, uint8_t index, uint8_t offset, uint8_t address += size ? index * size + offset : index * 256 + offset; #endif seekData(address); -} +} void FX::seekSave(uint24_t address) @@ -559,7 +562,7 @@ void FX::drawBitmap(int16_t x, int16_t y, uint24_t address, uint8_t frame, uint8 " st %a[buffer], %B[bitmap] \n" "5: ;render_next: \n" " clr r1 \n" // restore zero reg - " subi %A[buffer], lo8(%[displaywidth]-1) \n" + " subi %A[buffer], lo8(%[displaywidth]-1) \n" " sbci %B[buffer], hi8(%[displaywidth]-1) \n" " dec r25 \n" " brne 2b ;render_column \n" // for (c < renderheigt) loop @@ -574,7 +577,7 @@ void FX::drawBitmap(int16_t x, int16_t y, uint24_t address, uint8_t frame, uint8 " sbi %[fxport], %[fxbit] \n" // disable external flash " cp r1, %[renderheight] \n" // while (renderheight > 0) " brge .+2 \n" - " rjmp 1b ;render_row \n" + " rjmp 1b ;render_row \n" : [address] "+r" (address), [mode] "+r" (mode), @@ -588,7 +591,7 @@ void FX::drawBitmap(int16_t x, int16_t y, uint24_t address, uint8_t frame, uint8 [yshift] "r" (yshift), [renderwidth] "r" (renderwidth), [buffer] "e" (Arduboy2Base::sBuffer + displayoffset), - + [fxport] "I" (_SFR_IO_ADDR(FX_PORT)), [fxbit] "I" (FX_BIT), [cmd] "I" (SFC_READ), @@ -700,10 +703,10 @@ void FX::displayPrefetch(uint24_t address, uint8_t* target, uint16_t len, bool c { seekData(address); asm volatile - ( "dbg:\n" + ( " ldi r30, lo8(%[sbuf]) \n" // uint8_t* ptr = Arduboy2::sBuffer; " ldi r31, hi8(%[sbuf]) \n" - " ldi r25, hi8(%[end]) \n" + " ldi r25, hi8(%[end]) \n" " in r0, %[spsr] \n" // wait(); //for 1st target data recieved (can't enable OLED mid transfer) " sbrs r0, %[spif] \n" " rjmp .-6 \n" @@ -723,7 +726,7 @@ void FX::displayPrefetch(uint24_t address, uint8_t* target, uint16_t len, bool c "2: \n" " cpi r30, lo8(%[end]) ;1 \ \n" // if (ptr >= Arduboy2::sBuffer + WIDTH * HEIGHT / 8) break; " cpc r31, r25 ;1 \n" - " brcs 1b ;1-2/4 \n" // } + " brcs 1b ;1-2/4 \n" // } "3: \n" " brmi 2b ;1-2 \n" // branch only when coming from above brmi : [target] "+e" (target), @@ -742,3 +745,17 @@ void FX::displayPrefetch(uint24_t address, uint8_t* target, uint16_t len, bool c disable(); SPSR; } + +void FX::display() +{ + enableOLED(); + Arduboy2Base::display(); + disableOLED(); +} + +void FX::display(bool clear) +{ + enableOLED(); + Arduboy2Base::display(clear); + disableOLED(); +} diff --git a/board-package-source/libraries/ArduboyFX/src/ArduboyFX.h b/board-package-source/libraries/ArduboyFX/src/ArduboyFX.h index 76a62d5..e8c8ab1 100644 --- a/board-package-source/libraries/ArduboyFX/src/ArduboyFX.h +++ b/board-package-source/libraries/ArduboyFX/src/ArduboyFX.h @@ -123,10 +123,14 @@ class FX SPDR = data; } - static uint8_t readByte(); //read a single byte from flash memory + static uint8_t readByte(); // read a single byte from flash memory static void displayPrefetch(uint24_t address, uint8_t* target, uint16_t len, bool clear); + static void display(); // display screen buffer + + static void display(bool clear); // display screen buffer with clear + static void begin(); // Initializes flash memory. Use only when program does not require data and save areas in flash memory static void begin(uint16_t programDataPage); // Initializes flash memory. Use when program depends on data in flash memory