working on driver for the max7219 to test the spi interface. Problem remains with the integration of the device drivers inside the cmake project

spi
polymurph 3 years ago
parent 78ce1a0ec4
commit 978ca001eb

@ -211,7 +211,7 @@ uint32_t spiReadWrite32bit(
spi_ch_t *spi_ch,
uint8_t bits);
//implementation
// implementation
/**
* @brief SPI hardware peripheral reset

@ -138,6 +138,8 @@ uint8_t spiTrx8BitPolling(spiCH_t spi_hw_ch, uint8_t tx_data)
// Wait for RXNE to set -> This will indicate that the Rx buffer is not empty
while (!(SPI_BASE->SR &SPI_SR_RXNE));
// TODO: test read!
return *(uint8_t*)&(SPI_BASE->DR);
}

@ -0,0 +1,22 @@
#include "max7219.h"
void max7219_init(
max7219_t *display,
spi_ch_t *spi_ch)
{
display->spiCH = spi_ch;
}
void max7219_testDisplay(
max7219_t *display,
uint8_t logic)
{
if(logic) {
spiWriteReg(display->spiCH, 0x0F, 0x01);
} else {
spiWriteReg(display->spiCH, 0x0F, 0x00);
}
}

@ -0,0 +1,65 @@
/**
**************************************************************************************************
* @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"
typedef struct{
spi_ch_t *spiCH;
}max7219_t;
#if 0
/*
* @brief TODO:
*/
void max7219_init(
max7219_t *display,
spi_ch_t *spi_ch);
/**
* @brief Test Display
* Test Display by setting logic > 0 and stop testing by setting logic = 0
* In test mode all the LEDs should light up. Stopping testmode will resume back to previous
* setting.
* @param *display pointer to max7219 display object
* @param logic logic state for logic high enter value > 0 and for low enter value = 0
*/
void max7219_testDisplay(
max7219_t *display,
uint8_t logic);
/**
* @brief Shutdown Display
* Shut down the display by setting the logic value > 0. To activate the display again set
* logic = 0.
* @param
*/
void max7219_shutdownDisplay(
max7219_t *display,
uint8_t logic);
#endif
#ifdef _cplusplus
}
#endif
#endif // _MAX7219_H_

@ -6,6 +6,34 @@
#include "timer.h"
#include "spi.h"
//#include "ked/device_drivers/max7219/max7219.h "
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 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)
{
@ -19,6 +47,8 @@ void max7219_test_display(spi_ch_t* spi_ch)
*/
spiWriteReg(spi_ch,0x0F,0x01);
//max7219_testDisplay(spi_ch, 1);
// spiWrite16bit(spi_ch, 0x0F01);
//delayMs(50);
// spiWrite16bit(spi_ch, 0x0F01);
@ -32,6 +62,7 @@ void max7219_test_display(spi_ch_t* spi_ch)
// set mode to shutdown
spiWrite16bit(spi_ch, 0x0F00);
//max7219_testDisplay(spi_ch, 0);
delayMs(200);
/*
pinWrite(spi_ch->pin, 0);
@ -40,7 +71,7 @@ void max7219_test_display(spi_ch_t* spi_ch)
pinWrite(spi_ch->pin,1);
// set mode to shutdown
// set mode to shutdown
// spiWrite16bit(spi_ch, 0x0C00);
delayMs(1000);*/
}
@ -56,6 +87,7 @@ int main(int argc, char *argv[])
uint8_t i = 0;
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
@ -113,6 +145,10 @@ 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
@ -134,7 +170,8 @@ int main(int argc, char *argv[])
while(1){
pinToggle(pinB3);
max7219_test_display(&spi_test_channel);
dispTest(&ledMatrix);
//max7219_test_display(&spi_test_channel);
}
for(i = 0 ; i < 100 ; i++) {

Loading…
Cancel
Save