Skip to content
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

Add SSD1306 example #18

Merged
merged 8 commits into from
Dec 24, 2021
Merged

Add SSD1306 example #18

merged 8 commits into from
Dec 24, 2021

Conversation

peterstuart
Copy link
Owner

@peterstuart peterstuart commented Dec 23, 2021

movie

There's some tearing (although it looks much worse in the video than real life).

@@ -0,0 +1,39 @@
name: hardware-examples
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nightly compiler seems to be required to use an allocator in no_std programs, so I split this into a separate CI script.

const BLOCK_SIZE_INCREMENT: u32 = 2;

#[global_allocator]
static ALLOCATOR: CortexMHeap = CortexMHeap::empty();
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Configuring an allocator so we can use a heap.

ALLOCATOR.init(
&mut HEAP as *const u8 as usize,
core::mem::size_of_val(&HEAP),
)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it, this allocates a chunk of free space in the stack, and then using that space as the heap. That avoids the issue where the stack and heap can collide, and since the allocator I'm using has a fixed size anyway, I don't think there's really a downside to this. See details here: knurling-rs/flip-link#62

&mut rcc.apb1,
);

let interface = I2CDisplayInterface::new(i2c);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SSD1306 I'm using communicates over I2C, so this is just a bunch of boilerplate setting that up with the pins being used.

let mut block_size: u32 = MIN_BLOCK_SIZE;

loop {
display.clear();
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, any parts of the display that are untouched by the drawing code (because they are transparent, I guess) aren't reset back to black.

Copy link

@helixbass helixbass left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peterstuart I'm not following much of the embedded stuff but I see how the animation loop is working, nice to see it running on a physical display!

Base automatically changed from images to main December 24, 2021 19:19
@peterstuart peterstuart merged commit fb2338f into main Dec 24, 2021
@peterstuart peterstuart deleted the hardware-example branch December 24, 2021 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants