/**
  **************************************************************************************************
  * @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;

typedef struct{
	spi_ch_t *spiCH;
}max7219_t;

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_