Embedded: support btstack_stdin via SEGGER RTT

This commit is contained in:
Matthias Ringwald 2018-04-15 11:38:46 +02:00
parent e271797415
commit ad2a4692c4
2 changed files with 28 additions and 7 deletions

View File

@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
- SM: support pairing using Out-of-Band (OOB) data with LE Secure Connections
- Embedded: support btstack_stdin via SEGGER RTT
### Changed
- att_db_util: added security requirement arguments to characteristic creators

View File

@ -44,17 +44,26 @@
*
*/
#include "hal_stdin.h"
#include "btstack_config.h"
#include "btstack_stdin.h"
#include "btstack_run_loop.h"
#include "btstack_run_loop_embedded.h"
volatile int stdin_character_received;
volatile char stdin_character;
#ifdef ENABLE_SEGGER_RTT
#include "SEGGER_RTT.h"
#else
#include "hal_stdin.h"
#endif
static void (*stdin_handler)(char c);
static btstack_data_source_t stdin_data_source;
#ifndef ENABLE_SEGGER_RTT
volatile int stdin_character_received;
volatile char stdin_character;
static void btstack_stdin_handler(char c){
stdin_character = c;
stdin_character_received = 1;
@ -63,12 +72,21 @@ static void btstack_stdin_handler(char c){
static void btstack_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_character);
}
(*stdin_handler)(stdin_character);
stdin_character_received = 0;
}
#else
static void btstack_stdin_process(struct btstack_data_source *ds, btstack_data_source_callback_type_t callback_type){
if (SEGGER_RTT_HasKey()){
int stdin_character = SEGGER_RTT_GetKey();
(*stdin_handler)((uint8_t)stdin_character);
}
}
#endif
void btstack_stdin_setup(void (*handler)(char c)){
// set handler
stdin_handler = handler;
@ -78,6 +96,8 @@ void btstack_stdin_setup(void (*handler)(char c)){
btstack_run_loop_enable_data_source_callbacks(&stdin_data_source, DATA_SOURCE_CALLBACK_POLL);
btstack_run_loop_add_data_source(&stdin_data_source);
// start receiving
#ifndef ENABLE_SEGGER_RTT
// start receiving via hal_stdin.h
hal_stdin_setup(&btstack_stdin_handler);
#endif
}