support Board
This commit is contained in:
15
ChangeLog
15
ChangeLog
@@ -1,5 +1,20 @@
|
|||||||
2015-07-15 Niibe Yutaka <gniibe@fsij.org>
|
2015-07-15 Niibe Yutaka <gniibe@fsij.org>
|
||||||
|
|
||||||
|
* tool/usb_strings.py (field): Add 'Board'.
|
||||||
|
|
||||||
|
* regnual/regnual.c (usb_cb_get_descriptor): Update.
|
||||||
|
* src/usb_ctrl.c (usb_cb_interface): Call usb_lld_write.
|
||||||
|
* src/usb_desc.c (usb_cb_get_descriptor): Support sys_board_name,
|
||||||
|
using usb_lld_write.
|
||||||
|
* src/usb_lld.h (usb_cb_get_descriptor): Add last argument length
|
||||||
|
for asked length.
|
||||||
|
* src/usb_stm32f103.c (handle_setup0): Allow setup callback to
|
||||||
|
call usb_lld_write with ENDP0.
|
||||||
|
* src/usb_conf.h (NUM_STRING_DESC): Remove.
|
||||||
|
|
||||||
|
* src/configure [!sys1_compat] (CONFIG): Don't include target
|
||||||
|
board name.
|
||||||
|
|
||||||
* src/flash.c: Detect flash_page_size at runtime.
|
* src/flash.c: Detect flash_page_size at runtime.
|
||||||
|
|
||||||
* src/main.c: Remove dependency to board.h.
|
* src/main.c: Remove dependency to board.h.
|
||||||
|
|||||||
@@ -250,9 +250,10 @@ usb_cb_setup (uint8_t req, uint8_t req_no,
|
|||||||
|
|
||||||
int
|
int
|
||||||
usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
||||||
uint16_t index)
|
uint16_t index, uint16_t length)
|
||||||
{
|
{
|
||||||
(void)index;
|
(void)index;
|
||||||
|
(void)length;
|
||||||
if (rcp != DEVICE_RECIPIENT)
|
if (rcp != DEVICE_RECIPIENT)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
|
|||||||
4
src/configure
vendored
4
src/configure
vendored
@@ -252,7 +252,11 @@ SERIALNO="FSIJ-`cat ../VERSION | sed -e 's%^[^/]*/%%'`-"
|
|||||||
SERIALNO_STR_LEN_DEFINE="#define SERIALNO_STR_LEN ${#SERIALNO}"
|
SERIALNO_STR_LEN_DEFINE="#define SERIALNO_STR_LEN ${#SERIALNO}"
|
||||||
|
|
||||||
|
|
||||||
|
if test "$sys1_compat" = "yes"; then
|
||||||
CONFIG="$target:dfu=$with_dfu:debug=$debug:pinpad=$pinpad:certdo=$certdo:keygen=$keygen"
|
CONFIG="$target:dfu=$with_dfu:debug=$debug:pinpad=$pinpad:certdo=$certdo:keygen=$keygen"
|
||||||
|
else
|
||||||
|
CONFIG="dfu=$with_dfu:debug=$debug:pinpad=$pinpad:certdo=$certdo:keygen=$keygen"
|
||||||
|
fi
|
||||||
|
|
||||||
if !(IFS=" "
|
if !(IFS=" "
|
||||||
while read VIDPID VERSION PRODUCT VENDOR; do
|
while read VIDPID VERSION PRODUCT VENDOR; do
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
#ifndef __USB_CONF_H
|
#ifndef __USB_CONF_H
|
||||||
#define __USB_CONF_H
|
#define __USB_CONF_H
|
||||||
|
|
||||||
#define NUM_STRING_DESC 7
|
|
||||||
#define ICC_NUM_INTERFACES 1
|
#define ICC_NUM_INTERFACES 1
|
||||||
#define ICC_INTERFACE 0
|
#define ICC_INTERFACE 0
|
||||||
#ifdef HID_CARD_CHANGE_SUPPORT
|
#ifdef HID_CARD_CHANGE_SUPPORT
|
||||||
|
|||||||
@@ -478,7 +478,7 @@ int usb_cb_handle_event (uint8_t event_type, uint16_t value)
|
|||||||
|
|
||||||
int usb_cb_interface (uint8_t cmd, uint16_t interface, uint16_t alt)
|
int usb_cb_interface (uint8_t cmd, uint16_t interface, uint16_t alt)
|
||||||
{
|
{
|
||||||
static const uint8_t zero = 0;
|
const uint8_t zero = 0;
|
||||||
|
|
||||||
if (interface >= NUM_INTERFACES)
|
if (interface >= NUM_INTERFACES)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
@@ -495,7 +495,8 @@ int usb_cb_interface (uint8_t cmd, uint16_t interface, uint16_t alt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
case USB_GET_INTERFACE:
|
case USB_GET_INTERFACE:
|
||||||
usb_lld_set_data_to_send (&zero, 1);
|
usb_lld_write (ENDP0, &zero, 1);
|
||||||
|
usb_lld_set_data_to_send (NULL, 1);
|
||||||
return USB_SUCCESS;
|
return USB_SUCCESS;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -330,7 +330,7 @@ struct desc
|
|||||||
uint16_t size;
|
uint16_t size;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct desc String_Descriptors[NUM_STRING_DESC] = {
|
static const struct desc string_descriptors[] = {
|
||||||
{gnukStringLangID, sizeof (gnukStringLangID)},
|
{gnukStringLangID, sizeof (gnukStringLangID)},
|
||||||
{gnukStringVendor, sizeof (gnukStringVendor)},
|
{gnukStringVendor, sizeof (gnukStringVendor)},
|
||||||
{gnukStringProduct, sizeof (gnukStringProduct)},
|
{gnukStringProduct, sizeof (gnukStringProduct)},
|
||||||
@@ -339,13 +339,14 @@ static const struct desc String_Descriptors[NUM_STRING_DESC] = {
|
|||||||
{gnuk_config_options, sizeof (gnuk_config_options)},
|
{gnuk_config_options, sizeof (gnuk_config_options)},
|
||||||
{sys_version, sizeof (sys_version)},
|
{sys_version, sizeof (sys_version)},
|
||||||
};
|
};
|
||||||
|
#define NUM_STRING_DESC (sizeof (string_descriptors) / sizeof (struct desc))
|
||||||
|
|
||||||
#define USB_DT_HID 0x21
|
#define USB_DT_HID 0x21
|
||||||
#define USB_DT_REPORT 0x22
|
#define USB_DT_REPORT 0x22
|
||||||
|
|
||||||
int
|
int
|
||||||
usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
||||||
uint16_t index)
|
uint16_t index, uint16_t length)
|
||||||
{
|
{
|
||||||
if (rcp == DEVICE_RECIPIENT)
|
if (rcp == DEVICE_RECIPIENT)
|
||||||
{
|
{
|
||||||
@@ -365,8 +366,30 @@ usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
|||||||
{
|
{
|
||||||
if (desc_index < NUM_STRING_DESC)
|
if (desc_index < NUM_STRING_DESC)
|
||||||
{
|
{
|
||||||
usb_lld_set_data_to_send (String_Descriptors[desc_index].desc,
|
usb_lld_set_data_to_send (string_descriptors[desc_index].desc,
|
||||||
String_Descriptors[desc_index].size);
|
string_descriptors[desc_index].size);
|
||||||
|
return USB_SUCCESS;
|
||||||
|
}
|
||||||
|
else if (desc_index == NUM_STRING_DESC)
|
||||||
|
{
|
||||||
|
uint8_t usbbuf[64];
|
||||||
|
int i;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
for (i = 0; i < (int)sizeof (usbbuf)/2 - 2; i++)
|
||||||
|
{
|
||||||
|
if (sys_board_name[i] == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
usbbuf[i*2+2] = sys_board_name[i];
|
||||||
|
usbbuf[i*2+3] = 0;
|
||||||
|
}
|
||||||
|
usbbuf[0] = len = i*2 + 2;
|
||||||
|
usbbuf[1] = USB_STRING_DESCRIPTOR_TYPE;
|
||||||
|
if (len > length)
|
||||||
|
len = length;
|
||||||
|
usb_lld_write (ENDP0, usbbuf, len);
|
||||||
|
usb_lld_set_data_to_send (NULL, len);
|
||||||
return USB_SUCCESS;
|
return USB_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -392,15 +415,6 @@ usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
|||||||
#else
|
#else
|
||||||
(void)index;
|
(void)index;
|
||||||
#endif
|
#endif
|
||||||
if (desc_type == STRING_DESCRIPTOR)
|
|
||||||
{
|
|
||||||
if (desc_index < NUM_STRING_DESC)
|
|
||||||
{
|
|
||||||
usb_lld_set_data_to_send (String_Descriptors[desc_index].desc,
|
|
||||||
String_Descriptors[desc_index].size);
|
|
||||||
return USB_SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ void usb_cb_ctrl_write_finish (uint8_t req, uint8_t req_no,
|
|||||||
int usb_cb_setup (uint8_t req, uint8_t req_no, uint16_t value,
|
int usb_cb_setup (uint8_t req, uint8_t req_no, uint16_t value,
|
||||||
uint16_t index, uint16_t len);
|
uint16_t index, uint16_t len);
|
||||||
int usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
int usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
||||||
uint16_t index);
|
uint16_t index, uint16_t length);
|
||||||
int usb_cb_handle_event (uint8_t event_type, uint16_t value);
|
int usb_cb_handle_event (uint8_t event_type, uint16_t value);
|
||||||
int usb_cb_interface (uint8_t cmd, uint16_t interface, uint16_t value);
|
int usb_cb_interface (uint8_t cmd, uint16_t interface, uint16_t value);
|
||||||
|
|
||||||
|
|||||||
@@ -698,7 +698,8 @@ static int std_get_descriptor (uint8_t req, uint16_t value,
|
|||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
(void)length;
|
(void)length;
|
||||||
return usb_cb_get_descriptor (rcp, (value >> 8), (value & 0xff), index);
|
return usb_cb_get_descriptor (rcp, (value >> 8), (value & 0xff),
|
||||||
|
index, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int std_get_configuration (uint8_t req, uint16_t value,
|
static int std_get_configuration (uint8_t req, uint16_t value,
|
||||||
@@ -851,14 +852,23 @@ static void handle_setup0 (void)
|
|||||||
if (data_p->len > len)
|
if (data_p->len > len)
|
||||||
data_p->len = len;
|
data_p->len = len;
|
||||||
|
|
||||||
if ((data_p->len % USB_MAX_PACKET_SIZE) == 0)
|
if (data_p->len != 0 && (data_p->len % USB_MAX_PACKET_SIZE) == 0)
|
||||||
data_p->require_zlp = TRUE;
|
data_p->require_zlp = TRUE;
|
||||||
else
|
else
|
||||||
data_p->require_zlp = FALSE;
|
data_p->require_zlp = FALSE;
|
||||||
|
|
||||||
|
if (data_p->addr == NULL)
|
||||||
|
{
|
||||||
|
/* usb_lld_wite was called already by the setup callback. */
|
||||||
|
dev_p->state = LAST_IN_DATA;
|
||||||
|
data_p->len = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
dev_p->state = IN_DATA;
|
dev_p->state = IN_DATA;
|
||||||
handle_datastage_in ();
|
handle_datastage_in ();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (ctrl_p->wLength == 0)
|
else if (ctrl_p->wLength == 0)
|
||||||
{
|
{
|
||||||
dev_p->state = WAIT_STATUS_IN;
|
dev_p->state = WAIT_STATUS_IN;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ def gnuk_devices():
|
|||||||
continue
|
continue
|
||||||
yield dev
|
yield dev
|
||||||
|
|
||||||
title = [ '', 'Vendor', 'Product', 'Serial', 'Revision', 'Config', 'Sys' ]
|
field = ['', 'Vendor', 'Product', 'Serial', 'Revision', 'Config', 'Sys', 'Board']
|
||||||
|
|
||||||
def main(n):
|
def main(n):
|
||||||
for dev in gnuk_devices():
|
for dev in gnuk_devices():
|
||||||
@@ -47,7 +47,7 @@ def main(n):
|
|||||||
try:
|
try:
|
||||||
for i in range(1,n):
|
for i in range(1,n):
|
||||||
str = handle.getString(i, 512)
|
str = handle.getString(i, 512)
|
||||||
print "%10s: %s" % (title[i], str)
|
print "%10s: %s" % (field[i], str)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
del dev
|
del dev
|
||||||
@@ -56,5 +56,5 @@ if __name__ == '__main__':
|
|||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
n = int(sys.argv[1])
|
n = int(sys.argv[1])
|
||||||
else:
|
else:
|
||||||
n = 7 # Gnuk has seven strings
|
n = 8 # Gnuk has eight strings
|
||||||
main(n)
|
main(n)
|
||||||
|
|||||||
Reference in New Issue
Block a user