aboutsummaryrefslogtreecommitdiff
path: root/drivers/avr/i2c_slave.c
diff options
context:
space:
mode:
authorskullY <skullydazed@gmail.com>2019-08-30 11:19:03 -0700
committerskullydazed <skullydazed@users.noreply.github.com>2019-08-30 15:01:52 -0700
commitb624f32f944acdc59dcb130674c09090c5c404cb (patch)
treebc13adbba137d122d9a2c2fb2fafcbb08ac10e25 /drivers/avr/i2c_slave.c
parent61af76a10d00aba185b8338604171de490a13e3b (diff)
downloadqmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.tar.gz
qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.zip
clang-format changes
Diffstat (limited to 'drivers/avr/i2c_slave.c')
-rw-r--r--[-rwxr-xr-x]drivers/avr/i2c_slave.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/drivers/avr/i2c_slave.c b/drivers/avr/i2c_slave.c
index 4958a0f8e..3fb684f70 100755..100644
--- a/drivers/avr/i2c_slave.c
+++ b/drivers/avr/i2c_slave.c
@@ -27,24 +27,24 @@
27volatile uint8_t i2c_slave_reg[I2C_SLAVE_REG_COUNT]; 27volatile uint8_t i2c_slave_reg[I2C_SLAVE_REG_COUNT];
28 28
29static volatile uint8_t buffer_address; 29static volatile uint8_t buffer_address;
30static volatile bool slave_has_register_set = false; 30static volatile bool slave_has_register_set = false;
31 31
32void i2c_slave_init(uint8_t address){ 32void i2c_slave_init(uint8_t address) {
33 // load address into TWI address register 33 // load address into TWI address register
34 TWAR = address; 34 TWAR = address;
35 // set the TWCR to enable address matching and enable TWI, clear TWINT, enable TWI interrupt 35 // set the TWCR to enable address matching and enable TWI, clear TWINT, enable TWI interrupt
36 TWCR = (1 << TWIE) | (1 << TWEA) | (1 << TWINT) | (1 << TWEN); 36 TWCR = (1 << TWIE) | (1 << TWEA) | (1 << TWINT) | (1 << TWEN);
37} 37}
38 38
39void i2c_slave_stop(void){ 39void i2c_slave_stop(void) {
40 // clear acknowledge and enable bits 40 // clear acknowledge and enable bits
41 TWCR &= ~((1 << TWEA) | (1 << TWEN)); 41 TWCR &= ~((1 << TWEA) | (1 << TWEN));
42} 42}
43 43
44ISR(TWI_vect){ 44ISR(TWI_vect) {
45 uint8_t ack = 1; 45 uint8_t ack = 1;
46 46
47 switch(TW_STATUS){ 47 switch (TW_STATUS) {
48 case TW_SR_SLA_ACK: 48 case TW_SR_SLA_ACK:
49 // The device is now a slave receiver 49 // The device is now a slave receiver
50 slave_has_register_set = false; 50 slave_has_register_set = false;
@@ -53,14 +53,14 @@ ISR(TWI_vect){
53 case TW_SR_DATA_ACK: 53 case TW_SR_DATA_ACK:
54 // This device is a slave receiver and has received data 54 // This device is a slave receiver and has received data
55 // First byte is the location then the bytes will be writen in buffer with auto-incriment 55 // First byte is the location then the bytes will be writen in buffer with auto-incriment
56 if(!slave_has_register_set){ 56 if (!slave_has_register_set) {
57 buffer_address = TWDR; 57 buffer_address = TWDR;
58 58
59 if (buffer_address >= I2C_SLAVE_REG_COUNT) { // address out of bounds dont ack 59 if (buffer_address >= I2C_SLAVE_REG_COUNT) { // address out of bounds dont ack
60 ack = 0; 60 ack = 0;
61 buffer_address = 0; 61 buffer_address = 0;
62 } 62 }
63 slave_has_register_set = true; // address has been receaved now fill in buffer 63 slave_has_register_set = true; // address has been receaved now fill in buffer
64 } else { 64 } else {
65 i2c_slave_reg[buffer_address] = TWDR; 65 i2c_slave_reg[buffer_address] = TWDR;
66 buffer_address++; 66 buffer_address++;