2024-12-02 22:15:50 +08:00
|
|
|
#include "mw_bluetooth.h"
|
|
|
|
|
2024-12-17 22:12:53 +08:00
|
|
|
/* user external inc. */
|
2024-12-17 21:18:40 +08:00
|
|
|
|
2024-12-17 22:12:53 +08:00
|
|
|
#include "mw_soft_timer.h"
|
2024-12-03 22:49:37 +08:00
|
|
|
|
2024-12-17 22:12:53 +08:00
|
|
|
#include "stm32f10x.h"
|
|
|
|
|
|
|
|
#include "public_diy.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define BLUETOOTH_USART_PERIPH (USART1)
|
2024-12-03 22:49:37 +08:00
|
|
|
// Initial the entity of bluetooth buf.
|
2025-03-17 22:52:44 +08:00
|
|
|
mw_bluetooth_t bt_drv_buf[bluetooth_num];
|
2024-12-03 22:49:37 +08:00
|
|
|
|
2024-12-17 21:18:40 +08:00
|
|
|
/*************************************************************************************
|
|
|
|
* @brief Get the bluetooth object
|
2024-12-17 22:12:53 +08:00
|
|
|
* @param[in/out] e_val
|
|
|
|
* @return mw_bluetooth_t
|
2024-12-17 21:18:40 +08:00
|
|
|
*
|
2024-12-17 22:12:53 +08:00
|
|
|
* @warning
|
|
|
|
* @note
|
2024-12-17 21:18:40 +08:00
|
|
|
*************************************************************************************/
|
|
|
|
mw_bluetooth_t mw_get_bluetooth_drv(bluetooth_type_enum e_val)
|
2024-12-03 22:49:37 +08:00
|
|
|
{
|
2024-12-17 21:18:40 +08:00
|
|
|
if(e_val >= bluetooth_num)
|
|
|
|
{
|
|
|
|
while(1);
|
|
|
|
}
|
2025-03-17 22:52:44 +08:00
|
|
|
return bt_drv_buf[e_val];
|
2024-12-03 22:49:37 +08:00
|
|
|
}
|
2025-03-17 22:52:44 +08:00
|
|
|
/*************************************************************************************
|
|
|
|
* @brief Bluetooth_usart init function
|
|
|
|
* @return int8_t 【返回值注释】
|
|
|
|
*
|
|
|
|
* @warning 【不可重入,阻塞等警告】
|
|
|
|
* @note 【重大修改】
|
|
|
|
*************************************************************************************/
|
|
|
|
static int8_t bluetooth_system_usart_init(void)
|
2024-12-17 22:12:53 +08:00
|
|
|
{
|
|
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
USART_InitTypeDef USART_InitStructure;
|
|
|
|
NVIC_InitTypeDef NVIC_InitStructure;
|
|
|
|
|
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
|
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
|
|
|
|
|
|
|
|
|
|
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;//TX
|
|
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
|
|
|
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
|
|
|
|
|
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//RX
|
|
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
|
|
|
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
|
|
|
|
|
|
|
|
|
|
|
USART_InitStructure.USART_BaudRate = 9600;
|
|
|
|
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
|
|
|
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
|
|
|
|
USART_InitStructure.USART_Parity = USART_Parity_No;
|
|
|
|
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
|
|
|
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
|
|
|
USART_Init(BLUETOOTH_USART_PERIPH, &USART_InitStructure);
|
|
|
|
|
|
|
|
USART_ITConfig(BLUETOOTH_USART_PERIPH, USART_IT_RXNE, ENABLE);
|
|
|
|
|
|
|
|
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
|
|
|
|
|
|
|
|
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
|
|
|
NVIC_Init(&NVIC_InitStructure);
|
|
|
|
|
|
|
|
USART_Cmd(BLUETOOTH_USART_PERIPH, ENABLE);
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
}
|
|
|
|
|
2025-03-17 22:52:44 +08:00
|
|
|
static int8_t bluetooth_system_usart_deinit(void)
|
2024-12-17 22:12:53 +08:00
|
|
|
{
|
|
|
|
USART_DeInit(BLUETOOTH_USART_PERIPH);
|
|
|
|
return RET_OK;
|
|
|
|
}
|
2024-12-17 21:18:40 +08:00
|
|
|
|
2025-03-17 22:52:44 +08:00
|
|
|
static int8_t bluetooth_system_usart_send_one_byte(uint8_t uc_data)
|
2024-12-17 22:12:53 +08:00
|
|
|
{
|
|
|
|
USART_SendData(BLUETOOTH_USART_PERIPH, uc_data);
|
|
|
|
return RET_OK;
|
|
|
|
}
|
2024-12-17 21:18:40 +08:00
|
|
|
|
2025-03-17 22:52:44 +08:00
|
|
|
static uint8_t bluetooth_system_usart_receive_one_byte(void)
|
2024-12-17 22:12:53 +08:00
|
|
|
{
|
|
|
|
return (uint8_t)(USART_ReceiveData(BLUETOOTH_USART_PERIPH));
|
|
|
|
}
|
2025-03-17 22:52:44 +08:00
|
|
|
|
|
|
|
static void bluetooth_init(void)
|
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|
|
|
|
static void bluetooth_deinit(void)
|
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|
|
|
|
static void bluetooth_send_bytes(uint8_t * tx_buf, uint16_t len)
|
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|
|
|
|
static void bluetooth_recv_deal(void)
|
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|
2024-12-17 22:12:53 +08:00
|
|
|
/*************************************************************************************
|
|
|
|
* @brief bluetooth driver init.
|
|
|
|
*
|
|
|
|
* @warning
|
|
|
|
* @note
|
|
|
|
*************************************************************************************/
|
2024-12-17 21:18:40 +08:00
|
|
|
void mw_bluetooth_drv_init(void)
|
|
|
|
{
|
2025-03-17 22:52:44 +08:00
|
|
|
/* =============== hc06 init ======================== */
|
|
|
|
/* launcg bluetooth driver type */
|
|
|
|
bt_drv_buf[hc06].bt_drv = hc06;
|
|
|
|
/* launch timer api - 32bit systick */
|
|
|
|
bt_drv_buf[hc06].bt_timer.pf_get_systick_ms = get_systick_ms;
|
|
|
|
/* launch the api of USART. */
|
|
|
|
bt_drv_buf[hc06].bt_usart.pf_init = bluetooth_system_usart_init;
|
|
|
|
bt_drv_buf[hc06].bt_usart.pf_deinit = bluetooth_system_usart_deinit;
|
|
|
|
bt_drv_buf[hc06].bt_usart.pf_recv_one_byte = bluetooth_system_usart_receive_one_byte;
|
|
|
|
bt_drv_buf[hc06].bt_usart.pf_trans_one_byte = bluetooth_system_usart_send_one_byte;
|
|
|
|
bt_drv_buf[hc06].bt_usart.pf_recv_one_byte = bluetooth_system_usart_receive_one_byte;
|
|
|
|
/* launch the api of inner bluetooth. */
|
|
|
|
bt_drv_buf[hc06].pf_init = bluetooth_init;
|
|
|
|
bt_drv_buf[hc06].pf_deinit = bluetooth_deinit;
|
|
|
|
bt_drv_buf[hc06].pf_send_bytes = bluetooth_send_bytes;
|
|
|
|
bt_drv_buf[hc06].pf_recv_deal = bluetooth_recv_deal;
|
|
|
|
|
2024-12-17 21:18:40 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|