-
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d402c18
commit 42de0a0
Showing
4 changed files
with
93 additions
and
6 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include <string.h> | ||
#include "../zephyr/types.h" | ||
#include "../util.h" | ||
#include "npiso.h" | ||
|
||
enum { | ||
NPISO_LD_RIGHT = 0, | ||
NPISO_LD_LEFT, | ||
NPISO_LD_DOWN, | ||
NPISO_LD_UP, | ||
NPISO_START, | ||
NPISO_SELECT, | ||
NPISO_Y, | ||
NPISO_B, | ||
NPISO_R = 12, | ||
NPISO_L, | ||
NPISO_X, | ||
NPISO_A, | ||
}; | ||
|
||
const struct ctrl_meta npiso_btns_meta = | ||
{ | ||
.polarity = 1, | ||
}; | ||
|
||
struct npiso_map { | ||
uint16_t buttons; | ||
} __packed; | ||
|
||
const uint32_t npiso_mask[4] = {0x113F0F00, 0x00000000, 0x00000000, 0x00000000}; | ||
const uint32_t npiso_desc[4] = {0x00000000, 0x00000000, 0x00000000, 0x00000000}; | ||
|
||
const uint32_t npiso_btns_mask[32] = { | ||
0, 0, 0, 0, | ||
0, 0, 0, 0, | ||
BIT(NPISO_LD_LEFT), BIT(NPISO_LD_RIGHT), BIT(NPISO_LD_DOWN), BIT(NPISO_LD_UP), | ||
0, 0, 0, 0, | ||
BIT(NPISO_Y), BIT(NPISO_A), BIT(NPISO_B), BIT(NPISO_X), | ||
BIT(NPISO_START), BIT(NPISO_SELECT), 0, 0, | ||
BIT(NPISO_L), 0, 0, 0, | ||
BIT(NPISO_R), 0, 0, 0, | ||
}; | ||
|
||
void npiso_init_buffer(int32_t dev_mode, struct wired_data *wired_data) { | ||
struct npiso_map *map = (struct npiso_map *)wired_data->output; | ||
|
||
map->buttons = 0xFFFF; | ||
} | ||
|
||
void npiso_meta_init(int32_t dev_mode, struct generic_ctrl *ctrl_data) { | ||
memset((void *)ctrl_data, 0, sizeof(*ctrl_data)*WIRED_MAX_DEV); | ||
|
||
for (uint32_t i = 0; i < WIRED_MAX_DEV; i++) { | ||
ctrl_data[i].mask = npiso_mask; | ||
ctrl_data[i].desc = npiso_desc; | ||
} | ||
} | ||
|
||
void npiso_from_generic(int32_t dev_mode, struct generic_ctrl *ctrl_data, struct wired_data *wired_data) { | ||
struct npiso_map map_tmp; | ||
|
||
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] & BIT(i)) { | ||
if (ctrl_data->btns[0].value & generic_btns_mask[i]) { | ||
map_tmp.buttons &= ~npiso_btns_mask[i]; | ||
} | ||
else { | ||
map_tmp.buttons |= npiso_btns_mask[i]; | ||
} | ||
} | ||
} | ||
|
||
memcpy(wired_data->output, (void *)&map_tmp, sizeof(map_tmp)); | ||
} |
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,9 @@ | ||
#ifndef _NPISO_H_ | ||
#define _NPISO_H_ | ||
#include "adapter.h" | ||
|
||
void npiso_meta_init(int32_t dev_mode, struct generic_ctrl *ctrl_data); | ||
void npiso_init_buffer(int32_t dev_mode, struct wired_data *wired_data); | ||
void npiso_from_generic(int32_t dev_mode, struct generic_ctrl *ctrl_data, struct wired_data *wired_data); | ||
|
||
#endif /* _NPISO_H_ */ |