Start to implement i2c support

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

@ -24,7 +24,8 @@
#include <Arduino.h> #include <Arduino.h>
#include "Model100Side.h" #include "Model100Side.h"
#include <Wire.h>
#include <utility/twi.h>
#include "kaleidoscope/driver/color/GammaCorrection.h" #include "kaleidoscope/driver/color/GammaCorrection.h"
@ -69,8 +70,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 ; // TODO = twi_writeTo(addr, data, ELEMENTS(data), 1, 0); uint8_t result = writeData( data, ELEMENTS(data));
return result; return result;
} }
@ -100,19 +100,25 @@ 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 ; // TODO = twi_writeTo(addr, data, ELEMENTS(data), 1, 0); uint8_t result = writeData(data, ELEMENTS(data));
return result; return result;
} }
uint8_t Model100Side::writeData(uint8_t *data,uint8_t length) {
Wire.beginTransmission(addr);
Wire.write( data, length);
uint8_t result = Wire.endTransmission();
return result;
}
int Model100Side::readRegister(uint8_t cmd) { 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 ; // TODO = twi_writeTo(addr, data, ELEMENTS(data), 1, 0); uint8_t result = writeData(data, ELEMENTS(data));
@ -121,7 +127,7 @@ int Model100Side::readRegister(uint8_t cmd) {
// sized pull-ups on both the left and right // sized pull-ups on both the left and right
// hands' i2c SDA and SCL lines // hands' i2c SDA and SCL lines
uint8_t rxBuffer[1]; uint8_t rxBuffer[1] = {0};
// perform blocking read into buffer // perform blocking read into buffer
uint8_t read ; // TODO = twi_readFrom(addr, rxBuffer, ELEMENTS(rxBuffer), true); uint8_t read ; // TODO = twi_readFrom(addr, rxBuffer, ELEMENTS(rxBuffer), true);
@ -137,7 +143,7 @@ int Model100Side::readRegister(uint8_t cmd) {
// 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 rxBuffer[5]; uint8_t rxBuffer[5] = {0};
// perform blocking read into buffer // perform blocking read into buffer
uint8_t read ; // TODO = twi_readFrom(addr, rxBuffer, ELEMENTS(rxBuffer), true); uint8_t read ; // TODO = twi_readFrom(addr, rxBuffer, ELEMENTS(rxBuffer), true);
@ -181,7 +187,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 ; // TODO = twi_writeTo(addr, data, ELEMENTS(data), 1, 0); uint8_t result = writeData(data, ELEMENTS(data));
} }
void Model100Side::setAllLEDsTo(cRGB color) { void Model100Side::setAllLEDsTo(cRGB color) {
@ -190,7 +196,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 ; // TODO = twi_writeTo(addr, data, ELEMENTS(data), 1, 0); uint8_t result = writeData(data, ELEMENTS(data));
} }
void Model100Side::setOneLEDTo(byte led, cRGB color) { void Model100Side::setOneLEDTo(byte led, cRGB color) {
@ -200,7 +206,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 ; // TODO = twi_writeTo(addr, data, ELEMENTS(data), 1, 0); uint8_t result = writeData(data, ELEMENTS(data));
} }

@ -96,6 +96,7 @@ class Model100Side {
byte nextLEDBank = 0; byte nextLEDBank = 0;
void sendLEDBank(byte bank); void sendLEDBank(byte bank);
int readRegister(uint8_t cmd); int readRegister(uint8_t cmd);
uint8_t writeData(uint8_t* data, uint8_t length);
}; };
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
class Model100Side; class Model100Side;

Loading…
Cancel
Save