Skip to content

Commit

Permalink
Changed the layout of the max7219_matrix files, also added Javadoc st…
Browse files Browse the repository at this point in the history
…yle documentation to the same
  • Loading branch information
LuisAGC committed Oct 5, 2019
1 parent 9965084 commit a59dd0b
Show file tree
Hide file tree
Showing 2 changed files with 205 additions and 24 deletions.
42 changes: 21 additions & 21 deletions max7219_matrix.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <max7219_matrix.h>

void _shiftRowLeft(unsigned int8 row){
unsigned int8 counter = 0;
void _shiftRowLeft(unsigned int16 row){
unsigned int16 counter = 0;
for(counter = 0; counter < MATRIX_COLUMNS; counter++){
if(counter == (MATRIX_COLUMNS - 1)){
ledMatrix[row][counter] <<= 1;
Expand Down Expand Up @@ -84,6 +84,18 @@ void clearMatrix(){
}
}

void clearPartialMatrix(signed int16 x0, signed int16 y0, signed int16 x1, signed int16 y1){
unsigned int16 x = x0;
unsigned int16 y = y0;
for(x = x0; x <= x1; x++){
for(y = y0; y <= y1; y++){
unsigned int16 column = x/8 ;
unsigned int16 subColumn = x - column * 8;
ledMatrix[y][column] &= ~(0x80 >> subColumn);
}
}
}

int1 putPixel(signed int16 x, signed int16 y){
if(x < 0 || y < 0) return FALSE;

Expand Down Expand Up @@ -192,17 +204,6 @@ void drawCircle(signed int16 xc, signed int16 yc, signed int16 radius){
}
}

void sendMatrix( unsigned int16 * loadPinArray){
unsigned int8 counter = 0;
unsigned int8 pinIndex = 0;
for(pinIndex = 0; pinIndex < MAX7219_VERTICAL_DISPLAYS_AMOUNT; pinIndex++){
for(counter = MAX7219_D0_REG; counter <= MAX7219_D7_REG; counter++){
unsigned int8 matrixIndex = (pinIndex*MAX7219_DIGITS_AMOUNT) + counter - 1;
max7219_SendArray(ledMatrix[matrixIndex], counter, loadPinArray[pinIndex]);
}
}
}

void drawCharacter(signed int16 x, signed int16 y, char character){
unsigned int8 fontHeightCounter = 0;
unsigned int8 fontWidthCounter = 0;
Expand All @@ -223,14 +224,13 @@ void drawString(signed int16 x, signed int16 y, char * string, unsigned int8 str
}
}

void clearPartialMatrix(signed int16 x0, signed int16 y0, signed int16 x1, signed int16 y1){
unsigned int16 x = x0;
unsigned int16 y = y0;
for(x = x0; x <= x1; x++){
for(y = y0; y <= y1; y++){
unsigned int16 column = x/8 ;
unsigned int16 subColumn = x - column * 8;
ledMatrix[y][column] &= ~(0x80 >> subColumn);
void sendMatrix( unsigned int16 * loadPinArray){
unsigned int8 counter = 0;
unsigned int8 pinIndex = 0;
for(pinIndex = 0; pinIndex < MAX7219_VERTICAL_DISPLAYS_AMOUNT; pinIndex++){
for(counter = MAX7219_D0_REG; counter <= MAX7219_D7_REG; counter++){
unsigned int8 matrixIndex = (pinIndex*MAX7219_DIGITS_AMOUNT) + counter - 1;
max7219_SendArray(ledMatrix[matrixIndex], counter, loadPinArray[pinIndex]);
}
}
}
187 changes: 184 additions & 3 deletions max7219_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,203 @@

unsigned int8 ledMatrix[MATRIX_ROWS][MATRIX_COLUMNS];

void _shiftRowLeft(unsigned int8);
/**
* Shifts data to the left in the specified row of the in memory matrix
*
* @param row Number of row to be shifted
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void _shiftRowLeft(unsigned int16);

/**
* Shifts data to the left of the in memory matrix, depends on _shiftRowLeft
*
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void shiftMatrixLeft(void);

/**
* Shifts data to the right in the specified row of the in memory matrix
*
* @param row Number of row to be shifted
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void _shiftRowRight(unsigned int8);

/**
* Shifts data to the left of the in memory matrix, depends on _shiftRowRight
*
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void shiftMatrixRight(void);

/**
* Shifts data to the row above the specified row of the in memory matrix
*
* @param row Number of row to be shifted
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void _shiftRowUp(unsigned int8);

/**
* Shifts data of the in memory matrix upwards , depends on _shiftRowUp
*
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void shiftMatrixUp(void);

/**
* Shifts data to the row below the specified row of the in memory matrix
*
* @param row Number of row to be shifted
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void _shiftRowDown(unsigned int8);

/**
* Shifts data of the in memory matrix downwards , depends on _shiftRowDown
*
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void shiftMatrixDown(void);

/**
* Sets all the rows and columns values of the in memory matrix to zero
*
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void clearMatrix(void);

/**
* Sets the values of specific rows and columns of the in memory matrix to zero
*
* @param x0 The origin horizontal point of the section to be cleared
* @param y0 The origin vertical point of the section to be cleared
* @param x1 The last horizontal point of the section to be cleared
* @param y1 The last vertical point of the section to be cleared
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void clearPartialMatrix(signed int16, signed int16, signed int16, signed int16);

/**
* Sets the pixel at the given x and y coordinates as true
*
* @param x The horizontal coordinate of the pixel
* @param y The vertical coordinate of the pixel
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return True if a valid coordinate, False otherwise (e.g. negative values will return False)
*/
int1 putPixel(signed int16, signed int16);

/**
* Draws a line from a given coordinate to another, uses Bresenham algorithm to do the drawing.
* Depends on _drawLineLow and _drawLineHigh to be able to draw lines in all octants
*
* @param x0 The origin horizontal point of the line
* @param y0 The origin vertical point of the line
* @param x1 The end horizontal point of the line
* @param y1 The end vertical point of the line
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void drawLine(signed int16, signed int16, signed int16, signed int16);

/**
* Used to draw lines in the horizontal plane, uses Bresenham algorithm to do the drawing.
* Depends on putPixel
*
* @param x0 The origin horizontal point of the line
* @param y0 The origin vertical point of the line
* @param x1 The end horizontal point of the line
* @param y1 The end vertical point of the line
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void _drawLineLow(signed int16, signed int16, signed int16, signed int16);

/**
* Used to draw lines in the vertical plane, uses Bresenham algorithm to do the drawing.
* Depends on putPixel
*
* @param x0 The origin horizontal point of the line
* @param y0 The origin vertical point of the line
* @param x1 The end horizontal point of the line
* @param y1 The end vertical point of the line
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void _drawLineHigh(signed int16, signed int16, signed int16, signed int16);

/**
* Used to draw rectangular outlines in the matrix.
* Depends on drawLine
*
* @param x0 The origin horizontal point of the rectangle
* @param y0 The origin vertical point of the rectangle
* @param width The width of the rectangle in pixels
* @param height The height of the rectangle in pixels
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void drawRectangle(signed int16, signed int16, signed int16, signed int16);

/**
* Draws a circle with it's center on the given coordinates and radius, uses Bresenham circle algorithm to do the drawing.
*
* @param xc The horizontal coordinate of the circle center
* @param yc The vertical coordinate of the circle center
* @param radius The circle radius
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void drawCircle(signed int16, signed int16, signed int16);
void sendMatrix(unsigned int16 *);

/**
* Draws a character with it's origin on the given coordinates.
* Depends on putPixel
*
* @param x The horizontal coordinate of the character origin
* @param y The vertical coordinate of the character origin
* @param character The character to be drawn
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void drawCharacter(signed int16, signed int16, char);

/**
* Draws a string with it's origin on the given coordinates, also a spacing in can be given
* to separate each character horizantally from each other.
* Depends on drawCharacter
*
* @param x The horizontal coordinate of the string origin
* @param y The vertical coordinate of the string origin
* @param string The string to be drawn
* @param stringLength The length of the string to be drawn
* @param spacing The amount of horizontal pixels to be used as separation between characters
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void drawString(signed int16, signed int16, char *, unsigned int8, unsigned int8);
void clearPartialMatrix(signed int16, signed int16, signed int16, signed int16);

/**
* Sends the data from the in memory matrix to the MAX7219 devices, this should be done
* only after doing all the drawing and clearing operations to avoid unnecesary cycle wasting
*
* Depends on max7219.c so include it in your preprocessor directives like so:
* #include <max7219.c>
*
* @param pinArray The array of the pins which will be used to load the data in each row of MAX7219
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void sendMatrix(unsigned int16 *);

0 comments on commit a59dd0b

Please sign in to comment.