summaryrefslogtreecommitdiff
path: root/keyboards/handwired/frenchdev
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/handwired/frenchdev
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/handwired/frenchdev')
-rw-r--r--keyboards/handwired/frenchdev/frenchdev.c27
-rw-r--r--keyboards/handwired/frenchdev/frenchdev.h4
-rw-r--r--keyboards/handwired/frenchdev/matrix.c28
3 files changed, 20 insertions, 39 deletions
diff --git a/keyboards/handwired/frenchdev/frenchdev.c b/keyboards/handwired/frenchdev/frenchdev.c
index 6eed4de5ff..65f1ccce4b 100644
--- a/keyboards/handwired/frenchdev/frenchdev.c
+++ b/keyboards/handwired/frenchdev/frenchdev.c
@@ -83,23 +83,16 @@ uint8_t init_mcp23018(void) {
83 // - unused : input : 1 83 // - unused : input : 1
84 // - input : input : 1 84 // - input : input : 1
85 // - driving : output : 0 85 // - driving : output : 0
86 mcp23018_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT); if (mcp23018_status) goto out; 86 uint8_t data[] = {0b00000000, 0b00111111};
87 mcp23018_status = i2c_write(IODIRA, I2C_TIMEOUT); if (mcp23018_status) goto out; 87 mcp23018_status = i2c_writeReg(I2C_ADDR, IODIRA, data, sizeof(data), I2C_TIMEOUT);
88 mcp23018_status = i2c_write(0b00000000, I2C_TIMEOUT); if (mcp23018_status) goto out; 88
89 mcp23018_status = i2c_write(0b00111111, I2C_TIMEOUT); if (mcp23018_status) goto out; 89 if (!mcp23018_status) {
90 i2c_stop(); 90 // set pull-up
91 91 // - unused : on : 1
92 // set pull-up 92 // - input : on : 1
93 // - unused : on : 1 93 // - driving : off : 0
94 // - input : on : 1 94 mcp23018_status = i2c_writeReg(I2C_ADDR, GPPUA, data, sizeof(data), I2C_TIMEOUT);
95 // - driving : off : 0 95 }
96 mcp23018_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT); if (mcp23018_status) goto out;
97 mcp23018_status = i2c_write(GPPUA, I2C_TIMEOUT); if (mcp23018_status) goto out;
98 mcp23018_status = i2c_write(0b00000000, I2C_TIMEOUT); if (mcp23018_status) goto out;
99 mcp23018_status = i2c_write(0b00111111, I2C_TIMEOUT); if (mcp23018_status) goto out;
100
101out:
102 i2c_stop();
103 96
104 // SREG=sreg_prev; 97 // SREG=sreg_prev;
105 98
diff --git a/keyboards/handwired/frenchdev/frenchdev.h b/keyboards/handwired/frenchdev/frenchdev.h
index 6bea49d87b..0f1ac7dcaa 100644
--- a/keyboards/handwired/frenchdev/frenchdev.h
+++ b/keyboards/handwired/frenchdev/frenchdev.h
@@ -7,9 +7,7 @@
7#include <util/delay.h> 7#include <util/delay.h>
8 8
9// I2C aliases and register addresses (see "mcp23018.md" on tmk repository) 9// I2C aliases and register addresses (see "mcp23018.md" on tmk repository)
10#define I2C_ADDR 0b0100000 10#define I2C_ADDR (0b0100000<<1)
11#define I2C_ADDR_WRITE ( (I2C_ADDR<<1) | I2C_WRITE )
12#define I2C_ADDR_READ ( (I2C_ADDR<<1) | I2C_READ )
13#define IODIRA 0x00 // i/o direction register 11#define IODIRA 0x00 // i/o direction register
14#define IODIRB 0x01 12#define IODIRB 0x01
15#define GPPUA 0x0C // GPIO pull-up resistor register 13#define GPPUA 0x0C // GPIO pull-up resistor register
diff --git a/keyboards/handwired/frenchdev/matrix.c b/keyboards/handwired/frenchdev/matrix.c
index 3e859d47ef..3afc6dcee6 100644
--- a/keyboards/handwired/frenchdev/matrix.c
+++ b/keyboards/handwired/frenchdev/matrix.c
@@ -224,15 +224,9 @@ static matrix_row_t read_cols(uint8_t row)
224 return 0; 224 return 0;
225 } else { 225 } else {
226 uint8_t data = 0; 226 uint8_t data = 0;
227 mcp23018_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT); if (mcp23018_status) goto out; 227 mcp23018_status = i2c_readReg(I2C_ADDR, GPIOB, &data, 1, I2C_TIMEOUT);
228 mcp23018_status = i2c_write(GPIOB, I2C_TIMEOUT); if (mcp23018_status) goto out; 228
229 mcp23018_status = i2c_start(I2C_ADDR_READ, I2C_TIMEOUT); if (mcp23018_status) goto out; 229 return ~data;
230 data = i2c_read_nack(I2C_TIMEOUT); if (mcp23018_status < 0) goto out;
231 data = ~((uint8_t)mcp23018_status);
232 mcp23018_status = I2C_STATUS_SUCCESS;
233 out:
234 i2c_stop();
235 return data;
236 } 230 }
237 } else { 231 } else {
238 // read from teensy 232 // read from teensy
@@ -263,11 +257,10 @@ static void unselect_rows(void)
263 // do nothing 257 // do nothing
264 } else { 258 } else {
265 // set all rows hi-Z : 1 259 // set all rows hi-Z : 1
266 mcp23018_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT); if (mcp23018_status) goto out; 260 uint8_t data;
267 mcp23018_status = i2c_write(GPIOA, I2C_TIMEOUT); if (mcp23018_status) goto out; 261 data = 0xFF & ~(0<<8);
268 mcp23018_status = i2c_write( 0xFF & ~(0<<8), I2C_TIMEOUT); if (mcp23018_status) goto out; 262 mcp23018_status = i2c_writeReg(I2C_ADDR, GPIOA, &data, 1, I2C_TIMEOUT);
269 out: 263
270 i2c_stop();
271 } 264 }
272 265
273 // unselect on teensy 266 // unselect on teensy
@@ -289,11 +282,8 @@ static void select_row(uint8_t row)
289 } else { 282 } else {
290 // set active row low : 0 283 // set active row low : 0
291 // set other rows hi-Z : 1 284 // set other rows hi-Z : 1
292 mcp23018_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT); if (mcp23018_status) goto out; 285 uint8_t data = 0xFF & ~(1<<row) & ~(0<<8);
293 mcp23018_status = i2c_write(GPIOA, I2C_TIMEOUT); if (mcp23018_status) goto out; 286 mcp23018_status = i2c_writeReg(I2C_ADDR, GPIOA, &data, 1, I2C_TIMEOUT);
294 mcp23018_status = i2c_write( 0xFF & ~(1<<row) & ~(0<<8), I2C_TIMEOUT); if (mcp23018_status) goto out;
295 out:
296 i2c_stop();
297 } 287 }
298 } else { 288 } else {
299 // select on teensy 289 // select on teensy