ucglib_xmega_hal  3.0
Xmega Hardware Abstraction Layer for Ucglib
ucglib_xmega_hal Documentation

Introduction

This is the Xmega Hardware Abstraction Layer for the C implementation of the ucglib library from Oli Kraus

The C implementation of the ucglib library can be found at https://github.com/olikraus/ucglib/tree/master/csrc

This HAL contains four c- and h-files:

ucglib_xmega_hal.c Functions for the HAL
ucglib_xmega.h Prototypes and definitions of the HAL including the ucg.h with the extra hook
ucg.h An adjusted ucg.h with a extra hook for printing facilities
main_test_hal.c An example for a 1.8 inch TFT LCD Module

The struct ucg_t in the adjusted ucg.h has an extra field at the end on the struct:

*           #ifdef __AVR_XMEGA__
*           void  *xmega_hook;   // added pointer for print hook
*           #endif 

This HAL also contains a precompiled library for the ATxmega256a3u:

ucglib_xmega.a All precompiled functions of ucglib and all precompiled functions of the HAL
ucglib_xmega.h Prototypes and definitions of the HAL including the ucg.h with the extra hook
main_test_library.c An example for a 1.8 inch TFT LCD Module

You can use the precompiled library

The examples uses the 32 MHz clock. So you need clock.c and clock.h from http://dolman-wim.nl/xmega/libraries/index.php

Note
Important difference between version 2.1 and version 3.0
The Hardware Abstraction Layer version 2.1 uses #define's to define the connections.
The Hardware Abstraction Layer version 3.0 uses a function and an array with pindefinitions to define the connections.

Usage HAL

These are the steps for using ucglib with a Xmega

  • Add main_test_hal.c, ucglib_xmega_hal.c and ucglib_xmega.h to an Atmel Studio project
  • Add clock.c and clock.h to the project
  • Add a empty folder to this project
  • rename this folder as csrc
  • Add all files from the csrc folder of Oli Kraus in the empty csrc folder in the project
  • Copy ucg.h from ucglib_xmega_hal to csrc folder in the project. (overwriting the original ucg.h)
  • Build the solution, ignore the six warnings
  • Program the device
  • Connect the 1.8 inch TFT LCD Module with the Xmega:
    *             Display           Xmega
    *             VCC               3V3
    *             GND               GND
    *             CS                D4  (SS)
    *             RESET             D3
    *             A0   (DC or CD)   D2
    *             SDA               D5  (MOSI)
    *             SCK               D7  (SCK)
    *             LED  (BLK)        D1 
    *                               D6  (MISO)  not connected 

Usage precompiled library

These are the steps for using the precompiled atxmega256a3u library

  • Add main_test_library.c, and ucglib_xmega.h to an Atmel Studio project
  • Add the library ucglib_xmega.a to the project
  • Add clock.c and clock.h to the project
  • Build the solution
  • Program the device
  • Connect the 1.8 inch TFT LCD Module with the Xmega:
    *             Display           Xmega
    *             VCC               3V3
    *             GND               GND
    *             CS                D4  (SS)
    *             RESET             D3
    *             A0   (DC or CD)   D2
    *             SDA               D5  (MOSI)
    *             SCK               D7  (SCK)
    *             LED  (BLK)        D1 
    *                               D6  (MISO)  not connected 

Usage building the library

These are the steps for building a precompiled static library

  • Start a new Atmel project called ucglib_xmega for a static library ucglib_xmega
  • Add all files from the csrc folder of Oli Kraus to the project
  • Add from Hardware Abstraction Layer the files ucglib_xmega_hal.c and ucglib_xmega.h to the project
  • Copy ucg.h from ucglib_xmega_hal to the project. (overwriting the original ucg.h)
  • Modify in the accompanying ucglib_xmega.h possibly line 34 if an other device is used
  • Build the project, ignore the six warnings
  • In Output Files a static library ucglib_xmega.a will be created

SPI or Bit Banging

This HAL uses for the serial communication SPI or bit banging. With SPI the display must connected to one of the SPI's of the Xmega. With bit banging all connections are available

Test with TFT-display

The test uses this 1.8 inch TFT LCD Module:

display_pinout_scaled.jpg

The configuration for using SPI of port D. Declare an array of pins for the non-SPI connections

*     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 }
*     }; 

Call the connect function before you call ucg_Init:

*     ucg_connectXmega(&SPID, connectArraySPI, 0); 

The configuration for bit banging Declare an array all connections

*      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_NULL }    
*     }; 

Call the connect function before you call ucg_Init:

*     ucg_connectXmega(NULL, connectArrayBBcompatibelSPID, 0); 

LED (BLK) connection

The BLK connection of the display can be connected to the Xmega or external to VCC. If the third parameter in the function ucg_connectXmega() is 1 the pin of the Xmega that is connected to BLK will be disabled. This makes it possible to make a tight connection between the Xmega an the display on a breadboard.

display_connect_direct_scaled.jpg

The connections are listed here:

*             Display           Xmega/power
*             VCC               3V3
*             GND               GND
*             CS                D0 
*             RESET             D1
*             A0   (DC or CD)   D2
*             SDA               D3 
*             SCK               D4  
*             LED  (BLK)        D5 (Disabled), connect LED direct to 3V3 or 5V  

Bitmaps

From version 2.1 a function ucg_BitmapPrint() is added. This function prints a bitmap to the display. The bitmap is an array with rgb-pixels. The size of the array may not exceed the 32K limit. Pictures larger than 32K must be split in smaller blocks.

Two examples can be found in the folder examples.

A non-AVR program to split a PNG file in multiple arrays can be found in the folder gcc.

Contact

Author
Wim Dolman (w.e.dolman@hva.nl)
Version
3.0
Latest version can be found here: http://dolman-wim.nl/xmega/libraries/index.php
Date
30-05-2020

License

This library is free software. You can redistribute it and/or modify it. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.