ucglib_xmega_hal  3.0
Xmega Hardware Abstraction Layer for Ucglib
ucglib_xmega_hal.c File Reference

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

#include <avr/io.h>
#include <util/delay.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "ucglib_xmega.h"

Functions

void ucg_connectXmega (void *pInterface, pin_t *pArray, uint8_t blkDisabled)
 Defines the connections of the display with the Xmega. More...
 
void ucg_printXmegaConnection (void)
 Print (debugging) the connections with the Xmega. 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...
 
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_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_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...
 

Detailed Description

Xmega Hardware Abstraction Layer for ucglib from Oli Kraus.

Author
Wim Dolman (w.e.dolman@hva.nl)
Date
30-05-2020
Version
3.0

This Hardware Abstraction Layer is created confirm the <a href"https://github.com/olikraus/ucglib/wiki/hal">instructions of Oli Kraus.

The function ucg_connectXmega() sets the connections between the Xmega and the display. The function ucg_printXmegaConnection() prints the connections to the standard output.

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. The adapted ucg.h is included in this headerfile.

The function ucg_BitmapPrint() print a bitmap to the display. The bitmap is a headerfile in plain C. The maximum bitmap size is 32768 kB. To show large images the image must be split in smaller bitmaps.

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:
             -# 'const uint8_t array[]' will be placed the data memory.
                    for atXmega256a3u devices the largest array ia 16K.
             -# 'const uint8_t __flash array[]' will be placed only in the program memory.
                    for atXmega256a3u devices the maximum space is 64K
             -# 'const uint8_t array[] PROGMEM' will be placed only in the program memory.
                    for atXmega256a3u devices the maximum space is 64K 
             -# '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 __flash 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_connectXmega()

void ucg_connectXmega ( void *  pInterface,
pin_t pArray,
uint8_t  blkDisabled 
)

Defines the connections of the display with the Xmega.

Parameters
pInterfacepointer to the SPI-interface
pArraypointer to an array with pinconnections
blkDisabledindex to disable BLK-connection
       1. If pInterface is NULL bit banging is used.

       2. The pointer pArray points to an array with pins.
       A pin consist of three elements: an index, a pointer
       to a port and a pinposition. 
       The last element is UCG_XMEGA_PIN_NULL.
       Example 1 using a SPI-interface:
pin_t connectArraySPI[] = {
*                 { UCG_XMEGA_PIN_RST, &PORTD, PIN3_bp },   // RST
*                 { UCG_XMEGA_PIN_CD,  &PORTD, PIN2_bp },   // CD
*                 { UCG_XMEGA_PIN_BLK, &PORTD, PIN1_bp },   // BLK
*                 { UCG_XMEGA_PIN_NULL }
*             }; 

Example 2 using bit banging:

pin_t connectArrayBBcompatibelSPID[] = {
*               { UCG_XMEGA_PIN_SCK, &PORTD, PIN7_bp },   // SCK
*               { UCG_XMEGA_PIN_SDA, &PORTD, PIN5_bp },   // SDA
*               { UCG_XMEGA_PIN_CS,  &PORTD, PIN4_bp },   // CS
*               { UCG_XMEGA_PIN_RST, &PORTD, PIN3_bp },   // RST
*               { UCG_XMEGA_PIN_CD,  &PORTD, PIN2_bp },   // CD
*               { UCG_XMEGA_PIN_BLK, &PORTD, PIN1_bp },   // BLK
*               { UCG_XMEGA_PIN_NULL }    
*             }; 
  1. If blkDisabled is 1 the pin of the XMega that is connected to BLK will disabled. On a breadboard it is now possible to connect VCC to BLK. Be carefull with a powerline of 5V!
Returns
void

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

void ucg_printXmegaConnection ( void  )

Print (debugging) the connections with the Xmega.

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