-
-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add JOYSTICK_SERIAL_OUT system for outputting joystick data #978
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/* | ||
* Copyright (c) 2019-2023, Jacques Gagnon | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#include <string.h> | ||
#include "zephyr/types.h" | ||
#include "tools/util.h" | ||
#include "adapter/config.h" | ||
#include "adapter/kb_monitor.h" | ||
#include "adapter/wired/wired.h" | ||
#include "joystick_serial_out.h" | ||
|
||
enum { | ||
JOYSTICK_SERIAL_OUT_SELECT = 0, | ||
JOYSTICK_SERIAL_OUT_L3, | ||
JOYSTICK_SERIAL_OUT_R3, | ||
JOYSTICK_SERIAL_OUT_START, | ||
JOYSTICK_SERIAL_OUT_D_UP, | ||
JOYSTICK_SERIAL_OUT_D_RIGHT, | ||
JOYSTICK_SERIAL_OUT_D_DOWN, | ||
JOYSTICK_SERIAL_OUT_D_LEFT, | ||
JOYSTICK_SERIAL_OUT_L2, | ||
JOYSTICK_SERIAL_OUT_R2, | ||
JOYSTICK_SERIAL_OUT_L1, | ||
JOYSTICK_SERIAL_OUT_R1, | ||
JOYSTICK_SERIAL_OUT_Y, | ||
JOYSTICK_SERIAL_OUT_B, | ||
JOYSTICK_SERIAL_OUT_A, | ||
JOYSTICK_SERIAL_OUT_X, | ||
}; | ||
|
||
static DRAM_ATTR const uint8_t joystick_serial_out_axes_idx[ADAPTER_MAX_AXES] = | ||
{ | ||
/* AXIS_LX, AXIS_LY, AXIS_RX, AXIS_RY, TRIG_L, TRIG_R */ | ||
0, 1, 2, 3, 4, 5 | ||
}; | ||
|
||
static DRAM_ATTR const struct ctrl_meta joystick_serial_out_axes_meta[ADAPTER_MAX_AXES] = | ||
{ | ||
{.size_min = -128, .size_max = 127, .neutral = 0x80, .abs_max = 0x7F, .abs_min = 0x80}, | ||
{.size_min = -128, .size_max = 127, .neutral = 0x80, .abs_max = 0x7F, .abs_min = 0x80, .polarity = 1}, | ||
{.size_min = -128, .size_max = 127, .neutral = 0x80, .abs_max = 0x7F, .abs_min = 0x80}, | ||
{.size_min = -128, .size_max = 127, .neutral = 0x80, .abs_max = 0x7F, .abs_min = 0x80, .polarity = 1}, | ||
{.size_min = 0, .size_max = 255, .neutral = 0x00, .abs_max = 0xFF, .abs_min = 0x00}, | ||
{.size_min = 0, .size_max = 255, .neutral = 0x00, .abs_max = 0xFF, .abs_min = 0x00}, | ||
}; | ||
|
||
struct joystick_serial_out_map { | ||
uint16_t buttons; | ||
uint8_t axes[6]; | ||
} __packed; | ||
|
||
static const uint32_t joystick_serial_out_mask[4] = {0xBB7F0FFF, 0x00000000, 0x00000000, BR_COMBO_MASK}; | ||
static const uint32_t joystick_serial_out_desc[4] = {0x110000FF, 0x00000000, 0x00000000, 0x00000000}; | ||
static DRAM_ATTR const uint32_t joystick_serial_out_btns_mask[32] = { | ||
0, 0, 0, 0, | ||
0, 0, 0, 0, | ||
BIT(JOYSTICK_SERIAL_OUT_D_LEFT), BIT(JOYSTICK_SERIAL_OUT_D_RIGHT), BIT(JOYSTICK_SERIAL_OUT_D_DOWN), BIT(JOYSTICK_SERIAL_OUT_D_UP), | ||
0, 0, 0, 0, | ||
BIT(JOYSTICK_SERIAL_OUT_X), BIT(JOYSTICK_SERIAL_OUT_B), BIT(JOYSTICK_SERIAL_OUT_A), BIT(JOYSTICK_SERIAL_OUT_Y), | ||
BIT(JOYSTICK_SERIAL_OUT_START), BIT(JOYSTICK_SERIAL_OUT_SELECT), 0, 0, | ||
0, BIT(JOYSTICK_SERIAL_OUT_L1), 0, BIT(JOYSTICK_SERIAL_OUT_L3), | ||
0, BIT(JOYSTICK_SERIAL_OUT_R1), 0, BIT(JOYSTICK_SERIAL_OUT_R3), | ||
}; | ||
|
||
void IRAM_ATTR joystick_serial_out_init_buffer(int32_t dev_mode, struct wired_data *wired_data) { | ||
struct joystick_serial_out_map *map = (struct joystick_serial_out_map *)wired_data->output; | ||
struct joystick_serial_out_map *map_mask = (struct joystick_serial_out_map *)wired_data->output_mask; | ||
memset((void *)map, 0, sizeof(*map)); | ||
|
||
map->buttons = 0xFFFF; | ||
map_mask->buttons = 0x0000; | ||
for (uint32_t i = 0; i < ADAPTER_MAX_AXES; i++) { | ||
map->axes[joystick_serial_out_axes_idx[i]] = joystick_serial_out_axes_meta[i].neutral; | ||
} | ||
memset(map_mask->axes, 0x00, sizeof(map_mask->axes)); | ||
} | ||
|
||
void joystick_serial_out_meta_init(struct wired_ctrl *ctrl_data) { | ||
memset((void *)ctrl_data, 0, sizeof(*ctrl_data)*WIRED_MAX_DEV); | ||
|
||
for (uint32_t i = 0; i < WIRED_MAX_DEV; i++) { | ||
for (uint32_t j = 0; j < ADAPTER_MAX_AXES; j++) { | ||
ctrl_data[i].mask = joystick_serial_out_mask; | ||
ctrl_data[i].desc = joystick_serial_out_desc; | ||
ctrl_data[i].axes[j].meta = &joystick_serial_out_axes_meta[j]; | ||
} | ||
} | ||
} | ||
|
||
static void joystick_serial_out_ctrl_from_generic(struct wired_ctrl *ctrl_data, struct wired_data *wired_data) { | ||
struct joystick_serial_out_map map_tmp; | ||
uint32_t map_mask = 0xFFFF; | ||
|
||
memcpy((void *)&map_tmp, wired_data->output, sizeof(map_tmp)); | ||
|
||
for (uint32_t i = 0; i < ARRAY_SIZE(generic_btns_mask); i++) { | ||
if (ctrl_data->map_mask[0] & generic_btns_mask[i]) { | ||
if (ctrl_data->btns[0].value & generic_btns_mask[i]) { | ||
map_tmp.buttons |= joystick_serial_out_btns_mask[i]; | ||
map_mask &= ~joystick_serial_out_btns_mask[i]; | ||
wired_data->cnt_mask[i] = ctrl_data->btns[0].cnt_mask[i]; | ||
} | ||
else if (map_mask & joystick_serial_out_btns_mask[i]) { | ||
map_tmp.buttons &= ~joystick_serial_out_btns_mask[i]; | ||
wired_data->cnt_mask[i] = 0; | ||
} | ||
} | ||
} | ||
|
||
for (uint32_t i = 0; i < ADAPTER_MAX_AXES; i++) { | ||
if (ctrl_data->map_mask[0] & (axis_to_btn_mask(i) & joystick_serial_out_desc[0])) { | ||
if (ctrl_data->axes[i].value > ctrl_data->axes[i].meta->size_max) { | ||
map_tmp.axes[joystick_serial_out_axes_idx[i]] = 255; | ||
} | ||
else if (ctrl_data->axes[i].value < ctrl_data->axes[i].meta->size_min) { | ||
map_tmp.axes[joystick_serial_out_axes_idx[i]] = 0; | ||
} | ||
else { | ||
map_tmp.axes[joystick_serial_out_axes_idx[i]] = (uint8_t)(ctrl_data->axes[i].value + ctrl_data->axes[i].meta->neutral); | ||
} | ||
} | ||
wired_data->cnt_mask[axis_to_btn_id(i)] = ctrl_data->axes[i].cnt_mask; | ||
} | ||
|
||
memcpy(wired_data->output, (void *)&map_tmp, sizeof(map_tmp)); | ||
#ifdef CONFIG_BLUERETRO_RAW_OUTPUT | ||
printf("{\"log_type\": \"wired_output\", \"axes\": [%d, %d, %d, %d, %d, %d], \"btns\": [%d, %d]}\n", | ||
map_tmp.axes[joystick_serial_out_axes_idx[0]], map_tmp.axes[joystick_serial_out_axes_idx[1]], | ||
map_tmp.axes[joystick_serial_out_axes_idx[2]], map_tmp.axes[joystick_serial_out_axes_idx[3]], | ||
map_tmp.axes[joystick_serial_out_axes_idx[4]], map_tmp.axes[joystick_serial_out_axes_idx[5]], | ||
map_tmp.buttons, map_tmp.analog_btn); | ||
#endif | ||
} | ||
|
||
void joystick_serial_out_from_generic(int32_t dev_mode, struct wired_ctrl *ctrl_data, struct wired_data *wired_data) { | ||
joystick_serial_out_ctrl_from_generic(ctrl_data, wired_data); | ||
} | ||
|
||
void IRAM_ATTR joystick_serial_out_gen_turbo_mask(struct wired_data *wired_data) { | ||
struct joystick_serial_out_map *map_mask = (struct joystick_serial_out_map *)wired_data->output_mask; | ||
|
||
map_mask->buttons = 0xFFFF; | ||
memset(map_mask->axes, 0x00, sizeof(map_mask->axes)); | ||
|
||
wired_gen_turbo_mask_btns16_pos(wired_data, &map_mask->buttons, joystick_serial_out_btns_mask); | ||
wired_gen_turbo_mask_axes8(wired_data, map_mask->axes, ADAPTER_MAX_AXES, joystick_serial_out_axes_idx, joystick_serial_out_axes_meta); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright (c) 2019-2022, Jacques Gagnon | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef _JOYSTICK_SERIAL_OUT_H_ | ||
#define _JOYSTICK_SERIAL_OUT_H_ | ||
#include "adapter/adapter.h" | ||
|
||
void joystick_serial_out_meta_init(struct wired_ctrl *ctrl_data); | ||
void joystick_serial_out_init_buffer(int32_t dev_mode, struct wired_data *wired_data); | ||
void joystick_serial_out_from_generic(int32_t dev_mode, struct wired_ctrl *ctrl_data, struct wired_data *wired_data); | ||
void joystick_serial_out_gen_turbo_mask(struct wired_data *wired_data); | ||
|
||
#endif /* _JOYSTICK_SERIAL_OUT_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y | |
# Can't use SRAM1 for IRAM as it conflict with un-updatable bootloaders in the wild :@ . | ||
# CONFIG_ESP_SYSTEM_ESP32_SRAM1_REGION_AS_IRAM=y | ||
CONFIG_ESP_CONSOLE_UART_CUSTOM=y | ||
CONFIG_ESP_CONSOLE_UART_BAUDRATE=921600 | ||
CONFIG_ESP_CONSOLE_UART_BAUDRATE=1000000 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default baud rate of 921600 does not play nice with Arduino Pro Micro. The data comes across all garbled. Tested with the following baud rates and had no problems connecting Arduino. |
||
CONFIG_ESP_COREDUMP_ENABLE_TO_UART=y | ||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n | ||
CONFIG_ESP_WIFI_IRAM_OPT=n | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this enum was added so I could minimize the number of characters needed to represent the 15 buttons of the controller. With this new enum only 5 characters are needed.