From 8ddcc1e896f8eacb0dff205d1060ae90b9336b2e Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Wed, 15 Jul 2015 16:37:19 +0900 Subject: [PATCH] support Board --- ChangeLog | 15 +++++++++++++++ regnual/regnual.c | 3 ++- src/configure | 6 +++++- src/usb_conf.h | 1 - src/usb_ctrl.c | 5 +++-- src/usb_desc.c | 40 +++++++++++++++++++++++++++------------- src/usb_lld.h | 2 +- src/usb_stm32f103.c | 18 ++++++++++++++---- tool/usb_strings.py | 6 +++--- 9 files changed, 70 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 01d673f..df4c4b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,20 @@ 2015-07-15 Niibe Yutaka + * 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/main.c: Remove dependency to board.h. diff --git a/regnual/regnual.c b/regnual/regnual.c index c05181f..31e2164 100644 --- a/regnual/regnual.c +++ b/regnual/regnual.c @@ -250,9 +250,10 @@ usb_cb_setup (uint8_t req, uint8_t req_no, 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) { (void)index; + (void)length; if (rcp != DEVICE_RECIPIENT) return USB_UNSUPPORT; diff --git a/src/configure b/src/configure index 946236a..064aa0c 100755 --- a/src/configure +++ b/src/configure @@ -252,7 +252,11 @@ SERIALNO="FSIJ-`cat ../VERSION | sed -e 's%^[^/]*/%%'`-" SERIALNO_STR_LEN_DEFINE="#define SERIALNO_STR_LEN ${#SERIALNO}" -CONFIG="$target:dfu=$with_dfu:debug=$debug:pinpad=$pinpad:certdo=$certdo:keygen=$keygen" +if test "$sys1_compat" = "yes"; then + 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=" " while read VIDPID VERSION PRODUCT VENDOR; do diff --git a/src/usb_conf.h b/src/usb_conf.h index c9c67d6..54a6745 100644 --- a/src/usb_conf.h +++ b/src/usb_conf.h @@ -3,7 +3,6 @@ #ifndef __USB_CONF_H #define __USB_CONF_H -#define NUM_STRING_DESC 7 #define ICC_NUM_INTERFACES 1 #define ICC_INTERFACE 0 #ifdef HID_CARD_CHANGE_SUPPORT diff --git a/src/usb_ctrl.c b/src/usb_ctrl.c index 1d68891..01e7139 100644 --- a/src/usb_ctrl.c +++ b/src/usb_ctrl.c @@ -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) { - static const uint8_t zero = 0; + const uint8_t zero = 0; if (interface >= NUM_INTERFACES) return USB_UNSUPPORT; @@ -495,7 +495,8 @@ int usb_cb_interface (uint8_t cmd, uint16_t interface, uint16_t alt) } 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; default: diff --git a/src/usb_desc.c b/src/usb_desc.c index d278635..32b86f7 100644 --- a/src/usb_desc.c +++ b/src/usb_desc.c @@ -330,7 +330,7 @@ struct desc uint16_t size; }; -static const struct desc String_Descriptors[NUM_STRING_DESC] = { +static const struct desc string_descriptors[] = { {gnukStringLangID, sizeof (gnukStringLangID)}, {gnukStringVendor, sizeof (gnukStringVendor)}, {gnukStringProduct, sizeof (gnukStringProduct)}, @@ -339,13 +339,14 @@ static const struct desc String_Descriptors[NUM_STRING_DESC] = { {gnuk_config_options, sizeof (gnuk_config_options)}, {sys_version, sizeof (sys_version)}, }; +#define NUM_STRING_DESC (sizeof (string_descriptors) / sizeof (struct desc)) #define USB_DT_HID 0x21 #define USB_DT_REPORT 0x22 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) { 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) { - usb_lld_set_data_to_send (String_Descriptors[desc_index].desc, - String_Descriptors[desc_index].size); + usb_lld_set_data_to_send (string_descriptors[desc_index].desc, + 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; } } @@ -392,15 +415,6 @@ usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index, #else (void)index; #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; diff --git a/src/usb_lld.h b/src/usb_lld.h index 3ca1185..dfaedb7 100644 --- a/src/usb_lld.h +++ b/src/usb_lld.h @@ -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, uint16_t index, uint16_t len); 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_interface (uint8_t cmd, uint16_t interface, uint16_t value); diff --git a/src/usb_stm32f103.c b/src/usb_stm32f103.c index 2c946eb..a624e9b 100644 --- a/src/usb_stm32f103.c +++ b/src/usb_stm32f103.c @@ -698,7 +698,8 @@ static int std_get_descriptor (uint8_t req, uint16_t value, return USB_UNSUPPORT; (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, @@ -851,13 +852,22 @@ static void handle_setup0 (void) if (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; else data_p->require_zlp = FALSE; - dev_p->state = IN_DATA; - handle_datastage_in (); + 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; + handle_datastage_in (); + } } else if (ctrl_p->wLength == 0) { diff --git a/tool/usb_strings.py b/tool/usb_strings.py index 5d50c55..e24c0f2 100755 --- a/tool/usb_strings.py +++ b/tool/usb_strings.py @@ -38,7 +38,7 @@ def gnuk_devices(): continue yield dev -title = [ '', 'Vendor', 'Product', 'Serial', 'Revision', 'Config', 'Sys' ] +field = ['', 'Vendor', 'Product', 'Serial', 'Revision', 'Config', 'Sys', 'Board'] def main(n): for dev in gnuk_devices(): @@ -47,7 +47,7 @@ def main(n): try: for i in range(1,n): str = handle.getString(i, 512) - print "%10s: %s" % (title[i], str) + print "%10s: %s" % (field[i], str) except: pass del dev @@ -56,5 +56,5 @@ if __name__ == '__main__': if len(sys.argv) > 1: n = int(sys.argv[1]) else: - n = 7 # Gnuk has seven strings + n = 8 # Gnuk has eight strings main(n)