libjoybus
Joybus implementation for 32-bit MCUs
Loading...
Searching...
No Matches
joybus_host.pio.h
1// ---------------------------------------------------------------- //
2// This file is autogenerated by pioasm version 2.2.0; do not edit! //
3// ---------------------------------------------------------------- //
4
5#pragma once
6
7#if !PICO_NO_HARDWARE
8#include "hardware/pio.h"
9#endif
10
11// ----------- //
12// joybus_host //
13// ----------- //
14
15#define joybus_host_wrap_target 0
16#define joybus_host_wrap 14
17#define joybus_host_pio_version 0
18
19#define joybus_host_TICKS_PER_BIT 24
20
21#define joybus_host_offset_transmit 0u
22
23static const uint16_t joybus_host_program_instructions[] = {
24 // .wrap_target
25 0x80a0, // 0: pull block side 0
26 0x7021, // 1: out x, 1 side 1
27 0x1424, // 2: jmp !x, 4 side 1 [4]
28 0x0b05, // 3: jmp 5 side 0 [11]
29 0xbb42, // 4: nop side 1 [11]
30 0x05e1, // 5: jmp !osre, 1 side 0 [5]
31 0xb542, // 6: nop side 1 [5]
32 0xc010, // 7: irq nowait 0 rel side 0
33 0xe027, // 8: set x, 7 side 0
34 0x20a0, // 9: wait 1 pin, 0 side 0
35 0x2820, // 10: wait 0 pin, 0 side 0 [8]
36 0x4001, // 11: in pins, 1 side 0
37 0x0049, // 12: jmp x--, 9 side 0
38 0xc010, // 13: irq nowait 0 rel side 0
39 0x0008, // 14: jmp 8 side 0
40 // .wrap
41};
42
43#if !PICO_NO_HARDWARE
44static const struct pio_program joybus_host_program = {
45 .instructions = joybus_host_program_instructions,
46 .length = 15,
47 .origin = -1,
48 .pio_version = joybus_host_pio_version,
49#if PICO_PIO_VERSION > 0
50 .used_gpio_ranges = 0x0
51#endif
52};
53
54static inline pio_sm_config joybus_host_program_get_default_config(uint offset) {
55 pio_sm_config c = pio_get_default_sm_config();
56 sm_config_set_wrap(&c, offset + joybus_host_wrap_target, offset + joybus_host_wrap);
57 sm_config_set_sideset(&c, 1, false, true);
58 return c;
59}
60
61#include "hardware/clocks.h"
62static inline void joybus_host_program_init(PIO pio, uint sm, uint offset, uint pin, uint bus_freq) {
63 pio_sm_config c = joybus_host_program_get_default_config(offset);
64 // Set pin configuration
65 sm_config_set_in_pins(&c, pin);
66 sm_config_set_sideset_pins(&c, pin);
67 // Auto-pull and auto-push with 8-bit thresholds
68 sm_config_set_out_shift(&c, false, true, 8);
69 sm_config_set_in_shift(&c, false, true, 8);
70 // Set clock divider based on desired bus frequency and internal timing
71 float div = (float)clock_get_hz(clk_sys) / (joybus_host_TICKS_PER_BIT * bus_freq);
72 sm_config_set_clkdiv(&c, div);
73 // Initialize and enable the state machine
74 pio_sm_init(pio, sm, offset, &c);
75 pio_sm_set_enabled(pio, sm, true);
76}
77
78#endif
79