Move more UART-based keyboards to use timeout correctly. (#17329)

Co-authored-by: Tomasz Janeczko <tomasz.j@hey.com>
This commit is contained in:
Tomasz Janeczko 2022-06-08 22:51:41 +01:00 committed by GitHub
parent f6a7bf2a83
commit 6567b21688
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 111 additions and 31 deletions

View File

@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "matrix.h" #include "matrix.h"
#include "uart.h" #include "uart.h"
#define UART_MATRIX_RESPONSE_TIMEOUT 10000
void matrix_init_custom(void) { void matrix_init_custom(void) {
uart_init(500000); uart_init(500000);
} }
@ -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 //wait for the serial data, timeout if it's been too long
while (!uart_available()) { while (!uart_available()) {
timeout++; timeout++;
if (timeout > 10000) { if (timeout > UART_MATRIX_RESPONSE_TIMEOUT) {
break; break;
} }
} }
if (timeout < UART_MATRIX_RESPONSE_TIMEOUT) {
uart_data[i] = uart_read(); uart_data[i] = uart_read();
} else {
uart_data[i] = 0x00;
}
} }
//check for the end packet, the key state bytes use the LSBs, so 0xE0 //check for the end packet, the key state bytes use the LSBs, so 0xE0

View File

@ -48,6 +48,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define MAIN_ROWMASK 0xFFF0; #define MAIN_ROWMASK 0xFFF0;
#define LOWER_ROWMASK 0x3FC0; #define LOWER_ROWMASK 0x3FC0;
#define UART_MATRIX_RESPONSE_TIMEOUT 10000
/* matrix state(1:on, 0:off) */ /* matrix state(1:on, 0:off) */
static matrix_row_t matrix[MATRIX_ROWS]; static matrix_row_t matrix[MATRIX_ROWS];
@ -96,8 +98,6 @@ void matrix_init(void) {
uint8_t matrix_scan(void) uint8_t matrix_scan(void)
{ {
//xprintf("\r\nTRYING TO SCAN");
uint32_t timeout = 0; uint32_t timeout = 0;
//the s character requests the RF slave to send the matrix //the s character requests the RF slave to send the matrix
@ -113,12 +113,16 @@ uint8_t matrix_scan(void)
//harm to leave it in here //harm to leave it in here
while(!uart_available()){ while(!uart_available()){
timeout++; timeout++;
if (timeout > 10000){ if (timeout > UART_MATRIX_RESPONSE_TIMEOUT) {
xprintf("\r\nTime out in keyboard.");
break; break;
} }
} }
if (timeout < UART_MATRIX_RESPONSE_TIMEOUT) {
uart_data[i] = uart_read(); uart_data[i] = uart_read();
} else {
uart_data[i] = 0x00;
}
} }
//check for the end packet, the key state bytes use the LSBs, so 0xE0 //check for the end packet, the key state bytes use the LSBs, so 0xE0

View File

@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "matrix.h" #include "matrix.h"
#include "uart.h" #include "uart.h"
#define UART_MATRIX_RESPONSE_TIMEOUT 10000
void matrix_init_custom(void) { void matrix_init_custom(void) {
uart_init(1000000); uart_init(1000000);
} }
@ -41,11 +43,16 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
//harm to leave it in here //harm to leave it in here
while (!uart_available()) { while (!uart_available()) {
timeout++; timeout++;
if (timeout > 10000) { if (timeout > UART_MATRIX_RESPONSE_TIMEOUT) {
break; break;
} }
} }
if (timeout < UART_MATRIX_RESPONSE_TIMEOUT) {
uart_data[i] = uart_read(); uart_data[i] = uart_read();
} else {
uart_data[i] = 0x00;
}
} }
//check for the end packet, the key state bytes use the LSBs, so 0xE0 //check for the end packet, the key state bytes use the LSBs, so 0xE0

View File

@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "matrix.h" #include "matrix.h"
#include "uart.h" #include "uart.h"
#define UART_MATRIX_RESPONSE_TIMEOUT 10000
void matrix_init_custom(void) { void matrix_init_custom(void) {
uart_init(1000000); uart_init(1000000);
} }
@ -41,11 +43,16 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
//harm to leave it in here //harm to leave it in here
while (!uart_available()) { while (!uart_available()) {
timeout++; timeout++;
if (timeout > 10000) { if (timeout > UART_MATRIX_RESPONSE_TIMEOUT) {
break; break;
} }
} }
if (timeout < UART_MATRIX_RESPONSE_TIMEOUT) {
uart_data[i] = uart_read(); uart_data[i] = uart_read();
} else {
uart_data[i] = 0x00;
}
} }
//check for the end packet, the key state bytes use the LSBs, so 0xE0 //check for the end packet, the key state bytes use the LSBs, so 0xE0

View File

@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "matrix.h" #include "matrix.h"
#include "uart.h" #include "uart.h"
#define UART_MATRIX_RESPONSE_TIMEOUT 10000
void matrix_init_custom(void) { void matrix_init_custom(void) {
uart_init(1000000); uart_init(1000000);
} }
@ -41,11 +43,16 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
//harm to leave it in here //harm to leave it in here
while (!uart_available()) { while (!uart_available()) {
timeout++; timeout++;
if (timeout > 10000) { if (timeout > UART_MATRIX_RESPONSE_TIMEOUT) {
break; break;
} }
} }
if (timeout < UART_MATRIX_RESPONSE_TIMEOUT) {
uart_data[i] = uart_read(); uart_data[i] = uart_read();
} else {
uart_data[i] = 0x00;
}
} }
//check for the end packet, the key state bytes use the LSBs, so 0xE0 //check for the end packet, the key state bytes use the LSBs, so 0xE0

View File

@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "matrix.h" #include "matrix.h"
#include "uart.h" #include "uart.h"
#define UART_MATRIX_RESPONSE_TIMEOUT 10000
void matrix_init_custom(void) { void matrix_init_custom(void) {
uart_init(1000000); uart_init(1000000);
} }
@ -41,11 +43,16 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
//harm to leave it in here //harm to leave it in here
while (!uart_available()) { while (!uart_available()) {
timeout++; timeout++;
if (timeout > 10000) { if (timeout > UART_MATRIX_RESPONSE_TIMEOUT) {
break; break;
} }
} }
if (timeout < UART_MATRIX_RESPONSE_TIMEOUT) {
uart_data[i] = uart_read(); uart_data[i] = uart_read();
} else {
uart_data[i] = 0x00;
}
} }
//check for the end packet, the key state bytes use the LSBs, so 0xE0 //check for the end packet, the key state bytes use the LSBs, so 0xE0

View File

@ -46,6 +46,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# define ROW_SHIFTER ((uint32_t)1) # define ROW_SHIFTER ((uint32_t)1)
#endif #endif
#define UART_MATRIX_RESPONSE_TIMEOUT 10000
/* matrix state(1:on, 0:off) */ /* matrix state(1:on, 0:off) */
static matrix_row_t matrix[MATRIX_ROWS]; static matrix_row_t matrix[MATRIX_ROWS];
//extern int8_t encoderValue; //extern int8_t encoderValue;
@ -112,12 +114,16 @@ uint8_t matrix_scan(void)
// harm to leave it in here // harm to leave it in here
while(!uart_available()){ while(!uart_available()){
timeout++; timeout++;
if (timeout > 10000){ if (timeout > UART_MATRIX_RESPONSE_TIMEOUT) {
xprintf("\r\nTime out in keyboard.");
break; break;
} }
} }
if (timeout < UART_MATRIX_RESPONSE_TIMEOUT) {
uart_data[i] = uart_read(); uart_data[i] = uart_read();
} else {
uart_data[i] = 0x00;
}
} }
// Check for the end packet, it's our checksum. // Check for the end packet, it's our checksum.

View File

@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "matrix.h" #include "matrix.h"
#include "uart.h" #include "uart.h"
#define UART_MATRIX_RESPONSE_TIMEOUT 10000
void matrix_init_custom(void) { void matrix_init_custom(void) {
uart_init(1000000); uart_init(1000000);
} }
@ -34,18 +36,23 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
//trust the external keystates entirely, erase the last data //trust the external keystates entirely, erase the last data
uint8_t uart_data[11] = {0}; 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++) { for (uint8_t i = 0; i < 11; i++) {
//wait for the serial data, timeout if it's been too long //wait for the serial data, timeout if it's been too long
//this only happened in testing with a loose wire, but does no //this only happened in testing with a loose wire, but does no
//harm to leave it in here //harm to leave it in here
while (!uart_available()) { while (!uart_available()) {
timeout++; timeout++;
if (timeout > 10000) { if (timeout > UART_MATRIX_RESPONSE_TIMEOUT) {
break; break;
} }
} }
if (timeout < UART_MATRIX_RESPONSE_TIMEOUT) {
uart_data[i] = uart_read(); uart_data[i] = uart_read();
} else {
uart_data[i] = 0x00;
}
} }
//check for the end packet, the key state bytes use the LSBs, so 0xE0 //check for the end packet, the key state bytes use the LSBs, so 0xE0

View File

@ -34,7 +34,7 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
//trust the external keystates entirely, erase the last data //trust the external keystates entirely, erase the last data
uint8_t uart_data[11] = {0}; 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++) { for (uint8_t i = 0; i < 11; i++) {
//wait for the serial data, timeout if it's been too long //wait for the serial data, timeout if it's been too long
//this only happened in testing with a loose wire, but does no //this only happened in testing with a loose wire, but does no

View File

@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "matrix.h" #include "matrix.h"
#include "uart.h" #include "uart.h"
#define UART_MATRIX_RESPONSE_TIMEOUT 10000
void matrix_init_custom(void) { void matrix_init_custom(void) {
uart_init(1000000); uart_init(1000000);
} }
@ -41,11 +43,16 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
//harm to leave it in here //harm to leave it in here
while (!uart_available()) { while (!uart_available()) {
timeout++; timeout++;
if (timeout > 10000) { if (timeout > UART_MATRIX_RESPONSE_TIMEOUT) {
break; break;
} }
} }
if (timeout < UART_MATRIX_RESPONSE_TIMEOUT) {
uart_data[i] = uart_read(); uart_data[i] = uart_read();
} else {
uart_data[i] = 0x00;
}
} }
//check for the end packet, the key state bytes use the LSBs, so 0xE0 //check for the end packet, the key state bytes use the LSBs, so 0xE0

View File

@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "matrix.h" #include "matrix.h"
#include "uart.h" #include "uart.h"
#define UART_MATRIX_RESPONSE_TIMEOUT 10000
void matrix_init_custom(void) { void matrix_init_custom(void) {
uart_init(1000000); uart_init(1000000);
} }
@ -41,11 +43,16 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
//harm to leave it in here //harm to leave it in here
while (!uart_available()) { while (!uart_available()) {
timeout++; timeout++;
if (timeout > 10000) { if (timeout > UART_MATRIX_RESPONSE_TIMEOUT) {
break; break;
} }
} }
if (timeout < UART_MATRIX_RESPONSE_TIMEOUT) {
uart_data[i] = uart_read(); uart_data[i] = uart_read();
} else {
uart_data[i] = 0x00;
}
} }
//check for the end packet, the key state bytes use the LSBs, so 0xE0 //check for the end packet, the key state bytes use the LSBs, so 0xE0

View File

@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "matrix.h" #include "matrix.h"
#include "uart.h" #include "uart.h"
#define UART_MATRIX_RESPONSE_TIMEOUT 10000
void matrix_init_custom(void) { void matrix_init_custom(void) {
uart_init(1000000); uart_init(1000000);
} }
@ -41,11 +43,16 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
//harm to leave it in here //harm to leave it in here
while (!uart_available()) { while (!uart_available()) {
timeout++; timeout++;
if (timeout > 10000) { if (timeout > UART_MATRIX_RESPONSE_TIMEOUT) {
break; break;
} }
} }
if (timeout < UART_MATRIX_RESPONSE_TIMEOUT) {
uart_data[i] = uart_read(); uart_data[i] = uart_read();
} else {
uart_data[i] = 0x00;
}
} }
//check for the end packet, the key state bytes use the LSBs, so 0xE0 //check for the end packet, the key state bytes use the LSBs, so 0xE0

View File

@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "matrix.h" #include "matrix.h"
#include "uart.h" #include "uart.h"
#define UART_MATRIX_RESPONSE_TIMEOUT 10000
void matrix_init_custom(void) { void matrix_init_custom(void) {
uart_init(1000000); uart_init(1000000);
} }
@ -41,11 +43,16 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
//harm to leave it in here //harm to leave it in here
while (!uart_available()) { while (!uart_available()) {
timeout++; timeout++;
if (timeout > 10000) { if (timeout > UART_MATRIX_RESPONSE_TIMEOUT) {
break; break;
} }
} }
if (timeout < UART_MATRIX_RESPONSE_TIMEOUT) {
uart_data[i] = uart_read(); uart_data[i] = uart_read();
} else {
uart_data[i] = 0x00;
}
} }
//check for the end packet, the key state bytes use the LSBs, so 0xE0 //check for the end packet, the key state bytes use the LSBs, so 0xE0