Adafruit_CPFS compatibility (example included)
This commit is contained in:
parent
971b104f04
commit
40fdf7a97f
4 changed files with 97 additions and 4 deletions
72
examples/file_access/file_access.ino
Normal file
72
examples/file_access/file_access.ino
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
This example shows how to use PicoDVI and a board's flash filesystem (i.e.
|
||||
CIRCUITPY drive) simultaneously. This can be useful for loading graphics
|
||||
files, saving game state in emulators, etc. To keep this simple, it's just
|
||||
a mash-up of the existing PicoDVI '1bit_text' and Adafruit_CPFS 'simple'
|
||||
examples, but the same principles certainly apply to other modes.
|
||||
|
||||
To start, you first need to temporarily install CircuitPython on the board
|
||||
to initialize the flash filesystem, which can then be loaded up with the
|
||||
files you need. https://circuitpython.org/downloads
|
||||
With the filesystem prepared, one can then work with the Arduino code...
|
||||
|
||||
SUPER IMPORTANT: you MUST have current versions of several libraries and
|
||||
the Earle Philhower arduino-pico core installed. Failure to have all the
|
||||
right pieces will wipe out any data stored on the drive!
|
||||
|
||||
arduino-pico (via Arduino board manager) 3.3.0 or later
|
||||
Adafruit_CPFS (via Library manager) 1.0.1 or later
|
||||
Adafruit_SPIFlash (") 4.2.0 or later
|
||||
|
||||
That said, it's still a smart idea to keep a backup of any data you install
|
||||
on the board. These libraries combined are asking a LOT of the RP2040 chip,
|
||||
it's always possible there may be some hiccup and you'll have ot start over
|
||||
with the CircuitPython install and drive setup.
|
||||
*/
|
||||
|
||||
#include <PicoDVI.h> // For DVI video out
|
||||
#include <Adafruit_CPFS.h> // For accessing the CIRCUITPY drive
|
||||
|
||||
FatVolume *fs = NULL; // CIRCUITPY flash filesystem, as a FAT pointer
|
||||
|
||||
// This example uses 80x30 monochrome text mode. See other PicoDVI examples
|
||||
// for color, bitmapped graphics, widescreen, alternate boards, etc.
|
||||
DVItext1 display(DVI_RES_640x240p60, adafruit_feather_dvi_cfg);
|
||||
|
||||
void setup() { // Runs once on startup
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
|
||||
// Start the CIRCUITPY flash filesystem. SUPER IMPORTANT: NOTICE THE
|
||||
// EXTRA PARAMETERS HERE. This is REQUIRED when using PicoDVI and
|
||||
// Adafruit_CPFS together.
|
||||
fs = Adafruit_CPFS::begin(-1, NULL, false);
|
||||
|
||||
if (!display.begin()) { // Start DVI, slow blink LED if insufficient RAM
|
||||
for (;;) digitalWrite(LED_BUILTIN, (millis() / 500) & 1);
|
||||
}
|
||||
|
||||
if (fs == NULL) { // If CIRCUITPY filesystem is missing or malformed...
|
||||
// Show error message & fast blink LED to indicate problem. Full stop.
|
||||
display.println("Can't access board's CIRCUITPY drive.");
|
||||
display.println("Has CircuitPython been previously installed?");
|
||||
for (;;) digitalWrite(LED_BUILTIN, (millis() / 250) & 1);
|
||||
} // else valid CIRCUITPY drive, proceed...
|
||||
|
||||
// As in Adafruit_CPFS 'simple' example, allow USB events to settle...
|
||||
delay(2500);
|
||||
Adafruit_CPFS::change_ack();
|
||||
|
||||
// Then access files and directories using any SdFat calls (open(), etc.)
|
||||
|
||||
// Because fs is a pointer, we use "->" indirection rather than "." access.
|
||||
// display pointer is cast to print_t so ls() treats it just like Serial.
|
||||
fs->ls((print_t *)&display, LS_R | LS_SIZE); // List initial drive contents
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (Adafruit_CPFS::changed()) { // Anything changed on CIRCUITPY drive?
|
||||
Adafruit_CPFS::change_ack(); // Got it, thanks.
|
||||
display.println("CIRCUITPY drive contents changed.");
|
||||
fs->ls((print_t *)&display, LS_R | LS_SIZE); // List updated drive contents
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
name=PicoDVI - Adafruit Fork
|
||||
version=1.0.7
|
||||
version=1.1.0
|
||||
author=Luke Wren (Wren6991)
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=Arduino library for RP2040 DVI output, based on PicoDVI
|
||||
|
|
@ -7,4 +7,4 @@ paragraph=Arduino library for RP2040 DVI output, based on PicoDVI
|
|||
category=Display
|
||||
url=https://github.com/adafruit/PicoDVI
|
||||
architectures=rp2040
|
||||
depends=Adafruit GFX Library
|
||||
depends=Adafruit GFX Library, Adafruit CPFS
|
||||
|
|
|
|||
|
|
@ -54,6 +54,27 @@ void PicoDVI::_setup(void) {
|
|||
; // Wait for DVIGFX*::begin() to set this
|
||||
dvi_register_irqs_this_core(&dvi0, DMA_IRQ_0);
|
||||
dvi_start(&dvi0);
|
||||
|
||||
// This is disabled for now, for a transitional period while folks
|
||||
// might be mixing in older versions of arduino-pico, Adafruit_CPFS
|
||||
// and/or Adafruit_SPIFlash. Once is seems pretty solid that everyone's
|
||||
// using current versions that correctly locate PicoDVI functions in
|
||||
// RAM, this can be activated. Not urgent but a nice-to-have.
|
||||
#if 0
|
||||
// Borrowed from CircuitPython: turn off core 1 flash access. Any attempt
|
||||
// after this will hard fault (not good, but preferable to the alternative
|
||||
// which would corrupt the CIRCUITPY flash filesystem if mounted). Linker
|
||||
// file MUST place the following files in RAM or library won't work:
|
||||
// *interp.c.obj *divider.S.obj *PicoDVI.cpp.o *dvi.c.o
|
||||
// (Earle Philhower arduino-pico >= 3.3.0 does this now.)
|
||||
MPU->CTRL = MPU_CTRL_PRIVDEFENA_Msk | MPU_CTRL_ENABLE_Msk;
|
||||
MPU->RNR = 6;
|
||||
MPU->RBAR = XIP_MAIN_BASE | MPU_RBAR_VALID_Msk;
|
||||
MPU->RASR = MPU_RASR_XN_Msk | MPU_RASR_ENABLE_Msk |
|
||||
(0x1b << MPU_RASR_SIZE_Pos);
|
||||
MPU->RNR = 7;
|
||||
#endif
|
||||
|
||||
(*mainloop)(&dvi0);
|
||||
}
|
||||
|
||||
|
|
@ -384,7 +405,7 @@ static void mainlooptext1(struct dvi_inst *inst) {
|
|||
// This is a little simpler and might stick with it
|
||||
// since nothing important to do in idle func above.
|
||||
|
||||
static void mainlooptext1(struct dvi_inst *inst) {
|
||||
static void __not_in_flash_func(mainlooptext1)(struct dvi_inst *inst) {
|
||||
((DVItext1 *)gfxptr)->_mainloop();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
// so all the row 0 bytes for each of 256 chars appear first, then all row 1
|
||||
// bytes for each, row 2, etc. Individual character data is not contiguous.
|
||||
|
||||
uint8_t font_8x8[] = {
|
||||
uint8_t __not_in_flash_func(font_8x8)[] = {
|
||||
0x00, 0x7E, 0x7E, 0x6C, 0x10, 0x38, 0x10, 0x00, 0xFF, 0x00, 0xFF, 0x0F,
|
||||
0x3C, 0x3F, 0x7F, 0x99, 0x80, 0x02, 0x18, 0x66, 0x7F, 0x3E, 0x00, 0x18,
|
||||
0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x6C, 0x6C,
|
||||
|
|
|
|||
Loading…
Reference in a new issue