Skip to content

Commit

Permalink
Convert some AVR GPIO operations to macros (qmk#23424)
Browse files Browse the repository at this point in the history
  • Loading branch information
fauxpark authored May 2, 2024
1 parent 7220715 commit 61c7c1f
Show file tree
Hide file tree
Showing 71 changed files with 885 additions and 848 deletions.
14 changes: 6 additions & 8 deletions keyboards/40percentclub/ut47/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
44 changes: 24 additions & 20 deletions keyboards/40percentclub/ut47/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -160,31 +164,31 @@ 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)
{
// 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;
}
}
63 changes: 32 additions & 31 deletions keyboards/amjkeyboard/amj96/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ void matrix_init(void)
#endif

// 85 REST
DDRD |= _BV(PD7);
PORTD |= _BV(PD7);
gpio_set_pin_output(D7);
gpio_write_pin_high(D7);

// initialize row and col
init_rows();
Expand Down Expand Up @@ -143,36 +143,35 @@ static void init_cols(void)
DDRD &= 0b00011100;
PORTD |= 0b11100011;

DDRB &= ~(_BV(PB6) | _BV(PB7)| _BV(PB0));
PORTB |= (_BV(PB6) | _BV(PB7)| _BV(PB0));
gpio_set_pin_input_high(B0);
gpio_set_pin_input_high(B6);
gpio_set_pin_input_high(B7);

DDRE &= ~_BV(PE6);
PORTE |= _BV(PE6);
gpio_set_pin_input_high(E6);

DDRC &= ~_BV(PC7);
PORTC |= _BV(PC7);
gpio_set_pin_input_high(C7);

}

static matrix_row_t read_cols(void)
{

return (PINF&_BV(PF7) ? 0 : (1<<0)) |
(PINF&_BV(PF6) ? 0 : (1<<1)) |
(PINF&_BV(PF5) ? 0 : (1<<2)) |
(PINF&_BV(PF4) ? 0 : (1<<3)) |
(PINF&_BV(PF1) ? 0 : (1<<4)) |
(PINF&_BV(PF0) ? 0 : (1<<5)) |
(PINE&_BV(PE6) ? 0 : (1<<6)) |
(PIND&_BV(PD7) ? 0 : (1<<7)) |
(PIND&_BV(PD6) ? 0 : (1<<8)) |
(PIND&_BV(PD5) ? 0 : (1<<9)) |
(PIND&_BV(PD1) ? 0 : (1<<10)) |
(PIND&_BV(PD0) ? 0 : (1<<11)) |
(PINB&_BV(PB7) ? 0 : (1<<12)) |
(PINB&_BV(PB6) ? 0 : (1<<13)) |
(PINB&_BV(PB0) ? 0 : (1<<14)) |
(PINC&_BV(PC7) ? 0 : (1<<15));
return (gpio_read_pin(F7) ? 0 : (1<<0)) |
(gpio_read_pin(F6) ? 0 : (1<<1)) |
(gpio_read_pin(F5) ? 0 : (1<<2)) |
(gpio_read_pin(F4) ? 0 : (1<<3)) |
(gpio_read_pin(F1) ? 0 : (1<<4)) |
(gpio_read_pin(F0) ? 0 : (1<<5)) |
(gpio_read_pin(E6) ? 0 : (1<<6)) |
(gpio_read_pin(D7) ? 0 : (1<<7)) |
(gpio_read_pin(D6) ? 0 : (1<<8)) |
(gpio_read_pin(D5) ? 0 : (1<<9)) |
(gpio_read_pin(D1) ? 0 : (1<<10)) |
(gpio_read_pin(D0) ? 0 : (1<<11)) |
(gpio_read_pin(B7) ? 0 : (1<<12)) |
(gpio_read_pin(B6) ? 0 : (1<<13)) |
(gpio_read_pin(B0) ? 0 : (1<<14)) |
(gpio_read_pin(C7) ? 0 : (1<<15));
}

/* Row pin configuration
Expand All @@ -184,21 +183,23 @@ static matrix_row_t read_cols(void)

static void init_rows(void)
{
DDRB |= (1<<PB1 | 1<<PB2 | 1<<PB3);
gpio_set_pin_input(B1);
gpio_set_pin_input(B2);
gpio_set_pin_input(B3);
}

static void unselect_rows(void)
{
// Hi-Z(DDR:0, PORT:0) to unselect
PORTB |= (1<<PB1);
PORTB |= (1<<PB2);
PORTB |= (1<<PB3);
gpio_write_pin_high(B1);
gpio_write_pin_high(B2);
gpio_write_pin_high(B3);
}

static void select_row(uint8_t row)
{
// Output low(DDR:1, PORT:0) to select
(row & (1<<0)) ? (PORTB |= (1<<PB3)) : (PORTB &= ~(1<<PB3));
(row & (1<<1)) ? (PORTB |= (1<<PB2)) : (PORTB &= ~(1<<PB2));
(row & (1<<2)) ? (PORTB |= (1<<PB1)) : (PORTB &= ~(1<<PB1));
gpio_write_pin(B3, row & (1<<0));
gpio_write_pin(B2, row & (1<<1));
gpio_write_pin(B1, row & (1<<2));
}
10 changes: 4 additions & 6 deletions keyboards/bajjak/bajjak.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,13 @@ void matrix_init_kb(void) {
TCCR1B = 0b00001001; // set and configure fast PWM

// (tied to Vcc for hardware convenience)
DDRB &= ~(1<<4); // set B(4) as input
PORTB &= ~(1<<4); // set B(4) internal pull-up disabled
gpio_set_pin_input(B4); // set B(4) as input, internal pull-up disabled

// unused pins - D4, D5, E6
// set as input with internal pull-up enabled
DDRD &= ~(1<<5 | 1<<4);
DDRE &= ~(1<<6);
PORTD |= (1<<5 | 1<<4);
PORTE |= (1<<6);
gpio_set_pin_input_high(D4);
gpio_set_pin_input_high(D5);
gpio_set_pin_input_high(E6);

keyboard_config.raw = eeconfig_read_kb();
bajjak_led_all_set((uint8_t)keyboard_config.led_level * 255 / 4 );
Expand Down
61 changes: 49 additions & 12 deletions keyboards/bpiphany/sixshooter/sixshooter.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,56 @@

#include "quantum.h"

inline void sixshooter_led_0_on(void) { DDRB |= (1<<6); PORTB |= (1<<6); }
inline void sixshooter_led_1_on(void) { DDRC |= (1<<7); PORTC |= (1<<7); }
inline void sixshooter_led_2_on(void) { DDRD |= (1<<0); PORTD |= (1<<0); }
inline void sixshooter_led_3_on(void) { DDRB |= (1<<5); PORTB |= (1<<5); }
inline void sixshooter_led_4_on(void) { DDRD |= (1<<7); PORTD |= (1<<7); }
inline void sixshooter_led_5_on(void) { DDRB |= (1<<7); PORTB |= (1<<7); }
#define SIXSHOOTER_LED_0_PIN B6
#define SIXSHOOTER_LED_1_PIN C7
#define SIXSHOOTER_LED_2_PIN D0
#define SIXSHOOTER_LED_3_PIN B5
#define SIXSHOOTER_LED_4_PIN D7
#define SIXSHOOTER_LED_5_PIN B7

inline void sixshooter_led_0_off(void) { DDRB &= ~(1<<6); PORTB &= ~(1<<6); }
inline void sixshooter_led_1_off(void) { DDRC &= ~(1<<7); PORTC &= ~(1<<7); }
inline void sixshooter_led_2_off(void) { DDRD &= ~(1<<0); PORTD &= ~(1<<0); }
inline void sixshooter_led_3_off(void) { DDRB &= ~(1<<5); PORTB &= ~(1<<5); }
inline void sixshooter_led_4_off(void) { DDRD &= ~(1<<7); PORTD &= ~(1<<7); }
inline void sixshooter_led_5_off(void) { DDRB &= ~(1<<7); PORTB &= ~(1<<7); }
inline void sixshooter_led_0_on(void) {
gpio_set_pin_output(SIXSHOOTER_LED_0_PIN);
gpio_write_pin_high(SIXSHOOTER_LED_0_PIN);
}
inline void sixshooter_led_1_on(void) {
gpio_set_pin_output(SIXSHOOTER_LED_1_PIN);
gpio_write_pin_high(SIXSHOOTER_LED_1_PIN);
}
inline void sixshooter_led_2_on(void) {
gpio_set_pin_output(SIXSHOOTER_LED_2_PIN);
gpio_write_pin_high(SIXSHOOTER_LED_2_PIN);
}
inline void sixshooter_led_3_on(void) {
gpio_set_pin_output(SIXSHOOTER_LED_3_PIN);
gpio_write_pin_high(SIXSHOOTER_LED_3_PIN);
}
inline void sixshooter_led_4_on(void) {
gpio_set_pin_output(SIXSHOOTER_LED_4_PIN);
gpio_write_pin_high(SIXSHOOTER_LED_4_PIN);
}
inline void sixshooter_led_5_on(void) {
gpio_set_pin_output(SIXSHOOTER_LED_5_PIN);
gpio_write_pin_high(SIXSHOOTER_LED_5_PIN);
}

inline void sixshooter_led_0_off(void) {
gpio_set_pin_input(SIXSHOOTER_LED_0_PIN);
}
inline void sixshooter_led_1_off(void) {
gpio_set_pin_input(SIXSHOOTER_LED_1_PIN);
}
inline void sixshooter_led_2_off(void) {
gpio_set_pin_input(SIXSHOOTER_LED_2_PIN);
}
inline void sixshooter_led_3_off(void) {
gpio_set_pin_input(SIXSHOOTER_LED_3_PIN);
}
inline void sixshooter_led_4_off(void) {
gpio_set_pin_input(SIXSHOOTER_LED_4_PIN);
}
inline void sixshooter_led_5_off(void) {
gpio_set_pin_input(SIXSHOOTER_LED_5_PIN);
}

inline void sixshooter_led_all_on(void) {
sixshooter_led_0_on();
Expand Down
4 changes: 2 additions & 2 deletions keyboards/ckeys/obelus/obelus.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ void matrix_init_kb(void) {
// put your keyboard start-up code here
// runs once when the firmware starts up
// Turn status LED on
DDRD |= (1<<6);
PORTD |= (1<<6);
gpio_set_pin_output(D6);
gpio_write_pin_high(D6);

matrix_init_user();
}
24 changes: 12 additions & 12 deletions keyboards/clueboard/66/rev2/rev2.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
void backlight_init_ports(void) {
print("init_backlight_pin()\n");
// Set our LED pins as output
DDRD |= (1<<6); // Esc
DDRB |= (1<<7); // Page Up
DDRD |= (1<<4); // Arrows
gpio_set_pin_output(D6); // Esc
gpio_set_pin_output(B7); // Page Up
gpio_set_pin_output(D4); // Arrows

// Set our LED pins low
PORTD &= ~(1<<6); // Esc
PORTB &= ~(1<<7); // Page Up
PORTD &= ~(1<<4); // Arrows
gpio_write_pin_low(D6); // Esc
gpio_write_pin_low(B7); // Page Up
gpio_write_pin_low(D4); // Arrows
}

void backlight_set(uint8_t level) {
if ( level == 0 ) {
// Turn off light
PORTD |= (1<<6); // Esc
PORTB |= (1<<7); // Page Up
PORTD |= (1<<4); // Arrows
gpio_write_pin_high(D6); // Esc
gpio_write_pin_high(B7); // Page Up
gpio_write_pin_high(D4); // Arrows
} else {
// Turn on light
PORTD &= ~(1<<6); // Esc
PORTB &= ~(1<<7); // Page Up
PORTD &= ~(1<<4); // Arrows
gpio_write_pin_low(D6); // Esc
gpio_write_pin_low(B7); // Page Up
gpio_write_pin_low(D4); // Arrows
}
}
24 changes: 12 additions & 12 deletions keyboards/clueboard/66/rev3/rev3.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
void backlight_init_ports(void) {
print("init_backlight_pin()\n");
// Set our LED pins as output
DDRD |= (1<<6); // Esc
DDRB |= (1<<7); // Page Up
DDRD |= (1<<4); // Arrows
gpio_set_pin_output(D6); // Esc
gpio_set_pin_output(B7); // Page Up
gpio_set_pin_output(D4); // Arrows

// Set our LED pins low
PORTD &= ~(1<<6); // Esc
PORTB &= ~(1<<7); // Page Up
PORTD &= ~(1<<4); // Arrows
gpio_write_pin_low(D6); // Esc
gpio_write_pin_low(B7); // Page Up
gpio_write_pin_low(D4); // Arrows
}

void backlight_set(uint8_t level) {
if ( level == 0 ) {
// Turn off light
PORTD |= (1<<6); // Esc
PORTB |= (1<<7); // Page Up
PORTD |= (1<<4); // Arrows
gpio_write_pin_high(D6); // Esc
gpio_write_pin_high(B7); // Page Up
gpio_write_pin_high(D4); // Arrows
} else {
// Turn on light
PORTD &= ~(1<<6); // Esc
PORTB &= ~(1<<7); // Page Up
PORTD &= ~(1<<4); // Arrows
gpio_write_pin_low(D6); // Esc
gpio_write_pin_low(B7); // Page Up
gpio_write_pin_low(D4); // Arrows
}
}
Loading

0 comments on commit 61c7c1f

Please sign in to comment.