Skip to content

Commit

Permalink
orthodox: TWI (i2c) is working, kludge for col9
Browse files Browse the repository at this point in the history
The TWI interconnect ("i2c" in directories and build config) is now
working for the Orthodox, including the slave half's column qmk#9.
This is intended as an interim solution, as it's a kludge, not a fix.

Rather than a working multi-byte implementation, the two col9 keys'
bits are packed-into and unpacked-from the two unused bits in row1.
Furthermore, the TWI clock constant has been reduced to 100000 from
400000, as testing revealed the higher value just didn't work.
Testing also found that (with this kludge) increasing the TWI buffer
was not necessary.

This commit leaves many commented-out lines in matrix.c from previous
testing, which will be removed in a future commit once the
interconnects' multi-byte problems have been debugged more thoroughly.
  • Loading branch information
utrrrongeeb committed Jun 26, 2017
1 parent 3244e69 commit e5d724d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion keyboards/orthodox/i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#define I2C_ACK 1
#define I2C_NACK 0

#define SLAVE_BUFFER_SIZE 0x20
#define SLAVE_BUFFER_SIZE 0x10

// i2c SCL clock frequency
#define SCL_CLOCK 100000UL
Expand Down
33 changes: 21 additions & 12 deletions keyboards/orthodox/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,22 +171,27 @@ int i2c_transaction(void) {
if (err) goto i2c_error;

if (!err) {
/*
// read from TWI byte-by-byte into matrix_row_t memory space
/*
// read from TWI byte-by-byte into matrix_row_t memory space
size_t i;
for (i = 0; i < SLAVE_BUFFER_SIZE-1; ++i) {
*((uint8_t*)&matrix[slaveOffset]+i) = i2c_master_read(I2C_ACK);
}
// last byte to be read / end of chunk
// last byte to be read / end of chunk
*((uint8_t*)&matrix[slaveOffset]+i) = i2c_master_read(I2C_NACK);
*/

// i2c_master_read(I2C_ACK);
matrix[slaveOffset+0] = i2c_master_read(I2C_ACK);
// i2c_master_read(I2C_ACK);
matrix[slaveOffset+1] = i2c_master_read(I2C_ACK);
// i2c_master_read(I2C_ACK);
matrix[slaveOffset+2] = i2c_master_read(I2C_NACK);
*/

// kludge for column #9: unpack bits for keys (2,9) and (3,9) from (1,7) and (1,8)
// i2c_master_read(I2C_ACK);
matrix[slaveOffset+0] = i2c_master_read(I2C_ACK);
// i2c_master_read(I2C_ACK);
matrix[slaveOffset+1] = (matrix_row_t)i2c_master_read(I2C_ACK)\
| (matrix[slaveOffset+0]&0x40U)<<2;
// i2c_master_read(I2C_ACK);
matrix[slaveOffset+2] = (matrix_row_t)i2c_master_read(I2C_NACK)\
| (matrix[slaveOffset+0]&0x80U)<<1;
// clear highest two bits on row 1, where the col9 bits were transported
matrix[slaveOffset+0] &= 0x3F;

i2c_master_stop();
} else {
Expand Down Expand Up @@ -255,7 +260,11 @@ void matrix_slave_scan(void) {
// SLAVE_BUFFER_SIZE is from i2c.h
// (MATRIX_ROWS/2*sizeof(matrix_row_t))
// memcpy((void*)i2c_slave_buffer, (const void*)&matrix[offset], (ROWS_PER_HAND*sizeof(matrix_row_t)));
i2c_slave_buffer[0] = (uint8_t)(matrix[offset+0]);

// kludge for column #9: put bits for keys (2,9) and (3,9) into (1,7) and (1,8)
i2c_slave_buffer[0] = (uint8_t)(matrix[offset+0])\
| (matrix[offset+1]&0x100U)>>2\
| (matrix[offset+2]&0x100U)>>1;
i2c_slave_buffer[1] = (uint8_t)(matrix[offset+1]);
i2c_slave_buffer[2] = (uint8_t)(matrix[offset+2]);
// note: looks like a possible operator-precedence bug here, in last version?
Expand Down

0 comments on commit e5d724d

Please sign in to comment.