astyle with current project style guidelines

pull/365/head
Jesse Vincent 7 years ago
parent 915e7068f6
commit 959e20b678
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -18,12 +18,12 @@ Model01::Model01(void) {
} }
void Model01::enable_scanner_power(void) { void Model01::enable_scanner_power(void) {
// PC7 // PC7
//pinMode(13, OUTPUT); //pinMode(13, OUTPUT);
//digitalWrite(13, HIGH); //digitalWrite(13, HIGH);
// Turn on power to the LED net // Turn on power to the LED net
DDRC |= _BV(7); DDRC |= _BV(7);
PORTC |= _BV(7); PORTC |= _BV(7);
} }
@ -31,174 +31,174 @@ void Model01::enable_scanner_power(void) {
// the host. That violates the USB spec. But it sure // the host. That violates the USB spec. But it sure
// is pretty looking // is pretty looking
void Model01::enable_high_power_leds(void) { void Model01::enable_high_power_leds(void) {
// PE6 // PE6
// pinMode(7, OUTPUT); // pinMode(7, OUTPUT);
// digitalWrite(7, LOW); // digitalWrite(7, LOW);
DDRE |= _BV(6); DDRE |= _BV(6);
PORTE &= ~_BV(6); PORTE &= ~_BV(6);
// 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
DDRB &= ~_BV(4); // set bit, input DDRB &= ~_BV(4); // set bit, input
PORTB &= ~_BV(4); // set bit, enable pull-up resistor PORTB &= ~_BV(4); // set bit, enable pull-up resistor
} }
void Model01::setup(void) { void Model01::setup(void) {
wdt_disable(); wdt_disable();
delay(100); delay(100);
enable_scanner_power(); enable_scanner_power();
// Consider not doing this until 30s after keyboard // Consider not doing this until 30s after keyboard
// boot up, to make it easier to rescue things // boot up, to make it easier to rescue things
// in case of power draw issues. // in case of power draw issues.
enable_high_power_leds(); enable_high_power_leds();
leftHandState.all = 0; leftHandState.all = 0;
rightHandState.all = 0; rightHandState.all = 0;
TWBR=12; // This is 400mhz, which is the fastest we can drive the ATTiny TWBR=12; // This is 400mhz, which is the fastest we can drive the ATTiny
} }
void Model01::led_set_crgb_at(uint8_t i, cRGB crgb) { void Model01::led_set_crgb_at(uint8_t i, cRGB crgb) {
if(i<32) { if (i<32) {
cRGB oldColor = led_get_crgb_at(i); cRGB oldColor = led_get_crgb_at(i);
isLEDChanged |= !(oldColor.r == crgb.r && oldColor.g == crgb.g && oldColor.b == crgb.b); isLEDChanged |= !(oldColor.r == crgb.r && oldColor.g == crgb.g && oldColor.b == crgb.b);
leftHand.ledData.leds[i] = crgb; leftHand.ledData.leds[i] = crgb;
} else if (i<64) { } else if (i<64) {
cRGB oldColor = led_get_crgb_at(i); cRGB oldColor = led_get_crgb_at(i);
isLEDChanged |= !(oldColor.r == crgb.r && oldColor.g == crgb.g && oldColor.b == crgb.b); isLEDChanged |= !(oldColor.r == crgb.r && oldColor.g == crgb.g && oldColor.b == crgb.b);
rightHand.ledData.leds[i-32] = crgb; rightHand.ledData.leds[i-32] = crgb;
} else { } else {
// TODO how do we want to handle debugging assertions about crazy user // TODO how do we want to handle debugging assertions about crazy user
// code that would overwrite other memory? // code that would overwrite other memory?
} }
} }
void Model01::led_set_crgb_at(byte row, byte col, cRGB color) { void Model01::led_set_crgb_at(byte row, byte col, cRGB color) {
led_set_crgb_at(key_led_map[row][col], color); led_set_crgb_at(key_led_map[row][col], color);
} }
uint8_t Model01::get_led_index(byte row, byte col) { uint8_t Model01::get_led_index(byte row, byte col) {
return key_led_map[row][col]; return key_led_map[row][col];
} }
cRGB Model01::led_get_crgb_at(uint8_t i) { cRGB Model01::led_get_crgb_at(uint8_t i) {
if(i<32) { if (i<32) {
return leftHand.ledData.leds[i]; return leftHand.ledData.leds[i];
} else if (i<64) { } else if (i<64) {
return rightHand.ledData.leds[i-32] ; return rightHand.ledData.leds[i-32] ;
} else { } else {
return {0, 0, 0}; return {0, 0, 0};
} }
} }
void Model01::led_sync() { void Model01::led_sync() {
if (!isLEDChanged) if (!isLEDChanged)
return; return;
leftHand.sendLEDData(); leftHand.sendLEDData();
rightHand.sendLEDData(); rightHand.sendLEDData();
leftHand.sendLEDData(); leftHand.sendLEDData();
rightHand.sendLEDData(); rightHand.sendLEDData();
leftHand.sendLEDData(); leftHand.sendLEDData();
rightHand.sendLEDData(); rightHand.sendLEDData();
leftHand.sendLEDData(); leftHand.sendLEDData();
rightHand.sendLEDData(); rightHand.sendLEDData();
isLEDChanged = false; isLEDChanged = false;
} }
boolean Model01::led_power_fault() { boolean Model01::led_power_fault() {
if (PINB & _BV(4)) { if (PINB & _BV(4)) {
return true; return true;
} else { } else {
return false; return false;
} }
} }
void debug_keyswitch_event(keydata_t state, keydata_t previousState, uint8_t keynum, uint8_t row, uint8_t col) { void debug_keyswitch_event(keydata_t state, keydata_t previousState, uint8_t keynum, uint8_t row, uint8_t col) {
if (bitRead(state.all, keynum) != bitRead(previousState.all, keynum )) { if (bitRead(state.all, keynum) != bitRead(previousState.all, keynum)) {
Serial.print("Looking at row "); Serial.print("Looking at row ");
Serial.print(row); Serial.print(row);
Serial.print(", col "); Serial.print(", col ");
Serial.print(col); Serial.print(col);
Serial.print(" key # "); Serial.print(" key # ");
Serial.print(keynum); Serial.print(keynum);
Serial.print(" "); Serial.print(" ");
Serial.print(bitRead(previousState.all, keynum)); Serial.print(bitRead(previousState.all, keynum));
Serial.print(" -> "); Serial.print(" -> ");
Serial.print(bitRead(state.all, keynum )); Serial.print(bitRead(state.all, keynum));
Serial.println(); Serial.println();
} }
} }
void Model01::read_matrix() { void Model01::read_matrix() {
//scan the Keyboard matrix looking for connections //scan the Keyboard matrix looking for connections
previousLeftHandState = leftHandState; previousLeftHandState = leftHandState;
previousRightHandState = rightHandState; previousRightHandState = rightHandState;
if (leftHand.readKeys()) { if (leftHand.readKeys()) {
leftHandState = leftHand.getKeyData(); leftHandState = leftHand.getKeyData();
} }
if (rightHand.readKeys()) { if (rightHand.readKeys()) {
rightHandState = rightHand.getKeyData(); rightHandState = rightHand.getKeyData();
} }
} }
void Model01::act_on_matrix_scan() { void Model01::act_on_matrix_scan() {
for (byte row = 0; row < 4; row++) { for (byte row = 0; row < 4; row++) {
for (byte col = 0; col < 8; col++) { for (byte col = 0; col < 8; col++) {
uint8_t keynum = (row*8)+(col); uint8_t keynum = (row*8)+(col);
uint8_t keyState = (bitRead(previousLeftHandState.all, keynum) << 0) | uint8_t keyState = (bitRead(previousLeftHandState.all, keynum) << 0) |
(bitRead(leftHandState.all, keynum) << 1); (bitRead(leftHandState.all, keynum) << 1);
handle_keyswitch_event(Key_NoKey, row, 7-col, keyState); handle_keyswitch_event(Key_NoKey, row, 7-col, keyState);
keyState = (bitRead(previousRightHandState.all, keynum) << 0) | keyState = (bitRead(previousRightHandState.all, keynum) << 0) |
(bitRead(rightHandState.all, keynum) << 1); (bitRead(rightHandState.all, keynum) << 1);
handle_keyswitch_event(Key_NoKey, row, (15- col), keyState); handle_keyswitch_event(Key_NoKey, row, (15- col), keyState);
}
} }
}
} }
void Model01::scan_matrix() { void Model01::scan_matrix() {
read_matrix(); read_matrix();
act_on_matrix_scan(); act_on_matrix_scan();
} }
void Model01::reboot_bootloader() { void Model01::reboot_bootloader() {
// Set the magic bits to get a Caterina-based device // Set the magic bits to get a Caterina-based device
// to reboot into the bootloader and stay there, rather // to reboot into the bootloader and stay there, rather
// than run move onward // than run move onward
// //
// These values are the same as those defined in // These values are the same as those defined in
// Caterina.c // Caterina.c
uint16_t bootKey = 0x7777; uint16_t bootKey = 0x7777;
uint16_t *const bootKeyPtr = (uint16_t *)0x0800; uint16_t *const bootKeyPtr = (uint16_t *)0x0800;
// Stash the magic key // Stash the magic key
*bootKeyPtr = bootKey; *bootKeyPtr = bootKey;
// Set a watchdog timer // Set a watchdog timer
wdt_enable(WDTO_120MS); wdt_enable(WDTO_120MS);
while (1) {} // This infinite loop ensures nothing else while (1) {} // This infinite loop ensures nothing else
// happens before the watchdog reboots us // happens before the watchdog reboots us
} }
HARDWARE_IMPLEMENTATION KeyboardHardware; HARDWARE_IMPLEMENTATION KeyboardHardware;

@ -11,34 +11,34 @@
#define CRGB(r,g,b) (cRGB){b, g, r} #define CRGB(r,g,b) (cRGB){b, g, r}
class Model01 { class Model01 {
public: public:
Model01(void); Model01(void);
void led_sync(void); void led_sync(void);
void led_set_crgb_at(byte row, byte col, cRGB color); void led_set_crgb_at(byte row, byte col, cRGB color);
void led_set_crgb_at(uint8_t i, cRGB crgb); void led_set_crgb_at(uint8_t i, cRGB crgb);
cRGB led_get_crgb_at(uint8_t i); cRGB led_get_crgb_at(uint8_t i);
cRGB get_key_color(byte row, byte col); cRGB get_key_color(byte row, byte col);
uint8_t get_led_index(byte row, byte col); uint8_t get_led_index(byte row, byte col);
void scan_matrix(void); void scan_matrix(void);
void read_matrix(void); void read_matrix(void);
void act_on_matrix_scan(void); void act_on_matrix_scan(void);
void setup(); void setup();
void enable_high_power_leds(void); void enable_high_power_leds(void);
void enable_scanner_power(void); void enable_scanner_power(void);
void reboot_bootloader(); void reboot_bootloader();
boolean led_power_fault(void); boolean led_power_fault(void);
keydata_t leftHandState; keydata_t leftHandState;
keydata_t rightHandState; keydata_t rightHandState;
keydata_t previousLeftHandState; keydata_t previousLeftHandState;
keydata_t previousRightHandState; keydata_t previousRightHandState;
private: private:
static bool isLEDChanged; static bool isLEDChanged;
static KeyboardioScanner leftHand; static KeyboardioScanner leftHand;
static KeyboardioScanner rightHand; static KeyboardioScanner rightHand;
}; };
#define SCANBIT(row,col) ((uint32_t)1 << (row * 8 + (7 - col))) #define SCANBIT(row,col) ((uint32_t)1 << (row * 8 + (7 - col)))

Loading…
Cancel
Save