mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-21 03:40:47 +00:00
restructured eZ430-RF2560 example into example/ez430-rf2560
This commit is contained in:
parent
4b65c57fb5
commit
193e9b112e
@ -1,77 +0,0 @@
|
||||
#
|
||||
# Makefile for eZ430-RF2560
|
||||
#
|
||||
# mspgcc is used: http://sourceforge.net/apps/mediawiki/mspgcc/index.php?title=MSPGCC_Wiki
|
||||
#
|
||||
|
||||
BTSTACK_ROOT = ../..
|
||||
|
||||
MCU = msp430bt5190
|
||||
|
||||
CC = msp430-gcc
|
||||
CFLAGS = -mmcu=${MCU} -Os -Wall -fno-toplevel-reorder -I. -I../src -I../firmware -I${BTSTACK_ROOT} -I${BTSTACK_ROOT}/chipset-cc256x -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include
|
||||
LDFLAGS = -mmcu=${MCU}
|
||||
|
||||
CORE = \
|
||||
../src/hal_tick.c \
|
||||
../src/hal_cpu.c \
|
||||
../firmware/hal_board.c \
|
||||
../firmware/hal_compat.c \
|
||||
../firmware/hal_usb.c \
|
||||
${BTSTACK_ROOT}/src/btstack_memory.c \
|
||||
${BTSTACK_ROOT}/src/linked_list.c \
|
||||
${BTSTACK_ROOT}/src/memory_pool.c \
|
||||
${BTSTACK_ROOT}/src/run_loop.c \
|
||||
${BTSTACK_ROOT}/src/run_loop_embedded.c
|
||||
|
||||
COMMON = \
|
||||
../src/hal_uart_dma.c \
|
||||
${BTSTACK_ROOT}/chipset-cc256x/bt_control_cc256x.c \
|
||||
${BTSTACK_ROOT}/chipset-cc256x/bluetooth_init_cc2564_2.5.c \
|
||||
${BTSTACK_ROOT}/src/hci.c \
|
||||
${BTSTACK_ROOT}/src/hci_cmds.c \
|
||||
${BTSTACK_ROOT}/src/hci_dump.c \
|
||||
${BTSTACK_ROOT}/src/hci_transport_h4_ehcill_dma.c \
|
||||
${BTSTACK_ROOT}/src/l2cap.c \
|
||||
${BTSTACK_ROOT}/src/l2cap_signaling.c \
|
||||
${BTSTACK_ROOT}/src/remote_device_db_memory.c \
|
||||
${BTSTACK_ROOT}/src/rfcomm.c \
|
||||
${BTSTACK_ROOT}/src/sdp.c \
|
||||
${BTSTACK_ROOT}/src/sdp_util.c \
|
||||
${BTSTACK_ROOT}/src/utils.c \
|
||||
|
||||
CORE_OBJ = $(CORE:.c=.o)
|
||||
COMMON_OBJ = $(COMMON:.c=.o)
|
||||
|
||||
# create .hex file from .out
|
||||
%.hex: %.out
|
||||
msp430-objcopy -O ihex $< $@
|
||||
|
||||
# create firmware image from common objects and example source file
|
||||
|
||||
all: led_counter.hex spp_counter.hex spp_flowcontrol.hex
|
||||
# missing: spp_accel.hex
|
||||
|
||||
led_counter.out: ${CORE_OBJ} led_counter.o
|
||||
${CC} $^ ${LDFLAGS} -o $@
|
||||
|
||||
spp_accel.out: ${CORE_OBJ} ${COMMON_OBJ} spp_accel.o ../firmware/hal_adc.o
|
||||
echo "accelerometer code not adapted yet for eZ430-RF2560 target"
|
||||
${CC} $^ ${LDFLAGS} -o $@
|
||||
|
||||
spp_counter.out: ${CORE_OBJ} ${COMMON_OBJ} spp_counter.o ../firmware/hal_adc.o
|
||||
${CC} $^ ${LDFLAGS} -o $@
|
||||
|
||||
spp_flowcontrol.out: ${CORE_OBJ} ${COMMON_OBJ} spp_flowcontrol.o ../firmware/hal_adc.o
|
||||
${CC} $^ ${LDFLAGS} -o $@
|
||||
|
||||
clean:
|
||||
rm -f $ *.o *.out *.hex ../driver/*.o ../../src/*.o ../src/*.o ../firmware/*.o ${BTSTACK_ROOT}/chipset-cc256x/*.o
|
||||
|
||||
size: all
|
||||
msp430-size ../firmware/*.o
|
||||
msp430-size ../src/*.o
|
||||
msp430-size ${BTSTACK_ROOT}/chipset-cc256x/*.o
|
||||
msp430-size ${BTSTACK_ROOT}/src/*.o
|
||||
msp430-size *.o
|
||||
msp430-size *.out
|
@ -1,201 +0,0 @@
|
||||
// *****************************************************************************
|
||||
//
|
||||
// spp_counter demo - it provides a SPP and sends a counter every second
|
||||
//
|
||||
// it doesn't use the LCD to get down to a minimal memory footpring
|
||||
//
|
||||
// *****************************************************************************
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <msp430x54x.h>
|
||||
|
||||
#include "bt_control_cc256x.h"
|
||||
#include "hal_board.h"
|
||||
#include "hal_compat.h"
|
||||
#include "hal_usb.h"
|
||||
|
||||
#include <btstack/hci_cmds.h>
|
||||
#include <btstack/run_loop.h>
|
||||
#include <btstack/sdp_util.h>
|
||||
|
||||
#include "hci.h"
|
||||
#include "l2cap.h"
|
||||
#include "btstack_memory.h"
|
||||
#include "remote_device_db.h"
|
||||
#include "rfcomm.h"
|
||||
#include "sdp.h"
|
||||
#include "btstack-config.h"
|
||||
|
||||
#define HEARTBEAT_PERIOD_MS 500
|
||||
|
||||
static uint8_t rfcomm_channel_nr = 1;
|
||||
static uint16_t rfcomm_channel_id;
|
||||
static uint8_t rfcomm_send_credit = 0;
|
||||
static uint8_t spp_service_buffer[100];
|
||||
|
||||
// Bluetooth logic
|
||||
static void packet_handler (void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||
bd_addr_t event_addr;
|
||||
uint8_t rfcomm_channel_nr;
|
||||
uint16_t mtu;
|
||||
|
||||
switch (packet_type) {
|
||||
case HCI_EVENT_PACKET:
|
||||
switch (packet[0]) {
|
||||
|
||||
case BTSTACK_EVENT_STATE:
|
||||
// bt stack activated, get started - set local name
|
||||
if (packet[2] == HCI_STATE_WORKING) {
|
||||
hci_send_cmd(&hci_write_local_name, "BlueMSP-Demo");
|
||||
}
|
||||
break;
|
||||
|
||||
case HCI_EVENT_COMMAND_COMPLETE:
|
||||
if (COMMAND_COMPLETE_EVENT(packet, hci_read_bd_addr)){
|
||||
bt_flip_addr(event_addr, &packet[6]);
|
||||
printf("BD-ADDR: %s\n\r", bd_addr_to_str(event_addr));
|
||||
break;
|
||||
}
|
||||
if (COMMAND_COMPLETE_EVENT(packet, hci_write_local_name)){
|
||||
hci_discoverable_control(1);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case HCI_EVENT_LINK_KEY_REQUEST:
|
||||
// deny link key request
|
||||
printf("Link key request\n\r");
|
||||
bt_flip_addr(event_addr, &packet[2]);
|
||||
hci_send_cmd(&hci_link_key_request_negative_reply, &event_addr);
|
||||
break;
|
||||
|
||||
case HCI_EVENT_PIN_CODE_REQUEST:
|
||||
// inform about pin code request
|
||||
printf("Pin code request - using '0000'\n\r");
|
||||
bt_flip_addr(event_addr, &packet[2]);
|
||||
hci_send_cmd(&hci_pin_code_request_reply, &event_addr, 4, "0000");
|
||||
break;
|
||||
|
||||
case RFCOMM_EVENT_INCOMING_CONNECTION:
|
||||
// data: event (8), len(8), address(48), channel (8), rfcomm_cid (16)
|
||||
bt_flip_addr(event_addr, &packet[2]);
|
||||
rfcomm_channel_nr = packet[8];
|
||||
rfcomm_channel_id = READ_BT_16(packet, 9);
|
||||
printf("RFCOMM channel %u requested for %s\n\r", rfcomm_channel_nr, bd_addr_to_str(event_addr));
|
||||
rfcomm_accept_connection_internal(rfcomm_channel_id);
|
||||
break;
|
||||
|
||||
case RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE:
|
||||
// data: event(8), len(8), status (8), address (48), server channel(8), rfcomm_cid(16), max frame size(16)
|
||||
if (packet[2]) {
|
||||
printf("RFCOMM channel open failed, status %u\n\r", packet[2]);
|
||||
} else {
|
||||
rfcomm_channel_id = READ_BT_16(packet, 12);
|
||||
mtu = READ_BT_16(packet, 14);
|
||||
printf("\n\rRFCOMM channel open succeeded. New RFCOMM Channel ID %u, max frame size %u\n\r", rfcomm_channel_id, mtu);
|
||||
}
|
||||
break;
|
||||
|
||||
case RFCOMM_EVENT_CHANNEL_CLOSED:
|
||||
rfcomm_channel_id = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case RFCOMM_DATA_PACKET:
|
||||
// hack: truncate data (we know that the packet is at least on byte bigger
|
||||
packet[size] = 0;
|
||||
puts( (const char *) packet);
|
||||
rfcomm_send_credit = 1;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void heartbeat_handler(struct timer *ts){
|
||||
if (rfcomm_send_credit){
|
||||
rfcomm_grant_credits(rfcomm_channel_id, 1);
|
||||
rfcomm_send_credit = 0;
|
||||
}
|
||||
run_loop_set_timer(ts, HEARTBEAT_PERIOD_MS);
|
||||
run_loop_add_timer(ts);
|
||||
}
|
||||
|
||||
// main
|
||||
int main(void)
|
||||
{
|
||||
// stop watchdog timer
|
||||
WDTCTL = WDTPW + WDTHOLD;
|
||||
|
||||
//Initialize clock and peripherals
|
||||
halBoardInit();
|
||||
halBoardStartXT1();
|
||||
halBoardSetSystemClock(SYSCLK_16MHZ);
|
||||
|
||||
// init debug UART
|
||||
halUsbInit();
|
||||
|
||||
// init LEDs
|
||||
LED_PORT_OUT |= LED_1 | LED_2;
|
||||
LED_PORT_DIR |= LED_1 | LED_2;
|
||||
|
||||
/// GET STARTED with BTstack ///
|
||||
btstack_memory_init();
|
||||
run_loop_init(RUN_LOOP_EMBEDDED);
|
||||
|
||||
// init HCI
|
||||
hci_transport_t * transport = hci_transport_h4_dma_instance();
|
||||
bt_control_t * control = bt_control_cc256x_instance();
|
||||
hci_uart_config_t * config = hci_uart_config_cc256x_instance();
|
||||
remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory;
|
||||
hci_init(transport, config, control, remote_db);
|
||||
|
||||
// use eHCILL
|
||||
bt_control_cc256x_enable_ehcill(1);
|
||||
|
||||
// init L2CAP
|
||||
l2cap_init();
|
||||
l2cap_register_packet_handler(packet_handler);
|
||||
|
||||
// init RFCOMM
|
||||
rfcomm_init();
|
||||
rfcomm_register_packet_handler(packet_handler);
|
||||
rfcomm_register_service_with_initial_credits_internal(NULL, rfcomm_channel_nr, 100, 1); // reserved channel, mtu=100, 1 credit
|
||||
|
||||
// init SDP, create record for SPP and register with SDP
|
||||
sdp_init();
|
||||
memset(spp_service_buffer, 0, sizeof(spp_service_buffer));
|
||||
service_record_item_t * service_record_item = (service_record_item_t *) spp_service_buffer;
|
||||
sdp_create_spp_service( (uint8_t*) &service_record_item->service_record, 1, "SPP Counter");
|
||||
printf("SDP service buffer size: %u\n\r", (uint16_t) (sizeof(service_record_item_t) + de_get_len((uint8_t*) &service_record_item->service_record)));
|
||||
sdp_register_service_internal(NULL, service_record_item);
|
||||
|
||||
// set one-shot timer
|
||||
timer_source_t heartbeat;
|
||||
heartbeat.process = &heartbeat_handler;
|
||||
run_loop_set_timer(&heartbeat, HEARTBEAT_PERIOD_MS);
|
||||
run_loop_add_timer(&heartbeat);
|
||||
|
||||
|
||||
puts("SPP FlowControl Demo: simulates processing on received data...\n\r");
|
||||
|
||||
// ready - enable irq used in h4 task
|
||||
__enable_interrupt();
|
||||
|
||||
// turn on!
|
||||
hci_power_control(HCI_POWER_ON);
|
||||
|
||||
// go!
|
||||
run_loop_execute();
|
||||
|
||||
// happy compiler!
|
||||
return 0;
|
||||
}
|
||||
|
148
platforms/ez430-rf2560/Makefile
Normal file
148
platforms/ez430-rf2560/Makefile
Normal file
@ -0,0 +1,148 @@
|
||||
# Makefile for MSP-EXP430F5438 board with CC2560B/CC2564B/CC2567 modules
|
||||
#
|
||||
# Please check instructions at https://code.google.com/p/btstack/wiki/CC256x on downloading
|
||||
# and converting the init scripts for use with BTstack
|
||||
#
|
||||
# mspgcc is used: http://sourceforge.net/apps/mediawiki/mspgcc/index.php?title=MSPGCC_Wiki
|
||||
#
|
||||
|
||||
# init scripts
|
||||
CC2560B = bluetooth_init_cc2560B_1.0_BT_Spec_4.1.o
|
||||
CC2564B = bluetooth_init_cc2564B_1.0_BT_Spec_4.1.o
|
||||
CC2567 = CC256x_BT_Service_Pack_2.8_ANT_1.16.o
|
||||
|
||||
BTSTACK_ROOT = ../..
|
||||
VPATH += example
|
||||
VPATH += firmware
|
||||
VPATH += src
|
||||
VPATH += $(BTSTACK_ROOT)/ble
|
||||
VPATH += $(BTSTACK_ROOT)/chipset-cc256x
|
||||
VPATH += $(BTSTACK_ROOT)/example/embedded
|
||||
VPATH += $(BTSTACK_ROOT)/src
|
||||
|
||||
CC = msp430-gcc
|
||||
CFLAGS = -mmcu=msp430f5438a -Os -Wall -fno-toplevel-reorder
|
||||
CFLAGS += \
|
||||
-I. \
|
||||
-I src \
|
||||
-I firmware \
|
||||
-I$(BTSTACK_ROOT)/include \
|
||||
-I$(BTSTACK_ROOT)/src \
|
||||
-I$(BTSTACK_ROOT)/ble \
|
||||
-I$(BTSTACK_ROOT)/chipset-cc256x \
|
||||
|
||||
LDFLAGS = -mmcu=msp430f5438a
|
||||
|
||||
CORE = \
|
||||
hal_tick.c \
|
||||
hal_cpu.c \
|
||||
hal_board.c \
|
||||
hal_compat.c \
|
||||
hal_usb.c \
|
||||
hci_dump.c \
|
||||
btstack_memory.c \
|
||||
linked_list.c \
|
||||
memory_pool.c \
|
||||
run_loop.c \
|
||||
run_loop_embedded.c \
|
||||
utils.c \
|
||||
main.c \
|
||||
|
||||
COMMON = \
|
||||
hal_uart_dma.c \
|
||||
bt_control_cc256x.c \
|
||||
hci.c \
|
||||
hci_cmds.c \
|
||||
hci_transport_h4_ehcill_dma.c \
|
||||
remote_device_db_memory.c \
|
||||
|
||||
SPP = \
|
||||
l2cap.c \
|
||||
l2cap_signaling.c \
|
||||
rfcomm.c \
|
||||
sdp_util.c \
|
||||
|
||||
SDP_CLIENT += \
|
||||
sdp_client.o \
|
||||
sdp_parser.o \
|
||||
sdp_query_util.o \
|
||||
sdp_query_rfcomm.o \
|
||||
|
||||
BLE = \
|
||||
att.c \
|
||||
att_server.c \
|
||||
central_device_db_memory.c \
|
||||
sm.c \
|
||||
att_dispatch.c \
|
||||
l2cap_le.c \
|
||||
${CC2564B} \
|
||||
# gatt_client.c \
|
||||
|
||||
LCD = hal_lcd.c hal_lcd_fonts.c
|
||||
|
||||
|
||||
CORE_OBJ = $(CORE:.c=.o)
|
||||
COMMON_OBJ = $(COMMON:.c=.o)
|
||||
SPP_OBJ = $(SPP:.c=.o)
|
||||
BLE_OBJ = $(BLE:.c=.o)
|
||||
LCD_OBJ = $(LCD:.c=.o)
|
||||
|
||||
# create .hex file from .out
|
||||
%.hex: %.out
|
||||
msp430-objcopy -O ihex $< $@
|
||||
|
||||
# create firmware image from common objects and example source file
|
||||
|
||||
all: led_counter.hex spp_counter.hex spp_accel.hex gap_inquiry.hex spp_flowcontrol.hex \
|
||||
sdp_rfcomm_query.hex sdp_general_query.hex
|
||||
|
||||
# compiling requires a 20-bit mspgcc version
|
||||
# spp_and_le_counter.hex
|
||||
|
||||
# compiling ant-test requires special ant init script
|
||||
# ant-test.hex
|
||||
|
||||
# compile GATT database
|
||||
%.h: %.gatt
|
||||
python ${BTSTACK_ROOT}/ble/compile-gatt.py $< $@
|
||||
|
||||
|
||||
led_counter.out: ${CORE_OBJ} ${COMMON_OBJ} ${CC2560B} led_counter.o
|
||||
${CC} $^ ${LDFLAGS} -o $@
|
||||
|
||||
ant-test.out: ${CORE_OBJ} ${COMMON_OBJ} ${SPP_OBJ} profile.h sdp.o ant_cmds.o ${CC2567} ant-test.o
|
||||
${CC} $^ ${LDFLAGS} -o $@
|
||||
|
||||
ble_server.out: ${CORE_OBJ} ${COMMON_OBJ} ${BLE_OBJ} ${LCD_OBJ} profile.h ble_server.o
|
||||
${CC} $^ ${LDFLAGS} -o $@
|
||||
|
||||
hid_demo.out: ${CORE_OBJ} ${COMMON_OBJ} ${LCD_OBJ} ${SPP_OBJ} ${CC2560B} hid_demo.o
|
||||
${CC} $^ ${LDFLAGS} -o $@
|
||||
|
||||
spp_accel.out: ${CORE_OBJ} ${COMMON_OBJ} ${SPP_OBJ} ${CC2560B} spp_accel.o sdp.o hal_adc.o
|
||||
${CC} $^ ${LDFLAGS} -o $@
|
||||
|
||||
spp_and_le_counter.out: ${CORE_OBJ} ${COMMON_OBJ} ${SPP_OBJ} ${BLE_OBJ} spp_and_le_counter.h spp_and_le_counter.o sdp.o hal_adc.o
|
||||
${CC} $^ ${LDFLAGS} -o $@
|
||||
|
||||
spp_counter.out: ${CORE_OBJ} ${COMMON_OBJ} ${SPP_OBJ} ${CC2560B} spp_counter.o sdp.o hal_adc.o
|
||||
${CC} $^ ${LDFLAGS} -o $@
|
||||
|
||||
spp_flowcontrol.out: ${CORE_OBJ} ${COMMON_OBJ} ${SPP_OBJ} ${CC2560B} spp_flowcontrol.o sdp.o hal_adc.o
|
||||
${CC} $^ ${LDFLAGS} -o $@
|
||||
|
||||
gap_inquiry.out: ${CORE_OBJ} ${COMMON_OBJ} ${SPP_OBJ} ${CC2560B} gap_inquiry.o hal_adc.o
|
||||
${CC} $^ ${LDFLAGS} -o $@
|
||||
|
||||
sdp_rfcomm_query.out: ${CORE_OBJ} ${COMMON_OBJ} ${SPP_OBJ} ${SDP_CLIENT} ${CC2560B} sdp_rfcomm_query.o hal_adc.o
|
||||
${CC} $^ ${LDFLAGS} -o $@
|
||||
|
||||
sdp_general_query.out: ${CORE_OBJ} ${COMMON_OBJ} ${SPP_OBJ} ${SDP_CLIENT} ${CC2560B} sdp_general_query.o hal_adc.o
|
||||
${CC} $^ ${LDFLAGS} -o $@
|
||||
|
||||
clean:
|
||||
rm -f $ *.o *.out *.hex profile.h spp_and_le_counter.h ../driver/*.o ../../src/*.o ../src/*.o ../firmware/*.o ${BTSTACK_ROOT}/chipset-cc256x/*.o ${BTSTACK_ROOT}/src/*.o
|
||||
|
||||
size: all
|
||||
msp430-size *.o
|
||||
msp430-size *.out
|
@ -1,18 +1,20 @@
|
||||
// config.h created by configure for BTstack Tue Jun 4 23:10:20 CEST 2013
|
||||
|
||||
#ifndef __BTSTACK_CONFIG
|
||||
#define __BTSTACK_CONFIG
|
||||
|
||||
#define EMBEDDED
|
||||
|
||||
#define HAVE_BLE
|
||||
|
||||
#define HAVE_INIT_SCRIPT
|
||||
#define HAVE_BZERO
|
||||
#define HAVE_TICK
|
||||
|
||||
#define HAVE_EHCILL
|
||||
|
||||
#define HAVE_HCI_DUMP
|
||||
// #define ENABLE_LOG_ERROR
|
||||
// #define ENABLE_LOG_INFO
|
||||
#define ENABLE_LOG_ERROR
|
||||
|
||||
#define HCI_ACL_PAYLOAD_SIZE 52
|
||||
|
||||
@ -20,6 +22,8 @@
|
||||
#define MAX_SPP_CONNECTIONS 1
|
||||
|
||||
#define MAX_NO_HCI_CONNECTIONS MAX_SPP_CONNECTIONS
|
||||
#define MAX_NO_GATT_CLIENTS 0
|
||||
#define MAX_NO_GATT_SUBCLIENTS 0
|
||||
#define MAX_NO_L2CAP_SERVICES 2
|
||||
#define MAX_NO_L2CAP_CHANNELS (1+MAX_SPP_CONNECTIONS)
|
||||
#define MAX_NO_RFCOMM_MULTIPLEXERS MAX_SPP_CONNECTIONS
|
||||
@ -31,4 +35,5 @@
|
||||
#define MAX_NO_DB_MEM_DEVICE_NAMES 0
|
||||
#define MAX_NO_DB_MEM_SERVICES 1
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -1,6 +1,7 @@
|
||||
// *****************************************************************************
|
||||
//
|
||||
// spp_counter demo - it provides a SPP and sends a counter every second
|
||||
// ant + spp demo - it provides a SPP port and and sends a counter every second
|
||||
// - it also listens on ANT channel 33,1,1
|
||||
//
|
||||
// it doesn't use the LCD to get down to a minimal memory footpring
|
||||
//
|
||||
@ -18,9 +19,11 @@
|
||||
#include "hal_compat.h"
|
||||
#include "hal_usb.h"
|
||||
|
||||
#include <btstack/ant_cmds.h>
|
||||
#include <btstack/hci_cmds.h>
|
||||
#include <btstack/run_loop.h>
|
||||
#include <btstack/sdp_util.h>
|
||||
#include <btstack/utils.h>
|
||||
|
||||
#include "hci.h"
|
||||
#include "l2cap.h"
|
||||
@ -33,15 +36,20 @@
|
||||
#define HEARTBEAT_PERIOD_MS 1000
|
||||
|
||||
static uint8_t rfcomm_channel_nr = 1;
|
||||
static uint16_t rfcomm_channel_id;
|
||||
static uint16_t rfcomm_channel_id = 0;
|
||||
static uint8_t spp_service_buffer[100];
|
||||
|
||||
|
||||
// Bluetooth logic
|
||||
static void packet_handler (void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||
bd_addr_t event_addr;
|
||||
uint8_t rfcomm_channel_nr;
|
||||
uint16_t mtu;
|
||||
|
||||
uint8_t event_code;
|
||||
// uint8_t channel;
|
||||
uint8_t message_id;
|
||||
|
||||
switch (packet_type) {
|
||||
case HCI_EVENT_PACKET:
|
||||
switch (packet[0]) {
|
||||
@ -60,8 +68,9 @@ static void packet_handler (void * connection, uint8_t packet_type, uint16_t cha
|
||||
break;
|
||||
}
|
||||
if (COMMAND_COMPLETE_EVENT(packet, hci_write_local_name)){
|
||||
hci_discoverable_control(1);
|
||||
break;
|
||||
// start ANT init
|
||||
ant_send_cmd(&ant_reset);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -103,9 +112,47 @@ static void packet_handler (void * connection, uint8_t packet_type, uint16_t cha
|
||||
rfcomm_channel_id = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
case 0xff: // vendor specific -> ANT
|
||||
|
||||
// vendor specific ant message
|
||||
if (packet[2] != 0x00) break;
|
||||
if (packet[3] != 0x05) break;
|
||||
|
||||
event_code = packet[7];
|
||||
|
||||
printf("ANT Event: ");
|
||||
printf_hexdump(packet, size);
|
||||
|
||||
switch(event_code){
|
||||
|
||||
case MESG_STARTUP_MESG_ID:
|
||||
// 2. assign channel
|
||||
ant_send_cmd(&ant_assign_channel, 0, 0x00, 0);
|
||||
break;
|
||||
|
||||
case MESG_RESPONSE_EVENT_ID:
|
||||
// channel = packet[8];
|
||||
message_id = packet[9];
|
||||
switch (message_id){
|
||||
case MESG_ASSIGN_CHANNEL_ID:
|
||||
// 3. set channel ID
|
||||
ant_send_cmd(&ant_channel_id, 0, 33, 1, 1);
|
||||
break;
|
||||
case MESG_CHANNEL_ID_ID:
|
||||
// 4. open channel
|
||||
ant_send_cmd(&ant_open_channel, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -120,50 +167,21 @@ static void heartbeat_handler(struct timer *ts){
|
||||
char lineBuffer[30];
|
||||
sprintf(lineBuffer, "BTstack counter %04u\n\r", ++counter);
|
||||
printf(lineBuffer);
|
||||
if (rfcomm_can_send_packet_now(rfcomm_channel_id)) {
|
||||
if (rfcomm_can_send_packet_now(rfcomm_channel_id)){
|
||||
int err = rfcomm_send_internal(rfcomm_channel_id, (uint8_t*) lineBuffer, strlen(lineBuffer));
|
||||
if (err) {
|
||||
printf("rfcomm_send_internal -> error %d", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
run_loop_set_timer(ts, HEARTBEAT_PERIOD_MS);
|
||||
run_loop_add_timer(ts);
|
||||
}
|
||||
|
||||
// main
|
||||
int main(void)
|
||||
{
|
||||
// stop watchdog timer
|
||||
WDTCTL = WDTPW + WDTHOLD;
|
||||
int btstack_main(int argc, const char * argv[]);
|
||||
int btstack_main(int argc, const char * argv[]){
|
||||
|
||||
//Initialize clock and peripherals
|
||||
halBoardInit();
|
||||
halBoardStartXT1();
|
||||
halBoardSetSystemClock(SYSCLK_16MHZ);
|
||||
|
||||
// init debug UART
|
||||
halUsbInit();
|
||||
|
||||
// init LEDs
|
||||
LED_PORT_OUT |= LED_1 | LED_2;
|
||||
LED_PORT_DIR |= LED_1 | LED_2;
|
||||
|
||||
/// GET STARTED with BTstack ///
|
||||
btstack_memory_init();
|
||||
run_loop_init(RUN_LOOP_EMBEDDED);
|
||||
|
||||
// init HCI
|
||||
hci_transport_t * transport = hci_transport_h4_dma_instance();
|
||||
bt_control_t * control = bt_control_cc256x_instance();
|
||||
hci_uart_config_t * config = hci_uart_config_cc256x_instance();
|
||||
remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory;
|
||||
hci_init(transport, config, control, remote_db);
|
||||
|
||||
// use eHCILL
|
||||
bt_control_cc256x_enable_ehcill(1);
|
||||
|
||||
// init L2CAP
|
||||
l2cap_init();
|
||||
l2cap_register_packet_handler(packet_handler);
|
||||
@ -189,12 +207,12 @@ int main(void)
|
||||
|
||||
printf("Run...\n\r");
|
||||
|
||||
// ready - enable irq used in h4 task
|
||||
__enable_interrupt();
|
||||
|
||||
// turn on!
|
||||
hci_power_control(HCI_POWER_ON);
|
||||
|
||||
// default to discoverable
|
||||
hci_discoverable_control(1);
|
||||
|
||||
// go!
|
||||
run_loop_execute();
|
||||
|
@ -22,54 +22,40 @@
|
||||
|
||||
#define HEARTBEAT_PERIOD_MS 1000
|
||||
|
||||
static void heartbeat_handler(struct timer *ts){
|
||||
static int counter = 0;
|
||||
static timer_source_t heartbeat;
|
||||
|
||||
static void run_loop_register_timer(timer_source_t *timer, uint16_t period){
|
||||
run_loop_set_timer(timer, period);
|
||||
run_loop_add_timer(timer);
|
||||
}
|
||||
|
||||
static void heartbeat_handler(timer_source_t *ts){
|
||||
// increment counter
|
||||
static int counter = 0;
|
||||
char lineBuffer[30];
|
||||
sprintf(lineBuffer, "BTstack counter %04u\n\r", ++counter);
|
||||
printf(lineBuffer);
|
||||
|
||||
// toggle LED
|
||||
LED_PORT_OUT = LED_PORT_OUT ^ LED_2;
|
||||
|
||||
run_loop_set_timer(ts, HEARTBEAT_PERIOD_MS);
|
||||
run_loop_add_timer(ts);
|
||||
|
||||
// re-register timer
|
||||
run_loop_register_timer(ts, HEARTBEAT_PERIOD_MS);
|
||||
}
|
||||
|
||||
// main
|
||||
int main(void)
|
||||
{
|
||||
// stop watchdog timer
|
||||
WDTCTL = WDTPW + WDTHOLD;
|
||||
|
||||
//Initialize clock and peripherals
|
||||
halBoardInit();
|
||||
halBoardStartXT1();
|
||||
halBoardSetSystemClock(SYSCLK_16MHZ);
|
||||
|
||||
// init debug UART
|
||||
halUsbInit();
|
||||
|
||||
// init LEDs
|
||||
LED_PORT_OUT |= LED_1 | LED_2;
|
||||
LED_PORT_DIR |= LED_1 | LED_2;
|
||||
|
||||
/// GET STARTED with BTstack ///
|
||||
btstack_memory_init();
|
||||
run_loop_init(RUN_LOOP_EMBEDDED);
|
||||
|
||||
static void timer_setup(){
|
||||
// set one-shot timer
|
||||
timer_source_t heartbeat;
|
||||
heartbeat.process = &heartbeat_handler;
|
||||
run_loop_set_timer(&heartbeat, HEARTBEAT_PERIOD_MS);
|
||||
run_loop_add_timer(&heartbeat);
|
||||
run_loop_register_timer(&heartbeat, HEARTBEAT_PERIOD_MS);
|
||||
}
|
||||
|
||||
int btstack_main(int argc, const char * argv[]);
|
||||
int btstack_main(int argc, const char * argv[]){
|
||||
|
||||
timer_setup();
|
||||
|
||||
printf("Run...\n\r");
|
||||
|
||||
// ready - enable irq used in h4 task
|
||||
__enable_interrupt();
|
||||
|
||||
// turn on!
|
||||
// go!
|
||||
run_loop_execute();
|
@ -15,11 +15,8 @@
|
||||
#include "hal_adc.h"
|
||||
#include "hal_board.h"
|
||||
#include "hal_compat.h"
|
||||
#include "hal_lcd.h"
|
||||
#include "hal_usb.h"
|
||||
|
||||
#include "UserExperienceGraphics.h"
|
||||
|
||||
#include <btstack/hci_cmds.h>
|
||||
#include <btstack/run_loop.h>
|
||||
#include <btstack/sdp_util.h>
|
||||
@ -34,40 +31,14 @@
|
||||
|
||||
#define HEARTBEAT_PERIOD_MS 1000
|
||||
|
||||
#define FONT_HEIGHT 12 // Each character has 13 lines
|
||||
#define FONT_HEIGHT 12 // Each character has 13 lines
|
||||
#define FONT_WIDTH 8
|
||||
static int row = 0;
|
||||
char lineBuffer[80];
|
||||
|
||||
static uint8_t rfcomm_channel_nr = 1;
|
||||
static uint16_t rfcomm_channel_id;
|
||||
static uint8_t spp_service_buffer[100];
|
||||
|
||||
// LCD setup
|
||||
void doLCD(void){
|
||||
//Initialize LCD
|
||||
// 138 x 110, 4-level grayscale pixels.
|
||||
halLcdInit();
|
||||
halLcdSetContrast(100);
|
||||
halLcdClearScreen();
|
||||
halLcdImage(TI_TINY_BUG, 4, 32, 104, 12 );
|
||||
|
||||
halLcdPrintLine("BTstack on ", 0, 0);
|
||||
halLcdPrintLine("TI MSP430", 1, 0);
|
||||
halLcdPrintLine("SPP ACCEL", 2, 0);
|
||||
halLcdPrintLine("Init...", 4, 0);
|
||||
row = 5;
|
||||
}
|
||||
|
||||
void clearLine(int line){
|
||||
halLcdClearImage(130, FONT_HEIGHT, 0, line*FONT_HEIGHT);
|
||||
}
|
||||
|
||||
void printLine(char *text){
|
||||
printf("LCD: %s\n\r", text);
|
||||
halLcdPrintLine(text, row++, 0);
|
||||
}
|
||||
|
||||
static uint8_t spp_service_buffer[150];
|
||||
|
||||
// SPP description
|
||||
static uint8_t accel_buffer[6];
|
||||
@ -98,18 +69,18 @@ static void prepare_accel_packet(){
|
||||
printf("Accel: X: %04d, Y: %04d, Z: %04d\n\r", accl_x, accl_y, accl_z);
|
||||
}
|
||||
|
||||
static void send_packet(void){
|
||||
static void send_packet(){
|
||||
int err = rfcomm_send_internal(rfcomm_channel_id, (uint8_t *)accel_buffer, sizeof(accel_buffer));
|
||||
switch (err){
|
||||
switch(err){
|
||||
case 0:
|
||||
prepare_accel_packet();
|
||||
prepare_accel_packet();
|
||||
break;
|
||||
case BTSTACK_ACL_BUFFERS_FULL:
|
||||
break;
|
||||
default:
|
||||
printf("rfcomm_send_internal -> error 0X%02x", err);
|
||||
printf("rfcomm_send_internal() -> err %d\n\r", err);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Bluetooth logic
|
||||
@ -119,64 +90,62 @@ static void packet_handler (void * connection, uint8_t packet_type, uint16_t cha
|
||||
uint16_t mtu;
|
||||
int err;
|
||||
|
||||
switch (packet_type) {
|
||||
case HCI_EVENT_PACKET:
|
||||
switch (packet[0]) {
|
||||
|
||||
case BTSTACK_EVENT_STATE:
|
||||
// bt stack activated, get started - set local name
|
||||
if (packet[2] == HCI_STATE_WORKING) {
|
||||
hci_send_cmd(&hci_write_local_name, "BlueMSP-Demo");
|
||||
}
|
||||
break;
|
||||
|
||||
case HCI_EVENT_COMMAND_COMPLETE:
|
||||
if (COMMAND_COMPLETE_EVENT(packet, hci_read_bd_addr)){
|
||||
switch (packet_type) {
|
||||
case HCI_EVENT_PACKET:
|
||||
switch (packet[0]) {
|
||||
|
||||
case BTSTACK_EVENT_STATE:
|
||||
// bt stack activated, get started - set local name
|
||||
if (packet[2] == HCI_STATE_WORKING) {
|
||||
hci_send_cmd(&hci_write_local_name, "BTstack SPP Sensor");
|
||||
}
|
||||
break;
|
||||
|
||||
case HCI_EVENT_COMMAND_COMPLETE:
|
||||
if (COMMAND_COMPLETE_EVENT(packet, hci_read_bd_addr)){
|
||||
bt_flip_addr(event_addr, &packet[6]);
|
||||
printf("BD-ADDR: %s\n\r", bd_addr_to_str(event_addr));
|
||||
break;
|
||||
}
|
||||
if (COMMAND_COMPLETE_EVENT(packet, hci_write_local_name)){
|
||||
if (COMMAND_COMPLETE_EVENT(packet, hci_write_local_name)){
|
||||
hci_discoverable_control(1);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case HCI_EVENT_LINK_KEY_REQUEST:
|
||||
// deny link key request
|
||||
case HCI_EVENT_LINK_KEY_REQUEST:
|
||||
// deny link key request
|
||||
printf("Link key request\n\r");
|
||||
bt_flip_addr(event_addr, &packet[2]);
|
||||
hci_send_cmd(&hci_link_key_request_negative_reply, &event_addr);
|
||||
break;
|
||||
|
||||
case HCI_EVENT_PIN_CODE_REQUEST:
|
||||
// inform about pin code request
|
||||
printLine( "PIN = 0000");
|
||||
hci_send_cmd(&hci_link_key_request_negative_reply, &event_addr);
|
||||
break;
|
||||
|
||||
case HCI_EVENT_PIN_CODE_REQUEST:
|
||||
// inform about pin code request
|
||||
printf("Pin code request - using '0000'\n\r");
|
||||
bt_flip_addr(event_addr, &packet[2]);
|
||||
hci_send_cmd(&hci_pin_code_request_reply, &event_addr, 4, "0000");
|
||||
break;
|
||||
hci_send_cmd(&hci_pin_code_request_reply, &event_addr, 4, "0000");
|
||||
break;
|
||||
|
||||
case RFCOMM_EVENT_INCOMING_CONNECTION:
|
||||
// data: event (8), len(8), address(48), channel (8), rfcomm_cid (16)
|
||||
bt_flip_addr(event_addr, &packet[2]);
|
||||
rfcomm_channel_nr = packet[8];
|
||||
rfcomm_channel_id = READ_BT_16(packet, 9);
|
||||
printf("RFCOMM channel %u requested for %s\n\r", rfcomm_channel_nr, bd_addr_to_str(event_addr));
|
||||
// data: event (8), len(8), address(48), channel (8), rfcomm_cid (16)
|
||||
bt_flip_addr(event_addr, &packet[2]);
|
||||
rfcomm_channel_nr = packet[8];
|
||||
rfcomm_channel_id = READ_BT_16(packet, 9);
|
||||
printf("RFCOMM channel %u requested for %s\n\r", rfcomm_channel_nr, bd_addr_to_str(event_addr));
|
||||
rfcomm_accept_connection_internal(rfcomm_channel_id);
|
||||
break;
|
||||
|
||||
case RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE:
|
||||
// data: event(8), len(8), status (8), address (48), server channel(8), rfcomm_cid(16), max frame size(16)
|
||||
if (packet[2]) {
|
||||
printf("RFCOMM channel open failed, status %u\n\r", packet[2]);
|
||||
printLine("Connection failed :(");
|
||||
} else {
|
||||
rfcomm_channel_id = READ_BT_16(packet, 12);
|
||||
mtu = READ_BT_16(packet, 14);
|
||||
printf("\n\rRFCOMM channel open succeeded. New RFCOMM Channel ID %u, max frame size %u\n\r", rfcomm_channel_id, mtu);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE:
|
||||
// data: event(8), len(8), status (8), address (48), server channel(8), rfcomm_cid(16), max frame size(16)
|
||||
if (packet[2]) {
|
||||
printf("RFCOMM channel open failed, status %u\n\r", packet[2]);
|
||||
} else {
|
||||
rfcomm_channel_id = READ_BT_16(packet, 12);
|
||||
mtu = READ_BT_16(packet, 14);
|
||||
printf("\n\rRFCOMM channel open succeeded. New RFCOMM Channel ID %u, max frame size %u\n\r", rfcomm_channel_id, mtu);
|
||||
}
|
||||
break;
|
||||
|
||||
case DAEMON_EVENT_HCI_PACKET_SENT:
|
||||
case RFCOMM_EVENT_CREDITS:
|
||||
@ -189,59 +158,21 @@ static void packet_handler (void * connection, uint8_t packet_type, uint16_t cha
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// main
|
||||
int main(void) {
|
||||
|
||||
// stop watchdog timer
|
||||
WDTCTL = WDTPW + WDTHOLD;
|
||||
|
||||
//Initialize clock and peripherals
|
||||
halBoardInit();
|
||||
halBoardStartXT1();
|
||||
halBoardSetSystemClock(SYSCLK_16MHZ);
|
||||
|
||||
// Debug UART
|
||||
halUsbInit();
|
||||
int btstack_main(int argc, const char * argv[]);
|
||||
int btstack_main(int argc, const char * argv[]){
|
||||
|
||||
// Accel
|
||||
halAccelerometerInit();
|
||||
|
||||
// MindTree demo doesn't calibrate
|
||||
// halAccelerometerCalibrate();
|
||||
|
||||
// init LEDs
|
||||
LED_PORT_OUT |= LED_1 | LED_2;
|
||||
LED_PORT_DIR |= LED_1 | LED_2;
|
||||
|
||||
// show off
|
||||
doLCD();
|
||||
|
||||
prepare_accel_packet();
|
||||
|
||||
printf("Init BTstack...\n\r");
|
||||
|
||||
/// GET STARTED ///
|
||||
btstack_memory_init();
|
||||
run_loop_init(RUN_LOOP_EMBEDDED);
|
||||
|
||||
// init HCI
|
||||
hci_transport_t * transport = hci_transport_h4_dma_instance();
|
||||
bt_control_t * control = bt_control_cc256x_instance();
|
||||
hci_uart_config_t * config = hci_uart_config_cc256x_instance();
|
||||
remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory;
|
||||
hci_init(transport, config, control, remote_db);
|
||||
|
||||
// use eHCILL
|
||||
bt_control_cc256x_enable_ehcill(1);
|
||||
|
||||
// init L2CAP
|
||||
l2cap_init();
|
||||
l2cap_register_packet_handler(packet_handler);
|
||||
@ -253,7 +184,7 @@ int main(void) {
|
||||
|
||||
// init SDP, create record for SPP and register with SDP
|
||||
sdp_init();
|
||||
memset(spp_service_buffer, 0, sizeof(spp_service_buffer));
|
||||
memset(spp_service_buffer, 0, sizeof(spp_service_buffer));
|
||||
service_record_item_t * service_record_item = (service_record_item_t *) spp_service_buffer;
|
||||
sdp_create_spp_service( (uint8_t*) &service_record_item->service_record, 1, "SPP Accel");
|
||||
printf("SDP service buffer size: %u\n\r", (uint16_t) (sizeof(service_record_item_t) + de_get_len((uint8_t*) &service_record_item->service_record)));
|
||||
@ -262,11 +193,13 @@ int main(void) {
|
||||
// ready - enable irq used in h4 task
|
||||
__enable_interrupt();
|
||||
|
||||
// turn on!
|
||||
hci_power_control(HCI_POWER_ON);
|
||||
|
||||
// turn on!
|
||||
hci_power_control(HCI_POWER_ON);
|
||||
// make discoverable
|
||||
hci_discoverable_control(1);
|
||||
|
||||
// go!
|
||||
run_loop_execute();
|
||||
run_loop_execute();
|
||||
|
||||
// happy compiler!
|
||||
return 0;
|
Loading…
x
Reference in New Issue
Block a user