User Tools

Site Tools


first_demo:framebuffer

The library is very much in its infancy…GitHub will be coming online soon but here is a taste of how you might do a simple software only framebuffer:

#include <zephyr.h>
#include <device.h>
#include <devicetree.h>
 
#include <math.h>
#include <string.h>
 
//the retro watch sdk includes
#include "lcd.h"
 
#define SCREEN_WIDTH 240
#define SCREEN_HEIGHT 240
 
//convert 565 rgb into 16 bit word and swap bytes for lcd
uint16_t rgb(int r, int g, int b)
{
	uint16_t c = (((r) << 11) | ((g) << 5) | (b));
 
	return ((c >> 8) & 0xFF) | ((c & 0xFF) << 8);
}
 
 
void main(void)
{
	uint16_t *frame_buffer;
 
	printk("hello cruel world\n");
 
	//initialize the lcd
	lcd_configure();
 
	while(1)
	{
		//swaps buffers and DMA previous buffer to LCD
		lcd_update_screen();
 
		//get new back buffer
		frame_buffer = lcd_get_buffer();
 
		for(int ix = 0; ix < SCREEN_WIDTH; ix++)
		{	
			for(int iy = 0; iy < SCREEN_HEIGHT; iy++)
			{
				//fill frame buffer with a simple xor pattern
				frame_buffer[ix + iy * SCREEN_WIDTH] = rgb((ix ^ iy)>>3, iy>>2, ix>>3);
			}
		}
	}
}
first_demo/framebuffer.txt · Last modified: 2021/11/17 14:07 by jason

Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain
Public Domain Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki