Mac Keyboard Stack Complete
This commit is contained in:
@@ -34,8 +34,9 @@ void setPullup(uint PIN);
|
||||
void holdForEnable();
|
||||
uint8_t readCommand();
|
||||
void sendByte(uint8_t payload);
|
||||
void inquiry();
|
||||
void sendNextKey();
|
||||
void transmitKey(uint8_t key);
|
||||
void sendKey(uint8_t key);
|
||||
|
||||
queue_t key_queue;
|
||||
|
||||
@@ -73,10 +74,11 @@ int main() {
|
||||
switch(readCommand()) {
|
||||
case 0x10:
|
||||
// Key Requested
|
||||
|
||||
inquiry();
|
||||
break;
|
||||
case 0x14:
|
||||
// Send Key
|
||||
sendNextKey();
|
||||
break;
|
||||
case 0x16:
|
||||
// Requests Model Number
|
||||
@@ -139,21 +141,25 @@ void sendByte(uint8_t payload) {
|
||||
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)
|
||||
uint64_t startTime = time_us_64();
|
||||
while (time_us_64() - startTime < 250000) { // 250ms timeout
|
||||
uint8_t key;
|
||||
if (queue_try_remove(&key_queue, &key)) {
|
||||
transmitKey(key); // TODO: Replace with mac-plus-ps2's sendKey()
|
||||
return;
|
||||
}
|
||||
sendNextKey();
|
||||
sleep_us(2);
|
||||
}
|
||||
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){
|
||||
sendByte(0x79);
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user