Changed to use stdint types.

This commit is contained in:
Piotr Esden-Tempski
2013-06-12 19:11:22 -07:00
parent 7df63fcae0
commit 34de1e776e
127 changed files with 1886 additions and 1895 deletions

View File

@@ -65,7 +65,7 @@ usbd_device *usbd_init(const usbd_driver *driver,
const struct usb_device_descriptor *dev,
const struct usb_config_descriptor *conf,
const char **strings, int num_strings,
u8 *control_buffer, u16 control_buffer_size)
uint8_t *control_buffer, uint16_t control_buffer_size)
{
usbd_device *usbd_dev;
@@ -137,34 +137,34 @@ void usbd_disconnect(usbd_device *usbd_dev, bool disconnected)
}
}
void usbd_ep_setup(usbd_device *usbd_dev, u8 addr, u8 type, u16 max_size,
void (*callback)(usbd_device *usbd_dev, u8 ep))
void usbd_ep_setup(usbd_device *usbd_dev, uint8_t addr, uint8_t type, uint16_t max_size,
void (*callback)(usbd_device *usbd_dev, uint8_t ep))
{
usbd_dev->driver->ep_setup(usbd_dev, addr, type, max_size, callback);
}
u16 usbd_ep_write_packet(usbd_device *usbd_dev, u8 addr,
const void *buf, u16 len)
uint16_t usbd_ep_write_packet(usbd_device *usbd_dev, uint8_t addr,
const void *buf, uint16_t len)
{
return usbd_dev->driver->ep_write_packet(usbd_dev, addr, buf, len);
}
u16 usbd_ep_read_packet(usbd_device *usbd_dev, u8 addr, void *buf, u16 len)
uint16_t usbd_ep_read_packet(usbd_device *usbd_dev, uint8_t addr, void *buf, uint16_t len)
{
return usbd_dev->driver->ep_read_packet(usbd_dev, addr, buf, len);
}
void usbd_ep_stall_set(usbd_device *usbd_dev, u8 addr, u8 stall)
void usbd_ep_stall_set(usbd_device *usbd_dev, uint8_t addr, uint8_t stall)
{
usbd_dev->driver->ep_stall_set(usbd_dev, addr, stall);
}
u8 usbd_ep_stall_get(usbd_device *usbd_dev, u8 addr)
uint8_t usbd_ep_stall_get(usbd_device *usbd_dev, uint8_t addr)
{
return usbd_dev->driver->ep_stall_get(usbd_dev, addr);
}
void usbd_ep_nak_set(usbd_device *usbd_dev, u8 addr, u8 nak)
void usbd_ep_nak_set(usbd_device *usbd_dev, uint8_t addr, uint8_t nak)
{
usbd_dev->driver->ep_nak_set(usbd_dev, addr, nak);
}

View File

@@ -40,7 +40,7 @@ LGPL License Terms @ref lgpl_license
#include "usb_private.h"
/* Register application callback function for handling USB control requests. */
int usbd_register_control_callback(usbd_device *usbd_dev, u8 type, u8 type_mask,
int usbd_register_control_callback(usbd_device *usbd_dev, uint8_t type, uint8_t type_mask,
usbd_control_callback callback)
{
int i;
@@ -85,10 +85,10 @@ static void usb_control_send_chunk(usbd_device *usbd_dev)
static int usb_control_recv_chunk(usbd_device *usbd_dev)
{
u16 packetsize = MIN(usbd_dev->desc->bMaxPacketSize0,
uint16_t packetsize = MIN(usbd_dev->desc->bMaxPacketSize0,
usbd_dev->control_state.req.wLength -
usbd_dev->control_state.ctrl_len);
u16 size = usbd_ep_read_packet(usbd_dev, 0,
uint16_t size = usbd_ep_read_packet(usbd_dev, 0,
usbd_dev->control_state.ctrl_buf +
usbd_dev->control_state.ctrl_len,
packetsize);
@@ -177,7 +177,7 @@ static void usb_control_setup_write(usbd_device *usbd_dev,
/* Do not appear to belong to the API, so are omitted from docs */
/**@}*/
void _usbd_control_setup(usbd_device *usbd_dev, u8 ea)
void _usbd_control_setup(usbd_device *usbd_dev, uint8_t ea)
{
struct usb_setup_data *req = &usbd_dev->control_state.req;
(void)ea;
@@ -198,7 +198,7 @@ void _usbd_control_setup(usbd_device *usbd_dev, u8 ea)
}
}
void _usbd_control_out(usbd_device *usbd_dev, u8 ea)
void _usbd_control_out(usbd_device *usbd_dev, uint8_t ea)
{
(void)ea;
@@ -244,7 +244,7 @@ void _usbd_control_out(usbd_device *usbd_dev, u8 ea)
}
}
void _usbd_control_in(usbd_device *usbd_dev, u8 ea)
void _usbd_control_in(usbd_device *usbd_dev, uint8_t ea)
{
(void)ea;
struct usb_setup_data *req = &(usbd_dev->control_state.req);

View File

@@ -25,21 +25,21 @@
#include "usb_private.h"
static usbd_device *stm32f103_usbd_init(void);
static void stm32f103_set_address(usbd_device *usbd_dev, u8 addr);
static void stm32f103_ep_setup(usbd_device *usbd_dev, u8 addr, u8 type,
u16 max_size,
void (*callback) (usbd_device *usbd_dev, u8 ep));
static void stm32f103_set_address(usbd_device *usbd_dev, uint8_t addr);
static void stm32f103_ep_setup(usbd_device *usbd_dev, uint8_t addr, uint8_t type,
uint16_t max_size,
void (*callback) (usbd_device *usbd_dev, uint8_t ep));
static void stm32f103_endpoints_reset(usbd_device *usbd_dev);
static void stm32f103_ep_stall_set(usbd_device *usbd_dev, u8 addr, u8 stall);
static u8 stm32f103_ep_stall_get(usbd_device *usbd_dev, u8 addr);
static void stm32f103_ep_nak_set(usbd_device *usbd_dev, u8 addr, u8 nak);
static u16 stm32f103_ep_write_packet(usbd_device *usbd_dev, u8 addr,
const void *buf, u16 len);
static u16 stm32f103_ep_read_packet(usbd_device *usbd_dev, u8 addr, void *buf,
u16 len);
static void stm32f103_ep_stall_set(usbd_device *usbd_dev, uint8_t addr, uint8_t stall);
static uint8_t stm32f103_ep_stall_get(usbd_device *usbd_dev, uint8_t addr);
static void stm32f103_ep_nak_set(usbd_device *usbd_dev, uint8_t addr, uint8_t nak);
static uint16_t stm32f103_ep_write_packet(usbd_device *usbd_dev, uint8_t addr,
const void *buf, uint16_t len);
static uint16_t stm32f103_ep_read_packet(usbd_device *usbd_dev, uint8_t addr, void *buf,
uint16_t len);
static void stm32f103_poll(usbd_device *usbd_dev);
static u8 force_nak[8];
static uint8_t force_nak[8];
static struct _usbd_device usbd_dev;
const struct _usbd_driver stm32f103_usb_driver = {
@@ -69,7 +69,7 @@ static usbd_device *stm32f103_usbd_init(void)
return &usbd_dev;
}
static void stm32f103_set_address(usbd_device *dev, u8 addr)
static void stm32f103_set_address(usbd_device *dev, uint8_t addr)
{
(void)dev;
/* Set device address and enable. */
@@ -82,7 +82,7 @@ static void stm32f103_set_address(usbd_device *dev, u8 addr)
* @param ep Index of endpoint to configure.
* @param size Size in bytes of the RX buffer.
*/
static void usb_set_ep_rx_bufsize(usbd_device *dev, u8 ep, u32 size)
static void usb_set_ep_rx_bufsize(usbd_device *dev, uint8_t ep, uint32_t size)
{
(void)dev;
if (size > 62) {
@@ -98,18 +98,18 @@ static void usb_set_ep_rx_bufsize(usbd_device *dev, u8 ep, u32 size)
}
}
static void stm32f103_ep_setup(usbd_device *dev, u8 addr, u8 type,
u16 max_size,
void (*callback) (usbd_device *usbd_dev, u8 ep))
static void stm32f103_ep_setup(usbd_device *dev, uint8_t addr, uint8_t type,
uint16_t max_size,
void (*callback) (usbd_device *usbd_dev, uint8_t ep))
{
/* Translate USB standard type codes to STM32. */
const u16 typelookup[] = {
const uint16_t typelookup[] = {
[USB_ENDPOINT_ATTR_CONTROL] = USB_EP_TYPE_CONTROL,
[USB_ENDPOINT_ATTR_ISOCHRONOUS] = USB_EP_TYPE_ISO,
[USB_ENDPOINT_ATTR_BULK] = USB_EP_TYPE_BULK,
[USB_ENDPOINT_ATTR_INTERRUPT] = USB_EP_TYPE_INTERRUPT,
};
u8 dir = addr & 0x80;
uint8_t dir = addr & 0x80;
addr &= 0x7f;
/* Assign address. */
@@ -152,7 +152,7 @@ static void stm32f103_endpoints_reset(usbd_device *dev)
dev->pm_top = 0x40 + (2 * dev->desc->bMaxPacketSize0);
}
static void stm32f103_ep_stall_set(usbd_device *dev, u8 addr, u8 stall)
static void stm32f103_ep_stall_set(usbd_device *dev, uint8_t addr, uint8_t stall)
{
(void)dev;
if (addr == 0) {
@@ -181,7 +181,7 @@ static void stm32f103_ep_stall_set(usbd_device *dev, u8 addr, u8 stall)
}
}
static u8 stm32f103_ep_stall_get(usbd_device *dev, u8 addr)
static uint8_t stm32f103_ep_stall_get(usbd_device *dev, uint8_t addr)
{
(void)dev;
if (addr & 0x80) {
@@ -196,7 +196,7 @@ static u8 stm32f103_ep_stall_get(usbd_device *dev, u8 addr)
return 0;
}
static void stm32f103_ep_nak_set(usbd_device *dev, u8 addr, u8 nak)
static void stm32f103_ep_nak_set(usbd_device *dev, uint8_t addr, uint8_t nak)
{
(void)dev;
/* It does not make sence to force NAK on IN endpoints. */
@@ -220,18 +220,18 @@ static void stm32f103_ep_nak_set(usbd_device *dev, u8 addr, u8 nak)
* @param buf Source pointer to data buffer.
* @param len Number of bytes to copy.
*/
static void usb_copy_to_pm(volatile void *vPM, const void *buf, u16 len)
static void usb_copy_to_pm(volatile void *vPM, const void *buf, uint16_t len)
{
const u16 *lbuf = buf;
volatile u16 *PM = vPM;
const uint16_t *lbuf = buf;
volatile uint16_t *PM = vPM;
for (len = (len + 1) >> 1; len; PM += 2, lbuf++, len--) {
*PM = *lbuf;
}
}
static u16 stm32f103_ep_write_packet(usbd_device *dev, u8 addr,
const void *buf, u16 len)
static uint16_t stm32f103_ep_write_packet(usbd_device *dev, uint8_t addr,
const void *buf, uint16_t len)
{
(void)dev;
addr &= 0x7F;
@@ -254,23 +254,23 @@ static u16 stm32f103_ep_write_packet(usbd_device *dev, u8 addr,
* @param vPM Destination pointer into packet memory.
* @param len Number of bytes to copy.
*/
static void usb_copy_from_pm(void *buf, const volatile void *vPM, u16 len)
static void usb_copy_from_pm(void *buf, const volatile void *vPM, uint16_t len)
{
u16 *lbuf = buf;
const volatile u16 *PM = vPM;
u8 odd = len & 1;
uint16_t *lbuf = buf;
const volatile uint16_t *PM = vPM;
uint8_t odd = len & 1;
for (len >>= 1; len; PM += 2, lbuf++, len--) {
*lbuf = *PM;
}
if (odd) {
*(u8 *) lbuf = *(u8 *) PM;
*(uint8_t *) lbuf = *(uint8_t *) PM;
}
}
static u16 stm32f103_ep_read_packet(usbd_device *dev, u8 addr, void *buf,
u16 len)
static uint16_t stm32f103_ep_read_packet(usbd_device *dev, uint8_t addr, void *buf,
uint16_t len)
{
(void)dev;
if ((*USB_EP_REG(addr) & USB_EP_RX_STAT) == USB_EP_RX_STAT_VALID) {
@@ -290,7 +290,7 @@ static u16 stm32f103_ep_read_packet(usbd_device *dev, u8 addr, void *buf,
static void stm32f103_poll(usbd_device *dev)
{
u16 istr = *USB_ISTR_REG;
uint16_t istr = *USB_ISTR_REG;
if (istr & USB_ISTR_RESET) {
dev->pm_top = 0x40;
@@ -300,8 +300,8 @@ static void stm32f103_poll(usbd_device *dev)
}
if (istr & USB_ISTR_CTR) {
u8 ep = istr & USB_ISTR_EP_ID;
u8 type = (istr & USB_ISTR_DIR) ? 1 : 0;
uint8_t ep = istr & USB_ISTR_EP_ID;
uint8_t type = (istr & USB_ISTR_DIR) ? 1 : 0;
if (type) /* OUT or SETUP transaction */
type += (*USB_EP_REG(ep) & USB_EP_SETUP) ? 1 : 0;

View File

@@ -31,21 +31,21 @@
* according to the selected cores base address. */
#define dev_base_address (usbd_dev->driver->base_address)
#define REBASE(x) MMIO32((x)+(dev_base_address))
#define REBASE_FIFO(x) ((volatile u32*)((dev_base_address) + (OTG_FIFO(x))))
#define REBASE_FIFO(x) ((volatile uint32_t*)((dev_base_address) + (OTG_FIFO(x))))
void stm32fx07_set_address(usbd_device *usbd_dev, u8 addr)
void stm32fx07_set_address(usbd_device *usbd_dev, uint8_t addr)
{
REBASE(OTG_DCFG) = (REBASE(OTG_DCFG) & ~OTG_FS_DCFG_DAD) | (addr << 4);
}
void stm32fx07_ep_setup(usbd_device *usbd_dev, u8 addr, u8 type, u16 max_size,
void (*callback) (usbd_device *usbd_dev, u8 ep))
void stm32fx07_ep_setup(usbd_device *usbd_dev, uint8_t addr, uint8_t type, uint16_t max_size,
void (*callback) (usbd_device *usbd_dev, uint8_t ep))
{
/*
* Configure endpoint address and type. Allocate FIFO memory for
* endpoint. Install callback funciton.
*/
u8 dir = addr & 0x80;
uint8_t dir = addr & 0x80;
addr &= 0x7f;
if (addr == 0) { /* For the default control endpoint */
@@ -120,7 +120,7 @@ void stm32fx07_endpoints_reset(usbd_device *usbd_dev)
usbd_dev->fifo_mem_top = usbd_dev->fifo_mem_top_ep0;
}
void stm32fx07_ep_stall_set(usbd_device *usbd_dev, u8 addr, u8 stall)
void stm32fx07_ep_stall_set(usbd_device *usbd_dev, uint8_t addr, uint8_t stall)
{
if (addr == 0) {
if (stall) {
@@ -149,7 +149,7 @@ void stm32fx07_ep_stall_set(usbd_device *usbd_dev, u8 addr, u8 stall)
}
}
u8 stm32fx07_ep_stall_get(usbd_device *usbd_dev, u8 addr)
uint8_t stm32fx07_ep_stall_get(usbd_device *usbd_dev, uint8_t addr)
{
/* Return non-zero if STALL set. */
if (addr & 0x80) {
@@ -161,7 +161,7 @@ u8 stm32fx07_ep_stall_get(usbd_device *usbd_dev, u8 addr)
}
}
void stm32fx07_ep_nak_set(usbd_device *usbd_dev, u8 addr, u8 nak)
void stm32fx07_ep_nak_set(usbd_device *usbd_dev, uint8_t addr, uint8_t nak)
{
/* It does not make sence to force NAK on IN endpoints. */
if (addr & 0x80) {
@@ -177,10 +177,10 @@ void stm32fx07_ep_nak_set(usbd_device *usbd_dev, u8 addr, u8 nak)
}
}
u16 stm32fx07_ep_write_packet(usbd_device *usbd_dev, u8 addr,
const void *buf, u16 len)
uint16_t stm32fx07_ep_write_packet(usbd_device *usbd_dev, uint8_t addr,
const void *buf, uint16_t len)
{
const u32 *buf32 = buf;
const uint32_t *buf32 = buf;
int i;
addr &= 0x7F;
@@ -194,7 +194,7 @@ u16 stm32fx07_ep_write_packet(usbd_device *usbd_dev, u8 addr,
REBASE(OTG_DIEPTSIZ(addr)) = OTG_FS_DIEPSIZ0_PKTCNT | len;
REBASE(OTG_DIEPCTL(addr)) |= OTG_FS_DIEPCTL0_EPENA |
OTG_FS_DIEPCTL0_CNAK;
volatile u32 *fifo = REBASE_FIFO(addr);
volatile uint32_t *fifo = REBASE_FIFO(addr);
/* Copy buffer to endpoint FIFO, note - memcpy does not work */
for (i = len; i > 0; i -= 4) {
@@ -204,16 +204,16 @@ u16 stm32fx07_ep_write_packet(usbd_device *usbd_dev, u8 addr,
return len;
}
u16 stm32fx07_ep_read_packet(usbd_device *usbd_dev, u8 addr, void *buf, u16 len)
uint16_t stm32fx07_ep_read_packet(usbd_device *usbd_dev, uint8_t addr, void *buf, uint16_t len)
{
int i;
u32 *buf32 = buf;
u32 extra;
uint32_t *buf32 = buf;
uint32_t extra;
len = MIN(len, usbd_dev->rxbcnt);
usbd_dev->rxbcnt -= len;
volatile u32 *fifo = REBASE_FIFO(addr);
volatile uint32_t *fifo = REBASE_FIFO(addr);
for (i = len; i >= 4; i -= 4) {
*buf32++ = *fifo++;
}
@@ -234,7 +234,7 @@ u16 stm32fx07_ep_read_packet(usbd_device *usbd_dev, u8 addr, void *buf, u16 len)
void stm32fx07_poll(usbd_device *usbd_dev)
{
/* Read interrupt status register. */
u32 intsts = REBASE(OTG_GINTSTS);
uint32_t intsts = REBASE(OTG_GINTSTS);
int i;
if (intsts & OTG_FS_GINTSTS_ENUMDNE) {
@@ -248,15 +248,15 @@ void stm32fx07_poll(usbd_device *usbd_dev)
/* Note: RX and TX handled differently in this device. */
if (intsts & OTG_FS_GINTSTS_RXFLVL) {
/* Receive FIFO non-empty. */
u32 rxstsp = REBASE(OTG_GRXSTSP);
u32 pktsts = rxstsp & OTG_FS_GRXSTSP_PKTSTS_MASK;
uint32_t rxstsp = REBASE(OTG_GRXSTSP);
uint32_t pktsts = rxstsp & OTG_FS_GRXSTSP_PKTSTS_MASK;
if ((pktsts != OTG_FS_GRXSTSP_PKTSTS_OUT) &&
(pktsts != OTG_FS_GRXSTSP_PKTSTS_SETUP)) {
return;
}
u8 ep = rxstsp & OTG_FS_GRXSTSP_EPNUM_MASK;
u8 type;
uint8_t ep = rxstsp & OTG_FS_GRXSTSP_EPNUM_MASK;
uint8_t type;
if (pktsts == OTG_FS_GRXSTSP_PKTSTS_SETUP) {
type = USB_TRANSACTION_SETUP;
} else {

View File

@@ -20,17 +20,17 @@
#ifndef __USB_FX07_COMMON_H_
#define __USB_FX07_COMMON_H_
void stm32fx07_set_address(usbd_device *usbd_dev, u8 addr);
void stm32fx07_ep_setup(usbd_device *usbd_dev, u8 addr, u8 type, u16 max_size,
void (*callback)(usbd_device *usbd_dev, u8 ep));
void stm32fx07_set_address(usbd_device *usbd_dev, uint8_t addr);
void stm32fx07_ep_setup(usbd_device *usbd_dev, uint8_t addr, uint8_t type, uint16_t max_size,
void (*callback)(usbd_device *usbd_dev, uint8_t ep));
void stm32fx07_endpoints_reset(usbd_device *usbd_dev);
void stm32fx07_ep_stall_set(usbd_device *usbd_dev, u8 addr, u8 stall);
u8 stm32fx07_ep_stall_get(usbd_device *usbd_dev, u8 addr);
void stm32fx07_ep_nak_set(usbd_device *usbd_dev, u8 addr, u8 nak);
u16 stm32fx07_ep_write_packet(usbd_device *usbd_dev, u8 addr, const void *buf,
u16 len);
u16 stm32fx07_ep_read_packet(usbd_device *usbd_dev, u8 addr, void *buf,
u16 len);
void stm32fx07_ep_stall_set(usbd_device *usbd_dev, uint8_t addr, uint8_t stall);
uint8_t stm32fx07_ep_stall_get(usbd_device *usbd_dev, uint8_t addr);
void stm32fx07_ep_nak_set(usbd_device *usbd_dev, uint8_t addr, uint8_t nak);
uint16_t stm32fx07_ep_write_packet(usbd_device *usbd_dev, uint8_t addr, const void *buf,
uint16_t len);
uint16_t stm32fx07_ep_read_packet(usbd_device *usbd_dev, uint8_t addr, void *buf,
uint16_t len);
void stm32fx07_poll(usbd_device *usbd_dev);
void stm32fx07_disconnect(usbd_device *usbd_dev, bool disconnected);

View File

@@ -48,13 +48,13 @@ struct _usbd_device {
const char **strings;
int num_strings;
u8 *ctrl_buf; /**< Internal buffer used for control transfers */
u16 ctrl_buf_len;
uint8_t *ctrl_buf; /**< Internal buffer used for control transfers */
uint16_t ctrl_buf_len;
u8 current_address;
u8 current_config;
uint8_t current_address;
uint8_t current_config;
u16 pm_top; /**< Top of allocated endpoint buffer memory */
uint16_t pm_top; /**< Top of allocated endpoint buffer memory */
/* User callback functions for various USB events */
void (*user_callback_reset)(void);
@@ -69,22 +69,22 @@ struct _usbd_device {
DATA_OUT, LAST_DATA_OUT, STATUS_OUT,
} state;
struct usb_setup_data req __aligned(4);
u8 *ctrl_buf;
u16 ctrl_len;
uint8_t *ctrl_buf;
uint16_t ctrl_len;
void (*complete)(usbd_device *usbd_dev,
struct usb_setup_data *req);
} control_state;
struct user_control_callback {
usbd_control_callback cb;
u8 type;
u8 type_mask;
uint8_t type;
uint8_t type_mask;
} user_control_callback[MAX_USER_CONTROL_CALLBACK];
void (*user_callback_ctr[8][3])(usbd_device *usbd_dev, u8 ea);
void (*user_callback_ctr[8][3])(usbd_device *usbd_dev, uint8_t ea);
/* User callback function for some standard USB function hooks */
void (*user_callback_set_config)(usbd_device *usbd_dev, u16 wValue);
void (*user_callback_set_config)(usbd_device *usbd_dev, uint16_t wValue);
const struct _usbd_driver *driver;
@@ -92,12 +92,12 @@ struct _usbd_device {
uint16_t fifo_mem_top;
uint16_t fifo_mem_top_ep0;
u8 force_nak[4];
uint8_t force_nak[4];
/*
* We keep a backup copy of the out endpoint size registers to restore
* them after a transaction.
*/
u32 doeptsiz[4];
uint32_t doeptsiz[4];
/*
* Received packet size for each endpoint. This is assigned in
* stm32f107_poll() which reads the packet status push register GRXSTSP
@@ -115,43 +115,43 @@ enum _usbd_transaction {
/* Do not appear to belong to the API, so are omitted from docs */
/**@}*/
void _usbd_control_in(usbd_device *usbd_dev, u8 ea);
void _usbd_control_out(usbd_device *usbd_dev, u8 ea);
void _usbd_control_setup(usbd_device *usbd_dev, u8 ea);
void _usbd_control_in(usbd_device *usbd_dev, uint8_t ea);
void _usbd_control_out(usbd_device *usbd_dev, uint8_t ea);
void _usbd_control_setup(usbd_device *usbd_dev, uint8_t ea);
int _usbd_standard_request_device(usbd_device *usbd_dev,
struct usb_setup_data *req, u8 **buf,
u16 *len);
struct usb_setup_data *req, uint8_t **buf,
uint16_t *len);
int _usbd_standard_request_interface(usbd_device *usbd_dev,
struct usb_setup_data *req, u8 **buf,
u16 *len);
struct usb_setup_data *req, uint8_t **buf,
uint16_t *len);
int _usbd_standard_request_endpoint(usbd_device *usbd_dev,
struct usb_setup_data *req, u8 **buf,
u16 *len);
struct usb_setup_data *req, uint8_t **buf,
uint16_t *len);
int _usbd_standard_request(usbd_device *usbd_dev, struct usb_setup_data *req,
u8 **buf, u16 *len);
uint8_t **buf, uint16_t *len);
void _usbd_reset(usbd_device *usbd_dev);
/* Functions provided by the hardware abstraction. */
struct _usbd_driver {
usbd_device *(*init)(void);
void (*set_address)(usbd_device *usbd_dev, u8 addr);
void (*ep_setup)(usbd_device *usbd_dev, u8 addr, u8 type, u16 max_size,
void (*cb)(usbd_device *usbd_dev, u8 ep));
void (*set_address)(usbd_device *usbd_dev, uint8_t addr);
void (*ep_setup)(usbd_device *usbd_dev, uint8_t addr, uint8_t type, uint16_t max_size,
void (*cb)(usbd_device *usbd_dev, uint8_t ep));
void (*ep_reset)(usbd_device *usbd_dev);
void (*ep_stall_set)(usbd_device *usbd_dev, u8 addr, u8 stall);
void (*ep_nak_set)(usbd_device *usbd_dev, u8 addr, u8 nak);
u8 (*ep_stall_get)(usbd_device *usbd_dev, u8 addr);
u16 (*ep_write_packet)(usbd_device *usbd_dev, u8 addr, const void *buf,
u16 len);
u16 (*ep_read_packet)(usbd_device *usbd_dev, u8 addr, void *buf,
u16 len);
void (*ep_stall_set)(usbd_device *usbd_dev, uint8_t addr, uint8_t stall);
void (*ep_nak_set)(usbd_device *usbd_dev, uint8_t addr, uint8_t nak);
uint8_t (*ep_stall_get)(usbd_device *usbd_dev, uint8_t addr);
uint16_t (*ep_write_packet)(usbd_device *usbd_dev, uint8_t addr, const void *buf,
uint16_t len);
uint16_t (*ep_read_packet)(usbd_device *usbd_dev, uint8_t addr, void *buf,
uint16_t len);
void (*poll)(usbd_device *usbd_dev);
void (*disconnect)(usbd_device *usbd_dev, bool disconnected);
u32 base_address;
uint32_t base_address;
bool set_address_before_status;
u16 rx_fifo_size;
uint16_t rx_fifo_size;
};
#endif

View File

@@ -41,18 +41,18 @@ LGPL License Terms @ref lgpl_license
void usbd_register_set_config_callback(usbd_device *usbd_dev,
void (*callback)(usbd_device *usbd_dev,
u16 wValue))
uint16_t wValue))
{
usbd_dev->user_callback_set_config = callback;
}
static u16 build_config_descriptor(usbd_device *usbd_dev,
u8 index, u8 *buf, u16 len)
static uint16_t build_config_descriptor(usbd_device *usbd_dev,
uint8_t index, uint8_t *buf, uint16_t len)
{
u8 *tmpbuf = buf;
uint8_t *tmpbuf = buf;
const struct usb_config_descriptor *cfg = &usbd_dev->config[index];
u16 count, total = 0, totallen = 0;
u16 i, j, k;
uint16_t count, total = 0, totallen = 0;
uint16_t i, j, k;
memcpy(buf, cfg, count = MIN(len, cfg->bLength));
buf += count;
@@ -103,24 +103,24 @@ static u16 build_config_descriptor(usbd_device *usbd_dev,
}
/* Fill in wTotalLength. */
*(u16 *)(tmpbuf + 2) = totallen;
*(uint16_t *)(tmpbuf + 2) = totallen;
return total;
}
static int usb_descriptor_type(u16 wValue)
static int usb_descriptor_type(uint16_t wValue)
{
return wValue >> 8;
}
static int usb_descriptor_index(u16 wValue)
static int usb_descriptor_index(uint16_t wValue)
{
return wValue & 0xFF;
}
static int usb_standard_get_descriptor(usbd_device *usbd_dev,
struct usb_setup_data *req,
u8 **buf, u16 *len)
uint8_t **buf, uint16_t *len)
{
int i, array_idx, descr_idx;
struct usb_string_descriptor *sd;
@@ -129,7 +129,7 @@ static int usb_standard_get_descriptor(usbd_device *usbd_dev,
switch (usb_descriptor_type(req->wValue)) {
case USB_DT_DEVICE:
*buf = (u8 *) usbd_dev->desc;
*buf = (uint8_t *) usbd_dev->desc;
*len = MIN(*len, usbd_dev->desc->bLength);
return USBD_REQ_HANDLED;
case USB_DT_CONFIGURATION:
@@ -182,7 +182,7 @@ static int usb_standard_get_descriptor(usbd_device *usbd_dev,
}
sd->bDescriptorType = USB_DT_STRING;
*buf = (u8 *)sd;
*buf = (uint8_t *)sd;
return USBD_REQ_HANDLED;
}
@@ -190,8 +190,8 @@ static int usb_standard_get_descriptor(usbd_device *usbd_dev,
}
static int usb_standard_set_address(usbd_device *usbd_dev,
struct usb_setup_data *req, u8 **buf,
u16 *len)
struct usb_setup_data *req, uint8_t **buf,
uint16_t *len)
{
(void)req;
(void)buf;
@@ -217,7 +217,7 @@ static int usb_standard_set_address(usbd_device *usbd_dev,
static int usb_standard_set_configuration(usbd_device *usbd_dev,
struct usb_setup_data *req,
u8 **buf, u16 *len)
uint8_t **buf, uint16_t *len)
{
int i;
@@ -252,7 +252,7 @@ static int usb_standard_set_configuration(usbd_device *usbd_dev,
static int usb_standard_get_configuration(usbd_device *usbd_dev,
struct usb_setup_data *req,
u8 **buf, u16 *len)
uint8_t **buf, uint16_t *len)
{
(void)req;
@@ -266,7 +266,7 @@ static int usb_standard_get_configuration(usbd_device *usbd_dev,
static int usb_standard_set_interface(usbd_device *usbd_dev,
struct usb_setup_data *req,
u8 **buf, u16 *len)
uint8_t **buf, uint16_t *len)
{
(void)usbd_dev;
(void)req;
@@ -283,7 +283,7 @@ static int usb_standard_set_interface(usbd_device *usbd_dev,
static int usb_standard_get_interface(usbd_device *usbd_dev,
struct usb_setup_data *req,
u8 **buf, u16 *len)
uint8_t **buf, uint16_t *len)
{
(void)usbd_dev;
(void)req;
@@ -298,7 +298,7 @@ static int usb_standard_get_interface(usbd_device *usbd_dev,
static int usb_standard_device_get_status(usbd_device *usbd_dev,
struct usb_setup_data *req,
u8 **buf, u16 *len)
uint8_t **buf, uint16_t *len)
{
(void)usbd_dev;
(void)req;
@@ -316,7 +316,7 @@ static int usb_standard_device_get_status(usbd_device *usbd_dev,
static int usb_standard_interface_get_status(usbd_device *usbd_dev,
struct usb_setup_data *req,
u8 **buf, u16 *len)
uint8_t **buf, uint16_t *len)
{
(void)usbd_dev;
(void)req;
@@ -333,7 +333,7 @@ static int usb_standard_interface_get_status(usbd_device *usbd_dev,
static int usb_standard_endpoint_get_status(usbd_device *usbd_dev,
struct usb_setup_data *req,
u8 **buf, u16 *len)
uint8_t **buf, uint16_t *len)
{
(void)req;
@@ -348,7 +348,7 @@ static int usb_standard_endpoint_get_status(usbd_device *usbd_dev,
static int usb_standard_endpoint_stall(usbd_device *usbd_dev,
struct usb_setup_data *req,
u8 **buf, u16 *len)
uint8_t **buf, uint16_t *len)
{
(void)buf;
(void)len;
@@ -360,7 +360,7 @@ static int usb_standard_endpoint_stall(usbd_device *usbd_dev,
static int usb_standard_endpoint_unstall(usbd_device *usbd_dev,
struct usb_setup_data *req,
u8 **buf, u16 *len)
uint8_t **buf, uint16_t *len)
{
(void)buf;
(void)len;
@@ -374,11 +374,11 @@ static int usb_standard_endpoint_unstall(usbd_device *usbd_dev,
/**@}*/
int _usbd_standard_request_device(usbd_device *usbd_dev,
struct usb_setup_data *req, u8 **buf,
u16 *len)
struct usb_setup_data *req, uint8_t **buf,
uint16_t *len)
{
int (*command)(usbd_device *usbd_dev, struct usb_setup_data *req, u8
**buf, u16 *len) = NULL;
int (*command)(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t
**buf, uint16_t *len) = NULL;
switch (req->bRequest) {
case USB_REQ_CLEAR_FEATURE:
@@ -428,11 +428,11 @@ int _usbd_standard_request_device(usbd_device *usbd_dev,
}
int _usbd_standard_request_interface(usbd_device *usbd_dev,
struct usb_setup_data *req, u8 **buf,
u16 *len)
struct usb_setup_data *req, uint8_t **buf,
uint16_t *len)
{
int (*command)(usbd_device *usbd_dev, struct usb_setup_data *req,
u8 **buf, u16 *len) = NULL;
uint8_t **buf, uint16_t *len) = NULL;
switch (req->bRequest) {
case USB_REQ_CLEAR_FEATURE:
@@ -458,11 +458,11 @@ int _usbd_standard_request_interface(usbd_device *usbd_dev,
}
int _usbd_standard_request_endpoint(usbd_device *usbd_dev,
struct usb_setup_data *req, u8 **buf,
u16 *len)
struct usb_setup_data *req, uint8_t **buf,
uint16_t *len)
{
int (*command) (usbd_device *usbd_dev, struct usb_setup_data *req,
u8 **buf, u16 *len) = NULL;
uint8_t **buf, uint16_t *len) = NULL;
switch (req->bRequest) {
case USB_REQ_CLEAR_FEATURE:
@@ -495,7 +495,7 @@ int _usbd_standard_request_endpoint(usbd_device *usbd_dev,
}
int _usbd_standard_request(usbd_device *usbd_dev,
struct usb_setup_data *req, u8 **buf, u16 *len)
struct usb_setup_data *req, uint8_t **buf, uint16_t *len)
{
/* FIXME: Have class/vendor requests as well. */
if ((req->bmRequestType & USB_REQ_TYPE_TYPE) != USB_REQ_TYPE_STANDARD) {