Пример #1
0
/**
 * The write function is called when LEDs should be set. Normally, we get only
 * one byte that contains info about the LED states.
 * \param data pointer to received data
 * \param len number ob bytes received
 * \return 0x01
 */
uint8_t usbFunctionWrite(uchar *data, uchar len) {
//    DBG1(0xBB, (uchar *)&len, 1);
    if (expectReport == 1 && (len == 1)) {
        // change LEDs of indicator
        delegateLedUsb(data[0]);
        expectReport = 0;
    }else if (expectReport == 2){   // options
        DBG1(0xEE, data, len);
        // start bootloader
        if(data[1] == OPTION_INDEX_BOOTLOADER && len == 8){
        	if(data[2] == 0xFF){
        		eeprom_write_byte((uint8_t *)EEPROM_BOOTLOADER_START, 0x00);
        	}
        	delegateGotoBootloader();
/* TODO
 * 이전 버전과 호환을 위해 남겨둠
 */
#ifdef ENABLE_BOOTMAPPER
        }else if(data[1] == OPTION_INDEX_BOOTMAPPER){
        	if(data[2] == OPTION_VALUE_BOOTMAPPER_START){
        		setToBootMapper(true);
        	}else{
        		setToBootMapper(false);
        	}
#endif
       /* }else if(data[1] == OPTION_INDEX_READY){
            stopPwmForUsbReport(true);

        }else if(data[1] == OPTION_INDEX_ACTION){
            stopPwmForUsbReport(false);*/
        }else{
        	setOptions((uint8_t *)data);
        }
    }else if (expectReport == 4){
    	// rainbow color setting
    	setOptions((uint8_t *)data);
    }else if (expectReport == 5){
        // write quick macro;
        updateQuickMacro((uint8_t *)data, len);
    }

    return 0x01;
}
Пример #2
0
/**
 * The write function is called when LEDs should be set. Normally, we get only
 * one byte that contains info about the LED states.
 * \param data pointer to received data
 * \param len number ob bytes received
 * \return 0x01
 */
uint8_t usbFunctionWrite(uchar *data, uchar len) {
    DBG1(0xBB, (uchar *)&len, 1);
    if (expectReport == 1 && (len == 1)) {
        delegateLedUsb(data[0]); 
        expectReport = 0;
    }else if (expectReport == 2){   // options
        DBG1(0xEE, data, len);
        // start bootloader
        if(data[1] == OPTION_INDEX_BOOTLOADER && len == 8){
        	if(data[2] == 0xFF){
        		eeprom_write_byte((uint8_t *)EEPROM_BOOTLOADER_START, 0x00);
        	}
        	delegateGotoBootloader();
#ifdef ENABLE_BOOTMAPPER
        }else if(data[1] == OPTION_INDEX_BOOTMAPPER){
        	if(data[2] == OPTION_VALUE_BOOTMAPPER_START){
        		setToBootMapper(true);
        	}else{
        		setToBootMapper(false);
        	}
#endif
        }else if(data[1] == OPTION_INDEX_READY){
        	//stop timer
        	// stop timer1
        	stopFullLed();

        }else if(data[1] == OPTION_INDEX_ACTION){
        	// start timer1
        	startFullLed();

        }else{
        	setLed2((uint8_t *)data);
        }

//        expectReport = 0;
    }else if (expectReport == 4){
    	// rainbow color setting
    	DBG1(0x44, data, len);
        setLed2((uint8_t *)data);
    }else if (expectReport == 3){   // HID_REPORT_BOOT
        DBG1(0xDD, data, len);
        /*
         * 44: 02 10 00 00 00 00 00 00
        44: ff 00 ff 00 ff 00 00 00
        44: 00 00 00 00 00 00 00 00
        44: 00 00 00 00 00 00 00 00
        44: 00 00 00
         */
//        uchar   isLast;
//        static uchar            offset;
//        if(isStart == 1){
//        	isStart = 0;
//			offset = 0;
//			len -= 4;
//		}
//		offset += len;
//		isLast = offset & 0x80; /* != 0 if last block received */
//		DBG1(0xDE, (void *)&isLast, 1);
//		return isLast;

       /* uint8_t gRet;

        gRet = writeFlash(data, len, isStart);
        if(isStart == 1){
            isStart = 0;
        }

        DBG1(0xDF, (uchar *)&gRet, 1);
        return gRet;*/

        /*
         *
         *
         * 여기까지 제대로 실행이 되지만, '커뮤니케이션 에러'가 발생하면서 다음 page로 진행이 되지 않는다.
         * - 일단 page는 저장이 된 상태
         *
         * USB_CFG_SUPPRESS_INTR_CODE 와 USB_CFG_INTR_POLL_INTERVAL 값을 변경해야 통신이 원활히 된다.
         * (아마도 다른 인터럽트를 허용하지 않고 해당 통신만 전담하는 세팅인것 같다.)
         *
         * USB_CFG_INTR_POLL_INTERVAL를 높히면 매크로 출력시 속도가 느리고,
         * USB_CFG_SUPPRESS_INTR_CODE를 1로 설정하면 키보드로 작동을 안한다.
         *
         * 이 둘을 최적화 했다 치더라도, 통신 중(페이지 단위로 쓰기 위해서 8바이트씩 전송되는 데이터를 조합하고 이 페이지를 5개 받는다)에
         * 플래시를 쓰면 커뮤니케이션 에러가 발생하고,
         *
         * 이를 방지하기 위해서 모든 페이지를 메모리에 저장 후 쓰려고 하면, 작동은하지만 메모리가 부족한 현상이 있다.
         *
         *
         *
         *
         * */
    }

    return 0x01;
}