TEAMUSB
/
TEAMUSB_SLAVE
TEAMUSB_SLAVE
Fork of USBHostKeyboard_HelloWorld by
main.cpp
- Committer:
- armdran
- Date:
- 2015-04-01
- Revision:
- 9:8bcd70b26084
- Parent:
- 8:f8122ca2f58f
- Child:
- 10:54ffd94e075c
File content as of revision 9:8bcd70b26084:
#include "mbed.h" #include "USBHostKeyboard.h" #include "rtos.h" DigitalOut led(LED1); SPISlave device(D11, D12, D13, D10); uint8_t keyReg = 0x0; void onKeyMod(uint8_t key, uint8_t modifier) { printf("Key: %x modifier: %x\r\n", key, modifier); keyReg = key; } void keyboard_task(void const *) { USBHostKeyboard keyboard; while(1) { printf("trying to connect\r\n"); // try to connect a USB keyboard while(!keyboard.connect()) { Thread::wait(500); } printf("connected\r\n"); // when connected, attach handler called on keyboard event //keyboard.attach(onKey); keyboard.attach(onKeyMod); printf("eventhandler attached\r\n"); // wait until the keyboard is disconnected while(keyboard.connected()) { USBHost::poll(); } printf("disconnected\r\n"); } } int main() { Thread keyboardTask(keyboard_task, NULL, osPriorityNormal, 256 * 4); device.frequency(1000000); device.format(8, 1); //while(1) { //Thread::wait(1000); //printf("waiting...\r\n"); //} int i = 0; while(1) { //get instruciton device.reply(0x00); while(!device.receive()) { if(i++ % 10000 == 0) { printf("."); } } uint8_t instruction = device.read(); if(instruction != 0xFE) continue; device.reply(keyReg); while(!device.receive()) { if(i++ % 10000 == 0) { printf("."); } } device.read(); device.reply(0x00); while(!device.receive()) { if(i++ % 10000 == 0) { printf("."); } } int response = device.read(); //printf("Sent Keystroke %x over SPI. response was %x\r\n", keyReg, response); if(response == keyReg) { keyReg = 0; } } }