|
|
@ -25,9 +25,6 @@
|
|
|
|
#include <Arduino.h>
|
|
|
|
#include <Arduino.h>
|
|
|
|
#include "Model100Side.h"
|
|
|
|
#include "Model100Side.h"
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
#include "kaleidoscope/device/keyboardio/twi.h"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "kaleidoscope/driver/color/GammaCorrection.h"
|
|
|
|
#include "kaleidoscope/driver/color/GammaCorrection.h"
|
|
|
|
|
|
|
|
|
|
|
@ -44,7 +41,7 @@ Model100Side::Model100Side(byte setAd01) {
|
|
|
|
ad01 = setAd01;
|
|
|
|
ad01 = setAd01;
|
|
|
|
addr = SCANNER_I2C_ADDR_BASE | ad01;
|
|
|
|
addr = SCANNER_I2C_ADDR_BASE | ad01;
|
|
|
|
if (twi_uninitialized--) {
|
|
|
|
if (twi_uninitialized--) {
|
|
|
|
twi_init();
|
|
|
|
// TODO twi_init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -72,7 +69,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 = twi_writeTo(addr, data, ELEMENTS(data), 1, 0);
|
|
|
|
uint8_t result ; // TODO = twi_writeTo(addr, data, ELEMENTS(data), 1, 0);
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -103,7 +100,7 @@ int Model100Side::readLEDSPIFrequency() {
|
|
|
|
// https://www.arduino.cc/en/Reference/WireEndTransmission
|
|
|
|
// https://www.arduino.cc/en/Reference/WireEndTransmission
|
|
|
|
byte Model100Side::setLEDSPIFrequency(byte frequency) {
|
|
|
|
byte Model100Side::setLEDSPIFrequency(byte frequency) {
|
|
|
|
uint8_t data[] = {TWI_CMD_LED_SPI_FREQUENCY, frequency};
|
|
|
|
uint8_t data[] = {TWI_CMD_LED_SPI_FREQUENCY, frequency};
|
|
|
|
uint8_t result = twi_writeTo(addr, data, ELEMENTS(data), 1, 0);
|
|
|
|
uint8_t result ; // TODO = twi_writeTo(addr, data, ELEMENTS(data), 1, 0);
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -115,7 +112,7 @@ int Model100Side::readRegister(uint8_t cmd) {
|
|
|
|
byte return_value = 0;
|
|
|
|
byte return_value = 0;
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t data[] = {cmd};
|
|
|
|
uint8_t data[] = {cmd};
|
|
|
|
uint8_t result = twi_writeTo(addr, data, ELEMENTS(data), 1, 0);
|
|
|
|
uint8_t result ; // TODO = twi_writeTo(addr, data, ELEMENTS(data), 1, 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -127,7 +124,7 @@ int Model100Side::readRegister(uint8_t cmd) {
|
|
|
|
uint8_t rxBuffer[1];
|
|
|
|
uint8_t rxBuffer[1];
|
|
|
|
|
|
|
|
|
|
|
|
// perform blocking read into buffer
|
|
|
|
// perform blocking read into buffer
|
|
|
|
uint8_t read = twi_readFrom(addr, rxBuffer, ELEMENTS(rxBuffer), true);
|
|
|
|
uint8_t read ; // TODO = twi_readFrom(addr, rxBuffer, ELEMENTS(rxBuffer), true);
|
|
|
|
if (read > 0) {
|
|
|
|
if (read > 0) {
|
|
|
|
return rxBuffer[0];
|
|
|
|
return rxBuffer[0];
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -143,7 +140,7 @@ bool Model100Side::readKeys() {
|
|
|
|
uint8_t rxBuffer[5];
|
|
|
|
uint8_t rxBuffer[5];
|
|
|
|
|
|
|
|
|
|
|
|
// perform blocking read into buffer
|
|
|
|
// perform blocking read into buffer
|
|
|
|
uint8_t read = twi_readFrom(addr, rxBuffer, ELEMENTS(rxBuffer), true);
|
|
|
|
uint8_t read ; // TODO = twi_readFrom(addr, rxBuffer, ELEMENTS(rxBuffer), true);
|
|
|
|
if (rxBuffer[0] == TWI_REPLY_KEYDATA) {
|
|
|
|
if (rxBuffer[0] == TWI_REPLY_KEYDATA) {
|
|
|
|
keyData.rows[0] = rxBuffer[1];
|
|
|
|
keyData.rows[0] = rxBuffer[1];
|
|
|
|
keyData.rows[1] = rxBuffer[2];
|
|
|
|
keyData.rows[1] = rxBuffer[2];
|
|
|
@ -184,7 +181,7 @@ void Model100Side::sendLEDBank(byte bank) {
|
|
|
|
|
|
|
|
|
|
|
|
data[i + 1] = pgm_read_byte(&gamma8[c]);
|
|
|
|
data[i + 1] = pgm_read_byte(&gamma8[c]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uint8_t result = twi_writeTo(addr, data, ELEMENTS(data), 1, 0);
|
|
|
|
uint8_t result ; // TODO = twi_writeTo(addr, data, ELEMENTS(data), 1, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Model100Side::setAllLEDsTo(cRGB color) {
|
|
|
|
void Model100Side::setAllLEDsTo(cRGB color) {
|
|
|
@ -193,7 +190,7 @@ void Model100Side::setAllLEDsTo(cRGB color) {
|
|
|
|
pgm_read_byte(&gamma8[color.g]),
|
|
|
|
pgm_read_byte(&gamma8[color.g]),
|
|
|
|
pgm_read_byte(&gamma8[color.r])
|
|
|
|
pgm_read_byte(&gamma8[color.r])
|
|
|
|
};
|
|
|
|
};
|
|
|
|
uint8_t result = twi_writeTo(addr, data, ELEMENTS(data), 1, 0);
|
|
|
|
uint8_t result ; // TODO = twi_writeTo(addr, data, ELEMENTS(data), 1, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Model100Side::setOneLEDTo(byte led, cRGB color) {
|
|
|
|
void Model100Side::setOneLEDTo(byte led, cRGB color) {
|
|
|
@ -203,7 +200,7 @@ void Model100Side::setOneLEDTo(byte led, cRGB color) {
|
|
|
|
pgm_read_byte(&gamma8[color.g]),
|
|
|
|
pgm_read_byte(&gamma8[color.g]),
|
|
|
|
pgm_read_byte(&gamma8[color.r])
|
|
|
|
pgm_read_byte(&gamma8[color.r])
|
|
|
|
};
|
|
|
|
};
|
|
|
|
uint8_t result = twi_writeTo(addr, data, ELEMENTS(data), 1, 0);
|
|
|
|
uint8_t result ; // TODO = twi_writeTo(addr, data, ELEMENTS(data), 1, 0);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|