Reindent files using spaces
This commit is contained in:
		
				
					committed by
					
						 Jeremy Soller
						Jeremy Soller
					
				
			
			
				
	
			
			
			
						parent
						
							720af4b2b0
						
					
				
				
					commit
					4963e04a83
				
			| @@ -18,8 +18,8 @@ grep '^#define \(K_\|KT_FN\)' "$header" \ | |||||||
| | cut -d ' ' -f2 \ | | cut -d ' ' -f2 \ | ||||||
| | while read keycode | | while read keycode | ||||||
| do | do | ||||||
| 	name="$(echo "$keycode" | cut -d '_' -f2-)" |     name="$(echo "$keycode" | cut -d '_' -f2-)" | ||||||
| 	echo "printf(\"${name},0x%04X\\n\", $keycode);" >> "$source" |     echo "printf(\"${name},0x%04X\\n\", $keycode);" >> "$source" | ||||||
| done | done | ||||||
| echo "return 0;" >> "$source" | echo "return 0;" >> "$source" | ||||||
| echo "}" >> "$source" | echo "}" >> "$source" | ||||||
| @@ -29,37 +29,37 @@ gcc -I. "$source" -o "$binary" | |||||||
| cd src/board | cd src/board | ||||||
| for board in */* | for board in */* | ||||||
| do | do | ||||||
| 	file="$board/include/board/keymap.h" |     file="$board/include/board/keymap.h" | ||||||
| 	if [ ! -e "$file" ] |     if [ ! -e "$file" ] | ||||||
| 	then |     then | ||||||
| 		continue |         continue | ||||||
| 	fi |     fi | ||||||
| 	echo "# $board" |     echo "# $board" | ||||||
| 	mkdir -p "$D/$board" |     mkdir -p "$D/$board" | ||||||
| 	cp "$D/keymap.csv" "$D/$board" |     cp "$D/keymap.csv" "$D/$board" | ||||||
| 	row=0 |     row=0 | ||||||
| 	rg \ |     rg \ | ||||||
| 		--multiline \ |         --multiline \ | ||||||
| 		--multiline-dotall \ |         --multiline-dotall \ | ||||||
| 		--regexp '#define LAYOUT\(.*\) \{.*\}' \ |         --regexp '#define LAYOUT\(.*\) \{.*\}' \ | ||||||
| 		"$file" \ |         "$file" \ | ||||||
| 	| grep --only-matching '\{.*\}' \ |     | grep --only-matching '\{.*\}' \ | ||||||
| 	| sed 's/^{ //' \ |     | sed 's/^{ //' \ | ||||||
| 	| sed 's/ }$//' \ |     | sed 's/ }$//' \ | ||||||
| 	| sed 's/, / /g' \ |     | sed 's/, / /g' \ | ||||||
| 	| while read line |     | while read line | ||||||
| 	do |     do | ||||||
| 		col=0 |         col=0 | ||||||
| 		for word in $line |         for word in $line | ||||||
| 		do |         do | ||||||
| 			if [ "$word" != "___" ] |             if [ "$word" != "___" ] | ||||||
| 			then |             then | ||||||
| 				echo "$word,$row,$col" |                 echo "$word,$row,$col" | ||||||
| 			fi |             fi | ||||||
| 			col=$(expr $col + 1) |             col=$(expr $col + 1) | ||||||
| 		done |         done | ||||||
| 		row=$(expr $row + 1) |         row=$(expr $row + 1) | ||||||
| 	done \ |     done \ | ||||||
| 	| sort -n \ |     | sort -n \ | ||||||
| 	| tee "$D/${board}/layout.csv" |     | tee "$D/${board}/layout.csv" | ||||||
| done | done | ||||||
|   | |||||||
| @@ -11,77 +11,77 @@ | |||||||
| #define TIMEOUT (F_CPU/1000) | #define TIMEOUT (F_CPU/1000) | ||||||
|  |  | ||||||
| int i2c_start(struct I2C * i2c, uint8_t addr, bool read) { | int i2c_start(struct I2C * i2c, uint8_t addr, bool read) { | ||||||
| 	uint32_t count; |     uint32_t count; | ||||||
|  |  | ||||||
| 	// reset TWI control register |     // reset TWI control register | ||||||
| 	TWCR = 0; |     TWCR = 0; | ||||||
| 	// transmit START condition |     // transmit START condition | ||||||
| 	TWCR = BIT(TWINT) | BIT(TWSTA) | BIT(TWEN); |     TWCR = BIT(TWINT) | BIT(TWSTA) | BIT(TWEN); | ||||||
| 	// wait for end of transmission |     // wait for end of transmission | ||||||
| 	count = TIMEOUT; |     count = TIMEOUT; | ||||||
| 	while(!(TWCR & BIT(TWINT)) && count > 0) count -= 1; |     while(!(TWCR & BIT(TWINT)) && count > 0) count -= 1; | ||||||
| 	if (count == 0) return -1; |     if (count == 0) return -1; | ||||||
|  |  | ||||||
| 	// check if the start condition was successfully transmitted |     // check if the start condition was successfully transmitted | ||||||
| 	if((TWSR & 0xF8) != TW_START) return -1; |     if((TWSR & 0xF8) != TW_START) return -1; | ||||||
|  |  | ||||||
| 	// load slave addr into data register |     // load slave addr into data register | ||||||
| 	TWDR = ((addr << 1) | read); |     TWDR = ((addr << 1) | read); | ||||||
| 	// start transmission of addr |     // start transmission of addr | ||||||
| 	TWCR = BIT(TWINT) | BIT(TWEN); |     TWCR = BIT(TWINT) | BIT(TWEN); | ||||||
| 	// wait for end of transmission |     // wait for end of transmission | ||||||
| 	count = TIMEOUT; |     count = TIMEOUT; | ||||||
| 	while(!(TWCR & BIT(TWINT)) && count > 0) count -= 1; |     while(!(TWCR & BIT(TWINT)) && count > 0) count -= 1; | ||||||
| 	if (count == 0) return -1; |     if (count == 0) return -1; | ||||||
|  |  | ||||||
| 	// check if the device has acknowledged the READ / WRITE mode |     // check if the device has acknowledged the READ / WRITE mode | ||||||
| 	uint8_t twst = TW_STATUS & 0xF8; |     uint8_t twst = TW_STATUS & 0xF8; | ||||||
| 	if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) return -1; |     if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) return -1; | ||||||
|  |  | ||||||
| 	return 0; |     return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| void i2c_stop(struct I2C * i2c) { | void i2c_stop(struct I2C * i2c) { | ||||||
| 	// transmit STOP condition |     // transmit STOP condition | ||||||
| 	TWCR = BIT(TWINT) | BIT(TWEN) | BIT(TWSTO); |     TWCR = BIT(TWINT) | BIT(TWEN) | BIT(TWSTO); | ||||||
| } | } | ||||||
|  |  | ||||||
| int i2c_write(struct I2C * i2c, uint8_t * data, int length) { | int i2c_write(struct I2C * i2c, uint8_t * data, int length) { | ||||||
| 	int i; |     int i; | ||||||
| 	for (i = 0; i < length; i++) { |     for (i = 0; i < length; i++) { | ||||||
| 		// load data into data register |         // load data into data register | ||||||
| 		TWDR = data[i]; |         TWDR = data[i]; | ||||||
| 		// start transmission of data |         // start transmission of data | ||||||
| 		TWCR = BIT(TWINT) | BIT(TWEN); |         TWCR = BIT(TWINT) | BIT(TWEN); | ||||||
| 		// wait for end of transmission |         // wait for end of transmission | ||||||
| 		uint32_t count = TIMEOUT; |         uint32_t count = TIMEOUT; | ||||||
| 		while(!(TWCR & BIT(TWINT)) && count > 0) count -= 1; |         while(!(TWCR & BIT(TWINT)) && count > 0) count -= 1; | ||||||
| 		// timed out |         // timed out | ||||||
| 		if (count == 0) return -1; |         if (count == 0) return -1; | ||||||
| 		// failed to receive ack |         // failed to receive ack | ||||||
| 		if((TWSR & 0xF8) != TW_MT_DATA_ACK) return -1; |         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 i2c_read(struct I2C * i2c, uint8_t * data, int length) { | ||||||
| 	int i; |     int i; | ||||||
| 	for (i = 0; i < length; i++) { |     for (i = 0; i < length; i++) { | ||||||
| 	    if ((i + 1) < length) { |         if ((i + 1) < length) { | ||||||
| 	    	// start TWI module and acknowledge data after reception |             // start TWI module and acknowledge data after reception | ||||||
| 	    	TWCR = BIT(TWINT) | BIT(TWEN) | BIT(TWEA); |             TWCR = BIT(TWINT) | BIT(TWEN) | BIT(TWEA); | ||||||
| 	    } else { |         } else { | ||||||
| 	        // start receiving without acknowledging reception |             // start receiving without acknowledging reception | ||||||
| 	    	TWCR = BIT(TWINT) | BIT(TWEN); |             TWCR = BIT(TWINT) | BIT(TWEN); | ||||||
| 	    } |         } | ||||||
| 		// wait for end of transmission |         // wait for end of transmission | ||||||
| 		uint32_t count = TIMEOUT; |         uint32_t count = TIMEOUT; | ||||||
| 		while(!(TWCR & BIT(TWINT)) && count > 0) count -= 1; |         while(!(TWCR & BIT(TWINT)) && count > 0) count -= 1; | ||||||
| 		if (count == 0) return -1; |         if (count == 0) return -1; | ||||||
| 		// return received data from TWDR |         // return received data from TWDR | ||||||
| 		data[i] = TWDR; |         data[i] = TWDR; | ||||||
| 	} |     } | ||||||
|  |  | ||||||
| 	return i; |     return i; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -16,75 +16,75 @@ static void (* volatile i2c_slave_recv_cb)(uint8_t) = NULL; | |||||||
| static uint8_t (* volatile i2c_slave_send_cb)() = 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)()){ | 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 |     // ensure correct behavior by stopping before changing callbacks or address | ||||||
| 	i2c_slave_stop(); |     i2c_slave_stop(); | ||||||
|  |  | ||||||
| 	// clear interrupts |     // clear interrupts | ||||||
| 	cli(); |     cli(); | ||||||
|  |  | ||||||
| 	// setup callbacks |     // setup callbacks | ||||||
| 	i2c_slave_new_cb = new_cb; |     i2c_slave_new_cb = new_cb; | ||||||
| 	i2c_slave_recv_cb = recv_cb; |     i2c_slave_recv_cb = recv_cb; | ||||||
| 	i2c_slave_send_cb = send_cb; |     i2c_slave_send_cb = send_cb; | ||||||
| 	// load address into TWI address register |     // load address into TWI address register | ||||||
| 	TWAR = (address << 1); |     TWAR = (address << 1); | ||||||
| 	// set the TWCR to enable address matching and enable TWI, clear TWINT, enable TWI interrupt |     // set the TWCR to enable address matching and enable TWI, clear TWINT, enable TWI interrupt | ||||||
| 	TWCR = BIT(TWIE) | BIT(TWEA) | BIT(TWINT) | BIT(TWEN); |     TWCR = BIT(TWIE) | BIT(TWEA) | BIT(TWINT) | BIT(TWEN); | ||||||
|  |  | ||||||
| 	// set interrupts |     // set interrupts | ||||||
| 	sei(); |     sei(); | ||||||
| } | } | ||||||
|  |  | ||||||
| void i2c_slave_stop(){ | void i2c_slave_stop(){ | ||||||
| 	// clear interrupts |     // clear interrupts | ||||||
| 	cli(); |     cli(); | ||||||
|  |  | ||||||
| 	// clear acknowledge and enable bits |     // clear acknowledge and enable bits | ||||||
| 	TWCR &= ~(BIT(TWEA) | BIT(TWEN)); |     TWCR &= ~(BIT(TWEA) | BIT(TWEN)); | ||||||
| 	// clear address |     // clear address | ||||||
| 	TWAR = 0; |     TWAR = 0; | ||||||
| 	// remove callbacks |     // remove callbacks | ||||||
| 	i2c_slave_new_cb = NULL; |     i2c_slave_new_cb = NULL; | ||||||
| 	i2c_slave_recv_cb = NULL; |     i2c_slave_recv_cb = NULL; | ||||||
| 	i2c_slave_send_cb = NULL; |     i2c_slave_send_cb = NULL; | ||||||
|  |  | ||||||
| 	// set interrupts |     // set interrupts | ||||||
| 	sei(); |     sei(); | ||||||
| } | } | ||||||
|  |  | ||||||
| ISR(TWI_vect) { | ISR(TWI_vect) { | ||||||
| 	uint8_t status = TW_STATUS; |     uint8_t status = TW_STATUS; | ||||||
| 	switch(status) { |     switch(status) { | ||||||
| 	case TW_SR_SLA_ACK: |     case TW_SR_SLA_ACK: | ||||||
| 		// master has started a new transaction, call the new callback |         // master has started a new transaction, call the new callback | ||||||
| 		if (i2c_slave_new_cb != NULL) { |         if (i2c_slave_new_cb != NULL) { | ||||||
| 			i2c_slave_new_cb(); |             i2c_slave_new_cb(); | ||||||
| 		} |         } | ||||||
| 		TWCR = BIT(TWIE) | BIT(TWINT) | BIT(TWEA) | BIT(TWEN); |         TWCR = BIT(TWIE) | BIT(TWINT) | BIT(TWEA) | BIT(TWEN); | ||||||
| 		break; |         break; | ||||||
| 	case TW_SR_DATA_ACK: |     case TW_SR_DATA_ACK: | ||||||
| 		// received data from master, call the receive callback |         // received data from master, call the receive callback | ||||||
| 		if(i2c_slave_send_cb != NULL){ |         if(i2c_slave_send_cb != NULL){ | ||||||
| 			i2c_slave_recv_cb(TWDR); |             i2c_slave_recv_cb(TWDR); | ||||||
| 		} |         } | ||||||
| 		TWCR = BIT(TWIE) | BIT(TWINT) | BIT(TWEA) | BIT(TWEN); |         TWCR = BIT(TWIE) | BIT(TWINT) | BIT(TWEA) | BIT(TWEN); | ||||||
| 		break; |         break; | ||||||
| 	case TW_ST_SLA_ACK: |     case TW_ST_SLA_ACK: | ||||||
| 	case TW_ST_DATA_ACK: |     case TW_ST_DATA_ACK: | ||||||
| 		// master is requesting data, call the send callback |         // master is requesting data, call the send callback | ||||||
| 		if(i2c_slave_recv_cb != NULL) { |         if(i2c_slave_recv_cb != NULL) { | ||||||
| 			TWDR = i2c_slave_send_cb(); |             TWDR = i2c_slave_send_cb(); | ||||||
| 		} |         } | ||||||
| 		TWCR = BIT(TWIE) | BIT(TWINT) | BIT(TWEA) | BIT(TWEN); |         TWCR = BIT(TWIE) | BIT(TWINT) | BIT(TWEA) | BIT(TWEN); | ||||||
| 		break; |         break; | ||||||
| 	case TW_BUS_ERROR: |     case TW_BUS_ERROR: | ||||||
| 		// some sort of erroneous state, prepare TWI to be readdressed |         // some sort of erroneous state, prepare TWI to be readdressed | ||||||
| 		printf("TWI_vect bus error\n"); |         printf("TWI_vect bus error\n"); | ||||||
| 		TWCR = 0; |         TWCR = 0; | ||||||
| 		TWCR = BIT(TWIE) | BIT(TWINT) | BIT(TWEA) | BIT(TWEN); |         TWCR = BIT(TWIE) | BIT(TWINT) | BIT(TWEA) | BIT(TWEN); | ||||||
| 		break; |         break; | ||||||
| 	default: |     default: | ||||||
| 		TWCR = BIT(TWIE) | BIT(TWINT) | BIT(TWEA) | BIT(TWEN); |         TWCR = BIT(TWIE) | BIT(TWINT) | BIT(TWEA) | BIT(TWEN); | ||||||
| 		break; |         break; | ||||||
| 	} |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -6,7 +6,7 @@ | |||||||
| #include <board/i2c.h> | #include <board/i2c.h> | ||||||
|  |  | ||||||
| void i2c_init(unsigned long baud) { | void i2c_init(unsigned long baud) { | ||||||
| 	TWAR = 0; |     TWAR = 0; | ||||||
| 	TWBR = (uint8_t)(((F_CPU / baud) - 16 ) / 2); |     TWBR = (uint8_t)(((F_CPU / baud) - 16 ) / 2); | ||||||
| 	TWCR = 0; |     TWCR = 0; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -6,7 +6,7 @@ | |||||||
| #include <board/i2c.h> | #include <board/i2c.h> | ||||||
|  |  | ||||||
| void i2c_init(unsigned long baud) { | void i2c_init(unsigned long baud) { | ||||||
| 	TWAR = 0; |     TWAR = 0; | ||||||
| 	TWBR = (uint8_t)(((F_CPU / baud) - 16 ) / 2); |     TWBR = (uint8_t)(((F_CPU / baud) - 16 ) / 2); | ||||||
| 	TWCR = 0; |     TWCR = 0; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ | |||||||
|  |  | ||||||
| // Main program while running in scratch ROM | // Main program while running in scratch ROM | ||||||
| void main(void) { | void main(void) { | ||||||
| 	for (;;) { |     for (;;) { | ||||||
|         smfi_event(); |         smfi_event(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -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); |     res = i2c_read(i2c, data, length); | ||||||
|     if (res < 0) return res; |     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 { | 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); |     res = i2c_write(i2c, data, length); | ||||||
|     if (res < 0) return res; |     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 { | 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); |     res = i2c_start(i2c, addr, false); | ||||||
|     if (res < 0) return res; |     if (res < 0) return res; | ||||||
|  |  | ||||||
| 	res = i2c_write(i2c, ®, 1); |     res = i2c_write(i2c, ®, 1); | ||||||
|     if (res < 0) return res; |     if (res < 0) return res; | ||||||
|  |  | ||||||
|     return i2c_send(i2c, addr, data, length); |     return i2c_send(i2c, addr, data, length); | ||||||
|   | |||||||
| @@ -80,7 +80,7 @@ int i2c_start(struct I2C * i2c, uint8_t addr, bool read) __reentrant { | |||||||
|         *(i2c->trasla) = (addr << 1) | read; |         *(i2c->trasla) = (addr << 1) | read; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| 	return 0; |     return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| void i2c_stop(struct I2C * i2c) { | void i2c_stop(struct I2C * i2c) { | ||||||
|   | |||||||
| @@ -72,7 +72,7 @@ int i2c_start(struct I2C * i2c, uint8_t addr, bool read) __reentrant { | |||||||
|         *(i2c->trasla) = (addr << 1) | read; |         *(i2c->trasla) = (addr << 1) | read; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| 	return 0; |     return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| void i2c_stop(struct I2C * i2c) { | void i2c_stop(struct I2C * i2c) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user