sdfgdsfg
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#include "max2719.h"
|
#include "max2719.h"
|
||||||
#include "dotmatrix.h"
|
#include "dotmatrix.h"
|
||||||
#include "malloc_safe.h"
|
#include "malloc_safe.h"
|
||||||
|
#include "com/debug.h"
|
||||||
|
|
||||||
DotMatrix_Cfg* dmtx_init(DotMatrix_Init *init)
|
DotMatrix_Cfg* dmtx_init(DotMatrix_Init *init)
|
||||||
{
|
{
|
||||||
@@ -37,6 +38,11 @@ void dmtx_show(DotMatrix_Cfg* dmtx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dmtx_clear(DotMatrix_Cfg* dmtx)
|
||||||
|
{
|
||||||
|
memset(dmtx->screen, 0, dmtx->drv.chain_len*8);
|
||||||
|
}
|
||||||
|
|
||||||
void dmtx_intensity(DotMatrix_Cfg* dmtx, uint8_t intensity)
|
void dmtx_intensity(DotMatrix_Cfg* dmtx, uint8_t intensity)
|
||||||
{
|
{
|
||||||
max2719_cmd_all(&dmtx->drv, MAX2719_CMD_INTENSITY, intensity & 0x0F);
|
max2719_cmd_all(&dmtx->drv, MAX2719_CMD_INTENSITY, intensity & 0x0F);
|
||||||
@@ -46,3 +52,26 @@ void dmtx_blank(DotMatrix_Cfg* dmtx, bool blank)
|
|||||||
{
|
{
|
||||||
max2719_cmd_all(&dmtx->drv, MAX2719_CMD_SHUTDOWN, blank & 0x01);
|
max2719_cmd_all(&dmtx->drv, MAX2719_CMD_SHUTDOWN, blank & 0x01);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dmtx_set(DotMatrix_Cfg* dmtx, int32_t x, int32_t y, bool bit)
|
||||||
|
{
|
||||||
|
if (x < 0 || y < 0) return;
|
||||||
|
if ((uint32_t)x >= dmtx->cols*8 || (uint32_t)y >= dmtx->rows*8) return;
|
||||||
|
|
||||||
|
uint32_t cell_x = (uint32_t)x >> 3;
|
||||||
|
uint8_t xd = x & 7;
|
||||||
|
|
||||||
|
// resolve cell
|
||||||
|
uint32_t digit = y & 7;
|
||||||
|
cell_x += ((uint32_t)y >> 3) * dmtx->cols;
|
||||||
|
|
||||||
|
uint32_t cell_idx = (digit * dmtx->drv.chain_len) + cell_x;
|
||||||
|
|
||||||
|
uint8_t *cell = &dmtx->screen[cell_idx];
|
||||||
|
|
||||||
|
if (bit) {
|
||||||
|
*cell |= bit << xd;
|
||||||
|
} else {
|
||||||
|
*cell &= ~(bit << xd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -34,4 +34,16 @@ void dmtx_intensity(DotMatrix_Cfg* dmtx, uint8_t intensity);
|
|||||||
/** Display on/off */
|
/** Display on/off */
|
||||||
void dmtx_blank(DotMatrix_Cfg* dmtx, bool blank);
|
void dmtx_blank(DotMatrix_Cfg* dmtx, bool blank);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Send a single bit
|
||||||
|
* @param dmtx : driver struct
|
||||||
|
* @param x : pixel X
|
||||||
|
* @param y : pixel Y
|
||||||
|
* @param bit : 1 or 0
|
||||||
|
*/
|
||||||
|
void dmtx_set(DotMatrix_Cfg* dmtx, int32_t x, int32_t y, bool bit);
|
||||||
|
|
||||||
|
/** Clear the screen (not showing) */
|
||||||
|
void dmtx_clear(DotMatrix_Cfg* dmtx);
|
||||||
|
|
||||||
#endif // MATRIXDSP_H
|
#endif // MATRIXDSP_H
|
||||||
|
|||||||
+24
-10
@@ -35,15 +35,12 @@ int main(void)
|
|||||||
dmtx_cfg.CS_GPIOx = GPIOA;
|
dmtx_cfg.CS_GPIOx = GPIOA;
|
||||||
dmtx_cfg.CS_PINx = GPIO_Pin_4;
|
dmtx_cfg.CS_PINx = GPIO_Pin_4;
|
||||||
dmtx_cfg.SPIx = SPI1;
|
dmtx_cfg.SPIx = SPI1;
|
||||||
dmtx_cfg.cols = 4;
|
dmtx_cfg.cols = 2;
|
||||||
dmtx_cfg.rows = 1;
|
dmtx_cfg.rows = 2;
|
||||||
|
|
||||||
dmtx = dmtx_init(&dmtx_cfg);
|
dmtx = dmtx_init(&dmtx_cfg);
|
||||||
|
|
||||||
dmtx->screen[0] = 0xF0;
|
dmtx_intensity(dmtx, 2);
|
||||||
dmtx->screen[4] = 0x0F;
|
|
||||||
|
|
||||||
dmtx_show(dmtx);
|
|
||||||
|
|
||||||
ms_time_t last;
|
ms_time_t last;
|
||||||
while (1) {
|
while (1) {
|
||||||
@@ -52,10 +49,27 @@ int main(void)
|
|||||||
}
|
}
|
||||||
poll_subsystems();
|
poll_subsystems();
|
||||||
|
|
||||||
dmtx_blank(dmtx, false);
|
// 1
|
||||||
delay_ms(250);
|
dmtx_clear(dmtx);
|
||||||
dmtx_blank(dmtx, true);
|
for (int i = 0; i <= 15; i++) {
|
||||||
delay_ms(250);
|
dmtx_set(dmtx, i, i, true);
|
||||||
|
dmtx_set(dmtx, i+2, i-2, true);
|
||||||
|
dmtx_set(dmtx, i-2, i+2, true);
|
||||||
|
}
|
||||||
|
dmtx_show(dmtx);
|
||||||
|
|
||||||
|
delay_ms(500);
|
||||||
|
|
||||||
|
// 2
|
||||||
|
dmtx_clear(dmtx);
|
||||||
|
for (int i = 0; i <= 15; i++) {
|
||||||
|
dmtx_set(dmtx, 15-i, i, true);
|
||||||
|
dmtx_set(dmtx, 15-(i+2), i-2, true);
|
||||||
|
dmtx_set(dmtx, 15-(i-2), i+2, true);
|
||||||
|
}
|
||||||
|
dmtx_show(dmtx);
|
||||||
|
|
||||||
|
delay_ms(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user