Skip to content

Commit fae74f4

Browse files
committed
Code-Examples-BT-20819A1-1.0-for-ModusToolbox
1 parent 7d38e1e commit fae74f4

File tree

643 files changed

+125247
-1
lines changed

Some content is hidden

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

643 files changed

+125247
-1
lines changed

Diff for: .project

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>Code-Examples-BT-20819A1-1.0-for-ModusToolbox</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
</buildSpec>
9+
<natures>
10+
</natures>
11+
</projectDescription>

Diff for: 20819_readme.txt

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
------------------------------------------------------------------------------------
2+
BT 20819 SDK
3+
------------------------------------------------------------------------------------
4+
5+
Overview
6+
--------
7+
The Cypress CYW920819 is an ultra-low-power dual-mode Bluetooth 5.0 wireless MCU
8+
device. It has a stand-alone baseband processor with an integrated 2.4 GHz
9+
transceiver supporting BR/EDR/BLE.
10+
11+
SDK Software Features
12+
----------------------
13+
- Dual mode Bluetooth stack included the ROM (BR/EDR and BLE).
14+
- BT stack and profile level APIs for embedded BT application development.
15+
- WICED HCI protocol to simplify host/MCU application development.
16+
- APIs and drivers to access on board peripherals
17+
- Bluetooth protocols include GAP, GATT, SMP, RFCOMM, SDP, AVDT/AVCT, BLE Mesh
18+
- BLE and BR/EDR profile APIs, libraries and sample apps
19+
- Support for Over-The-Air (OTA) upgrade.
20+
- Device Configurator for creating custom pin mapping.
21+
- Bluetooth Configurator for creating BLE GATT Database.
22+
- Documentation for APIs, datasheet, profiles and features.
23+
24+
Kits
25+
----
26+
CYW920819EVB-02:
27+
62-FBGA package, Arduino compatible headers, 9-axis motion sensor and thermistor,
28+
user switches and LEDs, USB connector for power, programming and USB-UART bridge.
29+
Note: Max UART baud rate is 3M
30+
For more information, see - http://www.cypress.com/CYW920819EVB-02
31+
CYBT-213043-MESH
32+
62-FBGA package, PIR sensor (motion detection), Ambient Light Sensor and thermistor,
33+
user switches and RGB LEDs, with additional 1MB External Serial Flash.
34+
Bluetooth 5.0 with SIG MESH Qualified Module, FCC, ISED, MIC, and CE Certified Module
35+
USB connector for power, programming and USB-UART bridge.
36+
Note: Max UART baud rate is 1M
37+
For more information, see - http://www.cypress.com/CYBT-213043-MESH
38+
39+
Software Tools
40+
--------------
41+
Following applications are installed with ModusToolbox on your computer.
42+
43+
BT Spy :
44+
BTSpy is a trace viewer utility that can be used in the WICED BT platforms to
45+
view protocol and application trace messages from the embedded device. The
46+
utility is located in folder below. For more information, see readme.txt
47+
in the same folder. (This utility can also be run from IDE Launches menu).
48+
It is supported on Windows, Linux and macOS.
49+
<Install Dir>\ModusToolbox_1.1\tools\wiced-tools-1.0\BT\BTSpy
50+
51+
BT/BLE Profile Client Control:
52+
This application emulates the host MCU applications for BLE and BR/EDR profile.
53+
It demonstrates WICED BT APIs. It communicates with embedded apps
54+
over the WICED HCI interface. The application is located in folder below.
55+
See readme.txt in the same folder. (This utility can also be run from IDE Launches menu).
56+
It is supported on Windows, Linux and macOS.
57+
<Install Dir>\ModusToolbox_1.1\libraries\bt_20819A1-1.0\components\BT-SDK\common\client_control
58+
59+
BLE Mesh Client Control:
60+
Similar to the above app, this application emulates the host MCU applications
61+
for BLE Mesh models. It can configure and provision mesh devices and create mesh
62+
network. The application is located in folder below. (Currently for Windows OS only).
63+
<Install Dir>\ModusToolbox_1.1\libraries\bt_20819A1-1.0\components\BT-SDK\common\apps\snip\mesh\ClientControl
64+
See readme.txt in the same folder.
65+
66+
Peer apps:
67+
Application that run on Windows, iOS or Android and act as peer
68+
BT apps to demonstrate specific profiles or features.
69+
BT/BLE apps location -
70+
<Install Dir>\ModusToolbox_1.1\libraries\bt_20819A1-1.0\components\BT-SDK\common\peer_apps
71+
BLE Mesh apps location -
72+
<Install Dir>\ModusToolbox_1.1\libraries\bt_20819A1-1.0\components\BT-SDK\common\apps\snip\mesh\peerapps
73+
74+
Device Configurator:
75+
Use this tool to create custom pin mapping for your device. Run this tool from ModusToolbox IDE
76+
"Configure Device" menu. It is supported on Windows, Linux and macOS.
77+
Note: The pin mapping is based on wiced_platform.h for your board.
78+
79+
Bluetooth Configurator:
80+
Use this application to create and configure BLE GATT Database for your application.
81+
Run this tool from ModusToolbox IDE "Configure Device" menu -> Peripherals -> Bluetooth
82+
-> External tools. It is supported on Windows, Linux and macOS.
83+
84+
Tracing
85+
-------
86+
To view application traces, there are 2 methods available. Note that the application
87+
needs to configure the tracing options.
88+
1. WICED Peripheral UART - Open this port on your computer using serial port utility
89+
such as Tera Term or PuTTY (usually baud rate of 115200).
90+
2. WICED HCI UART - Open this port on your computer using Client Control application
91+
mentioned above (usually baud rate of 3M). Then run BT Spy utility mentioned above.
92+
93+
Application Settings
94+
--------------------
95+
Application settings can be changed via 'Change Application Settings...' menu (right click on
96+
application in IDE). Options below are available for all applications. Other application
97+
specific options might also be available and are documented in the readme.txt for those
98+
applications.
99+
100+
BT_DEVICE_ADDRESS
101+
Set BT device address for your BT device. The BT address is 6 bytes,
102+
for example 20819A10FFEE. By default, the SDK will set random BDA for your device.
103+
UART
104+
Select the UART port you want the application to be downloaded. For example 'COM6'
105+
on Windows or '/dev/ttyWICED_HCI_UART0' on Linux or '/dev/tty.usbserial-000154' on macOS.
106+
By default, the SDK will auto detect the port.
107+
APP_XIP
108+
This setting controls the "eXecute In Place" build option for an application. Here XIP
109+
means executing directly from On Chip Flash, rather than copying code to RAM first.
110+
Choices include 'xip' and 'xip_pi', which adds position independence. The trade-offs
111+
for the two settings are overall image size and compatible Over The Air update methods.
112+
The xip_pi build results in a bit larger image because tables and code are added to support
113+
position independent calls to ROM functions or accesses to RAM data. The position independence
114+
allows the load location of the image to be swapped, so fail-safe OTA firmware updates that always
115+
keep a known-good application image in On Chip Flash can be used. The drawback is that less than
116+
half of the On Chip Flash is available, limiting the overall xip_pi image size.
117+
The 'xip' option is built to run from one load location and optimizes size. The load location
118+
cannot be swapped to support OCF-only firmware updates. The recommended OTA firmware update method
119+
for 'xip' uses external flash to temporarily store the image during download and verification.
120+
This means the 'xip' method can support images larger than half the OCF size, but requires
121+
external serial flash for storage.
122+
ENABLE_DEBUG
123+
For HW debugging, select the option '1'. See the document WICED-Hardware-Debugging.pdf
124+
for more information.
125+
126+
Downloading application to kit
127+
------------------------------
128+
If you have issues downloading to the kit, follow the steps below -
129+
- Press and hold the 'Recover' button on the kit.
130+
- Press and hold the 'Reset' button on the kit.
131+
- Release the 'Reset' button.
132+
- After one second, release the 'Recover' button.
133+
134+
After downloading the application, press the 'Reset' button on the kit.
135+
136+
When using CYW920819EVB-02 kit on macOS, make sure to download the latest FTDI drivers
137+
from ftdichip.com (especially for macOS 10.10 or below).
138+
139+
Over The Air (OTA) Firmware Upgrade
140+
-----------------------------------
141+
Application that support OTA upgrade can be updated via peer OTA apps located in the folder -
142+
<Install Dir>\ModusToolbox_1.1\libraries\bt_20819A1-1.0\components\BT-SDK\common\peer_apps\ota_firmware_upgrade
143+
See the readme.txt file located in the above folder for instructions.
144+
145+
146+
------------------------------------------------------------------------------------
+229
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
/*
2+
* Copyright 2019, Cypress Semiconductor Corporation or a subsidiary of
3+
* Cypress Semiconductor Corporation. All Rights Reserved.
4+
*
5+
* This software, including source code, documentation and related
6+
* materials ("Software"), is owned by Cypress Semiconductor Corporation
7+
* or one of its subsidiaries ("Cypress") and is protected by and subject to
8+
* worldwide patent protection (United States and foreign),
9+
* United States copyright laws and international treaty provisions.
10+
* Therefore, you may use this Software only as provided in the license
11+
* agreement accompanying the software package from which you
12+
* obtained this Software ("EULA").
13+
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
14+
* non-transferable license to copy, modify, and compile the Software
15+
* source code solely for use in connection with Cypress's
16+
* integrated circuit products. Any reproduction, modification, translation,
17+
* compilation, or representation of this Software except as specified
18+
* above is prohibited without the express written permission of Cypress.
19+
*
20+
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
21+
* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
22+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
23+
* reserves the right to make changes to the Software without notice. Cypress
24+
* does not assume any liability arising out of the application or use of the
25+
* Software or any product or circuit described in the Software. Cypress does
26+
* not authorize its products for use in any products where a malfunction or
27+
* failure of the Cypress product may reasonably be expected to result in
28+
* significant property damage, injury or death ("High Risk Product"). By
29+
* including Cypress's product in a High Risk Product, the manufacturer
30+
* of such system or application assumes all risk of such use and in doing
31+
* so agrees to indemnify Cypress against all liability.
32+
*/
33+
34+
/** @file
35+
*
36+
* Button control functionality for a dimmer
37+
*
38+
*/
39+
40+
#include "sparcommon.h"
41+
42+
#include "wiced_bt_mesh_models.h"
43+
#include "wiced_bt_mesh_app.h"
44+
#include "wiced_bt_trace.h"
45+
#include "wiced_hal_gpio.h"
46+
#include "wiced_hal_aclk.h"
47+
#include "wiced_platform.h"
48+
#include "button_control.h"
49+
50+
/******************************************************************************
51+
* Constants
52+
******************************************************************************/
53+
#define NUM_STEPS 9
54+
static uint16_t button_level_step[NUM_STEPS] =
55+
{
56+
0x8000, 0xa000, 0xC000, 0xE000, 0x0000, 0x2000, 0x4000, 0x6000, 0x7FFF,
57+
};
58+
59+
extern wiced_platform_button_config_t platform_button[];
60+
/******************************************************************************
61+
* Function Declarations
62+
******************************************************************************/
63+
static void button_interrupt_handler(void* user_data, uint8_t value);
64+
static void button_set_level(wiced_bool_t is_instant, wiced_bool_t is_final);
65+
static void button_timer_callback(uint32_t arg);
66+
67+
/******************************************************************************
68+
* Variables Definitions
69+
******************************************************************************/
70+
uint8_t button_step = 0;
71+
uint64_t button_pushed_time = 0;
72+
wiced_bool_t button_direction = WICED_FALSE;
73+
wiced_bool_t button_level_moving = WICED_FALSE;
74+
uint32_t transation_start_time = 0;
75+
wiced_timer_t button_timer;
76+
uint32_t button_previous_value;
77+
/******************************************************************************
78+
* Function Definitions
79+
******************************************************************************/
80+
void button_control_init(void)
81+
{
82+
wiced_init_timer(&button_timer, &button_timer_callback, 0, WICED_MILLI_SECONDS_TIMER);
83+
button_previous_value = platform_button[WICED_PLATFORM_BUTTON_1].default_state;
84+
}
85+
86+
void button_hardware_init(void)
87+
{
88+
/* Configure buttons available on the platform */
89+
#if defined(CYW20706A2)
90+
wiced_hal_gpio_configure_pin(WICED_GPIO_BUTTON, WICED_GPIO_BUTTON_SETTINGS(GPIO_EN_INT_BOTH_EDGE), WICED_GPIO_BUTTON_DEFAULT_STATE);
91+
wiced_hal_gpio_register_pin_for_interrupt(WICED_GPIO_BUTTON, button_interrupt_handler, NULL);
92+
#elif (defined(CYW20735B0) || defined(CYW20719B0) || defined(CYW20721B0))
93+
wiced_hal_gpio_register_pin_for_interrupt(WICED_GPIO_PIN_BUTTON, button_interrupt_handler, NULL);
94+
wiced_hal_gpio_configure_pin(WICED_GPIO_PIN_BUTTON, WICED_GPIO_BUTTON_SETTINGS, GPIO_PIN_OUTPUT_LOW);
95+
#else
96+
wiced_platform_register_button_callback(WICED_PLATFORM_BUTTON_1, button_interrupt_handler, NULL, GPIO_EN_INT_BOTH_EDGE);
97+
#endif
98+
}
99+
100+
101+
/*
102+
* Process interrupts from the button.
103+
*/
104+
void button_interrupt_handler(void* user_data, uint8_t pin)
105+
{
106+
uint32_t value = wiced_hal_gpio_get_pin_input_status(pin);
107+
uint32_t current_time = wiced_bt_mesh_core_get_tick_count();
108+
uint32_t button_pushed_duration;
109+
110+
if (value == button_previous_value)
111+
{
112+
WICED_BT_TRACE("interrupt_handler: duplicate pin:%d value:%d current_time:%d\n", pin, value, current_time);
113+
return;
114+
}
115+
button_previous_value = value;
116+
117+
WICED_BT_TRACE("interrupt_handler: pin:%d value:%d current_time:%d\n", pin, value, current_time);
118+
119+
if (value == platform_button[WICED_PLATFORM_BUTTON_1].button_pressed_value)
120+
{
121+
button_pushed_time = current_time;
122+
123+
// if button is not released within 500ms, we will start sending move events
124+
wiced_start_timer(&button_timer, 500);
125+
return;
126+
}
127+
wiced_stop_timer(&button_timer);
128+
129+
// button is released
130+
button_pushed_duration = current_time - button_pushed_time;
131+
if (button_pushed_duration < 500)
132+
{
133+
button_level_moving = WICED_FALSE;
134+
135+
if (button_step == 0)
136+
button_step = NUM_STEPS - 1;
137+
else if (button_step == NUM_STEPS - 1)
138+
button_step = 0;
139+
else
140+
button_step = (button_direction ? NUM_STEPS - 1 : 0);
141+
button_set_level(WICED_TRUE, WICED_TRUE);
142+
return;
143+
}
144+
else if (button_pushed_duration < 15000)
145+
{
146+
// we were moving the level and button is released.
147+
// set message with ack
148+
if ((button_step != NUM_STEPS - 1) && (button_step != 0))
149+
button_set_level(WICED_FALSE, WICED_TRUE);
150+
return;
151+
}
152+
// More than 15 seconds means factory reset
153+
mesh_application_factory_reset();
154+
}
155+
156+
void button_timer_callback(uint32_t arg)
157+
{
158+
if (!button_level_moving)
159+
{
160+
if (button_step == 0)
161+
{
162+
button_direction = WICED_TRUE;
163+
button_step++;
164+
}
165+
else if (button_step == NUM_STEPS - 1)
166+
{
167+
button_direction = WICED_FALSE;
168+
button_step--;
169+
}
170+
else
171+
{
172+
if (button_direction)
173+
{
174+
if (button_step != NUM_STEPS - 1)
175+
button_step++;
176+
}
177+
else
178+
{
179+
if (button_step != 0)
180+
button_step--;
181+
}
182+
}
183+
}
184+
else
185+
{
186+
if (button_direction)
187+
{
188+
if (button_step != NUM_STEPS - 1)
189+
button_step++;
190+
}
191+
else
192+
{
193+
if (button_step != 0)
194+
button_step--;
195+
}
196+
}
197+
if ((button_step != NUM_STEPS - 1) && (button_step != 0))
198+
{
199+
button_level_moving = WICED_TRUE;
200+
wiced_start_timer(&button_timer, 500);
201+
button_set_level(WICED_FALSE, WICED_FALSE);
202+
}
203+
else
204+
{
205+
button_level_moving = WICED_FALSE;
206+
button_set_level(WICED_FALSE, WICED_TRUE);
207+
}
208+
}
209+
210+
/*
211+
* This function tells peer to set the level. Instant transition means that the button
212+
* is pushed and release, otherwise the button is being pushed, so the transition
213+
* time is set to 500ms which is the duration between 2 consecutive commands. I.e. we
214+
* send command to go to the next level every 500ms and duration is 500ms, which should
215+
* make the transition go smooth. The final parameter indicates that the transition is
216+
* complete, so we ask peer to send the ack.
217+
*/
218+
void button_set_level(wiced_bool_t is_instant, wiced_bool_t is_final)
219+
{
220+
wiced_bt_mesh_level_set_level_t set_data;
221+
222+
set_data.level = button_level_step[button_step];
223+
set_data.transition_time = is_instant ? 100 : 500;
224+
set_data.delay = 0;
225+
226+
WICED_BT_TRACE("Set level:%d transition time:%d final:%d\n", set_data.level, set_data.transition_time, is_final);
227+
228+
wiced_bt_mesh_model_level_client_set(0, is_final, &set_data);
229+
}

0 commit comments

Comments
 (0)