updated mcp23018 stuff for dox's PCB
parent
1af2423364
commit
a28b1f1182
|
@ -44,26 +44,26 @@ uint8_t mcp23018_init(void) {
|
||||||
|
|
||||||
// set pin direction
|
// set pin direction
|
||||||
// - unused : input : 1
|
// - unused : input : 1
|
||||||
// - rows : output : 0
|
// - row : input : 1
|
||||||
// - columns : input : 1
|
// - column : output : 0
|
||||||
twi_start();
|
twi_start();
|
||||||
ret = twi_send(TWI_ADDR_WRITE);
|
ret = twi_send(TWI_ADDR_WRITE);
|
||||||
if (ret) goto out; // make sure we got an ACK
|
if (ret) goto out; // make sure we got an ACK
|
||||||
twi_send(IODIRA);
|
twi_send(IODIRA);
|
||||||
twi_send(0b11000000); // IODIRA
|
twi_send(0b11111111); // IODIRA
|
||||||
twi_send(0b11111111); // IODIRB
|
twi_send(0b10000000); // IODIRB
|
||||||
twi_stop();
|
twi_stop();
|
||||||
|
|
||||||
// set pull-up
|
// set pull-up
|
||||||
// - unused : on : 1
|
// - unused : on : 1
|
||||||
// - rows : off : 0
|
// - rows : on : 1
|
||||||
// - columns : on : 1
|
// - columns : off : 0
|
||||||
twi_start();
|
twi_start();
|
||||||
ret = twi_send(TWI_ADDR_WRITE);
|
ret = twi_send(TWI_ADDR_WRITE);
|
||||||
if (ret) goto out; // make sure we got an ACK
|
if (ret) goto out; // make sure we got an ACK
|
||||||
twi_send(GPPUA);
|
twi_send(GPPUA);
|
||||||
twi_send(0b11000000); // GPPUA
|
twi_send(0b11111111); // GPPUA
|
||||||
twi_send(0b11111111); // GPPUB
|
twi_send(0b10000000); // GPPUB
|
||||||
twi_stop();
|
twi_stop();
|
||||||
|
|
||||||
// set logical value (doesn't matter on inputs)
|
// set logical value (doesn't matter on inputs)
|
||||||
|
@ -109,34 +109,34 @@ uint8_t mcp23018_update_matrix(bool matrix[KB_ROWS][KB_COLUMNS]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// update our part of the matrix
|
// update our part of the matrix
|
||||||
for (uint8_t row=0x6; row<=0xB; row++) {
|
for (uint8_t col=0; col<=6; col++) {
|
||||||
// set active row low : 0
|
// set active column low : 0
|
||||||
// set other rows high (hi-Z) : 1
|
// set other columns high (hi-Z) : 1
|
||||||
twi_start();
|
twi_start();
|
||||||
twi_send(TWI_ADDR_WRITE);
|
twi_send(TWI_ADDR_WRITE);
|
||||||
twi_send(OLATA);
|
twi_send(OLATB);
|
||||||
twi_send( 0b11111111 & ~(1<<(row-6)) );
|
twi_send( 0xFF & ~(1<<col) );
|
||||||
twi_stop();
|
twi_stop();
|
||||||
|
|
||||||
// read column data
|
// read row data
|
||||||
twi_start();
|
twi_start();
|
||||||
twi_send(TWI_ADDR_WRITE);
|
twi_send(TWI_ADDR_WRITE);
|
||||||
twi_send(GPIOB);
|
twi_send(GPIOA);
|
||||||
twi_start();
|
twi_start();
|
||||||
twi_send(TWI_ADDR_READ);
|
twi_send(TWI_ADDR_READ);
|
||||||
twi_read(&data);
|
twi_read(&data);
|
||||||
twi_stop();
|
twi_stop();
|
||||||
|
|
||||||
// update matrix
|
// update matrix
|
||||||
for (uint8_t col=0; col<=6; col++)
|
for (uint8_t row=0x6; row<=0xB; row++)
|
||||||
matrix[row][col] = !( data & (1<<col) );
|
matrix[row][col] = !( data & (1<<(row-6)) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// set all rows high (hi-Z) : 1
|
// set all columns high (hi-Z) : 1
|
||||||
twi_start();
|
twi_start();
|
||||||
twi_send(TWI_ADDR_WRITE);
|
twi_send(TWI_ADDR_WRITE);
|
||||||
twi_send(GPIOA);
|
twi_send(GPIOB);
|
||||||
twi_send(0b11111111);
|
twi_send(0xFF);
|
||||||
twi_stop();
|
twi_stop();
|
||||||
|
|
||||||
return ret; // success
|
return ret; // success
|
||||||
|
|
|
@ -80,9 +80,9 @@
|
||||||
* notes:
|
* notes:
|
||||||
* All addresses given for IOCON.BANK = 0, since that's the default value of
|
* All addresses given for IOCON.BANK = 0, since that's the default value of
|
||||||
the bit, and that's what we'll be using.
|
the bit, and that's what we'll be using.
|
||||||
* We want the row pins set as output high (hi-Z) without pull-ups
|
* We want the column pins set as output high (hi-Z) without pull-ups
|
||||||
initially, and the column pins set as input with pull-ups. We'll cycle
|
initially, and the row pins set as input with pull-ups. We'll cycle
|
||||||
through driving the row pins low and checking the column pins in the
|
through driving the column pins low and checking the row pins in the
|
||||||
update function.
|
update function.
|
||||||
|
|
||||||
* abbreviations:
|
* abbreviations:
|
||||||
|
|
Loading…
Reference in New Issue