![]() |
ucglib_xmega_hal
2.1
Xmega Hardware Abstraction Layer for Ucglib
|
Xmega Hardware Abstraction Layer for ucglib from Oli Kraus. More...
#include <avr/io.h>
#include <util/delay.h>
#include "csrc/ucg.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "ucglib_xmega_hal.h"
Data Structures | |
struct | ucg_print_t |
Macros | |
#define | F_CPU 320000000UL |
System clock is 32 MHz. | |
Functions | |
void | ucg_SetPrintPos (ucg_t *ucg, ucg_int_t x, ucg_int_t y) |
Sets the position for next "print" command. More... | |
void | ucg_GetPrintPos (ucg_t *ucg, ucg_int_t *x, ucg_int_t *y) |
Gets the current position of the 'print cursor'. More... | |
void | ucg_SetPrintDir (ucg_t *ucg, uint8_t dir) |
Sets the direction for next "print" command. More... | |
void | ucg_Print (ucg_t *ucg, char *fmt,...) |
Put a formatted string to the display at the current position and in the current direction. More... | |
void | ucg_PrintInit (ucg_t *ucg) |
Initializes the printing facilities compatible with Arduino/C++ version of library. More... | |
void | ucg_BitmapPrint (ucg_t *ucg, ucg_int_t xoffset, ucg_int_t yoffset, ucg_int_t width, ucg_int_t height, uint8_t nbytes, const __memx uint8_t *bitmap) |
Prints a bitmap to the display. More... | |
int16_t | ucg_comm_xmega (ucg_t *ucg, int16_t msg, uint16_t arg, uint8_t *data) |
The callback function for communication between the Xmega and the display. More... | |
Variables | |
ucg_t * | curr_ucg |
global pointer necessary for the printing facilities | |
Xmega Hardware Abstraction Layer for ucglib from Oli Kraus.
This Hardware Abstraction Layer is created confirm the <a href"https://github.com/olikraus/ucglib/wiki/hal">instructions of Oli Kraus.
This file contains a callback function ucg_com_xmega_bb()
that handles the communication with the Xmega using SPI or bit banging. The Arduino/C++ implementation of ucglib contains extra printing facilities. This file contains a bunch of functions that implements the same facilities. So you can use ucg_SetPrintPos()
, ucg_SetPrintDir()
and in stead of print
and println
you can use ucg_Print()
which prints a formatstring.
This print facility uses a hook in the struct ucg_t. Add to the struct these lines:
* #ifdef __AVR_XMEGA__ * void *xmega_hook; // added pointer for print hook * #endif
or uses the ucg.h of the HAL package in stead
void ucg_BitmapPrint | ( | ucg_t * | ucg, |
ucg_int_t | xoffset, | ||
ucg_int_t | yoffset, | ||
ucg_int_t | width, | ||
ucg_int_t | height, | ||
uint8_t | nbytes, | ||
const __memx uint8_t * | bitmap | ||
) |
Prints a bitmap to the display.
ucg | pointer to struct for the display |
xoffset | the x-position of the upper left corner of the bitmap |
yoffset | the y-position of the upper left corner of the bitmap |
width | the width of the bitmap in pixels |
height | the height of the bitmap in pixels |
nbytes | the number of bytes of one pixel; must always be 3 (RGB) |
bitmap | the pointer to a const unit8_t array with the bitmap. The bitmap must be smaller than 32K (largest AVR variable) Large bitmaps can be split in smaller parts The bitmaps can be located in the program memory or in the data memory:
|
The drawback of using __memx is that it is slower than __flash. This is because _memx uses a 24-bits pointer and __flash uses a 16-bit pointer. A sequence of two 30240 bytes bitmaps takes with __falsh 3013 ms and with __memx 3063 ms.
int16_t ucg_comm_xmega | ( | ucg_t * | ucg, |
int16_t | msg, | ||
uint16_t | arg, | ||
uint8_t * | data | ||
) |
The callback function for communication between the Xmega and the display.
ucg | pointer to struct for the display |
msg | number of the message (action to be done) |
arg | depends on msg: number of arguments, number of microseconds, ... |
data | pointer to 8-bit data-array with bytes that needs to be send |
void ucg_GetPrintPos | ( | ucg_t * | ucg, |
ucg_int_t * | x, | ||
ucg_int_t * | y | ||
) |
Gets the current position of the 'print cursor'.
ucg | pointer to struct for the display |
x | pointer to a variable for the x-coordinate of the current position |
y | pointer to a variable for the y-coordinate of the current position |
void ucg_Print | ( | ucg_t * | ucg, |
char * | fmt, | ||
... | |||
) |
Put a formatted string to the display at the current position and in the current direction.
This replaces print and println from the Arduino implementation of ucg_lib
The Arduino style:
* ucg.print("text "); * ucg.print(x); // x is an int * ucg.print(" more text "); * ucg.print(y); // y is a float * ucg.println(";");
The replacement in Xmega style:
* ucg_Print(&ucg, "text %d more text %f;\n", x, y);
ucg | pointer to struct for the display |
fmt | formatstring with escape sequences |
... | variables that are printed |
void ucg_PrintInit | ( | ucg_t * | ucg | ) |
Initializes the printing facilities compatible with Arduino/C++ version of library.
ucg | pointer to struct for the display |
void ucg_SetPrintDir | ( | ucg_t * | ucg, |
uint8_t | dir | ||
) |
Sets the direction for next "print" command.
ucg | pointer to struct for the display |
dir | the direction |
void ucg_SetPrintPos | ( | ucg_t * | ucg, |
ucg_int_t | x, | ||
ucg_int_t | y | ||
) |
Sets the position for next "print" command.
ucg | pointer to struct for the display |
x | x-coordinate of the position |
y | y-coordinate of the position |