Compare commits

...

7 Commits

Author SHA1 Message Date
Erez Zukerman
6652f5dbc4 LED test 2018-05-30 10:43:15 -04:00
Jack Humbert
682555faac i2c fix 2018-05-15 22:30:58 -04:00
Jack Humbert
6dc215cd67 Merge branch 'master' of github.com:qmk/qmk_firmware into hf/shinydox 2018-05-15 11:36:57 -04:00
Erez Zukerman
5272218ac9 Merge branch 'master' into hf/shinydox 2018-05-15 10:50:24 -04:00
Jack Humbert
0592d23b74 turn it on 2018-05-09 16:45:30 -04:00
Erez Zukerman
b5e7589bf9 disables RGB Matrix for now
just to see if that's why the board doesn't work. And it is... With this, the board works.
2018-05-09 09:53:32 -04:00
Erez Zukerman
3d00f38586 a quick attempt 2018-05-09 09:43:36 -04:00
10 changed files with 233 additions and 58 deletions

View File

@@ -13,32 +13,34 @@
void i2c_init(void)
{
TWSR = 0; /* no prescaler */
TWBR = (uint8_t)TWBR_val;
//TWBR = 10;
}
uint8_t i2c_start(uint8_t address)
{
// reset TWI control register
TWCR = 0;
// transmit START condition
//TWCR = 0;
// transmit START condition
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
// wait for end of transmission
while( !(TWCR & (1<<TWINT)) );
// check if the start condition was successfully transmitted
if((TWSR & 0xF8) != TW_START){ return 1; }
if(((TW_STATUS & 0xF8) != TW_START) && ((TW_STATUS & 0xF8) != TW_REP_START)){ return 1; }
// load slave address into data register
TWDR = address;
// start transmission of address
TWCR = (1<<TWINT) | (1<<TWEN);
// wait for end of transmission
while( !(TWCR & (1<<TWINT)) );
// check if the device has acknowledged the READ / WRITE mode
uint8_t twst = TW_STATUS & 0xF8;
if ( (twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK) ) return 1;
return 0;
}
@@ -50,17 +52,17 @@ uint8_t i2c_write(uint8_t data)
TWCR = (1<<TWINT) | (1<<TWEN);
// wait for end of transmission
while( !(TWCR & (1<<TWINT)) );
if( (TWSR & 0xF8) != TW_MT_DATA_ACK ){ return 1; }
if( (TW_STATUS & 0xF8) != TW_MT_DATA_ACK ){ return 1; }
return 0;
}
uint8_t i2c_read_ack(void)
{
// start TWI module and acknowledge data after reception
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA);
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA);
// wait for end of transmission
while( !(TWCR & (1<<TWINT)) );
// return received data from TWDR
@@ -69,7 +71,7 @@ uint8_t i2c_read_ack(void)
uint8_t i2c_read_nack(void)
{
// start receiving without acknowledging reception
TWCR = (1<<TWINT) | (1<<TWEN);
// wait for end of transmission
@@ -81,29 +83,29 @@ uint8_t i2c_read_nack(void)
uint8_t i2c_transmit(uint8_t address, uint8_t* data, uint16_t length)
{
if (i2c_start(address | I2C_WRITE)) return 1;
for (uint16_t i = 0; i < length; i++)
{
if (i2c_write(data[i])) return 1;
}
i2c_stop();
return 0;
}
uint8_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length)
{
if (i2c_start(address | I2C_READ)) return 1;
for (uint16_t i = 0; i < (length-1); i++)
{
data[i] = i2c_read_ack();
}
data[(length-1)] = i2c_read_nack();
i2c_stop();
return 0;
}
@@ -146,4 +148,6 @@ void i2c_stop(void)
{
// transmit STOP condition
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
// wait until stop condition is executed and bus released
while(TWCR & (1<<TWSTO));
}

View File

@@ -84,7 +84,8 @@ void IS31FL3731_write_register( uint8_t addr, uint8_t reg, uint8_t data )
g_twi_transfer_buffer[1] = data;
//Transmit data until succesful
while(i2c_transmit(addr << 1, g_twi_transfer_buffer,2) != 0);
//while(i2c_transmit(addr << 1, g_twi_transfer_buffer,2) != 0);
i2c_transmit(addr << 1, g_twi_transfer_buffer,2);
}
void IS31FL3731_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer )
@@ -108,7 +109,9 @@ void IS31FL3731_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer )
}
//Transmit buffer until succesful
while(i2c_transmit(addr << 1, g_twi_transfer_buffer,17) != 0);
//while(i2c_transmit(addr << 1, g_twi_transfer_buffer,17) != 0);
i2c_transmit(addr << 1, g_twi_transfer_buffer,17);
}
}

View File

@@ -102,6 +102,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define USB_MAX_POWER_CONSUMPTION 500
// RGB backlight
#define DRIVER_ADDR_1 0b1110100
#define DRIVER_ADDR_2 0b1110111
#define DRIVER_COUNT 2
#define DRIVER_1_LED_TOTAL 24
#define DRIVER_2_LED_TOTAL 24
#define DRIVER_LED_TOTAL DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL
#define RGB_MATRIX_SKIP_FRAMES 10
// #define RGBLIGHT_COLOR_LAYER_0 0x00, 0x00, 0xFF
/* #define RGBLIGHT_COLOR_LAYER_1 0x00, 0x00, 0xFF */
/* #define RGBLIGHT_COLOR_LAYER_2 0xFF, 0x00, 0x00 */

View File

@@ -1,6 +1,4 @@
#include QMK_KEYBOARD_H
#include "i2cmaster.h"
extern inline void ergodox_board_led_on(void);
extern inline void ergodox_right_led_1_on(void);
@@ -207,3 +205,130 @@ const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = {
{{0,0}, {1,0}, {2,0}, {3,0}, {4,0}, {5,0}},
};
#endif
#ifdef RGB_MATRIX_ENABLE
const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
/* driver
* | R location
* | | G location
* | | | B location
* | | | | */
{0, C3_1, C2_1, C4_1}, // LED1 on right
{0, C6_1, C5_1, C7_1}, // LED2
{0, C4_2, C3_2, C5_2}, // LED3
{0, C7_2, C6_2, C8_2}, // LED4
{0, C2_3, C1_3, C3_3}, // LED5
{0, C5_3, C4_3, C6_3}, // LED6
{0, C8_3, C7_3, C9_3}, // LED7
{0, C2_4, C1_4, C3_4}, // LED8
{0, C6_4, C5_4, C7_4}, // LED9
{0, C2_5, C1_5, C3_5}, // LED10
{0, C7_5, C6_5, C8_5}, // LED11
{0, C2_6, C1_6, C3_6}, // LED12
{0, C5_6, C4_6, C6_6}, // LED13
{0, C8_6, C7_6, C9_6}, // LED14
{0, C2_7, C1_7, C3_7}, // LED15
{0, C5_7, C4_7, C6_7}, // LED16
{0, C2_8, C1_8, C3_8}, // LED17
{0, C5_8, C4_8, C6_8}, // LED18
{0, C3_9, C2_9, C4_9}, // LED19
{0, C6_9, C5_9, C7_9}, // LED20
{0, C4_10, C3_10, C5_10}, // LED21
{0, C7_10, C6_10, C8_10}, // LED22
{0, C2_11, C1_11, C3_11}, // LED23
{0, C5_11, C4_11, C6_11}, // LED24
{1, C3_1, C2_1, C4_1}, // LED1 on left
{1, C6_1, C5_1, C7_1}, // LED2
{1, C4_2, C3_2, C5_2}, // LED3
{1, C7_2, C6_2, C8_2}, // LED4
{1, C2_3, C1_3, C3_3}, // LED5
{1, C5_3, C4_3, C6_3}, // LED6
{1, C8_3, C7_3, C9_3}, // LED7
{1, C2_4, C1_4, C3_4}, // LED8
{1, C6_4, C5_4, C7_4}, // LED9
{1, C2_5, C1_5, C3_5}, // LED10
{1, C7_5, C6_5, C8_5}, // LED11
{1, C2_6, C1_6, C3_6}, // LED12
{1, C5_6, C4_6, C6_6}, // LED13
{1, C8_6, C7_6, C9_6}, // LED14
{1, C2_7, C1_7, C3_7}, // LED15
{1, C5_7, C4_7, C6_7}, // LED16
{1, C2_8, C1_8, C3_8}, // LED17
{1, C5_8, C4_8, C6_8}, // LED18
{1, C3_9, C2_9, C4_9}, // LED19
{1, C6_9, C5_9, C7_9}, // LED20
{1, C4_10, C3_10, C5_10}, // LED21
{1, C7_10, C6_10, C8_10}, // LED22
{1, C2_11, C1_11, C3_11}, // LED23
{1, C5_11, C4_11, C6_11} // LED24
};
const rgb_led g_rgb_leds[DRIVER_LED_TOTAL] = {
/*{row | col << 4}
| {x=0..224, y=0..64}
| | modifier
| | | */
{{0|(0<<4)}, {24.9*5, 16*0}, 0}, // LED 1 on right
{{0|(1<<4)}, {24.9*6, 16*0}, 0}, // LED 2
{{0|(2<<4)}, {24.9*7, 16*0}, 0}, // LED 3
{{0|(3<<4)}, {24.9*8, 16*0}, 0}, // LED 4
{{0|(4<<4)}, {24.9*9, 16*0}, 0}, // LED 5
{{1|(5<<4)}, {24.9*5, 16*1}, 0}, // LED 6
{{1|(6<<4)}, {24.9*6, 16*1}, 0}, // LED 7
{{1|(7<<4)}, {24.9*7, 16*1}, 0}, // LED 8
{{1|(8<<4)}, {24.9*8, 16*1}, 0}, // LED 9
{{1|(9<<4)}, {24.9*9, 16*1}, 0}, // LED 10
{{2|(5<<4)}, {24.9*5, 16*2}, 0}, // LED 11
{{2|(6<<4)}, {24.9*6, 16*2}, 0}, // LED 12
{{2|(7<<4)}, {24.9*7, 16*2}, 0}, // LED 13
{{2|(8<<4)}, {24.9*8, 16*2}, 0}, // LED 14
{{2|(9<<4)}, {24.9*9, 16*2}, 0}, // LED 15
{{3|(5<<4)}, {24.9*5, 16*2}, 0}, // LED 16
{{3|(6<<4)}, {24.9*6, 16*2}, 0}, // LED 17
{{3|(7<<4)}, {24.9*7, 16*2}, 0}, // LED 18
{{3|(8<<4)}, {24.9*8, 16*2}, 0}, // LED 19
{{3|(9<<4)}, {24.9*9, 16*2}, 0}, // LED 20
{{4|(6<<4)}, {24.9*6, 16*2}, 0}, // LED 21
{{4|(7<<4)}, {24.9*7, 16*2}, 0}, // LED 22
{{4|(8<<4)}, {24.9*8, 16*2}, 0}, // LED 23
{{4|(9<<4)}, {24.9*9, 16*2}, 0}, // LED 24
{{0|(0<<4)}, {24.9*4, 16*0}, 0}, // LED 1 on left
{{0|(1<<4)}, {24.9*3, 16*0}, 0}, // LED 2
{{0|(2<<4)}, {24.9*2, 16*0}, 0}, // LED 3
{{0|(3<<4)}, {24.9*1, 16*0}, 0}, // LED 4
{{0|(4<<4)}, {24.9*0, 16*0}, 0}, // LED 5
{{1|(5<<4)}, {24.9*4, 16*1}, 0}, // LED 6
{{1|(6<<4)}, {24.9*3, 16*1}, 0}, // LED 7
{{1|(7<<4)}, {24.9*2, 16*1}, 0}, // LED 8
{{1|(8<<4)}, {24.9*1, 16*1}, 0}, // LED 9
{{1|(9<<4)}, {24.9*0, 16*1}, 0}, // LED 10
{{2|(5<<4)}, {24.9*4, 16*2}, 0}, // LED 11
{{2|(6<<4)}, {24.9*3, 16*2}, 0}, // LED 12
{{2|(7<<4)}, {24.9*2, 16*2}, 0}, // LED 13
{{2|(8<<4)}, {24.9*1, 16*2}, 0}, // LED 14
{{2|(9<<4)}, {24.9*0, 16*2}, 0}, // LED 15
{{3|(5<<4)}, {24.9*4, 16*2}, 0}, // LED 16
{{3|(6<<4)}, {24.9*3, 16*2}, 0}, // LED 17
{{3|(7<<4)}, {24.9*2, 16*2}, 0}, // LED 18
{{3|(8<<4)}, {24.9*1, 16*2}, 0}, // LED 19
{{3|(9<<4)}, {24.9*0, 16*2}, 0}, // LED 20
{{4|(6<<4)}, {24.9*3, 16*2}, 0}, // LED 21
{{4|(7<<4)}, {24.9*2, 16*2}, 0}, // LED 22
{{4|(8<<4)}, {24.9*1, 16*2}, 0}, // LED 23
{{4|(9<<4)}, {24.9*0, 16*2}, 0}, // LED 24
};
#endif

View File

@@ -4,7 +4,7 @@
#include "quantum.h"
#include <stdint.h>
#include <stdbool.h>
#include "i2cmaster.h"
#include "i2c_master.h"
#include <util/delay.h>
#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))

View File

@@ -11,7 +11,10 @@ enum custom_keycodes {
PLACEHOLDER = SAFE_RANGE, // can always be here
EPRM,
VRSN,
RGB_SLD
RGB_SLD,
RED,
GRN,
BLU
};
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
@@ -49,9 +52,9 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_HOME,
KC_SPC,KC_BSPC,KC_END,
// right hand
KC_RGHT, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS,
TG(SYMB), KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSLS,
KC_H, KC_J, KC_K, KC_L, LT(MDIA, KC_SCLN),GUI_T(KC_QUOT),
KC_RGHT, KC_6, KC_7, KC_8, KC_9, KC_0, RED,
TG(SYMB), KC_Y, KC_U, KC_I, KC_O, KC_P, GRN,
KC_H, KC_J, KC_K, KC_L, LT(MDIA, KC_SCLN),BLU,
MEH_T(KC_NO),KC_N, KC_M, KC_COMM,KC_DOT, CTL_T(KC_SLSH), KC_RSFT,
KC_UP, KC_DOWN,KC_LBRC,KC_RBRC, KC_FN1,
KC_LALT, CTL_T(KC_ESC),
@@ -168,6 +171,24 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
// dynamically generate these.
case RED:
if (record->event.pressed) {
rgb_matrix_set_color_all(255, 0, 0);
}
return false;
break;
case GRN:
if (record->event.pressed) {
rgb_matrix_set_color_all(0, 255, 0);
}
return false;
break;
case BLU:
if (record->event.pressed) {
rgb_matrix_set_color_all(0, 0, 255);
}
return false;
break;
case EPRM:
if (record->event.pressed) {
eeconfig_init();

View File

@@ -34,7 +34,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "util.h"
#include "matrix.h"
#include QMK_KEYBOARD_H
#include "i2cmaster.h"
#ifdef DEBUG_MATRIX_SCAN_RATE
#include "timer.h"
#endif
@@ -297,7 +296,7 @@ static matrix_row_t read_cols(uint8_t row)
mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out;
mcp23018_status = i2c_write(GPIOB); if (mcp23018_status) goto out;
mcp23018_status = i2c_start(I2C_ADDR_READ); if (mcp23018_status) goto out;
data = i2c_readNak();
data = i2c_read_nack();
data = ~data;
out:
i2c_stop();

View File

@@ -15,8 +15,8 @@
#----------------------------------------------------------------------------
# # project specific files
SRC = twimaster.c \
matrix.c
SRC = matrix.c \
i2c_master.c
# MCU name
MCU = atmega32u4
@@ -82,6 +82,7 @@ UNICODE_ENABLE = yes # Unicode
SWAP_HANDS_ENABLE= yes # Allow swapping hands of keyboard
SLEEP_LED_ENABLE = no
API_SYSEX_ENABLE = no
RGBLIGHT_ENABLE = yes
RGBLIGHT_ENABLE = no
RGB_MATRIX_ENABLE = yes
LAYOUTS = ergodox

View File

@@ -150,26 +150,27 @@ void rgb_matrix_set_suspend_state(bool state) {
void rgb_matrix_test(void) {
// Mask out bits 4 and 5
// This 2-bit value will stay the same for 16 ticks.
switch ( (g_tick & 0x30) >> 4 )
uint32_t factor = 10;
switch ( (g_tick & (0b11 << factor)) >> factor )
{
case 0:
{
rgb_matrix_set_color_all( 20, 0, 0 );
rgb_matrix_set_color_all( 255, 0, 0 );
break;
}
case 1:
{
rgb_matrix_set_color_all( 0, 20, 0 );
rgb_matrix_set_color_all( 0, 255, 0 );
break;
}
case 2:
{
rgb_matrix_set_color_all( 0, 0, 20 );
rgb_matrix_set_color_all( 0, 0, 255 );
break;
}
case 3:
{
rgb_matrix_set_color_all( 20, 20, 20 );
rgb_matrix_set_color_all( 255, 255, 255 );
break;
}
}
@@ -217,7 +218,7 @@ void rgb_matrix_single_LED_test(void) {
}
// All LEDs off
void rgb_matrix_all_off(void) {
void rgb_matrix_all_off(void) {
rgb_matrix_set_color_all( 0, 0, 0 );
}
@@ -243,7 +244,7 @@ void rgb_matrix_solid_reactive(void) {
// alphas = color1, mods = color2
void rgb_matrix_alphas_mods(void) {
RGB rgb1 = hsv_to_rgb( (HSV){ .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val } );
RGB rgb2 = hsv_to_rgb( (HSV){ .h = (rgb_matrix_config.hue + 180) % 360, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val } );
@@ -577,10 +578,10 @@ void rgb_matrix_custom(void) {
}
void rgb_matrix_task(void) {
static uint8_t toggle_enable_last = 255;
// static uint8_t toggle_enable_last = 255;
if (!rgb_matrix_config.enable) {
rgb_matrix_all_off();
toggle_enable_last = rgb_matrix_config.enable;
// toggle_enable_last = rgb_matrix_config.enable;
return;
}
// delay 1 second before driving LEDs or doing anything else
@@ -619,50 +620,61 @@ void rgb_matrix_task(void) {
// Keep track of the effect used last time,
// detect change in effect, so each effect can
// have an optional initialization.
static uint8_t effect_last = 255;
bool initialize = (effect != effect_last) || (rgb_matrix_config.enable != toggle_enable_last);
effect_last = effect;
toggle_enable_last = rgb_matrix_config.enable;
// static uint8_t effect_last = 255;
// bool initialize = (effect != effect_last) || (rgb_matrix_config.enable != toggle_enable_last);
// effect_last = effect;
// toggle_enable_last = rgb_matrix_config.enable;
// this gets ticked at 20 Hz.
// each effect can opt to do calculations
// and/or request PWM buffer updates.
switch ( effect ) {
case RGB_MATRIX_SOLID_COLOR:
rgb_matrix_solid_color();
rgb_matrix_test();
break;
case RGB_MATRIX_ALPHAS_MODS:
rgb_matrix_alphas_mods();
rgb_matrix_test();
// rgb_matrix_alphas_mods();
break;
case RGB_MATRIX_DUAL_BEACON:
rgb_matrix_dual_beacon();
rgb_matrix_test();
// rgb_matrix_dual_beacon();
break;
case RGB_MATRIX_GRADIENT_UP_DOWN:
rgb_matrix_gradient_up_down();
rgb_matrix_test();
// rgb_matrix_gradient_up_down();
break;
case RGB_MATRIX_RAINDROPS:
rgb_matrix_raindrops( initialize );
rgb_matrix_test();
// rgb_matrix_raindrops( initialize );
break;
case RGB_MATRIX_CYCLE_ALL:
rgb_matrix_cycle_all();
rgb_matrix_test();
// rgb_matrix_cycle_all();
break;
case RGB_MATRIX_CYCLE_LEFT_RIGHT:
rgb_matrix_cycle_left_right();
rgb_matrix_test();
// rgb_matrix_cycle_left_right();
break;
case RGB_MATRIX_CYCLE_UP_DOWN:
rgb_matrix_cycle_up_down();
rgb_matrix_test();
// rgb_matrix_cycle_up_down();
break;
case RGB_MATRIX_RAINBOW_BEACON:
rgb_matrix_rainbow_beacon();
rgb_matrix_test();
// rgb_matrix_rainbow_beacon();
break;
case RGB_MATRIX_RAINBOW_PINWHEELS:
rgb_matrix_rainbow_pinwheels();
rgb_matrix_test();
// rgb_matrix_rainbow_pinwheels();
break;
case RGB_MATRIX_RAINBOW_MOVING_CHEVRON:
rgb_matrix_rainbow_moving_chevron();
rgb_matrix_test();
// rgb_matrix_rainbow_moving_chevron();
break;
case RGB_MATRIX_JELLYBEAN_RAINDROPS:
rgb_matrix_jellybean_raindrops( initialize );
rgb_matrix_test();
// rgb_matrix_jellybean_raindrops( initialize );
break;
#ifdef RGB_MATRIX_KEYPRESSES
case RGB_MATRIX_SOLID_REACTIVE:

View File

@@ -86,6 +86,7 @@ enum rgb_matrix_effects {
};
void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue );
void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue );
// This runs after another backlight effect and replaces
// colors already set