mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-03-12 02:10:12 +01:00
allow 1, 2, 3 or 4 bytes in shift out
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user