FT81x Arduino Driver
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
FT81x Class Reference

Instatiate an FT81x context. More...

#include <FT81x.h>

Public Member Functions

 FT81x (int8_t cs1, int8_t cs2, int8_t dc)
 Initialize FT81x with hardware SPI. More...
 
void begin ()
 Initialize FT81x instance.
 
void sendCommand (const uint32_t cmd)
 Send single command to FT81x chip. More...
 
uint8_t read8 (const uint32_t address)
 Read 8 bits from FT81x address space. More...
 
uint16_t read16 (const uint32_t address)
 Read 16 bits from FT81x address space. More...
 
uint32_t read32 (const uint32_t address)
 Read 32 bits from FT81x address space. More...
 
void write8 (const uint32_t address, const uint8_t data)
 Write 8 bits to FT81x address space. More...
 
void write16 (const uint32_t address, const uint16_t data)
 Write 16 bits to FT81x address space. More...
 
void write32 (const uint32_t address, const uint32_t data)
 Write 32 bits to FT81x address space. More...
 
void clear (const uint32_t color)
 Write clear command to current display list. More...
 
void drawCircle (const int16_t x, const int16_t y, const uint8_t size, const uint32_t color)
 Draw circle in current display list. More...
 
void drawRect (const int16_t x, const int16_t y, const uint16_t width, const uint16_t height, const uint8_t cornerRadius, const uint32_t color)
 Draw rectangle in current display list. More...
 
void drawTri (const int16_t x1, const int16_t y1, const int16_t x2, const int16_t y2, const int16_t x3, const int16_t y3, const uint32_t color, const uint32_t bgcolor)
 Draw triangle in current display list. Points must be defined in clockwise order. Only tested with equilateral tris. More...
 
void drawLine (const int16_t x1, const int16_t y1, const int16_t x2, const int16_t y2, const uint8_t width, const uint32_t color)
 Draw line in current display list. More...
 
void beginLineStrip (const uint8_t width, const uint32_t color)
 Start drawing a line strip. More...
 
void addVertex (const int16_t x, const int16_t y)
 Add vertex to line strip. More...
 
void endLineStrip ()
 End line strio. More...
 
void drawLetter (const int16_t x, const int16_t y, const uint8_t font, const uint32_t color, const uint8_t letter)
 Draw a single letter in current display list. More...
 
void drawText (const int16_t x, const int16_t y, const uint8_t font, const uint32_t color, const uint16_t options, const char text[])
 Draw a single line of text in current display list. More...
 
void drawBitmap (const uint32_t offset, const uint16_t x, const uint16_t y, const uint16_t width, const uint16_t height, const uint8_t scale, const uint8_t rot)
 Draw bitmap data in current display list. More...
 
void overlayBitmap (const uint32_t offset, const uint16_t x, const uint16_t y, const uint16_t width, const uint16_t height, const uint8_t scale, const uint8_t rot)
 Overlay bitmap data (add pixel values to existing pixels) More...
 
void drawSpinner (const int16_t x, const int16_t y, const uint16_t style, const uint16_t scale, const uint32_t color)
 Draw a spinner in current display list. More...
 
void drawButton (const int16_t x, const int16_t y, const int16_t width, const int16_t height, const uint8_t font, const uint32_t textColor, const uint32_t buttonColor, const uint16_t options, const char text[])
 Draw a button. More...
 
void drawClock (const int16_t x, const int16_t y, const int16_t radius, const uint32_t handsColor, const uint32_t backgroundColor, const uint16_t options, const uint16_t hours, const uint16_t minutes, const uint16_t seconds)
 Draw an analog clock. More...
 
void drawGauge (const int16_t x, const int16_t y, const int16_t radius, const uint32_t handsColor, const uint32_t backgroundColor, const uint16_t options, const uint8_t major, const uint8_t minor, const uint16_t value, const uint16_t range)
 Draw a gauge. More...
 
void drawGradient (const int16_t x1, const int16_t y1, const uint32_t color1, const int16_t x2, const int16_t y2, const uint32_t color2)
 Draw a gradient. More...
 
void drawScrollbar (const int16_t x, const int16_t y, const int16_t width, const int16_t height, const uint32_t foregroundColor, const uint32_t backgroundColor, const uint16_t options, const uint16_t value, const uint16_t size, const uint16_t range)
 Draw a scrollbar. More...
 
void drawProgressbar (const int16_t x, const int16_t y, const int16_t width, const int16_t height, const uint32_t foregroundColor, const uint32_t backgroundColor, const uint16_t options, const uint16_t value, const uint16_t range)
 Draw a progressbar. More...
 
void beginDisplayList ()
 Begin a new display list.
 
void swapScreen ()
 End the current display list and swap the screen.
 
void waitForCommandBuffer ()
 The command buffer can take 4 kBytes of data while display lists can hold 8 kBytes. For display lists > 4k and < 8k you may need to wait for the buffer to catch up.
 
void setRotation (const uint8_t rotation)
 Set screen rotation. More...
 
void writeGRAM (const uint32_t offset, const uint32_t size, const uint8_t data[], const bool useProgmem=true)
 Write data to general purpose graphics RAM (must be aligned to 4 bytes) More...
 
void loadImage (const uint32_t offset, const uint32_t size, const uint8_t data[], const bool useProgmem=true)
 Load image data (JPEG, PNG) as bitmap into general purpose graphics RAM (must be aligned to 4 bytes) More...
 
void playAudio (const uint32_t offset, const uint32_t size, const uint16_t sampleRate, const uint8_t format, const bool loop)
 Play audio data located in general purpose graphics RAM (must be aligned to 8 bytes) More...
 
bool isSoundPlaying ()
 Query whether sound is currently playing. More...
 
void setAudioVolume (const uint8_t volume)
 Set the volume of the audio output. More...
 
void setSound (const uint8_t effect, const uint8_t pitch)
 Set a sound effect and its pitch. More...
 
void playSound ()
 Play the sound defined by setSound()
 
void stopSound ()
 Stop audio output by playing silence.
 
uint8_t queryDisplay (const uint8_t cmd)
 Query the display for data. More...
 

Protected Member Functions

void initFT81x ()
 Initialize the FT81x chip.
 
void initDisplay ()
 Initizalize the display.
 
void sendCommandToDisplay (const uint8_t cmd, const uint8_t numParams, const uint8_t *params)
 Send command to display. More...
 
void cmd (const uint32_t cmd)
 Write single command to the command buffer of the FT81x chip. More...
 
void startCmd (const uint32_t cmd)
 Start a bulk-write to the command buffer of the FT81x chip. More...
 
void intermediateCmd (const uint32_t cmd)
 Write an intermediate command to the command buffer of the FT81x chip during a bulk-write. More...
 
void endCmd (const uint32_t cmd)
 Write a final command to the command buffer of the FT81x chip during a bulk-write. More...
 
void increaseCmdWriteAddress (uint16_t delta)
 Increase the internal pointer to the command buffer. More...
 
void updateCmdWriteAddress ()
 Write the internal pointer to the command buffer to the FT81x chip.
 
void sendText (const char text[])
 Send text as the end of a command sequence. More...
 
uint8_t initBitmapHandleForFont (uint8_t font)
 Load and return the correct bitmap handle for fonts 16-34. More...
 

Protected Attributes

int8_t cs1
 CS pin for FT81x.
 
int8_t cs2
 CS pin for display.
 
int8_t dc
 Data/Command pin for display.
 
uint16_t cmdWriteAddress = 0
 Internal pointer to the command buffer of the FT81x chip.
 

Detailed Description

Instatiate an FT81x context.

Constructor & Destructor Documentation

◆ FT81x()

FT81x::FT81x ( int8_t  cs1,
int8_t  cs2,
int8_t  dc 
)
inline

Initialize FT81x with hardware SPI.

Parameters
cs1Number of the pin connected to the board's CS1 pin
cs2Number of the pin connected to the board's CS2 pin
dcNumber of the pin connected to the board's DC pin

Member Function Documentation

◆ addVertex()

void FT81x::addVertex ( const int16_t  x,
const int16_t  y 
)

Add vertex to line strip.

Parameters
xx-coordinate of the vertex
yy-coordinate of the vertex

◆ beginLineStrip()

void FT81x::beginLineStrip ( const uint8_t  width,
const uint32_t  color 
)

Start drawing a line strip.

Parameters
widthWidth of the line (1-6)
colorColor of the line

◆ clear()

void FT81x::clear ( const uint32_t  color)

Write clear command to current display list.

Parameters
colorClear display using this color

◆ cmd()

void FT81x::cmd ( const uint32_t  cmd)
protected

Write single command to the command buffer of the FT81x chip.

Parameters
cmd8-bit command to send to the chip

◆ drawBitmap()

void FT81x::drawBitmap ( const uint32_t  offset,
const uint16_t  x,
const uint16_t  y,
const uint16_t  width,
const uint16_t  height,
const uint8_t  scale,
const uint8_t  rot 
)

Draw bitmap data in current display list.

Parameters
offsetOffset in general purpose graphics RAM
xx-coordinate for the top-left of the bitmap
yy-coordinate for the top-left of the bitmap
widthWidth of the bitmap
heightHeight of the bitmap
scaleScale to resize the bitmap by
rotRotation of the image, in degrees, around the centre of the bitmap (works best with square images)

◆ drawButton()

void FT81x::drawButton ( const int16_t  x,
const int16_t  y,
const int16_t  width,
const int16_t  height,
const uint8_t  font,
const uint32_t  textColor,
const uint32_t  buttonColor,
const uint16_t  options,
const char  text[] 
)

Draw a button.

Parameters
xx-coordinate for the top-left of the button
yy-coordinate for the top-left of the button
widthWidth of the button
heightHeight of the button
fontFont handle (16-34 are built-in fonts)
textColorColor for the text
buttonColorColor for the button
optionsOption to use (e.g. FT81x_OPT_FLAT)
textText to draw, must be terminated by null character (e.g. "Hello World\0")

◆ drawCircle()

void FT81x::drawCircle ( const int16_t  x,
const int16_t  y,
const uint8_t  size,
const uint32_t  color 
)

Draw circle in current display list.

Parameters
xx-coordinate for the center of the circle
yy-coordinate for the center of the circle
sizeRadius of the circle
colorColor of the circle

◆ drawClock()

void FT81x::drawClock ( const int16_t  x,
const int16_t  y,
const int16_t  radius,
const uint32_t  handsColor,
const uint32_t  backgroundColor,
const uint16_t  options,
const uint16_t  hours,
const uint16_t  minutes,
const uint16_t  seconds 
)

Draw an analog clock.

Parameters
xx-coordinate for the center of the clock
yy-coordinate for the center of the clock
radiusRadius of the clock
handsColorColor for the clock hands
backgroundColorColor for the clock background
optionsOption to use (e.g. FT81x_OPT_FLAT | FT81x_OPT_NOSECS)
hoursHours clock hand
minutesMinutes clock hand
secondsSeconds clock hand

◆ drawGauge()

void FT81x::drawGauge ( const int16_t  x,
const int16_t  y,
const int16_t  radius,
const uint32_t  handsColor,
const uint32_t  backgroundColor,
const uint16_t  options,
const uint8_t  major,
const uint8_t  minor,
const uint16_t  value,
const uint16_t  range 
)

Draw a gauge.

Parameters
xx-coordinate for the center of the clock
yy-coordinate for the center of the clock
radiusRadius of the clock
handsColorColor for the clock hands
backgroundColorColor for the clock background
optionsOption to use (e.g. FT81x_OPT_FLAT | FT81x_OPT_NOTICKS)
majorNumber of major subdivisions on the dial, 1-10
minorNumber of minor subdivisions on the dial, 1-10
valueGauge indicated value between 0 and range
rangeMaximum value

◆ drawGradient()

void FT81x::drawGradient ( const int16_t  x1,
const int16_t  y1,
const uint32_t  color1,
const int16_t  x2,
const int16_t  y2,
const uint32_t  color2 
)

Draw a gradient.

Parameters
x1x-coordinate for the starting point of the gradient
y1y-coordinate for the starting point of the gradient
color1Color for the starting point of the gradient
x2x-coordinate for the ending point of the gradient
y2y-coordinate for the ending point of the gradient
color2Color for the ending point of the gradient

◆ drawLetter()

void FT81x::drawLetter ( const int16_t  x,
const int16_t  y,
const uint8_t  font,
const uint32_t  color,
const uint8_t  letter 
)

Draw a single letter in current display list.

Parameters
xx-coordinate for the letter
yy-coordinate for the letter
fontFont handle (16-34 are built-in fonts)
colorColor for the letter
letterLetter to draw

◆ drawLine()

void FT81x::drawLine ( const int16_t  x1,
const int16_t  y1,
const int16_t  x2,
const int16_t  y2,
const uint8_t  width,
const uint32_t  color 
)

Draw line in current display list.

Parameters
x1x-coordinate for the start of the line
y1y-coordinate for the start of the line
x2x-coordinate for the end of the line
y2y-coordinate for the end of the line
widthWidth of the line (1-6)
colorColor of the line

◆ drawProgressbar()

void FT81x::drawProgressbar ( const int16_t  x,
const int16_t  y,
const int16_t  width,
const int16_t  height,
const uint32_t  foregroundColor,
const uint32_t  backgroundColor,
const uint16_t  options,
const uint16_t  value,
const uint16_t  range 
)

Draw a progressbar.

Parameters
xx-coordinate of progressbar top-left
yy-coordinate of progressbar top-left
widthWidth of progressbar, if width is greater than height the progressbar is drawn horizontally
heightHeight of progressbar, if height is greater than width the progressbar is drawn vertically
foregroundColorColor for the progressbar foreground
backgroundColorColor for the progressbar background
optionsOption to use (e.g. FT81x_OPT_FLAT)
valueDisplayed value of the progressbar, between 0 and range (inclusive)
rangeMaximum value

◆ drawRect()

void FT81x::drawRect ( const int16_t  x,
const int16_t  y,
const uint16_t  width,
const uint16_t  height,
const uint8_t  cornerRadius,
const uint32_t  color 
)

Draw rectangle in current display list.

Parameters
xx-coordinate for the top-left of the rectangle
yy-coordinate for the top-left of the rectangle
widthWidth of the rectangle
heightHeight of the rectangle
cornerRadiusCorner radius of the rectangle
colorColor of the rectangle

◆ drawScrollbar()

void FT81x::drawScrollbar ( const int16_t  x,
const int16_t  y,
const int16_t  width,
const int16_t  height,
const uint32_t  foregroundColor,
const uint32_t  backgroundColor,
const uint16_t  options,
const uint16_t  value,
const uint16_t  size,
const uint16_t  range 
)

Draw a scrollbar.

Parameters
xx-coordinate of scrollbar top-left
yy-coordinate of scrollbar top-left
widthWidth of scrollbar, if width is greater than height the scrollbar is drawn horizontally
heightHeight of scrollbar, if height is greater than width the scrollbar is drawn vertically
foregroundColorColor for the scrollbar foreground
backgroundColorColor for the scrollbar background
optionsOption to use (e.g. FT81x_OPT_FLAT)
valueDisplayed value of the scrollbar, between 0 and range (inclusive)
sizeSize of scrollbar handle
rangeMaximum value

◆ drawSpinner()

void FT81x::drawSpinner ( const int16_t  x,
const int16_t  y,
const uint16_t  style,
const uint16_t  scale,
const uint32_t  color 
)

Draw a spinner in current display list.

Parameters
xx-coordinate for the spinner
yy-coordinate for the spinner
styleThe style of spinner, valid range is from 0 to 3.
scaleScale to resize the bitmap by
colorColor for the spinner

◆ drawText()

void FT81x::drawText ( const int16_t  x,
const int16_t  y,
const uint8_t  font,
const uint32_t  color,
const uint16_t  options,
const char  text[] 
)

Draw a single line of text in current display list.

Parameters
xx-coordinate for the letter
yy-coordinate for the letter
fontFont handle (16-34 are built-in fonts)
colorColor for the letter
optionsOption to use (e.g. FT81x_OPT_CENTER)
textText to draw, must be terminated by null character (e.g. "Hello World\0")

◆ drawTri()

void FT81x::drawTri ( const int16_t  x1,
const int16_t  y1,
const int16_t  x2,
const int16_t  y2,
const int16_t  x3,
const int16_t  y3,
const uint32_t  color,
const uint32_t  bgcolor 
)

Draw triangle in current display list. Points must be defined in clockwise order. Only tested with equilateral tris.

Parameters
x1x-coordinate for the first triangle point
y1y-coordinate for the first triangle point
x2x-coordinate for the first triangle point
y2y-coordinate for the first triangle point
x3x-coordinate for the first triangle point
y3y-coordinate for the first triangle point
colorColor of the rectangle
bgcolorColor of the background

◆ endCmd()

void FT81x::endCmd ( const uint32_t  cmd)
protected

Write a final command to the command buffer of the FT81x chip during a bulk-write.

Parameters
cmd8-bit command to send to the chip

◆ endLineStrip()

void FT81x::endLineStrip ( )

End line strio.

Parameters
xx-coordinate of the vertex
yy-coordinate of the vertex

◆ increaseCmdWriteAddress()

void FT81x::increaseCmdWriteAddress ( uint16_t  delta)
inlineprotected

Increase the internal pointer to the command buffer.

Parameters
deltaAmount to increase the pointer by

◆ initBitmapHandleForFont()

uint8_t FT81x::initBitmapHandleForFont ( uint8_t  font)
protected

Load and return the correct bitmap handle for fonts 16-34.

Returns
Bitmap handle

◆ intermediateCmd()

void FT81x::intermediateCmd ( const uint32_t  cmd)
protected

Write an intermediate command to the command buffer of the FT81x chip during a bulk-write.

Parameters
cmd8-bit command to send to the chip

◆ isSoundPlaying()

bool FT81x::isSoundPlaying ( )

Query whether sound is currently playing.

Returns
true when sound is playing and false otherwise

◆ loadImage()

void FT81x::loadImage ( const uint32_t  offset,
const uint32_t  size,
const uint8_t  data[],
const bool  useProgmem = true 
)

Load image data (JPEG, PNG) as bitmap into general purpose graphics RAM (must be aligned to 4 bytes)

Parameters
offsetOffset in general purpose graphics RAM
sizeSize of the data in bytes
dataPointer to the data
useProgmemLoad data from PROGMEM (only affects AVR architectures like the Arduino Uno)

◆ overlayBitmap()

void FT81x::overlayBitmap ( const uint32_t  offset,
const uint16_t  x,
const uint16_t  y,
const uint16_t  width,
const uint16_t  height,
const uint8_t  scale,
const uint8_t  rot 
)

Overlay bitmap data (add pixel values to existing pixels)

Parameters
offsetOffset in general purpose graphics RAM
xx-coordinate for the top-left of the bitmap
yy-coordinate for the top-left of the bitmap
widthWidth of the bitmap
heightHeight of the bitmap
scaleScale to resize the bitmap by
rotRotation of the image, in degrees, around the centre of the bitmap (works best with square images)

◆ playAudio()

void FT81x::playAudio ( const uint32_t  offset,
const uint32_t  size,
const uint16_t  sampleRate,
const uint8_t  format,
const bool  loop 
)

Play audio data located in general purpose graphics RAM (must be aligned to 8 bytes)

Parameters
offsetOffset in general purpose graphics RAM
sizeSize of the data in bytes
sampleRateSample rate for the audio data (e.g. 44100)
formatAudio data format (e.g. FT81x_AUDIO_FORMAT_LINEAR)
loopWhether to loop the audio or stop at the end

◆ queryDisplay()

uint8_t FT81x::queryDisplay ( const uint8_t  cmd)

Query the display for data.

Parameters
cmd8-bit command to send to the display
Returns
8-bit value

◆ read16()

uint16_t FT81x::read16 ( const uint32_t  address)

Read 16 bits from FT81x address space.

Parameters
address32-bit address
Returns
16-bit value

◆ read32()

uint32_t FT81x::read32 ( const uint32_t  address)

Read 32 bits from FT81x address space.

Parameters
address32-bit address
Returns
32-bit value

◆ read8()

uint8_t FT81x::read8 ( const uint32_t  address)

Read 8 bits from FT81x address space.

Parameters
address32-bit address
Returns
8-bit value

◆ sendCommand()

void FT81x::sendCommand ( const uint32_t  cmd)

Send single command to FT81x chip.

Parameters
cmd32-bit command

◆ sendCommandToDisplay()

void FT81x::sendCommandToDisplay ( const uint8_t  cmd,
const uint8_t  numParams,
const uint8_t *  params 
)
protected

Send command to display.

Parameters
cmd8-bit command to send to the display
numParamsNumber of parameters for the command
paramsPointer to the 8-bit data used as parameters

◆ sendText()

void FT81x::sendText ( const char  text[])
protected

Send text as the end of a command sequence.

Parameters
textText to send, must be terminated by null character (e.g. "Hello World\0")

◆ setAudioVolume()

void FT81x::setAudioVolume ( const uint8_t  volume)

Set the volume of the audio output.

Parameters
volumeNumber from 0 to 255

◆ setRotation()

void FT81x::setRotation ( const uint8_t  rotation)

Set screen rotation.

Parameters
rotationUse one of the pre-defined contants to set the rotation

◆ setSound()

void FT81x::setSound ( const uint8_t  effect,
const uint8_t  pitch 
)

Set a sound effect and its pitch.

Parameters
effectSound effect
pitchPitch of the sound (MIDI note ranging from 21 to 82) if supported by the selected effect

◆ startCmd()

void FT81x::startCmd ( const uint32_t  cmd)
protected

Start a bulk-write to the command buffer of the FT81x chip.

Parameters
cmd8-bit command to send to the chip

◆ write16()

void FT81x::write16 ( const uint32_t  address,
const uint16_t  data 
)

Write 16 bits to FT81x address space.

Parameters
address32-bit address
data16-bit value

◆ write32()

void FT81x::write32 ( const uint32_t  address,
const uint32_t  data 
)

Write 32 bits to FT81x address space.

Parameters
address32-bit address
data32-bit value

◆ write8()

void FT81x::write8 ( const uint32_t  address,
const uint8_t  data 
)

Write 8 bits to FT81x address space.

Parameters
address32-bit address
data8-bit value

◆ writeGRAM()

void FT81x::writeGRAM ( const uint32_t  offset,
const uint32_t  size,
const uint8_t  data[],
const bool  useProgmem = true 
)

Write data to general purpose graphics RAM (must be aligned to 4 bytes)

Parameters
offsetOffset in general purpose graphics RAM
sizeSize of the data in bytes
dataPointer to the data
useProgmemLoad data from PROGMEM (only affects AVR architectures like the Arduino Uno)

The documentation for this class was generated from the following files: