|
|
|
@ -6,235 +6,14 @@
|
|
|
|
|
#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)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#include "ad9833.h"
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
uint8_t i = 0;
|
|
|
|
|
uint8_t j = 0;
|
|
|
|
|
|
|
|
|
|
uint8_t matrix[] = {
|
|
|
|
|
0xAA,
|
|
|
|
|
0xFF,
|
|
|
|
|
0xAA,
|
|
|
|
|
0xFF,
|
|
|
|
|
0xAA,
|
|
|
|
|
0xFF,
|
|
|
|
|
0xAA,
|
|
|
|
|
0xFF};
|
|
|
|
|
|
|
|
|
|
uint8_t matrix_1[] = {
|
|
|
|
|
0x11,
|
|
|
|
|
0x11,
|
|
|
|
|
0x11,
|
|
|
|
|
0x11,
|
|
|
|
|
0x11,
|
|
|
|
|
0x11,
|
|
|
|
|
0x11,
|
|
|
|
|
0x11};
|
|
|
|
|
spi_ch_t spi_test_channel;
|
|
|
|
|
max7219_t ledMatrix;
|
|
|
|
|
|
|
|
|
|
// making array with all available timers
|
|
|
|
|
delayInitMs(8000000, 1000); // Clock Freq and Divider for ARM library
|
|
|
|
@ -287,13 +66,9 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
|
|
|
|
spiSetupCH(&spi_test_channel, SPI_CH_1, pinA3);
|
|
|
|
|
|
|
|
|
|
// LED Matrix object setup
|
|
|
|
|
//ledMatrix.spiCH = &spi_test_channel;
|
|
|
|
|
max7219_init(&ledMatrix, &spi_test_channel);
|
|
|
|
|
|
|
|
|
|
spiEnable(SPI_CH_1);
|
|
|
|
|
/*
|
|
|
|
|
* MAX7219 hoockup for this example
|
|
|
|
|
* SPI hoockup for this example
|
|
|
|
|
*
|
|
|
|
|
* Signal pin nucleo
|
|
|
|
|
* --------------------------
|
|
|
|
@ -310,66 +85,10 @@ int main(int argc, char *argv[])
|
|
|
|
|
delayMs(50);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
max7219_testDisplay(&ledMatrix,1);
|
|
|
|
|
delayMs(500);
|
|
|
|
|
max7219_testDisplay(&ledMatrix,0);
|
|
|
|
|
max7219_shutdownDiaply(&ledMatrix,0);
|
|
|
|
|
max7219_setDecodeMode(&ledMatrix, NO_DECODE_DIGIT_7_TO_0);
|
|
|
|
|
max7219_setScanLimit(&ledMatrix, DSIPLAX_DIGIT_7_TO_0);
|
|
|
|
|
max7219_setIntensity(&ledMatrix,0x01);
|
|
|
|
|
|
|
|
|
|
max7219_ledMatrixSetLED(&ledMatrix,0,0);
|
|
|
|
|
delayMs(1000);
|
|
|
|
|
max7219_setAllLEDsOff(&ledMatrix);
|
|
|
|
|
/*
|
|
|
|
|
for(i=0; i < 8; i++) {
|
|
|
|
|
max7219_ledMatrixSetLED(&ledMatrix,i,i);
|
|
|
|
|
delayMs(100);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, matrix);
|
|
|
|
|
//max7219_ledMatrixSetLED(&ledMatrix, 0, 0);
|
|
|
|
|
delayMs(100);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, matrix_1);
|
|
|
|
|
delayMs(100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
|
for(i=0; i < 0x8; i++) {
|
|
|
|
|
max7219_ledMatrixSetLED(&ledMatrix,i,i+j);
|
|
|
|
|
delayMs(100);
|
|
|
|
|
}
|
|
|
|
|
//delayMs(10);
|
|
|
|
|
j++;
|
|
|
|
|
if(j > 7) j =0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
while(1){
|
|
|
|
|
pinToggle(pinB3);
|
|
|
|
|
dispTest(&ledMatrix);
|
|
|
|
|
//max7219_test_display(&spi_test_channel);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
for(i = 0 ; i < 100 ; i++) {
|
|
|
|
|
pinWrite(pinB3, 1);
|
|
|
|
|
//pinWrite(pinA4,1);
|
|
|
|
|
delayMs(100);
|
|
|
|
|
pinWrite(pinB3, 0);
|
|
|
|
|
//pinWrite(pinA4,0);
|
|
|
|
|
delayMs(900);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//timer_capture_compare_test(timer_2);
|
|
|
|
|
//print_Usart(usart2, "All is working fine \r\n");
|
|
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|