Skip to content

Commit b4b05d4

Browse files
authored
Merge pull request #1 from AaronPerl/master
Implemented USB BOS and Capability Descriptors and callbacks
2 parents 079420f + 850ce1d commit b4b05d4

File tree

14 files changed

+2122
-0
lines changed

14 files changed

+2122
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.cproject
2+
.project
3+
.settings
4+
Keil 8051*/

AstroKey.hwconf

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?xml version="1.0" encoding="ASCII"?>
2+
<device:XMLDevice name="EFM8UB10F16G-B-QFN28" partId="mcu.8051.efm8.ub1.efm8ub10f16g-b-qfn28" xmlns:device="http://www.silabs.com/ss/hwconfig/document/device.ecore" xmlns:xmi="http://www.omg.org/XMI" xmi:version="2.0">
3+
<mode name="DefaultMode">
4+
<property object="ADC_0" propertyId="adc.configuration.sarclkactual" value="3.500 MHz"/>
5+
<property object="ADC_0" propertyId="adc.configuration.sarclktarget" value="3500000"/>
6+
<property object="ADC_0" propertyId="adc.configuration.sarclockdivider" value="6"/>
7+
<property object="ADC_0" propertyId="adc.configuration.sarclocksource" value="24.500 MHz"/>
8+
<property object="ADC_0" propertyId="adc.configuration.sysclk" value="24.500 MHz"/>
9+
<property object="ADC_0" propertyId="adc.control.timer0overflowfrequency" value="0 Hz"/>
10+
<property object="ADC_0" propertyId="adc.control.timer2overflowfrequency" value="0 Hz"/>
11+
<property object="ADC_0" propertyId="adc.control.timer3overflowfrequency" value="0 Hz"/>
12+
<property object="ADC_0" propertyId="adc.control.timer4overflowfrequency" value="0 Hz"/>
13+
<property object="CIP51_0" propertyId="ABPeripheral.included" value="true"/>
14+
<property object="CIP51_0" propertyId="cip51.prefetchenginecontrol.enableprefetch" value="Enabled"/>
15+
<property object="CIP51_0" propertyId="cip51.prefetchenginecontrol.flashreadtiming" value="SYSCLK is below 50 MHz"/>
16+
<property object="CLOCK_0" propertyId="ABPeripheral.included" value="true"/>
17+
<property object="CLOCK_0" propertyId="clock.clockselect.clocksourcedivider" value="SYSCLK / 1"/>
18+
<property object="CLOCK_0" propertyId="clock.clockselect.lfosc" value="0 Hz"/>
19+
<property object="CLOCK_0" propertyId="clock.clockselect.selectclocksource" value="Internal High Frequency Oscillator 1"/>
20+
<property object="CLOCK_0" propertyId="clock.clockselect.sysclk" value="48.000 MHz"/>
21+
<property object="DefaultMode" propertyId="mode.diagramLocation" value="100, 100"/>
22+
<property object="INTERRUPT_0" propertyId="ABPeripheral.included" value="true"/>
23+
<property object="INTERRUPT_0" propertyId="interrupt.extendedinterruptenable1.enableportmatchinterrupts" value="Enabled"/>
24+
<property object="INTERRUPT_0" propertyId="interrupt.interruptenable.enableallinterrupts" value="Enabled"/>
25+
<property object="INTERRUPT_0" propertyId="interruptenables.codegenerationoptions.generateinterruptfunctions" value="Disabled"/>
26+
<property object="P0.2" propertyId="ports.settings.maskvalue" value="Compared"/>
27+
<property object="P0.3" propertyId="ports.settings.maskvalue" value="Compared"/>
28+
<property object="PBCFG_0" propertyId="pbcfg.settings.enablecrossbar" value="Enabled"/>
29+
<property object="PCACH_0" propertyId="pcach.pcachannel.dutycycle" value="100.00%"/>
30+
<property object="PCACH_0" propertyId="pcach.pcachannel.outputfrequency" value="7.977 kHz"/>
31+
<property object="PCACH_1" propertyId="pcach.pcachannel.dutycycle" value="100.00%"/>
32+
<property object="PCACH_1" propertyId="pcach.pcachannel.outputfrequency" value="7.977 kHz"/>
33+
<property object="PCACH_2" propertyId="pcach.pcachannel.dutycycle" value="100.00%"/>
34+
<property object="PCACH_2" propertyId="pcach.pcachannel.outputfrequency" value="7.977 kHz"/>
35+
<property object="PCA_0" propertyId="pca.pcacountertimerconfiguration.pcaclockfrequency" value="2.042 MHz"/>
36+
<property object="PCA_0" propertyId="pca.pcacountertimerconfiguration.pcaclockperiod" value="489.796 nS"/>
37+
<property object="SPI_0" propertyId="spi.clockrate.spiclockfrequencyactual" value="1.531 MHz"/>
38+
<property object="SPI_0" propertyId="spi.clockrate.sysclk" value="24.500 MHz"/>
39+
<property object="SPI_0" propertyId="spi.clockrate.sysclkdividercoefficientspi0ckr" value="7"/>
40+
<property object="SPI_0" propertyId="spi.control.slaveselectmode" value="Slave or master 3-wire mode"/>
41+
<property object="USBLIB_0" propertyId="ABPeripheral.included" value="true"/>
42+
<property object="USBLIB_0" propertyId="configuration.configurationparameters.configurationstring" value=""/>
43+
<property object="USBLIB_0" propertyId="device.deviceproperties.bmaxpacketsize" value="64"/>
44+
<property object="USBLIB_0" propertyId="device.deviceproperties.productstring" value="EFM8 HID Keyboard"/>
45+
<property object="USBLIB_0" propertyId="endpoints.endpoint1in.endpoint1in" value="Enabled"/>
46+
<property object="USBLIB_0" propertyId="endpoints.endpoint1in.maxpacketsizebytes" value="64"/>
47+
<property object="USBLIB_0" propertyId="endpoints.endpoint1in.pollingintervalms" value="24"/>
48+
<property object="USBLIB_0" propertyId="endpoints.endpoint1in.transfertype" value="Interrupt"/>
49+
<property object="USBLIB_0" propertyId="endpoints.endpoint1in.usedbypreset" value="0"/>
50+
<property object="USBLIB_0" propertyId="endpoints.endpoint1out.maxpacketsizebytes" value="64"/>
51+
<property object="USBLIB_0" propertyId="endpoints.endpoint2in.maxpacketsizebytes" value="64"/>
52+
<property object="USBLIB_0" propertyId="endpoints.endpoint2out.maxpacketsizebytes" value="64"/>
53+
<property object="USBLIB_0" propertyId="endpoints.endpoint3in.maxpacketsizebytes" value="64"/>
54+
<property object="USBLIB_0" propertyId="endpoints.endpoint3out.maxpacketsizebytes" value="64"/>
55+
<property object="USBLIB_0" propertyId="interfaces.interface0.hidpollingintervalms" value="24"/>
56+
<property object="USBLIB_0" propertyId="interfaces.interface0.hidreportdescriptor" value="
57+
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
58+
0x09, 0x06, // USAGE (Keyboard)
59+
0xa1, 0x01, // COLLECTION (Application)
60+
0x05, 0x07, // USAGE_PAGE (Keyboard)
61+
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
62+
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
63+
0x15, 0x00, // LOGICAL_MINIMUM (0)
64+
0x25, 0x01, // LOGICAL_MAXIMUM (1)
65+
0x75, 0x01, // REPORT_SIZE (1)
66+
0x95, 0x08, // REPORT_COUNT (8)
67+
0x81, 0x02, // INPUT (Data,Var,Abs)
68+
0x15, 0x00, // LOGICAL_MINIMUM (0)
69+
0x25, 0x01, // LOGICAL_MAXIMUM (1)
70+
0x75, 0x01, // REPORT_SIZE (1)
71+
0x95, 0x08, // REPORT_COUNT (8)
72+
0x81, 0x01, // INPUT (Cnst,Ary,Abs)
73+
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
74+
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
75+
0x15, 0x00, // LOGICAL_MINIMUM (0)
76+
0x25, 0x65, // LOGICAL_MAXIMUM (101)
77+
0x75, 0x08, // REPORT_SIZE (8)
78+
0x95, 0x06, // REPORT_COUNT (6)
79+
0x81, 0x00, // INPUT (Data,Ary,Abs)
80+
0x05, 0x08, // USAGE_PAGE (LEDs)
81+
0x19, 0x01, // USAGE_MINIMUM (Num Lock)
82+
0x29, 0x03, // USAGE_MAXIMUM (Scroll Lock)
83+
0x15, 0x00, // LOGICAL_MINIMUM (0)
84+
0x25, 0x01, // LOGICAL_MAXIMUM (1)
85+
0x75, 0x01, // REPORT_SIZE (1)
86+
0x95, 0x03, // REPORT_COUNT (3)
87+
0x91, 0x02, // OUTPUT (Data,Var,Abs)
88+
0x75, 0x01, // REPORT_SIZE (1)
89+
0x95, 0x05, // REPORT_COUNT (5)
90+
0x91, 0x01, // OUTPUT (Cnst,Ary,Abs)
91+
0xc0 // END_COLLECTION
92+
"/>
93+
<property object="USBLIB_0" propertyId="interfaces.interface0.hidreporttemplate" value="Keyboard"/>
94+
<property object="USBLIB_0" propertyId="interfaces.interface0.interfaceclass" value="HID (Human Interface Device)"/>
95+
<property object="USBLIB_0" propertyId="interfaces.interface0.interfacestring" value=""/>
96+
<property object="USBLIB_0" propertyId="interfaces.interface0.preset" value="HID Keyboard"/>
97+
<property object="USBLIB_0" propertyId="interfaces.interface0.protocol" value="1"/>
98+
<property object="USBLIB_0" propertyId="library.callbackfunctions.handlercallback" value="Enabled"/>
99+
<property object="USBLIB_0" propertyId="library.callbackfunctions.resetcallback" value="Enabled"/>
100+
<property object="USBLIB_0" propertyId="library.callbackfunctions.selfpoweredcallback" value="Enabled"/>
101+
<property object="USBLIB_0" propertyId="library.callbackfunctions.setupcommandcallback" value="Enabled"/>
102+
<property object="USBLIB_0" propertyId="library.callbackfunctions.startofframecallback" value="Enabled"/>
103+
<property object="USBLIB_0" propertyId="library.callbackfunctions.statechangecallback" value="Enabled"/>
104+
<property object="USBLIB_0" propertyId="library.libraryconfiguration.clockrecovery" value="Enabled"/>
105+
<property object="USBLIB_0" propertyId="library.powersavingmode.enteronsuspend" value="Enabled"/>
106+
<property object="USBLIB_0" propertyId="library.powersavingmode.enteronvbusoff" value="Enabled"/>
107+
<property object="USBLIB_0" propertyId="library.powersavingmode.powersavemode" value="( USB_PWRSAVE_MODE_ONSUSPEND \
108+
| USB_PWRSAVE_MODE_ONVBUSOFF )"/>
109+
<property object="VREG_0" propertyId="ABPeripheral.included" value="true"/>
110+
<property object="VREG_0" propertyId="vreg.5vto33vldoregulatorldo1.regulatorbias" value="Disabled (Lowest power consumption)"/>
111+
<property object="WDT_0" propertyId="ABPeripheral.included" value="true"/>
112+
<property object="WDT_0" propertyId="wdt.watchdogcontrol.wdtenable" value="Disable"/>
113+
</mode>
114+
<modeTransition>
115+
<property object="RESET &#8594; DefaultMode" propertyId="modeTransition.target" value="DefaultMode"/>
116+
<property object="RESET &#8594; DefaultMode" propertyId="modeTransition.source" value="RESET"/>
117+
</modeTransition>
118+
</device:XMLDevice>

inc/InitDevice.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//=========================================================
2+
// inc/InitDevice.h: generated by Hardware Configurator
3+
//
4+
// This file will be regenerated when saving a document.
5+
// leave the sections inside the "$[...]" comment tags alone
6+
// or they will be overwritten!
7+
//=========================================================
8+
#ifndef __INIT_DEVICE_H__
9+
#define __INIT_DEVICE_H__
10+
11+
// USER CONSTANTS
12+
// USER PROTOTYPES
13+
14+
// $[Mode Transition Prototypes]
15+
extern void enter_DefaultMode_from_RESET(void);
16+
// [Mode Transition Prototypes]$
17+
18+
// $[Config(Per-Module Mode)Transition Prototypes]
19+
extern void WDT_0_enter_DefaultMode_from_RESET(void);
20+
extern void VREG_0_enter_DefaultMode_from_RESET(void);
21+
extern void PORTS_0_enter_DefaultMode_from_RESET(void);
22+
extern void PBCFG_0_enter_DefaultMode_from_RESET(void);
23+
extern void CLOCK_0_enter_DefaultMode_from_RESET(void);
24+
extern void CIP51_0_enter_DefaultMode_from_RESET(void);
25+
extern void INTERRUPT_0_enter_DefaultMode_from_RESET(void);
26+
extern void USBLIB_0_enter_DefaultMode_from_RESET(void);
27+
// [Config(Per-Module Mode)Transition Prototypes]$
28+
29+
30+
#endif
31+

inc/config/efm8_config.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/******************************************************************************
2+
* Copyright (c) 2014 by Silicon Laboratories Inc. All rights reserved.
3+
*
4+
* http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt
5+
*****************************************************************************/
6+
7+
#ifndef __EFM8_CONFIG_H__
8+
#define __EFM8_CONFIG_H__
9+
10+
#endif // __EFM8_CONFIG_H__

inc/config/usbconfig.h

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/**************************************************************************//**
2+
* Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved.
3+
*
4+
* http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt
5+
*****************************************************************************/
6+
7+
#ifndef __SILICON_LABS_USBCONFIG_H__
8+
#define __SILICON_LABS_USBCONFIG_H__
9+
10+
// -----------------------------------------------------------------------------
11+
// Specify bus- or self-powered
12+
// -----------------------------------------------------------------------------
13+
#define SLAB_USB_BUS_POWERED 0
14+
15+
// -----------------------------------------------------------------------------
16+
// Specify USB speed
17+
// -----------------------------------------------------------------------------
18+
#define SLAB_USB_FULL_SPEED 1
19+
20+
// -----------------------------------------------------------------------------
21+
// Enable or disable the clock recovery
22+
// -----------------------------------------------------------------------------
23+
#define SLAB_USB_CLOCK_RECOVERY_ENABLED 1
24+
25+
// -----------------------------------------------------------------------------
26+
// Enable or disable remote wakeup
27+
// -----------------------------------------------------------------------------
28+
#define SLAB_USB_REMOTE_WAKEUP_ENABLED 0
29+
30+
// -----------------------------------------------------------------------------
31+
// Specify number of interfaces and whether any interfaces support alternate
32+
// settings
33+
// -----------------------------------------------------------------------------
34+
#define SLAB_USB_NUM_INTERFACES 1
35+
#define SLAB_USB_SUPPORT_ALT_INTERFACES 0
36+
37+
// -----------------------------------------------------------------------------
38+
// Enable or disable each endpoint
39+
// -----------------------------------------------------------------------------
40+
#define SLAB_USB_EP1IN_USED 1
41+
#define SLAB_USB_EP1OUT_USED 0
42+
#define SLAB_USB_EP2IN_USED 0
43+
#define SLAB_USB_EP2OUT_USED 0
44+
#define SLAB_USB_EP3IN_USED 0
45+
#define SLAB_USB_EP3OUT_USED 0
46+
47+
// -----------------------------------------------------------------------------
48+
// Specify maximum packet size for each endpoint
49+
// -----------------------------------------------------------------------------
50+
#define SLAB_USB_EP1IN_MAX_PACKET_SIZE 64
51+
#define SLAB_USB_EP1OUT_MAX_PACKET_SIZE 0
52+
#define SLAB_USB_EP2IN_MAX_PACKET_SIZE 0
53+
#define SLAB_USB_EP2OUT_MAX_PACKET_SIZE 0
54+
#define SLAB_USB_EP3IN_MAX_PACKET_SIZE 0
55+
#define SLAB_USB_EP3OUT_MAX_PACKET_SIZE 0
56+
57+
// -----------------------------------------------------------------------------
58+
// Specify transfer type of each endpoint
59+
// -----------------------------------------------------------------------------
60+
#define SLAB_USB_EP1IN_TRANSFER_TYPE USB_EPTYPE_INTR
61+
#define SLAB_USB_EP1OUT_TRANSFER_TYPE USB_EPTYPE_BULK
62+
#define SLAB_USB_EP2IN_TRANSFER_TYPE USB_EPTYPE_INTR
63+
#define SLAB_USB_EP2OUT_TRANSFER_TYPE USB_EPTYPE_BULK
64+
#define SLAB_USB_EP3IN_TRANSFER_TYPE USB_EPTYPE_ISOC
65+
#define SLAB_USB_EP3OUT_TRANSFER_TYPE USB_EPTYPE_ISOC
66+
67+
// -----------------------------------------------------------------------------
68+
// Enable or disable callback functions
69+
// -----------------------------------------------------------------------------
70+
#define SLAB_USB_RESET_CB 1
71+
#define SLAB_USB_SOF_CB 1
72+
#define SLAB_USB_STATE_CHANGE_CB 1
73+
#define SLAB_USB_IS_SELF_POWERED_CB 1
74+
#define SLAB_USB_SETUP_CMD_CB 1
75+
#define SLAB_USB_HANDLER_CB 0
76+
77+
// -----------------------------------------------------------------------------
78+
// Specify number of languages supported by string descriptors
79+
// -----------------------------------------------------------------------------
80+
#define SLAB_USB_NUM_LANGUAGES 1
81+
82+
// -----------------------------------------------------------------------------
83+
// If only one descriptor language is supported, specify that language here.
84+
// If multiple descriptor languages are supported, this value is ignored and
85+
// the supported languages must listed in the
86+
// myUsbStringTableLanguageIDsDescriptor structure.
87+
// -----------------------------------------------------------------------------
88+
#define SLAB_USB_LANGUAGE USB_LANGID_ENUS
89+
90+
// -----------------------------------------------------------------------------
91+
// Set the power saving mode
92+
//
93+
// SLAB_USB_PWRSAVE_MODE configures when the device will automatically enter
94+
// the USB power-save mode. It is a bitmask constant with bit values:
95+
//
96+
// USB_PWRSAVE_MODE_OFF - No energy saving mode selected
97+
// USB_PWRSAVE_MODE_ONSUSPEND - Enter USB power-save mode on USB suspend
98+
// USB_PWRSAVE_MODE_ONVBUSOFF - Enter USB power-save mode when not attached
99+
// to the USB host.
100+
// USB_PWRSAVE_MODE_FASTWAKE - Exit USB power-save mode more quickly, but
101+
// consume more power while in USB power-save
102+
// mode.
103+
// While the device is in USB power-save mode
104+
// (typically during USB suspend), the
105+
// internal voltage regulator stays in normal
106+
// power mode instead of entering suspend
107+
// power mode.
108+
// This is an advanced feature that may be
109+
// useful in certain applications that support
110+
// remote wakeup.
111+
// -----------------------------------------------------------------------------
112+
#define SLAB_USB_PWRSAVE_MODE (USB_PWRSAVE_MODE_ONVBUSOFF \
113+
| USB_PWRSAVE_MODE_ONSUSPEND)
114+
115+
// -----------------------------------------------------------------------------
116+
// Enable or disable polled mode
117+
//
118+
// When enabled, the application must call USBD_Run() periodically to process
119+
// USB events.
120+
// When disabled, USB events will be handled automatically by an interrupt
121+
// handler.
122+
// -----------------------------------------------------------------------------
123+
#define SLAB_USB_POLLED_MODE 0
124+
125+
#endif // __SILICON_LABS_USBCONFIG_H__

0 commit comments

Comments
 (0)