Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
  • Loading branch information
mringwal committed Apr 3, 2020
2 parents 4d24213 + 985f340 commit 8ffc7c2
Show file tree
Hide file tree
Showing 232 changed files with 73,080 additions and 377 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Changed

## Changes April 2020

### Fixed

### Added
- GAP: gap_set_allow_role_switch allows to prevent role switch in outgoing classic ACL connections

### Changed

## Changes March 2020

### Fixed
- GAP: fixed gap_set_scan_parameters() if issued right before gap_start_scan()
- HCI: only send HCI Read Local Encryption Key Size if supported by Controller

### Added
- GATT Client: allow to register for any notification/indication and/or any connection
hci_cmd: added hci_read_inquiry_scan_activity and hci_write_inquiry_scan_activity
- chipset: assert hci packet buffers are suitable for firmware upload or patches (atwilc3000,bcm,cc256x,intel)

### Changed
- AVRCP Target: volume in avrcp_target_volume_changed is reported as current value in interim response to register for volume change notifications
- SDP Client: query attributes 0x0000..0xffff instead of 0x0001..0xffff to match other stacks / improve compatibility with bad sdp server implementations

## Changes Februar 2020

### Fixed
Expand All @@ -22,6 +46,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Changed
- hid_host_mode: allow sniff mode

### Added
- port/qt-usb and port/qt-h4: integrate BTstack Qt run loop for Unix- or Win32-based Qt application connected to Bluetooth module via H4 over serial port or USB.


## Changes January 2020

### Fixed
Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Welcome to BTstack

BTstack is [BlueKitchen's](http://bluekitchen-gmbh.com) implementation of the official Bluetooth stack.
BTstack is [BlueKitchen's](https://bluekitchen-gmbh.com) implementation of the official Bluetooth stack.
It is well suited for small, resource-constraint devices
such as 8 or 16 bit embedded systems as it is highly configurable and comes with an ultra small memory footprint.

Expand All @@ -20,7 +20,7 @@ BTstack is free for non-commercial use. However, for commercial use, <a href="ma

**Third-party libraries (FOSS):** [List of used libraries and their licenses](https://github.com/bluekitchen/btstack/blob/develop/3rd-party/README.md)

**Discussion and Community Support:** [BTstack Google Group](http://groups.google.com/group/btstack-dev)
**Discussion and Community Support:** [BTstack Google Group](https://groups.google.com/group/btstack-dev)


### Supported Protocols and Profiles
Expand All @@ -29,6 +29,10 @@ BTstack is free for non-commercial use. However, for commercial use, <a href="ma

**Profiles:** GAP, IOP, HFP, HSP, SPP, PAN, A2DP, AVRCP incl. Browsing, GATT.

**GATT Services:** Battery, Cycling Power, Cycling Speed and Cadence, Device Information, Heart Rate, HID over GATT (HOG), Mesh Provisioning, Mesh Proxy, Nordic SPP, u-Blox SPP.

GATT Services are in general easy to implement and require short development time. For more GATT Services please contact us, or follow the [implementation guidelines](http://bluekitchen-gmbh.com/btstack/profiles/#gatt-generic-attribute-profile).

**Beta Stage:** HID, HOGP, PBAP.

**In Development:** BLE Mesh and more.
Expand Down Expand Up @@ -58,13 +62,15 @@ No build server | [wiced-h5](https://github.com/bluekitchen/btstack/tree/master/
#### Other Platforms:
Status | Port | Platform
-------------------| ------|---------
[<img src="http://buildbot.bluekitchen-gmbh.com/btstack/badges/port-libusb-master.svg">](https://buildbot.bluekitchen-gmbh.com/btstack/#/builders/port-libusb-master) | [libusb](https://github.com/bluekitchen/btstack/tree/master/port/libusb) | Unix-based system with dedicated USB Bluetooth dongle
No build server | [libusb-intel](https://github.com/bluekitchen/btstack/tree/master/port/libusb-intel) | Unix-based system with Intel Wireless 8260/8265 Controller
[<img src="http://buildbot.bluekitchen-gmbh.com/btstack/badges/port-posix-h4-master.svg">](https://buildbot.bluekitchen-gmbh.com/btstack/#/builders/port-posix-h4-master) | [posix-h4](https://github.com/bluekitchen/btstack/tree/master/port/posix-h4) | Unix-based system connected to Bluetooth module via H4 over serial port
No build server | [posix-h4-da14581](https://github.com/bluekitchen/btstack/tree/master/port/posix-h4-da14581) | Unix-based system connected to Dialog Semiconductor DA14581 via H4 over serial port
No build server | [posix-h4-da14585](https://github.com/bluekitchen/btstack/tree/master/port/posix-h4-da14585) | Unix-based system connected to Dialog Semiconductor DA14585 via H4 over serial port
No build server | [posix-h5](https://github.com/bluekitchen/btstack/tree/master/port/posix-h5) | Unix-based system connected to Bluetooth module via H5 over serial port
No build server | [posix-h5-bcm](https://github.com/bluekitchen/btstack/tree/master/port/posix-h5) | Unix-based system connected to Broadcom/Cypress Bluetooth module via H5 over serial port
[<img src="http://buildbot.bluekitchen-gmbh.com/btstack/badges/port-libusb-master.svg">](https://buildbot.bluekitchen-gmbh.com/btstack/#/builders/port-libusb-master) | [libusb](https://github.com/bluekitchen/btstack/tree/master/port/libusb) | Unix-based system with dedicated USB Bluetooth dongle
No build server | [libusb-intel](https://github.com/bluekitchen/btstack/tree/master/port/libusb-intel) | Unix-based system with Intel Wireless 8260/8265 Controller
No build server | [qt-h4](https://github.com/bluekitchen/btstack/tree/master/port/qt-h4) | Unix- or Win32-based [Qt application](https://qt.io) connected to Bluetooth module via H4 over serial port
No build server | [qt-usb](https://github.com/bluekitchen/btstack/tree/master/port/qt-usb) | Unix- or Win32-based [Qt application](https://qt.io) with dedicated USB Bluetooth dongle
No build server | [windows-h4](https://github.com/bluekitchen/btstack/tree/master/port/windows-h4) | Win32-based system connected to Bluetooth module via serial port
No build server | [windows-winusb](https://github.com/bluekitchen/btstack/tree/master/port/windows-winusb) | Win32-based system with dedicated USB Bluetooth dongle
No build server | [windows-winusb-intel](https://github.com/bluekitchen/btstack/tree/master/port/windows-winusb-intel) | Win32-based system with Intel Wireless 8260/8265 Controller
Expand Down
20 changes: 14 additions & 6 deletions chipset/atwilc3000/btstack_chipset_atwilc3000.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,33 @@
*
*/

#define BTSTACK_FILE__ "btstack_chipset_atwilc3000.c"

/*
* btstack_chipset_atwilc3000.c
*
* Adapter to use atwilc3000-based chipsets with BTstack
*
*/

#define BTSTACK_FILE__ "btstack_chipset_atwilc3000.c"

#include "btstack_config.h"
#include "btstack_chipset_atwilc3000.h"
#include "btstack_debug.h"


#include <stddef.h> /* NULL */
#include <stdio.h>
#include <stdio.h>
#include <string.h> /* memcpy */

#include "btstack_chipset_atwilc3000.h"
#include "btstack_debug.h"
#include "hci.h"

// assert outgoing and incoming hci packet buffers can hold max hci command resp. event packet
#if HCI_OUTGOING_PACKET_BUFFER_SIZE < (HCI_CMD_HEADER_SIZE + 255)
#error "HCI_OUTGOING_PACKET_BUFFER_SIZE to small. Outgoing HCI packet buffer to small for largest HCI Command packet. Please set HCI_ACL_PAYLOAD_SIZE to 258 or higher."
#endif
#if HCI_INCOMING_PACKET_BUFFER_SIZE < (HCI_EVENT_HEADER_SIZE + 255)
#error "HCI_INCOMING_PACKET_BUFFER_SIZE to small. Incoming HCI packet buffer to small for largest HCI Event packet. Please set HCI_ACL_PAYLOAD_SIZE to 257 or higher."
#endif

// Address to load firmware
#define IRAM_START 0x80000000

Expand Down
9 changes: 9 additions & 0 deletions chipset/bcm/btstack_chipset_bcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "btstack_control.h"
#include "btstack_debug.h"
#include "btstack_chipset_bcm.h"
#include "hci.h"

#ifdef HAVE_POSIX_FILE_IO
#include <ctype.h>
Expand All @@ -64,6 +65,14 @@
#include <Windows.h>
#endif

// assert outgoing and incoming hci packet buffers can hold max hci command resp. event packet
#if HCI_OUTGOING_PACKET_BUFFER_SIZE < (HCI_CMD_HEADER_SIZE + 255)
#error "HCI_OUTGOING_PACKET_BUFFER_SIZE to small. Outgoing HCI packet buffer to small for largest HCI Command packet. Please set HCI_ACL_PAYLOAD_SIZE to 258 or higher."
#endif
#if HCI_INCOMING_PACKET_BUFFER_SIZE < (HCI_EVENT_HEADER_SIZE + 255)
#error "HCI_INCOMING_PACKET_BUFFER_SIZE to small. Incoming HCI packet buffer to small for largest HCI Event packet. Please set HCI_ACL_PAYLOAD_SIZE to 257 or higher."
#endif

static int send_download_command;
static uint32_t init_script_offset;

Expand Down
9 changes: 9 additions & 0 deletions chipset/cc256x/btstack_chipset_cc256x.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,20 @@
#include "btstack_config.h"
#include "btstack_chipset_cc256x.h"
#include "btstack_debug.h"
#include "hci.h"

#include <stddef.h> /* NULL */
#include <stdio.h>
#include <string.h> /* memcpy */

// assert outgoing and incoming hci packet buffers can hold max hci command resp. event packet
#if HCI_OUTGOING_PACKET_BUFFER_SIZE < (HCI_CMD_HEADER_SIZE + 255)
#error "HCI_OUTGOING_PACKET_BUFFER_SIZE to small. Outgoing HCI packet buffer to small for largest HCI Command packet. Please set HCI_ACL_PAYLOAD_SIZE to 258 or higher."
#endif
#if HCI_INCOMING_PACKET_BUFFER_SIZE < (HCI_EVENT_HEADER_SIZE + 255)
#error "HCI_INCOMING_PACKET_BUFFER_SIZE to small. Incoming HCI packet buffer to small for largest HCI Event packet. Please set HCI_ACL_PAYLOAD_SIZE to 257 or higher."
#endif

#if defined(__GNUC__) && defined(__MSP430X__) && (__MSP430X__ > 0)
#include "hal_compat.h"
#endif
Expand Down
14 changes: 7 additions & 7 deletions chipset/da14581/btstack_chipset_da14581.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
/*
* btstack_chipset_da14581.c
*
* Adapter to use da14581-based chipsets with BTstack
* Adapter to use da1458x-based chipsets with BTstack
*
*/

Expand Down Expand Up @@ -75,8 +75,7 @@ static const btstack_uart_block_t * the_uart_driver;

static int download_count;
static uint8_t response_buffer[1];
static uint8_t download_command[3];
static const uint8_t final_ack = ACK;
static uint8_t command_buffer[3];
static const uint8_t * fw_data;
static uint16_t fw_size;

Expand All @@ -93,10 +92,10 @@ static void da14581_w4_stx(void){
case STX:
log_info("da14581_w4_stx: send download command");
// setup download config message
download_command[0] = SOH;
little_endian_store_16(download_command, 1, fw_size);
command_buffer[0] = SOH;
little_endian_store_16(command_buffer, 1, fw_size);
the_uart_driver->set_block_sent(da14581_w4_command_sent);
the_uart_driver->send_block(download_command, sizeof(download_command));
the_uart_driver->send_block(command_buffer, 3);
break;
default:
// read again
Expand Down Expand Up @@ -166,8 +165,9 @@ static void da14581_w4_crc(void){
}

// everything's fine, send final ack
command_buffer[0] = ACK;
the_uart_driver->set_block_sent(&da14581_w4_final_ack_sent);
the_uart_driver->send_block(&final_ack, sizeof(final_ack));
the_uart_driver->send_block(command_buffer, 1);
}

static void da14581_w4_final_ack_sent(void){
Expand Down
18 changes: 14 additions & 4 deletions chipset/intel/btstack_chipset_intel_firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,23 @@
#include <stdio.h>

#include "btstack_chipset_intel_firmware.h"
#include "hci_cmd.h"

#include "bluetooth.h"
#include "hci_dump.h"
#include "btstack_event.h"
#include "btstack_debug.h"
#include "btstack_util.h"
#include "btstack_event.h"
#include "btstack_run_loop.h"
#include "btstack_util.h"
#include "hci.h"
#include "hci_cmd.h"
#include "hci_dump.h"

// assert outgoing and incoming hci packet buffers can hold max hci command resp. event packet
#if HCI_OUTGOING_PACKET_BUFFER_SIZE < (HCI_CMD_HEADER_SIZE + 255)
#error "HCI_OUTGOING_PACKET_BUFFER_SIZE to small. Outgoing HCI packet buffer to small for largest HCI Command packet. Please set HCI_ACL_PAYLOAD_SIZE to 258 or higher."
#endif
#if HCI_INCOMING_PACKET_BUFFER_SIZE < (HCI_EVENT_HEADER_SIZE_HEADER_SIZE + 255)
#error "HCI_INCOMING_PACKET_BUFFER_SIZE to small. Incoming HCI packet buffer to small for largest HCI Event packet. Please set HCI_ACL_PAYLOAD_SIZE to 257 or higher."
#endif

// Vendor specific structs

Expand Down
7 changes: 6 additions & 1 deletion doc/manual/docs/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Currently, we have two examples for this:
managed in a linked list. Then, the *select* function is used to wait
for the next file descriptor to become ready or timer to expire.

- *btstack_run_loop_cocoa.c* is an implementation for the CoreFoundation
- *btstack_run_loop_cocoa.c* is an integration for the CoreFoundation
Framework used in OS X and iOS. All run loop functions are
implemented in terms of CoreFoundation calls, data sources and
timers are modeled as CFSockets and CFRunLoopTimer respectively.
Expand All @@ -45,6 +45,11 @@ Currently, we have two examples for this:
Then, the *WaitForMultipleObjects* is used to wait for the next Event to
becomre ready or timer to expire.

- *btstack_run_loop_qt* is an integration for the Qt run loop.
The data sources on Windows systems use Event objects via Qt's QEventNotifier adapter,
while a QSocketNotifier is used for Mac/Linux to handle file descriptors.
With these in place, the Windows/POSIX implemenations for HCI USB/H2 and HCI H4 can be used.

## Adapting BTstack for Multi-Threaded Environments {#sec:multithreadingIntegration}


Expand Down
38 changes: 22 additions & 16 deletions example/a2dp_sink_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
*
* @test To controll the playback, tap SPACE on the console to show the available
* AVRCP commands.
*
* For more info on BTstack audio, see our blog post
* [A2DP Sink and Source on STM32 F4 Discovery Board](http://bluekitchen-gmbh.com/a2dp-sink-and-source-on-stm32-f4-discovery-board/).
*
*/
// *****************************************************************************

Expand Down Expand Up @@ -114,14 +118,14 @@ static int request_frames;
#define STORE_FROM_PLAYBACK

// WAV File
#ifdef STORE_TO_WAV_FILE
static int frame_count = 0;
static char * wav_filename = "avdtp_sink.wav";
#ifdef STORE_TO_WAV_FILE
static uint32_t audio_frame_count = 0;
static char * wav_filename = "av2dp_sink_demo.wav";
#endif

#ifdef STORE_TO_SBC_FILE
static FILE * sbc_file;
static char * sbc_filename = "avdtp_sink.sbc";
static char * sbc_filename = "av2dp_sink_demo.sbc";
#endif

static int volume_percentage = 0;
Expand Down Expand Up @@ -294,28 +298,28 @@ static int a2dp_and_avrcp_setup(void){
return 0;
}

static void playback_handler(int16_t * buffer, uint16_t num_frames){
static void playback_handler(int16_t * buffer, uint16_t num_audio_frames){

#ifdef STORE_TO_WAV_FILE
int wav_samples = num_frames * NUM_CHANNELS;
int wav_samples = num_audio_frames * NUM_CHANNELS;
int16_t * wav_buffer = buffer;
#endif

// called from lower-layer but guaranteed to be on main thread
if (sbc_frame_size == 0){
memset(buffer, 0, num_frames * BYTES_PER_FRAME);
memset(buffer, 0, num_audio_frames * BYTES_PER_FRAME);
return;
}

// first fill from resampled audio
uint32_t bytes_read;
btstack_ring_buffer_read(&decoded_audio_ring_buffer, (uint8_t *) buffer, num_frames * BYTES_PER_FRAME, &bytes_read);
btstack_ring_buffer_read(&decoded_audio_ring_buffer, (uint8_t *) buffer, num_audio_frames * BYTES_PER_FRAME, &bytes_read);
buffer += bytes_read / NUM_CHANNELS;
num_frames -= bytes_read / BYTES_PER_FRAME;
num_audio_frames -= bytes_read / BYTES_PER_FRAME;

// then start decoding sbc frames using request_* globals
request_buffer = buffer;
request_frames = num_frames;
request_frames = num_audio_frames;
while (request_frames && btstack_ring_buffer_bytes_available(&sbc_frame_ring_buffer) >= sbc_frame_size){
// decode frame
uint8_t sbc_frame[MAX_SBC_FRAME_SIZE];
Expand All @@ -324,26 +328,28 @@ static void playback_handler(int16_t * buffer, uint16_t num_frames){
}

#ifdef STORE_TO_WAV_FILE
audio_frame_count += num_audio_frames;
wav_writer_write_int16(wav_samples, wav_buffer);
#endif
}

static void handle_pcm_data(int16_t * data, int num_frames, int num_channels, int sample_rate, void * context){
static void handle_pcm_data(int16_t * data, int num_audio_frames, int num_channels, int sample_rate, void * context){
UNUSED(sample_rate);
UNUSED(context);
UNUSED(num_channels); // must be stereo == 2

const btstack_audio_sink_t * audio_sink = btstack_audio_sink_get_instance();
if (!audio_sink){
#ifdef STORE_TO_WAV_FILE
wav_writer_write_int16(num_frames * NUM_CHANNELS, data);
audio_frame_count += num_audio_frames;
wav_writer_write_int16(num_audio_frames * NUM_CHANNELS, data);
#endif
return;
}

// resample into request buffer - add some additional space for resampling
int16_t output_buffer[(128+16) * NUM_CHANNELS]; // 16 * 8 * 2
uint32_t resampled_frames = btstack_resample_block(&resample_instance, data, num_frames, output_buffer);
uint32_t resampled_frames = btstack_resample_block(&resample_instance, data, num_audio_frames, output_buffer);

// store data in btstack_audio buffer first
int frames_to_copy = btstack_min(resampled_frames, request_frames);
Expand Down Expand Up @@ -417,10 +423,10 @@ static void media_processing_close(void){

#ifdef STORE_TO_WAV_FILE
wav_writer_close();
int total_frames_nr = state.good_frames_nr + state.bad_frames_nr + state.zero_frames_nr;
uint32_t total_frames_nr = state.good_frames_nr + state.bad_frames_nr + state.zero_frames_nr;

printf("WAV Writer: Decoding done. Processed totaly %d frames:\n - %d good\n - %d bad\n", total_frames_nr, state.good_frames_nr, total_frames_nr - state.good_frames_nr);
printf("WAV Writer: Written %d frames to wav file: %s\n", frame_count, wav_filename);
printf("WAV Writer: Decoding done. Processed %u SBC frames:\n - %d good\n - %d bad\n", total_frames_nr, state.good_frames_nr, total_frames_nr - state.good_frames_nr);
printf("WAV Writer: Wrote %u audio frames to wav file: %s\n", audio_frame_count, wav_filename);
#endif

#ifdef STORE_TO_SBC_FILE
Expand Down
4 changes: 4 additions & 0 deletions example/a2dp_source_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
* set the device_addr_string to the Bluetooth address of your
* remote device in the code, and use the UI to connect and start playback.
* Tap SPACE on the console to show the available commands.
*
* For more info on BTstack audio, see our blog post
* [A2DP Sink and Source on STM32 F4 Discovery Board](http://bluekitchen-gmbh.com/a2dp-sink-and-source-on-stm32-f4-discovery-board/).
*
*/
// *****************************************************************************

Expand Down

0 comments on commit 8ffc7c2

Please sign in to comment.