Convert some AVR GPIO operations to macros (#23424)

This commit is contained in:
Ryan 2024-05-02 19:48:49 +10:00 committed by GitHub
parent 7220715dd1
commit 61c7c1f74c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
71 changed files with 877 additions and 840 deletions

View file

@ -25,16 +25,14 @@ bool led_update_kb(led_t led_state)
if (res) {
if (led_state.caps_lock) {
// output low
DDRB |= (1<<0);
PORTB &= ~(1<<0);
DDRD |= (1<<5);
PORTD &= ~(1<<5);
gpio_set_pin_output(B0);
gpio_write_pin_low(B0);
gpio_set_pin_output(D5);
gpio_write_pin_low(D5);
} else {
// Hi-Z
DDRB &= ~(1<<0);
PORTB &= ~(1<<0);
DDRD &= ~(1<<5);
PORTD &= ~(1<<5);
gpio_set_pin_input(B0);
gpio_set_pin_input(D5);
}
}
return false;

View file

@ -126,14 +126,18 @@ void matrix_print(void)
static void init_cols(void)
{
// Input with pull-up(DDR:0, PORT:1)
DDRF &= ~(1<<4 | 1<<5 | 1<<6 | 1<<7);
PORTF |= (1<<4 | 1<<5 | 1<<6 | 1<<7);
DDRE &= ~(1<<6);
PORTE |= (1<<6);
DDRD &= ~(1<<7);
PORTD |= (1<<7);
DDRB &= ~(1<<1 | 1<<2 | 1<<3 | 1<<4 | 1<<5 | 1<<6);
PORTB |= (1<<1 | 1<<2 | 1<<3 | 1<<4 | 1<<5 | 1<<6);
gpio_set_pin_input_high(F4);
gpio_set_pin_input_high(F5);
gpio_set_pin_input_high(F6);
gpio_set_pin_input_high(F7);
gpio_set_pin_input_high(E6);
gpio_set_pin_input_high(D7);
gpio_set_pin_input_high(B1);
gpio_set_pin_input_high(B2);
gpio_set_pin_input_high(B3);
gpio_set_pin_input_high(B4);
gpio_set_pin_input_high(B5);
gpio_set_pin_input_high(B6);
}
static matrix_row_t read_cols(void)
@ -160,10 +164,10 @@ static matrix_row_t read_cols(void)
static void unselect_rows(void)
{
// Hi-Z(DDR:0, PORT:0) to unselect
DDRD &= ~0b00010011;
PORTD &= ~0b00010011;
DDRC &= ~0b01000000;
PORTC &= ~0b01000000;
gpio_set_pin_input(C6);
gpio_set_pin_input(D0);
gpio_set_pin_input(D1);
gpio_set_pin_input(D4);
}
static void select_row(uint8_t row)
@ -171,20 +175,20 @@ static void select_row(uint8_t row)
// Output low(DDR:1, PORT:0) to select
switch (row) {
case 0:
DDRD |= (1<<1);
PORTD &= ~(1<<1);
gpio_set_pin_output(D1);
gpio_write_pin_low(D1);
break;
case 1:
DDRD |= (1<<0);
PORTD &= ~(1<<0);
gpio_set_pin_output(D0);
gpio_write_pin_low(D0);
break;
case 2:
DDRD |= (1<<4);
PORTD &= ~(1<<4);
gpio_set_pin_output(D4);
gpio_write_pin_low(D4);
break;
case 3:
DDRC |= (1<<6);
PORTC &= ~(1<<6);
gpio_set_pin_output(C6);
gpio_write_pin_low(C6);
break;
}
}