Arcade ctrls fixes
This commit is contained in:
Родитель
7e42cd56c8
Коммит
b64c23a996
2
Makefile
2
Makefile
|
@ -1,5 +1,5 @@
|
|||
TARGET ?= jm-v2.0
|
||||
PROF ?= dpad
|
||||
PROF ?= arcade
|
||||
FORCE ?=
|
||||
|
||||
.SECONDARY: # this prevents object files from being removed
|
||||
|
|
14
jd/gamepad.c
14
jd/gamepad.c
|
@ -46,7 +46,9 @@ struct srv_state {
|
|||
uint8_t prev_pressed;
|
||||
uint8_t num_zero;
|
||||
uint8_t num_pins;
|
||||
uint8_t active;
|
||||
const uint8_t *button_pins;
|
||||
const uint8_t *led_pins;
|
||||
uint32_t press_time;
|
||||
uint32_t nextSample;
|
||||
};
|
||||
|
@ -55,14 +57,16 @@ static uint32_t buttons_state(srv_t *state) {
|
|||
if (!state->inited) {
|
||||
state->inited = true;
|
||||
for (int i = 0; i < state->num_pins; ++i) {
|
||||
pin_setup_input(state->button_pins[i], 1);
|
||||
pin_setup_input(state->button_pins[i], state->active ? -1 : 1);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t r = 0;
|
||||
|
||||
for (int i = 0; i < state->num_pins; ++i) {
|
||||
if (pin_get(state->button_pins[i]) == 0) {
|
||||
if (state->button_pins[i] == 0xff)
|
||||
continue;
|
||||
if (pin_get(state->button_pins[i]) == state->active) {
|
||||
r |= (1 << i);
|
||||
}
|
||||
}
|
||||
|
@ -136,9 +140,11 @@ void gamepad_handle_packet(srv_t *state, jd_packet_t *pkt) {
|
|||
|
||||
SRV_DEF(gamepad, JD_SERVICE_CLASS_ARCADE_CONTROLS);
|
||||
|
||||
void gamepad_init(uint8_t num_pins, const uint8_t *pins) {
|
||||
void gamepad_init(uint8_t num_pins, const uint8_t *pins, const uint8_t *ledPins) {
|
||||
SRV_ALLOC(gamepad);
|
||||
update(state);
|
||||
state->num_pins = num_pins;
|
||||
state->button_pins = pins;
|
||||
state->led_pins = ledPins;
|
||||
state->active = ledPins ? 1 : 0;
|
||||
update(state);
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ void touch_init(uint8_t pin);
|
|||
void oled_init(void);
|
||||
void temp_init(void);
|
||||
void humidity_init(void);
|
||||
void gamepad_init(uint8_t num_pins, const uint8_t *pins);
|
||||
void gamepad_init(uint8_t num_pins, const uint8_t *pins, const uint8_t *ledPins);
|
||||
void power_init(void);
|
||||
|
||||
extern const char app_dev_class_name[];
|
|
@ -54,5 +54,5 @@
|
|||
#define PC_14 0x2E
|
||||
#define PC_15 0x2F
|
||||
|
||||
#define PF_0 0x5F
|
||||
#define PF_1 0x5F
|
||||
#define PF_0 0x50
|
||||
#define PF_1 0x51
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
#define PIN_LOG2 -1 // sig error
|
||||
#define PIN_LOG3 -1
|
||||
|
||||
#define PIN_PWR PA_10
|
||||
#define PIN_P0 PF_0
|
||||
#define PIN_P1 PF_1
|
||||
#define PIN_PWR -1
|
||||
#define PIN_P0 -1
|
||||
#define PIN_P1 -1
|
||||
|
||||
#define PIN_SERVO PA_7
|
||||
#define PIN_AMOSI PA_7
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
#include "jdprofile.h"
|
||||
|
||||
DEVICE_CLASS(0x38e3c25c, "JM ArcadeCtrls v2.0");
|
||||
|
||||
// left, up, right, down, a, b, menu, menu2, reset, exit
|
||||
static const uint8_t btnPins[] = {PA_2, PA_5, PA_4, PA_3, PF_0, PF_1, PA_10, -1, PA_0};
|
||||
static const uint8_t ledPins[] = {-1, -1, -1, -1, PA_6, PA_7, PB_1, -1, -1};
|
||||
|
||||
void init_services() {
|
||||
gamepad_init(sizeof(btnPins), btnPins, ledPins);
|
||||
}
|
|
@ -6,5 +6,5 @@ DEVICE_CLASS(0x36d257aa, "JM D-Pad v2.0");
|
|||
static const uint8_t btnPins[] = {PA_2, PA_5, PA_4, PA_3, PA_6, PA_7, PB_1, -1, PA_10};
|
||||
|
||||
void init_services() {
|
||||
gamepad_init(sizeof(btnPins), btnPins);
|
||||
gamepad_init(sizeof(btnPins), btnPins, NULL);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче