Skip to content
Open
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
1 change: 1 addition & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const demos: []const Demo = &.{
.{ .name = "additive_synthesis", .path = "demos/06_additive_synthesis/main.zig" },
.{ .name = "fm_synthesis_lfo", .path = "demos/07_fm_synthesis/lfo.zig" },
.{ .name = "fm_synthesis_operators", .path = "demos/07_fm_synthesis/operators.zig" },
.{ .name = "rick", .path = "demos/08_rick/main.zig" },
// zig fmt: on
};

Expand Down
42 changes: 42 additions & 0 deletions demos/08_rick/main.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const std = @import("std");
const assert = std.debug.assert;

const microzig = @import("microzig");
const cpu = microzig.cpu;
const rp2040 = microzig.hal;
const gpio = rp2040.gpio;
const irq = rp2040.irq;
const time = rp2040.time;

// code for this workshop
const workshop = @import("workshop");
const Oscillator = workshop.Oscillator;

// configuration
const sample_rate = 44_100;
const Sample = i16;

// hardware blocks
const I2S = workshop.I2S(Sample, .{ .sample_rate = sample_rate });

const uart = rp2040.uart.num(0);

const bruh = @embedFile("rick.raw");

pub fn main() !void {
const i2s = I2S.init(.pio0, .{
.clock_config = rp2040.clock_config,
.clk_pin = gpio.num(2),
.word_select_pin = gpio.num(3),
.data_pin = gpio.num(4),
});

var fbs = std.io.fixedBufferStream(bruh);

while (true) {
if (!i2s.is_writable())
continue;

i2s.write_mono(fbs.reader().readIntLittle(i16) catch @panic("NO!"));
}
}
Binary file added demos/08_rick/rick.raw
Binary file not shown.