diff --git a/scripts/layouts.sh b/scripts/layouts.sh index 169a58b..b702947 100755 --- a/scripts/layouts.sh +++ b/scripts/layouts.sh @@ -18,8 +18,8 @@ grep '^#define \(K_\|KT_FN\)' "$header" \ | cut -d ' ' -f2 \ | while read keycode do - name="$(echo "$keycode" | cut -d '_' -f2-)" - echo "printf(\"${name},0x%04X\\n\", $keycode);" >> "$source" + name="$(echo "$keycode" | cut -d '_' -f2-)" + echo "printf(\"${name},0x%04X\\n\", $keycode);" >> "$source" done echo "return 0;" >> "$source" echo "}" >> "$source" @@ -29,37 +29,37 @@ gcc -I. "$source" -o "$binary" cd src/board for board in */* do - file="$board/include/board/keymap.h" - if [ ! -e "$file" ] - then - continue - fi - echo "# $board" - mkdir -p "$D/$board" - cp "$D/keymap.csv" "$D/$board" - row=0 - rg \ - --multiline \ - --multiline-dotall \ - --regexp '#define LAYOUT\(.*\) \{.*\}' \ - "$file" \ - | grep --only-matching '\{.*\}' \ - | sed 's/^{ //' \ - | sed 's/ }$//' \ - | sed 's/, / /g' \ - | while read line - do - col=0 - for word in $line - do - if [ "$word" != "___" ] - then - echo "$word,$row,$col" - fi - col=$(expr $col + 1) - done - row=$(expr $row + 1) - done \ - | sort -n \ - | tee "$D/${board}/layout.csv" + file="$board/include/board/keymap.h" + if [ ! -e "$file" ] + then + continue + fi + echo "# $board" + mkdir -p "$D/$board" + cp "$D/keymap.csv" "$D/$board" + row=0 + rg \ + --multiline \ + --multiline-dotall \ + --regexp '#define LAYOUT\(.*\) \{.*\}' \ + "$file" \ + | grep --only-matching '\{.*\}' \ + | sed 's/^{ //' \ + | sed 's/ }$//' \ + | sed 's/, / /g' \ + | while read line + do + col=0 + for word in $line + do + if [ "$word" != "___" ] + then + echo "$word,$row,$col" + fi + col=$(expr $col + 1) + done + row=$(expr $row + 1) + done \ + | sort -n \ + | tee "$D/${board}/layout.csv" done diff --git a/src/arch/8051/include/arch/delay.h b/src/arch/8051/include/arch/delay.h index 0d44408..bfd70fd 100644 --- a/src/arch/8051/include/arch/delay.h +++ b/src/arch/8051/include/arch/delay.h @@ -16,7 +16,7 @@ void delay_ticks(uint16_t ticks); // Warning: this will round to the nearest tick #define delay_ns(X) \ delay_ticks((uint16_t)((((uint32_t)(X)) * 69UL + 89999UL) / 90000UL)); - + void delay_ms(int ms); #endif // _ARCH_DELAY_H diff --git a/src/arch/avr/i2c.c b/src/arch/avr/i2c.c index 668721c..2cb1161 100644 --- a/src/arch/avr/i2c.c +++ b/src/arch/avr/i2c.c @@ -11,77 +11,77 @@ #define TIMEOUT (F_CPU/1000) int i2c_start(struct I2C * i2c, uint8_t addr, bool read) { - uint32_t count; + uint32_t count; - // reset TWI control register - TWCR = 0; - // transmit START condition - TWCR = BIT(TWINT) | BIT(TWSTA) | BIT(TWEN); - // wait for end of transmission - count = TIMEOUT; - while(!(TWCR & BIT(TWINT)) && count > 0) count -= 1; - if (count == 0) return -1; + // reset TWI control register + TWCR = 0; + // transmit START condition + TWCR = BIT(TWINT) | BIT(TWSTA) | BIT(TWEN); + // wait for end of transmission + count = TIMEOUT; + while(!(TWCR & BIT(TWINT)) && count > 0) count -= 1; + if (count == 0) return -1; - // check if the start condition was successfully transmitted - if((TWSR & 0xF8) != TW_START) return -1; + // check if the start condition was successfully transmitted + if((TWSR & 0xF8) != TW_START) return -1; - // load slave addr into data register - TWDR = ((addr << 1) | read); - // start transmission of addr - TWCR = BIT(TWINT) | BIT(TWEN); - // wait for end of transmission - count = TIMEOUT; - while(!(TWCR & BIT(TWINT)) && count > 0) count -= 1; - if (count == 0) return -1; + // load slave addr into data register + TWDR = ((addr << 1) | read); + // start transmission of addr + TWCR = BIT(TWINT) | BIT(TWEN); + // wait for end of transmission + count = TIMEOUT; + while(!(TWCR & BIT(TWINT)) && count > 0) count -= 1; + if (count == 0) return -1; - // check if the device has acknowledged the READ / WRITE mode - uint8_t twst = TW_STATUS & 0xF8; - if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) return -1; + // check if the device has acknowledged the READ / WRITE mode + uint8_t twst = TW_STATUS & 0xF8; + if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) return -1; - return 0; + return 0; } void i2c_stop(struct I2C * i2c) { - // transmit STOP condition - TWCR = BIT(TWINT) | BIT(TWEN) | BIT(TWSTO); + // transmit STOP condition + TWCR = BIT(TWINT) | BIT(TWEN) | BIT(TWSTO); } int i2c_write(struct I2C * i2c, uint8_t * data, int length) { - int i; - for (i = 0; i < length; i++) { - // load data into data register - TWDR = data[i]; - // start transmission of data - TWCR = BIT(TWINT) | BIT(TWEN); - // wait for end of transmission - uint32_t count = TIMEOUT; - while(!(TWCR & BIT(TWINT)) && count > 0) count -= 1; - // timed out - if (count == 0) return -1; - // failed to receive ack - if((TWSR & 0xF8) != TW_MT_DATA_ACK) return -1; - } + int i; + for (i = 0; i < length; i++) { + // load data into data register + TWDR = data[i]; + // start transmission of data + TWCR = BIT(TWINT) | BIT(TWEN); + // wait for end of transmission + uint32_t count = TIMEOUT; + while(!(TWCR & BIT(TWINT)) && count > 0) count -= 1; + // timed out + if (count == 0) return -1; + // failed to receive ack + if((TWSR & 0xF8) != TW_MT_DATA_ACK) return -1; + } - return i; + return i; } int i2c_read(struct I2C * i2c, uint8_t * data, int length) { - int i; - for (i = 0; i < length; i++) { - if ((i + 1) < length) { - // start TWI module and acknowledge data after reception - TWCR = BIT(TWINT) | BIT(TWEN) | BIT(TWEA); - } else { - // start receiving without acknowledging reception - TWCR = BIT(TWINT) | BIT(TWEN); - } - // wait for end of transmission - uint32_t count = TIMEOUT; - while(!(TWCR & BIT(TWINT)) && count > 0) count -= 1; - if (count == 0) return -1; - // return received data from TWDR - data[i] = TWDR; - } + int i; + for (i = 0; i < length; i++) { + if ((i + 1) < length) { + // start TWI module and acknowledge data after reception + TWCR = BIT(TWINT) | BIT(TWEN) | BIT(TWEA); + } else { + // start receiving without acknowledging reception + TWCR = BIT(TWINT) | BIT(TWEN); + } + // wait for end of transmission + uint32_t count = TIMEOUT; + while(!(TWCR & BIT(TWINT)) && count > 0) count -= 1; + if (count == 0) return -1; + // return received data from TWDR + data[i] = TWDR; + } - return i; + return i; } diff --git a/src/arch/avr/i2c_slave.c b/src/arch/avr/i2c_slave.c index 35a3d3d..d9c769a 100644 --- a/src/arch/avr/i2c_slave.c +++ b/src/arch/avr/i2c_slave.c @@ -16,75 +16,75 @@ static void (* volatile i2c_slave_recv_cb)(uint8_t) = NULL; static uint8_t (* volatile i2c_slave_send_cb)() = NULL; void i2c_slave_init(uint8_t address, void (*new_cb)(), void (*recv_cb)(uint8_t), uint8_t (*send_cb)()){ - // ensure correct behavior by stopping before changing callbacks or address - i2c_slave_stop(); + // ensure correct behavior by stopping before changing callbacks or address + i2c_slave_stop(); - // clear interrupts - cli(); + // clear interrupts + cli(); - // setup callbacks - i2c_slave_new_cb = new_cb; - i2c_slave_recv_cb = recv_cb; - i2c_slave_send_cb = send_cb; - // load address into TWI address register - TWAR = (address << 1); - // set the TWCR to enable address matching and enable TWI, clear TWINT, enable TWI interrupt - TWCR = BIT(TWIE) | BIT(TWEA) | BIT(TWINT) | BIT(TWEN); + // setup callbacks + i2c_slave_new_cb = new_cb; + i2c_slave_recv_cb = recv_cb; + i2c_slave_send_cb = send_cb; + // load address into TWI address register + TWAR = (address << 1); + // set the TWCR to enable address matching and enable TWI, clear TWINT, enable TWI interrupt + TWCR = BIT(TWIE) | BIT(TWEA) | BIT(TWINT) | BIT(TWEN); - // set interrupts - sei(); + // set interrupts + sei(); } void i2c_slave_stop(){ - // clear interrupts - cli(); + // clear interrupts + cli(); - // clear acknowledge and enable bits - TWCR &= ~(BIT(TWEA) | BIT(TWEN)); - // clear address - TWAR = 0; - // remove callbacks - i2c_slave_new_cb = NULL; - i2c_slave_recv_cb = NULL; - i2c_slave_send_cb = NULL; + // clear acknowledge and enable bits + TWCR &= ~(BIT(TWEA) | BIT(TWEN)); + // clear address + TWAR = 0; + // remove callbacks + i2c_slave_new_cb = NULL; + i2c_slave_recv_cb = NULL; + i2c_slave_send_cb = NULL; - // set interrupts - sei(); + // set interrupts + sei(); } ISR(TWI_vect) { - uint8_t status = TW_STATUS; - switch(status) { - case TW_SR_SLA_ACK: - // master has started a new transaction, call the new callback - if (i2c_slave_new_cb != NULL) { - i2c_slave_new_cb(); - } - TWCR = BIT(TWIE) | BIT(TWINT) | BIT(TWEA) | BIT(TWEN); - break; - case TW_SR_DATA_ACK: - // received data from master, call the receive callback - if(i2c_slave_send_cb != NULL){ - i2c_slave_recv_cb(TWDR); - } - TWCR = BIT(TWIE) | BIT(TWINT) | BIT(TWEA) | BIT(TWEN); - break; - case TW_ST_SLA_ACK: - case TW_ST_DATA_ACK: - // master is requesting data, call the send callback - if(i2c_slave_recv_cb != NULL) { - TWDR = i2c_slave_send_cb(); - } - TWCR = BIT(TWIE) | BIT(TWINT) | BIT(TWEA) | BIT(TWEN); - break; - case TW_BUS_ERROR: - // some sort of erroneous state, prepare TWI to be readdressed - printf("TWI_vect bus error\n"); - TWCR = 0; - TWCR = BIT(TWIE) | BIT(TWINT) | BIT(TWEA) | BIT(TWEN); - break; - default: - TWCR = BIT(TWIE) | BIT(TWINT) | BIT(TWEA) | BIT(TWEN); - break; - } + uint8_t status = TW_STATUS; + switch(status) { + case TW_SR_SLA_ACK: + // master has started a new transaction, call the new callback + if (i2c_slave_new_cb != NULL) { + i2c_slave_new_cb(); + } + TWCR = BIT(TWIE) | BIT(TWINT) | BIT(TWEA) | BIT(TWEN); + break; + case TW_SR_DATA_ACK: + // received data from master, call the receive callback + if(i2c_slave_send_cb != NULL){ + i2c_slave_recv_cb(TWDR); + } + TWCR = BIT(TWIE) | BIT(TWINT) | BIT(TWEA) | BIT(TWEN); + break; + case TW_ST_SLA_ACK: + case TW_ST_DATA_ACK: + // master is requesting data, call the send callback + if(i2c_slave_recv_cb != NULL) { + TWDR = i2c_slave_send_cb(); + } + TWCR = BIT(TWIE) | BIT(TWINT) | BIT(TWEA) | BIT(TWEN); + break; + case TW_BUS_ERROR: + // some sort of erroneous state, prepare TWI to be readdressed + printf("TWI_vect bus error\n"); + TWCR = 0; + TWCR = BIT(TWIE) | BIT(TWINT) | BIT(TWEA) | BIT(TWEN); + break; + default: + TWCR = BIT(TWIE) | BIT(TWINT) | BIT(TWEA) | BIT(TWEN); + break; + } } diff --git a/src/board/arduino/mega2560/i2c.c b/src/board/arduino/mega2560/i2c.c index 46d3ead..3c056a3 100644 --- a/src/board/arduino/mega2560/i2c.c +++ b/src/board/arduino/mega2560/i2c.c @@ -6,7 +6,7 @@ #include void i2c_init(unsigned long baud) { - TWAR = 0; - TWBR = (uint8_t)(((F_CPU / baud) - 16 ) / 2); - TWCR = 0; + TWAR = 0; + TWBR = (uint8_t)(((F_CPU / baud) - 16 ) / 2); + TWCR = 0; } diff --git a/src/board/arduino/uno/i2c.c b/src/board/arduino/uno/i2c.c index 46d3ead..3c056a3 100644 --- a/src/board/arduino/uno/i2c.c +++ b/src/board/arduino/uno/i2c.c @@ -6,7 +6,7 @@ #include void i2c_init(unsigned long baud) { - TWAR = 0; - TWBR = (uint8_t)(((F_CPU / baud) - 16 ) / 2); - TWCR = 0; + TWAR = 0; + TWBR = (uint8_t)(((F_CPU / baud) - 16 ) / 2); + TWCR = 0; } diff --git a/src/board/system76/common/scratch/main.c b/src/board/system76/common/scratch/main.c index 0998629..498c720 100644 --- a/src/board/system76/common/scratch/main.c +++ b/src/board/system76/common/scratch/main.c @@ -4,7 +4,7 @@ // Main program while running in scratch ROM void main(void) { - for (;;) { + for (;;) { smfi_event(); } } diff --git a/src/common/i2c.c b/src/common/i2c.c index 5fb0eef..c1b4e98 100644 --- a/src/common/i2c.c +++ b/src/common/i2c.c @@ -11,9 +11,9 @@ int i2c_recv(struct I2C * i2c, uint8_t addr, uint8_t* data, int length) __reentr res = i2c_read(i2c, data, length); if (res < 0) return res; - i2c_stop(i2c); + i2c_stop(i2c); - return res; + return res; } int i2c_send(struct I2C * i2c, uint8_t addr, uint8_t* data, int length) __reentrant { @@ -25,9 +25,9 @@ int i2c_send(struct I2C * i2c, uint8_t addr, uint8_t* data, int length) __reentr res = i2c_write(i2c, data, length); if (res < 0) return res; - i2c_stop(i2c); + i2c_stop(i2c); - return res; + return res; } int i2c_get(struct I2C * i2c, uint8_t addr, uint8_t reg, uint8_t* data, int length) __reentrant { @@ -48,7 +48,7 @@ int i2c_set(struct I2C * i2c, uint8_t addr, uint8_t reg, uint8_t* data, int leng res = i2c_start(i2c, addr, false); if (res < 0) return res; - res = i2c_write(i2c, ®, 1); + res = i2c_write(i2c, ®, 1); if (res < 0) return res; return i2c_send(i2c, addr, data, length); diff --git a/src/ec/it5570e/i2c.c b/src/ec/it5570e/i2c.c index 5eb7faa..e9d7f94 100644 --- a/src/ec/it5570e/i2c.c +++ b/src/ec/it5570e/i2c.c @@ -80,7 +80,7 @@ int i2c_start(struct I2C * i2c, uint8_t addr, bool read) __reentrant { *(i2c->trasla) = (addr << 1) | read; } - return 0; + return 0; } void i2c_stop(struct I2C * i2c) { diff --git a/src/ec/it8587e/i2c.c b/src/ec/it8587e/i2c.c index 975466f..9b26690 100644 --- a/src/ec/it8587e/i2c.c +++ b/src/ec/it8587e/i2c.c @@ -72,7 +72,7 @@ int i2c_start(struct I2C * i2c, uint8_t addr, bool read) __reentrant { *(i2c->trasla) = (addr << 1) | read; } - return 0; + return 0; } void i2c_stop(struct I2C * i2c) {