Apply coding standards to Max7219 code

master
Scott Lahteine 7 years ago
parent aa612124f2
commit 8f57a3e28a

@ -102,12 +102,9 @@ void Max7219(const uint8_t reg, const uint8_t data) {
void Max7219_LED_Set(const uint8_t row, const uint8_t col, const bool on) { void Max7219_LED_Set(const uint8_t row, const uint8_t col, const bool on) {
if (row > 7 || col > 7) { if (row > 7 || col > 7) {
int r,c; SERIAL_ECHOPAIR("??? Max7219_LED_Set(", (int)row);
r = row; SERIAL_ECHOPAIR(",", (int)col);
c = col; SERIAL_ECHOLNPGM(")");
SERIAL_ECHOPAIR("??? Max7219_LED_Set(",r);
SERIAL_ECHOPAIR(",",c);
SERIAL_ECHO(")\n");
return; return;
} }
if (TEST(LEDs[row], col) == on) return; // if LED is already on/off, leave alone if (TEST(LEDs[row], col) == on) return; // if LED is already on/off, leave alone
@ -117,12 +114,9 @@ void Max7219_LED_Set(const uint8_t row, const uint8_t col, const bool on) {
void Max7219_LED_On(const uint8_t col, const uint8_t row) { void Max7219_LED_On(const uint8_t col, const uint8_t row) {
if (row > 7 || col > 7) { if (row > 7 || col > 7) {
int r,c; SERIAL_ECHOPAIR("??? Max7219_LED_On(", (int)col);
r = row; SERIAL_ECHOPAIR(",", (int)row);
c = col; SERIAL_ECHOLNPGM(")");
SERIAL_ECHOPAIR("??? Max7219_LED_On(",c);
SERIAL_ECHOPAIR(",",r);
SERIAL_ECHO(")\n");
return; return;
} }
Max7219_LED_Set(col, row, true); Max7219_LED_Set(col, row, true);
@ -130,12 +124,9 @@ void Max7219_LED_On(const uint8_t col, const uint8_t row) {
void Max7219_LED_Off(const uint8_t col, const uint8_t row) { void Max7219_LED_Off(const uint8_t col, const uint8_t row) {
if (row > 7 || col > 7) { if (row > 7 || col > 7) {
int r,c; SERIAL_ECHOPAIR("??? Max7219_LED_Off(", (int)row);
r = row; SERIAL_ECHOPAIR(",", (int)col);
c = col; SERIAL_ECHOLNPGM(")");
SERIAL_ECHOPAIR("??? Max7219_LED_Off(",r);
SERIAL_ECHOPAIR(",",c);
SERIAL_ECHO(")\n");
return; return;
} }
Max7219_LED_Set(col, row, false); Max7219_LED_Set(col, row, false);
@ -143,12 +134,9 @@ void Max7219_LED_Off(const uint8_t col, const uint8_t row) {
void Max7219_LED_Toggle(const uint8_t col, const uint8_t row) { void Max7219_LED_Toggle(const uint8_t col, const uint8_t row) {
if (row > 7 || col > 7) { if (row > 7 || col > 7) {
int r,c; SERIAL_ECHOPAIR("??? Max7219_LED_Toggle(", (int)row);
r = row; SERIAL_ECHOPAIR(",", (int)col);
c = col; SERIAL_ECHOLNPGM(")");
SERIAL_ECHOPAIR("??? Max7219_LED_Toggle(",r);
SERIAL_ECHOPAIR(",",c);
SERIAL_ECHO(")\n");
return; return;
} }
if (TEST(LEDs[row], col)) if (TEST(LEDs[row], col))
@ -159,10 +147,8 @@ void Max7219_LED_Toggle(const uint8_t col, const uint8_t row) {
void Max7219_Clear_Column(const uint8_t col) { void Max7219_Clear_Column(const uint8_t col) {
if (col > 7) { if (col > 7) {
int c; SERIAL_ECHOPAIR("??? Max7219_Clear_Column(", (int)col);
c = col; SERIAL_ECHOLNPGM(")");
SERIAL_ECHOPAIR("??? Max7219_Clear_Column(",c);
SERIAL_ECHO(")\n");
return; return;
} }
LEDs[col] = 0; LEDs[col] = 0;
@ -171,10 +157,8 @@ void Max7219_Clear_Column(const uint8_t col) {
void Max7219_Clear_Row(const uint8_t row) { void Max7219_Clear_Row(const uint8_t row) {
if (row > 7) { if (row > 7) {
int r; SERIAL_ECHOPAIR("??? Max7219_Clear_Row(", (int)row);
r = row; SERIAL_ECHOLNPGM(")");
SERIAL_ECHOPAIR("??? Max7219_Clear_Row(",r);
SERIAL_ECHO(")\n");
return; return;
} }
for (uint8_t c = 0; c <= 7; c++) for (uint8_t c = 0; c <= 7; c++)
@ -182,13 +166,10 @@ void Max7219_Clear_Row(const uint8_t row) {
} }
void Max7219_Set_Row(const uint8_t row, const uint8_t val) { void Max7219_Set_Row(const uint8_t row, const uint8_t val) {
if (row > 7 || val>255) { if (row > 7) {
int r, v; SERIAL_ECHOPAIR("??? Max7219_Set_Row(", (int)row);
r = row; SERIAL_ECHOPAIR(",", (int)val);
v = val; SERIAL_ECHOLNPGM(")");
SERIAL_ECHOPAIR("??? Max7219_Set_Row(",r);
SERIAL_ECHOPAIR(",",v);
SERIAL_ECHO(")\n");
return; return;
} }
for (uint8_t b = 0; b <= 7; b++) for (uint8_t b = 0; b <= 7; b++)
@ -199,44 +180,34 @@ void Max7219_Set_Row(const uint8_t row, const uint8_t val) {
} }
void Max7219_Set_2_Rows(const uint8_t row, const uint16_t val) { void Max7219_Set_2_Rows(const uint8_t row, const uint16_t val) {
if (row > 6 || val>65535) { if (row > 6) {
int r, v; SERIAL_ECHOPAIR("??? Max7219_Set_2_Rows(", (int)row);
r = row; SERIAL_ECHOPAIR(",", (int)val);
v = val; SERIAL_ECHOLNPGM(")");
SERIAL_ECHOPAIR("??? Max7219_Set_2_Rows(",r);
SERIAL_ECHOPAIR(",",v);
SERIAL_ECHO(")\n");
return; return;
} }
Max7219_Set_Row(row+1, (val & 0xff00) >> 8 ); Max7219_Set_Row(row + 1, (val >> 8) & 0xFF);
Max7219_Set_Row(row+0, (val & 0xff)); Max7219_Set_Row(row + 0, (val ) & 0xFF);
} }
void Max7219_Set_4_Rows(const uint8_t row, const uint32_t val) { void Max7219_Set_4_Rows(const uint8_t row, const uint32_t val) {
if (row > 4 ) { if (row > 4) {
int r; SERIAL_ECHOPAIR("??? Max7219_Set_4_Rows(", (int)row);
long v; SERIAL_ECHOPAIR(",", (long)val);
r = row; SERIAL_ECHOLNPGM(")");
v = val;
SERIAL_ECHOPAIR("??? Max7219_Set_4_Rows(",r);
SERIAL_ECHOPAIR(",",v);
SERIAL_ECHO(")\n");
return; return;
} }
Max7219_Set_Row(row+3, (val & 0xff000000) >> 24); Max7219_Set_Row(row + 3, (val >> 24) & 0xFF);
Max7219_Set_Row(row+2, (val & 0xff0000) >> 16); Max7219_Set_Row(row + 2, (val >> 16) & 0xFF);
Max7219_Set_Row(row+1, (val & 0xff00) >> 8); Max7219_Set_Row(row + 1, (val >> 8) & 0xFF);
Max7219_Set_Row(row+0, (val & 0xff)); Max7219_Set_Row(row + 0, (val ) & 0xFF);
} }
void Max7219_Set_Column(const uint8_t col, const uint8_t val) { void Max7219_Set_Column(const uint8_t col, const uint8_t val) {
if (val > 255 || col > 7) { if (col > 7) {
int v,c; SERIAL_ECHOPAIR("??? Max7219_Column(", (int)col);
v = val; SERIAL_ECHOPAIR(",", (int)val);
c = col; SERIAL_ECHOLNPGM(")");
SERIAL_ECHOPAIR("??? Max7219_Column(",c);
SERIAL_ECHOPAIR(",",v);
SERIAL_ECHO(")\n");
return; return;
} }
LEDs[col] = val; LEDs[col] = val;
@ -304,12 +275,10 @@ void Max7219_idle_tasks() {
#if MAX7219_DEBUG_STEPPER_HEAD || MAX7219_DEBUG_STEPPER_TAIL || MAX7219_DEBUG_STEPPER_QUEUE #if MAX7219_DEBUG_STEPPER_HEAD || MAX7219_DEBUG_STEPPER_TAIL || MAX7219_DEBUG_STEPPER_QUEUE
CRITICAL_SECTION_START CRITICAL_SECTION_START
#if MAX7219_DEBUG_STEPPER_HEAD || MAX7219_DEBUG_STEPPER_QUEUE #if MAX7219_DEBUG_STEPPER_HEAD || MAX7219_DEBUG_STEPPER_QUEUE
uint8_t head; const uint8_t head = planner.block_buffer_head;
head = planner.block_buffer_head;
#endif #endif
#if MAX7219_DEBUG_STEPPER_TAIL || MAX7219_DEBUG_STEPPER_QUEUE #if MAX7219_DEBUG_STEPPER_TAIL || MAX7219_DEBUG_STEPPER_QUEUE
uint8_t tail; const uint8_t tail = planner.block_buffer_tail;
tail = planner.block_buffer_tail;
#endif #endif
CRITICAL_SECTION_END CRITICAL_SECTION_END
#endif #endif
@ -323,34 +292,34 @@ void Max7219_idle_tasks() {
#endif #endif
#ifdef MAX7219_DEBUG_STEPPER_HEAD #ifdef MAX7219_DEBUG_STEPPER_HEAD
static int16_t last_head_cnt=0; static int16_t last_head_cnt = 0;
if (last_head_cnt != head) { if (last_head_cnt != head) {
if (last_head_cnt < 8) if (last_head_cnt < 8)
Max7219_LED_Off( last_head_cnt, MAX7219_DEBUG_STEPPER_HEAD); Max7219_LED_Off(last_head_cnt, MAX7219_DEBUG_STEPPER_HEAD);
else else
Max7219_LED_Off( last_head_cnt-8, MAX7219_DEBUG_STEPPER_HEAD+1); Max7219_LED_Off(last_head_cnt - 8, MAX7219_DEBUG_STEPPER_HEAD + 1);
last_head_cnt = head; last_head_cnt = head;
if (head < 8) if (head < 8)
Max7219_LED_On(head, MAX7219_DEBUG_STEPPER_HEAD); Max7219_LED_On(head, MAX7219_DEBUG_STEPPER_HEAD);
else else
Max7219_LED_On(head-8, MAX7219_DEBUG_STEPPER_HEAD+1); Max7219_LED_On(head - 8, MAX7219_DEBUG_STEPPER_HEAD + 1);
} }
#endif #endif
#ifdef MAX7219_DEBUG_STEPPER_TAIL #ifdef MAX7219_DEBUG_STEPPER_TAIL
static int16_t last_tail_cnt=0; static int16_t last_tail_cnt = 0;
if (last_tail_cnt != tail) { if (last_tail_cnt != tail) {
if (last_tail_cnt < 8) if (last_tail_cnt < 8)
Max7219_LED_Off( last_tail_cnt, MAX7219_DEBUG_STEPPER_TAIL); Max7219_LED_Off(last_tail_cnt, MAX7219_DEBUG_STEPPER_TAIL);
else else
Max7219_LED_Off( last_tail_cnt-8, MAX7219_DEBUG_STEPPER_TAIL+1); Max7219_LED_Off(last_tail_cnt - 8, MAX7219_DEBUG_STEPPER_TAIL + 1);
last_tail_cnt = tail; last_tail_cnt = tail;
if (tail < 8) if (tail < 8)
Max7219_LED_On(tail, MAX7219_DEBUG_STEPPER_TAIL); Max7219_LED_On(tail, MAX7219_DEBUG_STEPPER_TAIL);
else else
Max7219_LED_On(tail-8, MAX7219_DEBUG_STEPPER_TAIL+1); Max7219_LED_On(tail - 8, MAX7219_DEBUG_STEPPER_TAIL + 1);
} }
#endif #endif
@ -367,10 +336,10 @@ void Max7219_idle_tasks() {
en = max(current_depth, last_depth); en = max(current_depth, last_depth);
if (current_depth < last_depth) if (current_depth < last_depth)
for (uint8_t i = st; i <= en; i++) // clear the highest order LEDs for (uint8_t i = st; i <= en; i++) // clear the highest order LEDs
Max7219_LED_Off(i/2, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1)); Max7219_LED_Off(i / 2, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
else else
for (uint8_t i = st; i <= en; i++) // set the LEDs to current depth for (uint8_t i = st; i <= en; i++) // set the LEDs to current depth
Max7219_LED_On(i/2, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1)); Max7219_LED_On(i / 2, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
last_depth = current_depth; last_depth = current_depth;
} }

Loading…
Cancel
Save