diff --git a/src/backend/esp32/joybus.c b/src/backend/esp32/joybus.c index 0e99ea3..895837e 100644 --- a/src/backend/esp32/joybus.c +++ b/src/backend/esp32/joybus.c @@ -191,7 +191,7 @@ static void IRAM_ATTR handle_command_response(const uint8_t *response, uint8_t l } // Frequency-independent bit decode: '1' is short low + long high, '0' the reverse -static inline uint8_t decode_bit(rmt_symbol_word_t sym) +static inline IRAM_ATTR uint8_t decode_bit(rmt_symbol_word_t sym) { return sym.duration0 < sym.duration1; } diff --git a/src/n64_pak_fs.c b/src/n64_pak_fs.c index cf17f85..86df8ed 100644 --- a/src/n64_pak_fs.c +++ b/src/n64_pak_fs.c @@ -1,12 +1,13 @@ #include #include +#include #include #include // Offsets of the four ID copies in page 0 #define ID_COPIES 4 -static const uint16_t id_offsets[ID_COPIES] = {0x20, 0x60, 0x80, 0xC0}; +static JOYBUS_RAM_DATA const uint16_t id_offsets[ID_COPIES] = {0x20, 0x60, 0x80, 0xC0}; // ID block layout, 32 bytes with the checksums covering the first 28 #define ID_SIZE 32 @@ -106,6 +107,7 @@ bool joybus_n64_pak_fs_valid(const uint8_t *bank0, uint8_t banks) return false; } +JOYBUS_RAM_FUNC bool joybus_n64_pak_fs_is_id_block(uint16_t addr) { for (int i = 0; i < ID_COPIES; i++) { @@ -116,6 +118,7 @@ bool joybus_n64_pak_fs_is_id_block(uint16_t addr) return false; } +JOYBUS_RAM_FUNC uint8_t joybus_n64_pak_fs_id_banks(const uint8_t block[JOYBUS_N64_PAK_BLOCK_SIZE]) { return block[ID_BANKS]; diff --git a/src/target/gcn_controller.c b/src/target/gcn_controller.c index 2abdd16..650f11d 100644 --- a/src/target/gcn_controller.c +++ b/src/target/gcn_controller.c @@ -9,8 +9,9 @@ * Pack a "full" input state into a "short" 8-byte input state, depending on the * analog mode. See enum joybus_gcn_analog_mode for more details. */ -static inline uint8_t *pack_input_state(uint8_t *dest, const struct joybus_gcn_controller_state *src, - enum joybus_gcn_analog_mode analog_mode) +JOYBUS_RAM_FUNC +static uint8_t *pack_input_state(uint8_t *dest, const struct joybus_gcn_controller_state *src, + enum joybus_gcn_analog_mode analog_mode) { // Copy button and stick data memcpy(dest, src, 4); @@ -53,7 +54,8 @@ static inline uint8_t *pack_input_state(uint8_t *dest, const struct joybus_gcn_c } // Set or clear the "need origin" flag in the input state and device ID -static inline void set_need_origin(struct joybus_target_gcn_controller *controller, bool need_origin) +JOYBUS_RAM_FUNC +static void set_need_origin(struct joybus_target_gcn_controller *controller, bool need_origin) { // Always set the need_origin flag in the input state if (need_origin) { @@ -79,8 +81,8 @@ static inline void set_need_origin(struct joybus_target_gcn_controller *controll * Response: A 3-byte controller ID */ JOYBUS_RAM_FUNC -static inline int handle_reset(struct joybus_target_gcn_controller *controller, const uint8_t *command, - uint8_t bytes_read, joybus_target_response_cb send_response, void *user_data) +static int handle_reset(struct joybus_target_gcn_controller *controller, const uint8_t *command, uint8_t bytes_read, + joybus_target_response_cb send_response, void *user_data) { // Respond with the controller ID send_response((const uint8_t *)&controller->id, JOYBUS_CMD_RESET_RX, user_data); @@ -103,8 +105,8 @@ static inline int handle_reset(struct joybus_target_gcn_controller *controller, * Response: A 3-byte controller ID */ JOYBUS_RAM_FUNC -static inline int handle_identify(struct joybus_target_gcn_controller *controller, const uint8_t *command, - uint8_t bytes_read, joybus_target_response_cb send_response, void *user_data) +static int handle_identify(struct joybus_target_gcn_controller *controller, const uint8_t *command, uint8_t bytes_read, + joybus_target_response_cb send_response, void *user_data) { // Respond with the controller ID send_response((const uint8_t *)&controller->id, JOYBUS_CMD_IDENTIFY_RX, user_data); @@ -119,8 +121,8 @@ static inline int handle_identify(struct joybus_target_gcn_controller *controlle * Response: An 8-byte packed input state, see `pack_input_state` for details */ JOYBUS_RAM_FUNC -static inline int handle_read(struct joybus_target_gcn_controller *controller, const uint8_t *command, - uint8_t bytes_read, joybus_target_response_cb send_response, void *user_data) +static int handle_read(struct joybus_target_gcn_controller *controller, const uint8_t *command, uint8_t bytes_read, + joybus_target_response_cb send_response, void *user_data) { // We can respond after the first two bytes if (bytes_read == 2) { @@ -145,8 +147,8 @@ static inline int handle_read(struct joybus_target_gcn_controller *controller, c controller->input.buttons |= JOYBUS_GCN_USE_ORIGIN; // Get the previous motor state - uint8_t last_motor_state = (controller->id.status & JOYBUS_STATUS_GCN_MOTOR_STATE_MASK) >> - JOYBUS_STATUS_GCN_MOTOR_STATE_SHIFT; + uint8_t last_motor_state = + (controller->id.status & JOYBUS_STATUS_GCN_MOTOR_STATE_MASK) >> JOYBUS_STATUS_GCN_MOTOR_STATE_SHIFT; // Save the analog mode and motor state joybus_id_clear_status_flags(&controller->id, @@ -168,8 +170,9 @@ static inline int handle_read(struct joybus_target_gcn_controller *controller, c * Command: {0x41} * Response: A 10-byte input state representing the current origin. */ -static inline int handle_read_origin(struct joybus_target_gcn_controller *controller, const uint8_t *command, - uint8_t bytes_read, joybus_target_response_cb send_response, void *user_data) +JOYBUS_RAM_FUNC +static int handle_read_origin(struct joybus_target_gcn_controller *controller, const uint8_t *command, + uint8_t bytes_read, joybus_target_response_cb send_response, void *user_data) { // Respond with the controller origin send_response((uint8_t *)&controller->origin, JOYBUS_CMD_GCN_READ_ORIGIN_RX, user_data); @@ -186,8 +189,9 @@ static inline int handle_read_origin(struct joybus_target_gcn_controller *contro * Command: {0x42, 0x00, 0x00} * Response: A 10-byte input state representing the current origin. */ -static inline int handle_calibrate(struct joybus_target_gcn_controller *controller, const uint8_t *command, - uint8_t bytes_read, joybus_target_response_cb send_response, void *user_data) +JOYBUS_RAM_FUNC +static int handle_calibrate(struct joybus_target_gcn_controller *controller, const uint8_t *command, uint8_t bytes_read, + joybus_target_response_cb send_response, void *user_data) { // We can respond after the first byte if (bytes_read == 1) { @@ -212,8 +216,9 @@ static inline int handle_calibrate(struct joybus_target_gcn_controller *controll * * NOTE: This command is not used by any games, but is included for completeness. */ -static inline int handle_read_long(struct joybus_target_gcn_controller *controller, const uint8_t *command, - uint8_t bytes_read, joybus_target_response_cb send_response, void *user_data) +JOYBUS_RAM_FUNC +static int handle_read_long(struct joybus_target_gcn_controller *controller, const uint8_t *command, uint8_t bytes_read, + joybus_target_response_cb send_response, void *user_data) { // We can respond after the second byte is read if (bytes_read == 2) { @@ -233,8 +238,8 @@ static inline int handle_read_long(struct joybus_target_gcn_controller *controll controller->input.buttons |= JOYBUS_GCN_USE_ORIGIN; // Get the previous motor state - uint8_t last_motor_state = (controller->id.status & JOYBUS_STATUS_GCN_MOTOR_STATE_MASK) >> - JOYBUS_STATUS_GCN_MOTOR_STATE_SHIFT; + uint8_t last_motor_state = + (controller->id.status & JOYBUS_STATUS_GCN_MOTOR_STATE_MASK) >> JOYBUS_STATUS_GCN_MOTOR_STATE_SHIFT; // Save the analog mode and motor state joybus_id_clear_status_flags(&controller->id, @@ -264,8 +269,9 @@ static inline int handle_read_long(struct joybus_target_gcn_controller *controll * Command: {0x4D, 0x??, 0x??} - 2nd and 3rd bytes seem to differ every time * Response: 8 bytes of zeroes. */ -static inline int handle_probe_device(struct joybus_target_gcn_controller *controller, const uint8_t *command, - uint8_t bytes_read, joybus_target_response_cb send_response, void *user_data) +JOYBUS_RAM_FUNC +static int handle_probe_device(struct joybus_target_gcn_controller *controller, const uint8_t *command, + uint8_t bytes_read, joybus_target_response_cb send_response, void *user_data) { if (bytes_read == 1) { // Don't respond to probe commands if we already received data from a controller @@ -273,8 +279,8 @@ static inline int handle_probe_device(struct joybus_target_gcn_controller *contr return -JOYBUS_ERR_NOT_SUPPORTED; // Respond with 8 bytes of zeroes - static const uint8_t zeroes[8] = {0}; - send_response(zeroes, JOYBUS_CMD_GCN_PROBE_DEVICE_RX, user_data); + memset(controller->packed_input, 0, JOYBUS_CMD_GCN_PROBE_DEVICE_RX); + send_response(controller->packed_input, JOYBUS_CMD_GCN_PROBE_DEVICE_RX, user_data); } return JOYBUS_CMD_GCN_PROBE_DEVICE_TX - bytes_read; @@ -288,8 +294,9 @@ static inline int handle_probe_device(struct joybus_target_gcn_controller *contr * Command: {0x4E, wireless_id_h | 0x10, wireless_id_l} * Response: A 3-byte controller ID */ -static inline int handle_fix_device(struct joybus_target_gcn_controller *controller, const uint8_t *command, - uint8_t bytes_read, joybus_target_response_cb send_response, void *user_data) +JOYBUS_RAM_FUNC +static int handle_fix_device(struct joybus_target_gcn_controller *controller, const uint8_t *command, + uint8_t bytes_read, joybus_target_response_cb send_response, void *user_data) { if (bytes_read == JOYBUS_CMD_GCN_FIX_DEVICE_TX) { // Extract the wireless ID from the command @@ -336,7 +343,7 @@ static int gcn_controller_byte_received(struct joybus_target *target, const uint return -JOYBUS_ERR_NOT_SUPPORTED; } -static const struct joybus_target_api gcn_controller_api = { +static JOYBUS_RAM_DATA const struct joybus_target_api gcn_controller_api = { .byte_received = gcn_controller_byte_received, }; diff --git a/src/target/n64_controller.c b/src/target/n64_controller.c index ae3f141..7945874 100644 --- a/src/target/n64_controller.c +++ b/src/target/n64_controller.c @@ -13,7 +13,7 @@ // Helper to check if an pak is currently read for pak read/write commands // An pak is "ready" when it is present and pak changed flag has been cleared JOYBUS_RAM_FUNC -static inline bool pak_ready(struct joybus_target_n64_controller *controller) +static bool pak_ready(struct joybus_target_n64_controller *controller) { return controller->pak && !joybus_id_n64_pak_changed(&controller->id); } @@ -159,7 +159,8 @@ static int handle_pak_read(struct joybus_target_n64_controller *controller, cons if (ready) { // Calculate and append the data checksum - controller->response[JOYBUS_N64_PAK_BLOCK_SIZE] = joybus_data_checksum(controller->response, JOYBUS_N64_PAK_BLOCK_SIZE); + controller->response[JOYBUS_N64_PAK_BLOCK_SIZE] = + joybus_data_checksum(controller->response, JOYBUS_N64_PAK_BLOCK_SIZE); } else { // Prepare a zero response with the "no pak" CRC, which the host treats as a transfer error memset(controller->response, 0, JOYBUS_CMD_N64_PAK_READ_RX); @@ -249,7 +250,7 @@ static int n64_controller_byte_received(struct joybus_target *target, const uint return -JOYBUS_ERR_NOT_SUPPORTED; } -static const struct joybus_target_api n64_controller_api = { +static JOYBUS_RAM_DATA const struct joybus_target_api n64_controller_api = { .byte_received = n64_controller_byte_received, }; diff --git a/src/target/n64_pak_controller.c b/src/target/n64_pak_controller.c index af67fec..86db712 100644 --- a/src/target/n64_pak_controller.c +++ b/src/target/n64_pak_controller.c @@ -98,7 +98,7 @@ static int memory_write_block(struct joybus_target_n64_pak_controller *pak_contr return 0; } -static const struct joybus_target_n64_pak_api pak_controller_api = { +static JOYBUS_RAM_DATA const struct joybus_target_n64_pak_api pak_controller_api = { .read_block = pak_controller_read_block, .write_block = pak_controller_write_block, }; diff --git a/src/target/n64_pak_rumble.c b/src/target/n64_pak_rumble.c index e9ffb5b..3e9eefa 100644 --- a/src/target/n64_pak_rumble.c +++ b/src/target/n64_pak_rumble.c @@ -59,7 +59,7 @@ static int pak_rumble_write_block(struct joybus_target_n64_pak *pak, uint16_t ad return 0; } -static const struct joybus_target_n64_pak_api pak_rumble_api = { +static JOYBUS_RAM_DATA const struct joybus_target_n64_pak_api pak_rumble_api = { .read_block = pak_rumble_read_block, .write_block = pak_rumble_write_block, }; diff --git a/src/target/pixelfx_gameid.c b/src/target/pixelfx_gameid.c index b99186d..4e206e1 100644 --- a/src/target/pixelfx_gameid.c +++ b/src/target/pixelfx_gameid.c @@ -28,7 +28,7 @@ static int pixelfx_gameid_byte_received(struct joybus_target *target, const uint return 0; } -static const struct joybus_target_api pixelfx_gameid_api = { +static JOYBUS_RAM_DATA const struct joybus_target_api pixelfx_gameid_api = { .byte_received = pixelfx_gameid_byte_received, };