Mac Keyboard Stack Complete
This commit is contained in:
@@ -34,8 +34,9 @@ void setPullup(uint PIN);
|
|||||||
void holdForEnable();
|
void holdForEnable();
|
||||||
uint8_t readCommand();
|
uint8_t readCommand();
|
||||||
void sendByte(uint8_t payload);
|
void sendByte(uint8_t payload);
|
||||||
|
void inquiry();
|
||||||
void sendNextKey();
|
void sendNextKey();
|
||||||
void transmitKey(uint8_t key);
|
void sendKey(uint8_t key);
|
||||||
|
|
||||||
queue_t key_queue;
|
queue_t key_queue;
|
||||||
|
|
||||||
@@ -73,10 +74,11 @@ int main() {
|
|||||||
switch(readCommand()) {
|
switch(readCommand()) {
|
||||||
case 0x10:
|
case 0x10:
|
||||||
// Key Requested
|
// Key Requested
|
||||||
|
inquiry();
|
||||||
break;
|
break;
|
||||||
case 0x14:
|
case 0x14:
|
||||||
// Send Key
|
// Send Key
|
||||||
|
sendNextKey();
|
||||||
break;
|
break;
|
||||||
case 0x16:
|
case 0x16:
|
||||||
// Requests Model Number
|
// Requests Model Number
|
||||||
@@ -139,21 +141,25 @@ void sendByte(uint8_t payload) {
|
|||||||
gpio_put(MAC_KB_DATA, 1);
|
gpio_put(MAC_KB_DATA, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendNextKey() {
|
void inquiry() {
|
||||||
// Send the next key from the cache (To be filled by a USB HID device)
|
// Send the next key from the cache (To be filled by a USB HID device)
|
||||||
uint64_t startTime = time_us_64();
|
uint64_t startTime = time_us_64();
|
||||||
while (time_us_64() - startTime < 250000) { // 250ms timeout
|
while (time_us_64() - startTime < 250000) { // 250ms timeout
|
||||||
uint8_t key;
|
sendNextKey();
|
||||||
if (queue_try_remove(&key_queue, &key)) {
|
|
||||||
transmitKey(key); // TODO: Replace with mac-plus-ps2's sendKey()
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
sleep_us(2);
|
sleep_us(2);
|
||||||
}
|
}
|
||||||
sendByte(NULL_TRANSITION); // Send null transition if no key is available
|
sendByte(NULL_TRANSITION); // Send null transition if no key is available
|
||||||
}
|
}
|
||||||
|
|
||||||
void transmitKey(uint8_t key) {
|
void sendNextKey() {
|
||||||
|
uint8_t key;
|
||||||
|
if (queue_try_remove(&key_queue, &key)) {
|
||||||
|
sendKey(key);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendKey(uint8_t key) {
|
||||||
if (key & 0x0100){
|
if (key & 0x0100){
|
||||||
sendByte(0x79);
|
sendByte(0x79);
|
||||||
readCommand();
|
readCommand();
|
||||||
|
|||||||
@@ -29,5 +29,4 @@ const uint8_t numpad_ascii[18] = {
|
|||||||
'9', '.', 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // TODO: Replace with actual values once known
|
'9', '.', 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // TODO: Replace with actual values once known
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user