Some GPIO manipulations in matrix.c change to atomic. (#10491)

* Changed the processing of select_xxx()/unselect_xxx() in quantum/matrix.c to be atomic.

* Changed the processing of select_xxx()/unselect_xxx() in quantum/split_common/matrix.c to be atomic.

* update matrix.c

* add ATOMIC_BLOCK_FORCEON macro to quantum/quantum_atomic_extend.h

* quantum_atomic_extend.h's contents move into quantum.h

* update ATOMIC_BLOCK_xxx for unknown platform

* ATOMIC_BLOCK macro support PROTOCOL_ARM_ATSAM

* Add Atomic Operation section in docs/internals_gpio_control.md
This commit is contained in:
Takeshi ISHII 2020-10-26 12:11:14 +09:00 committed by James Young
parent 69d8bbf1f4
commit 75a18e69f9
No known key found for this signature in database
GPG key ID: 8E1085BF6FCFBD74
4 changed files with 124 additions and 20 deletions

View file

@ -32,6 +32,19 @@ static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
extern matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values
extern matrix_row_t matrix[MATRIX_ROWS]; // debounced values
static inline void setPinOutput_writeLow(pin_t pin) {
ATOMIC_BLOCK_FORCEON {
setPinOutput(pin);
writePinLow(pin);
}
}
static inline void setPinInputHigh_atomic(pin_t pin) {
ATOMIC_BLOCK_FORCEON {
setPinInputHigh(pin);
}
}
// matrix code
#ifdef DIRECT_PINS
@ -70,22 +83,23 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
# if (DIODE_DIRECTION == COL2ROW)
static void select_row(uint8_t row) {
setPinOutput(row_pins[row]);
writePinLow(row_pins[row]);
setPinOutput_writeLow(row_pins[row]);
}
static void unselect_row(uint8_t row) { setPinInputHigh(row_pins[row]); }
static void unselect_row(uint8_t row) {
setPinInputHigh_atomic(row_pins[row]);
}
static void unselect_rows(void) {
for (uint8_t x = 0; x < MATRIX_ROWS; x++) {
setPinInputHigh(row_pins[x]);
setPinInputHigh_atomic(row_pins[x]);
}
}
static void init_pins(void) {
unselect_rows();
for (uint8_t x = 0; x < MATRIX_COLS; x++) {
setPinInputHigh(col_pins[x]);
setPinInputHigh_atomic(col_pins[x]);
}
}
@ -120,22 +134,23 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
# elif (DIODE_DIRECTION == ROW2COL)
static void select_col(uint8_t col) {
setPinOutput(col_pins[col]);
writePinLow(col_pins[col]);
setPinOutput_writeLow(col_pins[col]);
}
static void unselect_col(uint8_t col) { setPinInputHigh(col_pins[col]); }
static void unselect_col(uint8_t col) {
setPinInputHigh_atomic(col_pins[col]);
}
static void unselect_cols(void) {
for (uint8_t x = 0; x < MATRIX_COLS; x++) {
setPinInputHigh(col_pins[x]);
setPinInputHigh_atomic(col_pins[x]);
}
}
static void init_pins(void) {
unselect_cols();
for (uint8_t x = 0; x < MATRIX_ROWS; x++) {
setPinInputHigh(row_pins[x]);
setPinInputHigh_atomic(row_pins[x]);
}
}