mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-22 06:41:17 +00:00
Begin porting btstack to esp32
This commit is contained in:
parent
4b8ec5bc8f
commit
d4d8445570
9
chipset/esp32/Makefile.inc
Normal file
9
chipset/esp32/Makefile.inc
Normal file
@ -0,0 +1,9 @@
|
||||
#
|
||||
# Makefile to download and convert .hcd init files for Broadcom Bluetooth chipsets
|
||||
#
|
||||
|
||||
all: BCM43430A1.hcd
|
||||
|
||||
# used with Ampak AP6121 and BCM43438A1
|
||||
BCM43430A1.hcd:
|
||||
curl -O -L https://github.com/OpenELEC/misc-firmware/raw/master/firmware/brcm/BCM43430A1.hcd
|
2
port/esp32/.gitignore
vendored
Normal file
2
port/esp32/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
build/
|
||||
sdkconfig.old
|
9
port/esp32/Makefile
Normal file
9
port/esp32/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
#
|
||||
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
|
||||
# project subdirectory.
|
||||
#
|
||||
|
||||
PROJECT_NAME := advertise
|
||||
|
||||
include $(IDF_PATH)/make/project.mk
|
||||
|
43
port/esp32/main/btstack_config.h
Normal file
43
port/esp32/main/btstack_config.h
Normal file
@ -0,0 +1,43 @@
|
||||
//
|
||||
// btstack_config.h for esp32 port
|
||||
//
|
||||
|
||||
#ifndef __BTSTACK_CONFIG
|
||||
#define __BTSTACK_CONFIG
|
||||
|
||||
// Port related features
|
||||
#define HAVE_EMBEDDED_TICK
|
||||
#define HAVE_MALLOC
|
||||
|
||||
// BTstack features that can be enabled
|
||||
#define ENABLE_BLE
|
||||
#define ENABLE_CLASSIC
|
||||
#define ENABLE_LE_PERIPHERAL
|
||||
#define ENABLE_LE_CENTRAL
|
||||
// #define ENABLE_LOG_ERROR
|
||||
// #define ENABLE_LOG_INFO
|
||||
#define ENABLE_LOG_DEBUG
|
||||
// #define ENABLE_EHCILL
|
||||
|
||||
// BTstack configuration. buffers, sizes, ...
|
||||
#define HCI_ACL_PAYLOAD_SIZE 52
|
||||
#define MAX_NR_BNEP_CHANNELS MAX_SPP_CONNECTIONS
|
||||
#define MAX_NR_BNEP_SERVICES 1
|
||||
#define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 2
|
||||
#define MAX_NR_GATT_CLIENTS 1
|
||||
#define MAX_NR_HCI_CONNECTIONS MAX_SPP_CONNECTIONS
|
||||
#define MAX_NR_HFP_CONNECTIONS 0
|
||||
#define MAX_NR_L2CAP_CHANNELS (1+MAX_SPP_CONNECTIONS)
|
||||
#define MAX_NR_L2CAP_SERVICES 2
|
||||
#define MAX_NR_RFCOMM_CHANNELS MAX_SPP_CONNECTIONS
|
||||
#define MAX_NR_RFCOMM_MULTIPLEXERS MAX_SPP_CONNECTIONS
|
||||
#define MAX_NR_RFCOMM_SERVICES 1
|
||||
#define MAX_NR_SERVICE_RECORD_ITEMS 1
|
||||
#define MAX_NR_SM_LOOKUP_ENTRIES 3
|
||||
#define MAX_NR_WHITELIST_ENTRIES 1
|
||||
#define MAX_SPP_CONNECTIONS 1
|
||||
#define MAX_NR_LE_DEVICE_DB_ENTRIES 0
|
||||
//
|
||||
|
||||
#endif
|
||||
|
21
port/esp32/main/component.mk
Normal file
21
port/esp32/main/component.mk
Normal file
@ -0,0 +1,21 @@
|
||||
#
|
||||
# Main component makefile.
|
||||
#
|
||||
# This Makefile can be left empty. By default, it will take the sources in the
|
||||
# src/ directory, compile them and link them into lib(subdirectory_name).a
|
||||
# in the build directory. This behaviour is entirely configurable,
|
||||
# please read the ESP-IDF documents if you need to do this.
|
||||
#
|
||||
BTSTACK_ROOT := ../../..
|
||||
|
||||
# Examples
|
||||
#include ${BTSTACK_ROOT}/example/Makefile.inc
|
||||
|
||||
COMPONENT_ADD_LDFLAGS := -l$(COMPONENT_NAME) $(COMPONENT_PATH)/../components/libbtdm_app/libbtdm_app.a
|
||||
|
||||
COMPONENT_ADD_INCLUDEDIRS := $(BTSTACK_ROOT)/src/ble $(BTSTACK_ROOT)/src $(BTSTACK_ROOT)/platform/embedded .
|
||||
|
||||
COMPONENT_SRCDIRS := $(BTSTACK_ROOT)/src/ble $(BTSTACK_ROOT)/src/ $(BTSTACK_ROOT)/platform/embedded .
|
||||
|
||||
CFLAGS += -Wno-format
|
||||
|
308
port/esp32/main/gatt_browser.c
Normal file
308
port/esp32/main/gatt_browser.c
Normal file
@ -0,0 +1,308 @@
|
||||
/*
|
||||
* Copyright (C) 2014 BlueKitchen GmbH
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holders nor the names of
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* 4. Any redistribution, use, or modification is done solely for
|
||||
* personal benefit and not for any commercial purpose or for
|
||||
* monetary gain.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
|
||||
* RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* Please inquire about commercial licensing options at
|
||||
* contact@bluekitchen-gmbh.com
|
||||
*
|
||||
*/
|
||||
|
||||
// *****************************************************************************
|
||||
/* EXAMPLE_START(gatt_browser): GATT Client - Discovering primary services and their characteristics
|
||||
*
|
||||
* @text This example shows how to use the GATT Client
|
||||
* API to discover primary services and their characteristics of the first found
|
||||
* device that is advertising its services.
|
||||
*
|
||||
* The logic is divided between the HCI and GATT client packet handlers.
|
||||
* The HCI packet handler is responsible for finding a remote device,
|
||||
* connecting to it, and for starting the first GATT client query.
|
||||
* Then, the GATT client packet handler receives all primary services and
|
||||
* requests the characteristics of the last one to keep the example short.
|
||||
*
|
||||
*/
|
||||
// *****************************************************************************
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "btstack.h"
|
||||
#include "gap.h"
|
||||
|
||||
typedef struct advertising_report {
|
||||
uint8_t type;
|
||||
uint8_t event_type;
|
||||
uint8_t address_type;
|
||||
bd_addr_t address;
|
||||
uint8_t rssi;
|
||||
uint8_t length;
|
||||
const uint8_t * data;
|
||||
} advertising_report_t;
|
||||
|
||||
static bd_addr_t cmdline_addr = { };
|
||||
static int cmdline_addr_found = 0;
|
||||
|
||||
static hci_con_handle_t connection_handler;
|
||||
static gatt_client_service_t services[40];
|
||||
static int service_count = 0;
|
||||
static int service_index = 0;
|
||||
|
||||
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||
|
||||
/* @section GATT client setup
|
||||
*
|
||||
* @text In the setup phase, a GATT client must register the HCI and GATT client
|
||||
* packet handlers, as shown in Listing GATTClientSetup.
|
||||
* Additionally, the security manager can be setup, if signed writes, or
|
||||
* encrypted, or authenticated connection are required, to access the
|
||||
* characteristics, as explained in Section on [SMP](../protocols/#sec:smpProtocols).
|
||||
*/
|
||||
|
||||
/* LISTING_START(GATTClientSetup): Setting up GATT client */
|
||||
|
||||
// Handles connect, disconnect, and advertising report events,
|
||||
// starts the GATT client, and sends the first query.
|
||||
static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
||||
|
||||
// Handles GATT client query results, sends queries and the
|
||||
// GAP disconnect command when the querying is done.
|
||||
static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
||||
|
||||
static void gatt_client_setup(void){
|
||||
|
||||
// register for HCI events
|
||||
hci_event_callback_registration.callback = &handle_hci_event;
|
||||
hci_add_event_handler(&hci_event_callback_registration);
|
||||
|
||||
// Initialize L2CAP and register HCI event handler
|
||||
l2cap_init();
|
||||
|
||||
// Initialize GATT client
|
||||
gatt_client_init();
|
||||
|
||||
// Optinoally, Setup security manager
|
||||
sm_init();
|
||||
sm_set_io_capabilities(IO_CAPABILITY_NO_INPUT_NO_OUTPUT);
|
||||
}
|
||||
/* LISTING_END */
|
||||
|
||||
static void printUUID(uint8_t * uuid128, uint16_t uuid16){
|
||||
if (uuid16){
|
||||
printf("%04x",uuid16);
|
||||
} else {
|
||||
printf("%s", uuid128_to_str(uuid128));
|
||||
}
|
||||
}
|
||||
|
||||
static void dump_advertising_report(advertising_report_t * e){
|
||||
printf(" * adv. event: evt-type %u, addr-type %u, addr %s, rssi %u, length adv %u, data: ", e->event_type,
|
||||
e->address_type, bd_addr_to_str(e->address), e->rssi, e->length);
|
||||
printf_hexdump(e->data, e->length);
|
||||
|
||||
}
|
||||
|
||||
static void dump_characteristic(gatt_client_characteristic_t * characteristic){
|
||||
printf(" * characteristic: [0x%04x-0x%04x-0x%04x], properties 0x%02x, uuid ",
|
||||
characteristic->start_handle, characteristic->value_handle, characteristic->end_handle, characteristic->properties);
|
||||
printUUID(characteristic->uuid128, characteristic->uuid16);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static void dump_service(gatt_client_service_t * service){
|
||||
printf(" * service: [0x%04x-0x%04x], uuid ", service->start_group_handle, service->end_group_handle);
|
||||
printUUID(service->uuid128, service->uuid16);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static void fill_advertising_report_from_packet(advertising_report_t * report, uint8_t *packet){
|
||||
gap_event_advertising_report_get_address(packet, report->address);
|
||||
report->event_type = gap_event_advertising_report_get_advertising_event_type(packet);
|
||||
report->address_type = gap_event_advertising_report_get_address_type(packet);
|
||||
report->rssi = gap_event_advertising_report_get_rssi(packet);
|
||||
report->length = gap_event_advertising_report_get_data_length(packet);
|
||||
report->data = gap_event_advertising_report_get_data(packet);
|
||||
}
|
||||
|
||||
/* @section HCI packet handler
|
||||
*
|
||||
* @text The HCI packet handler has to start the scanning,
|
||||
* to find the first advertising device, to stop scanning, to connect
|
||||
* to and later to disconnect from it, to start the GATT client upon
|
||||
* the connection is completed, and to send the first query - in this
|
||||
* case the gatt_client_discover_primary_services() is called, see
|
||||
* Listing GATTBrowserHCIPacketHandler.
|
||||
*/
|
||||
|
||||
/* LISTING_START(GATTBrowserHCIPacketHandler): Connecting and disconnecting from the GATT client */
|
||||
static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||
UNUSED(channel);
|
||||
UNUSED(size);
|
||||
|
||||
if (packet_type != HCI_EVENT_PACKET) return;
|
||||
advertising_report_t report;
|
||||
|
||||
uint8_t event = hci_event_packet_get_type(packet);
|
||||
switch (event) {
|
||||
case BTSTACK_EVENT_STATE:
|
||||
// BTstack activated, get started
|
||||
if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) break;
|
||||
if (cmdline_addr_found){
|
||||
printf("Trying to connect to %s\n", bd_addr_to_str(cmdline_addr));
|
||||
gap_connect(cmdline_addr, 0);
|
||||
break;
|
||||
}
|
||||
printf("BTstack activated, start scanning!\n");
|
||||
gap_set_scan_parameters(0,0x0030, 0x0030);
|
||||
gap_start_scan();
|
||||
break;
|
||||
case GAP_EVENT_ADVERTISING_REPORT:
|
||||
fill_advertising_report_from_packet(&report, packet);
|
||||
dump_advertising_report(&report);
|
||||
|
||||
// stop scanning, and connect to the device
|
||||
gap_stop_scan();
|
||||
gap_connect(report.address,report.address_type);
|
||||
break;
|
||||
case HCI_EVENT_LE_META:
|
||||
// wait for connection complete
|
||||
if (hci_event_le_meta_get_subevent_code(packet) != HCI_SUBEVENT_LE_CONNECTION_COMPLETE) break;
|
||||
connection_handler = hci_subevent_le_connection_complete_get_connection_handle(packet);
|
||||
// query primary services
|
||||
gatt_client_discover_primary_services(handle_gatt_client_event, connection_handler);
|
||||
break;
|
||||
case HCI_EVENT_DISCONNECTION_COMPLETE:
|
||||
printf("\nGATT browser - DISCONNECTED\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* LISTING_END */
|
||||
|
||||
/* @section GATT Client event handler
|
||||
*
|
||||
* @text Query results and further queries are handled by the GATT client packet
|
||||
* handler, as shown in Listing GATTBrowserQueryHandler. Here, upon
|
||||
* receiving the primary services, the
|
||||
* gatt_client_discover_characteristics_for_service() query for the last
|
||||
* received service is sent. After receiving the characteristics for the service,
|
||||
* gap_disconnect is called to terminate the connection. Upon
|
||||
* disconnect, the HCI packet handler receives the disconnect complete event.
|
||||
*/
|
||||
|
||||
/* LISTING_START(GATTBrowserQueryHandler): Handling of the GATT client queries */
|
||||
static int search_services = 1;
|
||||
|
||||
static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||
UNUSED(packet_type);
|
||||
UNUSED(channel);
|
||||
UNUSED(size);
|
||||
|
||||
gatt_client_service_t service;
|
||||
gatt_client_characteristic_t characteristic;
|
||||
switch(hci_event_packet_get_type(packet)){
|
||||
case GATT_EVENT_SERVICE_QUERY_RESULT:\
|
||||
gatt_event_service_query_result_get_service(packet, &service);
|
||||
dump_service(&service);
|
||||
services[service_count++] = service;
|
||||
break;
|
||||
case GATT_EVENT_CHARACTERISTIC_QUERY_RESULT:
|
||||
gatt_event_characteristic_query_result_get_characteristic(packet, &characteristic);
|
||||
dump_characteristic(&characteristic);
|
||||
break;
|
||||
case GATT_EVENT_QUERY_COMPLETE:
|
||||
if (search_services){
|
||||
// GATT_EVENT_QUERY_COMPLETE of search services
|
||||
service_index = 0;
|
||||
printf("\nGATT browser - CHARACTERISTIC for SERVICE %s\n", uuid128_to_str(service.uuid128));
|
||||
search_services = 0;
|
||||
gatt_client_discover_characteristics_for_service(handle_gatt_client_event, connection_handler, &services[service_index]);
|
||||
} else {
|
||||
// GATT_EVENT_QUERY_COMPLETE of search characteristics
|
||||
if (service_index < service_count) {
|
||||
service = services[service_index++];
|
||||
printf("\nGATT browser - CHARACTERISTIC for SERVICE %s, [0x%04x-0x%04x]\n",
|
||||
uuid128_to_str(service.uuid128), service.start_group_handle, service.end_group_handle);
|
||||
gatt_client_discover_characteristics_for_service(handle_gatt_client_event, connection_handler, &service);
|
||||
break;
|
||||
}
|
||||
service_index = 0;
|
||||
gap_disconnect(connection_handler);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* LISTING_END */
|
||||
|
||||
#ifdef HAVE_POSIX_STDIN
|
||||
static void usage(const char *name){
|
||||
fprintf(stderr, "\nUsage: %s [-a|--address aa:bb:cc:dd:ee:ff]\n", name);
|
||||
fprintf(stderr, "If no argument is provided, GATT browser will start scanning and connect to the first found device.\nTo connect to a specific device use argument [-a].\n\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
int btstack_main(int argc, const char * argv[]);
|
||||
int btstack_main(int argc, const char * argv[]){
|
||||
|
||||
#ifdef HAVE_POSIX_STDIN
|
||||
int arg = 1;
|
||||
cmdline_addr_found = 0;
|
||||
|
||||
while (arg < argc) {
|
||||
if(!strcmp(argv[arg], "-a") || !strcmp(argv[arg], "--address")){
|
||||
arg++;
|
||||
cmdline_addr_found = sscanf_bd_addr(argv[arg], cmdline_addr);
|
||||
arg++;
|
||||
continue;
|
||||
}
|
||||
usage(argv[0]);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
UNUSED(argc);
|
||||
UNUSED(argv);
|
||||
#endif
|
||||
|
||||
gatt_client_setup();
|
||||
|
||||
// turn on!
|
||||
hci_power_control(HCI_POWER_ON);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* EXAMPLE_END */
|
||||
|
||||
|
14
port/esp32/main/hal_cpu.c
Normal file
14
port/esp32/main/hal_cpu.c
Normal file
@ -0,0 +1,14 @@
|
||||
#include "hal_cpu.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void hal_cpu_disable_irqs(void){
|
||||
//printf("hal_cpu_disable_irqs\n");
|
||||
}
|
||||
void hal_cpu_enable_irqs(void){
|
||||
//printf("hal_cpu_enable_irqs\n");
|
||||
}
|
||||
void hal_cpu_enable_irqs_and_sleep(void){
|
||||
//printf("hal_cpu_enable_irqs_and_sleep\n");
|
||||
}
|
28
port/esp32/main/hal_tick.c
Normal file
28
port/esp32/main/hal_tick.c
Normal file
@ -0,0 +1,28 @@
|
||||
#include "hal_tick.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
|
||||
static void dummy_handler(void){};
|
||||
|
||||
static void (*tick_handler)(void) = &dummy_handler;
|
||||
|
||||
void hal_tick_init(void){
|
||||
printf("hal_tick_init\n");
|
||||
}
|
||||
|
||||
void hal_tick_set_handler(void (*handler)(void)){
|
||||
printf("hal_tick_set_handler\n");
|
||||
if (handler == NULL){
|
||||
tick_handler = &dummy_handler;
|
||||
return;
|
||||
}
|
||||
tick_handler = handler;
|
||||
}
|
||||
|
||||
int hal_tick_get_tick_period_in_ms(void){
|
||||
printf("hal_tick_get_tick_period_in_ms\n");
|
||||
return portTICK_PERIOD_MS;
|
||||
}
|
50
port/esp32/main/hal_uart_dma.c
Normal file
50
port/esp32/main/hal_uart_dma.c
Normal file
@ -0,0 +1,50 @@
|
||||
#include "hal_uart_dma.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
|
||||
/* VHCI function interface */
|
||||
typedef struct vhci_host_callback {
|
||||
void (*notify_host_send_available)(void); /*!< callback used to notify that the host can send packet to controller */
|
||||
int (*notify_host_recv)(uint8_t *data, uint16_t len); /*!< callback used to notify that the controller has a packet to send to the host*/
|
||||
} vhci_host_callback_t;
|
||||
|
||||
extern bool API_vhci_host_check_send_available(void);
|
||||
extern void API_vhci_host_send_packet(uint8_t *data, uint16_t len);
|
||||
extern void API_vhci_host_register_callback(const vhci_host_callback_t *callback);
|
||||
|
||||
void hal_uart_dma_init(void){
|
||||
printf("hal_uart_dma_init\n");
|
||||
}
|
||||
|
||||
void hal_uart_dma_set_block_received( void (*block_handler)(void)){
|
||||
printf("hal_uart_dma_set_block_received\n");
|
||||
}
|
||||
|
||||
void hal_uart_dma_set_block_sent( void (*block_handler)(void)){
|
||||
printf("hal_uart_dma_set_block_sent\n");
|
||||
}
|
||||
|
||||
void hal_uart_dma_set_csr_irq_handler( void (*csr_irq_handler)(void)){
|
||||
printf("hal_uart_dma_set_csr_irq_handler\n");
|
||||
}
|
||||
|
||||
int hal_uart_dma_set_baud(uint32_t baud){
|
||||
printf("hal_uart_dma_set_baud\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
void hal_uart_dma_send_block(const uint8_t *buffer, uint16_t length){
|
||||
printf("hal_uart_dma_send_block\n");
|
||||
API_vhci_host_send_packet(buffer, length);
|
||||
}
|
||||
|
||||
void hal_uart_dma_receive_block(uint8_t *buffer, uint16_t len){
|
||||
printf("hal_uart_dma_receive_block\n");
|
||||
}
|
||||
|
||||
void hal_uart_dma_set_sleep(uint8_t sleep){
|
||||
printf("hal_uart_dma_set_sleep\n");
|
||||
}
|
121
port/esp32/main/main.c
Normal file
121
port/esp32/main/main.c
Normal file
@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (C) 2014 BlueKitchen GmbH
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holders nor the names of
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* 4. Any redistribution, use, or modification is done solely for
|
||||
* personal benefit and not for any commercial purpose or for
|
||||
* monetary gain.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
|
||||
* RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* Please inquire about commercial licensing options at
|
||||
* contact@bluekitchen-gmbh.com
|
||||
*
|
||||
*/
|
||||
|
||||
// *****************************************************************************
|
||||
//
|
||||
// spp_counter demo - it provides an SPP and sends a counter every second
|
||||
//
|
||||
// it doesn't use the LCD to get down to a minimal memory footprint
|
||||
//
|
||||
// *****************************************************************************
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "btstack_config.h"
|
||||
#include "btstack_event.h"
|
||||
#include "btstack_memory.h"
|
||||
#include "btstack_run_loop.h"
|
||||
#include "btstack_run_loop_embedded.h"
|
||||
//#include "classic/btstack_link_key_db.h"
|
||||
#include "hci.h"
|
||||
|
||||
static void hw_setup(void){
|
||||
// @TODO
|
||||
}
|
||||
|
||||
static hci_transport_config_uart_t config = {
|
||||
HCI_TRANSPORT_CONFIG_UART,
|
||||
115200,
|
||||
1000000, // main baudrate
|
||||
1, // flow control
|
||||
NULL,
|
||||
};
|
||||
|
||||
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||
|
||||
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||
if (packet_type != HCI_EVENT_PACKET) return;
|
||||
switch(hci_event_packet_get_type(packet)){
|
||||
case BTSTACK_EVENT_STATE:
|
||||
if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) return;
|
||||
printf("BTstack up and running.\n");
|
||||
break;
|
||||
case HCI_EVENT_COMMAND_COMPLETE:
|
||||
if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_local_version_information)){
|
||||
// @TODO
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btstack_setup(void){
|
||||
/// GET STARTED with BTstack ///
|
||||
btstack_memory_init();
|
||||
btstack_run_loop_init(btstack_run_loop_embedded_get_instance());
|
||||
|
||||
// init HCI
|
||||
hci_init(hci_transport_h4_instance(btstack_uart_block_embedded_instance()), &config);
|
||||
//hci_set_link_key_db(btstack_link_key_db_memory_instance()); // @TODO
|
||||
//hci_set_chipset(btstack_chipset_cc256x_instance()); // @TODO
|
||||
|
||||
// inform about BTstack state
|
||||
hci_event_callback_registration.callback = &packet_handler;
|
||||
hci_add_event_handler(&hci_event_callback_registration);
|
||||
}
|
||||
|
||||
extern int btstack_main(int argc, const char * argv[]);
|
||||
|
||||
// main
|
||||
int app_main(void){
|
||||
|
||||
hw_setup();
|
||||
|
||||
btstack_setup();
|
||||
btstack_main(0, NULL);
|
||||
|
||||
printf("Entering btstack run loop!\n");
|
||||
btstack_run_loop_execute();
|
||||
printf("Run loop exited...this is unexpected\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
211
port/esp32/sdkconfig
Normal file
211
port/esp32/sdkconfig
Normal file
@ -0,0 +1,211 @@
|
||||
#
|
||||
# Automatically generated file; DO NOT EDIT.
|
||||
# Espressif IoT Development Framework Configuration
|
||||
#
|
||||
|
||||
#
|
||||
# SDK tool configuration
|
||||
#
|
||||
CONFIG_TOOLPREFIX="xtensa-esp32-elf-"
|
||||
CONFIG_PYTHON="python"
|
||||
|
||||
#
|
||||
# Bootloader config
|
||||
#
|
||||
# CONFIG_LOG_BOOTLOADER_LEVEL_NONE is not set
|
||||
# CONFIG_LOG_BOOTLOADER_LEVEL_ERROR is not set
|
||||
CONFIG_LOG_BOOTLOADER_LEVEL_WARN=y
|
||||
# CONFIG_LOG_BOOTLOADER_LEVEL_INFO is not set
|
||||
# CONFIG_LOG_BOOTLOADER_LEVEL_DEBUG is not set
|
||||
# CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE is not set
|
||||
CONFIG_LOG_BOOTLOADER_LEVEL=2
|
||||
|
||||
#
|
||||
# Security features
|
||||
#
|
||||
# CONFIG_SECURE_BOOT_ENABLED is not set
|
||||
# CONFIG_FLASH_ENCRYPTION_ENABLED is not set
|
||||
|
||||
#
|
||||
# Serial flasher config
|
||||
#
|
||||
CONFIG_ESPTOOLPY_PORT="/dev/tty.usbserial-141B"
|
||||
# CONFIG_ESPTOOLPY_BAUD_115200B is not set
|
||||
# CONFIG_ESPTOOLPY_BAUD_230400B is not set
|
||||
# CONFIG_ESPTOOLPY_BAUD_921600B is not set
|
||||
CONFIG_ESPTOOLPY_BAUD_2MB=y
|
||||
# CONFIG_ESPTOOLPY_BAUD_OTHER is not set
|
||||
CONFIG_ESPTOOLPY_BAUD_OTHER_VAL=115200
|
||||
CONFIG_ESPTOOLPY_BAUD=2000000
|
||||
# CONFIG_ESPTOOLPY_COMPRESSED is not set
|
||||
# CONFIG_ESPTOOLPY_FLASHMODE_QIO is not set
|
||||
# CONFIG_ESPTOOLPY_FLASHMODE_QOUT is not set
|
||||
CONFIG_ESPTOOLPY_FLASHMODE_DIO=y
|
||||
# CONFIG_ESPTOOLPY_FLASHMODE_DOUT is not set
|
||||
CONFIG_ESPTOOLPY_FLASHMODE="dio"
|
||||
# CONFIG_ESPTOOLPY_FLASHFREQ_80M is not set
|
||||
CONFIG_ESPTOOLPY_FLASHFREQ_40M=y
|
||||
# CONFIG_ESPTOOLPY_FLASHFREQ_26M is not set
|
||||
# CONFIG_ESPTOOLPY_FLASHFREQ_20M is not set
|
||||
CONFIG_ESPTOOLPY_FLASHFREQ="40m"
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_4MB is not set
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_8MB is not set
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE="2MB"
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y
|
||||
CONFIG_ESPTOOLPY_BEFORE_RESET=y
|
||||
# CONFIG_ESPTOOLPY_BEFORE_NORESET is not set
|
||||
# CONFIG_ESPTOOLPY_BEFORE_ESP32R0 is not set
|
||||
CONFIG_ESPTOOLPY_BEFORE="default_reset"
|
||||
CONFIG_ESPTOOLPY_AFTER_RESET=y
|
||||
# CONFIG_ESPTOOLPY_AFTER_NORESET is not set
|
||||
CONFIG_ESPTOOLPY_AFTER="hard_reset"
|
||||
# CONFIG_MONITOR_BAUD_9600B is not set
|
||||
# CONFIG_MONITOR_BAUD_57600B is not set
|
||||
CONFIG_MONITOR_BAUD_115200B=y
|
||||
# CONFIG_MONITOR_BAUD_230400B is not set
|
||||
# CONFIG_MONITOR_BAUD_921600B is not set
|
||||
# CONFIG_MONITOR_BAUD_2MB is not set
|
||||
# CONFIG_MONITOR_BAUD_OTHER is not set
|
||||
CONFIG_MONITOR_BAUD_OTHER_VAL=115200
|
||||
CONFIG_MONITOR_BAUD=115200
|
||||
|
||||
#
|
||||
# Partition Table
|
||||
#
|
||||
CONFIG_PARTITION_TABLE_SINGLE_APP=y
|
||||
# CONFIG_PARTITION_TABLE_TWO_OTA is not set
|
||||
# CONFIG_PARTITION_TABLE_CUSTOM is not set
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET=0x10000
|
||||
CONFIG_PARTITION_TABLE_FILENAME="partitions_singleapp.csv"
|
||||
CONFIG_APP_OFFSET=0x10000
|
||||
CONFIG_PHY_DATA_OFFSET=0xf000
|
||||
CONFIG_OPTIMIZATION_LEVEL_DEBUG=y
|
||||
# CONFIG_OPTIMIZATION_LEVEL_RELEASE is not set
|
||||
|
||||
#
|
||||
# Component config
|
||||
#
|
||||
# CONFIG_BT_ENABLED is not set
|
||||
CONFIG_BT_RESERVE_DRAM=0
|
||||
|
||||
#
|
||||
# ESP32-specific
|
||||
#
|
||||
# CONFIG_ESP32_DEFAULT_CPU_FREQ_80 is not set
|
||||
# CONFIG_ESP32_DEFAULT_CPU_FREQ_160 is not set
|
||||
CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y
|
||||
CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=240
|
||||
CONFIG_MEMMAP_SMP=y
|
||||
# CONFIG_MEMMAP_TRACEMEM is not set
|
||||
CONFIG_TRACEMEM_RESERVE_DRAM=0x0
|
||||
# CONFIG_ESP32_ENABLE_COREDUMP_TO_FLASH is not set
|
||||
# CONFIG_ESP32_ENABLE_COREDUMP_TO_UART is not set
|
||||
CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE=y
|
||||
# CONFIG_ESP32_ENABLE_COREDUMP is not set
|
||||
CONFIG_SYSTEM_EVENT_QUEUE_SIZE=32
|
||||
CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=2048
|
||||
CONFIG_MAIN_TASK_STACK_SIZE=4096
|
||||
CONFIG_NEWLIB_STDOUT_ADDCR=y
|
||||
# CONFIG_NEWLIB_NANO_FORMAT is not set
|
||||
CONFIG_CONSOLE_UART_DEFAULT=y
|
||||
# CONFIG_CONSOLE_UART_CUSTOM is not set
|
||||
# CONFIG_CONSOLE_UART_NONE is not set
|
||||
CONFIG_CONSOLE_UART_NUM=0
|
||||
CONFIG_CONSOLE_UART_BAUDRATE=115200
|
||||
# CONFIG_ULP_COPROC_ENABLED is not set
|
||||
CONFIG_ULP_COPROC_RESERVE_MEM=0
|
||||
# CONFIG_ESP32_PANIC_PRINT_HALT is not set
|
||||
CONFIG_ESP32_PANIC_PRINT_REBOOT=y
|
||||
# CONFIG_ESP32_PANIC_SILENT_REBOOT is not set
|
||||
# CONFIG_ESP32_PANIC_GDBSTUB is not set
|
||||
CONFIG_ESP32_DEBUG_OCDAWARE=y
|
||||
CONFIG_INT_WDT=y
|
||||
CONFIG_INT_WDT_TIMEOUT_MS=300
|
||||
CONFIG_TASK_WDT=y
|
||||
# CONFIG_TASK_WDT_PANIC is not set
|
||||
CONFIG_TASK_WDT_TIMEOUT_S=5
|
||||
CONFIG_TASK_WDT_CHECK_IDLE_TASK=y
|
||||
# CONFIG_ESP32_TIME_SYSCALL_USE_RTC is not set
|
||||
CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1=y
|
||||
# CONFIG_ESP32_TIME_SYSCALL_USE_FRC1 is not set
|
||||
# CONFIG_ESP32_TIME_SYSCALL_USE_NONE is not set
|
||||
CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC=y
|
||||
CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY=0
|
||||
# CONFIG_WIFI_ENABLED is not set
|
||||
# CONFIG_ETHERNET is not set
|
||||
|
||||
#
|
||||
# FreeRTOS
|
||||
#
|
||||
CONFIG_FREERTOS_UNICORE=y
|
||||
CONFIG_FREERTOS_CORETIMER_0=y
|
||||
# CONFIG_FREERTOS_CORETIMER_1 is not set
|
||||
CONFIG_FREERTOS_HZ=1000
|
||||
CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=y
|
||||
# CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE is not set
|
||||
CONFIG_FREERTOS_CHECK_STACKOVERFLOW_PTRVAL=y
|
||||
# CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY is not set
|
||||
CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=3
|
||||
CONFIG_FREERTOS_ASSERT_FAIL_ABORT=y
|
||||
# CONFIG_FREERTOS_ASSERT_FAIL_PRINT_CONTINUE is not set
|
||||
# CONFIG_FREERTOS_ASSERT_DISABLE is not set
|
||||
CONFIG_FREERTOS_BREAK_ON_SCHEDULER_START_JTAG=y
|
||||
# CONFIG_ENABLE_MEMORY_DEBUG is not set
|
||||
CONFIG_FREERTOS_ISR_STACKSIZE=1536
|
||||
# CONFIG_FREERTOS_LEGACY_HOOKS is not set
|
||||
# CONFIG_FREERTOS_DEBUG_INTERNALS is not set
|
||||
|
||||
#
|
||||
# Log output
|
||||
#
|
||||
# CONFIG_LOG_DEFAULT_LEVEL_NONE is not set
|
||||
# CONFIG_LOG_DEFAULT_LEVEL_ERROR is not set
|
||||
# CONFIG_LOG_DEFAULT_LEVEL_WARN is not set
|
||||
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
|
||||
# CONFIG_LOG_DEFAULT_LEVEL_DEBUG is not set
|
||||
# CONFIG_LOG_DEFAULT_LEVEL_VERBOSE is not set
|
||||
CONFIG_LOG_DEFAULT_LEVEL=3
|
||||
CONFIG_LOG_COLORS=y
|
||||
|
||||
#
|
||||
# LWIP
|
||||
#
|
||||
# CONFIG_L2_TO_L3_COPY is not set
|
||||
CONFIG_LWIP_MAX_SOCKETS=4
|
||||
CONFIG_LWIP_THREAD_LOCAL_STORAGE_INDEX=0
|
||||
# CONFIG_LWIP_SO_REUSE is not set
|
||||
# CONFIG_LWIP_SO_RCVBUF is not set
|
||||
CONFIG_LWIP_DHCP_MAX_NTP_SERVERS=1
|
||||
# CONFIG_LWIP_IP_FRAG is not set
|
||||
# CONFIG_LWIP_IP_REASSEMBLY is not set
|
||||
CONFIG_TCP_MAXRTX=12
|
||||
CONFIG_TCP_SYNMAXRTX=6
|
||||
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
|
||||
|
||||
#
|
||||
# mbedTLS
|
||||
#
|
||||
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=16384
|
||||
# CONFIG_MBEDTLS_DEBUG is not set
|
||||
CONFIG_MBEDTLS_HARDWARE_AES=y
|
||||
CONFIG_MBEDTLS_HARDWARE_MPI=y
|
||||
CONFIG_MBEDTLS_MPI_USE_INTERRUPT=y
|
||||
CONFIG_MBEDTLS_HARDWARE_SHA=y
|
||||
CONFIG_MBEDTLS_HAVE_TIME=y
|
||||
# CONFIG_MBEDTLS_HAVE_TIME_DATE is not set
|
||||
|
||||
#
|
||||
# OpenSSL
|
||||
#
|
||||
# CONFIG_OPENSSL_DEBUG is not set
|
||||
CONFIG_OPENSSL_ASSERT_DO_NOTHING=y
|
||||
# CONFIG_OPENSSL_ASSERT_EXIT is not set
|
||||
|
||||
#
|
||||
# SPI Flash driver
|
||||
#
|
||||
# CONFIG_SPI_FLASH_ENABLE_COUNTERS is not set
|
Loading…
x
Reference in New Issue
Block a user