MAXREFDES71# Code Documentation  V01.00
MAXREFDES71# 2-Channel Analog Input/Analog Output
 All Data Structures Files Functions Variables Macros Pages
utilities.c File Reference
#include "xparameters.h"
#include "stdio.h"
#include "utilities.h"
#include "MAXREFDES71.h"

Go to the source code of this file.

Macros

#define UART_BASEADDR   XPAR_XUARTPS_0_BASEADDR
 
#define OLED_VBAT   0x20
 
#define OLED_VDD   0x10;
 
#define OLED_RESET_B   0x08
 
#define OLED_DATA_COMMAND_B   0x04
 
#define OLED_SDIN   0x02
 
#define OLED_SCLK   0x01
 

Functions

void delay (int nStopValue)
 Loop for nStopValue iterations to provide a delay.
 
void led_knight_rider (XGpio *pLED_GPIO, int nNumberOfTimes)
 Blink a row of LEDs nNumberOfTimes times.
 
int number_raised_to_power (int nBase, int nExponent)
 Raise nBase to the nExponent power (operates with integers only).
 
void print_asterisks (int nQuantity)
 Print nQuantity of asterisks to the default Hyperterminal UART.
 
u8 getUartByte (u32 nUartAddress)
 Get a byte from either the full UART in the Zynq PS, or a Xilinx UartLite.
 
void sendUartByte (u32 unUartAddress, u8 uchByte)
 Send a byte to the UART. Either directs to the full UART in the Zynq PS, or a Xilinx UartLite.
 
u8 checkUartEmpty (u32 unUartAddress)
 Check if either Uart is empty. Either directs to the full UART in the Zynq PS, or a Xilinx UartLite.
 
void initializeOLED (u8 *pFont)
 Initializes the OLED display.
 
void sendOLEDSPI (u8 uchDataToWrite)
 Bit bang routine for Zedboard SPI OLED interface.
 
void clearOLEDBuffer (u8 *pauchBuffer)
 Clears the OLED display buffer.
 
void displayOLEDBuffer (u8 *pauchBuffer)
 Copies the display buffer into the OLED display.
 
void putCharOLED (int x, int y, char chCharacter)
 Places a single ASCII character into the OLED display buffer.
 
void printfToBufferOLED (int x, int y, char *chString)
 Printf-like function to copy an ASCII string into the OLED display buffer.
 
void printfToOLED (int x, int y, char *chString)
 Printf-like function to copy an ASCII string into the OLED display buffer.
 
void flipAndCopyDisplayBuffer (u8 *pauchSourceBuffer, u8 *pauchDestinationBuffer)
 Copies the pixels from the source display buffer, into the destination buffer, flipping their location 180 degrees.
 

Detailed Description


      Project: Maxim Plug-in Peripheral Modules
     Filename: utilities.c
  Description: This module contains a collection of general utility
               functions which are not specific to any particular
               module.

Revision History:
4-13-12 Rev 1.0 Seth Messimer Initial Release
7-20-12 Rev 1.4 Nathan Young Additional functions


This code follows the following naming conventions.

char chPmodValue char (array) sPmodString[16] float fPmodValue int nPmodValue int (array) anPmodValue[16] u16 uPmodValue u8 uchPmodValue u8 (array) auchPmodBuffer[16] unsigned int unPmodValue int * punPmodValue


Definition in file utilities.c.

Macro Definition Documentation

#define OLED_DATA_COMMAND_B   0x04

Definition at line 71 of file utilities.c.

#define OLED_RESET_B   0x08

Definition at line 70 of file utilities.c.

#define OLED_SCLK   0x01

Definition at line 73 of file utilities.c.

#define OLED_SDIN   0x02

Definition at line 72 of file utilities.c.

#define OLED_VBAT   0x20

Definition at line 68 of file utilities.c.

#define OLED_VDD   0x10;

Definition at line 69 of file utilities.c.

#define UART_BASEADDR   XPAR_XUARTPS_0_BASEADDR

Definition at line 66 of file utilities.c.

Function Documentation

u8 checkUartEmpty ( u32  unUartAddress)

Check if either Uart is empty. Either directs to the full UART in the Zynq PS, or a Xilinx UartLite.

Parameters
[in]unUartAddress.32 bit UART address
Return values
Trueif empty (false if not)

Definition at line 215 of file utilities.c.

void clearOLEDBuffer ( u8 *  pauchBuffer)

Clears the OLED display buffer.

Details
This function clears the display buffer by setting all pixels to zero.
Parameters
[in]*pauchBuffer- pointer to an u8 array used for the OLED pixel buffer
Return values
None

Definition at line 415 of file utilities.c.

void delay ( int  nStopValue)

Loop for nStopValue iterations to provide a delay.

Details
It is commonly used with the constant 'ABOUT_ONE_SECOND' defined in maximPMOD.h for setting approximate delays
Parameters
[in]nStopValue- number of iterations to loop
Return values
None

Definition at line 75 of file utilities.c.

void displayOLEDBuffer ( u8 *  pauchBuffer)

Copies the display buffer into the OLED display.

Details
This function writes the the display buffer into the OLED display using the page mode setting.
Note: The Zedboard OLED display contains a Solomon SSD1306 display controller.
Parameters
[in]*pauchBuffer- pointer to an u8 array used for the OLED pixel buffer
Return values
None

Definition at line 432 of file utilities.c.

void flipAndCopyDisplayBuffer ( u8 *  pauchSourceBuffer,
u8 *  pauchDestinationBuffer 
)

Copies the pixels from the source display buffer, into the destination buffer, flipping their location 180 degrees.

Details
The (0,0) pixel location on the OLED display is in the bottom right corner. This function flips the display so that the (0,0) is in the top left corner and (131,31) is in the bottom right.
Parameters
[in]*pauchSourceBuffer- pointer to an u8 buffer used as the source display buffer
[in]*pauchDestinationBuffer- pointer to an u8 buffer used as the destination display buffer
Return values
None

Definition at line 586 of file utilities.c.

u8 getUartByte ( u32  nUartAddress)

Get a byte from either the full UART in the Zynq PS, or a Xilinx UartLite.

Parameters
[in]unUartAddress.32 bit UART address
Return values
Returnsthe next byte from the Uart Rx FIFO

Definition at line 174 of file utilities.c.

void initializeOLED ( u8 *  pFont)

Initializes the OLED display.

Details
This function initializes the OLED display and the global data structure that holds the OLED display buffer and font.
Parameters
[in]*pFont- pointer to an u8 array containing the ASCII display font
Return values
None

Definition at line 252 of file utilities.c.

void led_knight_rider ( XGpio *  pLED_GPIO,
int  nNumberOfTimes 
)

Blink a row of LEDs nNumberOfTimes times.

Details
The Digilent NEXYS-3 and Zedboard have 8 green LEDs located above the toggle switches. This function blinks them back/forth (a bit like the KITT car from Knight Rider)
Parameters
[in]*pLED_GPIO- address of the GPIO peripheral driving the LEDs in MicroBlaze memory map
Return values
None

Definition at line 96 of file utilities.c.

int number_raised_to_power ( int  nBase,
int  nExponent 
)

Raise nBase to the nExponent power (operates with integers only).

Details
Many Microblaze applications will not have math.h included due to limited memory space. This is a simple functions to implement (nBase ^ nExponent) Some Maxim devices (such as MAX44009) return values in mantissa + (power of 2) exponent format.
Parameters
[in]nBase- base
[in]nExponent- exponent
Return values
Base^Exponent

Definition at line 131 of file utilities.c.

void print_asterisks ( int  nQuantity)

Print nQuantity of asterisks to the default Hyperterminal UART.

Parameters
[in]nQuantity- number of asterisks to print
Return values
None

Definition at line 160 of file utilities.c.

void printfToBufferOLED ( int  x,
int  y,
char *  chString 
)

Printf-like function to copy an ASCII string into the OLED display buffer.

Details
This function copies a pre-formatted ASCII string into the OLED display buffer, but does not take any action to display the buffer
Parameters
[in]x- The starting position of string within the 16x4 character display
[in]y- The starting position of string within the 16x4 character display
[in]*chString- pointer to an null terminated character string. Should be generated with sprintf (or similar).
Return values
None

Definition at line 527 of file utilities.c.

void printfToOLED ( int  x,
int  y,
char *  chString 
)

Printf-like function to copy an ASCII string into the OLED display buffer.

Details
This function copies a pre-formatted ASCII string into the OLED display buffer, flips/rotates the display pixels, and then sends the buffer to the OLED display
Parameters
[in]x- The starting position of string within the 16x4 character display
[in]y- The starting position of string within the 16x4 character display
[in]*chString- pointer to an null terminated character string. Should be generated with sprintf (or similar).
Return values
None

Definition at line 567 of file utilities.c.

void putCharOLED ( int  x,
int  y,
char  chCharacter 
)

Places a single ASCII character into the OLED display buffer.

Details
This function copies an ASCII character from the font table into the OLED display buffer (configured as a 16x4 character display).
Parameters
[in]x- The x position of the character location
[in]y- The y position of the character location
[in]chCharacter- ASCII character to be printed (ex: 0x41 = 'A')
Return values
None

Definition at line 495 of file utilities.c.

void sendOLEDSPI ( u8  uchDataToWrite)

Bit bang routine for Zedboard SPI OLED interface.

Details
This function sends an (unsigned) byte (msb first) to the OLED SPI port
Parameters
[in]uchDataToWrite- u8 value to be written to OLED SPI
Return values
None

Definition at line 382 of file utilities.c.

void sendUartByte ( u32  unUartAddress,
u8  uchByte 
)

Send a byte to the UART. Either directs to the full UART in the Zynq PS, or a Xilinx UartLite.

Parameters
[in]unUartAddress.32 bit UART address
[in]uchByte.The byte to be sent to the UART
Return values
None

Definition at line 195 of file utilities.c.