moved setup_printf(baud) into BTstack.h

This commit is contained in:
Matthias Ringwald 2015-05-25 00:16:09 +02:00
parent c8566a6b5e
commit 3d7b27c5a7
7 changed files with 30 additions and 86 deletions

View File

@ -81,6 +81,29 @@ static void (*gattCharacteristicWrittenCallback)(BLEStatus status, BLEDevice * d
static void (*gattCharacteristicSubscribedCallback)(BLEStatus status, BLEDevice * device) = NULL;
static void (*gattCharacteristicUnsubscribedCallback)(BLEStatus status, BLEDevice * device) = NULL;
// retarget printf to Serial
#ifdef ENERGIA
extern "C" int putchar(int c) {
Serial.write((uint8_t)c);
return c;
}
static void setup_printf(int baud) {
Serial.begin(baud);
}
#else
static FILE uartout = {0} ;
static int uart_putchar (char c, FILE *stream) {
Serial.write(c);
return 0;
}
void setup_printf(int baud) {
Serial.begin(baud);
fdev_setup_stream (&uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE);
stdout = &uartout;
}
#endif
// HAL CPU Implementation
extern "C" void hal_cpu_disable_irqs(void){ }
extern "C" void hal_cpu_enable_irqs(void) { }

View File

@ -19,6 +19,11 @@ typedef enum BLEStatus {
typedef void (*btstack_packet_handler_t) (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
/**
* @brief Setup printf to use Serial with given baud rate
*/
void setup_printf(int baud);
class UUID {
private:
uint8_t uuid[16];

View File

@ -15,30 +15,6 @@ const uint8_t adv_data[] = {
0x11,0x15,0xD0,0x00,0x2D,0x12,0x1E,0x4B,0x0F,0xA4,0x99,0x4E,0xCE,0xB5,0x31,0xF4,0x05,0x79
};
// retarget printf
#ifdef ENERGIA
extern "C" {
int putchar(int c) {
Serial.write((uint8_t)c);
return c;
}
}
static void setup_printf(void) {
Serial.begin(9600);
}
#else
static FILE uartout = {0} ;
static int uart_putchar (char c, FILE *stream) {
Serial.write(c);
return 0;
}
static void setup_printf(void) {
Serial.begin(9600);
fdev_setup_stream (&uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE);
stdout = &uartout;
}
#endif
static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
printf("packet_handler type %u, event 0x%02x\n", packet_type, packet[0]);
ancs_client_hci_event_handler(packet_type, channel, packet, size);
@ -65,7 +41,7 @@ void ancs_callback(ancs_event_t * event){
void setup(void){
setup_printf();
setup_printf(9600);
printf("BTstack ANCS Client starting up...\n");

View File

@ -39,18 +39,6 @@ char counterString[20];
static timer_source_t heartbeat;
// setup printf
static FILE uartout = {0} ;
static int uart_putchar (char c, FILE *stream) {
Serial.write(c);
return 0;
}
static void setup_printf(int baud) {
Serial.begin(baud);
fdev_setup_stream (&uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE);
stdout = &uartout;
}
void setup(void){
setup_printf(9600);

View File

@ -2,18 +2,6 @@
#include <BTstack.h>
#include <SPI.h>
// setup printf
static FILE uartout = {0} ;
static int uart_putchar (char c, FILE *stream) {
Serial.write(c);
return 0;
}
static void setup_printf(int baud) {
Serial.begin(baud);
fdev_setup_stream (&uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE);
stdout = &uartout;
}
static uint16_t value_handle;
void setup(void){

View File

@ -4,32 +4,8 @@
UUID uuid("E2C56DB5-DFFB-48D2-B060-D0F5A71096E0");
// retarget printf
#ifdef ENERGIA
extern "C" {
int putchar(int c) {
Serial.write((uint8_t)c);
return c;
}
}
static void setup_printf(void) {
Serial.begin(9600);
}
#else
static FILE uartout = {0} ;
static int uart_putchar (char c, FILE *stream) {
Serial.write(c);
return 0;
}
static void setup_printf(void) {
Serial.begin(9600);
fdev_setup_stream (&uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE);
stdout = &uartout;
}
#endif
void setup(void){
setup_printf();
setup_printf(9600);
BTstack.iBeaconConfigure(&uuid, 4711, 2);
BTstack.setup();
BTstack.startAdvertising();

View File

@ -2,18 +2,6 @@
#include <BTstack.h>
#include <SPI.h>
// setup printf
static FILE uartout = {0} ;
static int uart_putchar (char c, FILE *stream) {
Serial.write(c);
return 0;
}
static void setup_printf(int baud) {
Serial.begin(baud);
fdev_setup_stream (&uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE);
stdout = &uartout;
}
void setup(void){
setup_printf(9600);