4141
4242#pragma once
4343
44+ #include <stdbool.h>
4445#include <stddef.h>
4546#include <stdint.h>
4647
5657#define SI_CMD_INFO_LEN 1
5758#define SI_CMD_INFO_RESP 3
5859
59- // GameCube controller commands
60- #define SI_CMD_GC_SHORT_POLL 0x40
61- #define SI_CMD_GC_SHORT_POLL_LEN 3
62- #define SI_CMD_GC_SHORT_POLL_RESP 8
63-
64- #define SI_CMD_GC_READ_ORIGIN 0x41
65- #define SI_CMD_GC_READ_ORIGIN_LEN 1
66- #define SI_CMD_GC_READ_ORIGIN_RESP 10
67-
68- #define SI_CMD_GC_CALIBRATE 0x42
69- #define SI_CMD_GC_CALIBRATE_LEN 3
70- #define SI_CMD_GC_CALIBRATE_RESP 10
71-
72- #define SI_CMD_GC_LONG_POLL 0x43
73- #define SI_CMD_GC_LONG_POLL_LEN 3
74- #define SI_CMD_GC_LONG_POLL_RESP 10
75-
76- #define SI_CMD_GC_PROBE_DEVICE 0x4D
77- #define SI_CMD_GC_PROBE_DEVICE_LEN 3
78- #define SI_CMD_GC_PROBE_DEVICE_RESP 8
79-
80- #define SI_CMD_GC_FIX_DEVICE 0x4E
81- #define SI_CMD_GC_FIX_DEVICE_LEN 3
82- #define SI_CMD_GC_FIX_DEVICE_RESP 3
83-
8460// SI device info flags
8561// On wireless controllers 0x00C0FF is reserved for the controller ID
8662
@@ -118,12 +94,21 @@ enum {
11894 SI_ERR_TRANSFER_TIMEOUT ,
11995};
12096
97+ /**
98+ * Function type for per-byte callbacks during receive operations.
99+ *
100+ * @param byte the received byte
101+ * @param byte_index the zero-based index of the byte (0 for first byte)
102+ * @return true to continue the transfer, false to stop it
103+ */
104+ typedef bool (* si_byte_cb_t )(uint8_t byte , uint8_t byte_index );
105+
121106/**
122107 * Function type for transfer completion callbacks.
123108 *
124- * @param result 0 on success, negative error code on failure
109+ * @param result positive number of bytes read on success, negative error code on failure
125110 */
126- typedef void (* si_callback_fn )(int result );
111+ typedef void (* si_complete_cb_t )(int result );
127112
128113/**
129114 * Initialize the SI bus.
@@ -143,24 +128,17 @@ void si_init(uint8_t port, uint8_t pin, uint8_t mode, uint32_t rx_freq, uint32_t
143128 * @param length the length of the data
144129 * @param callback function to call when the transfer is complete
145130 */
146- void si_write_bytes (const uint8_t * data , uint8_t length , si_callback_fn callback );
131+ void si_write_bytes (const uint8_t * data , uint8_t length , si_complete_cb_t callback );
147132
148133/**
149134 * Read data from the SI bus.
150135 *
151136 * @param buffer the buffer to read into
152- * @param length the number of bytes expected
153- * @param callback function to call when the transfer is complete
154- */
155- void si_read_bytes (uint8_t * buffer , uint8_t length , si_callback_fn callback );
156-
157- /**
158- * Read a single command from the SI bus.
159- *
160- * @param buffer the buffer to read into
161- * @param callback function to call when the command has been read
137+ * @param max_length the maximum number of bytes to read (buffer size)
138+ * @param byte_callback optional function to call for each received byte (can be NULL)
139+ * @param complete_callback function to call when the transfer is complete
162140 */
163- void si_read_command (uint8_t * buffer , si_callback_fn callback );
141+ void si_read_bytes (uint8_t * buffer , uint8_t max_length , si_byte_cb_t byte_callback , si_complete_cb_t complete_callback );
164142
165143/**
166144 * Wait for the SI bus to be idle.
0 commit comments