Skip to content

Commit

Permalink
Move more UART-based keyboards to use timeout correctly. (qmk#17329)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomasz Janeczko <[email protected]>
  • Loading branch information
2 people authored and zykrah committed Jul 2, 2022
1 parent f968bab commit 2776022
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 31 deletions.
11 changes: 9 additions & 2 deletions keyboards/centromere/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "matrix.h"
#include "uart.h"

#define UART_MATRIX_RESPONSE_TIMEOUT 10000

void matrix_init_custom(void) {
uart_init(500000);
}
Expand All @@ -39,11 +41,16 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
//wait for the serial data, timeout if it's been too long
while (!uart_available()) {
timeout++;
if (timeout > 10000) {
if (timeout > UART_MATRIX_RESPONSE_TIMEOUT) {
break;
}
}
uart_data[i] = uart_read();

if (timeout < UART_MATRIX_RESPONSE_TIMEOUT) {
uart_data[i] = uart_read();
} else {
uart_data[i] = 0x00;
}
}

//check for the end packet, the key state bytes use the LSBs, so 0xE0
Expand Down
16 changes: 10 additions & 6 deletions keyboards/dichotomy/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define MAIN_ROWMASK 0xFFF0;
#define LOWER_ROWMASK 0x3FC0;

#define UART_MATRIX_RESPONSE_TIMEOUT 10000

/* matrix state(1:on, 0:off) */
static matrix_row_t matrix[MATRIX_ROWS];

Expand Down Expand Up @@ -96,8 +98,6 @@ void matrix_init(void) {

uint8_t matrix_scan(void)
{
//xprintf("\r\nTRYING TO SCAN");

uint32_t timeout = 0;

//the s character requests the RF slave to send the matrix
Expand All @@ -113,18 +113,22 @@ uint8_t matrix_scan(void)
//harm to leave it in here
while(!uart_available()){
timeout++;
if (timeout > 10000){
xprintf("\r\nTime out in keyboard.");
if (timeout > UART_MATRIX_RESPONSE_TIMEOUT) {
break;
}
}
uart_data[i] = uart_read();

if (timeout < UART_MATRIX_RESPONSE_TIMEOUT) {
uart_data[i] = uart_read();
} else {
uart_data[i] = 0x00;
}
}

//check for the end packet, the key state bytes use the LSBs, so 0xE0
//will only show up here if the correct bytes were recieved
uint8_t checksum = 0x00;
for (uint8_t z=0; z<10; z++){
for (uint8_t z = 0; z < 10; z++){
checksum = checksum^uart_data[z];
}
checksum = checksum ^ (uart_data[10] & 0xF0);
Expand Down
11 changes: 9 additions & 2 deletions keyboards/glenpickle/chimera_ergo/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "matrix.h"
#include "uart.h"

#define UART_MATRIX_RESPONSE_TIMEOUT 10000

void matrix_init_custom(void) {
uart_init(1000000);
}
Expand All @@ -41,11 +43,16 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
//harm to leave it in here
while (!uart_available()) {
timeout++;
if (timeout > 10000) {
if (timeout > UART_MATRIX_RESPONSE_TIMEOUT) {
break;
}
}
uart_data[i] = uart_read();

if (timeout < UART_MATRIX_RESPONSE_TIMEOUT) {
uart_data[i] = uart_read();
} else {
uart_data[i] = 0x00;
}
}

//check for the end packet, the key state bytes use the LSBs, so 0xE0
Expand Down
11 changes: 9 additions & 2 deletions keyboards/glenpickle/chimera_ls/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "matrix.h"
#include "uart.h"

#define UART_MATRIX_RESPONSE_TIMEOUT 10000

void matrix_init_custom(void) {
uart_init(1000000);
}
Expand All @@ -41,11 +43,16 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
//harm to leave it in here
while (!uart_available()) {
timeout++;
if (timeout > 10000) {
if (timeout > UART_MATRIX_RESPONSE_TIMEOUT) {
break;
}
}
uart_data[i] = uart_read();

if (timeout < UART_MATRIX_RESPONSE_TIMEOUT) {
uart_data[i] = uart_read();
} else {
uart_data[i] = 0x00;
}
}

//check for the end packet, the key state bytes use the LSBs, so 0xE0
Expand Down
11 changes: 9 additions & 2 deletions keyboards/glenpickle/chimera_ortho/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "matrix.h"
#include "uart.h"

#define UART_MATRIX_RESPONSE_TIMEOUT 10000

void matrix_init_custom(void) {
uart_init(1000000);
}
Expand All @@ -41,11 +43,16 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
//harm to leave it in here
while (!uart_available()) {
timeout++;
if (timeout > 10000) {
if (timeout > UART_MATRIX_RESPONSE_TIMEOUT) {
break;
}
}
uart_data[i] = uart_read();

if (timeout < UART_MATRIX_RESPONSE_TIMEOUT) {
uart_data[i] = uart_read();
} else {
uart_data[i] = 0x00;
}
}

//check for the end packet, the key state bytes use the LSBs, so 0xE0
Expand Down
11 changes: 9 additions & 2 deletions keyboards/glenpickle/chimera_ortho_plus/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "matrix.h"
#include "uart.h"

#define UART_MATRIX_RESPONSE_TIMEOUT 10000

void matrix_init_custom(void) {
uart_init(1000000);
}
Expand All @@ -41,11 +43,16 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
//harm to leave it in here
while (!uart_available()) {
timeout++;
if (timeout > 10000) {
if (timeout > UART_MATRIX_RESPONSE_TIMEOUT) {
break;
}
}
uart_data[i] = uart_read();

if (timeout < UART_MATRIX_RESPONSE_TIMEOUT) {
uart_data[i] = uart_read();
} else {
uart_data[i] = 0x00;
}
}

//check for the end packet, the key state bytes use the LSBs, so 0xE0
Expand Down
12 changes: 9 additions & 3 deletions keyboards/keyhive/honeycomb/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# define ROW_SHIFTER ((uint32_t)1)
#endif

#define UART_MATRIX_RESPONSE_TIMEOUT 10000

/* matrix state(1:on, 0:off) */
static matrix_row_t matrix[MATRIX_ROWS];
//extern int8_t encoderValue;
Expand Down Expand Up @@ -112,12 +114,16 @@ uint8_t matrix_scan(void)
// harm to leave it in here
while(!uart_available()){
timeout++;
if (timeout > 10000){
xprintf("\r\nTime out in keyboard.");
if (timeout > UART_MATRIX_RESPONSE_TIMEOUT) {
break;
}
}
uart_data[i] = uart_read();

if (timeout < UART_MATRIX_RESPONSE_TIMEOUT) {
uart_data[i] = uart_read();
} else {
uart_data[i] = 0x00;
}
}

// Check for the end packet, it's our checksum.
Expand Down
13 changes: 10 additions & 3 deletions keyboards/mitosis/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "matrix.h"
#include "uart.h"

#define UART_MATRIX_RESPONSE_TIMEOUT 10000

void matrix_init_custom(void) {
uart_init(1000000);
}
Expand All @@ -34,18 +36,23 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
//trust the external keystates entirely, erase the last data
uint8_t uart_data[11] = {0};

//there are 10 bytes corresponding to 10 columns, and an end byte
//there are 10 bytes corresponding to 10 columns, and then an end byte
for (uint8_t i = 0; i < 11; i++) {
//wait for the serial data, timeout if it's been too long
//this only happened in testing with a loose wire, but does no
//harm to leave it in here
while (!uart_available()) {
timeout++;
if (timeout > 10000) {
if (timeout > UART_MATRIX_RESPONSE_TIMEOUT) {
break;
}
}
uart_data[i] = uart_read();

if (timeout < UART_MATRIX_RESPONSE_TIMEOUT) {
uart_data[i] = uart_read();
} else {
uart_data[i] = 0x00;
}
}

//check for the end packet, the key state bytes use the LSBs, so 0xE0
Expand Down
2 changes: 1 addition & 1 deletion keyboards/redox_w/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
//trust the external keystates entirely, erase the last data
uint8_t uart_data[11] = {0};

//there are 14 bytes corresponding to 14 columns, and an end byte
//there are 10 bytes corresponding to 10 columns, and then an end byte
for (uint8_t i = 0; i < 11; i++) {
//wait for the serial data, timeout if it's been too long
//this only happened in testing with a loose wire, but does no
Expand Down
11 changes: 9 additions & 2 deletions keyboards/satt/comet46/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "matrix.h"
#include "uart.h"

#define UART_MATRIX_RESPONSE_TIMEOUT 10000

void matrix_init_custom(void) {
uart_init(1000000);
}
Expand All @@ -41,11 +43,16 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
//harm to leave it in here
while (!uart_available()) {
timeout++;
if (timeout > 10000) {
if (timeout > UART_MATRIX_RESPONSE_TIMEOUT) {
break;
}
}
uart_data[i] = uart_read();

if (timeout < UART_MATRIX_RESPONSE_TIMEOUT) {
uart_data[i] = uart_read();
} else {
uart_data[i] = 0x00;
}
}

//check for the end packet, the key state bytes use the LSBs, so 0xE0
Expand Down
11 changes: 9 additions & 2 deletions keyboards/sirius/uni660/rev1/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "matrix.h"
#include "uart.h"

#define UART_MATRIX_RESPONSE_TIMEOUT 10000

void matrix_init_custom(void) {
uart_init(1000000);
}
Expand All @@ -41,11 +43,16 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
//harm to leave it in here
while (!uart_available()) {
timeout++;
if (timeout > 10000) {
if (timeout > UART_MATRIX_RESPONSE_TIMEOUT) {
break;
}
}
uart_data[i] = uart_read();

if (timeout < UART_MATRIX_RESPONSE_TIMEOUT) {
uart_data[i] = uart_read();
} else {
uart_data[i] = 0x00;
}
}

//check for the end packet, the key state bytes use the LSBs, so 0xE0
Expand Down
11 changes: 9 additions & 2 deletions keyboards/sirius/uni660/rev2/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "matrix.h"
#include "uart.h"

#define UART_MATRIX_RESPONSE_TIMEOUT 10000

void matrix_init_custom(void) {
uart_init(1000000);
}
Expand All @@ -41,11 +43,16 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
//harm to leave it in here
while (!uart_available()) {
timeout++;
if (timeout > 10000) {
if (timeout > UART_MATRIX_RESPONSE_TIMEOUT) {
break;
}
}
uart_data[i] = uart_read();

if (timeout < UART_MATRIX_RESPONSE_TIMEOUT) {
uart_data[i] = uart_read();
} else {
uart_data[i] = 0x00;
}
}

//check for the end packet, the key state bytes use the LSBs, so 0xE0
Expand Down
11 changes: 9 additions & 2 deletions keyboards/telophase/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "matrix.h"
#include "uart.h"

#define UART_MATRIX_RESPONSE_TIMEOUT 10000

void matrix_init_custom(void) {
uart_init(1000000);
}
Expand All @@ -41,11 +43,16 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
//harm to leave it in here
while (!uart_available()) {
timeout++;
if (timeout > 10000) {
if (timeout > UART_MATRIX_RESPONSE_TIMEOUT) {
break;
}
}
uart_data[i] = uart_read();

if (timeout < UART_MATRIX_RESPONSE_TIMEOUT) {
uart_data[i] = uart_read();
} else {
uart_data[i] = 0x00;
}
}

//check for the end packet, the key state bytes use the LSBs, so 0xE0
Expand Down

0 comments on commit 2776022

Please sign in to comment.