Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions LICENSING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ The USB audio from a computer in `platform/src/usb.c` (`FOMA_USB_AUDIO`) is port
it be used under GPL-3.0; foma's version uses integer math. The TRS MIDI input (`platform/src/midi_uart.c`,
`platform/hal/fm1_uart.h`) is Felucca's.

`platform/mvave` (the `"mvave"` platform) is from M-VAVE's [fm1_open](https://github.com/m-vave/fm1_open)
(commit in `platform/mvave/sdk/VERSION`): `board/`, `sdk/include`, `sdk/config` and the boot resources are GPLv3 with
M-VAVE's FM1 SDK linking exception or Apache-2.0, `sdk/lib/libfm1_engine.a` is M-VAVE's binary SDK under its own
terms (FM-1 devices only), as `platform/mvave/LICENSE.md` and `platform/mvave/THIRD_PARTY.md` say. `port.c`, `sdk.c`
and `bridge.h` are foma's; `tools/mvpack.py` is a Python port of fm1_open's `sdk/Package.cs` (MIT, kagaimiq and
M-VAVE).

## Third-party material

| What | Licence | Where |
Expand Down
39 changes: 35 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,45 @@ turning one off takes its code and memory out of the firmware:
| `usb_audio` | A computer or tablet can pick the FM-1 as a 44.1 kHz stereo output. `audio_in()` gives `audio()` that sound: play it, process it, record it. | 10 KiB RAM |
| `trs_midi` | MIDI in on the 3.5 mm TRS jack (a TRS-to-DIN adapter for most gear), through `midi_read()`, which says where each message came from. | <1 KiB |
| `midi_clock` | One MIDI clock for `audio()`: its own tempo or the clock coming in, sent out over USB if you like. `clock_events()` gives each block's ticks, start and stop at the frame they fall on. | 1 KiB RAM |
| `bluetooth` | Only with `"platform": "mvave"` (below), and on there unless turned off: BLE MIDI in and out, and audio from a phone or computer. | <1 KiB |

```json
{ "name": "MY SYNTH", "version": "0.1", "identity": "FM-1_95", "options": { "usb_audio": false } }
```

In your code, `#if FOMA_USB_AUDIO` (and `FOMA_TRS_MIDI`, `FOMA_MIDI_CLOCK`) tells you what's in. The FM-1 has no MIDI out on the TRS jack, so that can't be an option. Bluetooth (audio and BLE MIDI) is possible in
principle: JieLi's AC79 SDK has a Bluetooth stack for this chip, but only as prebuilt libraries that need JieLi's OS
underneath, so it isn't here (yet). The emulator follows MIDI
clock from Web MIDI; it has no USB audio input (`audio_in()` gives 0).
In your code, `#if FOMA_USB_AUDIO` (and `FOMA_TRS_MIDI`, `FOMA_MIDI_CLOCK`, `FOMA_BLUETOOTH`) tells you what's in. The
FM-1 has no MIDI out on the TRS jack, so that can't be an option. The emulator follows MIDI clock from Web MIDI; it
has no USB audio input (`audio_in()` gives 0) and no Bluetooth (the calls answer "not ready").

### Platforms: Felucca's, or M-VAVE's SDK (Bluetooth)

`"platform"` in `firmware.json` picks what runs under your code on the FM-1. Your code and `fm1.h` stay the same.

- **`felucca`** (the default): Felucca's platform, all of it source, with Felucca's flash layout, updater and USB rescue
(OCT- at power-on).
- **`mvave`**: M-VAVE's official FM1 SDK, from [fm1_open](https://github.com/m-vave/fm1_open) (in `platform/mvave`):
their binary library runs FreeRTOS, USB, Bluetooth and the flash, and foma runs on top of it. It adds:
- **Bluetooth** (the `bluetooth` option): BLE MIDI in and out through `midi_read` (`MIDI_BLE`) and `midi_send`, with
the FM-1 as a BLE MIDI device phones and computers connect to, or connecting to a BLE MIDI controller itself
(`ble_central`, `ble_scan`, `ble_connect`); and audio from a phone or computer (`bt_audio_in()`). It's off until
`bt_enable(BT_MIDI | BT_AUDIO)`; `bt_status()` says what's connected. See `fm1.h`.
- **USB audio both ways**: the computer can record what the FM-1 plays.

The trade-offs:
- **Space**: M-VAVE's own instrument is inside the SDK's library and can't be left out, and their layout keeps 524
KiB of flash for user data (`settings_load` / `settings_save` use it). That leaves about **46 KiB** of flash for
your code and data (the build says how much), and about 160 KiB of RAM (no `POOL`: it's all one RAM).
- **Their layout and updater**: switching platform loses saved settings, the package identity is `FM-1_8` and six
digits (from the version), and there's no OCT- rescue: M-VAVE's workbench and the chip's boot ROM still are.
- **Tested only in an emulator** so far ([fm1-emu](https://github.com/joakimeriksson/fm1-emu), with fixes for this
SDK): the screen, keys, knobs, audio and TRS MIDI work there. Bluetooth, USB audio, saved settings and installing
haven't been tried on an FM-1 yet.
- **License**: `platform/mvave` is M-VAVE's: GPLv3 with their SDK linking exception, the library under their
binary terms (FM-1 devices only). See `platform/mvave/LICENSE.md` and `THIRD_PARTY.md`.

```json
{ "name": "MY SYNTH", "version": "0.1", "identity": "FM-1_95", "platform": "mvave" }
```

## The rules of the chip

Expand Down Expand Up @@ -154,6 +184,7 @@ platform/web.c the emulator side (the same API, for WebAssembly)
platform/common.c shared: drawing, fonts, sound helpers
platform/clock.c shared: the MIDI clock (midi_clock)
platform/hal, src, loader, gen, sdk the Felucca platform, vendored (src/usb.c trimmed to MIDI and usb_audio)
platform/mvave the "mvave" platform: port.c (fm1.h on the SDK), sdk.c, board/ and sdk/ from M-VAVE's fm1_open
tools/build.py the build (in Docker), with the checks
web/ the page: emulator, installer, rescue
```
Expand Down
53 changes: 48 additions & 5 deletions platform/fm1.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
#ifndef FOMA_MIDI_CLOCK
#define FOMA_MIDI_CLOCK 1 /* midi_clock: one MIDI clock for audio(), its own or followed: clock_*() */
#endif
#ifndef FOMA_BLUETOOTH
#define FOMA_BLUETOOTH 0 /* bluetooth: BLE MIDI and audio from a phone, bt_*() / ble_*() (the "mvave" platform only) */
#endif
/* FOMA_MVAVE: 1 when built on M-VAVE's FM1 SDK ("platform": "mvave" in firmware.json), else Felucca's platform */
#ifndef FOMA_MVAVE
#define FOMA_MVAVE 0
#endif

void setup(void);
void loop(void);
Expand Down Expand Up @@ -100,13 +107,15 @@ int text(int x, int y, const char *s, uint16_t color, int font); /* returns the
int text_width(const char *s, int font);
int text_height(int font);

/* ---- MIDI in over USB (and the TRS jack: trs_midi), out over USB (any channel; SysEx belongs to the updater).
/* ---- MIDI in over USB (and the TRS jack: trs_midi; BLE: bluetooth), out over USB (and BLE) (any channel; SysEx
* belongs to the updater).
* midi_read gives channel messages, and clock / start / continue / stop (0xF8 0xFA 0xFB 0xFC) unless the clock
* helper (midi_clock) takes them. midi_send works from loop() and audio() */
enum { MIDI_USB = 1,
MIDI_TRS = 2,
MIDI_ANY = 3 };
int midi_read(uint8_t *status, uint8_t *d1, uint8_t *d2); /* 0: none; else where it came from: MIDI_USB or MIDI_TRS */
MIDI_BLE = 4,
MIDI_ANY = 7 };
int midi_read(uint8_t *status, uint8_t *d1, uint8_t *d2); /* 0: none; else where it came from: MIDI_USB, MIDI_TRS, MIDI_BLE */
void midi_send(uint8_t status, uint8_t d1, uint8_t d2);

#if FOMA_MIDI_CLOCK
Expand All @@ -133,6 +142,40 @@ int clock_events(const clock_event_t **ev); /* audio() only: this block's events
uint32_t clock_bpm(void); /* BPM x 100: its tempo, or the followed clock's (0: none coming) */
#endif

#if FOMA_BLUETOOTH
/* ---- Bluetooth (bluetooth: the "mvave" platform). Off until bt_enable(). BLE MIDI comes in through midi_read
* (MIDI_BLE) and midi_send goes out over it too; a phone or computer can play into the FM-1 (bt_audio_in).
* By default phones and computers connect to the FM-1 (it shows up as a BLE MIDI device); ble_central(1)
* makes it connect to a BLE MIDI controller instead: ble_scan(), then ble_device() / ble_connect(). From loop();
* the calls return 0 when taken, -2 busy (try again), -3 not ready */
enum { BT_AUDIO = 1,
BT_MIDI = 2 };
enum { BLE_OFF,
BLE_IDLE,
BLE_ADVERTISING,
BLE_SCANNING,
BLE_CONNECTING,
BLE_DISCOVERING,
BLE_CONNECTED,
BLE_READY,
BLE_DISCONNECTING };
typedef struct {
uint8_t ready; /* the stack is up */
uint8_t audio_connected, audio_playing; /* a phone or computer, for audio */
uint8_t ble_role, ble_state; /* ble_central's, BLE_* (BLE_READY: MIDI flows) */
uint8_t ble_count, ble_error; /* devices found by ble_scan; the last failure (0 none) */
} bt_status_t;
int bt_enable(int features); /* BT_AUDIO | BT_MIDI, 0 off */
void bt_status(bt_status_t *s);
int ble_central(int on); /* 0: others connect to the FM-1; 1: it connects to a controller */
int ble_scan(void); /* central: 15 s of looking for BLE MIDI devices */
int ble_device(int i, char name[25], int *rssi); /* 0: device i of the scan */
int ble_connect(int i);
int ble_disconnect(void);
int ble_forget(void); /* forget the BLE pairings */
const int32_t *bt_audio_in(void); /* in audio(): this block from Bluetooth (as audio_in), or 0 */
#endif

#if FOMA_USB_AUDIO
/* ---- audio from a computer or tablet over USB (usb_audio): the FM-1 is a 44.1 kHz stereo output it can pick.
* In audio(): this block's frames, L R L R ..., +-32767 (process it, record it, add it to out), or 0 when nothing
Expand All @@ -154,9 +197,9 @@ uint32_t random32(void); /* xorshift */
void format_int(char *buf, int32_t v); /* decimal, buf of 12 */
void print(const char *s); /* to the emulator's console (nothing on the FM-1) */

/* big buffers (delay lines, samples): RAM is 96 KiB, the pool ~200 KiB more
/* big buffers (delay lines, samples): RAM is 96 KiB, the pool ~200 KiB more ("mvave": one RAM, POOL is ordinary)
* static int16_t delay[48000] POOL; */
#ifdef __wasm__
#if defined(__wasm__) || FOMA_MVAVE
#define POOL
#else
#define POOL __attribute__((section(".pool")))
Expand Down
Loading
Loading