adafruit_ra8875.ra8875

A Driver Library for the RA8875

  • Author(s): Melissa LeBlanc-Williams

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_ra8875.ra8875.RA8875(spi: SPI, cs: DigitalInOut, rst: DigitalInOut | None = None, width: int = 800, height: int = 480, baudrate: int = 6000000, polarity: int = 0, phase: int = 0)

Graphics Library Class for the Display. Contains all the hardware accelerated geometry Functions. For full display functionality, use this class. Valid display sizes are currently 800x480 and 480x272.

circle(x_center: int, y_center: int, radius: int, color: int) None

Draw a circle (HW Accelerated)

Parameters:
  • x_center (int) – The X coordinate of the center of the circle

  • y_center (int) – The Y coordinate of the center of the circle

  • radius (int) – The radius of the circle

  • color (int) – The color of the circle

curve(x_center: int, y_center: int, h_axis: int, v_axis: int, curve_part: int, color: int) None

Draw a Curve (HW Accelerated) This is basically a quarter of an ellipse.

Parameters:
  • x_center (int) – The X coordinate of the focal point of the curve

  • y_center (int) – The Y coordinate of the focal point of the curve

  • h_axis (int) – The length of the horizontal axis of the full ellipse

  • v_axis (int) – The length of the vertical axis of the full ellipse

  • curve_part (byte) – A number between 0-3 specifying the quarter section

  • color (int) – The color of the curve

ellipse(x_center: int, y_center: int, h_axis: int, v_axis: int, color: int) None

Draw an ellipse (HW Accelerated)

Parameters:
  • x_center (int) – The X coordinate of the center of the ellipse

  • y_center (int) – The Y coordinate of the center of the ellipse

  • h_axis (int) – The length of the horizontal axis

  • v_axis (int) – The length of the vertical axis

  • color (int) – The color of the ellipse

fill(color: int) None

Fill the Entire Screen (HW Accelerated)

Parameters:

color (int) – The color to Fill the screen

fill_circle(x_center: int, y_center: int, radius: int, color: int) None

Draw a filled circle (HW Accelerated)

Parameters:
  • x_center (int) – The X coordinate of the center of the circle

  • y_center (int) – The Y coordinate of the center of the circle

  • radius (int) – The radius of the circle

  • color (int) – The color of the circle

fill_curve(x_center: int, y_center: int, h_axis: int, v_axis: int, curve_part: int, color: int) None

Draw a Filled Curve (HW Accelerated) This is basically a quarter of an ellipse.

Parameters:
  • x_center (int) – The X coordinate of the focal point of the curve

  • y_center (int) – The Y coordinate of the focal point of the curve

  • h_axis (int) – The length of the horizontal axis of the full ellipse

  • v_axis (int) – The length of the vertical axis of the full ellipse

  • curve_part (byte) – A number between 0-3 specifying the quarter section

  • color (int) – The color of the curve

fill_ellipse(x_center: int, y_center: int, h_axis: int, v_axis: int, color: int) None

Draw a Filled Ellipse (HW Accelerated)

Parameters:
  • x_center (int) – The X coordinate of the center of the ellipse

  • y_center (int) – The Y coordinate of the center of the ellipse

  • h_axis (int) – The length of the horizontal axis

  • v_axis (int) – The length of the vertical axis

  • color (int) – The color of the ellipse

fill_rect(x: int, y: int, width: int, height: int, color: int) None

Draw a filled rectangle (HW Accelerated)

Parameters:
  • x (int) – The X coordinate of the left side of the rectangle

  • y (int) – The Y coordinate of the top side of the rectangle

  • width (int) – The width of the rectangle

  • height (int) – The height of the rectangle

  • color (int) – The color of the rectangle

fill_round_rect(x: int, y: int, width: int, height: int, radius: int, color: int) None

Draw a filled rounded rectangle

Parameters:
  • x (int) – The X coordinate of the left side of the rectangle

  • y (int) – The Y coordinate of the top side of the rectangle

  • width (int) – The width of the rectangle

  • height (int) – The height of the rectangle

  • radius (int) – The radius of the corners

  • color (int) – The color of the rectangle

fill_triangle(x1: int, y1: int, x2: int, y2: int, x3: int, y3: int, color: int) None

Draw a Filled Triangle (HW Accelerated)

Parameters:
  • x1 (int) – The X coordinate of the first point of the triangle

  • y1 (int) – The Y coordinate of the first point of the triangle

  • x2 (int) – The X coordinate of the second point of the triangle

  • y2 (int) – The Y coordinate of the second point of the triangle

  • x3 (int) – The X coordinate of the third point of the triangle

  • y3 (int) – The Y coordinate of the third point of the triangle

  • color (int) – The color of the triangle

hline(x: int, y: int, width: int, color: int) None

Draw a Horizontal Line (HW Accelerated)

Parameters:
  • x (int) – The X coordinate of the beginning point of the line

  • y (int) – The Y coordinate of the beginning point of the line

  • width (int) – The width of the line

  • color (int) – The color of the line

line(x1: int, y1: int, x2: int, y2: int, color: int) None

Draw a Line (HW Accelerated)

Parameters:
  • x1 (int) – The X coordinate of the beginning point of the line

  • y1 (int) – The Y coordinate of the beginning point of the line

  • x2 (int) – The X coordinate of the end point of the line

  • y2 (int) – The Y coordinate of the end point of the line

  • color (int) – The color of the line

rect(x: int, y: int, width: int, height: int, color: int) None

Draw a rectangle (HW Accelerated)

Parameters:
  • x (int) – The X coordinate of the left side of the rectangle

  • y (int) – The Y coordinate of the top side of the rectangle

  • width (int) – The width of the rectangle

  • height (int) – The height of the rectangle

  • color (int) – The color of the rectangle

round_rect(x: int, y: int, width: int, height: int, radius: int, color: int) None

Draw a rounded rectangle

Parameters:
  • x (int) – The X coordinate of the left side of the rectangle

  • y (int) – The Y coordinate of the top side of the rectangle

  • width (int) – The width of the rectangle

  • height (int) – The height of the rectangle

  • radius (int) – The radius of the corners

  • color (int) – The color of the rectangle

triangle(x1: int, y1: int, x2: int, y2: int, x3: int, y3: int, color: int) None

Draw a Triangle (HW Accelerated)

Parameters:
  • x1 (int) – The X coordinate of the first point of the triangle

  • y1 (int) – The Y coordinate of the first point of the triangle

  • x2 (int) – The X coordinate of the second point of the triangle

  • y2 (int) – The Y coordinate of the second point of the triangle

  • x3 (int) – The X coordinate of the third point of the triangle

  • y3 (int) – The Y coordinate of the third point of the triangle

  • color (int) – The color of the triangle

vline(x: int, y: int, height: int, color: int) None

Draw a Vertical Line (HW Accelerated)

Parameters:
  • x (int) – The X coordinate of the beginning point of the line

  • y (int) – The Y coordinate of the beginning point of the line

  • height (int) – The height of the line

  • color (int) – The color of the line

class adafruit_ra8875.ra8875.RA8875Display(spi: SPI, cs: DigitalInOut, rst: DigitalInOut | None = None, width: int = 800, height: int = 480, baudrate: int = 6000000, polarity: int = 0, phase: int = 0)

Drawing Class for the Display. Contains all the basic drawing functionality as well as the text functions. Valid display sizes are currently 800x480 and 480x272.

Parameters:
  • spi (SPI) – The spi peripheral to use

  • cs (DigitalInOut) – The chip-select pin to use (sometimes labeled “SS”)

  • rst (DigitalInOut) – (optional) The reset pin if it exists (default=None)

  • width (int) – (optional) The width of the display in pixels (default=800)

  • height (int) – (optional) The height of the display in pixels (default=480)

  • baudrate (int) – (optional) The spi speed (default=6000000)

  • phase (int) – (optional) The spi phase (default=0)

  • polarity (int) – (optional) The spi polarity (default=0)

pixel(x: int, y: int, color: int) None

Draw a pixel at the X and Y coordinates of the specified color

Parameters:
  • x (int) – The X coordinate to set the cursor

  • y (int) – The Y coordinate to set the cursor

  • color (int) – The color of the pixel

push_pixels(pixel_data: bytearray) None

Push a stream of pixel data to the screen.

Parameters:

pixel_data (bytearray) – Raw pixel data to push

set_bgcolor(color: int) None

Set the text background color

Parameters:

color (int) – The color behind the text

set_color(color: int) None

Set the foreground color for graphics/text

Parameters:

color (int) – The of the text or graphics

set_window(x: int, y: int, width: int, height: int) None

Set an Active Drawing Window, which can be used in conjuntion with push_pixels for faster drawing

Parameters:
  • x (int) – The X coordinate of the left side of the window

  • y (int) – The Y coordinate of the top side of the window

  • width (int) – The width of the window

  • height (int) – The height of the window

setxy(x: int, y: int) None

Set the X and Y coordinates of the Graphic Cursor

Parameters:
  • x (int) – The X coordinate to set the cursor

  • y (int) – The Y coordinate to set the cursor

txt_color(fgcolor: int, bgcolor: int)

Set the text foreground and background colors

Parameters:
  • fgcolor (int) – Foreground Color - The color of the text

  • bgcolor (int) – Background Color - The color behind the text

txt_set_cursor(x: int, y: int) None

Set the X and Y coordinates of the Text Cursor

Parameters:
  • x (int) – The X coordinate to set the cursor

  • y (int) – The Y coordinate to set the cursor

txt_size(scale: int) None

Set the Text Size (0-3)

Parameters:

scale (byte) – The the size to scale the Text to

txt_trans(color: int) None

Set the text foreground color with a transparent background

Parameters:

color (int) – The color of the text

txt_write(string: str) None

Write text at the current cursor location using current settings

Parameters:

string (str) – The text string to write

class adafruit_ra8875.ra8875.RA8875_Device(spi: SPI, cs: DigitalInOut, rst: DigitalInOut | None = None, width: int = 800, height: int = 480, baudrate: int = 6000000, polarity: int = 0, phase: int = 0)

Base Class for the Display. Contains all the low level stuff. As well as the touch functions. Valid display sizes are currently 800x480 and 480x272.

Parameters:
  • spi (SPI) – The spi peripheral to use

  • cs (DigitalInOut) – The chip-select pin to use (sometimes labeled “SS”)

  • rst (DigitalInOut) – (optional) The reset pin if it exists (default=None)

  • width (int) – (optional) The width of the display in pixels (default=800)

  • height (int) – (optional) The height of the display in pixels (default=480)

  • baudrate (int) – (optional) The spi speed (default=6000000)

  • polarity (int) – (optional) The spi polarity (default=0)

  • phase (int) – (optional) The spi phase (default=0)

brightness(level: int)

Configure the backlight brightness (0-255)

Parameters:

level (byte) – The PWM Duty Cycle

init(start_on: bool = True) None

Send the Init Commands for the selected Display Size

Parameters:

start_on (bool) – (optional) If the display should start in an On State (default=True)

pllinit() None

Init the Controller PLL

reset() None

Perform a hard reset

sleep(sleep: bool) None

Turn the display off with and set or remove the sleep state

Parameters:

sleep (bool) – Should we enable sleep mode

soft_reset() None

Perform a soft reset

touch_enable(touch_on: bool) None

Enable touch functionality

Parameters:

touch_on (bool) – Enable/Disable the Touch Functionality

touch_init(tpin: DigitalInOut | None = None, enable: bool = True) None

Initialize the Touchscreen

Parameters:
  • tpin (DigitalInOut) – (Optional) The Touch Screen Interrupt Pin (default=None)

  • enable (bool) – Enable the Touch Functionality as well

touch_read() Tuple[int, int]

Read the X and Y Coordinates of the current Touch Position

Returns:

The coordinate of the detected touch

Return type:

tuple[int, int]

touched() bool

Check if the Screen is currently being touched. If a touch interrupt was specified, this is checked first.

Returns:

Is screen is currently being touched

Return type:

bool

turn_on(display_on: bool) None

Turn the display on or off

Parameters:

start_on (bool) – If the display should turn on or off

adafruit_ra8875.ra8875.color565(r: int, g: int = 0, b: int = 0) int

Convert red, green and blue values (0-255) into a 16-bit 565 encoding.