From 68e1d59e127d449af5cc0f6cd46d9a6a7cb34a09 Mon Sep 17 00:00:00 2001 From: Conor Date: Mon, 25 Jan 2016 01:14:58 -0500 Subject: [PATCH] cleaned up some --- firmware/.cproject | 2 +- firmware/inc/InitDevice.h | 1 + firmware/inc/app.h | 14 ++ firmware/inc/bsp.h | 29 +++ firmware/src/InitDevice.c | 85 ++++++--- firmware/src/Interrupts.c | 30 ++++ firmware/src/bsp.c | 11 +- firmware/src/callback.c | 45 +---- firmware/src/callback.old.c | 299 ------------------------------- firmware/src/descriptors.old.c | 173 ------------------ firmware/src/u2f-firmware_main.c | 124 ++++++------- firmware/u2f-firmware.hwconf | 11 +- 12 files changed, 215 insertions(+), 609 deletions(-) create mode 100644 firmware/inc/app.h create mode 100644 firmware/src/Interrupts.c delete mode 100644 firmware/src/callback.old.c delete mode 100644 firmware/src/descriptors.old.c diff --git a/firmware/.cproject b/firmware/.cproject index 6cc7153..e431ed0 100644 --- a/firmware/.cproject +++ b/firmware/.cproject @@ -153,7 +153,7 @@ - + diff --git a/firmware/inc/InitDevice.h b/firmware/inc/InitDevice.h index a9427a7..28d9295 100644 --- a/firmware/inc/InitDevice.h +++ b/firmware/inc/InitDevice.h @@ -23,6 +23,7 @@ extern void PBCFG_0_enter_DefaultMode_from_RESET(void); extern void CIP51_0_enter_DefaultMode_from_RESET(void); extern void CLOCK_0_enter_DefaultMode_from_RESET(void); extern void TIMER01_0_enter_DefaultMode_from_RESET(void); +extern void TIMER16_2_enter_DefaultMode_from_RESET(void); extern void TIMER_SETUP_0_enter_DefaultMode_from_RESET(void); extern void UART_0_enter_DefaultMode_from_RESET(void); extern void INTERRUPT_0_enter_DefaultMode_from_RESET(void); diff --git a/firmware/inc/app.h b/firmware/inc/app.h new file mode 100644 index 0000000..40586d3 --- /dev/null +++ b/firmware/inc/app.h @@ -0,0 +1,14 @@ +/* + * app.h + * + */ + +#ifndef APP_H_ +#define APP_H_ + +struct APP_DATA +{ + +}; + +#endif /* APP_H_ */ diff --git a/firmware/inc/bsp.h b/firmware/inc/bsp.h index 5d0564e..ac90bc5 100644 --- a/firmware/inc/bsp.h +++ b/firmware/inc/bsp.h @@ -8,10 +8,39 @@ #ifndef BSP_H_ #define BSP_H_ +#include +#include + +typedef enum +{ + EP_BUSY = 0, + EP_FREE, +} +ENDPOINT_STATE; + + +struct APP_DATA +{ + ENDPOINT_STATE EP1_state; + uint8_t hidmsgbuf[64]; + + // ms + uint16_t usb_read_timeout; +}; + + SI_SBIT(LED_R, SFR_P0, 6); SI_SBIT(LED_G, SFR_P0, 5); SI_SBIT(LED_B, SFR_P0, 4); void Delay(int16_t ms); +extern uint16_t _MS_; + +#define get_ms() _MS_ + +extern SI_SEGMENT_VARIABLE(myUsbDevice, USBD_Device_TypeDef, MEM_MODEL_SEG); + +#define GetEp(epAddr) (&myUsbDevice.ep0 + epAddr) + #endif /* BSP_H_ */ diff --git a/firmware/src/InitDevice.c b/firmware/src/InitDevice.c index 66b58d3..f965b75 100644 --- a/firmware/src/InitDevice.c +++ b/firmware/src/InitDevice.c @@ -33,6 +33,7 @@ extern void enter_DefaultMode_from_RESET(void) { CIP51_0_enter_DefaultMode_from_RESET(); CLOCK_0_enter_DefaultMode_from_RESET(); TIMER01_0_enter_DefaultMode_from_RESET(); + TIMER16_2_enter_DefaultMode_from_RESET(); TIMER_SETUP_0_enter_DefaultMode_from_RESET(); UART_0_enter_DefaultMode_from_RESET(); INTERRUPT_0_enter_DefaultMode_from_RESET(); @@ -368,6 +369,58 @@ extern void TIMER01_0_enter_DefaultMode_from_RESET(void) { } +//================================================================================ +// TIMER16_2_enter_DefaultMode_from_RESET +//================================================================================ +extern void TIMER16_2_enter_DefaultMode_from_RESET(void) { + // $[Timer Initialization] + // Save Timer Configuration + uint8_t TMR2CN0_TR2_save; + TMR2CN0_TR2_save = TMR2CN0 & TMR2CN0_TR2__BMASK; + // Stop Timer + TMR2CN0 &= ~(TMR2CN0_TR2__BMASK); + // [Timer Initialization]$ + + // $[TMR2CN1 - Timer 2 Control 1] + // [TMR2CN1 - Timer 2 Control 1]$ + + // $[TMR2CN0 - Timer 2 Control] + // [TMR2CN0 - Timer 2 Control]$ + + // $[TMR2H - Timer 2 High Byte] + // [TMR2H - Timer 2 High Byte]$ + + // $[TMR2L - Timer 2 Low Byte] + // [TMR2L - Timer 2 Low Byte]$ + + // $[TMR2RLH - Timer 2 Reload High Byte] + /* + // TMR2RLH (Timer 2 Reload High Byte) = 0x44 + */ + TMR2RLH = (0x44 << TMR2RLH_TMR2RLH__SHIFT); + // [TMR2RLH - Timer 2 Reload High Byte]$ + + // $[TMR2RLL - Timer 2 Reload Low Byte] + /* + // TMR2RLL (Timer 2 Reload Low Byte) = 0x80 + */ + TMR2RLL = (0x80 << TMR2RLL_TMR2RLL__SHIFT); + // [TMR2RLL - Timer 2 Reload Low Byte]$ + + // $[TMR2CN0] + /* + // TR2 (Timer 2 Run Control) = RUN (Start Timer 2 running.) + */ + TMR2CN0 |= TMR2CN0_TR2__RUN; + // [TMR2CN0]$ + + // $[Timer Restoration] + // Restore Timer Configuration + TMR2CN0 |= TMR2CN0_TR2_save; + // [Timer Restoration]$ + +} + //================================================================================ // TIMER_SETUP_0_enter_DefaultMode_from_RESET //================================================================================ @@ -379,8 +432,8 @@ extern void TIMER_SETUP_0_enter_DefaultMode_from_RESET(void) { // defined by the prescale field, SCA.) // T2MH (Timer 2 High Byte Clock Select) = EXTERNAL_CLOCK (Timer 2 high // byte uses the clock defined by T2XCLK in TMR2CN0.) - // T2ML (Timer 2 Low Byte Clock Select) = EXTERNAL_CLOCK (Timer 2 low - // byte uses the clock defined by T2XCLK in TMR2CN0.) + // T2ML (Timer 2 Low Byte Clock Select) = SYSCLK (Timer 2 low byte uses + // the system clock.) // T3MH (Timer 3 High Byte Clock Select) = EXTERNAL_CLOCK (Timer 3 high // byte uses the clock defined by T3XCLK in TMR3CN0.) // T3ML (Timer 3 Low Byte Clock Select) = EXTERNAL_CLOCK (Timer 3 low @@ -388,7 +441,7 @@ extern void TIMER_SETUP_0_enter_DefaultMode_from_RESET(void) { // T1M (Timer 1 Clock Select) = SYSCLK (Timer 1 uses the system clock.) */ CKCON0 = CKCON0_SCA__SYSCLK_DIV_12 | CKCON0_T0M__PRESCALE - | CKCON0_T2MH__EXTERNAL_CLOCK | CKCON0_T2ML__EXTERNAL_CLOCK + | CKCON0_T2MH__EXTERNAL_CLOCK | CKCON0_T2ML__SYSCLK | CKCON0_T3MH__EXTERNAL_CLOCK | CKCON0_T3ML__EXTERNAL_CLOCK | CKCON0_T1M__SYSCLK; // [CKCON0 - Clock Control 0]$ @@ -441,27 +494,6 @@ extern void UART_0_enter_DefaultMode_from_RESET(void) { //================================================================================ extern void INTERRUPT_0_enter_DefaultMode_from_RESET(void) { // $[EIE1 - Extended Interrupt Enable 1] - /* - // EADC0 (ADC0 Conversion Complete Interrupt Enable) = DISABLED (Disable - // ADC0 Conversion Complete interrupt.) - // EWADC0 (ADC0 Window Comparison Interrupt Enable) = DISABLED (Disable - // ADC0 Window Comparison interrupt.) - // ECP0 (Comparator0 (CP0) Interrupt Enable) = DISABLED (Disable CP0 - // interrupts.) - // ECP1 (Comparator1 (CP1) Interrupt Enable) = DISABLED (Disable CP1 - // interrupts.) - // EMAT (Port Match Interrupts Enable) = ENABLED (Enable interrupt - // requests generated by a Port Match.) - // EPCA0 (Programmable Counter Array (PCA0) Interrupt Enable) = DISABLED - // (Disable all PCA0 interrupts.) - // ESMB0 (SMBus (SMB0) Interrupt Enable) = DISABLED (Disable all SMB0 - // interrupts.) - // ET3 (Timer 3 Interrupt Enable) = DISABLED (Disable Timer 3 - // interrupts.) - */ - EIE1 = EIE1_EADC0__DISABLED | EIE1_EWADC0__DISABLED | EIE1_ECP0__DISABLED - | EIE1_ECP1__DISABLED | EIE1_EMAT__ENABLED | EIE1_EPCA0__DISABLED - | EIE1_ESMB0__DISABLED | EIE1_ET3__DISABLED; // [EIE1 - Extended Interrupt Enable 1]$ // $[EIE2 - Extended Interrupt Enable 2] @@ -493,12 +525,13 @@ extern void INTERRUPT_0_enter_DefaultMode_from_RESET(void) { // interrupt.) // ET1 (Timer 1 Interrupt Enable) = DISABLED (Disable all Timer 1 // interrupt.) - // ET2 (Timer 2 Interrupt Enable) = DISABLED (Disable Timer 2 interrupt.) + // ET2 (Timer 2 Interrupt Enable) = ENABLED (Enable interrupt requests + // generated by the TF2L or TF2H flags.) // ES0 (UART0 Interrupt Enable) = DISABLED (Disable UART0 interrupt.) */ IE = IE_EA__ENABLED | IE_EX0__DISABLED | IE_EX1__DISABLED | IE_ESPI0__DISABLED | IE_ET0__DISABLED | IE_ET1__DISABLED - | IE_ET2__DISABLED | IE_ES0__DISABLED; + | IE_ET2__ENABLED | IE_ES0__DISABLED; // [IE - Interrupt Enable]$ // $[IP - Interrupt Priority] diff --git a/firmware/src/Interrupts.c b/firmware/src/Interrupts.c new file mode 100644 index 0000000..0c10928 --- /dev/null +++ b/firmware/src/Interrupts.c @@ -0,0 +1,30 @@ +//========================================================= +// src/Interrupts.c: generated by Hardware Configurator +// +// This file will be regenerated when saving a document. +// leave the sections inside the "$[...]" comment tags alone +// or they will be overwritten! +//========================================================= + +// USER INCLUDES +#include +#include + +//----------------------------------------------------------------------------- +// TIMER2_ISR +//----------------------------------------------------------------------------- +// +// TIMER2 ISR Content goes here. Remember to clear flag bits: +// TMR2CN0::TF2H (Timer # High Byte Overflow Flag) +// TMR2CN0::TF2L (Timer # Low Byte Overflow Flag) +// +//----------------------------------------------------------------------------- + +uint16_t _MS_ = 0; + +SI_INTERRUPT (TIMER2_ISR, TIMER2_IRQn) +{ + TMR2CN0_TF2H = 0; + ++_MS_; +} + diff --git a/firmware/src/bsp.c b/firmware/src/bsp.c index 23a5939..458908e 100644 --- a/firmware/src/bsp.c +++ b/firmware/src/bsp.c @@ -3,6 +3,15 @@ * */ +#include "bsp.h" - +void Delay(uint16_t ms) { + int16_t x; + int16_t y; + for (y = 0; y < ms; y++) { + for (x = 0; x < 1000; x) { + x++; + } + } +} diff --git a/firmware/src/callback.c b/firmware/src/callback.c index bd1bf88..b3e85a4 100644 --- a/firmware/src/callback.c +++ b/firmware/src/callback.c @@ -20,23 +20,11 @@ #include "bsp.h" #include "descriptors.h" -//----------------------------------------------------------------------------- -// Constants -//----------------------------------------------------------------------------- -#define HID_KEYBOARD_IFC 0 -//----------------------------------------------------------------------------- -// Variables -//----------------------------------------------------------------------------- -// uint8_t thebuf1[32]; -SI_SEGMENT_VARIABLE(thebuf1[64], uint8_t, SI_SEG_XDATA); +#define HID_INTERFACE_INDEX 0 +extern SI_SEGMENT_VARIABLE(appdata, struct APP_DATA, SI_SEG_XDATA); + uint8_t tmpBuffer; -extern bool readpacket; -//SI_SEGMENT_VARIABLE(thebuf1[32], -// uint8_t, -// SI_SEG_CODE); -//----------------------------------------------------------------------------- -// Functions -//----------------------------------------------------------------------------- + void USBD_EnterHandler(void) { @@ -65,16 +53,10 @@ bool USBD_IsSelfPoweredCb(void) { } - - USB_Status_TypeDef USBD_SetupCmdCb( SI_VARIABLE_SEGMENT_POINTER(setup, USB_Setup_TypeDef, MEM_MODEL_SEG)) { + USB_Status_TypeDef retVal = USB_STATUS_REQ_UNHANDLED; - int i; - - - - if ((setup->bmRequestType.Type == USB_SETUP_TYPE_STANDARD) @@ -114,7 +96,7 @@ USB_Status_TypeDef USBD_SetupCmdCb( } else if ((setup->bmRequestType.Type == USB_SETUP_TYPE_CLASS) && (setup->bmRequestType.Recipient == USB_SETUP_RECIPIENT_INTERFACE) - && (setup->wIndex == HID_KEYBOARD_IFC)) + && (setup->wIndex == HID_INTERFACE_INDEX)) { // Implement the necessary HID class specific commands. switch (setup->bRequest) @@ -125,8 +107,6 @@ USB_Status_TypeDef USBD_SetupCmdCb( case USB_HID_GET_REPORT: printf("input report\r\n"); - if ( USBD_Read(EP1OUT, thebuf1, sizeof(thebuf1), true) != USB_STATUS_OK) - printf("ERROR not ready\n"); break; @@ -168,12 +148,6 @@ USB_Status_TypeDef USBD_SetupCmdCb( return retVal; } -//SI_SEGMENT_VARIABLE(testtx[], -// uint8_t, -// SI_SEG_CODE) = -// "\x00\xff\xff\xff\xff\x86\x00\x08\x08\x07\x06\x05\x04\x03\x02\x01\x00\x00\x00\x00\x00\x00\x00" -// "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -// "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; uint16_t USBD_XferCompleteCb(uint8_t epAddr, USB_Status_TypeDef status, uint16_t xferred, uint16_t remaining) { @@ -187,14 +161,13 @@ uint16_t USBD_XferCompleteCb(uint8_t epAddr, USB_Status_TypeDef status, { printf("USBD_XferCompleteCb read 0x%x/0x%x \r\n", xferred, remaining); - for (i=0; i < sizeof(thebuf1); i++) + for (i=0; i < sizeof(appdata.hidmsgbuf); i++) { - uint16_t l = (uint8_t)thebuf1[i]; + uint16_t l = (uint8_t)appdata.hidmsgbuf[i]; printf("%x",l); - } printf("\n"); - readpacket = 1; + appdata.EP1_state = EP_FREE; } return 0; diff --git a/firmware/src/callback.old.c b/firmware/src/callback.old.c deleted file mode 100644 index b5a0e49..0000000 --- a/firmware/src/callback.old.c +++ /dev/null @@ -1,299 +0,0 @@ -/**************************************************************************//** - * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. - * - * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt - *****************************************************************************/ -#if 0 -#include - -#include "SI_EFM8UB1_Register_Enums.h" -#include "efm8_usb.h" -#include "descriptors.h" -#include "idle.h" -#include "bsp.h" - -// ---------------------------------------------------------------------------- -// Constants -// ---------------------------------------------------------------------------- -SI_SBIT(BSP_LED_G, SFR_P1, 4); -SI_SBIT(BSP_LED_B, SFR_P1, 5); -SI_SBIT(BSP_LED_R, SFR_P1, 6); - -#define numLock BSP_LED_G -#define capsLock BSP_LED_R - -// Endpoint address of the HID keyboard IN endpoint -#define KEYBOARD_IN_EP_ADDR EP1IN - -// Interface number of the HID keyboard -#define HID_KEYBOARD_IFC 0 - -// ---------------------------------------------------------------------------- -// Variables -// ---------------------------------------------------------------------------- -uint8_t tmpBuffer; -extern uint8_t keySeqNo; // Current position in report table. -extern bool keyPushed; // Current pushbutton status. - - -uint8_t thebuf[32]; -// ---------------------------------------------------------------------------- -// Functions -// ---------------------------------------------------------------------------- -void USBD_EnterHandler(void) -{ - - // printf("USBD_EnterHandler\r\n"); -} - -void USBD_ExitHandler(void) -{ - // printf("USBD_ExitHandler\r\n"); -} - -void USBD_ResetCb(void) -{ - printf("USBD_ResetCb\r\n"); -} - -void USBD_SofCb(uint16_t sofNr) -{ - - -} - -void USBD_DeviceStateChangeCb(USBD_State_TypeDef oldState, - USBD_State_TypeDef newState) -{ - bool numLockSave, capsLockSave; - - printf("USBD_DeviceStateChangeCb\r\n"); - - // If not configured or in suspend, disable the LED - if (newState < USBD_STATE_SUSPENDED) - { - // Disable the LED - numLockSave = 1; - capsLockSave = 1; - numLock = 1; - capsLock = 1; - } - // Entering suspend mode, power internal and external blocks down - else if (newState == USBD_STATE_SUSPENDED) - { - // Disable the LED's - numLockSave = numLock; - capsLockSave = capsLock; - numLock = 1; - capsLock = 1; - - // Abort any pending transfer - USBD_AbortTransfer(KEYBOARD_IN_EP_ADDR); - } - else if (newState == USBD_STATE_CONFIGURED) - { - idleTimerSet(POLL_RATE); - } - - // Exiting suspend mode, power internal and external blocks up - if (oldState == USBD_STATE_SUSPENDED) - { - // Restore the LED's to their previous values - numLock = numLockSave; - capsLock = capsLockSave; - } -} - -bool USBD_IsSelfPoweredCb(void) -{ - printf("USBD_IsSelfPoweredCb\r\n"); - return false; -} - -void print_setup_packet(USB_Setup_TypeDef * setup) -{ - uint16_t r = (uint8_t)setup->bmRequestType.Recipient; - uint16_t t = (uint8_t)setup->bmRequestType.Type; - uint16_t d = (uint8_t)setup->bmRequestType.Direction; - uint16_t req = (uint8_t)setup->bRequest; - uint16_t i = setup->wIndex; - uint16_t l = setup->wLength; - uint16_t val = setup->wValue; - - printf("setup packet\r\n" - " direction 0x%x\r\n" - " type 0x%x\r\n" - " recip inter 0x%x\r\n" - " bRequest 0x%x\r\n" - " value 0x%x\r\n" - " index 0x%x\r\n" - " length 0x%x\r\n" - ,d - ,t - ,r - , req - , val - , i - , l - - ); -} - -USB_Status_TypeDef USBD_SetupCmdCb(SI_VARIABLE_SEGMENT_POINTER( - setup, - USB_Setup_TypeDef, - MEM_MODEL_SEG)) -{ - - USB_Status_TypeDef retVal = USB_STATUS_REQ_UNHANDLED; - - // print_setup_packet(setup); - - - if ((setup->bmRequestType.Type == USB_SETUP_TYPE_STANDARD) - && (setup->bmRequestType.Direction == USB_SETUP_DIR_IN) - && (setup->bmRequestType.Recipient == USB_SETUP_RECIPIENT_INTERFACE)) - { - // A HID device must extend the standard GET_DESCRIPTOR command - // with support for HID descriptors. - switch (setup->bRequest) - { - case GET_DESCRIPTOR: - if ((setup->wValue >> 8) == USB_HID_REPORT_DESCRIPTOR) - { - switch (setup->wIndex) - { - case 0: // Interface 0 - - USBD_Write(EP0, - ReportDescriptor0, - EFM8_MIN(sizeof(ReportDescriptor0), setup->wLength), - false); - retVal = USB_STATUS_OK; - printf("USBD_SetupCmdCb report D\r\n"); - break; - - default: // Unhandled Interface - printf("USBD_SetupCmdCb unhandled get descriptor %d\r\n", setup->wIndex); - break; - } - } - else if ((setup->wValue >> 8) == USB_HID_DESCRIPTOR) - { - switch (setup->wIndex) - { - case 0: // Interface 0 - - USBD_Write(EP0, - (&configDesc[18]), - EFM8_MIN(USB_HID_DESCSIZE, setup->wLength), - false); - retVal = USB_STATUS_OK; - printf("get hid descsize\r\n"); - break; - - default: // Unhandled Interface - printf("Unhandled Interface\r\n"); - break; - } - } - else - { - printf("unhandled set up value %d\r\n", setup->wValue); - } - break; - default: - printf("USBD_SetupCmdCb setup->bRequest %d\r\n", setup->bRequest); - break; - } - } - else if ((setup->bmRequestType.Type == USB_SETUP_TYPE_CLASS) - && (setup->bmRequestType.Recipient == USB_SETUP_RECIPIENT_INTERFACE) - && (setup->wIndex == HID_KEYBOARD_IFC)) - { - // Implement the necessary HID class specific commands. - switch (setup->bRequest) - { - case USB_HID_SET_REPORT: - printf("output report\r\n"); - break; - - case USB_HID_GET_REPORT: - printf("input report\r\n"); - - - break; - - case USB_HID_SET_IDLE: - if (((setup->wValue & 0xFF) == 0) // Report ID - && (setup->wLength == 0) - && (setup->bmRequestType.Direction != USB_SETUP_DIR_IN)) - { - printf("set idle\r\n"); - idleTimerSet(setup->wValue >> 8); - retVal = USB_STATUS_OK; - } - else printf("unhandled USB_HID_SET_IDLE\r\n"); - break; - - case USB_HID_GET_IDLE: - if ((setup->wValue == 0) // Report ID - && (setup->wLength == 1) - && (setup->bmRequestType.Direction == USB_SETUP_DIR_IN)) - { - printf("get idle\r\n"); - tmpBuffer = idleGetRate(); - USBD_Write(EP0, &tmpBuffer, 1, false); - retVal = USB_STATUS_OK; - } - else printf("unhandled USB_HID_GET_IDLE\r\n"); - break; - default: - printf("unhandled setup->bRequest\r\n"); - } - } - else - { - if (setup->bmRequestType.Recipient == USB_SETUP_RECIPIENT_ENDPOINT) - printf("endpoint called!\n"); - // printf("NOT HANDLED\r\n"); - } - - return retVal; -} - - - -uint16_t USBD_XferCompleteCb(uint8_t epAddr, - USB_Status_TypeDef status, - uint16_t xferred, - uint16_t remaining) -{ - - int i = 0; - UNREFERENCED_ARGUMENT(xferred); - UNREFERENCED_ARGUMENT(remaining); - - printf("USBD_XferCompleteCb\r\n"); - for (i=0; i < 32 ; i++) - { - - printf("%hhx", thebuf[i]); - - } - printf("\r\n"); - - if (status == USB_STATUS_OK) - { - // The only output reported supported is the SetReport to enable - // Num Key and Caps Lock LED's. - if (epAddr == EP0) - { - numLock = !((bool) (tmpBuffer & 0x01)); - capsLock = !((bool) (tmpBuffer & 0x02)); - } - } - // USBD_Read(EP0, thebuf, 32, true); - return 0; -} -#endif diff --git a/firmware/src/descriptors.old.c b/firmware/src/descriptors.old.c deleted file mode 100644 index 01c36bb..0000000 --- a/firmware/src/descriptors.old.c +++ /dev/null @@ -1,173 +0,0 @@ -/******************************************************************************* - * @file descriptors.c - * @brief USB descriptors. - *******************************************************************************/ - -//============================================================================= -// src/descriptors.c: generated by Hardware Configurator -// -// This file is only generated if it does not exist. Modifications in this file -// will persist even if Configurator generates code. To refresh this file, -// you must first delete it and then regenerate code. -//============================================================================= -//----------------------------------------------------------------------------- -// Includes -//----------------------------------------------------------------------------- -#if 0 -#include -#include -#include -#include -#include -#include "descriptors.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// HID Report Descriptor for Interface 0 -SI_SEGMENT_VARIABLE(ReportDescriptor0[34], - const uint8_t, - SI_SEG_CODE) = -{ - - 0x06, 0xd0, 0xf1,// USAGE_PAGE (FIDO Alliance) - 0x09, 0x01,// USAGE (Keyboard) - 0xa1, 0x01,// COLLECTION (Application) - - 0x09, 0x20, // USAGE (Input Report Data) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255) - 0x75, 0x08, // REPORT_SIZE (8) - 0x95, 0x40, // REPORT_COUNT (64) - 0x81, 0x02, // INPUT (Data,Var,Abs) - 0x09, 0x21, // USAGE(Output Report Data) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255) - 0x75, 0x08, // REPORT_SIZE (8) - 0x95, 0x40, // REPORT_COUNT (64) - 0x91, 0x02, // OUTPUT (Data,Var,Abs) - - - 0xc0,// END_COLLECTION - -}; - -SI_SEGMENT_VARIABLE(deviceDesc[], - const USB_DeviceDescriptor_TypeDef, - SI_SEG_CODE) = -{ - USB_DEVICE_DESCSIZE, // bLength - USB_DEVICE_DESCRIPTOR,// bLength - htole16(0x0200),// bcdUSB - 0,// bDeviceClass - 0,// bDeviceSubClass - 0,// bDeviceProtocol - 64,// bMaxPacketSize - USB_VENDOR_ID,// idVendor - USB_PRODUCT_ID,// idProduct - htole16(0x0100),// bcdDevice - 1,// iManufacturer - 2,// iProduct - 0,// iSerialNumber - 1,// bNumConfigurations -}; - -SI_SEGMENT_VARIABLE(configDesc[], - const uint8_t, - SI_SEG_CODE) = -{ - USB_CONFIG_DESCSIZE, // bLength - USB_CONFIG_DESCRIPTOR,// bLength - 0x29,// wTotalLength(LSB) - 0x00,// wTotalLength(MSB) - 1,// bNumInterfaces - 1,// bConfigurationValue - 0,// iConfiguration - - CONFIG_DESC_BM_RESERVED_D7,// bmAttrib: Bus powered - - CONFIG_DESC_MAXPOWER_mA(100),// bMaxPower: 100 mA - - //Interface 0 Descriptor - USB_INTERFACE_DESCSIZE,// bLength - USB_INTERFACE_DESCRIPTOR,// bDescriptorType - 0,// bInterfaceNumber - 0,// bAlternateSetting - 2,// bNumEndpoints - 3,// bInterfaceClass: HID (Human Interface Device) - 0,// bInterfaceSubClass - 0,// bInterfaceProtocol - 0,// iInterface - - //HID Descriptor - USB_HID_DESCSIZE,// bLength - USB_HID_DESCRIPTOR,// bLength - 0x11,// bcdHID (LSB) - 0x01,// bcdHID (MSB) - 0,// bCountryCode - 1,// bNumDescriptors - USB_HID_REPORT_DESCRIPTOR,// bDescriptorType - sizeof( ReportDescriptor0 ),// wDescriptorLength(LSB) - sizeof( ReportDescriptor0 )>>8,// wDescriptorLength(MSB) - - //Endpoint 1 IN Descriptor - USB_ENDPOINT_DESCSIZE,// bLength - USB_ENDPOINT_DESCRIPTOR,// bDescriptorType - 0x81,// bEndpointAddress - USB_EPTYPE_INTR,// bAttrib - 0x40,// wMaxPacketSize (LSB) - 0x00,// wMaxPacketSize (MSB) - 5,// bInterval - - //Endpoint 1 OUT Descriptor - USB_ENDPOINT_DESCSIZE,// bLength - USB_ENDPOINT_DESCRIPTOR,// bDescriptorType - 0x01,// bEndpointAddress - USB_EPTYPE_INTR,// bAttrib - 0x40,// wMaxPacketSize (LSB) - 0x00,// wMaxPacketSize (MSB) - 5,// bInterval -}; - -#define LANG_STRING htole16( SLAB_USB_LANGUAGE ) -#define MFR_STRING "Silicon Labs" -#define PROD_STRING "U2F Zero" -#define SER_STRING "0123456789ABCDEF" -#define INT0_STRING "HID Keyboard" - -LANGID_STATIC_CONST_STRING_DESC( langDesc[], LANG_STRING ); -UTF16LE_PACKED_STATIC_CONST_STRING_DESC( mfrDesc[], MFR_STRING ); -UTF16LE_PACKED_STATIC_CONST_STRING_DESC( prodDesc[], PROD_STRING ); -UTF16LE_PACKED_STATIC_CONST_STRING_DESC( serDesc[], SER_STRING ); -UTF16LE_PACKED_STATIC_CONST_STRING_DESC( int0Desc[], INT0_STRING ); - -//----------------------------------------------------------------------------- -SI_SEGMENT_POINTER(myUsbStringTable_USEnglish[], - static const USB_StringDescriptor_TypeDef, - const SI_SEG_CODE) = -{ - langDesc, - mfrDesc, - prodDesc, - serDesc, - int0Desc, - -}; - -//----------------------------------------------------------------------------- -SI_SEGMENT_VARIABLE(initstruct, - const USBD_Init_TypeDef, - SI_SEG_CODE) = -{ - deviceDesc, // deviceDescriptor - configDesc,// configDescriptor - myUsbStringTable_USEnglish,// stringDescriptors - sizeof(myUsbStringTable_USEnglish) / sizeof(void *)// numberOfStrings -}; - -#ifdef __cplusplus -} -#endif -#endif - diff --git a/firmware/src/u2f-firmware_main.c b/firmware/src/u2f-firmware_main.c index a73e5a3..c3842fe 100644 --- a/firmware/src/u2f-firmware_main.c +++ b/firmware/src/u2f-firmware_main.c @@ -1,49 +1,3 @@ -//----------------------------------------------------------------------------- -// main.c -//----------------------------------------------------------------------------- -// Copyright 2014 Silicon Laboratories, Inc. -// http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt -// -// Program Description: -// -// This program enumerates as a USB keyboard. Each time a button is pressed -// a character is sent to the host. A series of presses will spell out -// "HID Keyboard ". The status of the Caps Lock and Num Lock on the host will -// be indicated by the color of the LED. -// -// Resources: -// SYSCLK - 48 MHz HFOSC1 / 1 -// USB0 - Full speed -// P0.2 - push button -// P0.3 - push button -// P2.3 - Display enable -// -//----------------------------------------------------------------------------- -// How To Test: EFM8UB1 STK -//----------------------------------------------------------------------------- -// 1) Place the switch in "AEM" mode. -// 2) Connect the EFM8UB1 STK board to a PC using a mini USB cable. -// 3) Compile and download code to the EFM8UB1 STK board. -// In Simplicity Studio IDE, select Run -> Debug from the menu bar, -// click the Debug button in the quick menu, or press F11. -// 4) Run the code. -// In Simplicity Studio IDE, select Run -> Resume from the menu bar, -// click the Resume button in the quick menu, or press F8. -// 5) The HID keyboard demo should start. -// 6) Connect a micro USB cable from the PC to the STK. -// 7) The device should enumerate on the PC as a HID keyboard. -// 8) Press either push-button (PB0 or PB1) to send one character in the -// string "HID Keyboard ". -// 9) Pressing Caps Lock or Num Lock on the host keyboard will change the color -// of the LED. -// -// Target: EFM8UB1 -// Tool chain: Generic -// -// Release 0.1 (JM) -// - Initial Revision -// - 26 JAN 2015 -// #include #include @@ -59,46 +13,74 @@ bool keyPushed = 0; // Current pushbutton status. bool readpacket = 1; -extern SI_SEGMENT_VARIABLE(thebuf1[64], uint8_t, SI_SEG_XDATA); +SI_SEGMENT_VARIABLE(appdata, struct APP_DATA, SI_SEG_XDATA); -void Delay(int16_t ms) { - int16_t x; - int16_t y; - for (y = 0; y < ms; y++) { - for (x = 0; x < 1000; x) { - x++; - } +static void init(struct APP_DATA* ap) +{ + memset(ap,0, sizeof(struct APP_DATA)); + ap->EP1_state = EP_FREE; +} + +void write_s_tx(char* d) +{ + uint16_t i; + while(*d) + { + // UART0 output queue + SBUF0 = *d++; + // 115200 baud , byte time ~ 7*10^-5 s * (48 MHz) ~ 3333 cycles + for (i=0; i<200; i++); } } -SI_SEGMENT_VARIABLE(mybuf[64], - uint8_t, - SI_SEG_CODE); + +void listen_for_pkt(struct APP_DATA* ap) +{ + if (USBD_Read(EP1OUT, ap->hidmsgbuf, sizeof(ap->hidmsgbuf), true) == USB_STATUS_OK) + { + ap->EP1_state = EP_BUSY; + } +} + + int16_t main(void) { - int i = 0; + + uint16_t i = 0; + uint16_t last_ms = get_ms(); + uint16_t ms_since; + + init(&appdata); enter_DefaultMode_from_RESET(); - SCON0_TI = 1; // This STDIO library requires TI to - // be set for prints to occur + // STDIO library requires TI to print + SCON0_TI = 1; + + // Enable interrupts IE_EA = 1; - printf("welcome \r\n"); + printf("Welcome\n"); while (1) { - ++i; + ms_since = get_ms() - last_ms; - printf("%d\r\n", i); - Delay(1000); - - if (readpacket) + if (ms_since > 499) { - USBD_Read(EP1OUT, thebuf1, sizeof(thebuf1), true); - readpacket = 0; + printf("%d\r\n", ++i); + last_ms = get_ms(); + } + + + if ( USBD_GetUsbState() == USBD_STATE_CONFIGURED) + { + if (!USBD_EpIsBusy(EP1OUT)) + { + listen_for_pkt(&appdata); + write_s_tx("read added\n"); + } + } } } -SI_INTERRUPT(PMATCH_IrqHandler, PMATCH_IRQn) { - keyPushed = 1; -} + diff --git a/firmware/u2f-firmware.hwconf b/firmware/u2f-firmware.hwconf index bb201ae..b7704dd 100644 --- a/firmware/u2f-firmware.hwconf +++ b/firmware/u2f-firmware.hwconf @@ -10,9 +10,8 @@ - - + @@ -23,9 +22,17 @@ + + + + + + + +