parent
c3096dfd23
commit
6842f8a6c1
@ -0,0 +1,126 @@
|
||||
#include "max7219.h"
|
||||
|
||||
void max7219_init(
|
||||
max7219_t *display,
|
||||
spi_ch_t *spi_ch)
|
||||
{
|
||||
display->spiCH = spi_ch;
|
||||
}
|
||||
|
||||
void h
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
// 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
|
||||
|
@ -0,0 +1,160 @@
|
||||
/**
|
||||
**************************************************************************************************
|
||||
* @file max7219.h
|
||||
* @author Kerem Yollu & Edwin Koch
|
||||
* @date 25.08.2022
|
||||
* @version 1.0
|
||||
**************************************************************************************************
|
||||
* @brief
|
||||
*
|
||||
* **Detailed Description :**
|
||||
*
|
||||
* @todo
|
||||
**************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _MAX7219_H_
|
||||
#define _MAX7219_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include "spi.h"
|
||||
#include "pin.h"
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @brief max7219 matrix class
|
||||
*
|
||||
* The matrix can be ccomposed of only one ore many devices daysichained
|
||||
* together.
|
||||
* @var *spiCH Pointer to spi channel object
|
||||
* @var nDevicesChained Ammount of devices hoocked up together
|
||||
* @var brightness brightness of the matrix
|
||||
* @var buf Array of matrix content. Each n to n + 7 (n can be 0, 8, 16, etc) represents the
|
||||
* content of one individual max7219 device.
|
||||
*/
|
||||
typedef struct{
|
||||
spi_ch_t *spiCH;
|
||||
uint8_t nDevicesChained;
|
||||
uint8_t brightness;
|
||||
uint8_t buf[];
|
||||
}max7219_mx_t;
|
||||
|
||||
void max7219_t_mx_init(
|
||||
max7219_mx_t *matrix,
|
||||
spi_ch_t *spiChannel,
|
||||
uint8_t *pBuf,
|
||||
uint8_t bufLen);
|
||||
|
||||
void max7219_mx_setPixel(
|
||||
max7219_mx_t *matrix,
|
||||
uint8_t row,
|
||||
uint8_t col,
|
||||
uint8_t logic);
|
||||
|
||||
void max7219_mx_print(
|
||||
max7219_mx_t *matrix,
|
||||
char *text,
|
||||
uint8_t len);
|
||||
|
||||
void max7219_mx_show(
|
||||
max7219_mx_t *matrix);
|
||||
|
||||
void max7219_mx_shutdown(
|
||||
max7219_mx_t *matrix);
|
||||
|
||||
void max7219_mx_test(
|
||||
max7219_mx_t *matrix);
|
||||
|
||||
void max7219_mx_mapMatrix(
|
||||
max7219_mx_t *matrix,
|
||||
uint8_t *map);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
|
||||
void max7219_init(
|
||||
max7219_t *display,
|
||||
spi_ch_t *spi_ch);
|
||||
|
||||
void max7219_testDisplay(
|
||||
max7219_t *display,
|
||||
uint8_t logic);
|
||||
|
||||
void max7219_shutdownDiaply(
|
||||
max7219_t *display,
|
||||
uint8_t logic);
|
||||
|
||||
void max7219_setDecodeMode(
|
||||
max7219_t *display,
|
||||
max7219_decodeMode_t dmode);
|
||||
|
||||
void max7219_setIntensity(
|
||||
max7219_t *display,
|
||||
uint8_t intensity);
|
||||
|
||||
void max7219_setScanLimit(
|
||||
max7219_t *display,
|
||||
max7219_scanLimit_t slimit);
|
||||
|
||||
void max7219_setAllLEDsOff(
|
||||
max7219_t *display);
|
||||
|
||||
void max7219_ledMatrixSetLED(
|
||||
max7219_t *display,
|
||||
uint8_t row,
|
||||
uint8_t col);
|
||||
|
||||
void max7219_rawWrite(
|
||||
max7219_t *display,
|
||||
uint8_t reg,
|
||||
uint8_t data);
|
||||
|
||||
void max7219_printLedMatrix(
|
||||
max7219_t *display,
|
||||
uint8_t matrix[]);
|
||||
|
||||
void max7219_ledMatrixUnsetLED(
|
||||
max7219_t *display,
|
||||
uint8_t row,
|
||||
uint8_t col);
|
||||
#if 0
|
||||
// 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);
|
||||
#endif
|
||||
*/
|
||||
#ifdef _cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _MAX7219_H_
|
Loading…
Reference in new issue