Skip to content

Commit

Permalink
update wasm support
Browse files Browse the repository at this point in the history
  • Loading branch information
toyoshim committed Nov 11, 2023
1 parent 68c4081 commit e033c53
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 2 deletions.
5 changes: 5 additions & 0 deletions us/iona_stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ export class IONA {
this.exports.iona_usb_host_check_hid_report_desc(this.communication_buffer_address);
}

checkHidReport(buffer) {
this.storeData(buffer);
this.exports.iona_usb_host_check_hid_report(this.communication_buffer_address, buffer.byteLength);
}

createPseudoDeviceDescriptor(pid, vid) {
const desc = new Uint8Array(18);
desc[0] = 0x12; // bLength
Expand Down
4 changes: 2 additions & 2 deletions us/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ LOGGER = logger
LOGGER_OBJS = logger.rel ch559.rel flash.rel gpio.rel hid.rel \
hid_dualshock3.rel hid_guncon3.rel hid_keyboard.rel hid_mouse.rel \
hid_switch.rel hid_xbox.rel led.rel serial.rel timer3.rel usb_host_debug.rel
WASM_OBJS = wasm.o hid.o hid_dualshock3.o hid_guncon3.o hid_keyboard.o \
hid_mouse.o hid_switch.o hid_xbox.o serial.o
WASM_OBJS = wasm.o controller.o hid.o hid_dualshock3.o hid_guncon3.o \
hid_keyboard.o hid_mouse.o hid_switch.o hid_xbox.o serial.o

.PHONY: all clean program run clean build prod wasm serv

Expand Down
87 changes: 87 additions & 0 deletions us/wasm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright 2023 Takashi Toyoshima <toyoshim@gmail.com>. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be found
// in the LICENSE file.

#include <emscripten/emscripten.h>
#include <stdint.h>
#include <stdio.h>

#include "hid.h"
#include "serial.h"
#include "usb_host.h"

#include "controller.h"
#include "settings.h"

static struct hid hid;
static struct usb_host* usb_host = 0;
static struct settings settings;
static uint8_t communication_buffer[1024];

void usb_host_init(struct usb_host* host) {
usb_host = host;
}

struct settings* settings_get(void) {
return &settings;
}

static void error(void) {
puts("iona_init may not be called");
}

EMSCRIPTEN_KEEPALIVE void iona_usb_host_check_device_desc(const uint8_t* desc) {
if (!usb_host) {
return error();
}
usb_host->check_device_desc(0, desc);
}

EMSCRIPTEN_KEEPALIVE void iona_usb_host_check_configuration_desc(
const uint8_t* desc) {
if (!usb_host) {
return error();
}
usb_host->check_configuration_desc(0, desc);
}

EMSCRIPTEN_KEEPALIVE void iona_usb_host_check_hid_report_desc(
const uint8_t* desc) {
if (!usb_host) {
return error();
}
usb_host->check_hid_report_desc(0, desc);
}

EMSCRIPTEN_KEEPALIVE void iona_usb_host_check_hid_report(uint8_t* data,
uint16_t size) {
if (!usb_host) {
return error();
}
usb_host->hid_report(0, data, size);
}

EMSCRIPTEN_KEEPALIVE void* iona_get_communication_buffer(void) {
return communication_buffer;
}

EMSCRIPTEN_KEEPALIVE void iona_init(void) {
serial_init();

for (int i = 0; i < 6; ++i) {
settings.analog_type[0][i] = 2;
settings.analog_index[0][i] = i;
}
for (int i = 0; i < 16; ++i) {
settings.digital_map[0][i].data[0] = 0x20 >> i;
settings.digital_map[0][i].data[1] = 0x2000 >> i;
}
for (int i = 0; i < 12; ++i) {
settings.rapid_fire[0][i] = 0;
}

hid.report = controller_update;
hid.detected = 0;
hid.get_flags = 0;
hid_init(&hid);
}

0 comments on commit e033c53

Please sign in to comment.