fork/GramFirmware

git clone https://git.julia.blue/fork/GramFirmware

CarVacrebase to configurator818d962

gram
5.2 KiB128 linesraw
1#ifndef _COMMS_BACKEND_INIT_HPP
2#define _COMMS_BACKEND_INIT_HPP
3
4#include "comms/console_detection.hpp"
5#include "core/CommunicationBackend.hpp"
6#include "core/InputSource.hpp"
7#include "core/pinout.hpp"
8#include "core/state.hpp"
9
10#include <config.pb.h>
11
12// clang-format off
13
14/**
15 * @brief Optionally defined function that allows a device config to hook into initialize_backends()
16 * and use a custom method for selecting backend config before console detection
17 *
18 * @param backend_config The reference to the current backend config after checking for button holds
19 * and connected console
20 * @param inputs Reference to the InputState struct to pass into each backend's constructor
21 * @param config Reference to the global Config struct
22 * @return true if the passed in backend config was altered, otherwise false
23 */
24typedef void (*backend_config_selector_t)(
25    CommunicationBackendConfig &backend_config,
26    const InputState &inputs,
27    Config &config
28);
29
30/**
31 * @brief Optionally defined function that allows a device config to hook into initialize_backends()
32 * and use a custom method for selecting the default USB communication backend to initialize prior
33 * to console/USB detection
34 *
35 * @param backend_config The reference to the current backend config after checking for button holds
36 * and connected console
37 * @param config Reference to the global Config struct
38 * @return true if the passed in backend config was altered, otherwise false
39 */
40// bool usb_backend_config_custom(CommunicationBackendConfig &backend_config, const Config &config)
41//     __attribute__((weak));
42typedef void (*usb_backend_getter_t)(
43    CommunicationBackendConfig &backend_config,
44    const Config &config
45);
46
47/**
48 * @brief Initialize primary backend based on the passed in backend id
49 *
50 * @param primary_backend The reference to the primary backend pointer to initialize
51 * @param backend_id The id of the backend to initialize
52 * @param backends The reference to assign to the created backends array
53 * @param inputs Reference to the InputState struct to pass into each backend's constructor
54 * @param input_sources Input sources array to pass into each backend's constructor
55 * @param input_source_count Number of elements in the input_sources array
56 * @param config Reference to global config struct
57 * @param pinout Pinout struct used for GameCube/N64 communication backends
58 */
59typedef void (*primary_backend_initializer_t)(
60    CommunicationBackend *&primary_backend,
61    CommunicationBackendId backend_id,
62    InputState &inputs,
63    InputSource **input_sources,
64    size_t input_source_count,
65    Config &config,
66    const Pinout &pinout
67);
68
69/**
70 * @brief Initialize secondary backends and the backends array and return the number of elements in
71 * the array
72 *
73 * @param backends The reference to assign to the created backends array
74 * @param primary_backend The reference to the primary backend to insert first in the backends array
75 * @param backend_id The id indicating the primary backend
76 * @param inputs Reference to the InputState struct to pass into each backend's constructor
77 * @param input_sources Input sources array to pass into each backend's constructor
78 * @param input_source_count Number of elements in the input_sources array
79 * @param config Reference to global config struct
80 * @param pinout Pinout struct used for GameCube/N64 communication backends
81 * @return The number of backends in the array
82 */
83typedef size_t (*secondary_backend_initializer_t)(
84    CommunicationBackend **&backends,
85    CommunicationBackend *&primary_backend,
86    CommunicationBackendId backend_id,
87    InputState &inputs,
88    InputSource **input_sources,
89    size_t input_source_count,
90    Config &config,
91    const Pinout &pinout
92);
93
94typedef CommunicationBackendId (*detect_console_t)(const Pinout &pinout);
95
96// clang-format on
97
98extern backend_config_selector_t get_backend_config_default;
99extern usb_backend_getter_t get_usb_backend_config_default;
100extern primary_backend_initializer_t init_primary_backend_default;
101extern secondary_backend_initializer_t init_secondary_backends_default;
102
103/**
104 * @brief Initialize the backends array and return the number of elements in the array
105 *
106 * @param backends The reference to assign to the created backends array
107 * @param inputs Reference to the InputState struct to pass into each backend's constructor
108 * @param input_sources Input sources array to pass into each backend's constructor
109 * @param input_source_count Number of elements in the input_sources array
110 * @param config Reference to global config struct
111 * @param pinout Pinout struct used for GameCube/N64 communication backends
112 * @return The number of backends in the array
113 */
114size_t initialize_backends(
115    CommunicationBackend **&backends,
116    InputState &inputs,
117    InputSource **input_sources,
118    size_t input_source_count,
119    Config &config,
120    const Pinout &pinout,
121    backend_config_selector_t get_backend_config_custom = get_backend_config_default,
122    usb_backend_getter_t get_usb_backend_config = get_usb_backend_config_default,
123    detect_console_t detect_console = &detect_console,
124    secondary_backend_initializer_t init_secondary_backends = init_secondary_backends_default,
125    primary_backend_initializer_t init_primary_backend = init_primary_backend_default
126);
127
128#endif