-
Notifications
You must be signed in to change notification settings - Fork 144
rp2xxx: ssd1306 oled display example #646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ymore - Removed all Enabled enum usage in schmitt trigger and turned them to be bool only - Only GPIO confing uses now the Enabled enum for user-friendly readability
- Remove switch and use logical eval
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's important that examples are compiled so that CI catches breaks. It's okay to add a dependency to the example as it is separate from the actual package. I also see that it is your package, and that is fine, but it needs to have a compatible LICENSE, and the dependency must link to a commit with that license. If you fail to maintain that package in the future and it blocks our CI, this example can be removed.
debe194
to
a4cac98
Compare
You should also add the example to build.zig as well adding the module import. These are the changes you need to make: diff --git a/examples/raspberrypi/rp2xxx/build.zig b/examples/raspberrypi/rp2xxx/build.zig
index 1add360d..8a4382ed 100644
--- a/examples/raspberrypi/rp2xxx/build.zig
+++ b/examples/raspberrypi/rp2xxx/build.zig
@@ -9,6 +9,8 @@ pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});
const maybe_example = b.option([]const u8, "example", "only build matching examples");
+ const font8x8_dep = b.dependency("font8x8", .{});
+
const mz_dep = b.dependency("microzig", .{});
const mb = MicroBuild.init(b, mz_dep) orelse return;
@@ -68,6 +70,9 @@ pub fn build(b: *std.Build) void {
.{ .name = "dma", .file = "src/dma.zig" },
.{ .name = "cyw43", .file = "src/cyw43.zig" },
.{ .name = "mlx90640", .file = "src/mlx90640.zig" },
+ .{ .name = "ssd1306-oled", .file = "src/ssd1306_oled.zig", .imports = &.{
+ .{ .name = "font8x8", .module = font8x8_dep.module("font8x8") },
+ } },
};
var available_examples = std.ArrayList(Example).init(b.allocator);
@@ -77,12 +82,14 @@ pub fn build(b: *std.Build) void {
.target = mb.ports.rp2xxx.boards.raspberrypi.pico,
.name = b.fmt("pico_{s}", .{example.name}),
.file = example.file,
+ .imports = example.imports,
}) catch @panic("out of memory");
available_examples.append(.{
.target = mb.ports.rp2xxx.boards.raspberrypi.pico2_arm,
.name = b.fmt("pico2_arm_{s}", .{example.name}),
.file = example.file,
+ .imports = example.imports,
}) catch @panic("out of memory");
if (example.works_with_riscv) {
@@ -90,6 +97,7 @@ pub fn build(b: *std.Build) void {
.target = mb.ports.rp2xxx.boards.raspberrypi.pico2_riscv,
.name = b.fmt("pico2_riscv_{s}", .{example.name}),
.file = example.file,
+ .imports = example.imports,
}) catch @panic("out of memory");
}
}
@@ -110,6 +118,7 @@ pub fn build(b: *std.Build) void {
.target = example.target,
.optimize = optimize,
.root_source_file = b.path(example.file),
+ .imports = example.imports,
});
// `install_firmware()` is the MicroZig pendant to `Build.installArtifact()`
@@ -127,10 +136,12 @@ const Example = struct {
target: *const microzig.Target,
name: []const u8,
file: []const u8,
+ imports: []const std.Build.Module.Import = &.{},
};
const ChipAgnosticExample = struct {
name: []const u8,
file: []const u8,
works_with_riscv: bool = true,
+ imports: []const std.Build.Module.Import = &.{},
}; To test that your example is building you should run |
const i2c0 = i2c.instance.num(0); | ||
const lcd_address = rp2xxx.i2c.Address.new(0x3C); | ||
const empty_row: []const u8 = " "; | ||
const four_rows = empty_row ++ empty_row ++ empty_row ++ empty_row; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty_row ** 4
is probably nicer
|
||
const i2c0 = i2c.instance.num(0); | ||
const lcd_address = rp2xxx.i2c.Address.new(0x3C); | ||
const empty_row: []const u8 = " "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be nicer to also do " " ** xxx
. Makes it easy to see how wide a row is.
const four_rows = empty_row ++ empty_row ++ empty_row ++ empty_row; | ||
|
||
pub fn main() void { | ||
var backinf_buffer: [200 * 1024]u8 = undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
magic numbers? Would be nice to define these as a const for someone with a different display to more easily understand and change these values
const font8x8 = @import("font8x8"); | ||
|
||
// Compile-time pin configuration | ||
const pin_config = rp2xxx.pins.GlobalConfiguration{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this is fine, it's probably overkill. You can probably just copy how the pins are configured for other i2c examples e.g. i2c_bus_scan
lcd.write_gdram(text) catch continue; | ||
|
||
counter += 1; | ||
time.sleep_ms(1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You sleep here but also at the top of the loop. Is this intentional?
|
||
var counter: u8 = 0; | ||
while (true) : (time.sleep_ms(1000)) { | ||
var allocator = fba.allocator(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you probably want to move this and the defer free out of the loop.
@memcpy(buf[0..64], four_rows); | ||
for (0..to_be_added) |i| { | ||
@memcpy(buf[(64 + i)..(64 + i + 1)], " "); | ||
} | ||
@memcpy(buf[(64 + to_be_added)..(64 + to_be_added + str.len)], str); | ||
for ((64 + str.len + to_be_added)..buf.len) |i| { | ||
@memcpy(buf[i..(i + 1)], " "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does 64 mean here? Avoid magic numbers
Co-authored-by: Grazfather <[email protected]>
No description provided.