Skip to content

Commit afaccf2

Browse files
committed
Merge branch 'master' into core-ble
2 parents d90f8b0 + 5a7e96c commit afaccf2

Some content is hidden

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

65 files changed

+26744
-330
lines changed

boards.txt

+7-7
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ artemis.build.mcu=cortex-m4
3737
artemis.build.f_cpu=48000000L
3838
artemis.build.core=arduino
3939
artemis.build.extra_flags=-DPART_apollo3 -DAM_PACKAGE_BGA -DAM_PART_APOLLO3
40-
artemis.build.includes=-I{build.variant.path}/config
40+
artemis.build.includes="-I{build.variant.path}/config" "-I{build.variant.path}/bsp"
4141
artemis.build.preferred_export_format=axf
4242
artemis.build.defs=
4343
artemis.build.libs=
@@ -73,7 +73,7 @@ amap3redboard.build.arch=APOLLO3
7373
amap3redboard.build.mcu=cortex-m4
7474
amap3redboard.build.f_cpu=48000000L
7575
amap3redboard.build.core=arduino
76-
amap3redboard.build.includes=-I{build.variant.path}/config
76+
amap3redboard.build.includes="-I{build.variant.path}/config" "-I{build.variant.path}/bsp"
7777
amap3redboard.build.ldscript={build.variant.path}/linker_scripts/gcc/artemis_sbl_svl_app.ld
7878
amap3redboard.build.extra_flags=-DPART_apollo3 -DAM_PACKAGE_BGA -DAM_PART_APOLLO3
7979
amap3redboard.build.preferred_export_format=axf
@@ -110,7 +110,7 @@ amap3nano.build.arch=APOLLO3
110110
amap3nano.build.mcu=cortex-m4
111111
amap3nano.build.f_cpu=48000000L
112112
amap3nano.build.core=arduino
113-
amap3nano.build.includes=-I{build.variant.path}/config
113+
amap3nano.build.includes="-I{build.variant.path}/config" "-I{build.variant.path}/bsp"
114114
amap3nano.build.ldscript={build.variant.path}/linker_scripts/gcc/artemis_sbl_svl_app.ld
115115
amap3nano.build.extra_flags=-DPART_apollo3 -DAM_PACKAGE_BGA -DAM_PART_APOLLO3
116116
amap3nano.build.preferred_export_format=axf
@@ -147,7 +147,7 @@ amap3atp.build.arch=APOLLO3
147147
amap3atp.build.mcu=cortex-m4
148148
amap3atp.build.f_cpu=48000000L
149149
amap3atp.build.core=arduino
150-
amap3atp.build.includes=-I{build.variant.path}/config
150+
amap3atp.build.includes="-I{build.variant.path}/config" "-I{build.variant.path}/bsp"
151151
amap3atp.build.extra_flags=-DPART_apollo3 -DAM_PACKAGE_BGA -DAM_PART_APOLLO3
152152
amap3atp.build.ldscript={build.variant.path}/linker_scripts/gcc/artemis_sbl_svl_app.ld
153153
amap3atp.build.preferred_export_format=axf
@@ -184,7 +184,7 @@ amap3thing.build.arch=APOLLO3
184184
amap3thing.build.mcu=cortex-m4
185185
amap3thing.build.f_cpu=48000000L
186186
amap3thing.build.core=arduino
187-
amap3thing.build.includes=-I{build.variant.path}/config
187+
amap3thing.build.includes="-I{build.variant.path}/config" "-I{build.variant.path}/bsp"
188188
amap3thing.build.ldscript={build.variant.path}/linker_scripts/gcc/artemis_sbl_svl_app.ld
189189
amap3thing.build.extra_flags=-DPART_apollo3 -DAM_PACKAGE_BGA -DAM_PART_APOLLO3
190190
amap3thing.build.preferred_export_format=axf
@@ -222,7 +222,7 @@ edge.build.mcu=cortex-m4
222222
edge.build.f_cpu=48000000L
223223
edge.build.core=arduino
224224
edge.build.defs=
225-
edge.build.includes=-I{build.variant.path}/config
225+
edge.build.includes="-I{build.variant.path}/config" "-I{build.variant.path}/bsp"
226226
edge.build.libs=
227227
edge.build.extra_flags=-DPART_apollo3 -DAM_PACKAGE_BGA -DAM_PART_APOLLO3
228228
edge.build.ldscript={build.variant.path}/linker_scripts/gcc/ambiq_sbl_app.ld
@@ -268,7 +268,7 @@ edge2.build.arch=APOLLO3
268268
edge2.build.mcu=cortex-m4
269269
edge2.build.f_cpu=48000000L
270270
edge2.build.core=arduino
271-
edge2.build.includes=-I{build.variant.path}/config
271+
edge2.build.includes="-I{build.variant.path}/config" "-I{build.variant.path}/bsp"
272272
edge2.build.extra_flags=-DPART_apollo3 -DAM_PACKAGE_BGA -DAM_PART_APOLLO3
273273
edge2.build.ldscript={build.variant.path}/linker_scripts/gcc/artemis_sbl_svl_app.ld
274274
edge2.build.preferred_export_format=axf
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
//*****************************************************************************
2+
//
3+
//! @file am_devices_button.c
4+
//!
5+
//! @brief Functions for controlling an array of LEDs
6+
//
7+
//*****************************************************************************
8+
9+
//*****************************************************************************
10+
//
11+
// Copyright (c) 2019, Ambiq Micro
12+
// All rights reserved.
13+
//
14+
// Redistribution and use in source and binary forms, with or without
15+
// modification, are permitted provided that the following conditions are met:
16+
//
17+
// 1. Redistributions of source code must retain the above copyright notice,
18+
// this list of conditions and the following disclaimer.
19+
//
20+
// 2. Redistributions in binary form must reproduce the above copyright
21+
// notice, this list of conditions and the following disclaimer in the
22+
// documentation and/or other materials provided with the distribution.
23+
//
24+
// 3. Neither the name of the copyright holder nor the names of its
25+
// contributors may be used to endorse or promote products derived from this
26+
// software without specific prior written permission.
27+
//
28+
// Third party software included in this distribution is subject to the
29+
// additional license terms as defined in the /docs/licenses directory.
30+
//
31+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
32+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
35+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
39+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41+
// POSSIBILITY OF SUCH DAMAGE.
42+
//
43+
// This is part of revision v2.2.0-7-g63f7c2ba1 of the AmbiqSuite Development Package.
44+
//
45+
//*****************************************************************************
46+
47+
#include <stdint.h>
48+
#include <stdbool.h>
49+
#include "am_mcu_apollo.h"
50+
#include "am_devices_button.h"
51+
52+
//*****************************************************************************
53+
//
54+
//! @brief Configures the necessary pins for an array of buttons.
55+
//!
56+
//! @param psButton is a pointer to a button structure.
57+
//!
58+
//! This function configures a GPIO to read a button in a low-power way.
59+
//!
60+
//! @return None.
61+
//
62+
//*****************************************************************************
63+
void
64+
am_devices_button_init(am_devices_button_t *psButton)
65+
{
66+
//
67+
// Disable the pin to save power.
68+
//
69+
#if AM_APOLLO3_GPIO
70+
am_hal_gpio_pinconfig(psButton->ui32GPIONumber, g_AM_HAL_GPIO_DISABLE);
71+
#else // AM_APOLLO3_GPIO
72+
am_hal_gpio_pin_config(psButton->ui32GPIONumber, AM_HAL_PIN_DISABLE);
73+
#endif // AM_APOLLO3_GPIO
74+
75+
76+
//
77+
// Initialize the state variables.
78+
//
79+
psButton->ui32Count = 0;
80+
psButton->bPressed = false;
81+
psButton->bChanged = false;
82+
}
83+
84+
//*****************************************************************************
85+
//
86+
//! @brief Configures the necessary pins for an array of buttons.
87+
//!
88+
//! @param psButtons is an array of button structures.
89+
//! @param ui32NumButtons is the total number of buttons in the array.
90+
//!
91+
//! This function configures the GPIOs for an array of buttons.
92+
//!
93+
//! @return None.
94+
//
95+
//*****************************************************************************
96+
void
97+
am_devices_button_array_init(am_devices_button_t *psButtons,
98+
uint32_t ui32NumButtons)
99+
{
100+
uint32_t i;
101+
102+
//
103+
// Loop through the list of buttons, configuring each one individually.
104+
//
105+
for ( i = 0; i < ui32NumButtons; i++ )
106+
{
107+
am_devices_button_init(psButtons + i);
108+
}
109+
}
110+
111+
//*****************************************************************************
112+
//
113+
//! @brief Configures the necessary pins for an array of buttons.
114+
//!
115+
//! @param psButtons is an array of button structures.
116+
//! @param ui32NumButtons is the total number of buttons in the array.
117+
//!
118+
//! This function configures the GPIOs for an array of buttons.
119+
//!
120+
//! @return None.
121+
//
122+
//*****************************************************************************
123+
void
124+
am_devices_button_tick(am_devices_button_t *psButton)
125+
{
126+
uint32_t ui32PinState;
127+
bool bRawButtonPressed;
128+
129+
//
130+
// Enable the button pin.
131+
//
132+
#if AM_APOLLO3_GPIO
133+
am_hal_gpio_pinconfig(psButton->ui32GPIONumber, g_AM_HAL_GPIO_INPUT);
134+
#else // AM_APOLLO3_GPIO
135+
am_hal_gpio_pin_config(psButton->ui32GPIONumber, AM_HAL_PIN_INPUT);
136+
#endif // AM_APOLLO3_GPIO
137+
138+
//
139+
// Read the pin state. If the pin is in its normal (unpressed) state, set
140+
// its "state" counter to zero.
141+
//
142+
#if AM_APOLLO3_GPIO
143+
am_hal_gpio_state_read(psButton->ui32GPIONumber, AM_HAL_GPIO_INPUT_READ, &ui32PinState);
144+
#else // AM_APOLLO3_GPIO
145+
ui32PinState = am_hal_gpio_input_bit_read(psButton->ui32GPIONumber);
146+
#endif // AM_APOLLO3_GPIO
147+
148+
//
149+
// Check to see if the button is "pressed" according to our GPIO reading.
150+
//
151+
bRawButtonPressed = (ui32PinState != psButton->ui32Polarity);
152+
153+
//
154+
// Is this button state different from the last saved state?
155+
//
156+
if ( bRawButtonPressed != psButton->bPressed )
157+
{
158+
//
159+
// If so, increase the debounce count.
160+
//
161+
psButton->ui32Count++;
162+
}
163+
else
164+
{
165+
//
166+
// Otherwise, set the count back to zero.
167+
//
168+
psButton->ui32Count = 0;
169+
}
170+
171+
//
172+
// If we hit the button debounce delay, record a button press to the
173+
// structure, and reset the count.
174+
//
175+
if ( psButton->ui32Count >= AM_DEVICES_BUTTON_DEBOUNCE_DELAY )
176+
{
177+
psButton->bPressed = bRawButtonPressed;
178+
psButton->bChanged = true;
179+
psButton->ui32Count = 0;
180+
}
181+
else
182+
{
183+
//
184+
// If we didn't just record a press/release event, update the structure
185+
// to say that the current state isn't new.
186+
//
187+
psButton->bChanged = false;
188+
}
189+
190+
//
191+
// Disable the button pin to save power.
192+
//
193+
#if AM_APOLLO3_GPIO
194+
am_hal_gpio_pinconfig(psButton->ui32GPIONumber, g_AM_HAL_GPIO_DISABLE);
195+
#else // AM_APOLLO3_GPIO
196+
am_hal_gpio_pin_config(psButton->ui32GPIONumber, AM_HAL_PIN_DISABLE);
197+
#endif // AM_APOLLO3_GPIO
198+
}
199+
200+
//*****************************************************************************
201+
//
202+
//! @brief Configures the necessary pins for an array of buttons.
203+
//!
204+
//! @param psButtons is an array of button structures.
205+
//! @param ui32NumButtons is the total number of buttons in the array.
206+
//!
207+
//! This function configures the GPIOs for an array of buttons.
208+
//!
209+
//! @return None.
210+
//
211+
//*****************************************************************************
212+
void
213+
am_devices_button_array_tick(am_devices_button_t *psButtons,
214+
uint32_t ui32NumButtons)
215+
{
216+
uint32_t i;
217+
218+
//
219+
// Run the "tick" function for each button in the list.
220+
//
221+
for ( i = 0; i < ui32NumButtons; i++ )
222+
{
223+
am_devices_button_tick(psButtons + i);
224+
}
225+
}

0 commit comments

Comments
 (0)