Kode Dot
Tarjeta microSD
Lee y escribe archivos en una tarjeta microSD desde tu app y mira cómo está conectada la ranura.
Qué es
En la tarjeta microSD tu app guarda y lee sus archivos, como grabaciones, registros o imágenes. KodeOS también la usa para tus apps, porque guarda en ella una copia de cada app que instalas. Así, cuando una app nueva no cabe en el Kode Dot, quita una que ya tiene su copia, que sigue en tus apps y se vuelve a instalar al abrirla. Las apps que copias tú a la microSD salen en la misma lista. El detalle está en KodeOS.
Tu app accede a cada archivo por su ruta con las llamadas kode_file_* de
kode.h, como kode_file_write o kode_file_read. Las rutas que empiezan por
sd/ son de la tarjeta y las que empiezan por flash/ van a la memoria
interna del Kode Dot. De encender y montar la tarjeta se encarga KodeOS, así que tu app nunca toca
los pines.

Por dentro
La tarjeta va directa al P4 por seis líneas, de GPIO39 a GPIO44, en el orden
D0, D1, D2, D3, CLK y CMD. El P4 también decide si la tarjeta tiene corriente.
Con GPIO22 a 0 V, un interruptor le da los 3,3 V. La línea que avisa de si hay
tarjeta va al C5, el chip de la radio.

Cuando enciendes o apagas el Wi-Fi o el Bluetooth, la tarjeta deja de estar disponible un momento.
El circuito completo está en el esquema de la placa principal.
Especificaciones
"sd/..." o "flash/...", sin / al principio y sin //, . ni ...kode_file_list devuelve hasta 24 (KODE_FILE_LIST_MAX). Si la carpeta tiene más, kode_file_list_from sigue a partir de la entrada que le indiques.flash/. Está siempre, haya tarjeta o no.Las llamadas son las kode_file_* de kode.h, para leer, escribir, listar,
borrar y mover archivos y carpetas. La lista completa está en
la API del SDK.
Errores comunes
kode_error() dice «the volume is not there or the call failed». Basta con volver a intentarlo un poco después.kode_file_create_folder, de una en una.Apps que lo usan
SD ReaderYour Kode becomes a USB card reader. Plug it into a computer and the microSD inside shows up as a disk: copy, delete or format, like any card reader. What you need - A Kode Dot - A microSD card in its slot - A USB-C cable to your computer, or the Kode charging base plugged into it What it does - The card is the screen: its real size and how full it is, read from the card - A live MB/s ring while the computer reads or writes - A Read only switch: turn it on and the computer can look at the card but never write to it - Fast eject: back to the Kode in under a second, and a warning if the cable was pulled while it was still writing - Remembers each card, so the next time it connects at once - Cable or charging base: it finds the one that goes to the computer by itself - The BLUE button connects and disconnects
OfficeRead Word, Excel and PowerPoint files straight from the microSD card: .docx documents, .xlsx sheets and .pptx slides, with the look of the first office apps. Copy your files into the Office folder of the card; three examples are written the first time you open it.
RecorderVoice notes in your pocket. Tap Record, talk, tap Stop: every take goes to the microSD as a WAV you can copy to any computer. - Swipe or use the pad to switch between Record and your Recordings - Tap a recording to play it back, with the progress running around the screen - Up to 2 minutes per take Needs a microSD card in the Dot.Código de ejemplo
Mete una tarjeta y ejecuta el programa, que escribe una línea en un archivo, la vuelve a leer e imprime cuánto espacio tiene la tarjeta. Si no hay tarjeta, la escritura falla y el programa imprime el motivo.
/* SPDX-License-Identifier: GPL-3.0-or-later */
/**
* @file storage_roundtrip.c
* @brief Writes a line to the microSD card of the Kode Dot, reads it back and prints it.
*
* Then it prints how much space the card has left. Insert a card first.
* "sd" is the card and "flash" is the Kode Dot's own storage.
*
* from Kode with love
*/
#include "kode.h"
#define HELLO_PATH "sd/hello.txt" /**< The file, on the microSD card. */
#define BYTES_PER_KB 1024U /**< Bytes in one KB. */
/** @brief Start the system, write, read back and report the free space. */
void app_main(void)
{
kode_init();
kode_print("Running: writing to the microSD card");
if ( !kode_file_write(HELLO_PATH, "hello from the Kode Dot\n") )
{
kode_print("write failed: %s", kode_error());
return;
}
kode_print("read back: %s", kode_file_read(HELLO_PATH));
uint64_t total = 0U;
uint64_t left = 0U;
if ( kode_file_space("sd", &total, &left) )
{
kode_print("card: %llu KB free of %llu KB",
(unsigned long long)(left / BYTES_PER_KB), (unsigned long long)(total / BYTES_PER_KB));
}
kode_print("Done");
}Si prefieres compilarlo tú, sigue los pasos comunes a todos los ejemplos.
En el SDK
kdrv/storage: la tarjeta y la memoria interna enkode-sdk, descritas en el driver de almacenamiento.examples/storage: un ejemplo del SDK con las mismas llamadas.