rust-embedded-community / ssd1306

SSD1306 OLED driver
Apache License 2.0
299 stars 68 forks source link

Custom mode support #208

Open MateuszJanda opened 7 months ago

MateuszJanda commented 7 months ago

Description of feature request

I tried create (in my project) custom mode (NonBufferedGraphicsMode) due to limitation of SRAM in my Arduino UNO R3. However Ssd1306 offer only into_buffered_graphics_mode and into_terminal_mode. I think public into_mode or public members of Ssd1306 can be helpful (I don't know, I don't have solution yet). Or maybe this is possible, but I don't know some rusty trick? If not (possible), what do you think about such improvement? GO, NOGO - and fork is my only option? I don't think that pushing more modes into driver code is good idea, but interface for customization looks handy.

Loose skeleton, how this could look like at the end.

#[derive(Clone, Debug)]
pub struct NonBufferedGraphicsMode
{
    // ...
}

impl NonBufferedGraphicsMode
{
    // ...
}

// Trick to extend Ssd1306 (which is in his own crate)
pub struct NonBufferedGraphicsModeWrapper<DI, SIZE>(Ssd1306<DI, SIZE, NonBufferedGraphicsMode>);

impl<DI, SIZE> NonBufferedGraphicsModeWrapper<DI, SIZE>
where
    DI: WriteOnlyDataCommand,
    SIZE: DisplaySize,
{
    // ...
}

impl<DI, SIZE> DrawTarget for NonBufferedGraphicsModeWrapper<DI, SIZE>
where
    DI: WriteOnlyDataCommand,
    SIZE: DisplaySize,
{
    fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error>
    where
        I: IntoIterator<Item = Pixel<Self::Color>>,
    {
        // ...
    }
}

// Integration 
let mut custom_mode = NonBufferedGraphicsModeWrapper::new();
let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0)
    .into_mode(custom_mode);