demo of driving MAX2719 dot matrix displays with STM32F103 Bluepill
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
f103-dotmatrix/project/max2719.c

74 lines
1.4 KiB

#include "max2719.h"
static inline
void send_byte(MAX2719_Cfg *inst, uint8_t b)
{
inst->SPIx->DR = b;
while (!(inst->SPIx->SR & SPI_SR_TXE));
}
static inline
void set_nss(MAX2719_Cfg *inst, bool nss)
{
if (nss) {
inst->CS_GPIOx->BSRR = inst->CS_PINx;
} else {
inst->CS_GPIOx->BRR = inst->CS_PINx;
}
}
static void send_word(MAX2719_Cfg *inst, MAX2719_Command cmd, uint8_t data)
{
send_byte(inst, cmd);
send_byte(inst, data);
}
void max2719_cmd(MAX2719_Cfg *inst, uint32_t nth, MAX2719_Command cmd, uint8_t data)
{
set_nss(inst, 0);
while (inst->SPIx->SR & SPI_SR_BSY);
for (uint32_t i = 0; i < inst->chain_len; i++) {
if (i == inst->chain_len - nth - 1) {
send_word(inst, cmd, data);
} else {
send_word(inst, MAX2719_CMD_NOOP, 0);
}
}
while (inst->SPIx->SR & SPI_SR_BSY);
set_nss(inst, 1);
}
void max2719_cmd_all(MAX2719_Cfg *inst, MAX2719_Command cmd, uint8_t data)
{
set_nss(inst, 0);
while (inst->SPIx->SR & SPI_SR_BSY);
for (uint32_t i = 0; i < inst->chain_len; i++) {
send_word(inst, cmd, data);
}
while (inst->SPIx->SR & SPI_SR_BSY);
set_nss(inst, 1);
}
void max2719_cmd_all_data(MAX2719_Cfg *inst, MAX2719_Command cmd, uint8_t *data)
{
set_nss(inst, 0);
while (inst->SPIx->SR & SPI_SR_BSY);
for (uint32_t i = 0; i < inst->chain_len; i++) {
send_word(inst, cmd, data[inst->chain_len - i - 1]);
}
while (inst->SPIx->SR & SPI_SR_BSY);
set_nss(inst, 1);
}