updated p-card interrupt information and other technical docs

This commit is contained in:
dekunukem
2022-03-12 13:13:52 +00:00
parent d2a8baa91f
commit c1b9fcd605
4 changed files with 22 additions and 6 deletions

View File

Binary file not shown.

BIN
photos/interrupt.png Normal file
View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

View File

@@ -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).

View File

@@ -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: