forked from rikka0w0/CH55x_USB_CompositeDevice
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
156 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,4 +40,7 @@ | |
|
||
void CH554_Init(void); | ||
|
||
// Interrupt Handlers | ||
void USBInterrupt(void); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,35 @@ | ||
#include "types.h" | ||
|
||
#include "ch554_conf.H" | ||
#include "Delay.H" | ||
#include "usb_endp.h" | ||
#include "usb_hid_keyboard.h" | ||
|
||
#include <string.h> | ||
#include <stdio.h> | ||
|
||
xdata uint8_t FLAG; | ||
extern uint8_t Ready; | ||
uint8_t keyState, kbdModifier, kbdKey; | ||
|
||
void main(void) { | ||
CH554_Init(); //CH559时钟选择配置 | ||
CH554_Init(); | ||
|
||
//printf("start ...\n"); | ||
//允许单片机中断 | ||
FLAG = 0; | ||
Ready = 0; | ||
printf("start ...\n"); | ||
|
||
keyState = KBD_STATE_IDLE; | ||
|
||
while(1); | ||
while(1) { | ||
while(keyState == KBD_STATE_IDLE); | ||
keyState = KBD_STATE_KEYDOWN; | ||
USB_Keyboard_SendKey(kbdModifier, kbdKey); | ||
while(keyState == KBD_STATE_KEYDOWN); | ||
USB_Keyboard_SendKey(0, 0); | ||
} | ||
} | ||
|
||
extern void DeviceInterrupt(void); | ||
void USB(void) interrupt INT_NO_USB { | ||
DeviceInterrupt(); | ||
/* | ||
* According to SDCC specification, interrupt handlers MUST be placed within the file which contains | ||
* the void main(void) function, otherwise SDCC won't be able to recognize it. It's not a bug but a feature. | ||
* If you know how to fix this, please let me know. | ||
*/ | ||
void USBInterruptEntry(void) interrupt INT_NO_USB { | ||
USBInterrupt(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "usb_hid_keyboard.h" | ||
#include "usb_endp.h" | ||
|
||
void USB_Keyboard_SendKey(uint8_t modifier, uint8_t key) { | ||
KBD_Tx_Buf[0] = modifier; | ||
KBD_Tx_Buf[1] = 0; // reserved | ||
KBD_Tx_Buf[2] = key; // key0 | ||
|
||
KBD_Tx_Buf[3] = 0; // key1 | ||
KBD_Tx_Buf[4] = 0; // key2 | ||
KBD_Tx_Buf[5] = 0; // key3 | ||
KBD_Tx_Buf[6] = 0; // key4 | ||
KBD_Tx_Buf[7] = 0; // key5 | ||
UEP1_T_LEN = 8; | ||
|
||
KBD_Tx_Enable(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef __USB_HID_KEYBOARD_H | ||
#define __USB_HID_KEYBOARD_H | ||
|
||
#include "types.h" | ||
|
||
#define KBD_Tx_Buf Ep1Buffer | ||
#define KBD_Tx_Enable() {UEP1_CTRL = UEP1_CTRL & ~ MASK_UEP_T_RES | UEP_T_RES_ACK;} | ||
|
||
#define KBD_LCTRL 0x01 | ||
#define KBD_LSHIFT 0x02 | ||
#define KBD_LALT 0x04 | ||
#define KBD_LGUI 0x08 | ||
#define KBD_RCTRL 0x10 | ||
#define KBD_RSHIFT 0x20 | ||
#define KBD_RALT 0x40 | ||
#define KBD_RGUI 0x80 | ||
|
||
#define KBD_STATE_IDLE 0 | ||
#define KBD_STATE_KEYDOWN 1 | ||
#define KBD_STATE_KEYUP 2 | ||
|
||
void USB_Keyboard_SendKey(uint8_t modifier, uint8_t key); | ||
|
||
#endif /* __USB_HID_KEYBOARD_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters