Project

General

Profile

« Previous | Next » 

Revision 270

Added by markw almost 11 years ago

Fixes to make this build into ZPU firmware

View differences:

firmware/common/integer.h
typedef unsigned char u08;
typedef unsigned char uint8_t;
typedef signed char int8_t;
/* These types MUST be 16 bit */
typedef short SHORT;
typedef unsigned short WORD;
typedef unsigned short WCHAR;
typedef unsigned short u16;
typedef unsigned short uint16_t;
typedef signed short int16_t;
/* These types MUST be 16 bit or 32 bit */
typedef int INT;
typedef unsigned int UINT;
......
typedef long LONG;
typedef unsigned int DWORD;
typedef unsigned int u32;
typedef unsigned int uint32_t;
typedef uint8_t bool;
#define false (0)
#define NULL (0)
#define true (1)
#endif
#endif
firmware/usb/LICENSE
This part is GPL - in fact this whole firmware should be - just need to check a few things...
This part is GPL - in fact this whole firmware should be - just need to check a few things from other contributors...
firmware/usb/events.h
#include "printf.h"
void event_keyboard(uint8_t i, uint8_t buf[])
{
int j;
firmware/usb/hid.c
#include <stdio.h>
//#include <stdio.h>
#include "usb.h"
#include "timer.h"
......
hid_set_protocol(dev, info->iface[i].iface_idx, HID_BOOT_PROTOCOL);
}
puts("HID configured");
iprintf("HID configured\n");
// update leds
for(i=0;i<MAX_IFACES;i++)
......
static uint8_t usb_hid_release(usb_device_t *dev) {
usb_hid_info_t *info = &(dev->hid_info);
puts(__FUNCTION__);
iprintf("%s\n",__FUNCTION__);
uint8_t i;
// check if a joystick is released
firmware/usb/hid.h
#ifndef HID_H
#define HID_H
#include <stdbool.h>
#include <inttypes.h>
//#include <stdbool.h>
//#include <inttypes.h>
#include <common/integer.h>
#include "hidparser.h"
#define HID_LED_NUM_LOCK 0x01
firmware/usb/hidparser.c
// http://www.frank-zhao.com/cache/hid_tutorial_1.php
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
//#include <inttypes.h>
//#include <stdbool.h>
//#include <stdio.h>
#include "hidparser.h"
#include "debug.h"
......
uint8_t setup_complete = 0;
// joystick/mouse components
int8_t axis[2] = { -1, -1};
int8_t axis[2]; // MWW = { -1, -1}; (this instantiates memcpy!)
axis[0] = -1;
axis[1] = -1;
uint8_t btns = 0;
conf->type = CONFIG_TYPE_NONE;
firmware/usb/hidparser.h
#ifndef HIDPARSER_H
#define HIDPARSER_H
#include <common/integer.h>
#define CONFIG_TYPE_NONE 0
#define CONFIG_TYPE_MOUSE 1
#define CONFIG_TYPE_KEYBOARD 2
firmware/usb/hub.c
#include <stdio.h>
//#include <stdio.h>
#include "usb.h"
#include "timer.h"
......
rcode = usb_get_dev_descr( dev, 8, &buf.dev_desc );
if( rcode ) {
puts("failed to get device descriptor 1");
iprintf("failed to get device descriptor 1\n");
return rcode;
}
// Extract device class from device descriptor
// If device class is not a hub return
if (buf.dev_desc.bDeviceClass != USB_CLASS_HUB) {
puts("not a hub!");
iprintf("not a hub!\n");
return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
}
// try to re-read full device descriptor from newly assigned address
if(rcode = usb_get_dev_descr( dev, sizeof(usb_device_descriptor_t), &buf.dev_desc )) {
puts("failed to get device descriptor 2");
iprintf("failed to get device descriptor 2\n");
return rcode;
}
......
rcode = usb_hub_get_hub_descriptor(dev, 0, 8, &buf.hub_desc);
if (rcode) {
puts("failed to get hub descriptor");
iprintf("failed to get hub descriptor\n");
return rcode;
}
......
// Read configuration Descriptor in Order To Obtain Proper Configuration Value
rcode = usb_get_conf_descr(dev, sizeof(usb_configuration_descriptor_t), 0, &buf.conf_desc);
if (rcode) {
puts("failed to read configuration descriptor");
iprintf("failed to read configuration descriptor\n");
return rcode;
}
......
}
static uint8_t usb_hub_release(usb_device_t *dev) {
puts(__FUNCTION__);
iprintf("%s\n",__FUNCTION__);
// root hub unplugged
if(!dev->parent)
......
static void usb_hub_show_port_status(uint8_t port, uint16_t status, uint16_t changed) {
iprintf("Status of port %d:\n", port);
if(status & USB_HUB_PORT_STATUS_PORT_CONNECTION) puts(" connected");
if(status & USB_HUB_PORT_STATUS_PORT_ENABLE) puts(" enabled");
if(status & USB_HUB_PORT_STATUS_PORT_SUSPEND) puts(" suspended");
if(status & USB_HUB_PORT_STATUS_PORT_OVER_CURRENT) puts(" over current");
if(status & USB_HUB_PORT_STATUS_PORT_RESET) puts(" reset");
if(status & USB_HUB_PORT_STATUS_PORT_POWER) puts(" powered");
if(status & USB_HUB_PORT_STATUS_PORT_LOW_SPEED) puts(" low speed");
if(status & USB_HUB_PORT_STATUS_PORT_HIGH_SPEED) puts(" high speed");
if(status & USB_HUB_PORT_STATUS_PORT_TEST) puts(" test");
if(status & USB_HUB_PORT_STATUS_PORT_INDICATOR) puts(" indicator");
if(status & USB_HUB_PORT_STATUS_PORT_CONNECTION) iprintf(" connected\n");
if(status & USB_HUB_PORT_STATUS_PORT_ENABLE) iprintf(" enabled\n");
if(status & USB_HUB_PORT_STATUS_PORT_SUSPEND) iprintf(" suspended\n");
if(status & USB_HUB_PORT_STATUS_PORT_OVER_CURRENT) iprintf(" over current\n");
if(status & USB_HUB_PORT_STATUS_PORT_RESET) iprintf(" reset\n");
if(status & USB_HUB_PORT_STATUS_PORT_POWER) iprintf(" powered\n");
if(status & USB_HUB_PORT_STATUS_PORT_LOW_SPEED) iprintf(" low speed\n");
if(status & USB_HUB_PORT_STATUS_PORT_HIGH_SPEED) iprintf(" high speed\n");
if(status & USB_HUB_PORT_STATUS_PORT_TEST) iprintf(" test\n");
if(status & USB_HUB_PORT_STATUS_PORT_INDICATOR) iprintf(" indicator\n");
iprintf("Changes on port %d:\n", port);
if(changed & USB_HUB_PORT_STATUS_PORT_CONNECTION) puts(" connected");
if(changed & USB_HUB_PORT_STATUS_PORT_ENABLE) puts(" enabled");
if(changed & USB_HUB_PORT_STATUS_PORT_SUSPEND) puts(" suspended");
if(changed & USB_HUB_PORT_STATUS_PORT_OVER_CURRENT) puts(" over current");
if(changed & USB_HUB_PORT_STATUS_PORT_RESET) puts(" reset");
if(changed & USB_HUB_PORT_STATUS_PORT_CONNECTION) iprintf(" connected\n");
if(changed & USB_HUB_PORT_STATUS_PORT_ENABLE) iprintf(" enabled\n");
if(changed & USB_HUB_PORT_STATUS_PORT_SUSPEND) iprintf(" suspended\n");
if(changed & USB_HUB_PORT_STATUS_PORT_OVER_CURRENT) iprintf(" over current\n");
if(changed & USB_HUB_PORT_STATUS_PORT_RESET) iprintf(" reset\n");
}
static uint8_t usb_hub_port_status_change(usb_device_t *dev, uint8_t port, hub_event_t evt) {
firmware/usb/hub.h
#ifndef HUB_H
#define HUB_H
#include <stdbool.h>
#include <inttypes.h>
//#include <stdbool.h>
//#include <inttypes.h>
#include <common/integer.h>
typedef struct {
uint8_t bNbrPorts; // number of ports
firmware/usb/timer.h
#ifndef TIMER_H
#define TIMER_H
#include <inttypes.h>
//#include <inttypes.h>
#include <common/integer.h>
typedef uint32_t msec_t;
void timer_init();
firmware/usb/usb.c
#include <stdio.h>
//#include <stdio.h>
#include "timer.h"
#include "usb.h"
......
static usb_device_t dev[USB_NUMDEVICES];
void usb_reset_state() {
puts(__FUNCTION__);
iprintf("%s\n",__FUNCTION__);
bmHubPre = 0;
}
......
}
void usb_init() {
puts(__FUNCTION__);
iprintf("%s\n",__FUNCTION__);
// MWW max3421e_init(); // init underlaying hardware layer
usbhostslave[OHS900_HOSTSLAVECTLREG] = OHS900_HSCTLREG_RESET_CORE;
......
iprintf("Setting addr %x\n", i+1);
rcode = usb_set_addr(d, i+1);
if(rcode) {
puts("failed to assign address");
iprintf("failed to assign address\n");
return rcode;
}
......
if (!rcode) {
d->class = class_list[c];
puts(" -> accepted :-)");
iprintf(" -> accepted :-)\n");
// ok, device accepted by class
return 0;
}
puts(" -> not accepted :-(");
iprintf(" -> not accepted :-(\n");
}
} else
iprintf("no more free entries\n");
firmware/usb/usb.h
#ifndef USB_H
#define USB_H
#include <inttypes.h>
#include <stdbool.h>
//#include <inttypes.h>
//#include <stdbool.h>
#include "common/integer.h"
/* NAK powers. To save space in endpoint data structure, amount of retries */
/* before giving up and returning 0x4 is stored in bmNakPower as a power of 2.*/
/* The actual nak_limit is then calculated as nak_limit = ( 2^bmNakPower - 1) */

Also available in: Unified diff