-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code-Examples-BT-20819A1-1.0-for-ModusToolbox
- Loading branch information
1 parent
7d38e1e
commit fae74f4
Showing
643 changed files
with
125,247 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>Code-Examples-BT-20819A1-1.0-for-ModusToolbox</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
</buildSpec> | ||
<natures> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
------------------------------------------------------------------------------------ | ||
BT 20819 SDK | ||
------------------------------------------------------------------------------------ | ||
|
||
Overview | ||
-------- | ||
The Cypress CYW920819 is an ultra-low-power dual-mode Bluetooth 5.0 wireless MCU | ||
device. It has a stand-alone baseband processor with an integrated 2.4 GHz | ||
transceiver supporting BR/EDR/BLE. | ||
|
||
SDK Software Features | ||
---------------------- | ||
- Dual mode Bluetooth stack included the ROM (BR/EDR and BLE). | ||
- BT stack and profile level APIs for embedded BT application development. | ||
- WICED HCI protocol to simplify host/MCU application development. | ||
- APIs and drivers to access on board peripherals | ||
- Bluetooth protocols include GAP, GATT, SMP, RFCOMM, SDP, AVDT/AVCT, BLE Mesh | ||
- BLE and BR/EDR profile APIs, libraries and sample apps | ||
- Support for Over-The-Air (OTA) upgrade. | ||
- Device Configurator for creating custom pin mapping. | ||
- Bluetooth Configurator for creating BLE GATT Database. | ||
- Documentation for APIs, datasheet, profiles and features. | ||
|
||
Kits | ||
---- | ||
CYW920819EVB-02: | ||
62-FBGA package, Arduino compatible headers, 9-axis motion sensor and thermistor, | ||
user switches and LEDs, USB connector for power, programming and USB-UART bridge. | ||
Note: Max UART baud rate is 3M | ||
For more information, see - http://www.cypress.com/CYW920819EVB-02 | ||
CYBT-213043-MESH | ||
62-FBGA package, PIR sensor (motion detection), Ambient Light Sensor and thermistor, | ||
user switches and RGB LEDs, with additional 1MB External Serial Flash. | ||
Bluetooth 5.0 with SIG MESH Qualified Module, FCC, ISED, MIC, and CE Certified Module | ||
USB connector for power, programming and USB-UART bridge. | ||
Note: Max UART baud rate is 1M | ||
For more information, see - http://www.cypress.com/CYBT-213043-MESH | ||
|
||
Software Tools | ||
-------------- | ||
Following applications are installed with ModusToolbox on your computer. | ||
|
||
BT Spy : | ||
BTSpy is a trace viewer utility that can be used in the WICED BT platforms to | ||
view protocol and application trace messages from the embedded device. The | ||
utility is located in folder below. For more information, see readme.txt | ||
in the same folder. (This utility can also be run from IDE Launches menu). | ||
It is supported on Windows, Linux and macOS. | ||
<Install Dir>\ModusToolbox_1.1\tools\wiced-tools-1.0\BT\BTSpy | ||
|
||
BT/BLE Profile Client Control: | ||
This application emulates the host MCU applications for BLE and BR/EDR profile. | ||
It demonstrates WICED BT APIs. It communicates with embedded apps | ||
over the WICED HCI interface. The application is located in folder below. | ||
See readme.txt in the same folder. (This utility can also be run from IDE Launches menu). | ||
It is supported on Windows, Linux and macOS. | ||
<Install Dir>\ModusToolbox_1.1\libraries\bt_20819A1-1.0\components\BT-SDK\common\client_control | ||
|
||
BLE Mesh Client Control: | ||
Similar to the above app, this application emulates the host MCU applications | ||
for BLE Mesh models. It can configure and provision mesh devices and create mesh | ||
network. The application is located in folder below. (Currently for Windows OS only). | ||
<Install Dir>\ModusToolbox_1.1\libraries\bt_20819A1-1.0\components\BT-SDK\common\apps\snip\mesh\ClientControl | ||
See readme.txt in the same folder. | ||
|
||
Peer apps: | ||
Application that run on Windows, iOS or Android and act as peer | ||
BT apps to demonstrate specific profiles or features. | ||
BT/BLE apps location - | ||
<Install Dir>\ModusToolbox_1.1\libraries\bt_20819A1-1.0\components\BT-SDK\common\peer_apps | ||
BLE Mesh apps location - | ||
<Install Dir>\ModusToolbox_1.1\libraries\bt_20819A1-1.0\components\BT-SDK\common\apps\snip\mesh\peerapps | ||
|
||
Device Configurator: | ||
Use this tool to create custom pin mapping for your device. Run this tool from ModusToolbox IDE | ||
"Configure Device" menu. It is supported on Windows, Linux and macOS. | ||
Note: The pin mapping is based on wiced_platform.h for your board. | ||
|
||
Bluetooth Configurator: | ||
Use this application to create and configure BLE GATT Database for your application. | ||
Run this tool from ModusToolbox IDE "Configure Device" menu -> Peripherals -> Bluetooth | ||
-> External tools. It is supported on Windows, Linux and macOS. | ||
|
||
Tracing | ||
------- | ||
To view application traces, there are 2 methods available. Note that the application | ||
needs to configure the tracing options. | ||
1. WICED Peripheral UART - Open this port on your computer using serial port utility | ||
such as Tera Term or PuTTY (usually baud rate of 115200). | ||
2. WICED HCI UART - Open this port on your computer using Client Control application | ||
mentioned above (usually baud rate of 3M). Then run BT Spy utility mentioned above. | ||
|
||
Application Settings | ||
-------------------- | ||
Application settings can be changed via 'Change Application Settings...' menu (right click on | ||
application in IDE). Options below are available for all applications. Other application | ||
specific options might also be available and are documented in the readme.txt for those | ||
applications. | ||
|
||
BT_DEVICE_ADDRESS | ||
Set BT device address for your BT device. The BT address is 6 bytes, | ||
for example 20819A10FFEE. By default, the SDK will set random BDA for your device. | ||
UART | ||
Select the UART port you want the application to be downloaded. For example 'COM6' | ||
on Windows or '/dev/ttyWICED_HCI_UART0' on Linux or '/dev/tty.usbserial-000154' on macOS. | ||
By default, the SDK will auto detect the port. | ||
APP_XIP | ||
This setting controls the "eXecute In Place" build option for an application. Here XIP | ||
means executing directly from On Chip Flash, rather than copying code to RAM first. | ||
Choices include 'xip' and 'xip_pi', which adds position independence. The trade-offs | ||
for the two settings are overall image size and compatible Over The Air update methods. | ||
The xip_pi build results in a bit larger image because tables and code are added to support | ||
position independent calls to ROM functions or accesses to RAM data. The position independence | ||
allows the load location of the image to be swapped, so fail-safe OTA firmware updates that always | ||
keep a known-good application image in On Chip Flash can be used. The drawback is that less than | ||
half of the On Chip Flash is available, limiting the overall xip_pi image size. | ||
The 'xip' option is built to run from one load location and optimizes size. The load location | ||
cannot be swapped to support OCF-only firmware updates. The recommended OTA firmware update method | ||
for 'xip' uses external flash to temporarily store the image during download and verification. | ||
This means the 'xip' method can support images larger than half the OCF size, but requires | ||
external serial flash for storage. | ||
ENABLE_DEBUG | ||
For HW debugging, select the option '1'. See the document WICED-Hardware-Debugging.pdf | ||
for more information. | ||
|
||
Downloading application to kit | ||
------------------------------ | ||
If you have issues downloading to the kit, follow the steps below - | ||
- Press and hold the 'Recover' button on the kit. | ||
- Press and hold the 'Reset' button on the kit. | ||
- Release the 'Reset' button. | ||
- After one second, release the 'Recover' button. | ||
|
||
After downloading the application, press the 'Reset' button on the kit. | ||
|
||
When using CYW920819EVB-02 kit on macOS, make sure to download the latest FTDI drivers | ||
from ftdichip.com (especially for macOS 10.10 or below). | ||
|
||
Over The Air (OTA) Firmware Upgrade | ||
----------------------------------- | ||
Application that support OTA upgrade can be updated via peer OTA apps located in the folder - | ||
<Install Dir>\ModusToolbox_1.1\libraries\bt_20819A1-1.0\components\BT-SDK\common\peer_apps\ota_firmware_upgrade | ||
See the readme.txt file located in the above folder for instructions. | ||
|
||
|
||
------------------------------------------------------------------------------------ |
229 changes: 229 additions & 0 deletions
229
CYBT-213043-MESH/apps/demo/mesh/dimmer/button_control.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,229 @@ | ||
/* | ||
* Copyright 2019, Cypress Semiconductor Corporation or a subsidiary of | ||
* Cypress Semiconductor Corporation. All Rights Reserved. | ||
* | ||
* This software, including source code, documentation and related | ||
* materials ("Software"), is owned by Cypress Semiconductor Corporation | ||
* or one of its subsidiaries ("Cypress") and is protected by and subject to | ||
* worldwide patent protection (United States and foreign), | ||
* United States copyright laws and international treaty provisions. | ||
* Therefore, you may use this Software only as provided in the license | ||
* agreement accompanying the software package from which you | ||
* obtained this Software ("EULA"). | ||
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive, | ||
* non-transferable license to copy, modify, and compile the Software | ||
* source code solely for use in connection with Cypress's | ||
* integrated circuit products. Any reproduction, modification, translation, | ||
* compilation, or representation of this Software except as specified | ||
* above is prohibited without the express written permission of Cypress. | ||
* | ||
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress | ||
* reserves the right to make changes to the Software without notice. Cypress | ||
* does not assume any liability arising out of the application or use of the | ||
* Software or any product or circuit described in the Software. Cypress does | ||
* not authorize its products for use in any products where a malfunction or | ||
* failure of the Cypress product may reasonably be expected to result in | ||
* significant property damage, injury or death ("High Risk Product"). By | ||
* including Cypress's product in a High Risk Product, the manufacturer | ||
* of such system or application assumes all risk of such use and in doing | ||
* so agrees to indemnify Cypress against all liability. | ||
*/ | ||
|
||
/** @file | ||
* | ||
* Button control functionality for a dimmer | ||
* | ||
*/ | ||
|
||
#include "sparcommon.h" | ||
|
||
#include "wiced_bt_mesh_models.h" | ||
#include "wiced_bt_mesh_app.h" | ||
#include "wiced_bt_trace.h" | ||
#include "wiced_hal_gpio.h" | ||
#include "wiced_hal_aclk.h" | ||
#include "wiced_platform.h" | ||
#include "button_control.h" | ||
|
||
/****************************************************************************** | ||
* Constants | ||
******************************************************************************/ | ||
#define NUM_STEPS 9 | ||
static uint16_t button_level_step[NUM_STEPS] = | ||
{ | ||
0x8000, 0xa000, 0xC000, 0xE000, 0x0000, 0x2000, 0x4000, 0x6000, 0x7FFF, | ||
}; | ||
|
||
extern wiced_platform_button_config_t platform_button[]; | ||
/****************************************************************************** | ||
* Function Declarations | ||
******************************************************************************/ | ||
static void button_interrupt_handler(void* user_data, uint8_t value); | ||
static void button_set_level(wiced_bool_t is_instant, wiced_bool_t is_final); | ||
static void button_timer_callback(uint32_t arg); | ||
|
||
/****************************************************************************** | ||
* Variables Definitions | ||
******************************************************************************/ | ||
uint8_t button_step = 0; | ||
uint64_t button_pushed_time = 0; | ||
wiced_bool_t button_direction = WICED_FALSE; | ||
wiced_bool_t button_level_moving = WICED_FALSE; | ||
uint32_t transation_start_time = 0; | ||
wiced_timer_t button_timer; | ||
uint32_t button_previous_value; | ||
/****************************************************************************** | ||
* Function Definitions | ||
******************************************************************************/ | ||
void button_control_init(void) | ||
{ | ||
wiced_init_timer(&button_timer, &button_timer_callback, 0, WICED_MILLI_SECONDS_TIMER); | ||
button_previous_value = platform_button[WICED_PLATFORM_BUTTON_1].default_state; | ||
} | ||
|
||
void button_hardware_init(void) | ||
{ | ||
/* Configure buttons available on the platform */ | ||
#if defined(CYW20706A2) | ||
wiced_hal_gpio_configure_pin(WICED_GPIO_BUTTON, WICED_GPIO_BUTTON_SETTINGS(GPIO_EN_INT_BOTH_EDGE), WICED_GPIO_BUTTON_DEFAULT_STATE); | ||
wiced_hal_gpio_register_pin_for_interrupt(WICED_GPIO_BUTTON, button_interrupt_handler, NULL); | ||
#elif (defined(CYW20735B0) || defined(CYW20719B0) || defined(CYW20721B0)) | ||
wiced_hal_gpio_register_pin_for_interrupt(WICED_GPIO_PIN_BUTTON, button_interrupt_handler, NULL); | ||
wiced_hal_gpio_configure_pin(WICED_GPIO_PIN_BUTTON, WICED_GPIO_BUTTON_SETTINGS, GPIO_PIN_OUTPUT_LOW); | ||
#else | ||
wiced_platform_register_button_callback(WICED_PLATFORM_BUTTON_1, button_interrupt_handler, NULL, GPIO_EN_INT_BOTH_EDGE); | ||
#endif | ||
} | ||
|
||
|
||
/* | ||
* Process interrupts from the button. | ||
*/ | ||
void button_interrupt_handler(void* user_data, uint8_t pin) | ||
{ | ||
uint32_t value = wiced_hal_gpio_get_pin_input_status(pin); | ||
uint32_t current_time = wiced_bt_mesh_core_get_tick_count(); | ||
uint32_t button_pushed_duration; | ||
|
||
if (value == button_previous_value) | ||
{ | ||
WICED_BT_TRACE("interrupt_handler: duplicate pin:%d value:%d current_time:%d\n", pin, value, current_time); | ||
return; | ||
} | ||
button_previous_value = value; | ||
|
||
WICED_BT_TRACE("interrupt_handler: pin:%d value:%d current_time:%d\n", pin, value, current_time); | ||
|
||
if (value == platform_button[WICED_PLATFORM_BUTTON_1].button_pressed_value) | ||
{ | ||
button_pushed_time = current_time; | ||
|
||
// if button is not released within 500ms, we will start sending move events | ||
wiced_start_timer(&button_timer, 500); | ||
return; | ||
} | ||
wiced_stop_timer(&button_timer); | ||
|
||
// button is released | ||
button_pushed_duration = current_time - button_pushed_time; | ||
if (button_pushed_duration < 500) | ||
{ | ||
button_level_moving = WICED_FALSE; | ||
|
||
if (button_step == 0) | ||
button_step = NUM_STEPS - 1; | ||
else if (button_step == NUM_STEPS - 1) | ||
button_step = 0; | ||
else | ||
button_step = (button_direction ? NUM_STEPS - 1 : 0); | ||
button_set_level(WICED_TRUE, WICED_TRUE); | ||
return; | ||
} | ||
else if (button_pushed_duration < 15000) | ||
{ | ||
// we were moving the level and button is released. | ||
// set message with ack | ||
if ((button_step != NUM_STEPS - 1) && (button_step != 0)) | ||
button_set_level(WICED_FALSE, WICED_TRUE); | ||
return; | ||
} | ||
// More than 15 seconds means factory reset | ||
mesh_application_factory_reset(); | ||
} | ||
|
||
void button_timer_callback(uint32_t arg) | ||
{ | ||
if (!button_level_moving) | ||
{ | ||
if (button_step == 0) | ||
{ | ||
button_direction = WICED_TRUE; | ||
button_step++; | ||
} | ||
else if (button_step == NUM_STEPS - 1) | ||
{ | ||
button_direction = WICED_FALSE; | ||
button_step--; | ||
} | ||
else | ||
{ | ||
if (button_direction) | ||
{ | ||
if (button_step != NUM_STEPS - 1) | ||
button_step++; | ||
} | ||
else | ||
{ | ||
if (button_step != 0) | ||
button_step--; | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
if (button_direction) | ||
{ | ||
if (button_step != NUM_STEPS - 1) | ||
button_step++; | ||
} | ||
else | ||
{ | ||
if (button_step != 0) | ||
button_step--; | ||
} | ||
} | ||
if ((button_step != NUM_STEPS - 1) && (button_step != 0)) | ||
{ | ||
button_level_moving = WICED_TRUE; | ||
wiced_start_timer(&button_timer, 500); | ||
button_set_level(WICED_FALSE, WICED_FALSE); | ||
} | ||
else | ||
{ | ||
button_level_moving = WICED_FALSE; | ||
button_set_level(WICED_FALSE, WICED_TRUE); | ||
} | ||
} | ||
|
||
/* | ||
* This function tells peer to set the level. Instant transition means that the button | ||
* is pushed and release, otherwise the button is being pushed, so the transition | ||
* time is set to 500ms which is the duration between 2 consecutive commands. I.e. we | ||
* send command to go to the next level every 500ms and duration is 500ms, which should | ||
* make the transition go smooth. The final parameter indicates that the transition is | ||
* complete, so we ask peer to send the ack. | ||
*/ | ||
void button_set_level(wiced_bool_t is_instant, wiced_bool_t is_final) | ||
{ | ||
wiced_bt_mesh_level_set_level_t set_data; | ||
|
||
set_data.level = button_level_step[button_step]; | ||
set_data.transition_time = is_instant ? 100 : 500; | ||
set_data.delay = 0; | ||
|
||
WICED_BT_TRACE("Set level:%d transition time:%d final:%d\n", set_data.level, set_data.transition_time, is_final); | ||
|
||
wiced_bt_mesh_model_level_client_set(0, is_final, &set_data); | ||
} |
Oops, something went wrong.