This commit is contained in:
NIIBE Yutaka
2011-12-09 17:53:45 +09:00
parent ec409fe8a4
commit f58233aa5d
6 changed files with 181 additions and 47 deletions

View File

@@ -101,6 +101,10 @@ ifneq ($(ENABLE_PINPAD),)
CSRC += pin-$(ENABLE_PINPAD).c CSRC += pin-$(ENABLE_PINPAD).c
endif endif
ifeq ($(ENABLE_PINPAD),dnd)
CSRC += usb_msc.c
endif
# List ASM source files here # List ASM source files here
ASMSRC = $(PORTASM) \ ASMSRC = $(PORTASM) \
$(CHIBIOS)/os/ports/GCC/ARMCMx/STM32F10x/vectors.s $(CHIBIOS)/os/ports/GCC/ARMCMx/STM32F10x/vectors.s

10
src/configure vendored
View File

@@ -86,8 +86,8 @@ Configuration:
STM8S_DISCOVERY STM8S_DISCOVERY
STBEE STBEE
--enable-debug debug with virtual COM port [no] --enable-debug debug with virtual COM port [no]
--enable-pinpad={cir,dial} --enable-pinpad={dnd,cir,dial}
PIN input device support [no] PIN entry support [no]
--with-dfu build image for DFU [<target specific>] --with-dfu build image for DFU [<target specific>]
EOF EOF
exit 0 exit 0
@@ -159,10 +159,10 @@ if test "$pinpad" = "no"; then
PINPAD_MORE_DEFINE="" PINPAD_MORE_DEFINE=""
echo "PIN pad option disabled" echo "PIN pad option disabled"
elif test "$pinpad" = "yes"; then elif test "$pinpad" = "yes"; then
PINPAD_MAKE_OPTION="ENABLE_PINPAD=cir" PINPAD_MAKE_OPTION="ENABLE_PINPAD=dnd"
PINPAD_DEFINE="#define PINPAD_SUPPORT 1" PINPAD_DEFINE="#define PINPAD_SUPPORT 1"
PINPAD_MORE_DEFINE="#define PINPAD_CIR_SUPPORT 1" PINPAD_MORE_DEFINE="#define PINPAD_DND_SUPPORT 1"
echo "PIN pad option enabled (cir)" echo "PIN pad option enabled (dnd)"
else else
PINPAD_MAKE_OPTION="ENABLE_PINPAD=$pinpad" PINPAD_MAKE_OPTION="ENABLE_PINPAD=$pinpad"
PINPAD_DEFINE="#define PINPAD_SUPPORT 1" PINPAD_DEFINE="#define PINPAD_SUPPORT 1"

View File

@@ -439,13 +439,6 @@ main (int argc, char **argv)
"Hello world\r\n\r\n", 35+21+15); "Hello world\r\n\r\n", 35+21+15);
} }
#endif #endif
if (msc_recv_cbw () == 0)
{
int r = msc_handle_cbw ();
if (r != 1)
msc_handle_err (r);
}
} }
return 0; return 0;

View File

@@ -1,10 +1,65 @@
#include <stdint.h>
#include "config.h" #include "config.h"
#include "ch.h" #include "ch.h"
#include "board.h" #include "board.h"
#include "gnuk.h"
#include "usb_msc.h"
extern Thread *main_thread; uint8_t pin_input_buffer[MAX_PIN_CHARS];
uint8_t pin_input_len;
static Thread *pin_thread;
/*
* Let user input PIN string.
* Return length of the string.
* The string itself is in PIN_INPUT_BUFFER.
*/
int
pinpad_getline (int msg_code, systime_t timeout)
{
msg_t msg;
(void)msg_code;
DEBUG_INFO (">>>\r\n");
pin_input_len = 0;
while (1)
{
chSysLock ();
msc_media_insert_change (1);
pin_thread = chThdSelf ();
chSchGoSleepS (THD_STATE_SUSPENDED);
msg = chThdSelf ()->p_u.rdymsg;
chSysUnlock ();
led_blink (0);
if (msg == 1)
break;
}
msc_media_insert_change (0);
return pin_input_len;
}
static void pinpad_input (void)
{
chSysLock ();
pin_thread->p_u.rdymsg = 0;
chSchReadyI (pin_thread);
chSysUnlock ();
}
static void pinpad_finish_entry (void)
{
chSysLock ();
pin_thread->p_u.rdymsg = 1;
chSchReadyI (pin_thread);
chSysUnlock ();
}
#define TOTAL_SECTOR 68 #define TOTAL_SECTOR 68
@@ -195,8 +250,6 @@ msc_scsi_read (uint32_t lba, const uint8_t **sector_p)
} }
} }
uint8_t datetime_string[29];
static uint8_t *dts = datetime_string;
static void parse_directory_sector (const uint8_t *p, uint8_t index) static void parse_directory_sector (const uint8_t *p, uint8_t index)
{ {
@@ -206,6 +259,8 @@ static void parse_directory_sector (const uint8_t *p, uint8_t index)
0x20, 0x20, 0x20 }; 0x20, 0x20, 0x20 };
uint8_t child; uint8_t child;
uint8_t *p_orig = p; uint8_t *p_orig = p;
int input = 0;
int num_children = 0;
if (index != 0) if (index != 0)
{ {
@@ -218,24 +273,38 @@ static void parse_directory_sector (const uint8_t *p, uint8_t index)
cluster_no = p[26] | (p[27] << 8); cluster_no = p[26] | (p[27] << 8);
dest_index = CLUSTER_NO_TO_FOLDER_INDEX (cluster_no); dest_index = CLUSTER_NO_TO_FOLDER_INDEX (cluster_no);
if (dest_index >= 1 && dest_index <= 7) if (dest_index < 1 || dest_index > 7)
dts += sprintf (dts, "%c%c ", FOLDER_INDEX_TO_DIRCHAR (index), ; /* it can be 255 : root_dir */
FOLDER_INDEX_TO_DIRCHAR (dest_index));
else else
; /* can be 255 : root_dir */ if (pin_input_len < MAX_PIN_CHARS - 2)
{
pin_input_buffer[pin_input_len++]
= FOLDER_INDEX_TO_DIRCHAR (index);
pin_input_buffer[pin_input_len++]
= FOLDER_INDEX_TO_DIRCHAR (dest_index);
input = 1;
}
p += 32; p += 32;
} }
for (i = 0; i < 7; i++) for (i = 0; i < 7; i++)
{
if (*p) if (*p)
{ {
child = DIRCHAR_TO_FOLDER_INDEX (*p); child = DIRCHAR_TO_FOLDER_INDEX (*p);
folders[index].children[i] = child; folders[index].children[i] = child;
p += 32; num_children++;
} }
else else
break; folders[index].children[i] = 0;
p += 32;
}
if (index == 0 && num_children == 1)
pinpad_finish_entry ();
else if (input)
pinpad_input ();
} }
int int

View File

@@ -141,8 +141,6 @@ void EP7_OUT_Callback (void)
} }
} }
static const uint8_t lun_buf[4] = {0, 0, 0, 0}; /* One drives: 0 */
static const uint8_t scsi_inquiry_data_00[] = { 0, 0, 0, 0, 0 }; static const uint8_t scsi_inquiry_data_00[] = { 0, 0, 0, 0, 0 };
static const uint8_t scsi_inquiry_data[] = { static const uint8_t scsi_inquiry_data[] = {
@@ -280,6 +278,7 @@ static void msc_send_result (const uint8_t *p, size_t n)
} }
void msc_handle_command (void) void msc_handle_command (void)
{ {
size_t n; size_t n;
@@ -500,3 +499,22 @@ void msc_handle_command (void)
} }
} }
} }
static msg_t
msc_main (void *arg)
{
(void)arg;
while (1)
msc_handle_command ();
return 0;
}
static WORKING_AREA(wa_msc_thread, 128);
void msc_init (void)
{
chThdCreateStatic (wa_msc_thread, sizeof (wa_msc_thread),
NORMALPRIO, msc_main, NULL);
}

View File

@@ -36,6 +36,10 @@
#include "usb-cdc-vport.c" #include "usb-cdc-vport.c"
#endif #endif
#ifdef PINPAD_DND_SUPPORT
#include "usb_msc.h"
#endif
static void static void
gnuk_device_init (void) gnuk_device_init (void)
@@ -247,11 +251,24 @@ gnuk_data_rates (uint16_t len)
return (uint8_t *)data_rate_table; return (uint8_t *)data_rate_table;
} }
static const uint8_t lun_table[] = { 0, 0, 0, 0, };
static uint8_t *
msc_lun_info (uint16_t len)
{
if (len == 0)
{
pInformation->Ctrl_Info.Usb_wLength = sizeof (lun_table);
return NULL;
}
return (uint8_t *)lun_table;
}
static RESULT static RESULT
gnuk_setup_with_data (uint8_t RequestNo) gnuk_setup_with_data (uint8_t RequestNo)
{ {
if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) /* Interface */
if (pInformation->USBwIndex0 == 0) /* Interface */ if (pInformation->USBwIndex0 == 0)
{ {
if (RequestNo == USB_CCID_REQ_GET_CLOCK_FREQUENCIES) if (RequestNo == USB_CCID_REQ_GET_CLOCK_FREQUENCIES)
{ {
@@ -270,23 +287,41 @@ gnuk_setup_with_data (uint8_t RequestNo)
else else
return USB_UNSUPPORT; return USB_UNSUPPORT;
} }
else #if defined(PINPAD_DND_SUPPORT)
{
# if defined(ENABLE_VIRTUAL_COM_PORT) # if defined(ENABLE_VIRTUAL_COM_PORT)
else if (pInformation->USBwIndex0 == 2)
return Virtual_Com_Port_Data_Setup (RequestNo); return Virtual_Com_Port_Data_Setup (RequestNo);
else if (pInformation->USBwIndex0 == 3)
# else # else
return USB_UNSUPPORT; else if (pInformation->USBwIndex0 == 1)
# endif # endif
{
if (RequestNo == MSC_GET_MAX_LUN_COMMAND)
{
pInformation->Ctrl_Info.CopyData = msc_lun_info;
pInformation->Ctrl_Info.Usb_wOffset = 0;
msc_lun_info (0);
return USB_SUCCESS;
} }
else else
return USB_UNSUPPORT; return USB_UNSUPPORT;
} }
#elif defined(ENABLE_VIRTUAL_COM_PORT)
else if (pInformation->USBwIndex0 == 2)
return Virtual_Com_Port_Data_Setup (RequestNo);
#endif
else
return USB_UNSUPPORT;
else
return USB_UNSUPPORT;
}
static RESULT static RESULT
gnuk_setup_with_nodata (uint8_t RequestNo) gnuk_setup_with_nodata (uint8_t RequestNo)
{ {
if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) /* Interface */
if (pInformation->USBwIndex0 == 0) /* Interface */ if (pInformation->USBwIndex0 == 0)
{ {
if (RequestNo == USB_CCID_REQ_ABORT) if (RequestNo == USB_CCID_REQ_ABORT)
/* wValue: bSeq, bSlot */ /* wValue: bSeq, bSlot */
@@ -295,17 +330,32 @@ gnuk_setup_with_nodata (uint8_t RequestNo)
else else
return USB_UNSUPPORT; return USB_UNSUPPORT;
} }
else #if defined(PINPAD_DND_SUPPORT)
{
# if defined(ENABLE_VIRTUAL_COM_PORT) # if defined(ENABLE_VIRTUAL_COM_PORT)
else if (pInformation->USBwIndex0 == 2)
return Virtual_Com_Port_NoData_Setup (RequestNo); return Virtual_Com_Port_NoData_Setup (RequestNo);
else if (pInformation->USBwIndex0 == 3)
# else # else
return USB_UNSUPPORT; else if (pInformation->USBwIndex0 == 1)
# endif # endif
{
if (RequestNo == MSC_MASS_STORAGE_RESET_COMMAND)
{
/* Should call resetting MSC thread, something like msc_reset() */
return USB_SUCCESS;
} }
else else
return USB_UNSUPPORT; return USB_UNSUPPORT;
} }
#elif defined(ENABLE_VIRTUAL_COM_PORT)
else if (pInformation->USBwIndex0 == 2)
return Virtual_Com_Port_NoData_Setup (RequestNo);
#endif
else
return USB_UNSUPPORT;
else
return USB_UNSUPPORT;
}
/* /*
* Interface to USB core * Interface to USB core