mirror of
https://github.com/mist-devel/mist-firmware.git
synced 2026-02-04 23:24:45 +00:00
SD write for 8bit and usb joystick enumeration fix
This commit is contained in:
39
usb/hid.c
39
usb/hid.c
@@ -7,8 +7,8 @@
|
||||
#include "../user_io.h"
|
||||
|
||||
// joystick todo:
|
||||
// - renumber on unplug
|
||||
// - shift legacy joysticks up
|
||||
// + renumber on unplug
|
||||
// + shift legacy joysticks up
|
||||
// - emulate extra joysticks (at printerport, ...)
|
||||
// - second fire button (no known system uses it, but OSD may have a use ...)
|
||||
|
||||
@@ -45,6 +45,10 @@ static void hexdump(void *data, int size) {
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t hid_get_joysticks(void) {
|
||||
return joysticks;
|
||||
}
|
||||
|
||||
//get HID report descriptor
|
||||
static uint8_t hid_get_report_descr(usb_device_t *dev, uint8_t iface, uint16_t size) {
|
||||
iprintf("%s(%x, if=%d, size=%d)\n", __FUNCTION__, dev->bAddress, iface, size);
|
||||
@@ -61,7 +65,7 @@ static uint8_t hid_get_report_descr(usb_device_t *dev, uint8_t iface, uint16_t s
|
||||
// we got a report descriptor. Try to parse it
|
||||
if(parse_report_descriptor(buf, size)) {
|
||||
if(hid_conf[0].type == CONFIG_TYPE_JOYSTICK) {
|
||||
iprintf("Detected USB joystick %d\n", joysticks);
|
||||
iprintf("Detected USB joystick #%d\n", joysticks);
|
||||
|
||||
info->iface_info[iface].device_type = HID_DEVICE_JOYSTICK;
|
||||
info->iface_info[iface].conf = hid_conf[0];
|
||||
@@ -321,12 +325,35 @@ static uint8_t usb_hid_release(usb_device_t *dev) {
|
||||
|
||||
puts(__FUNCTION__);
|
||||
|
||||
int8_t i;
|
||||
uint8_t i;
|
||||
// check if a joystick is released
|
||||
for(i=0;i<info->bNumIfaces;i++) {
|
||||
if(info->iface_info[i].device_type == HID_DEVICE_JOYSTICK) {
|
||||
iprintf("releasing joystick #%d, renumbering\n", info->iface_info[i].jindex);
|
||||
|
||||
uint8_t c_jindex = info->iface_info[i].jindex;
|
||||
iprintf("releasing joystick #%d, renumbering\n", c_jindex);
|
||||
|
||||
// walk through all devices and search for sticks with a higher id
|
||||
|
||||
// search for all joystick interfaces on all hid devices
|
||||
usb_device_t *dev = usb_get_devices();
|
||||
uint8_t j;
|
||||
for(j=0;j<USB_NUMDEVICES;j++) {
|
||||
if(dev[j].bAddress && (dev[j].class == &usb_hid_class)) {
|
||||
// search for joystick interfaces
|
||||
uint8_t k;
|
||||
for(k=0;k<MAX_IFACES;k++) {
|
||||
if(dev[j].hid_info.iface_info[k].device_type == HID_DEVICE_JOYSTICK) {
|
||||
if(dev[j].hid_info.iface_info[k].jindex > c_jindex) {
|
||||
iprintf("decreasing jindex of dev #%d from %d to %d\n", j,
|
||||
dev[j].hid_info.iface_info[k].jindex, dev[j].hid_info.iface_info[k].jindex-1);
|
||||
dev[j].hid_info.iface_info[k].jindex--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// one less joystick in the system ...
|
||||
joysticks--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,5 +83,6 @@ typedef struct {
|
||||
extern const usb_device_class_config_t usb_hid_class;
|
||||
|
||||
void hid_set_kbd_led(unsigned char led, bool on);
|
||||
uint8_t hid_get_joysticks(void);
|
||||
|
||||
#endif // HID_H
|
||||
|
||||
45
user_io.c
45
user_io.c
@@ -137,7 +137,7 @@ void user_io_detect_core_type() {
|
||||
}
|
||||
|
||||
void user_io_joystick(unsigned char joystick, unsigned char map) {
|
||||
iprintf("j%d: %x\n", joystick, map);
|
||||
// iprintf("j%d: %x\n", joystick, map);
|
||||
|
||||
// most cores process joystick events themselves
|
||||
if((core_type == CORE_TYPE_MINIMIG) ||
|
||||
@@ -235,6 +235,16 @@ void user_io_poll() {
|
||||
if(!(joy0_state & JOY0_BTN1)) joy_map |= JOY_BTN1;
|
||||
if(!(joy0_state & JOY0_BTN2)) joy_map |= JOY_BTN2;
|
||||
|
||||
// Thw slighlty odd handling of joystick numbering is required
|
||||
// since the primary joystick is in port 1 and thus
|
||||
// the first usb joystick becomes joystick 1 and omly the second
|
||||
// one becomes joystick 0 (mouse port)
|
||||
|
||||
// if usb joysticks are present, then physical joystick 0 (mouse port)
|
||||
// becomes becomes 2,3,...
|
||||
uint8_t j = 0;
|
||||
if(hid_get_joysticks() > 0) j = hid_get_joysticks() + 1;
|
||||
|
||||
user_io_joystick(0, joy_map);
|
||||
}
|
||||
|
||||
@@ -250,7 +260,14 @@ void user_io_poll() {
|
||||
if(!(joy1_state & JOY1_BTN1)) joy_map |= JOY_BTN1;
|
||||
if(!(joy1_state & JOY1_BTN2)) joy_map |= JOY_BTN2;
|
||||
|
||||
user_io_joystick(1, joy_map);
|
||||
// if one usb joystick is present, then physical joystick 1 (joystick port)
|
||||
// becomes physical joystick 0 (mouse) port. If more than 1 usb joystick
|
||||
// is present it becomes 2,3,...
|
||||
uint8_t j = 1;
|
||||
if(hid_get_joysticks() == 1) j = 0;
|
||||
else if(hid_get_joysticks() > 1) j = hid_get_joysticks();
|
||||
|
||||
user_io_joystick(j, joy_map);
|
||||
}
|
||||
|
||||
// frequently poll the adc the switches
|
||||
@@ -314,29 +331,37 @@ void user_io_poll() {
|
||||
DisableFpga();
|
||||
|
||||
if(status != bit8_status) {
|
||||
unsigned long sector = (status>>8)&0xffffff;
|
||||
char buffer[512];
|
||||
|
||||
// bit8_debugf("st %08x", status);
|
||||
bit8_status = status;
|
||||
|
||||
// sector read testing
|
||||
DISKLED_ON;
|
||||
|
||||
// sector read
|
||||
if((status & 0xff) == 0xa5) {
|
||||
unsigned long sector = (status>>8)&0xffffff;
|
||||
// bit8_debugf("sec rd %u", sector);
|
||||
|
||||
if(MMC_Read(sector, buffer)) {
|
||||
short i;
|
||||
|
||||
// data is now stored in buffer. send it to fpga
|
||||
EnableFpga();
|
||||
SPI(UIO_SECTOR_SND); // send sector data IO->FPGA
|
||||
SPI_block_write(buffer);
|
||||
DisableFpga();
|
||||
|
||||
} else
|
||||
bit8_debugf("read failed!");
|
||||
bit8_debugf("rd %ld fail", sector);
|
||||
}
|
||||
|
||||
// sector write
|
||||
if((status & 0xff) == 0xa6) {
|
||||
|
||||
// read sector from FPGA
|
||||
EnableFpga();
|
||||
SPI(UIO_SECTOR_RCV); // receive sector data FPGA->IO
|
||||
SPI_block_read(buffer);
|
||||
DisableFpga();
|
||||
|
||||
if(!MMC_Write(sector, buffer))
|
||||
bit8_debugf("wr %ld fail", sector);
|
||||
}
|
||||
|
||||
DISKLED_OFF;
|
||||
|
||||
Reference in New Issue
Block a user