diff --git a/ChangeLog b/ChangeLog index 305f668..22604e5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2016-05-12 Niibe Yutaka + + * chopstx: Update + * src/sys.c: Update from Chopstx. + * src/usb_lld.h: Likewise. + * src/usb_stm32f103.c: Likewise. + + * src/usb_ctrl.c (usb_intr): Follow the change of USB API. + * src/main.c (usb_cb_rx_ready, usb_cb_tx_done): Likewise. + + * src/adc.h: Remove unused declarations. + 2016-03-08 Niibe Yutaka * tool/gnuk_token.py (gnuk_token.__init__, regnual.__init__): diff --git a/chopstx b/chopstx index a30a069..fabd271 160000 --- a/chopstx +++ b/chopstx @@ -1 +1 @@ -Subproject commit a30a069ed8e75f14b520b407b07a3f137b87ef1c +Subproject commit fabd271196710655a508b8b2727945ddc581d2ae diff --git a/src/adc.h b/src/adc.h index 67367b0..54e1f4e 100644 --- a/src/adc.h +++ b/src/adc.h @@ -1,15 +1,7 @@ -extern chopstx_mutex_t adc_mtx; -extern chopstx_cond_t adc_cond; -extern int adc_waiting; -extern int adc_data_available; - void adc_init (void); void adc_start (void); void adc_stop (void); -#define ADC_SAMPLE_MODE 0 -#define ADC_CRC32_MODE 1 - extern uint32_t adc_buf[64]; void adc_start_conversion (int offset, int count); diff --git a/src/main.c b/src/main.c index e921033..549d16c 100644 --- a/src/main.c +++ b/src/main.c @@ -1,7 +1,7 @@ /* * main.c - main routine of Gnuk * - * Copyright (C) 2010, 2011, 2012, 2013, 2015 + * Copyright (C) 2010, 2011, 2012, 2013, 2015, 2016 * Free Software Initiative of Japan * Author: NIIBE Yutaka * @@ -85,21 +85,6 @@ _write (const char *s, int len) chopstx_mutex_unlock (&stdout.m); } -void -EP3_IN_Callback (void) -{ - chopstx_mutex_lock (&stdout.m_dev); - chopstx_cond_signal (&stdout.cond_dev); - chopstx_mutex_unlock (&stdout.m_dev); -} - -void -EP5_OUT_Callback (void) -{ - chopstx_mutex_lock (&stdout.m_dev); - usb_lld_rx_enable (ENDP5); - chopstx_mutex_unlock (&stdout.m_dev); -} #else void _write (const char *s, int size) @@ -111,6 +96,48 @@ _write (const char *s, int size) extern void *USBthread (void *arg); +extern void EP1_IN_Callback (void); +extern void EP2_IN_Callback (void); +extern void EP1_OUT_Callback (void); +extern void EP6_IN_Callback (void); + +void +usb_cb_rx_ready (uint8_t ep_num) +{ + if (ep_num == ENDP1) + EP1_OUT_Callback (); +#ifdef DEBUG + else if (ep_num == ENDP5) + { + chopstx_mutex_lock (&stdout.m_dev); + usb_lld_rx_enable (ep_num); + chopstx_mutex_unlock (&stdout.m_dev); + } +#endif +} + +void +usb_cb_tx_done (uint8_t ep_num) +{ + if (ep_num == ENDP1) + EP1_IN_Callback (); + else if (ep_num == ENDP2) + EP2_IN_Callback (); +#ifdef DEBUG + else if (ep_num == ENDP3) + { + chopstx_mutex_lock (&stdout.m_dev); + chopstx_cond_signal (&stdout.cond_dev); + chopstx_mutex_unlock (&stdout.m_dev); + } +#endif +#ifdef PINPAD_SUPPORT + else if (ep_num == ENDP6) + EP6_IN_Callback (); +#endif +} + + /* * main thread does 1-bit LED display output */ diff --git a/src/sys.c b/src/sys.c index 586a79f..7ab8ce4 100644 --- a/src/sys.c +++ b/src/sys.c @@ -17,7 +17,7 @@ #include #include "board.h" -#include "clk_gpio_init.c" +#include "clk_gpio_init-stm32.c" #define CORTEX_PRIORITY_BITS 4 #define CORTEX_PRIORITY_MASK(n) ((n) << (8 - CORTEX_PRIORITY_BITS)) @@ -25,17 +25,17 @@ #define STM32_USB_IRQ_PRIORITY 11 struct NVIC { - uint32_t ISER[8]; - uint32_t unused1[24]; - uint32_t ICER[8]; - uint32_t unused2[24]; - uint32_t ISPR[8]; - uint32_t unused3[24]; - uint32_t ICPR[8]; - uint32_t unused4[24]; - uint32_t IABR[8]; - uint32_t unused5[56]; - uint32_t IPR[60]; + volatile uint32_t ISER[8]; + volatile uint32_t unused1[24]; + volatile uint32_t ICER[8]; + volatile uint32_t unused2[24]; + volatile uint32_t ISPR[8]; + volatile uint32_t unused3[24]; + volatile uint32_t ICPR[8]; + volatile uint32_t unused4[24]; + volatile uint32_t IABR[8]; + volatile uint32_t unused5[56]; + volatile uint32_t IPR[60]; }; static struct NVIC *const NVICBase = ((struct NVIC *const)0xE000E100); diff --git a/src/usb_ctrl.c b/src/usb_ctrl.c index d1815f7..d28c8fb 100644 --- a/src/usb_ctrl.c +++ b/src/usb_ctrl.c @@ -199,13 +199,7 @@ usb_cb_device_reset (void) { int i; - /* Set DEVICE as not configured */ - usb_lld_set_configuration (0); - - /* Current Feature initialization */ - usb_lld_set_feature (USB_INITIAL_FEATURE); - - usb_lld_reset (); + usb_lld_reset (USB_INITIAL_FEATURE); /* Initialize Endpoint 0 */ usb_lld_setup_endpoint (ENDP0, EP_CONTROL, 0, ENDP0_RXADDR, ENDP0_TXADDR, diff --git a/src/usb_lld.h b/src/usb_lld.h index 34a1068..3710f20 100644 --- a/src/usb_lld.h +++ b/src/usb_lld.h @@ -63,6 +63,8 @@ int usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index, int usb_cb_handle_event (uint8_t event_type, uint16_t value); void usb_cb_ctrl_write_finish (uint8_t req, uint8_t req_no, struct req_args *arg); +void usb_cb_tx_done (uint8_t ep_num); +void usb_cb_rx_ready (uint8_t ep_num); enum { USB_EVENT_ADDRESS, @@ -102,13 +104,12 @@ int usb_lld_reply_request (const void *buf, size_t buflen, void usb_lld_rx_enable (int ep_num); int usb_lld_rx_data_len (int ep_num); void usb_lld_rxcpy (uint8_t *dst, int ep_num, int offset, size_t len); -void usb_lld_reset (void); +void usb_lld_reset (uint8_t feature); void usb_lld_setup_endpoint (int ep_num, int ep_type, int ep_kind, int ep_rx_addr, int ep_tx_addr, int ep_rx_memory_size); void usb_lld_set_configuration (uint8_t config); uint8_t usb_lld_current_configuration (void); -void usb_lld_set_feature (uint8_t feature); void usb_lld_set_data_to_recv (void *p, size_t len); void usb_lld_prepare_shutdown (void); diff --git a/src/usb_stm32f103.c b/src/usb_stm32f103.c index 7df3841..80fbcc7 100644 --- a/src/usb_stm32f103.c +++ b/src/usb_stm32f103.c @@ -355,7 +355,7 @@ void usb_lld_init (uint8_t feature) dev_p->state = IN_DATA; usb_lld_set_configuration (0); - usb_lld_set_feature (feature); + dev_p->current_feature = feature; /* Reset USB */ st103_set_cntr (CNTR_FRES); @@ -478,7 +478,7 @@ static int std_get_status (uint8_t req, struct req_args *arg) uint16_t status_info = 0; if (arg->value != 0 || arg->len != 2 || (arg->index >> 8) != 0 - || (req & REQUEST_DIR) == 0) + || USB_SETUP_SET (req)) return USB_UNSUPPORT; if (rcp == DEVICE_RECIPIENT) @@ -551,7 +551,7 @@ static int std_clear_feature (uint8_t req, struct req_args *arg) { uint8_t rcp = req & RECIPIENT; - if ((req & REQUEST_DIR) == 1) + if (USB_SETUP_GET (req)) return USB_UNSUPPORT; if (rcp == DEVICE_RECIPIENT) @@ -601,7 +601,7 @@ static int std_set_feature (uint8_t req, struct req_args *arg) { uint8_t rcp = req & RECIPIENT; - if ((req & REQUEST_DIR) == 1) + if (USB_SETUP_GET (req)) return USB_UNSUPPORT; if (rcp == DEVICE_RECIPIENT) @@ -654,7 +654,7 @@ static int std_set_address (uint8_t req, struct req_args *arg) { uint8_t rcp = req & RECIPIENT; - if ((req & REQUEST_DIR) == 1) + if (USB_SETUP_GET (req)) return USB_UNSUPPORT; if (rcp == DEVICE_RECIPIENT && arg->len == 0 && arg->value <= 127 @@ -668,7 +668,7 @@ static int std_get_descriptor (uint8_t req, struct req_args *arg) { uint8_t rcp = req & RECIPIENT; - if ((req & REQUEST_DIR) == 0) + if (USB_SETUP_SET (req)) return USB_UNSUPPORT; return usb_cb_get_descriptor (rcp, (arg->value >> 8), @@ -679,7 +679,7 @@ static int std_get_configuration (uint8_t req, struct req_args *arg) { uint8_t rcp = req & RECIPIENT; - if ((req & REQUEST_DIR) == 0) + if (USB_SETUP_SET (req)) return USB_UNSUPPORT; if (rcp == DEVICE_RECIPIENT) @@ -692,7 +692,7 @@ static int std_set_configuration (uint8_t req, struct req_args *arg) { uint8_t rcp = req & RECIPIENT; - if ((req & REQUEST_DIR) == 1) + if (USB_SETUP_GET (req)) return USB_UNSUPPORT; if (rcp == DEVICE_RECIPIENT && arg->index == 0 && arg->len == 0) @@ -705,7 +705,7 @@ static int std_get_interface (uint8_t req, struct req_args *arg) { uint8_t rcp = req & RECIPIENT; - if ((req & REQUEST_DIR) == 0) + if (USB_SETUP_SET (req)) return USB_UNSUPPORT; if (rcp == INTERFACE_RECIPIENT) @@ -726,7 +726,7 @@ static int std_set_interface (uint8_t req, struct req_args *arg) { uint8_t rcp = req & RECIPIENT; - if ((req & REQUEST_DIR) == 1 || rcp != INTERFACE_RECIPIENT + if (USB_SETUP_GET (req) || rcp != INTERFACE_RECIPIENT || arg->len != 0 || (arg->index >> 8) != 0 || (arg->value >> 8) != 0 || dev_p->current_configuration == 0) return USB_UNSUPPORT; @@ -843,27 +843,6 @@ static void handle_out0 (void) dev_p->state = STALLED; } -static void nop_proc (void) -{ -} - -#define WEAK __attribute__ ((weak, alias ("nop_proc"))) -void WEAK EP1_IN_Callback (void); -void WEAK EP2_IN_Callback (void); -void WEAK EP3_IN_Callback (void); -void WEAK EP4_IN_Callback (void); -void WEAK EP5_IN_Callback (void); -void WEAK EP6_IN_Callback (void); -void WEAK EP7_IN_Callback (void); - -void WEAK EP1_OUT_Callback (void); -void WEAK EP2_OUT_Callback (void); -void WEAK EP3_OUT_Callback (void); -void WEAK EP4_OUT_Callback (void); -void WEAK EP5_OUT_Callback (void); -void WEAK EP6_OUT_Callback (void); -void WEAK EP7_OUT_Callback (void); - static void usb_handle_transfer (uint16_t istr_value) { @@ -901,37 +880,21 @@ usb_handle_transfer (uint16_t istr_value) if ((ep_value & EP_CTR_RX)) { st103_ep_clear_ctr_rx (ep_index); - switch ((ep_index - 1)) - { - case 0: EP1_OUT_Callback (); break; - case 1: EP2_OUT_Callback (); break; - case 2: EP3_OUT_Callback (); break; - case 3: EP4_OUT_Callback (); break; - case 4: EP5_OUT_Callback (); break; - case 5: EP6_OUT_Callback (); break; - case 6: EP7_OUT_Callback (); break; - } + usb_cb_rx_ready (ep_index); } if ((ep_value & EP_CTR_TX)) { st103_ep_clear_ctr_tx (ep_index); - switch ((ep_index - 1)) - { - case 0: EP1_IN_Callback (); break; - case 1: EP2_IN_Callback (); break; - case 2: EP3_IN_Callback (); break; - case 3: EP4_IN_Callback (); break; - case 4: EP5_IN_Callback (); break; - case 5: EP6_IN_Callback (); break; - case 6: EP7_IN_Callback (); break; - } + usb_cb_tx_done (ep_index); } } } -void usb_lld_reset (void) +void usb_lld_reset (uint8_t feature) { + usb_lld_set_configuration (0); + dev_p->current_feature = feature; st103_set_btable (); st103_set_daddr (0); } @@ -1038,11 +1001,6 @@ uint8_t usb_lld_current_configuration (void) return dev_p->current_configuration; } -void usb_lld_set_feature (uint8_t feature) -{ - dev_p->current_feature = feature; -} - void usb_lld_set_data_to_recv (void *p, size_t len) { data_p->addr = p;