Skip to content
This repository was archived by the owner on Jan 29, 2024. It is now read-only.

Commit 1441712

Browse files
committed
added example user apps
1 parent 05b7b13 commit 1441712

File tree

163 files changed

+51140
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+51140
-0
lines changed

example-apps/mouseplay/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.bak
2+
D11mouseplay THUMB Debug/*
3+
D11mouseplay THUMB Release/*
4+
*.hzs
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!DOCTYPE Board_Memory_Definition_File>
2+
<root name="ATSAMD11D14AM">
3+
<MemorySegment name="FLASH" start="0x00000400" size="0x00003C00" access="ReadOnly" />
4+
<MemorySegment name="RAM" start="0x20000000" size="0x00001000" access="Read/Write" />
5+
</root>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<!DOCTYPE CrossStudio_Project_File>
2+
<solution Name="D11mouseplay" target="8" version="2">
3+
<project Name="D11mouseplay">
4+
<configuration
5+
CMSIS_CORE="Yes"
6+
Name="Common"
7+
Placement="Flash"
8+
Startup="Release Only"
9+
Target="ATSAMD11D14AM"
10+
arm_architecture="v6M"
11+
arm_core_type="Cortex-M0+"
12+
arm_endian="Little"
13+
arm_fpu_type="None"
14+
arm_interwork="No"
15+
arm_linker_heap_size="256"
16+
arm_linker_process_stack_size="0"
17+
arm_linker_stack_size="256"
18+
arm_simulator_memory_simulation_filename="$(TargetsDir)/SAM_D/Simulator/SAM_D_SimulatorMemory_$(HostOS)_$(HostArch)$(HostDLLExt)"
19+
arm_simulator_memory_simulation_parameter="SAM D,SAM D11;FLASH,0x00000000,0x00004000,ROM;RAM,0x20000000,0x00001000,RAM"
20+
arm_target_debug_interface_type="ADIv5"
21+
arm_target_device_name="ATSAMD11D14AM"
22+
arm_target_interface_type="SWD"
23+
arm_target_loader_applicable_loaders="Flash"
24+
arm_target_loader_default_loader="Flash"
25+
c_preprocessor_definitions="DONT_USE_CMSIS_INIT;F_CPU=48000000"
26+
c_user_include_directories="$(ProjectDir);$(ProjectDir)/include"
27+
debug_register_definition_file="$(DeviceRegisterDefinitionFile)"
28+
gcc_entry_point="Reset_Handler"
29+
linker_keep_symbols="vectors"
30+
linker_memory_map_file="$(DeviceMemoryMapFile)"
31+
linker_output_format="bin"
32+
linker_section_placement_file="$(StudioDir)/targets/Cortex_M/flash_placement.xml"
33+
macros="DeviceLoaderFile=$(TargetsDir)/SAM_D/Loader/SAM_D11_Loader.elf;DeviceMemoryMapFile=$(TargetsDir)/SAM_D/XML/ATSAMD11D14AM_MemoryMap.xml;DeviceRegisterDefinitionFile=$(TargetsDir)/SAM_D/XML/ATSAMD11D14AM_Registers.xml;DeviceFamily=SAM D;DeviceSubFamily=SAM D11"
34+
package_dependencies="Atmel_ATSAMD11-XPRO"
35+
project_directory=""
36+
project_type="Executable"
37+
property_groups_file_path="$(TargetsDir)/SAM_D/XML/property_groups.xml"
38+
target_get_partname_script="GetPartName()"
39+
target_match_partname_script="MatchPartName(&quot;$(Target)&quot;)"
40+
target_reset_script="Reset();"
41+
target_trace_initialize_script="EnableTrace(&quot;$(TraceInterfaceType)&quot;)" />
42+
<configuration
43+
Name="Flash"
44+
arm_target_flash_loader_file_path="$(DeviceLoaderFile)" />
45+
<folder Name="Script Files">
46+
<file file_name="$(TargetsDir)/SAM_D/Scripts/SAM_D_Target.js">
47+
<configuration Name="Common" file_type="Reset Script" />
48+
</file>
49+
</folder>
50+
<folder Name="Source Files">
51+
<configuration Name="Common" filter="c;cpp;cxx;cc;h;s;asm;inc" />
52+
<file file_name="main.c" />
53+
<file file_name="startup_samd11.c" />
54+
<file file_name="usb.c" />
55+
<file file_name="usb_descriptors.c" />
56+
<file file_name="usb_std.c" />
57+
<file file_name="usb_hid.c" />
58+
</folder>
59+
<folder Name="System Files">
60+
<file file_name="ATSAMD11D14AM_MemoryMap.xml" />
61+
</folder>
62+
</project>
63+
<configuration Name="THUMB Debug" inherited_configurations="THUMB;Debug" />
64+
<configuration
65+
Name="THUMB"
66+
Platform="ARM"
67+
arm_instruction_set="Thumb"
68+
arm_library_instruction_set="Thumb"
69+
c_preprocessor_definitions="__THUMB"
70+
hidden="Yes" />
71+
<configuration
72+
Name="Debug"
73+
c_preprocessor_definitions="DEBUG"
74+
gcc_debugging_level="Level 3"
75+
gcc_omit_frame_pointer="Yes"
76+
gcc_optimization_level="None"
77+
hidden="Yes" />
78+
<configuration
79+
Name="THUMB Release"
80+
inherited_configurations="THUMB;Release" />
81+
<configuration
82+
Name="Release"
83+
c_preprocessor_definitions="NDEBUG"
84+
gcc_debugging_level="None"
85+
gcc_omit_frame_pointer="Yes"
86+
gcc_optimization_level="Level 1"
87+
hidden="Yes" />
88+
</solution>

example-apps/mouseplay/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
mouseplay: example HID mouse
2+
============================
3+
4+
## Introduction
5+
6+
This functions like the example app "mouseplay" included with [USB DFU Bootloader for PIC16F1454/5/9](https://github.com/majbthrd/PIC16F1-USB-DFU-Bootloader).
7+
8+
The USB stack source code owes its origins to both [vcp](https://github.com/ataradov/vcp) and [free-dap](https://github.com/ataradov/free-dap). The [vcp](https://github.com/ataradov/vcp) USB stack is newer and more sophisticated, but is not a HID implementation like [free-dap](https://github.com/ataradov/free-dap). Using the two code bases, I made an educated guess at what sort of USB HID implementation the author might have written after written vcp.
9+
10+
The linker memory maps have been adjusted to exclude the first 0x400 bytes so as allow operation with the [USB DFU Bootloader for SAMD11](https://github.com/majbthrd/SAMD11-USB-DFU-Bootloader/).
11+
12+
## Build Requirements
13+
14+
One approach is to use [Rowley Crossworks for ARM](http://www.rowley.co.uk/arm/) to compile this code. It is not free software, but has been my favorite go-to ARM development tool for a decade and counting.
15+
16+
*OR*
17+
18+
Use the Makefile in the make subdirectory. With this approach, the code can be built using only open-source software. In Ubuntu-derived distributions, this is likely achieved with as little as:
19+
20+
```
21+
sudo apt-get install gcc-arm-none-eabi libnewlib-arm-none-eabi build-essential
22+
```
23+
24+
## Customizing
25+
26+
usb_descriptors.c contains the USB VID:PID. All unique USB device implementations must have their own unique USB VID:PID identifiers.
27+
28+
If modifying usb_hid_report_descriptor in usb_hid.c, the USB_HID_REPORT_DESCRIPTOR_LENGTH define in usb_hid.h *MUST* exactly match the new size of usb_hid_report_descriptor.
29+
30+
As with any USB HID device, the HID report size (nominally sent by send_buffer() in main.c) *MUST* exactly match the metadata conveyed in the usb_hid_report_descriptor.

example-apps/mouseplay/hal_gpio.h

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Copyright (c) 2014-2016, Alex Taradov <[email protected]>
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
* 3. The name of the author may not be used to endorse or promote products
14+
* derived from this software without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
*/
28+
29+
#ifndef _HAL_GPIO_H_
30+
#define _HAL_GPIO_H_
31+
32+
/*- Definitions -------------------------------------------------------------*/
33+
#define HAL_GPIO_PORTA 0
34+
#define HAL_GPIO_PORTB 1
35+
#define HAL_GPIO_PORTC 2
36+
37+
#define HAL_GPIO_PMUX_A 0
38+
#define HAL_GPIO_PMUX_B 1
39+
#define HAL_GPIO_PMUX_C 2
40+
#define HAL_GPIO_PMUX_D 3
41+
#define HAL_GPIO_PMUX_E 4
42+
#define HAL_GPIO_PMUX_F 5
43+
#define HAL_GPIO_PMUX_G 6
44+
#define HAL_GPIO_PMUX_H 7
45+
#define HAL_GPIO_PMUX_I 8
46+
47+
#define HAL_GPIO_PIN(name, port, pin) \
48+
static inline void HAL_GPIO_##name##_set(void) \
49+
{ \
50+
PORT->Group[HAL_GPIO_PORT##port].OUTSET.reg = (1 << pin); \
51+
(void)HAL_GPIO_##name##_set; \
52+
} \
53+
\
54+
static inline void HAL_GPIO_##name##_clr(void) \
55+
{ \
56+
PORT->Group[HAL_GPIO_PORT##port].OUTCLR.reg = (1 << pin); \
57+
(void)HAL_GPIO_##name##_clr; \
58+
} \
59+
\
60+
static inline void HAL_GPIO_##name##_toggle(void) \
61+
{ \
62+
PORT->Group[HAL_GPIO_PORT##port].OUTTGL.reg = (1 << pin); \
63+
(void)HAL_GPIO_##name##_toggle; \
64+
} \
65+
\
66+
static inline void HAL_GPIO_##name##_write(int value) \
67+
{ \
68+
if (value) \
69+
PORT->Group[HAL_GPIO_PORT##port].OUTSET.reg = (1 << pin); \
70+
else \
71+
PORT->Group[HAL_GPIO_PORT##port].OUTCLR.reg = (1 << pin); \
72+
(void)HAL_GPIO_##name##_write; \
73+
} \
74+
\
75+
static inline void HAL_GPIO_##name##_in(void) \
76+
{ \
77+
PORT->Group[HAL_GPIO_PORT##port].DIRCLR.reg = (1 << pin); \
78+
PORT->Group[HAL_GPIO_PORT##port].PINCFG[pin].reg |= PORT_PINCFG_INEN; \
79+
PORT->Group[HAL_GPIO_PORT##port].PINCFG[pin].reg &= ~PORT_PINCFG_PULLEN; \
80+
(void)HAL_GPIO_##name##_in; \
81+
} \
82+
\
83+
static inline void HAL_GPIO_##name##_out(void) \
84+
{ \
85+
PORT->Group[HAL_GPIO_PORT##port].DIRSET.reg = (1 << pin); \
86+
PORT->Group[HAL_GPIO_PORT##port].PINCFG[pin].reg |= PORT_PINCFG_INEN; \
87+
(void)HAL_GPIO_##name##_out; \
88+
} \
89+
\
90+
static inline void HAL_GPIO_##name##_pullup(void) \
91+
{ \
92+
PORT->Group[HAL_GPIO_PORT##port].OUTSET.reg = (1 << pin); \
93+
PORT->Group[HAL_GPIO_PORT##port].PINCFG[pin].reg |= PORT_PINCFG_PULLEN; \
94+
(void)HAL_GPIO_##name##_pullup; \
95+
} \
96+
\
97+
static inline int HAL_GPIO_##name##_read(void) \
98+
{ \
99+
return (PORT->Group[HAL_GPIO_PORT##port].IN.reg & (1 << pin)) != 0; \
100+
(void)HAL_GPIO_##name##_read; \
101+
} \
102+
\
103+
static inline int HAL_GPIO_##name##_state(void) \
104+
{ \
105+
return (PORT->Group[HAL_GPIO_PORT##port].DIR.reg & (1 << pin)) != 0; \
106+
(void)HAL_GPIO_##name##_state; \
107+
} \
108+
\
109+
static inline void HAL_GPIO_##name##_pmuxen(int mux) \
110+
{ \
111+
PORT->Group[HAL_GPIO_PORT##port].PINCFG[pin].reg |= PORT_PINCFG_PMUXEN; \
112+
if (pin & 1) \
113+
PORT->Group[HAL_GPIO_PORT##port].PMUX[pin>>1].bit.PMUXO = mux; \
114+
else \
115+
PORT->Group[HAL_GPIO_PORT##port].PMUX[pin>>1].bit.PMUXE = mux; \
116+
(void)HAL_GPIO_##name##_pmuxen; \
117+
} \
118+
\
119+
static inline void HAL_GPIO_##name##_pmuxdis(void) \
120+
{ \
121+
PORT->Group[HAL_GPIO_PORT##port].PINCFG[pin].reg &= ~PORT_PINCFG_PMUXEN; \
122+
(void)HAL_GPIO_##name##_pmuxdis; \
123+
} \
124+
125+
#endif // _HAL_GPIO_H_
126+

0 commit comments

Comments
 (0)