====== 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 [[https://docs.google.com/document/d/1XbXVW16oLL4Eco4ZBgYXWCi05NH3-hVhp9q-J26maV8/edit|Proposal (Spanish)]]. You can find the slideshow here [[https://drive.google.com/drive/#folders/0B50L99OoaOobZC1nWC13dmN5NjA|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 ==== - To support USB on the Stm32f429-discovery through libopencm3. - To develop basic communication with the LCD screen through SPI. - To elaborate routines to draw vectors on the screen. - 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. {{:ie0117_proyectos_ii_2014:proyecto_2:spi1.png?300|}} This image shows the attempted connection with the LCD screen. It's a 3-wire serial interface . {{:ie0117_proyectos_ii_2014:proyecto_2:spi2.png?300|}} 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 ==== {{:ie0117_proyectos_ii_2014:proyecto_2:linea.png?200|}} 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 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= 0.5) { y = y + 1; /*aproximate to neares integer value of y*/ error = error - 1.0;} }} ==== Mid-point circle algorithm ==== {{:ie0117_proyectos_ii_2014:proyecto_2:circle.png?200|}} 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 ===== - Bresenham's algorithm and the midpoint circle algorithm were coded in C. - Attempted communication with the ILI9341 through SPI.