Generate callgraph
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
This is a collection of common modules, such as utility functions,
|
||||
etc. Note, that these modules do not directly access the hardware but
|
||||
instead use the device driver modules.
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/** @file boing.c
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 24 August 2010
|
||||
@brief Bouncing ball module
|
||||
*/
|
||||
#include "system.h"
|
||||
#include "boing.h"
|
||||
|
||||
/** Update the state of a ball bouncing off the edges of the display
|
||||
@param state current state
|
||||
@return new state. */
|
||||
boing_state_t boing_update (boing_state_t state)
|
||||
{
|
||||
tinygl_point_t hops[] = {{0, 1}, {1, 1}, {1, 0}, {1, -1},
|
||||
{0, -1}, {-1, -1}, {-1, 0}, {-1, 1}};
|
||||
|
||||
state.pos.x += hops[state.dir].x;
|
||||
state.pos.y += hops[state.dir].y;
|
||||
|
||||
if (state.pos.x > TINYGL_WIDTH - 1 || state.pos.x < 0)
|
||||
{
|
||||
boing_dir_t newdir[] = {DIR_N, DIR_NW, DIR_W, DIR_SW,
|
||||
DIR_S, DIR_SE, DIR_E, DIR_NE};
|
||||
state.pos.x -= 2 * hops[state.dir].x;
|
||||
state.dir = newdir[state.dir];
|
||||
}
|
||||
|
||||
if (state.pos.y > TINYGL_HEIGHT - 1 || state.pos.y < 0)
|
||||
{
|
||||
boing_dir_t newdir[] = {DIR_S, DIR_SE, DIR_E, DIR_NE,
|
||||
DIR_N, DIR_NW, DIR_W, DIR_SW};
|
||||
state.pos.y -= 2 * hops[state.dir].y;
|
||||
state.dir = newdir[state.dir];
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
/** Reverse the direction of a ball
|
||||
@param state current state
|
||||
@return new state with direction reversed. */
|
||||
boing_state_t boing_reverse (boing_state_t state)
|
||||
{
|
||||
boing_dir_t newdir[] = {DIR_S, DIR_SW, DIR_W, DIR_NW,
|
||||
DIR_N, DIR_NE, DIR_W, DIR_SE};
|
||||
|
||||
state.dir = newdir[state.dir];
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
/** Initialise the state of a ball
|
||||
@param xstart x coordinate to start at
|
||||
@param ystart y coordinate to start at
|
||||
@param dir initial direction
|
||||
@return state. */
|
||||
boing_state_t boing_init (uint8_t xstart, uint8_t ystart, boing_dir_t dir)
|
||||
{
|
||||
boing_state_t state;
|
||||
|
||||
if (xstart > TINYGL_WIDTH)
|
||||
xstart = TINYGL_WIDTH - 1;
|
||||
if (ystart > TINYGL_HEIGHT)
|
||||
ystart = TINYGL_HEIGHT - 1;
|
||||
|
||||
state.pos.x = xstart;
|
||||
state.pos.y = ystart;
|
||||
state.dir = dir;
|
||||
|
||||
return state;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/** @file boing.h
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 24 August 2010
|
||||
@brief Bouncing ball module
|
||||
|
||||
@defgroup boing Bouncing ball module
|
||||
*/
|
||||
#ifndef BOING_H
|
||||
#define BOING_H
|
||||
|
||||
#include "tinygl.h"
|
||||
|
||||
/** Compass direction of ball. */
|
||||
typedef enum dir {DIR_N, DIR_NE, DIR_E, DIR_SE,
|
||||
DIR_S, DIR_SW, DIR_W, DIR_NW} boing_dir_t;
|
||||
|
||||
|
||||
/** Structure defining state of ball. */
|
||||
typedef struct state {tinygl_point_t pos; boing_dir_t dir;} boing_state_t;
|
||||
|
||||
|
||||
/** Update the state of a ball bouncing off the edges of the display
|
||||
@param state current state
|
||||
@return new state. */
|
||||
boing_state_t boing_update (boing_state_t state);
|
||||
|
||||
|
||||
/** Reverse the direction of a ball
|
||||
@param state current state
|
||||
@return new state with direction reversed. */
|
||||
boing_state_t boing_reverse (boing_state_t state);
|
||||
|
||||
|
||||
/** Initialise the state of a ball
|
||||
@param xstart x coordinate to start at
|
||||
@param ystart y coordinate to start at
|
||||
@param dir initial direction
|
||||
@return state. */
|
||||
boing_state_t boing_init (uint8_t xstart, uint8_t ystart, boing_dir_t dir);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,41 @@
|
||||
/** @file font.h
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 1 March 2007
|
||||
@brief Font definition.
|
||||
*/
|
||||
|
||||
#ifndef FONT_H
|
||||
#define FONT_H
|
||||
|
||||
#include "system.h"
|
||||
|
||||
typedef const uint8_t font_data_t;
|
||||
|
||||
/** Font structure. */
|
||||
typedef const struct
|
||||
{
|
||||
/** Flags for future options. */
|
||||
uint8_t flags;
|
||||
/** Width of font element. */
|
||||
uint8_t width;
|
||||
/** Height of font element. */
|
||||
uint8_t height;
|
||||
/** Index of first entry in font. */
|
||||
uint8_t offset;
|
||||
/** Number of font entries in table. */
|
||||
uint8_t size;
|
||||
/** Number of bytes per font entry. */
|
||||
uint8_t bytes;
|
||||
/** Font element data. */
|
||||
font_data_t data[];
|
||||
} font_t;
|
||||
|
||||
|
||||
/** Return the first character in the font. */
|
||||
#define FONT_FIRST(font) ((font)->offset)
|
||||
|
||||
/** Return the last character in the font. */
|
||||
#define FONT_LAST(font) ((font)->offset + (font)->size - 1)
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
/** @file pacer.c
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 23 August 2010
|
||||
@brief Paced loop module
|
||||
*/
|
||||
#include "system.h"
|
||||
#include "timer.h"
|
||||
#include "pacer.h"
|
||||
|
||||
static timer_tick_t pacer_period;
|
||||
|
||||
|
||||
/** Initialise pacer:
|
||||
@param pacer_rate rate in Hz. */
|
||||
void pacer_init (pacer_rate_t pacer_rate)
|
||||
{
|
||||
timer_init ();
|
||||
|
||||
pacer_period = TIMER_RATE / pacer_rate;
|
||||
}
|
||||
|
||||
|
||||
/** Wait until next pacer tick. */
|
||||
void pacer_wait (void)
|
||||
{
|
||||
static timer_tick_t when = 0;
|
||||
|
||||
timer_wait_until (when);
|
||||
when += pacer_period;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/** @file pacer.h
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 23 August 2010
|
||||
@brief Paced loop support.
|
||||
|
||||
@defgroup pacer Paced loop module
|
||||
|
||||
This module provides support for paced loops by abstracting a
|
||||
hardware timer.
|
||||
|
||||
Here's a simple example for a paced loop that operates at 1 kHz.
|
||||
|
||||
@code
|
||||
#include "pacer.h"
|
||||
|
||||
void main (void)
|
||||
{
|
||||
pacer_init (1000);
|
||||
|
||||
while (1)
|
||||
{
|
||||
pacer_wait ();
|
||||
|
||||
// Do something.
|
||||
}
|
||||
}
|
||||
@endcode
|
||||
*/
|
||||
#ifndef PACER_H
|
||||
#define PACER_H
|
||||
|
||||
#include "system.h"
|
||||
|
||||
/** Define size of pacer rates. */
|
||||
typedef uint16_t pacer_rate_t;
|
||||
|
||||
|
||||
/** Wait for the next pacer tick. */
|
||||
extern void pacer_wait (void);
|
||||
|
||||
|
||||
/** Initialise pacer:
|
||||
@param pacer_rate rate in Hz. */
|
||||
extern void pacer_init (pacer_rate_t pacer_rate);
|
||||
|
||||
#endif /* PACER_H */
|
||||
@@ -0,0 +1,76 @@
|
||||
/** @file task.c
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 17 August 2011
|
||||
@brief Simple task scheduler.
|
||||
*/
|
||||
#include "system.h"
|
||||
#include "task.h"
|
||||
#include "timer.h"
|
||||
|
||||
|
||||
/** With 16-bit times the maximum value is 32768. */
|
||||
#define TASK_OVERRUN_MAX 32767
|
||||
|
||||
|
||||
/** Schedule tasks
|
||||
@param tasks pointer to array of tasks (the highest priority
|
||||
task comes first)
|
||||
@param num_tasks number of tasks to schedule
|
||||
@return this never returns.
|
||||
*/
|
||||
void task_schedule (task_t *tasks, uint8_t num_tasks)
|
||||
{
|
||||
uint8_t i;
|
||||
timer_tick_t now;
|
||||
task_t *next_task;
|
||||
|
||||
timer_init ();
|
||||
now = timer_get ();
|
||||
|
||||
/* Start by scheduling the first task. */
|
||||
next_task = tasks;
|
||||
|
||||
while (1)
|
||||
{
|
||||
timer_tick_t sleep_min;
|
||||
|
||||
/* Wait until the next task is ready to run. */
|
||||
timer_wait_until (next_task->reschedule);
|
||||
|
||||
/* Schedule the task. */
|
||||
next_task->func (next_task->data);
|
||||
|
||||
/* Update the reschedule time. */
|
||||
next_task->reschedule += next_task->period;
|
||||
|
||||
sleep_min = ~0;
|
||||
now = timer_get ();
|
||||
|
||||
/* Search array of tasks. Schedule the first task (highest priority)
|
||||
that needs to run otherwise wait until first task ready. */
|
||||
for (i = 0; i < num_tasks; i++)
|
||||
{
|
||||
task_t * task = tasks + i;
|
||||
timer_tick_t overrun;
|
||||
|
||||
overrun = now - task->reschedule;
|
||||
if (overrun < TASK_OVERRUN_MAX)
|
||||
{
|
||||
/* Have found a task that can run immediately. */
|
||||
next_task = task;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
timer_tick_t sleep;
|
||||
|
||||
sleep = -overrun;
|
||||
if (sleep < sleep_min)
|
||||
{
|
||||
sleep_min = sleep;
|
||||
next_task = task;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
/** @file task.h
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 17 August 2011
|
||||
@brief Simple task scheduler.
|
||||
|
||||
@defgroup task Simple task scheduler
|
||||
|
||||
This scheduler periodically calls functions specified in an array
|
||||
of tasks to schedule. There is no pre-emption; a task can hog the CPU.
|
||||
The tasks at the start of the array have a higher priority.
|
||||
|
||||
Each task must maintain its own state; either using static local
|
||||
variables, file variables, or dynamically using the generic pointer
|
||||
passed when the task is called.
|
||||
|
||||
Here's an example of two LED flashing tasks that run at 2 and 3 Hz.
|
||||
|
||||
@code
|
||||
#include "task.h"
|
||||
#include "led.h"
|
||||
#include "system.h"
|
||||
|
||||
static void led1_task (void *data)
|
||||
{
|
||||
static uint8_t state = 0;
|
||||
|
||||
led_set (LED1, state);
|
||||
state = !state;
|
||||
}
|
||||
|
||||
|
||||
static void led2_task (void *data)
|
||||
{
|
||||
static uint8_t state = 0;
|
||||
|
||||
led_set (LED2, state);
|
||||
state = !state;
|
||||
}
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
task_t tasks[] =
|
||||
{
|
||||
{.func = led1_task, .period = TASK_RATE / 2, .data = 0},
|
||||
{.func = led2_task, .period = TASK_RATE / 3, .data = 0},
|
||||
};
|
||||
|
||||
system_init ();
|
||||
led_init ();
|
||||
|
||||
task_schedule (tasks, 2);
|
||||
return 0;
|
||||
}
|
||||
@endcode
|
||||
|
||||
Here's another similar example. This time there are two instances
|
||||
of the same task but with different state.
|
||||
|
||||
@code
|
||||
#include "task.h"
|
||||
#include "led.h"
|
||||
#include "system.h"
|
||||
|
||||
typedef struct state_struct
|
||||
{
|
||||
uint8_t led;
|
||||
uint8_t on;
|
||||
} state_t;
|
||||
|
||||
|
||||
static void led_task (void *data)
|
||||
{
|
||||
state_t *pstate = data;
|
||||
|
||||
led_set (pstate->led, pstate->on);
|
||||
pstate->on = !pstate->on;
|
||||
}
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
state_t led1 = {.led = LED1, .on = 0};
|
||||
state_t led2 = {.led = LED2, .on = 0};
|
||||
task_t tasks[] =
|
||||
{
|
||||
{.func = led_task, .period = TASK_RATE / 2, .data = &led1},
|
||||
{.func = led_task, .period = TASK_RATE / 3, .data = &led2},
|
||||
};
|
||||
|
||||
system_init ();
|
||||
led_init ();
|
||||
|
||||
task_schedule (tasks, 2);
|
||||
return 0;
|
||||
}
|
||||
@endcode
|
||||
*/
|
||||
|
||||
#ifndef TASK_H
|
||||
#define TASK_H
|
||||
|
||||
#include "system.h"
|
||||
#include "timer.h"
|
||||
|
||||
|
||||
#define TASK_RATE TIMER_RATE
|
||||
|
||||
|
||||
/** Task function prototype. */
|
||||
typedef void (* task_func_t)(void *data);
|
||||
|
||||
|
||||
/** Task structure. */
|
||||
typedef struct task_struct
|
||||
{
|
||||
/** Function to call. */
|
||||
task_func_t func;
|
||||
/** Generic pointer to pass to function. */
|
||||
void *data;
|
||||
/** How many ticks between scheduling events. */
|
||||
timer_tick_t period;
|
||||
/** When to reschedule. */
|
||||
timer_tick_t reschedule;
|
||||
} task_t;
|
||||
|
||||
|
||||
/** Schedule tasks
|
||||
@param tasks pointer to array of tasks (the highest priority
|
||||
task comes first)
|
||||
@param num_tasks number of tasks to schedule
|
||||
@return this never returns.
|
||||
*/
|
||||
void task_schedule (task_t *tasks, uint8_t num_tasks);
|
||||
|
||||
#endif
|
||||
|
||||
+278
@@ -0,0 +1,278 @@
|
||||
/** @file tinygl.c
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 24 August 2010
|
||||
@brief Tiny graphics library.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include "system.h"
|
||||
#include "tinygl.h"
|
||||
#include "display.h"
|
||||
|
||||
enum {TINYGL_SPEED_DEFAULT = 20};
|
||||
|
||||
static uint16_t update_rate;
|
||||
static uint16_t text_advance_period;
|
||||
static font_t *font;
|
||||
static tinygl_text_mode_t text_mode = TINYGL_TEXT_MODE_STEP;
|
||||
static uint8_t message_index;
|
||||
static uint8_t scroll_pos = 0;
|
||||
static char message1[32] = "";
|
||||
|
||||
|
||||
/** Draw point.
|
||||
@param point coordinates of point
|
||||
@param pixel_value pixel value for line. */
|
||||
void tinygl_draw_point (tinygl_point_t point, tinygl_pixel_value_t pixel_value)
|
||||
{
|
||||
display_pixel_set (point.x, point.y, pixel_value);
|
||||
}
|
||||
|
||||
|
||||
/** Draw line.
|
||||
@param point1 coordinates of start of line
|
||||
@param point2 coordinates of end of line
|
||||
@param pixel_value pixel value for line. */
|
||||
void tinygl_draw_line (tinygl_point_t point1, tinygl_point_t point2,
|
||||
tinygl_pixel_value_t pixel_value)
|
||||
{
|
||||
int dx;
|
||||
int dy;
|
||||
int x_inc;
|
||||
int y_inc;
|
||||
|
||||
/* Draw a line using Bresenham's algorithm. */
|
||||
|
||||
dx = point2.x - point1.x;
|
||||
dy = point2.y - point1.y;
|
||||
|
||||
x_inc = dx >= 0 ? 1 : -1;
|
||||
y_inc = dy >= 0 ? 1 : -1;
|
||||
if (dx < 0)
|
||||
dx = -dx;
|
||||
if (dy < 0)
|
||||
dy = -dy;
|
||||
|
||||
if (dx >= dy)
|
||||
{
|
||||
int error;
|
||||
|
||||
error = dx / 2;
|
||||
|
||||
for (; point1.x != point2.x; point1.x += x_inc)
|
||||
{
|
||||
tinygl_draw_point (point1, pixel_value);
|
||||
|
||||
error -= dy;
|
||||
if (error < 0)
|
||||
{
|
||||
error += dx;
|
||||
point1.y += y_inc;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int error;
|
||||
|
||||
error = dy / 2;
|
||||
for (; point1.y != point2.y; point1.y += y_inc)
|
||||
{
|
||||
tinygl_draw_point (point1, pixel_value);
|
||||
|
||||
error -= dx;
|
||||
if (error < 0)
|
||||
{
|
||||
error += dy;
|
||||
point1.x += x_inc;
|
||||
}
|
||||
}
|
||||
}
|
||||
tinygl_draw_point (point1, pixel_value);
|
||||
}
|
||||
|
||||
|
||||
/** Draw box.
|
||||
@param tl coordinates of top left corner of box
|
||||
@param br coordinates of bottom right of box
|
||||
@param pixel_value pixel value for box. */
|
||||
void tinygl_draw_box (tinygl_point_t tl, tinygl_point_t br,
|
||||
tinygl_pixel_value_t pixel_value)
|
||||
{
|
||||
tinygl_draw_line (tl, tinygl_point (br.x, tl.y), pixel_value);
|
||||
tinygl_draw_line (tl, tinygl_point (tl.x, br.y), pixel_value);
|
||||
tinygl_draw_line (tinygl_point (br.x, tl.y), br, pixel_value);
|
||||
tinygl_draw_line (tinygl_point (tl.x, br.y), br, pixel_value);
|
||||
}
|
||||
|
||||
|
||||
/** Clear display. */
|
||||
void tinygl_clear (void)
|
||||
{
|
||||
display_clear ();
|
||||
|
||||
/* Stop message display. */
|
||||
message1[0] = 0;
|
||||
message_index = 0;
|
||||
}
|
||||
|
||||
|
||||
/** Determine if pixel on or off.
|
||||
@param ch character to display
|
||||
@param col column of font element
|
||||
@param row row of font element
|
||||
@return 1 if pixel on; if pixel out of bounds return 0. */
|
||||
static bool tinygl_font_pixel_get (char ch, uint8_t col, uint8_t row)
|
||||
{
|
||||
int8_t index;
|
||||
font_data_t *char_data;
|
||||
uint8_t offset;
|
||||
|
||||
if (!font || col >= font->width || row >= font->height)
|
||||
return 0;
|
||||
|
||||
/* Find index of font entry. */
|
||||
index = ch - font->offset;
|
||||
if (index < 0 || index >= font->size)
|
||||
return 0;
|
||||
|
||||
/* Get start of font entry data for ch. */
|
||||
char_data = &font->data[index * font->bytes];
|
||||
|
||||
/* Extract whether pixel should be on or off. */
|
||||
offset = row * font->width + col;
|
||||
return (char_data[offset / 8] & BIT (offset % 8)) != 0;
|
||||
}
|
||||
|
||||
|
||||
/** Display a character.
|
||||
@param ch character to display
|
||||
@return 1 if character fully displayed. */
|
||||
static bool tinygl_display_char (char ch)
|
||||
{
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
|
||||
if (!font)
|
||||
return 0;
|
||||
|
||||
switch (text_mode)
|
||||
{
|
||||
case TINYGL_TEXT_MODE_SCROLL_LEFT:
|
||||
display_scroll_left ();
|
||||
|
||||
for (y = 0; y < font->height; y++)
|
||||
{
|
||||
tinygl_draw_point (tinygl_point (TINYGL_WIDTH - 1, y),
|
||||
tinygl_font_pixel_get (ch, scroll_pos, y));
|
||||
}
|
||||
break;
|
||||
|
||||
case TINYGL_TEXT_MODE_STEP:
|
||||
if (scroll_pos != 0)
|
||||
break;
|
||||
|
||||
for (x = 0; x < font->width; x++)
|
||||
{
|
||||
for (y = 0; y < font->height; y++)
|
||||
{
|
||||
tinygl_draw_point (tinygl_point (x, y),
|
||||
tinygl_font_pixel_get (ch, x, y));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case TINYGL_TEXT_MODE_ROTATE_SCROLL_DOWN:
|
||||
display_scroll_down ();
|
||||
|
||||
for (x = 0; x < font->height; x++)
|
||||
{
|
||||
tinygl_draw_point (tinygl_point (x, 0),
|
||||
tinygl_font_pixel_get (ch, scroll_pos, x));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
scroll_pos++;
|
||||
if (scroll_pos > font->width)
|
||||
scroll_pos = 0;
|
||||
return scroll_pos == 0;
|
||||
}
|
||||
|
||||
|
||||
/** Advance message. */
|
||||
static void tinygl_text_advance (void)
|
||||
{
|
||||
if (!message1[message_index])
|
||||
message_index = 0;
|
||||
|
||||
if (message1[message_index])
|
||||
{
|
||||
if (tinygl_display_char (message1[message_index]))
|
||||
message_index++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Display a message repeatedly.
|
||||
@param string null terminated message to display. */
|
||||
void tinygl_text (const char *string)
|
||||
{
|
||||
message_index = 0;
|
||||
scroll_pos = 0;
|
||||
strncpy (message1, string, sizeof (message1));
|
||||
}
|
||||
|
||||
|
||||
/** Set the message update speed.
|
||||
@param speed text advance speed (characters per 10 s). */
|
||||
void tinygl_text_speed_set (uint8_t speed)
|
||||
{
|
||||
text_advance_period = update_rate / (speed * TINYGL_WIDTH) * 10;
|
||||
}
|
||||
|
||||
|
||||
/** Set the message display mode.
|
||||
@param mode display mode. */
|
||||
void tinygl_text_mode_set (tinygl_text_mode_t mode)
|
||||
{
|
||||
text_mode = mode;
|
||||
}
|
||||
|
||||
|
||||
/** Set the font to use for text.
|
||||
@param pfont pointer to font description. */
|
||||
void tinygl_font_set (font_t *pfont)
|
||||
{
|
||||
font = pfont;
|
||||
}
|
||||
|
||||
|
||||
/** Update display (refresh display and update message). */
|
||||
void tinygl_update (void)
|
||||
{
|
||||
static uint16_t tick = 0;
|
||||
|
||||
tick++;
|
||||
if (tick >= text_advance_period)
|
||||
{
|
||||
tick = 0;
|
||||
|
||||
tinygl_text_advance ();
|
||||
}
|
||||
|
||||
display_update ();
|
||||
}
|
||||
|
||||
|
||||
/** Initialise things.
|
||||
@param rate rate in Hz that tinygl_update called. */
|
||||
void tinygl_init (uint16_t rate)
|
||||
{
|
||||
update_rate = rate;
|
||||
|
||||
display_init ();
|
||||
|
||||
tinygl_text_speed_set (TINYGL_SPEED_DEFAULT);
|
||||
|
||||
tinygl_clear ();
|
||||
}
|
||||
+182
@@ -0,0 +1,182 @@
|
||||
/** @file tinygl.h
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 24 August 2010
|
||||
@brief Tiny graphics library.
|
||||
|
||||
@defgroup tinygl Tiny graphics library
|
||||
|
||||
<h3>Introduction to Tinygl</h3>
|
||||
|
||||
Tinygl is a tiny graphics library for a simple dot matrix
|
||||
display. This file declares the data types and graphics
|
||||
primitives provided by tinygl. The basic graphics primitive is
|
||||
a point. This specifies a pair of (x, y) coordinates on the
|
||||
display. Each point has an associated pixel value. Currently,
|
||||
this can be 0 for off and 1 for on.
|
||||
|
||||
|
||||
<h3>A simple Tinygl application</h3>
|
||||
|
||||
Here's a simple application that draws a line from (1, 2) to
|
||||
(3, 5). The paced loop runs at 1 kHz and this sets the display
|
||||
refresh period to 200 Hz since there are 5 columns.
|
||||
|
||||
@code
|
||||
#include "pacer.h"
|
||||
#include "tinygl.h"
|
||||
|
||||
void main (void)
|
||||
{
|
||||
pacer_init (1000);
|
||||
tinygl_init (1000);
|
||||
|
||||
tinygl_draw_line (tinygl_point (1, 2), tinygl_point (3, 5));
|
||||
|
||||
while (1)
|
||||
{
|
||||
pacer_wait ();
|
||||
tinygl_update ();
|
||||
}
|
||||
}
|
||||
@endcode
|
||||
|
||||
<h3>A Tinygl text application</h3>
|
||||
|
||||
Here's another simple application that displays a message.
|
||||
|
||||
@code
|
||||
#include "pacer.h"
|
||||
#include "tinygl.h"
|
||||
#include "../fonts/font5x7_1.h"
|
||||
|
||||
void main (void)
|
||||
{
|
||||
pacer_init (1000);
|
||||
tinygl_init (1000);
|
||||
|
||||
tinygl_font_set (&font5x7_1);
|
||||
tinygl_text_speed_set (10);
|
||||
tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL_LEFT);
|
||||
tinygl_text ("HELLO WORLD ");
|
||||
|
||||
while (1)
|
||||
{
|
||||
pacer_wait ();
|
||||
tinygl_update ();
|
||||
}
|
||||
}
|
||||
@endcode
|
||||
|
||||
*/
|
||||
|
||||
#ifndef TINYGL_H
|
||||
#define TINYGL_H
|
||||
|
||||
#include "system.h"
|
||||
#include "display.h"
|
||||
#include "font.h"
|
||||
|
||||
/** Define size of display. */
|
||||
#define TINYGL_WIDTH DISPLAY_WIDTH
|
||||
#define TINYGL_HEIGHT DISPLAY_HEIGHT
|
||||
|
||||
|
||||
/** Define a pixel value. Currently the only supported values are 0
|
||||
for off and 1 for on. */
|
||||
typedef uint8_t tinygl_pixel_value_t;
|
||||
|
||||
|
||||
/** Define a display coordinate. Note these are signed to allow
|
||||
relative coordinates. */
|
||||
typedef int8_t tinygl_coord_t;
|
||||
|
||||
|
||||
/** Define a point as a pair of coordinates. The display origin is the
|
||||
top left corner. */
|
||||
typedef struct tinygl_point
|
||||
{
|
||||
tinygl_coord_t x;
|
||||
tinygl_coord_t y;
|
||||
} tinygl_point_t;
|
||||
|
||||
|
||||
/** Define text display modes. */
|
||||
typedef enum
|
||||
{
|
||||
/* Stepping text. */
|
||||
TINYGL_TEXT_MODE_STEP,
|
||||
/** Scrolling text. */
|
||||
TINYGL_TEXT_MODE_SCROLL_LEFT,
|
||||
/** Rotated scrolling text. */
|
||||
TINYGL_TEXT_MODE_ROTATE_SCROLL_DOWN
|
||||
} tinygl_text_mode_t;
|
||||
|
||||
|
||||
/** Construct a point from a pair of coordinates.
|
||||
@param x x coordinate
|
||||
@param y y coordinate
|
||||
@return point. */
|
||||
static inline tinygl_point_t tinygl_point (tinygl_coord_t x, tinygl_coord_t y)
|
||||
{
|
||||
tinygl_point_t point = {x, y};
|
||||
|
||||
return point;
|
||||
}
|
||||
|
||||
|
||||
/** Display a message repeatedly.
|
||||
@param string null terminated message to display. */
|
||||
void tinygl_text (const char *string);
|
||||
|
||||
|
||||
/** Set the message update speed.
|
||||
@param speed text advance speed (characters per 10 s). */
|
||||
void tinygl_text_speed_set (uint8_t speed);
|
||||
|
||||
|
||||
/** Set the message display mode.
|
||||
@param mode display mode. */
|
||||
void tinygl_text_mode_set (tinygl_text_mode_t mode);
|
||||
|
||||
|
||||
/** Set the font to use for text.
|
||||
@param pfont pointer to font description. */
|
||||
void tinygl_font_set (font_t *pfont);
|
||||
|
||||
|
||||
/** Draw point.
|
||||
@param point coordinates of point
|
||||
@param pixel_value pixel value to draw point. */
|
||||
void tinygl_draw_point (tinygl_point_t point, tinygl_pixel_value_t pixel_value);
|
||||
|
||||
|
||||
/** Draw line.
|
||||
@param point1 coordinates of start of line
|
||||
@param point2 coordinates of end of line
|
||||
@param pixel_value pixel value to draw line. */
|
||||
void tinygl_draw_line (tinygl_point_t point1, tinygl_point_t point2,
|
||||
tinygl_pixel_value_t pixel_value);
|
||||
|
||||
|
||||
/** Draw box.
|
||||
@param tl coordinates of top left corner of box
|
||||
@param br coordinates of bottom right of box
|
||||
@param pixel_value pixel value to draw box. */
|
||||
void tinygl_draw_box (tinygl_point_t tl, tinygl_point_t br,
|
||||
tinygl_pixel_value_t pixel_value);
|
||||
|
||||
|
||||
/** Clear display. */
|
||||
void tinygl_clear (void);
|
||||
|
||||
|
||||
/** Update display and advance message. */
|
||||
void tinygl_update (void);
|
||||
|
||||
|
||||
/** Initialise things.
|
||||
@param rate rate in Hz that tinygl_update called. */
|
||||
void tinygl_init (uint16_t rate);
|
||||
|
||||
|
||||
#endif /* TINYGL_H */
|
||||
@@ -0,0 +1,34 @@
|
||||
/** @file uint8toa.c
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 15 May 2007
|
||||
@brief
|
||||
*/
|
||||
#include "system.h"
|
||||
|
||||
|
||||
/** Convert 8 bit unsigned number to decimal ASCII string. This uses
|
||||
much less memory than sprintf.
|
||||
@param num number to convert
|
||||
@param str pointer to array of at least 4 chars to hold string
|
||||
@param leading_zeroes non-zero to pad with leading zeroes. */
|
||||
void
|
||||
uint8toa (uint8_t num, char *str, bool leading_zeroes)
|
||||
{
|
||||
uint8_t d;
|
||||
uint8_t i;
|
||||
uint8_t const powers[] = {100, 10, 1, 0};
|
||||
|
||||
for (i = 0; (d = powers[i]); i++)
|
||||
{
|
||||
uint8_t q;
|
||||
|
||||
q = num / d;
|
||||
if (leading_zeroes || q || d == 1)
|
||||
{
|
||||
*str++ = '0' + q;
|
||||
num -= q * d;
|
||||
leading_zeroes = 1;
|
||||
}
|
||||
}
|
||||
*str = '\0';
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/** @file uint8toa.h
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 21 Nov 2006
|
||||
@brief 8 bit unsigned int to ASCII conversion.
|
||||
|
||||
@defgroup uint8toa 8 bit unsigned int to ASCII conversion
|
||||
*/
|
||||
|
||||
#ifndef UINT8TOA_H
|
||||
#define UINT8TOA_H
|
||||
|
||||
#include "system.h"
|
||||
|
||||
|
||||
/** Convert 8 bit unsigned number to decimal ASCII string. This uses
|
||||
much less memory than sprintf.
|
||||
@param num number to convert
|
||||
@param str pointer to array of at least 4 chars to hold string
|
||||
@param leading_zeroes non-zero to pad with leading zeroes. */
|
||||
void uint8toa (uint8_t num, char *str, bool leading_zeroes);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user