Skip to content

Commit

Permalink
changed names to more appropriate meaning
Browse files Browse the repository at this point in the history
  • Loading branch information
jmatth11 committed Nov 23, 2024
1 parent 5a090dc commit daa15f2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/driver/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ void i2c_init() {
(0x0 << USICNT0)
);
// flip the ports to input mode so we can enable pullup resistors on the next line
i2c_bus &= ~_BV(i2c_sda);
i2c_bus &= ~_BV(i2c_scl);
i2c_ddr &= ~_BV(i2c_sda);
i2c_ddr &= ~_BV(i2c_scl);

// set both pins to HIGH to enable pullup.
i2c_port |= _BV(i2c_sda);
i2c_port |= _BV(i2c_scl);

// flip the ports to output mode
i2c_bus |= _BV(i2c_sda);
i2c_bus |= _BV(i2c_scl);
i2c_ddr |= _BV(i2c_sda);
i2c_ddr |= _BV(i2c_scl);
}

/**
Expand Down Expand Up @@ -147,10 +147,10 @@ unsigned char i2c_write_byte(unsigned char data) {
transfer(STATUS_CLOCK_8_BITS);

// change data pin to input
i2c_bus &= ~_BV(i2c_sda);
i2c_ddr &= ~_BV(i2c_sda);
unsigned char nack = transfer(STATUS_CLOCK_1_BIT);
// change back to output
i2c_bus |= _BV(i2c_sda);
i2c_ddr |= _BV(i2c_sda);
return nack;
}

Expand All @@ -168,10 +168,10 @@ unsigned char i2c_read_byte(bool ack) {
response = 0x00;
}
// change data pin to input
i2c_bus &= ~_BV(i2c_sda);
i2c_ddr &= ~_BV(i2c_sda);
unsigned char data = transfer(STATUS_CLOCK_8_BITS);
// change back to output
i2c_bus |= _BV(i2c_sda);
i2c_ddr |= _BV(i2c_sda);
// send n/ack
i2c_data = response;
transfer(STATUS_CLOCK_1_BIT);
Expand Down
5 changes: 3 additions & 2 deletions src/driver/i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#define T4_TWI 4 // >4.0microseconds
#endif

#ifndef i2c_bus
#define i2c_bus DDRB
#ifndef i2c_ddr
#define i2c_ddr DDRB
#endif
#ifndef i2c_port
#define i2c_port PORTB
Expand Down Expand Up @@ -51,6 +51,7 @@ void i2c_init();

/**
* Send start command.
* @return True if the start successfully initiated, False otherwise.
*/
bool i2c_start();

Expand Down

0 comments on commit daa15f2

Please sign in to comment.