中级
30 分钟

使用BGM220P和TM4C123GH6PZ解锁蓝牙的魔力

我们的蓝牙奇迹!

BLE 9 Click with Fusion for Tiva v8

已发布 6月 24, 2024

点击板

BLE 9 Click

开发板

Fusion for Tiva v8

编译器

NECTO Studio

微控制器单元

TM4C123GH6PZ

体验我们先进的蓝牙解决方案,轻松连接您的设备,消除线缆的烦恼,发现无线便利的真正本质。

A

A

硬件概览

它是如何工作的?

BLE 9 Click基于BGM220P,这是一种来自Silicon Labs的射频性能蓝牙低功耗解决方案,为任何嵌入式应用提供BT/BLE连接。它支持蓝牙5.2、方向查找和蓝牙Mesh低功耗节点协议,提供业界领先的准确性。具有全球监管认证和完全可升级的软件堆栈,作为高级开发和调试工具。BGM220P模块结合了EFR32BG22无线系统芯片(SoC)、所需的去耦电容和电感、38.4 MHz和32.768 kHz晶体、RF匹配电路和集成的陶瓷板载芯片天线。BGM220P模块内的EFR32BG22 SoC包含一个Arm Cortex-M33处理核心,最多32Kb的RAM,最多512kB的闪存,以及一个2.4GHz射频收发器,提供高达8dB的输出功率。此Click板™提供增强的性

能、安全性和可靠性,以支持在蓝牙网络上运行的物联网产品。BLE 9 Click使用UART接口作为默认通信协议与MCU通信,用户也可以选择使用其他接口,如SPI和I2C,若希望自行配置模块并编写库。这款Click板™还可以在没有外部主处理器的独立SoC配置中使用。除了这些协议引脚外,此Click板™还具有标记为CTS和RTS的串行UART连接,分别路由到mikroBUS™插座的CS和INT引脚,以及提供并路由到mikroBUS™插座的RST引脚的复位引脚。一个额外的GPIO引脚,标记为IO,路由到mikroBUS™插座的PWM引脚,留给用户根据需要进行配置。板载跳线选择CS mikroBUS™引脚在SPI或UART通信引脚之间的功能。通过

将标记为CTS或CS的SMD跳线置于适当位置进行选择。BLE 9 Click底部有一个额外的头部,Mini Simplicity Debug Connector,完全支持调试和编程功能。通过此头部,用户可以使用串行线调试接口进行编程和调试,使用SWCLK和SWDIO引脚,虚拟UART COM端口和基于虚拟UART-SWD的接口也可以通过SWD接口(SWDIO、SWCLK和SWO)使用。此Click板™只能在3.3V逻辑电压水平下运行。在使用具有不同逻辑电平的MCU之前,必须进行适当的逻辑电压电平转换。此外,它还配备了一个包含函数和示例代码的库,可用作进一步开发的参考。

BLE 9 Click hardware overview image

功能概述

开发板

Fusion for TIVA v8 是一款专为快速开发嵌入式应用的需求而特别设计的开发板。它支持广泛的微控制器,如不同的32位ARM® Cortex®-M基础MCUs,来自Texas Instruments,无论它们的引脚数量如何,并且具有一系列独特功能,例如首次通过WiFi网络实现的嵌入式调试器/程序员。开发板布局合理,设计周到,使得最终用户可以在一个地方找到所有必要的元素,如开关、按钮、指示灯、连接器等。得益于创新的制造技术,Fusion for TIVA v8 提供了流畅而沉浸式的工作体验,允许在任何情况下、任何地方、任何

时候都能访问。Fusion for TIVA v8开发板的每个部分都包含了使同一板块运行最高效的必要组件。一个先进的集成CODEGRIP程序/调试模块提供许多有价值的编程/调试选项,包括对JTAG、SWD和SWO Trace(单线输出)的支持,并与Mikroe软件环境无缝集成。此外,它还包括一个干净且调节过的开发板电源供应模块。它可以使用广泛的外部电源,包括电池、外部12V电源供应和通过USB Type-C(USB-C)连接器的电源。通信选项如USB-UART、USB HOST/DEVICE、CAN(如果MCU卡支持的话)和以

太网也包括在内。此外,它还拥有广受好评的 mikroBUS™标准,为MCU卡提供了标准化插座(SiBRAIN标准),以及两种显示选项,用于TFT板线产品和基于字符的LCD。Fusion for TIVA v8 是Mikroe快速开发生态系统的一个组成部分。它由Mikroe软件工具原生支持,得益于大量不同的Click板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作和开发的许多方面。

Fusion for Tiva v8 horizontal image

微控制器概述 

MCU卡片 / MCU

default

类型

8th Generation

建筑

ARM Cortex-M4

MCU 内存 (KB)

256

硅供应商

Texas Instruments

引脚数

100

RAM (字节)

32768

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
Reset
PH0
RST
UART CTS / SPI Chip Select
PF7
CS
SPI Clock
PK0
SCK
SPI Data OUT
PK2
MISO
SPI Data IN
PK3
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
User-Configurable I/0
PF5
PWM
UART RTS
PH4
INT
UART TX
PC7
TX
UART RX
PC6
RX
I2C Clock
PA6
SCL
I2C Data
PA7
SDA
NC
NC
5V
Ground
GND
GND
1

“仔细看看!”

原理图

BLE 9 Click Schematic schematic

一步一步来

项目组装

Fusion for PIC v8 front image hardware assembly

从选择您的开发板和Click板™开始。以Fusion for Tiva v8作为您的开发板开始。

Fusion for PIC v8 front image hardware assembly
Buck 22 Click front image hardware assembly
SiBRAIN for PIC32MZ1024EFK144 front image hardware assembly
v8 SiBRAIN MB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
NECTO Compiler Selection Step Image hardware assembly
NECTO Output Selection Step Image hardware assembly
Necto image step 6 hardware assembly
Necto image step 7 hardware assembly
Necto image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto PreFlash Image hardware assembly

实时跟踪您的结果

应用输出通过UART模式

1. 一旦代码示例加载完成,按下 "FLASH" 按钮将启动构建过程,并将其编程到创建的设置上。

2. 编程完成后,点击右上角面板中的工具图标,选择 UART 终端

3. 打开 UART 终端标签后,首先在选项菜单中检查波特率设置(默认是 115200)。如果该参数正确,通过点击 "CONNECT" 按钮激活终端。

4. 现在,终端状态从 Disconnected 变为绿色的 Connected,数据将显示在 Received data 字段中。

UART_Application_Output

软件支持

库描述

该库包含 BLE 9 Click 驱动程序的 API。

关键功能:

  • ble9_adv_create_id - 此功能创建适当的ID。

  • ble9_adv_start - 此功能启动广播。

开源

代码示例

这个示例可以在 NECTO Studio 中找到。欢迎下载代码,或者您也可以复制下面的代码。

/*!
 * @file main.c
 * @brief BLE 9 Click example
 *
 * # Description
 * This example demonstrates the use of BLE 9 click board by processing
 * the incoming data and displaying them on the USB UART.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the click default configuration.
 *
 * ## Application Task
 * Reads and processes all incoming data and displays them on the USB UART.
 *
 * ## Additional Function
 * - static void ble9_clear_app_buf ( void )
 * - static err_t ble9_process ( ble9_t *ctx )
 * 
 * <pre>
 * For more information on the chip itself and the firmware on it,
 * please visit the following page:
 *     [1] https://docs.silabs.com/bluetooth/3.1
 *         - Take into condideration that the library itself
 *           is designed to work with GSDK version 3.1.0
 *           If you wish to use a different version of firmware,
 *           take into consideration that some functions might not work.
 * </pre>
 *
 * @author MikroE Team
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "ble9.h"
#include "log.h"

#define PROCESS_BUFFER_SIZE 200

static ble9_t ble9;
static log_t logger;

static uint8_t app_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
static int32_t app_buf_len = 0;

/**
 * @brief BLE 9 clearing application buffer.
 * @details This function clears memory of application buffer and reset its length.
 * @note None.
 */
static void ble9_clear_app_buf ( void );

/**
 * @brief BLE 9 data reading function.
 * @details This function reads data from device and concatenates data to application buffer. 
 * @param[in] ctx : Click context object.
 * See #ble9_t object definition for detailed explanation.
 * @return @li @c  0 - Read some data.
 *         @li @c -1 - Nothing is read.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t ble9_process ( ble9_t *ctx );

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    ble9_cfg_t cfg;

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, "---- Application Init ----" );
    Delay_ms ( 100 );

    // Click initialization.
    ble9_cfg_setup( &cfg );
    BLE9_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    ble9_init( &ble9, &cfg );
    Delay_ms ( 1000 );
    
    // Clear app buffer
    ble9_process ( &ble9 );
    ble9_clear_app_buf( );
    Delay_ms ( 100 );
    
    if ( BLE9_OK == ble9_sys_get_version ( &ble9 ) )
    {
        log_printf( &logger, "--- System Version ---\r\n" );
        log_printf( &logger, " Major: 0x%.4X\r\n", ble9.ble9_version.version_major );
        log_printf( &logger, " Minor: 0x%.4X\r\n", ble9.ble9_version.version_minor );
        log_printf( &logger, " Patch: 0x%.4X\r\n", ble9.ble9_version.version_patch );
        log_printf( &logger, " Build: 0x%.4X\r\n", ble9.ble9_version.version_build );
        log_printf( &logger, " Bootloader: 0x%.8LX\r\n", ble9.ble9_version.version_bootloader );
        log_printf( &logger, " Hash: 0x%.8LX\r\n", ble9.ble9_version.version_hash );
        log_printf( &logger, "------------------------\r\n" );
    }
    
    log_printf( &logger, "Creating advertising point...\r\n" );
    Delay_ms ( 100 );
    ble9_adv_create_id ( &ble9 );

    log_printf( &logger, "Starting module advertising...\r\n" );
    Delay_ms ( 100 );
    ble9_adv_start ( &ble9, BLE9_ADVERTISER_MODE_DISCOVERABLE_GENERAL, 
                     BLE9_ADVERTISER_MODE_CONNECTABLE_SCANNABLE );

    log_printf( &logger, "The module has been configured.\r\n" );
    Delay_ms ( 100 );
}

void application_task ( void )
{
    ble9_process ( &ble9 );
    if ( app_buf_len > 0 ) 
    {
        for ( uint16_t cnt = 0; cnt < app_buf_len; cnt++ )
        {
            log_printf( &logger, "%.2X ", ( uint16_t ) app_buf[ cnt ] );
        }
        ble9_clear_app_buf( );
    }
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

static void ble9_clear_app_buf ( void ) 
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
}

static err_t ble9_process ( ble9_t *ctx ) 
{
    uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    int32_t rx_size = 0;
    rx_size = ble9_generic_read( ctx, rx_buf, PROCESS_BUFFER_SIZE );
    if ( rx_size > 0 ) 
    {
        int32_t buf_cnt = app_buf_len;
        if ( ( ( app_buf_len + rx_size ) > PROCESS_BUFFER_SIZE ) && ( app_buf_len > 0 ) ) 
        {
            buf_cnt = PROCESS_BUFFER_SIZE - ( ( app_buf_len + rx_size ) - PROCESS_BUFFER_SIZE );
            memmove ( app_buf, &app_buf[ PROCESS_BUFFER_SIZE - buf_cnt ], buf_cnt );
        }
        for ( int32_t rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ ) 
        {
            if ( rx_buf[ rx_cnt ] ) 
            {
                app_buf[ buf_cnt++ ] = rx_buf[ rx_cnt ];
                if ( app_buf_len < PROCESS_BUFFER_SIZE )
                {
                    app_buf_len++;
                }
            }
        }
        return BLE9_OK;
    }
    return BLE9_ERROR;
}

// ------------------------------------------------------------------------ END
/*!
 * @file main.c
 * @brief BLE 9 Click example
 *
 * # Description
 * This example demonstrates the use of BLE 9 click board by processing
 * the incoming data and displaying them on the USB UART.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the click default configuration.
 *
 * ## Application Task
 * Reads and processes all incoming data and displays them on the USB UART.
 *
 * ## Additional Function
 * - static void ble9_clear_app_buf ( void )
 * - static err_t ble9_process ( ble9_t *ctx )
 * 
 * <pre>
 * For more information on the chip itself and the firmware on it,
 * please visit the following page:
 *     [1] https://docs.silabs.com/bluetooth/3.1
 *         - Take into condideration that the library itself
 *           is designed to work with GSDK version 3.1.0
 *           If you wish to use a different version of firmware,
 *           take into consideration that some functions might not work.
 * </pre>
 *
 * @author MikroE Team
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "ble9.h"
#include "log.h"

#define PROCESS_BUFFER_SIZE 200

static ble9_t ble9;
static log_t logger;

static uint8_t app_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
static int32_t app_buf_len = 0;

/**
 * @brief BLE 9 clearing application buffer.
 * @details This function clears memory of application buffer and reset its length.
 * @note None.
 */
static void ble9_clear_app_buf ( void );

/**
 * @brief BLE 9 data reading function.
 * @details This function reads data from device and concatenates data to application buffer. 
 * @param[in] ctx : Click context object.
 * See #ble9_t object definition for detailed explanation.
 * @return @li @c  0 - Read some data.
 *         @li @c -1 - Nothing is read.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t ble9_process ( ble9_t *ctx );

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    ble9_cfg_t cfg;

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, "---- Application Init ----" );
    Delay_ms ( 100 );

    // Click initialization.
    ble9_cfg_setup( &cfg );
    BLE9_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    ble9_init( &ble9, &cfg );
    Delay_ms ( 1000 );
    
    // Clear app buffer
    ble9_process ( &ble9 );
    ble9_clear_app_buf( );
    Delay_ms ( 100 );
    
    if ( BLE9_OK == ble9_sys_get_version ( &ble9 ) )
    {
        log_printf( &logger, "--- System Version ---\r\n" );
        log_printf( &logger, " Major: 0x%.4X\r\n", ble9.ble9_version.version_major );
        log_printf( &logger, " Minor: 0x%.4X\r\n", ble9.ble9_version.version_minor );
        log_printf( &logger, " Patch: 0x%.4X\r\n", ble9.ble9_version.version_patch );
        log_printf( &logger, " Build: 0x%.4X\r\n", ble9.ble9_version.version_build );
        log_printf( &logger, " Bootloader: 0x%.8LX\r\n", ble9.ble9_version.version_bootloader );
        log_printf( &logger, " Hash: 0x%.8LX\r\n", ble9.ble9_version.version_hash );
        log_printf( &logger, "------------------------\r\n" );
    }
    
    log_printf( &logger, "Creating advertising point...\r\n" );
    Delay_ms ( 100 );
    ble9_adv_create_id ( &ble9 );

    log_printf( &logger, "Starting module advertising...\r\n" );
    Delay_ms ( 100 );
    ble9_adv_start ( &ble9, BLE9_ADVERTISER_MODE_DISCOVERABLE_GENERAL, 
                     BLE9_ADVERTISER_MODE_CONNECTABLE_SCANNABLE );

    log_printf( &logger, "The module has been configured.\r\n" );
    Delay_ms ( 100 );
}

void application_task ( void )
{
    ble9_process ( &ble9 );
    if ( app_buf_len > 0 ) 
    {
        for ( uint16_t cnt = 0; cnt < app_buf_len; cnt++ )
        {
            log_printf( &logger, "%.2X ", ( uint16_t ) app_buf[ cnt ] );
        }
        ble9_clear_app_buf( );
    }
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

static void ble9_clear_app_buf ( void ) 
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
}

static err_t ble9_process ( ble9_t *ctx ) 
{
    uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    int32_t rx_size = 0;
    rx_size = ble9_generic_read( ctx, rx_buf, PROCESS_BUFFER_SIZE );
    if ( rx_size > 0 ) 
    {
        int32_t buf_cnt = app_buf_len;
        if ( ( ( app_buf_len + rx_size ) > PROCESS_BUFFER_SIZE ) && ( app_buf_len > 0 ) ) 
        {
            buf_cnt = PROCESS_BUFFER_SIZE - ( ( app_buf_len + rx_size ) - PROCESS_BUFFER_SIZE );
            memmove ( app_buf, &app_buf[ PROCESS_BUFFER_SIZE - buf_cnt ], buf_cnt );
        }
        for ( int32_t rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ ) 
        {
            if ( rx_buf[ rx_cnt ] ) 
            {
                app_buf[ buf_cnt++ ] = rx_buf[ rx_cnt ];
                if ( app_buf_len < PROCESS_BUFFER_SIZE )
                {
                    app_buf_len++;
                }
            }
        }
        return BLE9_OK;
    }
    return BLE9_ERROR;
}

// ------------------------------------------------------------------------ END
/*!
 * @file main.c
 * @brief BLE 9 Click example
 *
 * # Description
 * This example demonstrates the use of BLE 9 click board by processing
 * the incoming data and displaying them on the USB UART.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the click default configuration.
 *
 * ## Application Task
 * Reads and processes all incoming data and displays them on the USB UART.
 *
 * ## Additional Function
 * - static void ble9_clear_app_buf ( void )
 * - static err_t ble9_process ( ble9_t *ctx )
 * 
 * <pre>
 * For more information on the chip itself and the firmware on it,
 * please visit the following page:
 *     [1] https://docs.silabs.com/bluetooth/3.1
 *         - Take into condideration that the library itself
 *           is designed to work with GSDK version 3.1.0
 *           If you wish to use a different version of firmware,
 *           take into consideration that some functions might not work.
 * </pre>
 *
 * @author MikroE Team
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "ble9.h"
#include "log.h"

#define PROCESS_BUFFER_SIZE 200

static ble9_t ble9;
static log_t logger;

static uint8_t app_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
static int32_t app_buf_len = 0;

/**
 * @brief BLE 9 clearing application buffer.
 * @details This function clears memory of application buffer and reset its length.
 * @note None.
 */
static void ble9_clear_app_buf ( void );

/**
 * @brief BLE 9 data reading function.
 * @details This function reads data from device and concatenates data to application buffer. 
 * @param[in] ctx : Click context object.
 * See #ble9_t object definition for detailed explanation.
 * @return @li @c  0 - Read some data.
 *         @li @c -1 - Nothing is read.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t ble9_process ( ble9_t *ctx );

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    ble9_cfg_t cfg;

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, "---- Application Init ----" );
    Delay_ms ( 100 );

    // Click initialization.
    ble9_cfg_setup( &cfg );
    BLE9_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    ble9_init( &ble9, &cfg );
    Delay_ms ( 1000 );
    
    // Clear app buffer
    ble9_process ( &ble9 );
    ble9_clear_app_buf( );
    Delay_ms ( 100 );
    
    if ( BLE9_OK == ble9_sys_get_version ( &ble9 ) )
    {
        log_printf( &logger, "--- System Version ---\r\n" );
        log_printf( &logger, " Major: 0x%.4X\r\n", ble9.ble9_version.version_major );
        log_printf( &logger, " Minor: 0x%.4X\r\n", ble9.ble9_version.version_minor );
        log_printf( &logger, " Patch: 0x%.4X\r\n", ble9.ble9_version.version_patch );
        log_printf( &logger, " Build: 0x%.4X\r\n", ble9.ble9_version.version_build );
        log_printf( &logger, " Bootloader: 0x%.8LX\r\n", ble9.ble9_version.version_bootloader );
        log_printf( &logger, " Hash: 0x%.8LX\r\n", ble9.ble9_version.version_hash );
        log_printf( &logger, "------------------------\r\n" );
    }
    
    log_printf( &logger, "Creating advertising point...\r\n" );
    Delay_ms ( 100 );
    ble9_adv_create_id ( &ble9 );

    log_printf( &logger, "Starting module advertising...\r\n" );
    Delay_ms ( 100 );
    ble9_adv_start ( &ble9, BLE9_ADVERTISER_MODE_DISCOVERABLE_GENERAL, 
                     BLE9_ADVERTISER_MODE_CONNECTABLE_SCANNABLE );

    log_printf( &logger, "The module has been configured.\r\n" );
    Delay_ms ( 100 );
}

void application_task ( void )
{
    ble9_process ( &ble9 );
    if ( app_buf_len > 0 ) 
    {
        for ( uint16_t cnt = 0; cnt < app_buf_len; cnt++ )
        {
            log_printf( &logger, "%.2X ", ( uint16_t ) app_buf[ cnt ] );
        }
        ble9_clear_app_buf( );
    }
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

static void ble9_clear_app_buf ( void ) 
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
}

static err_t ble9_process ( ble9_t *ctx ) 
{
    uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    int32_t rx_size = 0;
    rx_size = ble9_generic_read( ctx, rx_buf, PROCESS_BUFFER_SIZE );
    if ( rx_size > 0 ) 
    {
        int32_t buf_cnt = app_buf_len;
        if ( ( ( app_buf_len + rx_size ) > PROCESS_BUFFER_SIZE ) && ( app_buf_len > 0 ) ) 
        {
            buf_cnt = PROCESS_BUFFER_SIZE - ( ( app_buf_len + rx_size ) - PROCESS_BUFFER_SIZE );
            memmove ( app_buf, &app_buf[ PROCESS_BUFFER_SIZE - buf_cnt ], buf_cnt );
        }
        for ( int32_t rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ ) 
        {
            if ( rx_buf[ rx_cnt ] ) 
            {
                app_buf[ buf_cnt++ ] = rx_buf[ rx_cnt ];
                if ( app_buf_len < PROCESS_BUFFER_SIZE )
                {
                    app_buf_len++;
                }
            }
        }
        return BLE9_OK;
    }
    return BLE9_ERROR;
}

// ------------------------------------------------------------------------ END

额外支持

资源

喜欢这个项目吗?

'购买此套件' 按钮会直接带您进入购物车,您可以在购物车中轻松添加或移除产品。