qmk

QMK Firmware
git clone git://git.z3bra.org/qmk.git
Log | Files | Refs | Submodules | LICENSE

v1.c (13089B)


      1 /* Copyright 2018 Yiancar
      2  *
      3  * This program is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published by
      5  * the Free Software Foundation, either version 2 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * This program is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11  * GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License
     14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15  */
     16 #include "v1.h"
     17 
     18 // Please ignore this is for upcoming features
     19 /*#ifdef RAW_ENABLE
     20 
     21 void raw_hid_receive( uint8_t *data, uint8_t length )
     22 {
     23 	uint8_t command = data[0];
     24 	switch ( command )
     25 	{
     26 		case id_protocol_version:
     27 		{
     28 			msg_protocol_version *msg = (msg_protocol_version*)&data[1];
     29 			msg->version = PROTOCOL_VERSION;
     30 			break;
     31 		}
     32 #if USE_KEYMAPS_IN_EEPROM
     33 		case id_keymap_keycode_load:
     34 		{
     35 			msg_keymap_keycode_load *msg = (msg_keymap_keycode_load*)&data[1];
     36 			msg->keycode = keymap_keycode_load( msg->layer, msg->row, msg->column );
     37 			break;
     38 		}
     39 		case id_keymap_keycode_save:
     40 		{
     41 			msg_keymap_keycode_save *msg = (msg_keymap_keycode_save*)&data[1];
     42 			keymap_keycode_save( msg->layer, msg->row, msg->column, msg->keycode);
     43 			break;
     44 		}
     45 		case id_keymap_default_save:
     46 		{
     47 			keymap_default_save();
     48 			break;
     49 		}
     50 #endif // USE_KEYMAPS_IN_EEPROM
     51 		case id_backlight_config_set_values:
     52 		{
     53 			msg_backlight_config_set_values *msg = (msg_backlight_config_set_values*)&data[1];
     54 			backlight_config_set_values(msg);
     55 			backlight_config_save();
     56 			break;
     57 		}
     58 		case id_backlight_config_set_alphas_mods:
     59 		{
     60 			msg_backlight_config_set_alphas_mods *msg = (msg_backlight_config_set_alphas_mods*)&data[1];
     61 			backlight_config_set_alphas_mods( msg->alphas_mods );
     62 			backlight_config_save();
     63 			break;
     64 		}
     65 		case id_backlight_set_key_color:
     66 		{
     67 			msg_backlight_set_key_color *msg = (msg_backlight_set_key_color*)&data[1];
     68 			backlight_set_key_color(msg->row, msg->column, msg->hsv);
     69 			break;
     70 		}
     71 		case id_system_get_state:
     72 		{
     73 			msg_system_state *msg = (msg_system_state*)&data[1];
     74 			msg->value = backlight_get_tick();
     75 			break;
     76 		}
     77 		default:
     78 		{
     79 			// Unhandled message.
     80 			data[0] = id_unhandled;
     81 			break;
     82 		}
     83 	}
     84 
     85 	// Return same buffer with values changed
     86 	raw_hid_send( data, length );
     87 
     88 }
     89 
     90 #endif*/
     91 
     92 #ifdef HS60_ANSI
     93 
     94 const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
     95 /* Refer to IS31 manual for these locations
     96  *   driver
     97  *   |  R location
     98  *   |  |      G location
     99  *   |  |      |      B location
    100  *   |  |      |      | */
    101     {0, C1_1,   C3_2,   C4_2}, //A1
    102     {0, C1_2,   C2_2,   C4_3}, //A2
    103     {0, C1_3,   C2_3,   C3_3}, //A3
    104     {0, C1_4,   C2_4,   C3_4}, //A4
    105     {0, C1_5,   C2_5,   C3_5}, //A5
    106     {0, C1_6,   C2_6,   C3_6}, //A6
    107     {0, C1_7,   C2_7,   C3_7}, //A7
    108     {0, C1_8,   C2_8,   C3_8}, //A8
    109     {0, C9_1,   C8_1,   C7_1}, //A9
    110     {0, C9_2,   C8_2,   C7_2}, //A10
    111     {0, C9_3,   C8_3,   C7_3}, //A11
    112     {0, C9_4,   C8_4,   C7_4}, //A12
    113     {0, C9_5,   C8_5,   C7_5}, //A13
    114     {0, C9_6,   C8_6,   C7_6}, //A14
    115     {0, C9_7,   C8_7,   C6_6}, //A15
    116     {0, C9_8,   C7_7,   C6_7}, //A16
    117 
    118     {0, C1_9,   C3_10,  C4_10}, //B1
    119     {0, C1_10,  C2_10,  C4_11}, //B2
    120     {0, C1_11,  C2_11,  C3_11}, //B3
    121     {0, C1_12,  C2_12,  C3_12}, //B4
    122     {0, C1_13,  C2_13,  C3_13}, //B5
    123     {0, C1_14,  C2_14,  C3_14}, //B6
    124     {0, C1_15,  C2_15,  C3_15}, //B7
    125     {0, C1_16,  C2_16,  C3_16}, //B8
    126     {0, C9_9,   C8_9,   C7_9},  //B9
    127     {0, C9_10,  C8_10,  C7_10}, //B10
    128     {0, C9_11,  C8_11,  C7_11}, //B11
    129     {0, C9_12,  C8_12,  C7_12}, //B12
    130     {0, C9_13,  C8_13,  C7_13}, //B13
    131     {0, C9_14,  C8_14,  C7_14}, //B14
    132 
    133     {1, C1_1,   C3_2,   C4_2}, //C1
    134     {1, C1_2,   C2_2,   C4_3}, //C2
    135     {1, C1_3,   C2_3,   C3_3}, //C3
    136     {1, C1_4,   C2_4,   C3_4}, //C4
    137     {1, C1_5,   C2_5,   C3_5}, //C5
    138     {1, C1_6,   C2_6,   C3_6}, //C6
    139     {1, C1_7,   C2_7,   C3_7}, //C7
    140     {1, C1_8,   C2_8,   C3_8}, //C8
    141     {1, C9_1,   C8_1,   C7_1}, //C9
    142     {1, C9_2,   C8_2,   C7_2}, //C10
    143     {1, C9_3,   C8_3,   C7_3}, //C11
    144     {1, C9_4,   C8_4,   C7_4}, //C12
    145     {1, C9_5,   C8_5,   C7_5}, //C13
    146     {1, C9_6,   C8_6,   C7_6}, //C14
    147     {1, C9_7,   C8_7,   C6_6}, //C15
    148     {1, C9_8,   C7_7,   C6_7}, //C16
    149 
    150     {1, C1_9,   C3_10,  C4_10}, //D1
    151     //D2
    152     {1, C1_11,  C2_11,  C3_11}, //D3
    153     {1, C1_12,  C2_12,  C3_12}, //D4
    154     {1, C1_13,  C2_13,  C3_13}, //D5
    155     {1, C1_14,  C2_14,  C3_14}, //D6
    156     {1, C1_15,  C2_15,  C3_15}, //D7
    157     {1, C1_16,  C2_16,  C3_16}, //D8
    158     {1, C9_9,   C8_9,   C7_9},  //D9
    159     {1, C9_10,  C8_10,  C7_10}, //D10
    160     {1, C9_11,  C8_11,  C7_11}, //D11
    161     {1, C9_12,  C8_12,  C7_12}, //D12
    162     {1, C9_13,  C8_13,  C7_13}, //D13
    163     {1, C9_14,  C8_14,  C7_14}, //D14
    164     {1, C9_15,  C8_15,  C6_14}, //D15
    165     {1, C9_16,  C7_15,  C6_15}  //D16
    166 };
    167 
    168 led_config_t g_led_config = { {
    169     {  36,  35,  34,  33,  32,  31,  30,   6,   5,   4,   3,   2,   1,   0 },
    170     {  37,  38,  39,  40,  41,  42,  43,   7,   8,   9,  10,  11,  12, NO_LED },
    171     {  48,  49,  50,  51,  52,  45,  44,  20,  21,  22,  23,  15,  14,  13 },
    172     {  47, NO_LED,  46,  53,  54,  55,  56,  19,  18,  17,  16,  24, NO_LED,  25 },
    173     {  60,  59,  58,  57, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED,  29,  28,  27,  26 }
    174 }, {
    175 	//A1-A16
    176     { 224,   0 }, { 204,   0 }, { 187,   0 }, { 170,   0 }, { 153,   0 }, { 136,   0 }, { 119,   0 }, { 119,  16 }, { 136,  16 }, { 153,  16 }, { 170,  16 }, { 187,  16 }, { 204,  16 }, { 224,  32 },
    177     { 224,  16 }, { 197,  32 },
    178 	//B1-B14
    179     { 170,  48 }, { 153,  48 }, { 136,  48 }, { 119,  48 }, { 119,  32 }, { 136,  32 }, { 153,  32 }, { 170,  32 }, { 187,  48 }, { 214,  48 }, { 224,  64 }, { 204,  64 }, { 187,  64 }, { 170,  64 },
    180 	//C1-C16
    181     { 102,   0 }, {  85,   0 }, {  68,   0 }, {  51,   0 }, {  34,   0 }, {  17,   0 }, {   0,   0 }, {   0,  16 }, {  17,  16 }, {  34,  16 }, {  51,  16 }, {  68,  16 }, {  85,  16 }, { 102,  16 },
    182     { 102,  32 }, {  85,  32 },
    183 	//D1-D16
    184     {  32,  48 }, {  10,  48 }, {   0,  32 }, {  17,  32 }, {  34,  32 }, {  51,  32 }, {  68,  32 }, {  51,  48 }, {  68,  48 }, {  85,  48 }, { 102,  48 }, { 102,  64 }, {  34,  68 }, {  17,  68 },
    185     {   0,  68 }
    186 }, {
    187 	//A1-A16
    188     1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1,
    189     4, 4,
    190 	//B1-B14
    191     4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1,
    192 	//C1-C16
    193     4, 4, 4, 4, 4, 4, 1, 1, 4, 4, 4, 4, 4, 4,
    194     4, 4,
    195 	//D1-D16
    196     4, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1,
    197     1
    198 } };
    199 
    200 #else
    201 
    202 const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
    203 /* Refer to IS31 manual for these locations
    204  *   driver
    205  *   |  R location
    206  *   |  |      G location
    207  *   |  |      |      B location
    208  *   |  |      |      | */
    209     {0, C1_1,   C3_2,   C4_2}, //A1
    210     {0, C1_2,   C2_2,   C4_3}, //A2
    211     {0, C1_3,   C2_3,   C3_3}, //A3
    212     {0, C1_4,   C2_4,   C3_4}, //A4
    213     {0, C1_5,   C2_5,   C3_5}, //A5
    214     {0, C1_6,   C2_6,   C3_6}, //A6
    215     {0, C1_7,   C2_7,   C3_7}, //A7
    216     {0, C1_8,   C2_8,   C3_8}, //A8
    217     {0, C9_1,   C8_1,   C7_1}, //A9
    218     {0, C9_2,   C8_2,   C7_2}, //A10
    219     {0, C9_3,   C8_3,   C7_3}, //A11
    220     {0, C9_4,   C8_4,   C7_4}, //A12
    221     {0, C9_5,   C8_5,   C7_5}, //A13
    222     {0, C9_6,   C8_6,   C7_6}, //A14
    223     {0, C9_7,   C8_7,   C6_6}, //A15
    224     {0, C9_8,   C7_7,   C6_7}, //A16
    225 
    226     {0, C1_9,   C3_10,  C4_10}, //B1
    227     {0, C1_10,  C2_10,  C4_11}, //B2
    228     {0, C1_11,  C2_11,  C3_11}, //B3
    229     {0, C1_12,  C2_12,  C3_12}, //B4
    230     {0, C1_13,  C2_13,  C3_13}, //B5
    231     {0, C1_14,  C2_14,  C3_14}, //B6
    232     {0, C1_15,  C2_15,  C3_15}, //B7
    233     {0, C1_16,  C2_16,  C3_16}, //B8
    234     {0, C9_9,   C8_9,   C7_9},  //B9
    235     {0, C9_10,  C8_10,  C7_10}, //B10
    236     {0, C9_11,  C8_11,  C7_11}, //B11
    237     {0, C9_12,  C8_12,  C7_12}, //B12
    238     {0, C9_13,  C8_13,  C7_13}, //B13
    239     {0, C9_14,  C8_14,  C7_14}, //B14
    240 
    241     {1, C1_1,   C3_2,   C4_2}, //C1
    242     {1, C1_2,   C2_2,   C4_3}, //C2
    243     {1, C1_3,   C2_3,   C3_3}, //C3
    244     {1, C1_4,   C2_4,   C3_4}, //C4
    245     {1, C1_5,   C2_5,   C3_5}, //C5
    246     {1, C1_6,   C2_6,   C3_6}, //C6
    247     {1, C1_7,   C2_7,   C3_7}, //C7
    248     {1, C1_8,   C2_8,   C3_8}, //C8
    249     {1, C9_1,   C8_1,   C7_1}, //C9
    250     {1, C9_2,   C8_2,   C7_2}, //C10
    251     {1, C9_3,   C8_3,   C7_3}, //C11
    252     {1, C9_4,   C8_4,   C7_4}, //C12
    253     {1, C9_5,   C8_5,   C7_5}, //C13
    254     {1, C9_6,   C8_6,   C7_6}, //C14
    255     {1, C9_7,   C8_7,   C6_6}, //C15
    256     {1, C9_8,   C7_7,   C6_7}, //C16
    257 
    258     {1, C1_9,   C3_10,  C4_10}, //D1
    259     {1, C1_10,  C2_10,  C4_11}, //D2
    260     {1, C1_11,  C2_11,  C3_11}, //D3
    261     {1, C1_12,  C2_12,  C3_12}, //D4
    262     {1, C1_13,  C2_13,  C3_13}, //D5
    263     {1, C1_14,  C2_14,  C3_14}, //D6
    264     {1, C1_15,  C2_15,  C3_15}, //D7
    265     {1, C1_16,  C2_16,  C3_16}, //D8
    266     {1, C9_9,   C8_9,   C7_9},  //D9
    267     {1, C9_10,  C8_10,  C7_10}, //D10
    268     {1, C9_11,  C8_11,  C7_11}, //D11
    269     {1, C9_12,  C8_12,  C7_12}, //D12
    270     {1, C9_13,  C8_13,  C7_13}, //D13
    271     {1, C9_14,  C8_14,  C7_14}, //D14
    272     {1, C9_15,  C8_15,  C6_14}, //D15
    273     {1, C9_16,  C7_15,  C6_15}  //D16
    274 };
    275 
    276 led_config_t g_led_config = { {
    277     {  36,  35,  34,  33,  32,  31,  30,   6,   5,   4,   3,   2,   1,   0 },
    278     {  37,  38,  39,  40,  41,  42,  43,   7,   8,   9,  10,  11,  12, NO_LED },
    279     {  49,  50,  51,  52,  53,  45,  44,  20,  21,  22,  23,  15,  14,  13 },
    280     {  48,  47,  46,  54,  55,  56,  57,  19,  18,  17,  16,  24, NO_LED,  25 },
    281     {  61,  60,  59,  58, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED,  29,  28,  27,  26 }
    282 }, {
    283 	//A1-A16
    284     { 224,   0 }, { 204,   0 }, { 187,   0 }, { 170,   0 }, { 153,   0 }, { 136,   0 }, { 119,   0 }, { 119,  16 }, { 136,  16 }, { 153,  16 }, { 170,  16 }, { 187,  16 }, { 204,  16 }, { 224,   8 },
    285     { 204,  32 }, { 187,  32 },
    286 	//B1-B14
    287     { 170,  48 }, { 153,  48 }, { 136,  48 }, { 119,  48 }, { 119,  32 }, { 136,  32 }, { 153,  32 }, { 170,  32 }, { 187,  48 }, { 214,  48 }, { 224,  64 }, { 204,  64 }, { 187,  64 }, { 170,  64 },
    288 	//C1-C16
    289     { 102,   0 }, {  85,   0 }, {  68,   0 }, {  51,   0 }, {  34,   0 }, {  17,   0 }, {   0,   0 }, {   0,  16 }, {  17,  16 }, {  34,  16 }, {  51,  16 }, {  68,  16 }, {  85,  16 }, { 102,  16 },
    290     { 102,  32 }, {  85,  32 },
    291 	//D1-D16
    292     {  32,  48 }, {  17,  48 }, {   0,  48 }, {   0,  32 }, {  17,  32 }, {  34,  32 }, {  51,  32 }, {  68,  32 }, {  51,  48 }, {  68,  48 }, {  85,  48 }, { 102,  48 }, { 102,  64 }, {  34,  68 },
    293     {  17,  68 }, {   0,  68 }
    294 }, {
    295 	//A1-A16
    296     1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1,
    297     4, 4,
    298 	//B1-B14
    299     4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1,
    300 	//C1-C16
    301     4, 4, 4, 4, 4, 4, 1, 1, 4, 4, 4, 4, 4, 4,
    302     4, 4,
    303 	//D1-D16
    304     4, 4, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1,
    305     1, 1
    306 } };
    307 
    308 #endif
    309 
    310 void bootmagic_lite(void)
    311 {
    312 	// The lite version of TMK's bootmagic made by Wilba.
    313 	// 100% less potential for accidentally making the
    314 	// keyboard do stupid things.
    315 
    316 	// We need multiple scans because debouncing can't be turned off.
    317 	matrix_scan();
    318 	wait_ms(DEBOUNCE);
    319 	matrix_scan();
    320 
    321 	// If the Esc and space bar are held down on power up,
    322 	// reset the EEPROM valid state and jump to bootloader.
    323 	// Assumes Esc is at [0,0] and spacebar is at [4,6].
    324 	// This isn't very generalized, but we need something that doesn't
    325 	// rely on user's keymaps in firmware or EEPROM.
    326 	if ( ( matrix_get_row(0) & (1<<0) ) &&
    327 		( matrix_get_row(4) & (1<<6) ) )
    328 	{
    329 		// Set the TMK/QMK EEPROM state as invalid.
    330 		eeconfig_disable();
    331 		//eeprom_set_valid(false);
    332 		// Jump to bootloader.
    333 		bootloader_jump();
    334 	}
    335 }
    336 
    337 void matrix_init_kb(void) {
    338 	// put your keyboard start-up code here
    339 	// runs once when the firmware starts up
    340 
    341 	bootmagic_lite();
    342 
    343     // Please ignore this is for upcoming features
    344 	// If the EEPROM has the magic, the data is good.
    345 	// OK to load from EEPROM.
    346 	/*if (eeprom_is_valid())
    347 	{
    348 		backlight_config_load();
    349 
    350 		// TODO: do something to "turn on" keymaps in EEPROM?
    351 	}
    352 	else
    353 	{
    354 		// If the EEPROM has not been saved before, or is out of date,
    355 		// save the default values to the EEPROM. Default values
    356 		// come from construction of the zeal_backlight_config instance.
    357 		backlight_config_save();
    358 
    359 		// Clear the LED colors stored in EEPROM
    360 		for ( int row=0; row < MATRIX_ROWS; row++ )
    361 		{
    362 			HSV hsv;
    363 			for ( int column=0; column < MATRIX_COLS; column++ )
    364 			{
    365 				hsv.h = rand() & 0xFF;
    366 				hsv.s = rand() & 0x7F;
    367 				hsv.v = 255;
    368 				backlight_set_key_color( row, column, hsv );
    369 			}
    370 		}
    371         #ifdef USE_KEYMAPS_IN_EEPROM
    372 		keymap_default_save();
    373 		#endif
    374 		// Save the magic number last, in case saving was interrupted
    375 		eeprom_set_valid(true);
    376 	}*/
    377 
    378 	matrix_init_user();
    379 }
    380 
    381 void matrix_scan_kb(void) {
    382 
    383 	matrix_scan_user();
    384 }
    385 
    386 bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
    387 
    388 	return process_record_user(keycode, record);
    389 }
    390 
    391 void led_set_kb(uint8_t usb_led) {
    392 	//backlight_set_indicator_state(usb_led);
    393 }
    394 
    395 void suspend_power_down_kb(void)
    396 {
    397     rgb_matrix_set_suspend_state(true);
    398 }
    399 
    400 void suspend_wakeup_init_kb(void)
    401 {
    402     rgb_matrix_set_suspend_state(false);
    403 }