Skip to content

Commit 581bf67

Browse files
committed
updated init code
1 parent 797ddab commit 581bf67

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/usb.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -358,22 +358,29 @@ __xdata uint8_t scratch[512];
358358
uint16_t ep0_xfer_bytes_left;
359359
uint8_t *ep0_xfer_src;
360360

361-
uint8_t received_usb_addr;
362-
361+
// usb state
362+
uint8_t __xdata received_usb_addr;
363363
uint8_t __xdata interface0_protocol;
364364
uint8_t __xdata interface1_protocol;
365+
uint8_t __xdata idle_time;
366+
uint8_t __xdata active_configution;
367+
uint8_t __xdata ep0_xfer_state;
365368

366369
// TODO: remove
367370
volatile __bit device_remote_wakeup_f;
368-
volatile uint8_t __xdata configution_value;
369371

370-
uint8_t __xdata EP1_IDLE_TIME;
371-
372-
uint8_t __xdata ep0_xfer_state;
373372

374373
void usb_init()
375374
{
376375
received_usb_addr = 0;
376+
idle_time = 0;
377+
interface0_protocol = 0;
378+
interface1_protocol = 0;
379+
active_configution = 0;
380+
ep0_xfer_state = 0;
381+
ep0_xfer_bytes_left = 0;
382+
ep0_xfer_src = 0;
383+
377384
USBADDR = 0;
378385
USBIE1 = (_OVERIE | _SETUPIE | _SOFIA | _RESMIE | _SUSPIE | _PBRSTIE);
379386
USBIE2 = (_OEP0IE | _IEP0IE);
@@ -710,7 +717,7 @@ static void usb_set_configuration_handler(__xdata struct usb_req_setup *req)
710717
if (USBADDR) {
711718
// TODO: can this actually support 2 configs?
712719
if ((req->wValue == 0) || (req->wValue == 1)) {
713-
configution_value = req->wValue;
720+
active_configution = req->wValue;
714721
// TODO: save config set state
715722
IEP0CNT_CLR;
716723
IN0_SET_READY;
@@ -934,7 +941,7 @@ static void usb_get_configuration_handler()
934941
{
935942
ep0_xfer_state = OUT0_STATUS_PHASE;
936943

937-
EP0_IN_BUF[0] = configution_value;
944+
EP0_IN_BUF[0] = active_configution;
938945

939946
IEP0CNT_SET(1);
940947
IN0_SET_READY;
@@ -979,7 +986,7 @@ static void usb_hid_set_report_handler(__xdata struct usb_req_setup *req)
979986
static void usb_hid_set_idle_handler(__xdata struct usb_req_setup *req)
980987
{
981988
// TODO: finish implementaiton to use the set idle time
982-
EP1_IDLE_TIME = req->wValue >> 8;
989+
idle_time = req->wValue >> 8;
983990

984991
IEP0CNT_CLR;
985992
IN0_SET_READY;
@@ -988,7 +995,7 @@ static void usb_hid_set_idle_handler(__xdata struct usb_req_setup *req)
988995
static void usb_hid_get_idle_handler()
989996
{
990997
// TODO: finish implementaiton to use the set idle time
991-
EP0_IN_BUF[0] = EP1_IDLE_TIME;
998+
EP0_IN_BUF[0] = idle_time;
992999

9931000
IEP0CNT_SET(1);
9941001
IN0_SET_READY;

0 commit comments

Comments
 (0)