示例#1
0
void main(void) {	
	USBCDC_ResetBehaviour(&cdcBehaviour);
	USB_Init(&usbDefinition, &usbDevice);
	USB_SoftConnect(&usbDevice);
	GPIO_SetDir(LED_PORT, LED_PIN, GPIO_Output);
	GPIO_WriteOutput(LED_PORT, LED_PIN, false);
	counter = 0;
	
	while (1) {
		uint8_t ch;
		if (USBCDC_ReadBytes(&usbDevice, &cdcBehaviour, &ch, 1)) {
			counter++;
			GPIO_WriteOutput(LED_PORT, LED_PIN, counter & 1);

			if ((ch >= 'a') && (ch <= 'z')) ch -= 'a'-'A';
			else if ((ch >= 'A') && (ch <= 'Z')) ch += 'a'-'A';
			if ((ch == 'a') || (ch == 'A')) ch = '4';
			if ((ch == 'i') || (ch == 'I')) ch = '1';
			if ((ch == 'o') || (ch == 'O')) ch = '0';
			if ((ch == 'e') || (ch == 'E')) ch = '3';
			if ((ch == 'l') || (ch == 'L')) ch = '7';
			if (ch == 's') ch = 'z';
			if (ch == 'S') ch = 'Z';
				
			USBCDC_WriteBytes(&usbDevice, &cdcBehaviour, &ch, 1);
		}
	}
}
示例#2
0
文件: main.c 项目: modul/anykey-sdk
void blinker() {
	if (blinks > 0) {
		bool led = GPIO_ReadInput(LED_PORT, LED_PIN);
		GPIO_WriteOutput(LED_PORT, LED_PIN, !led);
		blinks -= led;
	}
}
示例#3
0
文件: main.c 项目: modul/anykey-sdk
void main(void) {
	uint8_t counter = 0;
	GPIO_SetDir(LED_PORT, LED_PIN, GPIO_Output);
	GPIO_SetDir(KEY_PORT, KEY_PIN, GPIO_Input);
	GPIO_WriteOutput(LED_PORT, LED_PIN, false);
	SYSCON_StartSystick(72*200000); // 0.2s
	blinks = 0;

	while (true) {
		if (!debounced(KEY_PORT, KEY_PIN) && blinks == 0)
			blinks = counter = (counter+1)&7;
	}
}
示例#4
0
文件: main.c 项目: modul/anykey-sdk
void systick(void) {	//systick is used for regular, repeating tasks
    counter++;

    // calculate a smooth triangle ramp from counter
    uint32_t brightness = counter / ANIM_SPEED;
    if (brightness >= 2*ANIM_STEPS) counter = 0;	//reset counter
    else if (brightness >= ANIM_STEPS) brightness = 2*ANIM_STEPS-brightness;

    // scale brightness to match pwm
    brightness = (brightness * PWM_SPEED) / ANIM_STEPS;

    // this is the pwm high frequency counter
    uint32_t pwmPhase = counter % PWM_SPEED;

    // set output
    GPIO_WriteOutput(LED_PORT, LED_PIN, brightness > pwmPhase);
}