Skip to main content

Tutorial

From a checkout to your own app making sound on the unit. You need Linux (x86-64), the unit with Hako installed (Install), and a USB cable.

1. The compiler​

Hako builds with GCC 15 for the C6000, with one patch to its code generator (without it GCC 15 builds some loops wrong, silently). The script downloads the sources, patches and builds them into third_party/tic6x, in about an hour:

git clone https://github.com/chalkwalk/hako && cd hako
sudo apt install build-essential libgmp-dev libmpfr-dev libmpc-dev texinfo python3-numpy
toolchain/build-gcc-tic6x.sh

HAKO_GCC=/somewhere/else points the build at a compiler kept elsewhere.

2. Build, and run from RAM​

make                                    # the launcher and the examples, in work/apps/
make test # the host tests: the last line says ALL PASS
tools/bin/hako run work/apps/hello/APP.BIN

With the launcher's menu showing (or any SDK app running), hako run sends the app over USB MIDI and it starts. Nothing is written to the unit: the next power-on starts the default app as before. Put tools/bin on your PATH to type just hako.

hako screen text                        # the app's console rows
hako press OK # a button pressed from the computer
hako screen shot hello.png

Press keys on the unit: 01-hello shows each event. Three quick clicks of the power button go back to the menu.

3. The loop​

Open examples/01-hello/main.c. Every app has the same shape:

#include "app.h"

int main(void)
{
app_begin(); /* the board, the screen, the controls, USB */
for (;;) {
controls_scan(); /* one row of the key matrix */
app_service(); /* USB, the power button, the watchdog: every few ms */
/* your work */
}
}

Change the greeting, then:

make && hako run work/apps/hello/APP.BIN

It replaces the running app in a second or two. That is the whole loop: edit, make, hako run.

4. Sound​

examples/02-tone adds audio. The codec runs in blocks of 64 frames (1.33 ms at 48 kHz):

for (;;) {
int32_t *out = audio_block(); /* waits until the next block may be filled */
for (i = 0; i < BLOCK_FRAMES; i++)
out[2 * i] = out[2 * i + 1] = next_sample(); /* left, right */
audio_done();
controls_scan();
app_service();
con_update(3); /* draw a few characters a block, never a whole screen */
}

Everything in the loop shares the time between blocks, so keep it short. Run it, press OK, turn TYPE. Then work through 03-midi (USB MIDI), 04-files (the app's own folder on the disk) and 05-usbhost (a MIDI keyboard or a stick in the unit's port).

5. Test it​

hako test runs a script that drives the unit and checks what it shows:

from hako.testing import connect

u = connect()
u.run("work/apps/hello/APP.BIN")
u.expect("press anything", row=0)
u.press("OK")
u.expect(r"button (down|up)\s+15", row=1)
hako test tests/unit/01-hello.py        # ALL PASS
hako film tests/unit/01-hello.py hello.mp4 # the same, filmed: the screen and the steps

6. Your own app​

cp -r examples/06-template examples/07-mine
make && hako run work/apps/mine/APP.BIN

The number orders the examples; the app's name is the part after it. When it's ready, install it into its own folder on the unit's disk, where the launcher lists it:

hako install work/apps/mine/APP.BIN --as MINE.APP       # MINE/MINE.APP
hako open MINE # start it, as if picked in the menu

Read sdk/app.h's opening comment next: it is the contract every app keeps. The SDK page says what each header does.