From aee5dbf99d64ea46b9b9ea2c4fcc4603b5c955f0 Mon Sep 17 00:00:00 2001 From: openshwprojects Date: Sun, 9 Apr 2023 08:24:38 +0200 Subject: [PATCH] allow 1, 2, 3 or 4 bytes in shift out --- src/driver/drv_max72xx_internal.c | 9 +++++---- src/driver/drv_shiftRegister.c | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/driver/drv_max72xx_internal.c b/src/driver/drv_max72xx_internal.c index 4cbfc2e08..255cdd441 100644 --- a/src/driver/drv_max72xx_internal.c +++ b/src/driver/drv_max72xx_internal.c @@ -32,15 +32,16 @@ #define MAX72XX_DELAY // #define MAX72XX_DELAY usleep(123); -void PORT_shiftOut(int dataPin, int clockPin, int bitOrder, int val) +void PORT_shiftOut(int dataPin, int clockPin, int bitOrder, int val, int totalBytes) { int i; + int totalBits = totalBytes * 8; - for (i = 0; i < 8; i++) { + for (i = 0; i < totalBits; i++) { if (bitOrder == LSBFIRST) HAL_PIN_SetOutputValue(dataPin, !!(val & (1 << i))); else - HAL_PIN_SetOutputValue(dataPin, !!(val & (1 << (7 - i)))); + HAL_PIN_SetOutputValue(dataPin, !!(val & (1 << ((totalBits - 1) - i)))); MAX72XX_DELAY HAL_PIN_SetOutputValue(clockPin, HIGH); @@ -64,7 +65,7 @@ void MAX72XX_spiTransfer(max72XX_t *led, int adddr, unsigned char opcode, byte d HAL_PIN_SetOutputValue(led->port_cs, LOW); MAX72XX_DELAY for (i = maxbytes; i > 0; i--) - PORT_shiftOut(led->port_mosi, led->port_clk, MSBFIRST, led->spidata[i - 1]); + PORT_shiftOut(led->port_mosi, led->port_clk, MSBFIRST, led->spidata[i - 1], 1); MAX72XX_DELAY HAL_PIN_SetOutputValue(led->port_cs, HIGH); } diff --git a/src/driver/drv_shiftRegister.c b/src/driver/drv_shiftRegister.c index 10e209076..b5779fe77 100644 --- a/src/driver/drv_shiftRegister.c +++ b/src/driver/drv_shiftRegister.c @@ -58,11 +58,11 @@ void Shift_Init() { HAL_PIN_Setup_Output(g_clk); } -void PORT_shiftOut(int dataPin, int clockPin, int bitOrder, int val); +void PORT_shiftOut(int dataPin, int clockPin, int bitOrder, int val, int totalRegisters); -void PORT_shiftOutLatch(int dataPin, int clockPin, int latchPin, int bitOrder, int val) { +void PORT_shiftOutLatch(int dataPin, int clockPin, int latchPin, int bitOrder, int val, int totalRegisters) { HAL_PIN_SetOutputValue(latchPin, 0); - PORT_shiftOut(dataPin, clockPin, bitOrder, val); + PORT_shiftOut(dataPin, clockPin, bitOrder, val, totalRegisters); HAL_PIN_SetOutputValue(latchPin, 1); } @@ -90,7 +90,7 @@ void Shift_OnChannelChanged(int ch, int value) { BIT_CLEAR(g_currentValue, ch); } addLogAdv(LOG_INFO, LOG_FEATURE_MAIN, "Will send value %i", g_currentValue); - PORT_shiftOutLatch(g_data, g_clk, g_latch, g_order, g_currentValue); + PORT_shiftOutLatch(g_data, g_clk, g_latch, g_order, g_currentValue, g_totalRegisters); }