summaryrefslogtreecommitdiff
path: root/keyboards/ingrained
diff options
context:
space:
mode:
authorDavid Hoelscher <infinityis@users.noreply.github.com>2024-01-17 07:05:38 -0600
committerGitHub <noreply@github.com>2024-01-17 14:05:38 +0100
commite9bd7d7ad308f9c72c86863bf9f19382c7e2d892 (patch)
treec46ce87aaa57b8f49dc0a2b56527f0bc606038ab /keyboards/ingrained
parent2b0965944d9065daa65cd25540cf2dd007f23eda (diff)
I2C driver cleanup (#21273)
* remove i2c_start and i2c_stop from i2c drivers * remove static i2c_address variable from chibios i2c driver
Diffstat (limited to 'keyboards/ingrained')
-rw-r--r--keyboards/ingrained/matrix.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/keyboards/ingrained/matrix.c b/keyboards/ingrained/matrix.c
index 154a275d7a..3ba9d8dcf3 100644
--- a/keyboards/ingrained/matrix.c
+++ b/keyboards/ingrained/matrix.c
@@ -41,9 +41,7 @@ extern i2c_status_t mcp23017_status;
41// All address pins of the mcp23017 are connected to the ground on the ferris 41// All address pins of the mcp23017 are connected to the ground on the ferris
42// | 0 | 1 | 0 | 0 | A2 | A1 | A0 | 42// | 0 | 1 | 0 | 0 | A2 | A1 | A0 |
43// | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 43// | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
44#define I2C_ADDR 0b0100000 44#define I2C_ADDR (0b0100000<<1)
45#define I2C_ADDR_WRITE ((I2C_ADDR << 1) | I2C_WRITE)
46#define I2C_ADDR_READ ((I2C_ADDR << 1) | I2C_READ)
47 45
48// Register addresses 46// Register addresses
49// See https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library/blob/master/Adafruit_MCP23017.h 47// See https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library/blob/master/Adafruit_MCP23017.h
@@ -77,7 +75,7 @@ uint8_t init_mcp23017(void) {
77 // This means: we will read all the bits on GPIOA 75 // This means: we will read all the bits on GPIOA
78 // This means: we will write to the pins 0-4 on GPIOB (in select_rows) 76 // This means: we will write to the pins 0-4 on GPIOB (in select_rows)
79 uint8_t buf[] = {IODIRA, 0b11111111, 0b11110000}; 77 uint8_t buf[] = {IODIRA, 0b11111111, 0b11110000};
80 mcp23017_status = i2c_transmit(I2C_ADDR_WRITE, buf, sizeof(buf), I2C_TIMEOUT); 78 mcp23017_status = i2c_transmit(I2C_ADDR, buf, sizeof(buf), I2C_TIMEOUT);
81 if (!mcp23017_status) { 79 if (!mcp23017_status) {
82 // set pull-up 80 // set pull-up
83 // - unused : on : 1 81 // - unused : on : 1
@@ -86,7 +84,7 @@ uint8_t init_mcp23017(void) {
86 // This means: we will read all the bits on GPIOA 84 // This means: we will read all the bits on GPIOA
87 // This means: we will write to the pins 0-4 on GPIOB (in select_rows) 85 // This means: we will write to the pins 0-4 on GPIOB (in select_rows)
88 uint8_t pullup_buf[] = {GPPUA, 0b11111111, 0b11110000}; 86 uint8_t pullup_buf[] = {GPPUA, 0b11111111, 0b11110000};
89 mcp23017_status = i2c_transmit(I2C_ADDR_WRITE, pullup_buf, sizeof(pullup_buf), I2C_TIMEOUT); 87 mcp23017_status = i2c_transmit(I2C_ADDR, pullup_buf, sizeof(pullup_buf), I2C_TIMEOUT);
90 } 88 }
91 return mcp23017_status; 89 return mcp23017_status;
92} 90}
@@ -205,14 +203,14 @@ static matrix_row_t read_cols(uint8_t row) {
205 return 0; 203 return 0;
206 } else { 204 } else {
207 uint8_t buf[] = {GPIOA}; 205 uint8_t buf[] = {GPIOA};
208 mcp23017_status = i2c_transmit(I2C_ADDR_WRITE, buf, sizeof(buf), I2C_TIMEOUT); 206 mcp23017_status = i2c_transmit(I2C_ADDR, buf, sizeof(buf), I2C_TIMEOUT);
209 // We read all the pins on GPIOA. 207 // We read all the pins on GPIOA.
210 // The initial state was all ones and any depressed key at a given column for the currently selected row will have its bit flipped to zero. 208 // The initial state was all ones and any depressed key at a given column for the currently selected row will have its bit flipped to zero.
211 // The return value is a row as represented in the generic matrix code were the rightmost bits represent the lower columns and zeroes represent non-depressed keys while ones represent depressed keys. 209 // The return value is a row as represented in the generic matrix code were the rightmost bits represent the lower columns and zeroes represent non-depressed keys while ones represent depressed keys.
212 // Since the pins connected to eact columns are sequential, and counting from zero up (col 5 -> GPIOA0, col 6 -> GPIOA1 and so on), the only transformation needed is a bitwise not to swap all zeroes and ones. 210 // Since the pins connected to eact columns are sequential, and counting from zero up (col 5 -> GPIOA0, col 6 -> GPIOA1 and so on), the only transformation needed is a bitwise not to swap all zeroes and ones.
213 uint8_t data[] = {0}; 211 uint8_t data[] = {0};
214 if (!mcp23017_status) { 212 if (!mcp23017_status) {
215 mcp23017_status = i2c_receive(I2C_ADDR_READ, data, sizeof(data), I2C_TIMEOUT); 213 mcp23017_status = i2c_receive(I2C_ADDR, data, sizeof(data), I2C_TIMEOUT);
216 data[0] = ~(data[0]); 214 data[0] = ~(data[0]);
217 } 215 }
218 return data[0]; 216 return data[0];
@@ -249,7 +247,7 @@ static void select_row(uint8_t row) {
249 // Select the desired row by writing a byte for the entire GPIOB bus where only the bit representing the row we want to select is a zero (write instruction) and every other bit is a one. 247 // Select the desired row by writing a byte for the entire GPIOB bus where only the bit representing the row we want to select is a zero (write instruction) and every other bit is a one.
250 // Note that the row - MATRIX_ROWS_PER_SIDE reflects the fact that being on the right hand, the columns are numbered from MATRIX_ROWS_PER_SIDE to MATRIX_ROWS, but the pins we want to write to are indexed from zero up on the GPIOB bus. 248 // Note that the row - MATRIX_ROWS_PER_SIDE reflects the fact that being on the right hand, the columns are numbered from MATRIX_ROWS_PER_SIDE to MATRIX_ROWS, but the pins we want to write to are indexed from zero up on the GPIOB bus.
251 uint8_t buf[] = {GPIOB, 0xFF & ~(1 << (row - MATRIX_ROWS_PER_SIDE))}; 249 uint8_t buf[] = {GPIOB, 0xFF & ~(1 << (row - MATRIX_ROWS_PER_SIDE))};
252 mcp23017_status = i2c_transmit(I2C_ADDR_WRITE, buf, sizeof(buf), I2C_TIMEOUT); 250 mcp23017_status = i2c_transmit(I2C_ADDR, buf, sizeof(buf), I2C_TIMEOUT);
253 } 251 }
254 } 252 }
255} 253}