Embedded Xinu Operating System
An ongoing research project and educational operating system.
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
Functions
Framebuffer

Driver for the BCM2837B0 (Raspberry Pi 3 B+) framebuffer. More...

Functions

void drawChar (char c, int x, int y, ulong color)
 
void drawPixel (int x, int y, ulong color)
 
void drawLine (int x1, int y1, int x2, int y2, ulong color)
 
void drawSegment (int x1, int y1, int x2, int y2, ulong color)
 
void drawRect (int x1, int y1, int x2, int y2, ulong color)
 
void fillRect (int x1, int y1, int x2, int y2, ulong color, bool gradient)
 
void drawCircle (int x0, int y0, int radius, ulong color)
 
void fillCircle (int x0, int y0, int radius, ulong color, bool gradient)
 
void drawBody (int x0, int y0, int radius, ulong color)
 
void fillBody (int x0, int y0, int radius, ulong color, bool gradient)
 
syscall fbputc (uchar c, device *devptr)
 
syscall fbgetc (device *devptr)
 
syscall fbprintf (char *fmt,...)
 
devcall fbPutc (device *devptr, char ch)
 
devcall fbWrite (device *devptr, const uchar *buf, uint len)
 
ulong mailboxRead ()
 
void mailboxWrite (ulong data)
 
ulong readMMIO (ulong base, ulong reg)
 
void writeMMIO (ulong base, ulong reg, ulong val)
 
ulong physToBus (void *address)
 
volatile unsigned int __attribute__ ((aligned(16)))
 
void screenInit ()
 
int framebufferInit ()
 
void screenClear (ulong color)
 
void minishellClear (ulong color)
 
void initlinemap ()
 
double power (double base, int exp)
 
long factorial (int num)
 
double cosine_taylor (double x, int terms)
 
double cos (int x)
 
double sine_taylor (double x, int terms)
 

Detailed Description

Driver for the BCM2837B0 (Raspberry Pi 3 B+) framebuffer.

This driver communicates with the VideoCore GPU and provides functions to draw shapes and print text to the screen.

Function Documentation

volatile unsigned int __attribute__ ( (aligned(16))  )

Make a mailbox call.

Parameters
chMailbox channel
Returns
::SYSERR on failure, non-zero on success
double cos ( int  x)

Compute the cosine using the Taylor approximation as a helper function

Parameters
xAngle, in degrees
Returns
Double-precision result of the computation
double cosine_taylor ( double  x,
int  terms 
)

Compute the Taylor series approximation of cosine using power and factorial x Base value

Parameters
termsTerms of the sum
Returns
Double-precision result of the cosine approximation
void drawBody ( int  x0,
int  y0,
int  radius,
ulong  color 
)

Turtle graphics specific circle functions

Parameters
x0x-coordinate of circle center
y0y-coordinate of circle center
radiusradius of circle
colorcolor of circle
void drawChar ( char  c,
int  x,
int  y,
ulong  color 
)

font.c includes a 12 byte representation of each of the first 128 ASCII characters. each byte is one row of 0's and 1's, where 1's represent that a pixel should be rendered in that location.

Parameters
ccharacter to be drawn
xx-coordinate of character
yy-coordinate of character
colorcolor of character
void drawCircle ( int  x0,
int  y0,
int  radius,
ulong  color 
)

Midpoint Circle Algorithm calculation of a circle. Based on "x^2 + y^2 = r^2"

Parameters
x0x-coordinate of circle center
y0y-coordinate of circle center
radiusradius of circle
colorcolor of circle
void drawLine ( int  x1,
int  y1,
int  x2,
int  y2,
ulong  color 
)

Line drawing based on Bresenham's Algorithm. So that we don't need to mess with division or decimals.

Parameters
x1starting x-coordinate of line
y1starting y-coordinate of line
x2ending x-coordinate of line
y2ending y-coordinate of line
colorcolor of line
void drawPixel ( int  x,
int  y,
ulong  color 
)

Draws a colored pixel at given (x, y) coordinates.

Parameters
xx-coordinate of pixel
yy-coordinate of pixel
colorcolor of pixel
void drawRect ( int  x1,
int  y1,
int  x2,
int  y2,
ulong  color 
)

Draws a rectangle outline TODODC better description

Parameters
x1upper left hand corner x-coordinate
y1upper left hand corner y-coordinate
x2lower right hand corner x-coordinate
y2lower right hand corner y-coordinate
colorcolor of rectangle
void drawSegment ( int  x1,
int  y1,
int  x2,
int  y2,
ulong  color 
)

Modified drawLine specifically for turtle graphics

Parameters
x1starting x-coordinate
y1starting y-coordinate
x2ending x-coordinate
y2ending y-coordinate
colorcolor of line
long factorial ( int  num)

Compute the factorial of an integer

Parameters
numInteger to compute factorial operation on
Returns
Long integer result of the factorial operation
syscall fbgetc ( device *  devptr)

perform a synchronous kernel read

Parameters
*devptrpointer to device on which to write character
Returns
character read on success, SYSERR on failure
syscall fbprintf ( char *  fmt,
  ... 
)

kernel printf: formatted, unbuffered output to framebuffer Akin to "kprintf" for the serial driver. Alternate: fprintf(FRAMEBUF, "string");

Parameters
*fmtpointer to string being printed
Returns
OK on success
syscall fbputc ( uchar  c,
device *  devptr 
)

perform a synchronous character write

Parameters
*devptrpointer to device on which to write character
ccharacter to write
Returns
c on success, SYSERR on failure
devcall fbPutc ( device *  devptr,
char  ch 
)

Write a single character to the framebuffer

Parameters
devptrpointer to framebuffer device
chcharacter to write
devcall fbWrite ( device *  devptr,
const uchar *  buf,
uint  len 
)

Write a buffer of characters to the framebuffer.

Parameters
devptrpointer to framebuffer device
bufbuffer of characters to write
lennumber of characters to write from the buffer
Returns
The number of characters written, which may be less than len in the event of a write error; or ::SYSERR if an error occurred before any characters at all were written.
void fillBody ( int  x0,
int  y0,
int  radius,
ulong  color,
bool  gradient 
)

Draws filled in circle

Parameters
x0x-coordinate of circle center
y0y-coordinate of circle center
radiusradius of circle
colorcolor of circle
gradienttrue if circle has a gradient; false if not
void fillCircle ( int  x0,
int  y0,
int  radius,
ulong  color,
bool  gradient 
)

Draws a filled in circle TODODC better description

Parameters
x0x-coordinate of circle center
y0y-coordinate of circle center
radiusradius of circle
colorcolor of circle
gradienttrue if circle has a gradient; false if not
void fillRect ( int  x1,
int  y1,
int  x2,
int  y2,
ulong  color,
bool  gradient 
)

Draws a filled-in ractangle, given coordinates and colorization options

Parameters
x1upper left hand corner x-coordinate
y1upper left hand corner y-coordinate
x2lower right hand corner x-coordinate
y2lower right hand corner y-coordinate
colorcolor of rectangle
gradienttrue if rectangle has a gradient; false if not
int framebufferInit ( )

Initializes the framebuffer used by the GPU via the framebuffer mailbox.

Returns
::OK on success; ::SYSERR on failure.
void initlinemap ( )

Clear the "linemapping" array used to keep track of pixels we need to remember

ulong mailboxRead ( )

Read from mailbox one on channel one (GPU mailbox) Note: Data: first 28 bits. Channel: last 4 bits.

void mailboxWrite ( ulong  data)

Write to GPU mailbox.

Parameters
dataData to write to the mailbox
void minishellClear ( ulong  color)

Clear the minishell window

Parameters
colorColor to paint the window upon clear
ulong physToBus ( void *  address)

Converts ARM physical addresses to ARM bus addresses. Separate function for legibility's sake. Rev 1 board GPU required bus addresses. Now deprecated.

Parameters
addressPhysical address to convert
double power ( double  base,
int  exp 
)

Compute the double-precision result of a power operation

Parameters
baseDouble-precision base value of operation
expInteger exponent to which the base is raised
Returns
Double-precision result of the power operation
ulong readMMIO ( ulong  base,
ulong  reg 
)

To omit illegible lines of code, a helper function that reads from memory mapped IO registers.

Parameters
baseRegister base
regMMIO register to read
void screenClear ( ulong  color)

Very heavy handed clearing of the screen to a single color.

Parameters
color
void screenInit ( )

Calls framebufferInit() several times to ensure we successfully initialize, just in case.

Returns
Void upon completion.
double sine_taylor ( double  x,
int  terms 
)

Compute the Taylor series approximation of sine

Parameters
xBase value
termsTerms of the sum
Returns
Double-precision result of the sine approximation
void writeMMIO ( ulong  base,
ulong  reg,
ulong  val 
)

The opposite of above. Write to MMIO.

Parameters
baseRegister base
regMMIO register to write to
valValue to be written