f/keyboardio-model-100
Jesse Vincent 3 years ago
parent ff1cacad51
commit c6eb7529ca
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -54,12 +54,12 @@ void Model100Hands::setup(void) {
// TODO PORTE &= ~_BV(6); // TODO PORTE &= ~_BV(6);
// Turn on the switched 5V network. // Turn on the switched 5V network.
// TODO - make sure this happens at least 100ms after USB connect // TODO - make sure this happens at least 100ms after USB connect
// to satisfy inrush limits // to satisfy inrush limits
pinMode(PC13, OUTPUT_OPEN_DRAIN); pinMode(PC13, OUTPUT_OPEN_DRAIN);
digitalWrite(PC13, LOW); digitalWrite(PC13, LOW);
Wire.begin(); Wire.begin();
// Set B4, the overcurrent check to an input with an internal pull-up // Set B4, the overcurrent check to an input with an internal pull-up
// TODO DDRB &= ~_BV(4); // set bit, input // TODO DDRB &= ~_BV(4); // set bit, input
// TODO PORTB &= ~_BV(4); // set bit, enable pull-up resistor // TODO PORTB &= ~_BV(4); // set bit, enable pull-up resistor
@ -109,7 +109,7 @@ cRGB Model100LEDDriver::getCrgbAt(uint8_t i) {
void Model100LEDDriver::syncLeds() { void Model100LEDDriver::syncLeds() {
if (!isLEDChanged) if (!isLEDChanged)
return; return;
// LED Data is stored in four "banks" for each side // LED Data is stored in four "banks" for each side
// We send it all at once to make it look nicer. // We send it all at once to make it look nicer.
// We alternate left and right hands because otherwise // We alternate left and right hands because otherwise

@ -67,7 +67,7 @@ uint8_t Model100Side::controllerAddress() {
// https://www.arduino.cc/en/Reference/WireEndTransmission // https://www.arduino.cc/en/Reference/WireEndTransmission
byte Model100Side::setKeyscanInterval(byte delay) { byte Model100Side::setKeyscanInterval(byte delay) {
uint8_t data[] = {TWI_CMD_KEYSCAN_INTERVAL, delay}; uint8_t data[] = {TWI_CMD_KEYSCAN_INTERVAL, delay};
uint8_t result = writeData( data, ELEMENTS(data)); uint8_t result = writeData(data, ELEMENTS(data));
return result; return result;
} }
@ -103,9 +103,9 @@ byte Model100Side::setLEDSPIFrequency(byte frequency) {
} }
uint8_t Model100Side::writeData(uint8_t *data,uint8_t length) { uint8_t Model100Side::writeData(uint8_t *data, uint8_t length) {
Wire.beginTransmission(addr); Wire.beginTransmission(addr);
Wire.write( data, length); Wire.write(data, length);
uint8_t result = Wire.endTransmission(); uint8_t result = Wire.endTransmission();
return result; return result;
} }
@ -130,30 +130,30 @@ int Model100Side::readRegister(uint8_t cmd) {
Wire.requestFrom(addr, 1); // request 1 byte from the keyscanner Wire.requestFrom(addr, 1); // request 1 byte from the keyscanner
if (Wire.available()) { if (Wire.available()) {
return Wire.read(); return Wire.read();
} else { } else {
return -1; return -1;
} }
} }
// gives information on the key that was just pressed or released. // gives information on the key that was just pressed or released.
bool Model100Side::readKeys() { bool Model100Side::readKeys() {
uint8_t row_counter = 0; uint8_t row_counter = 0;
// perform blocking read into buffer // perform blocking read into buffer
uint8_t read = 0; uint8_t read = 0;
Wire.requestFrom(addr, 5); // request 1 byte from the keyscanner Wire.requestFrom(addr, 5); // request 1 byte from the keyscanner
if (Wire.available()) { if (Wire.available()) {
read = Wire.read(); read = Wire.read();
if (TWI_REPLY_KEYDATA == read) { if (TWI_REPLY_KEYDATA == read) {
while (Wire.available()) { while (Wire.available()) {
keyData.rows[row_counter++] = Wire.read(); keyData.rows[row_counter++] = Wire.read();
} }
return true; return true;
} }
} }
return false; return false;
} }
@ -180,9 +180,9 @@ void Model100Side::sendLEDBank(byte bank) {
* that results in a considerably smoother curve. */ * that results in a considerably smoother curve. */
uint8_t c = ledData.bytes[bank][i]; uint8_t c = ledData.bytes[bank][i];
if (c > brightness_adjustment_) if (c > brightness_adjustment_)
c -= brightness_adjustment_; c -= brightness_adjustment_;
else else
c = 0; c = 0;
data[i + 1] = c; data[i + 1] = c;
} }
@ -192,8 +192,8 @@ void Model100Side::sendLEDBank(byte bank) {
void Model100Side::setAllLEDsTo(cRGB color) { void Model100Side::setAllLEDsTo(cRGB color) {
uint8_t data[] = {TWI_CMD_LED_SET_ALL_TO, uint8_t data[] = {TWI_CMD_LED_SET_ALL_TO,
color.b, color.b,
color.g, color.g,
color.r color.r
}; };
uint8_t result = writeData(data, ELEMENTS(data)); uint8_t result = writeData(data, ELEMENTS(data));
} }
@ -202,8 +202,8 @@ void Model100Side::setOneLEDTo(byte led, cRGB color) {
uint8_t data[] = {TWI_CMD_LED_SET_ONE_TO, uint8_t data[] = {TWI_CMD_LED_SET_ONE_TO,
led, led,
color.b, color.b,
color.g, color.g,
color.r color.r
}; };
uint8_t result = writeData(data, ELEMENTS(data)); uint8_t result = writeData(data, ELEMENTS(data));

@ -82,4 +82,4 @@
#define Key_mouseBtnN XXX #define Key_mouseBtnN XXX
#endif #endif

Loading…
Cancel
Save