Skip to content

Commit

Permalink
Use wait_us() instead of chSysPolledDelayX
Browse files Browse the repository at this point in the history
...as it is powered by busy waiting now.
  • Loading branch information
KarlK90 committed Jul 11, 2022
1 parent 5c21da2 commit 782b632
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 29 deletions.
25 changes: 13 additions & 12 deletions keyboards/planck/rev6_drop/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "hal.h"
#include "timer.h"
#include "wait.h"
#include "debug.h"
#include "matrix.h"
#include "quantum.h"

/*
* col: { B11, B10, B2, B1, A7, B0 }
Expand All @@ -38,9 +31,13 @@ __attribute__((weak)) void matrix_init_user(void) {}

__attribute__((weak)) void matrix_scan_user(void) {}

__attribute__((weak)) void matrix_init_kb(void) { matrix_init_user(); }
__attribute__((weak)) void matrix_init_kb(void) {
matrix_init_user();
}

__attribute__((weak)) void matrix_scan_kb(void) { matrix_scan_user(); }
__attribute__((weak)) void matrix_scan_kb(void) {
matrix_scan_user();
}

void matrix_init(void) {
dprintf("matrix init\n");
Expand Down Expand Up @@ -146,9 +143,13 @@ uint8_t matrix_scan(void) {
return 1;
}

bool matrix_is_on(uint8_t row, uint8_t col) { return (matrix[row] & (1 << col)); }
bool matrix_is_on(uint8_t row, uint8_t col) {
return (matrix[row] & (1 << col));
}

matrix_row_t matrix_get_row(uint8_t row) { return matrix[row]; }
matrix_row_t matrix_get_row(uint8_t row) {
return matrix[row];
}

void matrix_print(void) {
dprintf("\nr/c 01234567\n");
Expand Down
25 changes: 13 additions & 12 deletions keyboards/preonic/rev3_drop/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "hal.h"
#include "timer.h"
#include "wait.h"
#include "debug.h"
#include "matrix.h"
#include "quantum.h"

typedef uint16_t matrix_col_t;

Expand All @@ -40,9 +33,13 @@ __attribute__((weak)) void matrix_init_user(void) {}

__attribute__((weak)) void matrix_scan_user(void) {}

__attribute__((weak)) void matrix_init_kb(void) { matrix_init_user(); }
__attribute__((weak)) void matrix_init_kb(void) {
matrix_init_user();
}

__attribute__((weak)) void matrix_scan_kb(void) { matrix_scan_user(); }
__attribute__((weak)) void matrix_scan_kb(void) {
matrix_scan_user();
}

void matrix_init(void) {
dprintf("matrix init\n");
Expand Down Expand Up @@ -150,9 +147,13 @@ uint8_t matrix_scan(void) {
return 1;
}

bool matrix_is_on(uint8_t row, uint8_t col) { return (matrix[row] & (1 << col)); }
bool matrix_is_on(uint8_t row, uint8_t col) {
return (matrix[row] & (1 << col));
}

matrix_row_t matrix_get_row(uint8_t row) { return matrix[row]; }
matrix_row_t matrix_get_row(uint8_t row) {
return matrix[row];
}

void matrix_print(void) {
dprintf("\nr/c 01234567\n");
Expand Down
5 changes: 2 additions & 3 deletions platforms/chibios/bootloaders/rp2040.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ void __late_init(void) {
if (magic_location != magic_token) {
magic_location = magic_token;
// ChibiOS is not initialized at this point, so sleeping is only
// possible via busy waiting. The internal timer peripheral is running
// at this point with a precision of 1us.
chSysPolledDelayX(MS2RTC(1 * MHZ, RP2040_BOOTLOADER_DOUBLE_TAP_RESET_TIMEOUT));
// possible via busy waiting.
wait_us(RP2040_BOOTLOADER_DOUBLE_TAP_RESET_TIMEOUT * 1000U);
magic_location = 0;
return;
}
Expand Down
3 changes: 2 additions & 1 deletion platforms/chibios/drivers/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
# error "chSysPolledDelayX method not supported on this platform"
#else
# undef wait_us
# define wait_us(x) chSysPolledDelayX(US2RTC(CPU_CLOCK, x))
// Force usage of polled waiting - in case WAIT_US_TIMER is activated
# define wait_us(us) chSysPolledDelayX(US2RTC(REALTIME_COUNTER_CLOCK, us))
#endif

#ifndef SELECT_SOFT_SERIAL_SPEED
Expand Down
2 changes: 1 addition & 1 deletion platforms/chibios/drivers/vendor/RP/RP2040/serial_vendor.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static inline void enter_rx_state(void) {
}
// Wait for ~11 bits, 1 start bit + 8 data bits + 1 stop bit + 1 bit
// headroom.
chSysPolledDelayX(US2RTC(1 * MHZ, (1000000U * 11 / SERIAL_USART_SPEED)));
wait_us(1000000U * 11U / SERIAL_USART_SPEED);
// Disable tx state machine to not interfere with our tx pin manipulation
pio_sm_set_enabled(pio, tx_state_machine, false);
gpio_set_drive_strength(SERIAL_USART_TX_PIN, GPIO_DRIVE_STRENGTH_2MA);
Expand Down

0 comments on commit 782b632

Please sign in to comment.