diff --git a/captures/diy_samples/pcard_interrupt_numlock.sal b/captures/diy_samples/pcard_interrupt_numlock.sal new file mode 100644 index 0000000..6e2f1a9 Binary files /dev/null and b/captures/diy_samples/pcard_interrupt_numlock.sal differ diff --git a/photos/interrupt.png b/photos/interrupt.png new file mode 100644 index 0000000..013cc80 Binary files /dev/null and b/photos/interrupt.png differ diff --git a/technical_notes.md b/technical_notes.md index 5038f9f..6efa675 100644 --- a/technical_notes.md +++ b/technical_notes.md @@ -52,8 +52,6 @@ Most pins are already in use: ![Alt text](photos/bb_pinout.png) -A few comments: - * Protocol Card and OLED screen shares the same SPI bus, with different CS of course. * Pin 22 is used to reset the P-Card, pin 32 for putting the microcontroller in bootloader mode for firmware updates. @@ -72,7 +70,9 @@ A few comments: Raspberri Pi communicates with Protocol Card through SPI. [Here's a quick introduction](https://www.circuitbasics.com/basics-of-the-spi-communication-protocol/) if you're unfamiliar. -RPi is master, P-card is slave. **Mode 0** is used (CPOL and CPHA both 0), **SCLK is 2MHz**. +RPi is master, P-card is slave. **SCLK is 2MHz**. + +**Mode 0** is used. CPOL=0 (CLK idle low), CPHA=0 (data valid on CLK rising edge). RPi and P-Card communicates via **fixed-length 32-byte packets**. @@ -94,6 +94,20 @@ Compare to the [keyboard tab in the document](https://docs.google.com/spreadshee ![Alt text](photos/spi_kb.png) +## P-Card Interrupt Handling + +When Protocol Card has data for RPi, it should prepare the SPI buffer, and switch its interrupt pin to HIGH ([Pin 36](#hardware-pinout)). + +Upon detecting this change, RPi will send out an ACK message. Upon receiving, the P-Card switches the interrupt pin to LOW. + +RPi will then send out another ACK (or NOP) message to shift the data from P-Card to itself. + +Here is a sample capture: + +![Alt text](photos/interrupt.png) + +Currently this feature is only used for changing keyboard LEDs. + ## Sample SPI Message Captures More **sample captures** [can be found here](https://github.com/dekuNukem/USB4VC/tree/master/captures/diy_samples). diff --git a/user_program/usb4vc_usb_scan.py b/user_program/usb4vc_usb_scan.py index 1d10470..b39ee35 100644 --- a/user_program/usb4vc_usb_scan.py +++ b/user_program/usb4vc_usb_scan.py @@ -910,9 +910,11 @@ def raw_input_event_worker(): # ----------------- PBOARD INTERRUPT ----------------- if GPIO.event_detected(SLAVE_REQ_PIN): - slave_result = None - for x in range(2): - slave_result = pcard_spi.xfer(make_spi_msg_ack()) + # send out ACK to turn off P-Card interrupt + slave_result = pcard_spi.xfer(make_spi_msg_ack()) + time.sleep(0.001) + # send another to shift response into RPi + slave_result = pcard_spi.xfer(make_spi_msg_ack()) print(int(time.time()), slave_result) if slave_result[SPI_BUF_INDEX_MAGIC] == SPI_MISO_MAGIC and slave_result[SPI_BUF_INDEX_MSG_TYPE] == SPI_MISO_MSG_TYPE_KB_LED_REQUEST: try: