Exemple #1
0
static void print_eeconfig(void)
{
    print("default_layer: "); print_dec(eeconfig_read_default_layer()); print("\n");

    debug_config_t dc;
    dc.raw = eeconfig_read_debug();
    print("debug_config.raw: "); print_hex8(dc.raw); print("\n");
    print(".enable: "); print_dec(dc.enable); print("\n");
    print(".matrix: "); print_dec(dc.matrix); print("\n");
    print(".keyboard: "); print_dec(dc.keyboard); print("\n");
    print(".mouse: "); print_dec(dc.mouse); print("\n");

    keymap_config_t kc;
    kc.raw = eeconfig_read_keymap();
    print("keymap_config.raw: "); print_hex8(kc.raw); print("\n");
    print(".swap_control_capslock: "); print_dec(kc.swap_control_capslock); print("\n");
    print(".capslock_to_control: "); print_dec(kc.capslock_to_control); print("\n");
    print(".swap_lalt_lgui: "); print_dec(kc.swap_lalt_lgui); print("\n");
    print(".swap_ralt_rgui: "); print_dec(kc.swap_ralt_rgui); print("\n");
    print(".no_gui: "); print_dec(kc.no_gui); print("\n");
    print(".swap_grave_esc: "); print_dec(kc.swap_grave_esc); print("\n");
    print(".swap_backslash_backspace: "); print_dec(kc.swap_backslash_backspace); print("\n");

#ifdef BACKLIGHT_ENABLE
    backlight_config_t bc;
    bc.raw = eeconfig_read_backlight();
    print("backlight_config.raw: "); print_hex8(bc.raw); print("\n");
    print(".enable: "); print_dec(bc.enable); print("\n");
    print(".level: "); print_dec(bc.level); print("\n");
#endif
}
Exemple #2
0
static void pc98_inhibit_repeat(void)
{
    uint8_t code;

    while (serial_recv()) ;
RETRY:
    PC98_RDY_PORT |= (1<<PC98_RDY_BIT);
    _delay_ms(500);
    serial_send(0x9C);

    PC98_RDY_PORT &= ~(1<<PC98_RDY_BIT);
    _delay_ms(100);
    while (!(code = serial_recv())) ;
    print("PC98: send 9C: "); print_hex8(code); print("\n");
    if (code != 0xFA) goto RETRY;



    PC98_RDY_PORT |= (1<<PC98_RDY_BIT);
    _delay_ms(100);
    serial_send(0x70);

    PC98_RDY_PORT &= ~(1<<PC98_RDY_BIT);
    _delay_ms(100);
    //code = serial_recv();
    while (!(code = serial_recv())) ;
    print("PC98: send 70: "); print_hex8(code); print("\n");
    if (code != 0xFA) goto RETRY;
}
Exemple #3
0
uint8_t matrix_scan(void)
{
    uint16_t code;
    code = serial_recv2();
    if (code == -1) {
#ifdef PC98_LED_CONTROL
        // Before sending command  we have to make sure that there is no unprocessed key in queue
        // otherwise keys will be missed during sending command
        if (pc98_led) {
            pc98_led_set();
            pc98_led = 0;
        }
#endif
        return 0;
    }

    print_hex8(code); print(" ");

    if (code&0x80) {
        // break code
        if (matrix_is_on(ROW(code), COL(code))) {
            matrix[ROW(code)] &= ~(1<<COL(code));
        }
    } else {
        // make code
        if (!matrix_is_on(ROW(code), COL(code))) {
            matrix[ROW(code)] |=  (1<<COL(code));
        }
    }
    return code;
}
Exemple #4
0
void print_hex16(uint16_t x)
{
#ifdef TARGET_ESC64
	union
	{
		uint16_t word;
		char bytes[2];
	} u;
	
	u.word = x;
	
	print_hex8(u.bytes[1]);
	print_hex8(u.bytes[0]);
#else
	printf("%04X", x);
#endif	
}
Exemple #5
0
uint8_t matrix_scan(void)
{
    is_modified = false;

    uint8_t code;
    code = serial_recv();
    if (!code) return 0;

    print_hex8(code);

    switch (code) {
        case 0xFF:  // reset success
        case 0xFE:  // layout
        case 0x7E:  // reset fail
            if (code == 0xFF) print("reset: 0xFF ");
            if (code == 0x7E) print("reset fail: 0x7E ");
            if (code == 0xFE) print("layout: 0xFE ");
            // response byte
            _delay_ms(500);
            if (code = serial_recv()) print_hex8(code);
            print("\n");
            // FALL THROUGH
        case 0x7F:
            // all keys up
            for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00;
            return 0;
    }

    if (code&0x80) {
        // break code
        if (matrix_is_on(ROW(code), COL(code))) {
            matrix[ROW(code)] &= ~(1<<COL(code));
            is_modified = true;
        }
    } else {
        // make code
        if (!matrix_is_on(ROW(code), COL(code))) {
            matrix[ROW(code)] |=  (1<<COL(code));
            is_modified = true;
        }
    }
    return code;
}
Exemple #6
0
static void print_eeconfig(void)
{

// Print these variables if NO_PRINT or USER_PRINT are not defined.
#if !defined(NO_PRINT) && !defined(USER_PRINT)

    print("default_layer: "); print_dec(eeconfig_read_default_layer()); print("\n");

    debug_config_t dc;
    dc.raw = eeconfig_read_debug();
    print("debug_config.raw: "); print_hex8(dc.raw); print("\n");
    print(".enable: "); print_dec(dc.enable); print("\n");
    print(".matrix: "); print_dec(dc.matrix); print("\n");
    print(".keyboard: "); print_dec(dc.keyboard); print("\n");
    print(".mouse: "); print_dec(dc.mouse); print("\n");

    keymap_config_t kc;
    kc.raw = eeconfig_read_keymap();
    print("keymap_config.raw: "); print_hex8(kc.raw); print("\n");
    print(".swap_control_capslock: "); print_dec(kc.swap_control_capslock); print("\n");
    print(".capslock_to_control: "); print_dec(kc.capslock_to_control); print("\n");
    print(".swap_lalt_lgui: "); print_dec(kc.swap_lalt_lgui); print("\n");
    print(".swap_ralt_rgui: "); print_dec(kc.swap_ralt_rgui); print("\n");
    print(".no_gui: "); print_dec(kc.no_gui); print("\n");
    print(".swap_grave_esc: "); print_dec(kc.swap_grave_esc); print("\n");
    print(".swap_backslash_backspace: "); print_dec(kc.swap_backslash_backspace); print("\n");
    print(".nkro: "); print_dec(kc.nkro); print("\n");

#ifdef BACKLIGHT_ENABLE
    backlight_config_t bc;
    bc.raw = eeconfig_read_backlight();
    print("backlight_config.raw: "); print_hex8(bc.raw); print("\n");
    print(".enable: "); print_dec(bc.enable); print("\n");
    print(".level: "); print_dec(bc.level); print("\n");
#endif /* BACKLIGHT_ENABLE */

#endif /* !NO_PRINT */

}
Exemple #7
0
uint8_t matrix_scan(void)
{
    uint16_t code;
    PC98_RDY_PORT |= (1<<PC98_RDY_BIT);
    _delay_us(30);
    code = serial_recv2();
    PC98_RDY_PORT &= ~(1<<PC98_RDY_BIT);
    if (code == -1) return 0;

if (code == 0x60) {
    pc98_inhibit_repeat();

/*
    PC98_RDY_PORT |= (1<<PC98_RDY_BIT);
    _delay_ms(100);
    serial_send(0x96);
    PC98_RDY_PORT &= ~(1<<PC98_RDY_BIT);
*/

    return 0;
}

    print_hex8(code); print(" ");

    if (code&0x80) {
        // break code
        if (matrix_is_on(ROW(code), COL(code))) {
            matrix[ROW(code)] &= ~(1<<COL(code));
        }
    } else {
        // make code
        if (!matrix_is_on(ROW(code), COL(code))) {
            matrix[ROW(code)] |=  (1<<COL(code));
        }
    }
    return code;
}
//=====================================================================================================================
int main(void){
unsigned char i;
unsigned char dsmX_channel_index = 1, CRC_SEED_index = 0;

	init();
	
	put_string("\r\nCYRF\r\n");	//	print_hex8(0x8A); //put_char(0xa5);

	CYRF_init(0);// normal mode
	CYRF_read_mnfctID();
	print_hex8(mnfctID[0]);print_hex8(mnfctID[1]);print_hex8(mnfctID[2]);print_hex8(mnfctID[3]);//print_hex8(mnfctID[4]);print_hex8(mnfctID[5]);

	if( ! (PORTD.IN & BIND_button)){
		put_string(" BIND\r\n");
		ortxRxBuffer[2] = ORTX_BIND_FLAG | ORTX_USE_DSMX | ORTX_USE_11bit;
	}else{
		ortxRxBuffer[2] = 0 | ORTX_USE_DSMX | ORTX_USE_11bit;
	}
		ortxRxISRIndex = 18;
		ortxRxBuffer[0] = 0xAA;
		ortxRxBuffer[1] = 0;
		ortxRxBuffer[3] = 0;//7;//power
		ortxRxBuffer[4] = 6;
		ortxRxBuffer[5] = 0;

while(1){

	//analize incoming from UART
	if(ortxRxISRIndex == 18){
		if(ortxRxBuffer[0] == 0xAA){
			switch(ortxRxBuffer[1]){
			case 0x00:														//init
				work_mode = ortxRxBuffer[2];
				power = ortxRxBuffer[3];
				max_channel_num = ortxRxBuffer[4];
				CYRF_read_mnfctID();
				mnfctID[3] += ortxRxBuffer[5];//model number for model match feature
				
				if(work_mode & ORTX_BIND_FLAG){
					BIND_procedure();
					work_mode &= ~ORTX_BIND_FLAG;//clear BIND flag
				}
				
				CYRF_init(0);// normal mode
				
				if(work_mode & ORTX_USE_DSMX){		//dsmX mode
					generateDSMXchannel_list();
				}else{
					generateDSM2channel();
				}
				sop_col = (mnfctID[0] + mnfctID[1] + mnfctID[2] + 2) & 7;
				data_col = 7 - sop_col;
				//CRC_SEED = 0xFFFF - (( mnfctID[0] << 8) | mnfctID[1]);
				//put_string("CRC_SEED "); print_hex8(CRC_SEED>>8);print_hex8(CRC_SEED);
				//put_string("sop_col "); print_hex8(sop_col);
			break;
			case 0x01:												//first 7 channel data
				for(i = 0; i < 7; i++){
					channelsData[i] = (ortxRxBuffer[i * 2 + 2] <<8) | ortxRxBuffer[i * 2 + 3];
				}
			break;
			case 0x02:												//second 7 channel data
				for(i = 0; i < 7; i++){
					channelsData[i + 7] = (ortxRxBuffer[i * 2 + 2] <<8) | ortxRxBuffer[i * 2 + 3];
				}
			break;
			}
		}
		ortxRxISRIndex = 0;
	}
	
	//transmit data packet and receive telemetry answer
	if(work_mode & ORTX_USE_DSMX){
//DSMX mode
			buildTransmitBuffer(0);
			main_tcount = 40; // - пауза между каналами 4 мсек
			main_tflag = 1;
			if(transmit_receive(channel_list[dsmX_channel_index++], CRC_SEED_index) == ORTX_USE_TM){put_char("!");}//				put_string("0[");for(i = 0; i < 0x10; i++){print_hex8(RXbuffer[i]);}put_string("]\r\n");			}
			if(dsmX_channel_index == 23)dsmX_channel_index = 0;
			if(CRC_SEED_index)CRC_SEED_index = 0;else CRC_SEED_index = 1;
			while(main_tflag);
			main_tcount = 70; // 7 mSec
			main_tflag = 1;
			if(max_channel_num < 8){
				TXbuffer[2] |= 0x80;
			}
			if(transmit_receive(channel_list[dsmX_channel_index++], CRC_SEED_index) == ORTX_USE_TM){put_char("!");}//				put_string("1[");for(i = 0; i < 0x10; i++){print_hex8(RXbuffer[i]);}put_string("]\r\n");			}
			while(main_tflag);
			if(dsmX_channel_index == 23)dsmX_channel_index = 0;
			if(CRC_SEED_index)CRC_SEED_index = 0;else CRC_SEED_index = 1;

			if(max_channel_num > 7){
				buildTransmitBuffer(1); // for 14 channel ok
				main_tcount = 40; // - пауза между каналами 4 мсек
				main_tflag = 1;
				if(transmit_receive(channel_list[dsmX_channel_index++], CRC_SEED_index) == ORTX_USE_TM){}//				put_string("[");for(i = 0; i < 0x10; i++){print_hex8(RXbuffer[i]);}put_string("]\r\n");			}
				if(dsmX_channel_index == 23)dsmX_channel_index = 0;
				if(CRC_SEED_index)CRC_SEED_index = 0;else CRC_SEED_index = 1;
				while(main_tflag);
				main_tcount = 70; // 7 mSec
				main_tflag = 1;
				if(transmit_receive(channel_list[dsmX_channel_index++], CRC_SEED_index) == ORTX_USE_TM){}//				put_string("[");for(i = 0; i < 0x10; i++){print_hex8(RXbuffer[i]);}put_string("]\r\n");			}			while(main_tflag);
				if(dsmX_channel_index == 23)dsmX_channel_index = 0;
				if(CRC_SEED_index)CRC_SEED_index = 0;else CRC_SEED_index = 1;
				while(main_tflag);
			}else{
				main_tcount = 40;main_tflag = 1;while(main_tflag);
				main_tcount = 70;main_tflag = 1;while(main_tflag);
			}
	}else{
//DSM2 mode	
		//build transmit data for first seven channels
		buildTransmitBuffer(0);
		main_tcount = 40; // - пауза между каналами 4 мсек
		main_tflag = 1;
		if(transmit_receive(channelA, 0) == ORTX_USE_TM){}//		put_string("0[");for(i = 0; i < 0x10; i++){print_hex8(RXbuffer[i]);}put_string("]\r\n");	}
		while(main_tflag);
		main_tcount = 70; // 7 mSec
		main_tflag = 1;
		TXbuffer[2] |= 0x80;
		if(transmit_receive(channelB, 1) == ORTX_USE_TM){}//		put_string("1[");for(i = 0; i < 0x10; i++){print_hex8(RXbuffer[i]);}put_string("]\r\n");		}
		while(main_tflag);

		if(max_channel_num > 7){
			main_tcount = 40; // - пауза между каналами 4 мсек
			main_tflag = 1;
			buildTransmitBuffer(1);
			if(transmit_receive(channelA, 0) == ORTX_USE_TM){}//		put_string("2[");for(i = 0; i < 0x10; i++){print_hex8(RXbuffer[i]);}put_string("]\r\n");			}
			while(main_tflag);
			main_tcount = 70; // 7 mSec
			if(transmit_receive(channelB, 1) == ORTX_USE_TM){}//		put_string("3[");for(i = 0; i < 0x10; i++){print_hex8(RXbuffer[i]);}put_string("]\r\n");			}
			main_tflag = 1;
			while(main_tflag);
		}else{
/*			main_tcount = 40;
			buildTransmitBuffer(0);
			transmit_receive(channelA, 0);
			main_tflag = 1; while(main_tflag);
			//TXbuffer[2] |= 0x80;
			main_tcount = 70;
			transmit_receive(channelB, 1);
			main_tflag = 1; while(main_tflag);
*/
			main_tcount = 110 ;main_tflag = 1; while(main_tflag);
		}
	}

}

return 0;
}