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

@ -82,17 +82,17 @@ void matrix_scan_user(void) {
// switch, and then into the diode, then into one of the columns into the
// matrix. the reset pin can be used to reset the entire counter.
#define RESET _BV(PB0)
#define SCLK _BV(PB1)
#define SDATA _BV(PB3)
#define LED _BV(PD6)
#define HP_46010A_RESET_PIN B0
#define HP_46010A_SCLK_PIN B1
#define HP_46010A_SDATA_PIN B3
#define HP_46010A_LED_PIN D6
inline
static
void SCLK_increment(void) {
PORTB &= ~SCLK ;
gpio_write_pin_low(HP_46010A_SCLK_PIN);
_delay_us( 4 ) ; // make sure the line is stable
PORTB |= SCLK ;
gpio_write_pin_high(HP_46010A_SCLK_PIN);
_delay_us( 4 ) ;
return ;
@ -101,9 +101,9 @@ void SCLK_increment(void) {
inline
static
void Matrix_Reset(void) {
PORTB |= RESET ;
gpio_write_pin_high(HP_46010A_RESET_PIN);
_delay_us( 4 ) ; // make sure the line is stable
PORTB &= ~RESET ;
gpio_write_pin_low(HP_46010A_RESET_PIN);
return ;
}
@ -116,7 +116,7 @@ uint8_t Matrix_ReceiveByte (void) {
for ( uint8_t bit = 0; bit < MATRIX_COLS; ++bit ) {
// toggle the clock
SCLK_increment();
temp = (PINB & SDATA) << 4 ;
temp = gpio_read_pin(HP_46010A_SDATA_PIN) << 4 ;
received |= temp >> bit ;
}
@ -138,18 +138,19 @@ void Matrix_ThrowByte(void) {
void matrix_init (void) {
// debug_matrix = 1;
// PB0 (SS) and PB1 (SCLK) set to outputs
DDRB |= RESET | SCLK ;
gpio_set_pin_output(HP_46010A_RESET_PIN);
gpio_set_pin_output(HP_46010A_SCLK_PIN);
// PB2, is unused, and PB3 is our serial input
DDRB &= ~SDATA ;
gpio_set_pin_input(HP_46010A_SDATA_PIN);
// SS is reset for this board, and is active High
// SCLK is the serial clock and is active High
PORTB &= ~RESET ;
PORTB |= SCLK ;
gpio_write_pin_low(HP_46010A_RESET_PIN);
gpio_write_pin_high(HP_46010A_SCLK_PIN);
// led pin
DDRD |= LED ;
PORTD &= ~LED ;
gpio_set_pin_output(HP_46010A_LED_PIN);
gpio_write_pin_low(HP_46010A_LED_PIN);
matrix_init_kb();

View file

@ -74,8 +74,8 @@ uint8_t matrix_cols(void)
void matrix_init(void)
{
/* DDRD |= (1<<6); */
/* PORTD |= (1<<6); */
/* gpio_set_pin_output(D6); */
/* gpio_write_pin_high(D6); */
debug_enable = true;
uart_init(1200);
@ -99,7 +99,7 @@ void matrix_init(void)
/* } */
/* print(" Done\n"); */
/* PORTD &= ~(1<<6); */
/* gpio_write_pin_low(D6) */
matrix_init_kb();
return;