PicoCalc Text Starter (C/C++)

I need to set my ANS Forth implementation aside since I believe I have made some bad design decisions and it needs to rest whilst I think about it.

However, I didn’t want some of the work I did to languish in obscurity, so I have taken what I can from that project, and added some additional things to create a PicoCalc Starter Kit for those that want to use develop for the PicoCalc using C/C++ on the bare metal using the Pico-Series C/C++ SDK.

Now, this is not designed to create graphical games as the display driver does not use a frame buffer and is text-based, but it does use very little memory. So you could create text-based games.

I have drivers for:

  • Audio (stereo)
  • Display (multicolour text with ANSI escape code emulation)
  • Keyboard
  • Pico onboard LED (WIFI-option aware)
  • Serial port
  • Southbridge functions (battery, backlights)

And these are not best-of-breed drivers either, this is something to get you going fast and you can then enhance/replace components as you need. The drivers have simple APIs, and they should be able to work independently, so you can pick and choose, or perhaps I can pass some hard-earned knowledge along.

The README explains it all.

I am currently working on FAT32 support on the “sdcard” branch.

8 Likes

Thanks for project, it helps develop firmwares more easily.

1 Like

Very good project

in case if anyone try to run this on pico1 like ,here is the diff

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c1bbe7b..aac107a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -23,7 +23,7 @@ if (EXISTS ${picoVscode})
     include(${picoVscode})
 endif()
 # ====================================================================================
-set(PICO_BOARD pico2_w CACHE STRING "Board type")
+#set(PICO_BOARD pico2_w CACHE STRING "Board type")
 
 # Pull in Raspberry Pi Pico SDK (must be before project)
 include(pico_sdk_import.cmake)
diff --git a/drivers/onboard_led.c b/drivers/onboard_led.c
index 7d77e0b..faa49db 100644
--- a/drivers/onboard_led.c
+++ b/drivers/onboard_led.c
@@ -6,7 +6,8 @@
 //
 
 #ifndef PICO_DEFAULT_LED_PIN
-#include "pico/cyw43_arch.h"
+//#include "pico/cyw43_arch.h"
+#define PICO_DEFAULT_LED_PIN 25
 #endif
 
 #include "onboard_led.h"

My bad! Thank you @guu.

I have changed the default board to “pico”, as it should have been from the start, and added a missing include which broke the build for non-wireless Pico’s.

I have implemented read functionality (the easy part) for FAT32-formatted SD cards. In this update:

  • Open and read from files and directories
  • Long filenames are supported
  • Absolute and relative paths
  • Change and retrieve your current directory
  • Supports both SDSC (standard capacity) and SDHC (high capacity) cards
  • Can read the MBR-partitioned disk layout (not GPT) and the unpartitioned disk layout
  • Documentation updated to include new functionality

I have started to create compiled “releases” with a selection of uf2 files for the Pico boards to demonstrate the starter.

@BlairLeduc I was wondering, so In my OS kernel, I would like to initialize the display and keyboard, but nothing else, as everything else will be initialized when needed, and I was wondering how I could do that.

there is full implementation of an “OS” example on the officical Fuzix repo(https://github.com/clockworkpi/PicoCalc/tree/master/Code/FUZIX)

why not just try to study it first?

what you ask is huge question rather than something can answer via “community reply”

1 Like

Looks like you figured it out?

Yeah, I did, it was simpler than I thought.

1 Like

I released v0.3 today:

Adds the ability to write to an SD card formatted with the FAT32 file system.

  • Write to a file
  • Remove a file or directory

This update always uses long filenames for files and directories to maintain case and special characters.

The auto-mount/unmount is more reliable now.

Adds additional tests for FAT32 and the keyboard.

The compiled UF2 files for this release:

1 Like

The PicoCalc-text-starter feature set is complete now.

I am still maintaining it for enhancements and bug reports/fixes.

I am moving on to my next PicoCalc project!

1 Like

How do you implement renaming files with long file names? I have been hesitant to implement LFN’s in zeptoforth because it would make renaming files far too complex because LFN’s of course live as arbitrary numbers of contiguous dummy directory entries.

As I just went through this myself, your hesitation is well founded!

Also, this being a starter library vs a language people depend upon gives me a pass on a lot of things.

With that, I left renaming files as out-of-scope for this library, mainly because I forgot about it.

However, if I were to add that feature, I would implement it as a move instead and free the directory entry, that would include the LFN’s, and create new entry with the new name in the possibility changed directory.

To be safe in a multithreaded system, you might do that the other way around. Also, depending how you do the equivalent of FILE *, it will be safe, since you are not moving the cluster layout, any open files will not be impacted.

One cautionary note, LFN entries can cross sector and cluster boundaries adding to the fun.

Small release today, v0.4:

  • Add underscore and bold text
  • Connected the standard C library file operations (fopen, fread, etc) to the fat32 driver
1 Like

Another release today, v0.5:

  • Corrected a problem preventing the Pico 1 from initialising SD cards
  • Recognise key on pressed state, key repeat
  • Update enhances file handling
    • Now correct reports errors with errno for file operations
3 Likes

This is beautiful (I wish I understood how to make stuff like this)

1 Like

The difference between the possible and the impossible is merely a measure of one’s determination.
— Captain James Thain

1 Like

Well, my determination is more hardware side vs software. I’m currently knee deep in designing a PCB for my GPIO expander board something that not a whole lot of people know how to do.

And I am very much looking forward to seeing more about what you are working towards.

I squeezed in another release today, v0.6:

  • Added ability to move/rename files
  • Now updating the FSInfo structure that caches free space and where to start looking for free clusters
  • Renamed FAT32 API functions for consistency by removing redundant file_ and dir_ prefixes
  • Added stat, link, unlink and rename support to the standard C library, corrected fstat
  • Various stabilisation and bug fixes
2 Likes