diff --git a/main/adapter/adapter.h b/main/adapter/adapter.h index 2abc3d76..a7b52eaf 100755 --- a/main/adapter/adapter.h +++ b/main/adapter/adapter.h @@ -13,6 +13,7 @@ #define BT_MAX_DEV 7 /* BT limitation */ #define WIRED_MAX_DEV 12 /* Saturn limit */ +#define ADAPTER_MAX_AXES 6 #define REPORT_MAX_USAGE 16 /* BT device ID */ @@ -305,7 +306,7 @@ struct generic_ctrl { const uint32_t *desc; uint32_t map_mask[4]; struct ctrl btns[4]; - struct ctrl axes[6]; + struct ctrl axes[ADAPTER_MAX_AXES]; }; struct generic_fb { @@ -351,7 +352,7 @@ struct bt_data { int32_t report_type; struct hid_report reports[REPORT_MAX]; uint8_t input[128]; - int32_t axes_cal[6]; + int32_t axes_cal[ADAPTER_MAX_AXES]; uint32_t sdp_len; uint8_t sdp_data[2048]; } __packed; diff --git a/main/adapter/dc.c b/main/adapter/dc.c index 2cda7297..285ac5d3 100644 --- a/main/adapter/dc.c +++ b/main/adapter/dc.c @@ -22,7 +22,7 @@ enum { DC_LD_RIGHT, }; -const uint8_t dc_axes_idx[6] = +const uint8_t dc_axes_idx[ADAPTER_MAX_AXES] = { /* AXIS_LX, AXIS_LY, AXIS_RX, AXIS_RY, TRIG_L, TRIG_R */ 7, 6, 5, 4, 0, 1 @@ -33,7 +33,7 @@ const struct ctrl_meta dc_btns_meta = .polarity = 1, }; -const struct ctrl_meta dc_axes_meta[6] = +const struct ctrl_meta dc_axes_meta[ADAPTER_MAX_AXES] = { {.size_min = -128, .size_max = 127, .neutral = 0x80, .abs_max = 0x80}, {.size_min = -128, .size_max = 127, .neutral = 0x80, .abs_max = 0x80, .polarity = 1}, @@ -71,7 +71,7 @@ void dc_init_buffer(int32_t dev_mode, struct wired_data *wired_data) { struct dc_map *map = (struct dc_map *)wired_data->output; map->buttons = 0xFFFF; - for (uint32_t i = 0; i < ARRAY_SIZE(dc_axes_meta); i++) { + for (uint32_t i = 0; i < ADAPTER_MAX_AXES; i++) { map->axes[dc_axes_idx[i]] = dc_axes_meta[i].neutral; } } @@ -80,7 +80,7 @@ void dc_meta_init(int32_t dev_mode, struct generic_ctrl *ctrl_data) { memset((void *)ctrl_data, 0, sizeof(*ctrl_data)*4); for (uint32_t i = 0; i < WIRED_MAX_DEV; i++) { - for (uint32_t j = 0; j < ARRAY_SIZE(dc_axes_meta); j++) { + for (uint32_t j = 0; j < ADAPTER_MAX_AXES; j++) { ctrl_data[i].mask = dc_mask; ctrl_data[i].desc = dc_desc; ctrl_data[i].axes[j].meta = &dc_axes_meta[j]; @@ -104,7 +104,7 @@ void dc_from_generic(int32_t dev_mode, struct generic_ctrl *ctrl_data, struct wi } } - for (uint32_t i = 0; i < ARRAY_SIZE(dc_axes_meta); i++) { + for (uint32_t i = 0; i < ADAPTER_MAX_AXES; i++) { if (ctrl_data->map_mask[0] & (axis_to_btn_mask(i) & dc_desc[0])) { if (ctrl_data->axes[i].value > ctrl_data->axes[i].meta->size_max) { map_tmp.axes[dc_axes_idx[i]] = 255; diff --git a/main/adapter/gc.c b/main/adapter/gc.c index 4470cc2c..52275b95 100644 --- a/main/adapter/gc.c +++ b/main/adapter/gc.c @@ -18,7 +18,7 @@ enum { GC_L, }; -const uint8_t gc_axes_idx[6] = +const uint8_t gc_axes_idx[ADAPTER_MAX_AXES] = { /* AXIS_LX, AXIS_LY, AXIS_RX, AXIS_RY, TRIG_L, TRIG_R */ 0, 1, 2, 3, 4, 5 @@ -29,7 +29,7 @@ const struct ctrl_meta gc_btns_meta = .polarity = 0, }; -const struct ctrl_meta gc_axes_meta[6] = +const struct ctrl_meta gc_axes_meta[ADAPTER_MAX_AXES] = { {.size_min = -128, .size_max = 127, .neutral = 0x80, .abs_max = 0x64}, {.size_min = -128, .size_max = 127, .neutral = 0x80, .abs_max = 0x64}, @@ -62,7 +62,7 @@ void gc_init_buffer(int32_t dev_mode, struct wired_data *wired_data) { struct gc_map *map = (struct gc_map *)wired_data->output; map->buttons = 0x8020; - for (uint32_t i = 0; i < ARRAY_SIZE(gc_axes_meta); i++) { + for (uint32_t i = 0; i < ADAPTER_MAX_AXES; i++) { map->axes[gc_axes_idx[i]] = gc_axes_meta[i].neutral; } } @@ -71,7 +71,7 @@ void gc_meta_init(int32_t dev_mode, struct generic_ctrl *ctrl_data) { memset((void *)ctrl_data, 0, sizeof(*ctrl_data)*4); for (uint32_t i = 0; i < WIRED_MAX_DEV; i++) { - for (uint32_t j = 0; j < ARRAY_SIZE(gc_axes_meta); j++) { + for (uint32_t j = 0; j < ADAPTER_MAX_AXES; j++) { ctrl_data[i].mask = gc_mask; ctrl_data[i].desc = gc_desc; ctrl_data[i].axes[j].meta = &gc_axes_meta[j]; @@ -97,7 +97,7 @@ void gc_from_generic(int32_t dev_mode, struct generic_ctrl *ctrl_data, struct wi } } - for (uint32_t i = 0; i < ARRAY_SIZE(gc_axes_meta); i++) { + for (uint32_t i = 0; i < ADAPTER_MAX_AXES; i++) { if (ctrl_data->map_mask[0] & (axis_to_btn_mask(i) & gc_desc[0])) { if (ctrl_data->axes[i].value > ctrl_data->axes[i].meta->size_max) { map_tmp.axes[gc_axes_idx[i]] = 127; diff --git a/main/adapter/hid_generic.c b/main/adapter/hid_generic.c index f7510368..44ad7761 100644 --- a/main/adapter/hid_generic.c +++ b/main/adapter/hid_generic.c @@ -8,9 +8,9 @@ struct hid_report_meta { int8_t hid_btn_idx; - int8_t hid_axes_idx[6]; + int8_t hid_axes_idx[ADAPTER_MAX_AXES]; int8_t hid_hat_idx; - struct ctrl_meta hid_axes_meta[6]; + struct ctrl_meta hid_axes_meta[ADAPTER_MAX_AXES]; uint32_t hid_mask[4]; uint32_t hid_desc[4]; uint32_t hid_btns_mask[32]; @@ -211,13 +211,13 @@ static void hid_mouse_to_generic(struct bt_data *bt_data, struct generic_ctrl *c } if (!atomic_test_bit(&bt_data->flags, BT_INIT)) { - for (uint32_t i = 0; i < sizeof(meta->hid_axes_idx); i++) { + for (uint32_t i = 0; i < ADAPTER_MAX_AXES; i++) { bt_data->axes_cal[i] = meta->hid_axes_meta[i].neutral; } atomic_set_bit(&bt_data->flags, BT_INIT); } - for (uint32_t i = 0; i < sizeof(meta->hid_axes_idx); i++) { + for (uint32_t i = 0; i < ADAPTER_MAX_AXES; i++) { if (meta->hid_axes_idx[i] > -1) { int32_t len = bt_data->reports[MOUSE].usages[meta->hid_axes_idx[i]].bit_size; uint32_t offset = bt_data->reports[MOUSE].usages[meta->hid_axes_idx[i]].bit_offset; @@ -426,7 +426,7 @@ static void hid_pad_to_generic(struct bt_data *bt_data, struct generic_ctrl *ctr ctrl_data->btns[0].value |= hat_to_ld_btns[(hat - min) & 0xF]; } - for (uint32_t i = 0; i < sizeof(meta->hid_axes_idx); i++) { + for (uint32_t i = 0; i < ADAPTER_MAX_AXES; i++) { if (meta->hid_axes_idx[i] > -1) { int32_t len = bt_data->reports[PAD].usages[meta->hid_axes_idx[i]].bit_size; uint32_t offset = bt_data->reports[PAD].usages[meta->hid_axes_idx[i]].bit_offset; diff --git a/main/adapter/io.h b/main/adapter/io.h deleted file mode 100644 index 1bf366d4..00000000 --- a/main/adapter/io.h +++ /dev/null @@ -1,148 +0,0 @@ -#ifndef _IO_H_ -#define _IO_H_ - -#include -#include -#include "sd.h" - -#define BTN_DU 0x00 -#define BTN_DL 0x01 -#define BTN_DR 0x02 -#define BTN_DD 0x03 -#define BTN_LU 0x04 -#define BTN_LL 0x05 -#define BTN_LR 0x06 -#define BTN_LD 0x07 -#define BTN_BU 0x08 -#define BTN_BL 0x09 -#define BTN_BR 0x0A -#define BTN_BD 0x0B -#define BTN_RU 0x0C -#define BTN_RL 0x0D -#define BTN_RR 0x0E -#define BTN_RD 0x0F - -/* - * Setup analog triggers so their LSB is clear since they are positive axes - * and make sure both analog trigger has only 1 bit different (2nd bit). - */ -#define BTN_LA 0x10 -#define BTN_LM 0x11 -#define BTN_RA 0x12 -#define BTN_RM 0x13 -#define BTN_LS 0x14 -#define BTN_LG 0x15 -#define BTN_LJ 0x16 -#define BTN_RS 0x17 -#define BTN_RG 0x18 -#define BTN_RJ 0x19 - -#define BTN_SL 0x1A -#define BTN_HM 0x1B -#define BTN_ST 0x1C -#define BTN_BE 0x1D -#define BTN_MX 0x1E -#define BTN_NN 0x1F - -#define AXIS_LX 0x00 -#define AXIS_LY 0x01 -#define AXIS_RX 0x02 -#define AXIS_RY 0x03 -#define TRIG_L 0x04 -#define TRIG_R 0x05 - -#define WIIU_PRO_AXIS_SIGN 0 -#define WIIU_PRO_AXIS_NEUTRAL 0x800 -#define WIIU_PRO_AXIS_DEADZONE 0x00F -#define WIIU_PRO_AXIS_HALFWAY 0x200 -#define WIIU_PRO_AXIS_MAX 0x490 - -enum { - BTIO_UPDATE_CTRL -}; - -enum { - WRIO_RUMBLE_ON, - WRIO_SAVE_MEM -}; - -extern const uint32_t map_presets[8][32]; - -struct axis_meta { - int32_t neutral; - int32_t deadzone; - int32_t abs_btn_thrs; - int32_t abs_max; - int32_t sign; -}; - -struct axis { - int32_t value; - const struct axis_meta *meta; -}; - -#define IO_FORMAT_GENERIC 0x00 -struct generic_map { - uint32_t buttons; - struct axis axes[6]; -}; - -#define IO_FORMAT_NES 0x01 -struct nes_map { - uint8_t buttons; -} __packed; - -#define IO_FORMAT_SNES 0x02 -struct snes_map { - uint16_t buttons; -} __packed; - -#define IO_FORMAT_N64 0x03 -struct n64_map { - uint16_t buttons; - int8_t axes[2]; -} __packed; - -#define IO_FORMAT_GC 0x04 -struct gc_map { - uint16_t buttons; - uint8_t axes[6]; -} __packed; - -#define IO_FORMAT_WIIU_PRO 0x06 -struct wiiu_pro_map { - uint16_t axes[4]; - uint32_t buttons; -} __packed; - -#define IO_FORMAT_DC 0x07 -struct dc_map { - union { - struct { - uint16_t pad; - uint16_t buttons; - }; - int8_t axes[8]; - }; -} __packed; - -struct io { - int32_t flags; - uint8_t format; - uint8_t leds_rumble; - uint8_t mode; - uint8_t poll_cnt; - union { - struct nes_map nes; - struct snes_map snes; - struct n64_map n64; - struct gc_map gc; - struct wiiu_pro_map wiiu_pro; - struct dc_map dc; - } io; -} __packed; - -void translate_status(struct config *config, struct io *input, struct io* output); - -#endif /* _IO_H_ */ - diff --git a/main/adapter/n64.c b/main/adapter/n64.c index 88ea1552..e697fae9 100644 --- a/main/adapter/n64.c +++ b/main/adapter/n64.c @@ -3,6 +3,7 @@ #include "../util.h" #include "n64.h" +#define N64_AXES_MAX 2 enum { N64_LD_RIGHT, N64_LD_LEFT, @@ -20,7 +21,7 @@ enum { N64_L, }; -const uint8_t n64_axes_idx[2] = +const uint8_t n64_axes_idx[N64_AXES_MAX] = { /* AXIS_LX, AXIS_LY */ 0, 1 @@ -31,7 +32,7 @@ const struct ctrl_meta n64_btns_meta = .polarity = 0, }; -const struct ctrl_meta n64_axes_meta[2] = +const struct ctrl_meta n64_axes_meta[N64_AXES_MAX] = { {.size_min = -128, .size_max = 127, .neutral = 0x00, .abs_max = 0x54}, {.size_min = -128, .size_max = 127, .neutral = 0x00, .abs_max = 0x54}, @@ -72,7 +73,7 @@ void n64_init_buffer(int32_t dev_mode, struct wired_data *wired_data) { struct n64_map *map = (struct n64_map *)wired_data->output; map->buttons = 0x0000; - for (uint32_t i = 0; i < ARRAY_SIZE(n64_axes_meta); i++) { + for (uint32_t i = 0; i < N64_AXES_MAX; i++) { map->axes[n64_axes_idx[i]] = n64_axes_meta[i].neutral; } } @@ -81,7 +82,7 @@ void n64_meta_init(int32_t dev_mode, struct generic_ctrl *ctrl_data) { memset((void *)ctrl_data, 0, sizeof(*ctrl_data)*4); for (uint32_t i = 0; i < WIRED_MAX_DEV; i++) { - for (uint32_t j = 0; j < ARRAY_SIZE(n64_axes_meta); j++) { + for (uint32_t j = 0; j < N64_AXES_MAX; j++) { switch (dev_mode) { case DEV_MOUSE: ctrl_data[i].mask = n64_mouse_mask; @@ -117,7 +118,7 @@ static void n64_ctrl_from_generic(struct generic_ctrl *ctrl_data, struct wired_d } } - for (uint32_t i = 0; i < ARRAY_SIZE(n64_axes_meta); i++) { + for (uint32_t i = 0; i < N64_AXES_MAX; i++) { if (ctrl_data->map_mask[0] & (axis_to_btn_mask(i) & n64_desc[0])) { if (ctrl_data->axes[i].value > ctrl_data->axes[i].meta->size_max) { map_tmp.axes[n64_axes_idx[i]] = 127; @@ -152,7 +153,7 @@ static void n64_mouse_from_generic(struct generic_ctrl *ctrl_data, struct wired_ } } - for (uint32_t i = 0; i < ARRAY_SIZE(n64_axes_meta); i++) { + for (uint32_t i = 0; i < N64_AXES_MAX; i++) { if (ctrl_data->map_mask[0] & (axis_to_btn_mask(i + 2) & n64_mouse_desc[0])) { if (ctrl_data->axes[i + 2].value > ctrl_data->axes[i + 2].meta->size_max) { map_tmp.axes[n64_axes_idx[i]] = 127; diff --git a/main/adapter/ps3.c b/main/adapter/ps3.c index 356c0e2a..ca109e77 100644 --- a/main/adapter/ps3.c +++ b/main/adapter/ps3.c @@ -35,7 +35,7 @@ static const uint8_t ps3_config[] = { 0x00, 0x00, 0x00 }; -const uint8_t ps3_axes_idx[6] = +const uint8_t ps3_axes_idx[ADAPTER_MAX_AXES] = { /* AXIS_LX, AXIS_LY, AXIS_RX, AXIS_RY, TRIG_L, TRIG_R */ 0, 1, 2, 3, 12, 13 @@ -46,7 +46,7 @@ const struct ctrl_meta ps3_btn_meta = .polarity = 0, }; -const struct ctrl_meta ps3_axes_meta[6] = +const struct ctrl_meta ps3_axes_meta[ADAPTER_MAX_AXES] = { {.neutral = 0x80, .abs_max = 0x80}, {.neutral = 0x80, .abs_max = 0x80, .polarity = 1}, @@ -102,17 +102,16 @@ void ps3_to_generic(struct bt_data *bt_data, struct generic_ctrl *ctrl_data) { } if (!atomic_test_bit(&bt_data->flags, BT_INIT)) { - for (uint32_t i = 0; i < ARRAY_SIZE(map->axes); i++) { + for (uint32_t i = 0; i < ADAPTER_MAX_AXES; i++) { bt_data->axes_cal[i] = -(map->axes[ps3_axes_idx[i]] - ps3_axes_meta[i].neutral); } atomic_set_bit(&bt_data->flags, BT_INIT); } - for (uint32_t i = 0; i < ARRAY_SIZE(map->axes); i++) { + for (uint32_t i = 0; i < ADAPTER_MAX_AXES; i++) { ctrl_data->axes[i].meta = &ps3_axes_meta[i]; ctrl_data->axes[i].value = map->axes[ps3_axes_idx[i]] - ps3_axes_meta[i].neutral + bt_data->axes_cal[i]; } - } void ps3_fb_from_generic(struct generic_fb *fb_data, struct bt_data *bt_data) { diff --git a/main/adapter/ps4.c b/main/adapter/ps4.c index 1ed12835..fc08e3f6 100644 --- a/main/adapter/ps4.c +++ b/main/adapter/ps4.c @@ -30,7 +30,7 @@ static const uint8_t ps4_led_dev_id_map[][3] = { {0x01, 0x01, 0x01}, }; -const uint8_t ps4_axes_idx[6] = +const uint8_t ps4_axes_idx[ADAPTER_MAX_AXES] = { /* AXIS_LX, AXIS_LY, AXIS_RX, AXIS_RY, TRIG_L, TRIG_R */ 0, 1, 2, 3, 7, 8 @@ -41,7 +41,7 @@ const struct ctrl_meta ps4_btn_meta = .polarity = 0, }; -const struct ctrl_meta ps4_axes_meta[6] = +const struct ctrl_meta ps4_axes_meta[ADAPTER_MAX_AXES] = { {.neutral = 0x80, .abs_max = 0x80}, {.neutral = 0x80, .abs_max = 0x80, .polarity = 1}, @@ -111,13 +111,13 @@ void ps4_to_generic(struct bt_data *bt_data, struct generic_ctrl *ctrl_data) { ctrl_data->btns[0].value |= hat_to_ld_btns[map->hat & 0xF]; if (!atomic_test_bit(&bt_data->flags, BT_INIT)) { - for (uint32_t i = 0; i < ARRAY_SIZE(map->axes); i++) { + for (uint32_t i = 0; i < ADAPTER_MAX_AXES; i++) { bt_data->axes_cal[i] = -(map->axes[ps4_axes_idx[i]] - ps4_axes_meta[i].neutral); } atomic_set_bit(&bt_data->flags, BT_INIT); } - for (uint32_t i = 0; i < ARRAY_SIZE(map->axes); i++) { + for (uint32_t i = 0; i < ADAPTER_MAX_AXES; i++) { ctrl_data->axes[i].meta = &ps4_axes_meta[i]; ctrl_data->axes[i].value = map->axes[ps4_axes_idx[i]] - ps4_axes_meta[i].neutral + bt_data->axes_cal[i]; } diff --git a/main/adapter/segaio.c b/main/adapter/segaio.c index 3abf4200..519368d4 100644 --- a/main/adapter/segaio.c +++ b/main/adapter/segaio.c @@ -19,7 +19,7 @@ enum { SATURN_R, }; -const uint8_t segaio_axes_idx[6] = +const uint8_t segaio_axes_idx[ADAPTER_MAX_AXES] = { /* AXIS_LX, AXIS_LY, AXIS_RX, AXIS_RY, TRIG_L, TRIG_R */ 0, 1, 0, 0, 3, 2 @@ -30,7 +30,7 @@ const struct ctrl_meta segaio_btns_meta = .polarity = 1, }; -const struct ctrl_meta segaio_axes_meta[6] = +const struct ctrl_meta segaio_axes_meta[ADAPTER_MAX_AXES] = { {.size_min = -128, .size_max = 127, .neutral = 0x80, .abs_max = 0x80}, {.size_min = -128, .size_max = 127, .neutral = 0x80, .abs_max = 0x80, .polarity = 1}, @@ -63,7 +63,7 @@ void segaio_init_buffer(int32_t dev_mode, struct wired_data *wired_data) { struct segaio_map *map = (struct segaio_map *)wired_data->output; map->buttons = 0xFFFF; - for (uint32_t i = 0; i < ARRAY_SIZE(segaio_axes_meta); i++) { + for (uint32_t i = 0; i < ADAPTER_MAX_AXES; i++) { if (i == 2 || i == 3) { continue; } @@ -77,7 +77,7 @@ void segaio_meta_init(int32_t dev_mode, struct generic_ctrl *ctrl_data) { for (uint32_t i = 0; i < WIRED_MAX_DEV; i++) { ctrl_data[i].mask = segaio_mask; ctrl_data[i].desc = segaio_desc; - for (uint32_t j = 0; j < ARRAY_SIZE(segaio_axes_meta); j++) { + for (uint32_t j = 0; j < ADAPTER_MAX_AXES; j++) { ctrl_data[i].axes[j].meta = &segaio_axes_meta[j]; } } @@ -99,7 +99,7 @@ void segaio_from_generic(int32_t dev_mode, struct generic_ctrl *ctrl_data, struc } } - for (uint32_t i = 0; i < ARRAY_SIZE(segaio_axes_meta); i++) { + for (uint32_t i = 0; i < ADAPTER_MAX_AXES; i++) { if (i == 2 || i == 3) { continue; } diff --git a/main/adapter/sw.c b/main/adapter/sw.c index cf22182d..f9463dc4 100644 --- a/main/adapter/sw.c +++ b/main/adapter/sw.c @@ -4,6 +4,7 @@ #include "sw.h" #define BT_HIDP_SW_SUBCMD_SET_LED 0x30 +#define SW_AXES_MAX 4 enum { SW_B, @@ -28,7 +29,7 @@ static const uint8_t led_dev_id_map[] = { 0x1, 0x2, 0x4, 0x8, 0x3, 0x6, 0xC }; -const uint8_t sw_axes_idx[4] = +const uint8_t sw_axes_idx[SW_AXES_MAX] = { /* AXIS_LX, AXIS_LY, AXIS_RX, AXIS_RY */ 0, 1, 2, 3 @@ -39,7 +40,7 @@ const struct ctrl_meta sw_btn_meta = .polarity = 0, }; -const struct ctrl_meta sw_axes_meta[] = +const struct ctrl_meta sw_axes_meta[SW_AXES_MAX] = { {.neutral = 0x8000, .abs_max = 0x5EEC, .deadzone = 0xB00}, {.neutral = 0x8000, .abs_max = 0x5EEC, .deadzone = 0xB00, .polarity = 1}, @@ -95,13 +96,13 @@ void sw_to_generic(struct bt_data *bt_data, struct generic_ctrl *ctrl_data) { ctrl_data->btns[0].value |= hat_to_ld_btns[map->hat & 0xF]; if (!atomic_test_bit(&bt_data->flags, BT_INIT)) { - for (uint32_t i = 0; i < ARRAY_SIZE(map->axes); i++) { + for (uint32_t i = 0; i < SW_AXES_MAX; i++) { bt_data->axes_cal[i] = -(map->axes[sw_axes_idx[i]] - sw_axes_meta[i].neutral); } atomic_set_bit(&bt_data->flags, BT_INIT); } - for (uint32_t i = 0; i < ARRAY_SIZE(map->axes); i++) { + for (uint32_t i = 0; i < SW_AXES_MAX; i++) { ctrl_data->axes[i].meta = &sw_axes_meta[i]; ctrl_data->axes[i].value = map->axes[sw_axes_idx[i]] - sw_axes_meta[i].neutral + bt_data->axes_cal[i]; } diff --git a/main/adapter/wii.c b/main/adapter/wii.c index 98337091..ee786652 100644 --- a/main/adapter/wii.c +++ b/main/adapter/wii.c @@ -3,6 +3,8 @@ #include "../util.h" #include "wii.h" +#define WIIU_AXES_MAX 4 +#define NUNCHUCK_AXES_MAX 2 enum { WII_CORE_D_LEFT = 0, WII_CORE_D_RIGHT, @@ -84,19 +86,19 @@ static const uint8_t led_dev_id_map[] = { 0x1, 0x2, 0x4, 0x8, 0x3, 0x6, 0xC }; -static const uint8_t wiiu_axes_idx[4] = +static const uint8_t wiiu_axes_idx[WIIU_AXES_MAX] = { /* AXIS_LX, AXIS_LY, AXIS_RX, AXIS_RY */ 0, 2, 1, 3 }; -static const struct ctrl_meta wiin_axes_meta[2] = +static const struct ctrl_meta wiin_axes_meta[NUNCHUCK_AXES_MAX] = { {.neutral = 0x80, .abs_max = 0x63}, {.neutral = 0x80, .abs_max = 0x63}, }; -static const struct ctrl_meta wiic_axes_meta[6] = +static const struct ctrl_meta wiic_axes_meta[ADAPTER_MAX_AXES] = { {.neutral = 0x20, .abs_max = 0x1B}, {.neutral = 0x20, .abs_max = 0x1B}, @@ -218,13 +220,13 @@ void wiin_to_generic(struct bt_data *bt_data, struct generic_ctrl *ctrl_data) { } if (!atomic_test_bit(&bt_data->flags, BT_INIT)) { - for (uint32_t i = 0; i < ARRAY_SIZE(wiin_axes_meta); i++) { + for (uint32_t i = 0; i < NUNCHUCK_AXES_MAX; i++) { bt_data->axes_cal[i] = -(map->axes[i] - wiin_axes_meta[i].neutral); } atomic_set_bit(&bt_data->flags, BT_INIT); } - for (uint32_t i = 0; i < ARRAY_SIZE(wiin_axes_meta); i++) { + for (uint32_t i = 0; i < NUNCHUCK_AXES_MAX; i++) { ctrl_data->axes[i].meta = &wiin_axes_meta[i]; ctrl_data->axes[i].value = map->axes[i] - wiin_axes_meta[i].neutral + bt_data->axes_cal[i]; } @@ -259,13 +261,13 @@ void wiic_to_generic(struct bt_data *bt_data, struct generic_ctrl *ctrl_data) { axes[5] = map->axes[3] & 0x1F; if (!atomic_test_bit(&bt_data->flags, BT_INIT)) { - for (uint32_t i = 0; i < ARRAY_SIZE(wiic_axes_meta); i++) { + for (uint32_t i = 0; i < ADAPTER_MAX_AXES; i++) { bt_data->axes_cal[i] = -(axes[i] - wiic_axes_meta[i].neutral); } atomic_set_bit(&bt_data->flags, BT_INIT); } - for (uint32_t i = 0; i < ARRAY_SIZE(wiic_axes_meta); i++) { + for (uint32_t i = 0; i < ADAPTER_MAX_AXES; i++) { ctrl_data->axes[i].meta = &wiic_axes_meta[i]; ctrl_data->axes[i].value = axes[i] - wiic_axes_meta[i].neutral + bt_data->axes_cal[i]; } @@ -286,13 +288,13 @@ void wiiu_to_generic(struct bt_data *bt_data, struct generic_ctrl *ctrl_data) { } if (!atomic_test_bit(&bt_data->flags, BT_INIT)) { - for (uint32_t i = 0; i < ARRAY_SIZE(map->axes); i++) { + for (uint32_t i = 0; i < WIIU_AXES_MAX; i++) { bt_data->axes_cal[i] = -(map->axes[wiiu_axes_idx[i]] - wiiu_axes_meta.neutral); } atomic_set_bit(&bt_data->flags, BT_INIT); } - for (uint32_t i = 0; i < ARRAY_SIZE(map->axes); i++) { + for (uint32_t i = 0; i < WIIU_AXES_MAX; i++) { ctrl_data->axes[i].meta = &wiiu_axes_meta; ctrl_data->axes[i].value = map->axes[wiiu_axes_idx[i]] - wiiu_axes_meta.neutral + bt_data->axes_cal[i]; } diff --git a/main/adapter/xb1.c b/main/adapter/xb1.c index 6f5ad5f6..407979fd 100644 --- a/main/adapter/xb1.c +++ b/main/adapter/xb1.c @@ -44,7 +44,7 @@ enum { XB1_ADAPTIVE_X4, }; -const uint8_t xb1_axes_idx[6] = +const uint8_t xb1_axes_idx[ADAPTER_MAX_AXES] = { /* AXIS_LX, AXIS_LY, AXIS_RX, AXIS_RY, TRIG_L, TRIG_R */ 0, 1, 2, 3, 4, 5 @@ -55,7 +55,7 @@ const struct ctrl_meta xb1_btn_meta = .polarity = 0, }; -const struct ctrl_meta xb1_axes_meta[6] = +const struct ctrl_meta xb1_axes_meta[ADAPTER_MAX_AXES] = { {.neutral = 0x8000, .abs_max = 0x8000}, {.neutral = 0x8000, .abs_max = 0x8000, .polarity = 1}, @@ -173,13 +173,13 @@ void xb1_to_generic(struct bt_data *bt_data, struct generic_ctrl *ctrl_data) { ctrl_data->btns[0].value |= hat_to_ld_btns[(map->hat - 1) & 0xF]; if (!atomic_test_bit(&bt_data->flags, BT_INIT)) { - for (uint32_t i = 0; i < ARRAY_SIZE(map->axes); i++) { + for (uint32_t i = 0; i < ADAPTER_MAX_AXES; i++) { bt_data->axes_cal[i] = -(map->axes[xb1_axes_idx[i]] - xb1_axes_meta[i].neutral); } atomic_set_bit(&bt_data->flags, BT_INIT); } - for (uint32_t i = 0; i < ARRAY_SIZE(map->axes); i++) { + for (uint32_t i = 0; i < ADAPTER_MAX_AXES; i++) { ctrl_data->axes[i].meta = &xb1_axes_meta[i]; ctrl_data->axes[i].value = map->axes[xb1_axes_idx[i]] - xb1_axes_meta[i].neutral + bt_data->axes_cal[i]; } diff --git a/main/bluetooth/hci.c b/main/bluetooth/hci.c index 5eea4d80..2e658b1b 100644 --- a/main/bluetooth/hci.c +++ b/main/bluetooth/hci.c @@ -927,6 +927,7 @@ void bt_hci_evt_hdlr(struct bt_hci_pkt *bt_hci_evt_pkt) { printf("# BT_HCI_EVT_DISCONN_COMPLETE\n"); bt_host_get_dev_from_handle(disconn_complete->handle, &device); if (device) { + printf("# DISCONN from dev: %d\n", device->id); bt_host_reset_dev(device); if (bt_host_get_active_dev(&device) == BT_NONE) { bt_hci_cmd_periodic_inquiry(NULL); @@ -935,12 +936,18 @@ void bt_hci_evt_hdlr(struct bt_hci_pkt *bt_hci_evt_pkt) { } else { bt_host_get_dev_conf(&device); - if (atomic_test_bit(&device->flags, BT_DEV_DEVICE_FOUND) && disconn_complete->handle == device->acl_handle) { - bt_host_reset_dev(device); - if (bt_host_get_active_dev(&device) == BT_NONE) { - bt_hci_cmd_le_set_adv_enable(NULL); + if (device && disconn_complete->handle == device->acl_handle) { + printf("# DISCONN from BLE config interface\n"); + if (atomic_test_bit(&device->flags, BT_DEV_DEVICE_FOUND)) { + bt_host_reset_dev(device); + if (bt_host_get_active_dev(&device) == BT_NONE) { + bt_hci_cmd_le_set_adv_enable(NULL); + } } } + else { + printf("# DISCONN for non existing device handle: %04X\n", disconn_complete->handle); + } } break; }