diff options
Diffstat (limited to 'hid/pico/src/ph_ps2_phy.c')
-rw-r--r-- | hid/pico/src/ph_ps2_phy.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/hid/pico/src/ph_ps2_phy.c b/hid/pico/src/ph_ps2_phy.c index 670e625a..05046b2b 100644 --- a/hid/pico/src/ph_ps2_phy.c +++ b/hid/pico/src/ph_ps2_phy.c @@ -1,6 +1,11 @@ +// Source: https://github.com/No0ne/ps2x2pico/blob/main/ps2phy.c +// replace ps2phy with ph_ps2_phy + #include "ph_ps2_phy.h" #include "ph_ps2_phy.pio.h" +uint prog = 0; + u32 ph_ps2_phy_frame(u8 byte) { bool parity = 1; for (u8 i = 0; i < 8; i++) { @@ -10,13 +15,17 @@ u32 ph_ps2_phy_frame(u8 byte) { } void ph_ps2_phy_init(ph_ps2_phy* this, PIO pio, u8 data_pin, rx_callback rx) { + if(!prog) { + prog = pio_add_program(pio, &ph_ps2_phy_program); + } + queue_init(&this->qbytes, sizeof(u8), 9); queue_init(&this->qpacks, sizeof(u8) * 9, 16); - this->pio = pio; - this->sm = pio_claim_unused_sm(this->pio, true); - ps2phy_program_init(this->pio, this->sm, pio_add_program(this->pio, &ps2phy_program), data_pin); + this->sm = pio_claim_unused_sm(pio, true); + ph_ps2_phy_program_init(pio, this->sm, prog, data_pin); + this->pio = pio; this->sent = 0; this->rx = rx; this->last_rx = 0; @@ -39,7 +48,7 @@ void ph_ps2_phy_task(ph_ps2_phy* this) { queue_try_add(&this->qpacks, &pack); } - this->idle = !pio_interrupt_get(this->pio, this->sm * 2); + this->idle = !pio_interrupt_get(this->pio, this->sm); if (!queue_is_empty(&this->qpacks) && pio_sm_is_tx_fifo_empty(this->pio, this->sm) && this->idle) { if (queue_try_peek(&this->qpacks, &pack)) { @@ -54,10 +63,10 @@ void ph_ps2_phy_task(ph_ps2_phy* this) { } } - if (pio_interrupt_get(this->pio, this->sm * 2 + 1)) { + if (pio_interrupt_get(this->pio, this->sm + 4)) { this->sent = 0; pio_sm_drain_tx_fifo(this->pio, this->sm); - pio_interrupt_clear(this->pio, this->sm * 2 + 1); + pio_interrupt_clear(this->pio, this->sm + 4); } if (!pio_sm_is_rx_fifo_empty(this->pio, this->sm)) { |