Skip to content

Commit

Permalink
last fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pellepl committed Mar 4, 2015
1 parent eef24bc commit 4b33f6e
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 108 deletions.
123 changes: 53 additions & 70 deletions src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,35 @@ static void device_send_report(device_info *d) {
memcpy(d->report_prev, d->report, d->report_len);
}

// lowlevel pin handling
static void device_check_report_dispatch(device_info *d, bool active) {
bool can_send = device_can_send(d);
if (d->report_filter) {
// relative reporting, do not send same report twice
if (arc_memcmp(d->report, d->report_prev, d->report_len) == 0) {
// report same as previous, do not send
d->pending_change = FALSE;
} else {
// report changed, send
if (can_send) {
device_send_report(d);
} else {
DBG(D_APP, D_DEBUG, "device %i:%i pending report\n", d->type, d->index);
d->pending_change = TRUE;
}
}
} else {
if (active) {
// absolute reporting, keep sending while any related pin is active
if (can_send) {
device_send_report(d);
} else {
d->pending_change = TRUE;
}
}
}
}

///////////////////////////////// PIN HANDLING

static void app_trigger_pin(u8_t pin, bool active) {
DBG(D_APP, D_DEBUG, "pin %i %s\n", (pin+1), active ? "!":"-");
Expand Down Expand Up @@ -440,37 +468,13 @@ static void app_pins_update(void) {
if (d->pending_change) continue;

bool active = d->construct_report(d, d->report);
bool can_send = device_can_send(d);
if (active) {
DBG(D_APP, D_DEBUG, "device %i:%i active\n", d->type, d->index);
} else {
DBG(D_APP, D_DEBUG, "device %i:%i inactive\n", d->type, d->index);
}

if (d->report_filter) {
// relative reporting, do not send same report twice
if (arc_memcmp(d->report, d->report_prev, d->report_len) == 0) {
// report same as previous, do not send
d->pending_change = FALSE;
} else {
// report changed, send
if (can_send) {
device_send_report(d);
} else {
DBG(D_APP, D_DEBUG, "device %i:%i pending report\n", d->type, d->index);
d->pending_change = TRUE;
}
}
} else {
if (active) {
// absolute reporting, keep sending while any related pin is active
if (can_send) {
device_send_report(d);
} else {
d->pending_change = TRUE;
}
}
}
device_check_report_dispatch(d, active);

if (active && !d->timer_started) {
// device pin pressed, start polling timer
Expand Down Expand Up @@ -525,31 +529,7 @@ static void app_device_timer_task(u32_t ignore, void *d_v) {
}
}

bool can_send = device_can_send(d);

if (d->report_filter) {
// relative reporting, do not send same report twice
if (arc_memcmp(d->report, d->report_prev, d->report_len) == 0) {
// report same as previous, do not send
d->pending_change = FALSE;
} else {
// report changed, send
if (can_send) {
device_send_report(d);
} else {
d->pending_change = TRUE;
}
}
} else {
// absolute reporting, keep sending while any related pin is active
if (active) {
if (can_send) {
device_send_report(d);
} else {
d->pending_change = TRUE;
}
}
}
device_check_report_dispatch(d, active);

if (!active) {
// no pins pressed, so stop polling this device
Expand Down Expand Up @@ -667,34 +647,36 @@ static void app_config_default(void) {
cfg.id[0].joy.joystick_code = JOYSTICK2_Y;
cfg.id[0].joy.joystick_sign = 1;
cfg.id[0].joy.joystick_data = 127;
APP_cfg_set_pin(&cfg);
// pin14 = JOYSTICK2_Y(127)
// pin14 = JOYSTICK2_Y(-127)
cfg.pin = 14;
cfg.id[0].joy.joystick_sign = 0;
APP_cfg_set_pin(&cfg);
// pin15 = JOYSTICK2_X(-127)
// pin15 = JOYSTICK2_Y(127)
cfg.pin = 15;
cfg.id[0].joy.joystick_sign = 0;
APP_cfg_set_pin(&cfg);
// pin16 = JOYSTICK2_X(-127)
cfg.pin = 16;
cfg.id[0].joy.joystick_code = JOYSTICK2_X;
cfg.id[0].joy.joystick_sign = 1;
APP_cfg_set_pin(&cfg);
// pin16 = JOYSTICK2_X(127)
cfg.pin = 16;
// pin17 = JOYSTICK2_X(127)
cfg.pin = 17;
cfg.id[0].joy.joystick_sign = 0;
APP_cfg_set_pin(&cfg);
// pin17 = JOYSTICK2_BUTTON1
cfg.pin = 17;
// pin18 = JOYSTICK2_BUTTON1
cfg.pin = 18;
cfg.id[0].joy.joystick_code = JOYSTICK2_BUTTON1;
APP_cfg_set_pin(&cfg);
// pin18 = JOYSTICK2_BUTTON2
cfg.pin = 18;
// pin19 = JOYSTICK2_BUTTON2
cfg.pin = 19;
cfg.id[0].joy.joystick_code = JOYSTICK2_BUTTON2;
APP_cfg_set_pin(&cfg);
// pin19 = JOYSTICK2_BUTTON3
cfg.pin = 19;
// pin20 = JOYSTICK2_BUTTON3
cfg.pin = 20;
cfg.id[0].joy.joystick_code = JOYSTICK2_BUTTON3;
APP_cfg_set_pin(&cfg);
// pin20 = JOYSTICK2_BUTTON4
cfg.pin = 20;
// pin21 = JOYSTICK2_BUTTON4
cfg.pin = 21;
cfg.id[0].joy.joystick_code = JOYSTICK2_BUTTON4;
APP_cfg_set_pin(&cfg);
}
Expand All @@ -705,11 +687,6 @@ volatile static bool app_init = FALSE;
void APP_init(void) {
memset(&app, 0, sizeof(app));


USB_ARC_set_kb_callback(app_kb_usb_cts_irq);
USB_ARC_set_mouse_callback(app_mouse_usb_cts_irq);
USB_ARC_set_joystick_callback(app_joystick_usb_cts_irq);

int res = FS_mount();
if (res == NIFFS_OK) {
app.fs_mounted = TRUE;
Expand All @@ -730,6 +707,12 @@ void APP_init(void) {
}
}

USB_ARC_set_kb_callback(app_kb_usb_cts_irq);
USB_ARC_set_mouse_callback(app_mouse_usb_cts_irq);
USB_ARC_set_joystick_callback(app_joystick_usb_cts_irq);

USB_ARC_start();

// setup devices

// keyboard device
Expand Down
32 changes: 28 additions & 4 deletions src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ static int f_cfg_pin_debounce(u8_t cycles);
static int f_cfg_mouse_delta(u8_t ms);
static int f_cfg_acc_pos_speed(u16_t speed);
static int f_cfg_acc_whe_speed(u16_t speed);
static int f_cfg_joy_delta(u8_t ms);
static int f_cfg_joy_acc_speed(u16_t speed);

static int f_usb_enable(int ena);
static int f_usb_keyboard_test(void);
Expand Down Expand Up @@ -126,6 +128,12 @@ static cmd c_tbl[] = {
{ .name = "set_mouse_wheel_acc", .fn = (func) f_cfg_acc_whe_speed, .dbg = FALSE,
.help = "Set mouse wheel accelerator speed (0-65535)\n"
},
{ .name = "set_joy_delta", .fn = (func) f_cfg_joy_delta, .dbg = FALSE,
.help = "Set number of milliseconds between joystick reports <0-255>\n"
},
{ .name = "set_joy_acc", .fn = (func) f_cfg_joy_acc_speed, .dbg = FALSE,
.help = "Set joystick direction accelerator speed (0-65535)\n"
},

{ .name = "usb_enable", .fn = (func) f_usb_enable, .dbg = FALSE,
.help = "Enables or disables usb\n"
Expand Down Expand Up @@ -339,10 +347,12 @@ static int f_sym(void) {
}

static int f_cfg(void) {
print("pin debounce cycles: %i\n", APP_cfg_get_debounce_cycles());
print("mouse report delta: %i ms\n", APP_cfg_get_mouse_delta_ms());
print("mouse position accelerator speed: %i\n", APP_cfg_get_acc_pos_speed());
print("mouse wheel accelerator speed: %i\n", APP_cfg_get_acc_wheel_speed());
print("pin debounce cycles: %i\n", APP_cfg_get_debounce_cycles());
print("mouse report delta: %i ms\n", APP_cfg_get_mouse_delta_ms());
print("mouse position accelerator speed: %i\n", APP_cfg_get_acc_pos_speed());
print("mouse wheel accelerator speed: %i\n", APP_cfg_get_acc_wheel_speed());
print("joystick report delta: %i ms\n", APP_cfg_get_joystick_delta_ms());
print("joystick direction accelerator speed: %i\n", APP_cfg_get_joystick_acc_speed());

int pin;
for (pin = 0; pin < APP_CONFIG_PINS; pin++) {
Expand Down Expand Up @@ -382,6 +392,20 @@ static int f_cfg_acc_whe_speed(u16_t speed) {
return 0;
}

static int f_cfg_joy_delta(u8_t ms) {
if (_argc != 1) {
return -1;
}
APP_cfg_set_joystick_delta_ms(ms);
return 0;
}
static int f_cfg_joy_acc_speed(u16_t speed) {
if (_argc != 1) {
return -1;
}
APP_cfg_set_joystick_acc_speed(speed);
return 0;
}

static int f_usb_enable(int ena) {
if (_argc != 1) {
Expand Down
3 changes: 2 additions & 1 deletion src/processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "system.h"
#include "gpio.h"
#include "gpio_map.h"
#include "usb_hw_config.h"

static void RCC_config() {
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
Expand Down Expand Up @@ -131,7 +132,7 @@ static void GPIO_config() {
gpio_config(in[i].port, in[i].pin, CLK_2MHZ, IN, AF0, OPENDRAIN, PULLUP);
}

gpio_config(PORTB, PIN9, CLK_2MHZ, IN, AF0, OPENDRAIN, NOPULL);
USB_Cable_Config(DISABLE);
}

// ifc
Expand Down
66 changes: 33 additions & 33 deletions src/usb/usb_arc_codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,40 +239,40 @@ enum mouse_code {
};

enum joystick_code {
_JOYSTICK_IX_1 = 0,
JOYSTICK1_X = 0,
_JOYSTICK_IX_1 = JOYSTICK1_X,
JOYSTICK1_Y,
JOYSTICK1_BUTTON1,
JOYSTICK1_BUTTON2,
JOYSTICK1_BUTTON3,
JOYSTICK1_BUTTON4,
JOYSTICK1_BUTTON5,
JOYSTICK1_BUTTON6,
JOYSTICK1_BUTTON7,
JOYSTICK1_BUTTON8,
JOYSTICK1_BUTTON9,
JOYSTICK1_BUTTON10,
JOYSTICK1_BUTTON11,
JOYSTICK1_BUTTON12,
JOYSTICK1_BUTTON13,
JOYSTICK1_BUTTON14,
JOYSTICK2_X,
_JOYSTICK_IX_2 = JOYSTICK2_X,
JOYSTICK2_Y,
JOYSTICK2_BUTTON1,
JOYSTICK2_BUTTON2,
JOYSTICK2_BUTTON3,
JOYSTICK2_BUTTON4,
JOYSTICK2_BUTTON5,
JOYSTICK2_BUTTON6,
JOYSTICK2_BUTTON7,
JOYSTICK2_BUTTON8,
JOYSTICK2_BUTTON9,
JOYSTICK2_BUTTON10,
JOYSTICK2_BUTTON11,
JOYSTICK2_BUTTON12,
JOYSTICK2_BUTTON13,
JOYSTICK2_BUTTON14,
JOYSTICK1_Y = 1,
JOYSTICK1_BUTTON1 = 2,
JOYSTICK1_BUTTON2 = 3,
JOYSTICK1_BUTTON3 = 4,
JOYSTICK1_BUTTON4 = 5,
JOYSTICK1_BUTTON5 = 6,
JOYSTICK1_BUTTON6 = 7,
JOYSTICK1_BUTTON7 = 8,
JOYSTICK1_BUTTON8 = 9,
JOYSTICK1_BUTTON9 = 10,
JOYSTICK1_BUTTON10 = 11,
JOYSTICK1_BUTTON11 = 12,
JOYSTICK1_BUTTON12 = 13,
JOYSTICK1_BUTTON13 = 14,
JOYSTICK1_BUTTON14 = 15,
_JOYSTICK_IX_2 = 16,
JOYSTICK2_X = 16,
JOYSTICK2_Y = 17,
JOYSTICK2_BUTTON1 = 18,
JOYSTICK2_BUTTON2 = 19,
JOYSTICK2_BUTTON3 = 20,
JOYSTICK2_BUTTON4 = 21,
JOYSTICK2_BUTTON5 = 22,
JOYSTICK2_BUTTON6 = 23,
JOYSTICK2_BUTTON7 = 24,
JOYSTICK2_BUTTON8 = 25,
JOYSTICK2_BUTTON9 = 26,
JOYSTICK2_BUTTON10 = 27,
JOYSTICK2_BUTTON11 = 28,
JOYSTICK2_BUTTON12 = 29,
JOYSTICK2_BUTTON13 = 30,
JOYSTICK2_BUTTON14 = 31,
};
// ugly but want to get rid of bit warning in bfield @ def_config.h
#define _JOYSTICK_CODE_MAX (JOYSTICK2_BUTTON14+1)
Expand Down
1 change: 1 addition & 0 deletions src/usb/usb_arcade.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@ void USB_ARC_set_mouse_callback(usb_mouse_report_ready_cb_f cb);
void USB_ARC_set_joystick_callback(usb_joy_report_ready_cb_f cb);

void USB_ARC_init(void);
void USB_ARC_start(void);

#endif /* USB_ARC_H_ */
3 changes: 3 additions & 0 deletions src/usb/usb_hw_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ void USB_ARC_init(void) {
ringbuf_init(&tx_rb, tx_buf, sizeof(tx_buf));
ringbuf_init(&rx_rb, rx_buf, sizeof(rx_buf));
#endif
}

void USB_ARC_start(void) {
USB_Init();
}

Expand Down

0 comments on commit 4b33f6e

Please sign in to comment.