> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/wokwi/wokwi-docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Framebuffer API

> Implement custom display chips with pixel-level control

Use the framebuffer API to implement displays (LCD, OLED, e-paper, etc.). The display size is defined in the `.chip.json` file. The framebuffer uses 32 bits per pixel. The pixels are stored in the RGBA format. The total size of the buffer is `pixel_width * pixel_height * 4` bytes.

## framebuffer\_init

```c theme={null}
buffer_t framebuffer_init(uint32_t *pixel_width, uint32_t *pixel_height)
```

Returns the framebuffer for the current chip, and the pixel dimensions (width/height) of the frame buffer.

<Warning>
  Note: `framebuffer_init` can only be called from `chip_init()`. Do not call it at a later time.
</Warning>

## buffer\_write

```c theme={null}
void buffer_write(buffer_t buffer, uint32_t offset, void *data, uint32_t data_len)
```

Copies `data_len` bytes from `data` into the frame buffer, at the given `offset`.

## buffer\_read

```c theme={null}
void buffer_read(buffer_t buffer, uint32_t offset, void *data, uint32_t data_len)
```

Copies `data_len` bytes at the given `offset` of the frame buffer into `data`.

## Simulator examples

* [Basic Framebuffer Chip Example](https://wokwi.com/projects/330503863007183442)
* [SSD1306 I2C OLED Display](https://wokwi.com/projects/371050937178768385)
* [IL9163 128x128 Color LCD Display Driver](https://wokwi.com/projects/333332561949360723)
