summaryrefslogtreecommitdiff
path: root/keyboards/bajjak
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/bajjak
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/bajjak')
-rw-r--r--keyboards/bajjak/bajjak.c47
-rw-r--r--keyboards/bajjak/bajjak.h4
-rw-r--r--keyboards/bajjak/matrix.c16
3 files changed, 21 insertions, 46 deletions
diff --git a/keyboards/bajjak/bajjak.c b/keyboards/bajjak/bajjak.c
index 74e2b2aa8c..e6102e817b 100644
--- a/keyboards/bajjak/bajjak.c
+++ b/keyboards/bajjak/bajjak.c
@@ -137,23 +137,16 @@ uint8_t init_mcp23018(void) {
// - unused : input : 1
// - input : input : 1
// - driving : output : 0
- mcp23018_status = i2c_start(I2C_ADDR_WRITE, BAJJAK_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(IODIRA, BAJJAK_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(0b00000000, BAJJAK_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(0b00111111, BAJJAK_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
- i2c_stop();
-
- // set pull-up
- // - unused : on : 1
- // - input : on : 1
- // - driving : off : 0
- mcp23018_status = i2c_start(I2C_ADDR_WRITE, BAJJAK_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(GPPUA, BAJJAK_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(0b00000000, BAJJAK_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(0b01111111, BAJJAK_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
-
-out:
- i2c_stop();
+ uint8_t data[] = {0b00000000, 0b00111111};
+ mcp23018_status = i2c_writeReg(I2C_ADDR, IODIRA, data, 2, BAJJAK_EZ_I2C_TIMEOUT);
+
+ if (!mcp23018_status) {
+ // set pull-up
+ // - unused : on : 1
+ // - input : on : 1
+ // - driving : off : 0
+ mcp23018_status = i2c_writeReg(I2C_ADDR, IODIRA, data, 2, BAJJAK_EZ_I2C_TIMEOUT);
+ }
#ifdef LEFT_LEDS
if (!mcp23018_status) mcp23018_status = bajjak_left_leds_update();
@@ -176,21 +169,11 @@ uint8_t bajjak_left_leds_update(void) {
// - unused : hi-Z : 1
// - input : hi-Z : 1
// - driving : hi-Z : 1
- mcp23018_status = i2c_start(I2C_ADDR_WRITE, BAJJAK_EZ_I2C_TIMEOUT);
- if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(OLATA, BAJJAK_EZ_I2C_TIMEOUT);
- if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(0b11111111
- & ~(bajjak_left_led_1<<LEFT_LED_1_SHIFT),
- BAJJAK_EZ_I2C_TIMEOUT);
- if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(0b11111111
- & ~(bajjak_left_led_2<<LEFT_LED_2_SHIFT),
- BAJJAK_EZ_I2C_TIMEOUT);
- if (mcp23018_status) goto out;
-
- out:
- i2c_stop();
+ uint8_t data[2];
+ data[0] = 0b11111111 & ~(bajjak_left_led_1<<LEFT_LED_1_SHIFT);
+ data[1] = 0b11111111 & ~(bajjak_left_led_2<<LEFT_LED_2_SHIFT);
+ mcp23018_status = i2c_writeReg(I2C_ADDR, OLATA, data, 2, BAJJAK_EZ_I2C_TIMEOUT);
+
return mcp23018_status;
}
#endif
diff --git a/keyboards/bajjak/bajjak.h b/keyboards/bajjak/bajjak.h
index 52f14ad3ea..c2d2d77ef6 100644
--- a/keyboards/bajjak/bajjak.h
+++ b/keyboards/bajjak/bajjak.h
@@ -27,9 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "i2c_master.h"
// I2C aliases and register addresses (see "mcp23018.md")
-#define I2C_ADDR 0b0100000
-#define I2C_ADDR_WRITE ( (I2C_ADDR<<1) | I2C_WRITE )
-#define I2C_ADDR_READ ( (I2C_ADDR<<1) | I2C_READ )
+#define I2C_ADDR (0b0100000<<1)
#define IODIRA 0x00 // i/o direction register
#define IODIRB 0x01
#define GPPUA 0x0C // GPIO pull-up resistor register
diff --git a/keyboards/bajjak/matrix.c b/keyboards/bajjak/matrix.c
index 20fc3c8f23..424bc29e4e 100644
--- a/keyboards/bajjak/matrix.c
+++ b/keyboards/bajjak/matrix.c
@@ -145,12 +145,7 @@ static matrix_row_t read_cols(uint8_t row) {
uint8_t data = 0;
// reading GPIOB (column port) since in mcp23018's sequential mode
// it is addressed directly after writing to GPIOA in select_row()
- mcp23018_status = i2c_start(I2C_ADDR_READ, BAJJAK_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
- mcp23018_status = i2c_read_nack(BAJJAK_EZ_I2C_TIMEOUT); if (mcp23018_status < 0) goto out;
- data = ~((uint8_t)mcp23018_status);
- mcp23018_status = I2C_STATUS_SUCCESS;
- out:
- i2c_stop();
+ mcp23018_status = i2c_receive(I2C_ADDR, &data, 1, BAJJAK_EZ_I2C_TIMEOUT);
return data;
}
} else {
@@ -195,11 +190,10 @@ static void select_row(uint8_t row) {
if (!mcp23018_status) {
// set active row low : 0
// set other rows hi-Z : 1
- mcp23018_status = i2c_start(I2C_ADDR_WRITE, BAJJAK_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(GPIOA, BAJJAK_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(0xFF & ~(1 << row), BAJJAK_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
- out:
- i2c_stop();
+ uint8_t data;
+ data = 0xFF & ~(1 << row);
+ mcp23018_status = i2c_writeReg(I2C_ADDR, GPIOA, &data, 1, BAJJAK_EZ_I2C_TIMEOUT);
+
}
} else {
// select on teensy