User Tools

Site Tools


Writing /var/lib/dokuwiki/data/meta/teaching/ie0117/proyectos/2014/ii/proyecto_2/soporte_basico_grafico_para_el_stm32f429-discovery.meta failed
teaching:ie0117:proyectos:2014:ii:proyecto_2:soporte_basico_grafico_para_el_stm32f429-discovery

Basic graphic support for the stm32f429-discovery

Luis Diego Soto Ugalde B26613

Introduction

This project attempted to support the stm32f429-discovery's creen on libopencm3.Communication with the screen was attempted through SPI.Two graphing algortithms were implemented in C.

You can find the original work proposal here Proposal (Spanish).

You can find the slideshow here Slideshow (English).

Objectives

General Objective

To improve libopencm3's support for the Stm32f429-discovery including the input device,LCD screen,vector drawing routines and USB.

Specific Objectives

  1. To support USB on the Stm32f429-discovery through libopencm3.
  2. To develop basic communication with the LCD screen through SPI.
  3. To elaborate routines to draw vectors on the screen.
  4. To support the touch input device.

Objectives 2 and 3 are the ones that were given the most attention.

SPI

SPI or Serial Peripheral Interface is a serial synchronous data link that can operate in full duplex mode,although the stm32f429-discovery also allows spi in half-duplex mode.

This image shows the attempted connection with the LCD screen. It's a 3-wire serial interface .

This is the display's communication protocol for the aforementioned interface. In order to operate this device all the required clocks should be enabled in the RCC register and the require GPIO's should be enabled and configured to their respective alternate functions.

It is worth mentioning that communication through SPI was achieved with one of the stm32f429-discovery's devices:the gyroscope. Communication with the LCD-screen turned to be somewhat harder due to the LCD having a 9-bit communication protocol for the spi configuration shown before.

Drawing routines

In the code presented in this section, the function plot is commented since communication through SPI with the LCD wasn't achieved.

Bresenham line algorithm

This algorithm receives the starting and ending points of a line , iterates over all integer values of X in the desired range and calculates the best integer value of y to eliminate the error against a prediction given by the line equation set by the starting and ending points.

This the header of the function created to implement this algorithm

#ifndef BRESENHAM_H_  
#define BRESENHAM_H_ 
 
void bresenham_line(int x0,int x1,int y0,int y1);  
 
#endif

This is the function itself

#include <math.h>
void bresenham_line(int x0,int x1,int y0,int y1)
{ int i;
 int deltax = x1 - x0; /*slope of the line required*/
 int deltay = y1 - y0;
 double error = 0;
 double deltaerr = fabs(deltay / deltax);   
 int y = y0;
 for (i=x0;i<x1+1;i++) /*iteration*/
 {
 /*plot(x,y)*/
error = error + deltaerr;
 if (error >= 0.5)
{  y = y + 1; /*aproximate to neares integer value of y*/
error = error - 1.0;}
 
}}

Mid-point circle algorithm

The mid-point circle algorithm takes the radius and the center of a wanted circle.It's based on the bresenham algorith already presented. The algorithm calculates in which direction the next pixel should be shaded (-x or +y) in order to minimize the error against the equation of a circle with the center and radius given.This algorithm can be extended to other conic sections as well.

This is the header.

#ifndef CIRCLE_H_  
#define CIRCLE_H_ 
 
void circle(int x0,int y0,int radius);  
 
#endif

Function

 void circle(int x0, int y0, int radius)
{
  int x = radius;
  int y = 0;
  int radiusError = 1-x;
 
  while(x >= y)
  {
    /*plot(x + x0, y + y0);
    plot(y + x0, x + y0);
    plot(-x + x0, y + y0);
    plot(-y + x0, x + y0);
    plot(-x + x0, -y + y0);
    plot(-y + x0, -x + y0);
    plot(x + x0, -y + y0);
    plot(y + x0, -x + y0);*/
    y++;
    if (radiusError<0)
    {
      radiusError += 2 * y + 1;
    }
    else
    {
      x--;
      radiusError += 2 * (y - x + 1);
    }
  }
}

Conclusions

  1. Bresenham's algorithm and the midpoint circle algorithm were coded in C.
  2. Attempted communication with the ILI9341 through SPI.
teaching/ie0117/proyectos/2014/ii/proyecto_2/soporte_basico_grafico_para_el_stm32f429-discovery.txt · Last modified: 2022/09/20 00:08 (external edit)