|
|
|
@ -6,207 +6,34 @@
|
|
|
|
|
#include "timer.h"
|
|
|
|
|
#include "spi.h"
|
|
|
|
|
#include "max7219.h"
|
|
|
|
|
//#include "ked/device_drivers/max7219/max7219.h"
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
typedef enum{
|
|
|
|
|
NO_DECODE_DIGIT_7_TO_0 = 0x00,
|
|
|
|
|
CODE_B_DECODE_ONLY_DIGIT_0 = 0x01,
|
|
|
|
|
CODE_B_DECODE_ONLY_DIGIT_3_TO_0 = 0x0F,
|
|
|
|
|
CODE_B_DECOD_DIGIT_7_TO_0 = 0xFF
|
|
|
|
|
}max7219_decodeMode_t;
|
|
|
|
|
|
|
|
|
|
typedef enum{
|
|
|
|
|
DISPLAY_DIGIT_0 = 0x00,
|
|
|
|
|
DISPLAY_DIGIT_1_TO_0 = 0x01,
|
|
|
|
|
DSIPLAX_DIGIT_2_TO_0 = 0x02,
|
|
|
|
|
DSIPLAX_DIGIT_3_TO_0 = 0x03,
|
|
|
|
|
DSIPLAX_DIGIT_4_TO_0 = 0x04,
|
|
|
|
|
DSIPLAX_DIGIT_5_TO_0 = 0x05,
|
|
|
|
|
DSIPLAX_DIGIT_6_TO_0 = 0x06,
|
|
|
|
|
DSIPLAX_DIGIT_7_TO_0 = 0x07
|
|
|
|
|
}max7219_scanLimit_t;
|
|
|
|
|
|
|
|
|
|
typedef struct{
|
|
|
|
|
spi_ch_t *spiCH;
|
|
|
|
|
}max7219_t;
|
|
|
|
|
|
|
|
|
|
void max7219_init(
|
|
|
|
|
max7219_t *display,
|
|
|
|
|
spi_ch_t *spi_ch)
|
|
|
|
|
{
|
|
|
|
|
display->spiCH = spi_ch;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void max7219_testDisplay(
|
|
|
|
|
max7219_t *display,
|
|
|
|
|
uint8_t logic)
|
|
|
|
|
{
|
|
|
|
|
spiWriteReg(display->spiCH,0x0F, (logic) ? 0x01 : 0x00);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void max7219_shutdownDiaply(
|
|
|
|
|
max7219_t *display,
|
|
|
|
|
uint8_t logic)
|
|
|
|
|
{
|
|
|
|
|
spiWriteReg(display->spiCH,0x0C, (logic) ? 0x00 : 0x01);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void max7219_setDecodeMode(
|
|
|
|
|
max7219_t *display,
|
|
|
|
|
max7219_decodeMode_t dmode)
|
|
|
|
|
{
|
|
|
|
|
spiWriteReg(display->spiCH,0x09,(uint8_t) dmode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void max7219_setIntensity(
|
|
|
|
|
max7219_t *display,
|
|
|
|
|
uint8_t intensity)
|
|
|
|
|
{
|
|
|
|
|
spiWriteReg(display->spiCH, 0x0A, intensity & 0x0F);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void max7219_setScanLimit(
|
|
|
|
|
max7219_t *display,
|
|
|
|
|
max7219_scanLimit_t slimit)
|
|
|
|
|
{
|
|
|
|
|
spiWriteReg(display->spiCH, 0x0B, ((uint8_t) slimit) & 0x0F);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void max7219_setAllLEDsOff(
|
|
|
|
|
max7219_t *display)
|
|
|
|
|
{
|
|
|
|
|
uint8_t i;
|
|
|
|
|
for(i = 0; i < 9; i++) {
|
|
|
|
|
spiWriteReg(display->spiCH, i, 0x00);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void max7219_ledMatrixSetLED(
|
|
|
|
|
max7219_t *display,
|
|
|
|
|
uint8_t row,
|
|
|
|
|
uint8_t col)
|
|
|
|
|
{
|
|
|
|
|
unsigned char A[] = {0b00000000,0b00111100,0b01100110,0b01100110,0b01111110,0b01100110,0b01100110,0b01100110};
|
|
|
|
|
unsigned char B[] = {0b01111000,0b01001000,0b01001000,0b01110000,0b01001000,0b01000100,0b01000100,0b01111100};
|
|
|
|
|
unsigned char C[] = {0b00000000,0b00011110,0b00100000,0b01000000,0b01000000,0b01000000,0b00100000,0b00011110};
|
|
|
|
|
unsigned char D[] = {0b00000000,0b00111000,0b00100100,0b00100010,0b00100010,0b00100100,0b00111000,0b00000000};
|
|
|
|
|
unsigned char E[] = {0b00000000,0b00111100,0b00100000,0b00111000,0b00100000,0b00100000,0b00111100,0b00000000};
|
|
|
|
|
unsigned char F[] = {0b00000000,0b00111100,0b00100000,0b00111000,0b00100000,0b00100000,0b00100000,0b00000000};
|
|
|
|
|
unsigned char G[] = {0b00000000,0b00111110,0b00100000,0b00100000,0b00101110,0b00100010,0b00111110,0b00000000};
|
|
|
|
|
unsigned char H[] = {0b00000000,0b00100100,0b00100100,0b00111100,0b00100100,0b00100100,0b00100100,0b00000000};
|
|
|
|
|
unsigned char I[] = {0b00000000,0b00111000,0b00010000,0b00010000,0b00010000,0b00010000,0b00111000,0b00000000};
|
|
|
|
|
unsigned char J[] = {0b00000000,0b00011100,0b00001000,0b00001000,0b00001000,0b00101000,0b00111000,0b00000000};
|
|
|
|
|
unsigned char K[] = {0b00000000,0b00100100,0b00101000,0b00110000,0b00101000,0b00100100,0b00100100,0b00000000};
|
|
|
|
|
unsigned char L[] = {0b00000000,0b00100000,0b00100000,0b00100000,0b00100000,0b00100000,0b00111100,0b00000000};
|
|
|
|
|
unsigned char M[] = {0b00000000,0b00000000,0b01000100,0b10101010,0b10010010,0b10000010,0b10000010,0b00000000};
|
|
|
|
|
unsigned char N[] = {0b00000000,0b00100010,0b00110010,0b00101010,0b00100110,0b00100010,0b00000000,0b00000000};
|
|
|
|
|
unsigned char O[] = {0b00000000,0b00111100,0b01000010,0b01000010,0b01000010,0b01000010,0b00111100,0b00000000};
|
|
|
|
|
unsigned char P[] = {0b00000000,0b00111000,0b00100100,0b00100100,0b00111000,0b00100000,0b00100000,0b00000000};
|
|
|
|
|
unsigned char Q[] = {0b00000000,0b00111100,0b01000010,0b01000010,0b01000010,0b01000110,0b00111110,0b00000001};
|
|
|
|
|
unsigned char R[] = {0b00000000,0b00111000,0b00100100,0b00100100,0b00111000,0b00100100,0b00100100,0b00000000};
|
|
|
|
|
unsigned char S[] = {0b00000000,0b00111100,0b00100000,0b00111100,0b00000100,0b00000100,0b00111100,0b00000000};
|
|
|
|
|
unsigned char T[] = {0b00000000,0b01111100,0b00010000,0b00010000,0b00010000,0b00010000,0b00010000,0b00000000};
|
|
|
|
|
unsigned char U[] = {0b00000000,0b01000010,0b01000010,0b01000010,0b01000010,0b00100100,0b00011000,0b00000000};
|
|
|
|
|
unsigned char V[] = {0b00000000,0b00100010,0b00100010,0b00100010,0b00010100,0b00010100,0b00001000,0b00000000};
|
|
|
|
|
unsigned char W[] = {0b00000000,0b10000010,0b10010010,0b01010100,0b01010100,0b00101000,0b00000000,0b00000000};
|
|
|
|
|
unsigned char X[] = {0b00000000,0b01000010,0b00100100,0b00011000,0b00011000,0b00100100,0b01000010,0b00000000};
|
|
|
|
|
unsigned char Y[] = {0b00000000,0b01000100,0b00101000,0b00010000,0b00010000,0b00010000,0b00010000,0b00000000};
|
|
|
|
|
unsigned char Z[] = {0b00000000,0b00111100,0b00000100,0b00001000,0b00010000,0b00100000,0b00111100,0b00000000};
|
|
|
|
|
|
|
|
|
|
uint8_t val = 0xAE;
|
|
|
|
|
|
|
|
|
|
row = (row & 0x07) + 1;
|
|
|
|
|
col = 1 << (col & 0x07);
|
|
|
|
|
|
|
|
|
|
spiWriteReg(display->spiCH, row,col);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void max7219_rawWrite(
|
|
|
|
|
max7219_t *display,
|
|
|
|
|
uint8_t reg,
|
|
|
|
|
uint8_t data)
|
|
|
|
|
{
|
|
|
|
|
spiWriteReg(display->spiCH, reg, data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void max7219_printLedMatrix(
|
|
|
|
|
max7219_t *display,
|
|
|
|
|
uint8_t matrix[])
|
|
|
|
|
{
|
|
|
|
|
uint8_t i = 0;
|
|
|
|
|
|
|
|
|
|
for(i = 0; i < 8; i ++) {
|
|
|
|
|
spiWriteReg(display->spiCH, i+1, matrix[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void max7219_ledMatrixUnsetLED(
|
|
|
|
|
max7219_t *display,
|
|
|
|
|
uint8_t row,
|
|
|
|
|
uint8_t col)
|
|
|
|
|
{
|
|
|
|
|
row = (row & 0x07) + 1;
|
|
|
|
|
col = 1 << (col & 0x07);
|
|
|
|
|
// TODO: find out how to turn off LED
|
|
|
|
|
spiWriteReg(display->spiCH, row,col+1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// daysichained matrix
|
|
|
|
|
typedef struct{
|
|
|
|
|
spi_ch_t *spiCH;
|
|
|
|
|
uint8_t nDevices;
|
|
|
|
|
}max7219_dm_t;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void max7219_dm_write(
|
|
|
|
|
max7219_dm_t *matrix,
|
|
|
|
|
uint8_t **data)
|
|
|
|
|
{
|
|
|
|
|
uint8_t i = 0;
|
|
|
|
|
uint8_t j = 0;
|
|
|
|
|
// TODO: Test it out
|
|
|
|
|
for(i = 0; i < 8; i++) {
|
|
|
|
|
pinWrite(matrix->spiCH->pin, 0);
|
|
|
|
|
for(j = 0; j < matrix->nDevices; j++) {
|
|
|
|
|
spiTrx8BitPolling(matrix->spiCH->spi, i+1); // reg
|
|
|
|
|
spiTrx8BitPolling(matrix->spiCH->spi, data[j][i]);
|
|
|
|
|
}
|
|
|
|
|
pinWrite(matrix->spiCH->pin, 1);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void dispTest(max7219_t *disp)
|
|
|
|
|
{
|
|
|
|
|
max7219_testDisplay(disp, 1);
|
|
|
|
|
delayMs(500);
|
|
|
|
|
max7219_testDisplay(disp, 0);
|
|
|
|
|
delayMs(500);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void max7219_test_display(spi_ch_t* spi_ch)
|
|
|
|
|
{
|
|
|
|
|
// set mode to display test
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
pinWrite(spi_ch->pin, 0);
|
|
|
|
|
spiTrx(spi_ch->spi, 0x0F);
|
|
|
|
|
spiTrx(spi_ch->spi, 0x01);
|
|
|
|
|
pinWrite(spi_ch->pin,1);
|
|
|
|
|
*/
|
|
|
|
|
spiWriteReg(spi_ch,0x0F,0x01);
|
|
|
|
|
|
|
|
|
|
//max7219_testDisplay(spi_ch, 1);
|
|
|
|
|
|
|
|
|
|
// spiWrite16bit(spi_ch, 0x0F01);
|
|
|
|
|
//delayMs(50);
|
|
|
|
|
// spiWrite16bit(spi_ch, 0x0F01);
|
|
|
|
|
delayMs(200);
|
|
|
|
|
/*
|
|
|
|
|
pinWrite(spi_ch->pin, 0);
|
|
|
|
|
spiTrx(spi_ch->spi, 0x0F);
|
|
|
|
|
spiTrx(spi_ch->spi, 0x00);
|
|
|
|
|
pinWrite(spi_ch->pin,1);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// set mode to shutdown
|
|
|
|
|
spiWrite16bit(spi_ch, 0x0F00);
|
|
|
|
|
//max7219_testDisplay(spi_ch, 0);
|
|
|
|
|
delayMs(200);
|
|
|
|
|
/*
|
|
|
|
|
pinWrite(spi_ch->pin, 0);
|
|
|
|
|
spiTrx(spi_ch->spi, 0x0C);
|
|
|
|
|
spiTrx(spi_ch->spi, 0x00);
|
|
|
|
|
pinWrite(spi_ch->pin,1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// set mode to shutdown
|
|
|
|
|
// spiWrite16bit(spi_ch, 0x0C00);
|
|
|
|
|
delayMs(1000);*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void max7219_SetIntensity(spi_ch_t* spi_ch, uint8_t intensity)
|
|
|
|
|
{
|
|
|
|
|
spiWrite16bit(spi_ch, 0x0A00 | intensity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
@ -214,6 +41,17 @@ int main(int argc, char *argv[])
|
|
|
|
|
uint8_t i = 0;
|
|
|
|
|
uint8_t j = 0;
|
|
|
|
|
|
|
|
|
|
uint8_t f[] = {
|
|
|
|
|
0x00,
|
|
|
|
|
0x7E,
|
|
|
|
|
0x40,
|
|
|
|
|
0x40,
|
|
|
|
|
0x3E,
|
|
|
|
|
0x40,
|
|
|
|
|
0x40,
|
|
|
|
|
0x40
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
uint8_t matrix[] = {
|
|
|
|
|
0xAA,
|
|
|
|
|
0xFF,
|
|
|
|
@ -329,11 +167,51 @@ int main(int argc, char *argv[])
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, matrix);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, F);
|
|
|
|
|
//max7219_ledMatrixSetLED(&ledMatrix, 0, 0);
|
|
|
|
|
delayMs(500);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, matrix_1);
|
|
|
|
|
delayMs(100);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, A);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, T);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, I);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_setAllLEDsOff(&ledMatrix);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, G);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, E);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, N);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, T);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, I);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_setAllLEDsOff(&ledMatrix);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, E);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, D);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, W);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, I);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, N);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_setAllLEDsOff(&ledMatrix);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
|