ucglib_xmega_hal  4.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/ucg.h"
#include "ucglib_xmega.h"

Macros

#define _XMEGA_TRANSFER_SPI(x)
 macro for fast communications More...
 

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_commXmega (ucg_t *ucg, int16_t msg, uint16_t arg, uint8_t *data)
 The callback function for communication between the Xmega and the display. More...
 
int16_t ucg_commXmegaSPI (ucg_t *ucg, int16_t msg, uint16_t arg, uint8_t *data)
 The callback function for communication with SPI between the Xmega and the display. More...
 

Detailed Description

Xmega Hardware Abstraction Layer for ucglib from Oli Kraus.

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

This Hardware Abstraction Layer is created confirm the 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 two callback function. The function ucg_com_xmega() handles the communication with the Xmega using SPI or bit banging. Bit banging is more flexable, but 1.2 to 2 times slower.

Earlier versions of this HAL (version 2.0, 2.1 and 3.0) contain some extensions for printing facilities and for using images. These extensions are now placed in separated files (ucg_print.c and ucg_bmp.c) that can be added to ucglib.

These HAL uses two static variables. It is not so complicated to add these to the ucg_t struct. In that case you can use multiple displays, but because of the overhead that solution will be about 20% slower.

Macro Definition Documentation

◆ _XMEGA_TRANSFER_SPI

#define _XMEGA_TRANSFER_SPI (   x)
Value:
_commInterface.pSPI->DATA = (x);\
while(!(_commInterface.pSPI->STATUS & (SPI_IF_bm)));

macro for fast communications

Function Documentation

◆ ucg_commXmega()

int16_t ucg_commXmega ( 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_commXmegaSPI()

int16_t ucg_commXmegaSPI ( ucg_t *  ucg,
int16_t  msg,
uint16_t  arg,
uint8_t *  data 
)

The callback function for communication with SPI 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

This specific function can only be used with SPI and is about 25% faster than the general ucg_commXmega

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

void ucg_printXmegaConnection ( void  )

Print (debugging) the connections with the Xmega.

Returns
void