Hardware level details:
1. Transmitter Operation
Encoder IC (HT12E) receives parallel data in the form of address bits and control bits.
The control signals from microcontroller along with 8 address bits constitute a set of 12 parallel signals. The encoder HT12E encodes these parallel signals into serial bits. Transmission is enabled by providing ground to pin14 (TE Pin in Encoder) which is active low. The control signals are given at pins 10-13 of HT12E. The serial data is fed to the RF transmitter through pin17 of HT12E.
2. Receiver Operation:
Transmitter, upon receiving serial data from encoder IC (HT12E), transmits it wirelessly to the RF receiver. The receiver, upon receiving these signals, sends them to the decoder IC (HT12D) through pin2. The serial data is received at the data pin (DIN, pin14) of HT12D.
The decoder then retrieves the original parallel format from the received serial data.
Software level details:
To convert LPC2148 into a HID device using the USB interface, main changes have to be done in the USB descriptor files. USB descriptor is the place, where the values of different descriptors like device, configuration, interface, report are configured. A device can be changed to HID devices like keyboard, mouse or joystick based on the values specified in these descriptors. There is no need to design a specific driver, alone making the OS recognize the device as a HID device (keyboard in our case) is sufficient.
To start with the basic, Keil provides an example setup code, which can be used to convert the LPC into a HID device. The source code is available at: http://www.keil.com/download/docs/306.asp
The basic code flow can be understood as:
GetInReport() is the function, which is called to receive the data stored in the InReport variable by the host. Similarly GetOutReport() is responsible to send the data from the host to the device using the OutReport, though it is not used in our implementation.
The value acquired through InReport variable is passed to the host using the endpoint0 buffer, “EP0Buf[0] = InReport” which is the by default control endpoint. But for the keyboard descriptor, the HID documentation states to have a 8 byte format of data with the first two bytes as modifier byte and reserved byte. The next six bytes contain the scan codes, unique for a key.
Thus, for better implementation, a structure has been defined as follows:
typedef __packed struct keyboard_report_t
{ BYTE modifier;
BYTE reserved;
BYTE keycode[6];
} keyboard_st;
USB_Endpoint1 In has been used to send the data packets to the host. InReport has been redefined as: BYTE InReport[8]; and it is written into the Endpoint1 In as:
USB_WriteEP(HID_EP_IN, InReport, sizeof(keyboard_st));
The changes done in USB descriptor have been summarized as follows: