ucglib_xmega_hal  2.1
Xmega Hardware Abstraction Layer for Ucglib
ucglib_xmega_hal.h File Reference

Xmega Hardware Abstraction Layer for ucglib from Oli Kraus. More...

#include "csrc/ucg.h"

Go to the source code of this file.

Macros

#define UCG_XMEGA_USING_SPI   0
 value defining SPI is used
 
#define UCG_XMEGA_USING_BB   1
 value defining bit banging is used
 
#define UCG_XMEGA_BLK_CONNECT   0
 value defining BLK/LED is connected to Xmega
 
#define UCG_XMEGA_BLK_EXTERN   1
 value defining BLK/LED is not connected with Xmega
 
#define UCG_XMEGA_BLK_DISABLED   2
 value defining BLK/LED is connected with Xmega, but pin is disabled
 
#define UCG_XMEGA_USE   UCG_XMEGA_USING_SPI
 defining the use of SPI or bit banging
 
#define UCG_XMEGA_BLK   UCG_XMEGA_BLK_DISABLED
 defining the status of the BLK or LED connection
 
#define UCG_XMEGA_INTERFACE   SPID
 SPI interface used.
 
#define UCG_XMEGA_SPI_PORT   PORTD
 port SPI interface using SPI
 
#define UCG_XMEGA_BB_PORT   PORTD
 port SPI interface using BB
 
#define UCG_XMEGA_SPI_SCK_PORT   UCG_XMEGA_SPI_PORT
 port SCK connection using SPI
 
#define UCG_XMEGA_SPI_MOSI_PORT   UCG_XMEGA_SPI_PORT
 port SDA or MOSI connection using SPI
 
#define UCG_XMEGA_SPI_MISO_PORT   UCG_XMEGA_SPI_PORT
 port MISO connection using SPI (not connected)
 
#define UCG_XMEGA_SPI_SS_PORT   UCG_XMEGA_SPI_PORT
 port CS or SS connection using SPI
 
#define UCG_XMEGA_SPI_RESET_PORT   UCG_XMEGA_SPI_PORT
 port RESET connection using SPI
 
#define UCG_XMEGA_SPI_CD_PORT   UCG_XMEGA_SPI_PORT
 port CD or DC or AO connection using SPI
 
#define UCG_XMEGA_SPI_BLK_PORT   UCG_XMEGA_SPI_PORT
 port BLK or LED connection using SPI (optional)
 
#define UCG_XMEGA_BB_SCK_PORT   UCG_XMEGA_BB_PORT
 port SCK connection using BB
 
#define UCG_XMEGA_BB_SDA_PORT   UCG_XMEGA_BB_PORT
 port SDA or MOSI connection using BB
 
#define UCG_XMEGA_BB_CS_PORT   UCG_XMEGA_BB_PORT
 port CS or SS connection using BB
 
#define UCG_XMEGA_BB_RESET_PORT   UCG_XMEGA_BB_PORT
 port RESET connection using BB
 
#define UCG_XMEGA_BB_CD_PORT   UCG_XMEGA_BB_PORT
 port CD or DC or AO connection using BB
 
#define UCG_XMEGA_BB_BLK_PORT   UCG_XMEGA_BB_PORT
 port BLK or LED connection using BB (optional)
 
#define UCG_XMEGA_SPI_SCK_bp   PIN7_bp
 pin position of SCK connection using SPI
 
#define UCG_XMEGA_SPI_MISO_bp   PIN6_bp
 pin position of MISO connection using SPI
 
#define UCG_XMEGA_SPI_MOSI_bp   PIN5_bp
 pin position of MOSI connection using SPI
 
#define UCG_XMEGA_SPI_SS_bp   PIN4_bp
 pin position of SS connection using SPI
 
#define UCG_XMEGA_SPI_RESET_bp   PIN3_bp
 pin position of RESET connection
 
#define UCG_XMEGA_SPI_CD_bp   PIN2_bp
 pin position of CD or DC or AO connection
 
#define UCG_XMEGA_SPI_BLK_bp   PIN1_bp
 pin position of BLK or LED connection (optional)
 
#define UCG_XMEGA_BB_SCK_bp   PIN4_bp
 pin position of SCK connection using BB
 
#define UCG_XMEGA_BB_SDA_bp   PIN3_bp
 pin position of SDA (MOSI) connection using using BB
 
#define UCG_XMEGA_BB_CS_bp   PIN0_bp
 pin position of CS or SS connection BB
 
#define UCG_XMEGA_BB_RESET_bp   PIN1_bp
 pin position of RESET connection using BB
 
#define UCG_XMEGA_BB_CD_bp   PIN2_bp
 pin position of CD or DC or AO connection using BB
 
#define UCG_XMEGA_BB_BLK_bp   PIN5_bp
 pin position of BLK or LED connection using BB (optional)
 

Functions

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...
 
void ucg_PrintInit (ucg_t *ucg)
 Initializes the printing facilities compatible with Arduino/C++ version of library. More...
 
void ucg_SetPrintPos (ucg_t *ucg, ucg_int_t x, ucg_int_t y)
 Sets the position for next "print" command. 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_GetPrintPos (ucg_t *ucg, ucg_int_t *x, ucg_int_t *y)
 Gets the current position of the 'print cursor'. 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 ncolors, const __memx uint8_t *bitmap)
 Prints a bitmap to the display. More...
 

Detailed Description

Xmega Hardware Abstraction Layer for ucglib from Oli Kraus.

Author
Wim Dolman (w.e.dolman@hva.nl)
Date
23-02-2020
Version
2.1

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() 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

Function Documentation

◆ ucg_BitmapPrint()

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.

Parameters
ucgpointer to struct for the display
xoffsetthe x-position of the upper left corner of the bitmap
yoffsetthe y-position of the upper left corner of the bitmap
widththe width of the bitmap in pixels
heightthe height of the bitmap in pixels
nbytesthe number of bytes of one pixel; must always be 3 (RGB)
bitmapthe 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:
  1. 'const uint8_t array[]' will be placed the data memory. for atXmega256a3u devices the largest array ia 16K.
  2. 'const uint8_t __flash array[]' will be placed only in the program memory. for atXmega256a3u devices the maximum space is 64K
  3. 'const uint8_t array[] PROGMEM' will be placed only in the program memory. for atXmega256a3u devices the maximum space is 64K this function doesn't uses "far-pointers"
  4. 'const uint8_t __memx array[]' will be placed only in the program memory. with __memx the complete program space can be used for atXmega256a3u devices the maximum space is 256K

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.

Returns
void

◆ ucg_comm_xmega()

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.

Parameters
ucgpointer to struct for the display
msgnumber of the message (action to be done)
argdepends on msg: number of arguments, number of microseconds, ...
datapointer to 8-bit data-array with bytes that needs to be send
Returns
16-bit value, always 1

◆ ucg_GetPrintPos()

void ucg_GetPrintPos ( ucg_t *  ucg,
ucg_int_t *  x,
ucg_int_t *  y 
)

Gets the current position of the 'print cursor'.

Parameters
ucgpointer to struct for the display
xpointer to a variable for the x-coordinate of the current position
ypointer to a variable for the y-coordinate of the current position
Returns
void

◆ ucg_Print()

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); 
Parameters
ucgpointer to struct for the display
fmtformatstring with escape sequences
...variables that are printed
Returns
void

◆ ucg_PrintInit()

void ucg_PrintInit ( ucg_t *  ucg)

Initializes the printing facilities compatible with Arduino/C++ version of library.

Parameters
ucgpointer to struct for the display
Returns
void

◆ ucg_SetPrintDir()

void ucg_SetPrintDir ( ucg_t *  ucg,
uint8_t  dir 
)

Sets the direction for next "print" command.

Parameters
ucgpointer to struct for the display
dirthe direction
Returns
void

◆ ucg_SetPrintPos()

void ucg_SetPrintPos ( ucg_t *  ucg,
ucg_int_t  x,
ucg_int_t  y 
)

Sets the position for next "print" command.

Parameters
ucgpointer to struct for the display
xx-coordinate of the position
yy-coordinate of the position
Returns
void