mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-14 01:27:41 +00:00
max32630-fthr: support btstack_stdin
This commit is contained in:
parent
7dabc299c3
commit
84e268121e
@ -119,6 +119,7 @@ PROJ_CFLAGS += \
|
||||
-I${BTSTACK_ROOT}/example \
|
||||
-I${BTSTACK_ROOT}/3rd-party/bluedroid/decoder/include \
|
||||
-I${BTSTACK_ROOT}/3rd-party/bluedroid/encoder/include \
|
||||
-I${BTSTACK_ROOT}/3rd-party/micro-ecc \
|
||||
-I${BTSTACK_ROOT}/3rd-party/hxcmod-player \
|
||||
|
||||
|
||||
@ -141,8 +142,9 @@ COMMON = \
|
||||
hci_cmd.o \
|
||||
hci_dump.o \
|
||||
btstack_uart_block_embedded.o \
|
||||
hal_flash_bank_mxc.o \
|
||||
btstack_tlv_flash_bank.o \
|
||||
hal_flash_bank_mxc.o \
|
||||
btstack_tlv_flash_bank.o \
|
||||
btstack_stdin_embedded.o \
|
||||
|
||||
CLASSIC = \
|
||||
btstack_link_key_db_tlv.o \
|
||||
@ -162,7 +164,8 @@ BLE = \
|
||||
ancs_client.o \
|
||||
gatt_client.o \
|
||||
hid_device.o \
|
||||
battery_service_server.o
|
||||
battery_service_server.o \
|
||||
uECC.o \
|
||||
|
||||
AVDTP += \
|
||||
avdtp_util.c \
|
||||
@ -175,6 +178,8 @@ AVDTP += \
|
||||
a2dp_sink.c \
|
||||
btstack_ring_buffer.c \
|
||||
avrcp.c \
|
||||
avrcp_target.c \
|
||||
avrcp_controller.c \
|
||||
|
||||
HFP_OBJ += sco_demo_util.o btstack_ring_buffer.o hfp.o hfp_gsm_model.o hfp_ag.o hfp_hf.o
|
||||
|
||||
|
@ -7,17 +7,17 @@
|
||||
// Port related features
|
||||
#define HAVE_INIT_SCRIPT
|
||||
#define HAVE_EMBEDDED_TIME_MS
|
||||
// BTstack features that can be enabled
|
||||
#define HAVE_BTSTACK_STDIN
|
||||
|
||||
// BTstack features that can be enabled
|
||||
#define ENABLE_BLE
|
||||
#define ENABLE_CLASSIC
|
||||
|
||||
#define ENABLE_LE_PERIPHERAL
|
||||
#define ENABLE_LE_CENTRAL
|
||||
//#define ENABLE_LOG_DEBUG
|
||||
#define ENABLE_LOG_ERROR
|
||||
#define ENABLE_LOG_INFO
|
||||
// #define ENABLE_LE_SECURE_CONNECTIONS
|
||||
#define ENABLE_LE_SECURE_CONNECTIONS
|
||||
//#define ENABLE_LOG_DEBUG
|
||||
|
||||
// BTstack configuration. buffers, sizes, ...
|
||||
#define HCI_ACL_PAYLOAD_SIZE 1021
|
||||
|
@ -32,19 +32,26 @@
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#include "hal_tick.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
// MXC
|
||||
#include "lp.h"
|
||||
#include "uart.h"
|
||||
#include "board.h"
|
||||
#include "led.h"
|
||||
#include "btstack_debug.h"
|
||||
|
||||
// BTstack Core
|
||||
#include "btstack_debug.h"
|
||||
#include "btstack.h"
|
||||
#include "btstack_config.h"
|
||||
#include "btstack_run_loop_embedded.h"
|
||||
#include "btstack_chipset_cc256x.h"
|
||||
|
||||
// BTstack HALs
|
||||
#include "hal_tick.h"
|
||||
#include "hal_stdin.h"
|
||||
|
||||
#include "btstack_port.h"
|
||||
|
||||
#define CC256X_UART_ID 0
|
||||
@ -84,7 +91,8 @@ void hal_cpu_enable_irqs(void)
|
||||
}
|
||||
void hal_cpu_enable_irqs_and_sleep(void)
|
||||
{
|
||||
|
||||
__enable_irq();
|
||||
/* TODO: Add sleep mode */
|
||||
}
|
||||
|
||||
void hal_uart_dma_send_block(const uint8_t *buffer, uint16_t len)
|
||||
@ -283,6 +291,83 @@ void hal_led_toggle(void){
|
||||
LED_Toggle(LED_BLUE);
|
||||
}
|
||||
|
||||
// hal_stdin.h
|
||||
static uint8_t stdin_buffer[1];
|
||||
static void (*stdin_handler)(char c);
|
||||
|
||||
static uart_req_t uart_byte_request;
|
||||
|
||||
static void uart_rx_handler(uart_req_t *request, int error)
|
||||
{
|
||||
if (stdin_handler){
|
||||
(*stdin_handler)(stdin_buffer[0]);
|
||||
}
|
||||
UART_ReadAsync(MXC_UART_GET_UART(CONSOLE_UART), &uart_byte_request);
|
||||
}
|
||||
|
||||
void hal_stdin_setup(void (*handler)(char c)){
|
||||
// set handler
|
||||
stdin_handler = handler;
|
||||
|
||||
/* set input handler */
|
||||
uart_byte_request.callback = uart_rx_handler;
|
||||
uart_byte_request.data = stdin_buffer;
|
||||
uart_byte_request.len = sizeof(uint8_t);
|
||||
UART_ReadAsync(MXC_UART_GET_UART(CONSOLE_UART), &uart_byte_request);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
#include "btstack_stdin.h"
|
||||
|
||||
static btstack_data_source_t stdin_data_source;
|
||||
static void (*stdin_handler)(char c);
|
||||
|
||||
static uart_req_t uart_byte_request;
|
||||
static volatile int stdin_character_received;
|
||||
static uint8_t stdin_buffer[1];
|
||||
|
||||
static void stdin_rx_complete(void) {
|
||||
stdin_character_received = 1;
|
||||
}
|
||||
|
||||
static void uart_rx_handler(uart_req_t *request, int error)
|
||||
{
|
||||
stdin_rx_complete();
|
||||
}
|
||||
|
||||
static void stdin_process(struct btstack_data_source *ds, btstack_data_source_callback_type_t callback_type){
|
||||
if (!stdin_character_received) return;
|
||||
if (stdin_handler){
|
||||
(*stdin_handler)(stdin_buffer[0]);
|
||||
}
|
||||
stdin_character_received = 0;
|
||||
UART_ReadAsync(MXC_UART_GET_UART(CONSOLE_UART), &uart_byte_request);
|
||||
}
|
||||
|
||||
static void btstack_stdin_handler(char c){
|
||||
stdin_character_received = 1;
|
||||
btstack_run_loop_embedded_trigger();
|
||||
printf("Received: %c\n", c);
|
||||
}
|
||||
|
||||
void btstack_stdin_setup(void (*handler)(char c)){
|
||||
// set handler
|
||||
stdin_handler = handler;
|
||||
|
||||
// set up polling data_source
|
||||
btstack_run_loop_set_data_source_handler(&stdin_data_source, &stdin_process);
|
||||
btstack_run_loop_enable_data_source_callbacks(&stdin_data_source, DATA_SOURCE_CALLBACK_POLL);
|
||||
btstack_run_loop_add_data_source(&stdin_data_source);
|
||||
|
||||
/* set input handler */
|
||||
uart_byte_request.callback = uart_rx_handler;
|
||||
uart_byte_request.data = stdin_buffer;
|
||||
uart_byte_request.len = sizeof(uint8_t);
|
||||
UART_ReadAsync(MXC_UART_GET_UART(CONSOLE_UART), &uart_byte_request);
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "hal_flash_bank_mxc.h"
|
||||
#include "btstack_tlv.h"
|
||||
#include "btstack_tlv_flash_bank.h"
|
||||
@ -296,6 +381,8 @@ void hal_led_toggle(void){
|
||||
static hal_flash_bank_mxc_t hal_flash_bank_context;
|
||||
static btstack_tlv_flash_bank_t btstack_tlv_flash_bank_context;
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
int bluetooth_main(void)
|
||||
{
|
||||
LED_Off(LED_GREEN);
|
||||
@ -307,6 +394,9 @@ int bluetooth_main(void)
|
||||
btstack_memory_init();
|
||||
btstack_run_loop_init(btstack_run_loop_embedded_get_instance());
|
||||
|
||||
// enable packet logger
|
||||
//hci_dump_open(NULL, HCI_DUMP_STDOUT);
|
||||
|
||||
/* Init HCI */
|
||||
const hci_transport_t * transport = hci_transport_h4_instance(btstack_uart_block_embedded_instance());
|
||||
hci_init(transport, &config);
|
||||
@ -314,12 +404,12 @@ int bluetooth_main(void)
|
||||
|
||||
// setup TLV Flash Bank implementation
|
||||
const hal_flash_bank_t * hal_flash_bank_impl = hal_flash_bank_mxc_init_instance(
|
||||
&hal_flash_bank_context,
|
||||
HAL_FLASH_BANK_SIZE,
|
||||
&hal_flash_bank_context,
|
||||
HAL_FLASH_BANK_SIZE,
|
||||
HAL_FLASH_BANK_0_ADDR,
|
||||
HAL_FLASH_BANK_1_ADDR);
|
||||
const btstack_tlv_t * btstack_tlv_impl = btstack_tlv_flash_bank_init_instance(
|
||||
&btstack_tlv_flash_bank_context,
|
||||
&btstack_tlv_flash_bank_context,
|
||||
hal_flash_bank_impl,
|
||||
&hal_flash_bank_context);
|
||||
|
||||
@ -332,6 +422,5 @@ int bluetooth_main(void)
|
||||
|
||||
// go
|
||||
btstack_main(0, (void *)NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user