DMD.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: Beerware
2 /**
3  * @file DMD.c
4  * @brief Dot Matrix Display driver
5  * @ingroup DMD
6  * @defgroup DMD Dot Matrix Display
7  * @author Michael Fitzmayer
8  * @copyright "THE BEER-WARE LICENCE" (Revision 42)
9  */
10 
11 #include <stdbool.h>
12 #include <stdint.h>
13 #include "DMD.h"
14 #include "MCAL.h"
15 
16 /**
17  * @struct DMDData
18  * @brief DMD driver data
19  */
20 typedef struct
21 {
22  uint8_t* pu8Buffer; ///< DMD image buffer
23 
24 } DMDData;
25 
26 /**
27  * @var _stDMD
28  * @brief DMD driver private data
29  */
30 static DMDData _stDMD = { 0 };
31 
32 /**
33  * @brief Latch shift register data to output
34  */
35 void DMD_Latch(void)
36 {
38  MCAL_Sleep(1);
40 }
41 
42 /**
43  * @brief Light up row group
44  * @param eRows
45  * DMD row group
46  */
48 {
49  switch (eRows)
50  {
51  case DMD_ROWS_1_5_9_13:
54  break;
55  case DMD_ROWS_2_6_10_14:
58  break;
59  case DMD_ROWS_3_7_11_15:
62  break;
63  case DMD_ROWS_4_8_12_16:
66  break;
67  }
68 }
69 
70 /**
71  * @brief Set OE pin low; all rows off
72  */
73 void DMD_OE_RowsOff(void)
74 {
76 }
77 
78 /**
79  * @brief Set OE pin high; all rows on
80  */
81 void DMD_OE_RowsOn(void)
82 {
84 }
85 
86 /**
87  * @brief Set DMD image buffer
88  * @param pu8Buffer
89  * Pointer to image buffer
90  */
91 void DMD_SetBuffer(uint8_t* pu8Buffer)
92 {
93  _stDMD.pu8Buffer = pu8Buffer;
94 }
95 
96 /**
97  * @brief Update dot matrix display
98  * @details Need to be called continously
99  */
100 void DMD_Update(void)
101 {
102  static uint8_t u8Scanline = 0;
103 
104  uint16_t u16Offset = 4U * u8Scanline;
105  for (uint8_t u8Idx = 0; u8Idx < 4U; u8Idx++)
106  {
107  SPI_Transmit(_stDMD.pu8Buffer + (u16Offset + u8Idx + 48), 1);
108  SPI_Transmit(_stDMD.pu8Buffer + (u16Offset + u8Idx + 32), 1);
109  SPI_Transmit(_stDMD.pu8Buffer + (u16Offset + u8Idx + 16), 1);
110  SPI_Transmit(_stDMD.pu8Buffer + (u16Offset + u8Idx), 1);
111  }
112 
113  DMD_OE_RowsOff();
114  DMD_Latch();
115 
116  switch (u8Scanline)
117  {
118  case 0:
120  u8Scanline = 1;
121  break;
122  case 1:
124  u8Scanline = 2;
125  break;
126  case 2:
128  u8Scanline = 3;
129  break;
130  case 3:
132  u8Scanline = 0;
133  break;
134  }
135 
136  DMD_OE_RowsOn();
137 }
void DMD_SetBuffer(uint8_t *pu8Buffer)
Set DMD image buffer.
Definition: DMD.c:91
static DMDData _stDMD
DMD driver private data.
Definition: DMD.c:30
#define DMD_SCLK_Pin
DMD SCLK pin.
Definition: DMD.h:16
@ DMD_ROWS_2_6_10_14
DMD rows 2, 6, 10 and 14.
Definition: DMD.h:35
#define DMD_GPIO_Port
DMD GPIO port.
Definition: DMD.h:25
void GPIO_RaiseHigh(GPIOPort ePort, uint16_t u16PinMask)
Raise output pin(s) high.
Definition: MCAL.c:70
void DMD_Latch(void)
Latch shift register data to output.
Definition: DMD.c:35
uint8_t * pu8Buffer
DMD image buffer.
Definition: DMD.c:22
void DMD_LightRows(DMDRows eRows)
Light up row group.
Definition: DMD.c:47
void GPIO_PullDown(GPIOPort ePort, uint16_t u16PinMask)
Pull output pin(s) low.
Definition: MCAL.c:57
#define DMD_A_Pin
DMD A pin.
Definition: DMD.h:19
void DMD_OE_RowsOff(void)
Set OE pin low; all rows off.
Definition: DMD.c:73
DMDRows
Dot Matrix Display rows.
Definition: DMD.h:32
DMD driver data.
Definition: DMD.c:20
void MCAL_Sleep(uint16_t u16DelayInUs)
Microsecond delay (blocking)
Definition: MCAL.c:207
Microcontroller Abstraction Layer.
@ DMD_ROWS_4_8_12_16
DMD rows 4, 8, 12 and 16.
Definition: DMD.h:37
@ DMD_ROWS_3_7_11_15
DMD rows 3, 7, 11 and 15.
Definition: DMD.h:36
void DMD_Update(void)
Update dot matrix display.
Definition: DMD.c:100
void DMD_OE_RowsOn(void)
Set OE pin high; all rows on.
Definition: DMD.c:81
#define DMD_B_Pin
DMD B pin.
Definition: DMD.h:22
Dot Matrix Display driver.
@ DMD_ROWS_1_5_9_13
DMD rows 1, 5, 9 and 13.
Definition: DMD.h:34
#define DMD_OE_Pin
DMD OE pin.
Definition: DMD.h:13
int SPI_Transmit(uint8_t *pu8TxData, uint16_t u16Size)
Transmit an amount via SPI.
Definition: MCAL.c:279