添加了bt驱动
This commit is contained in:
parent
ed01a45816
commit
a7e664ba78
|
@ -197,5 +197,5 @@
|
||||||
</storageModule>
|
</storageModule>
|
||||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||||
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
|
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
|
||||||
<storageModule moduleId="refreshScope"/>
|
|
||||||
</cproject>
|
</cproject>
|
||||||
|
|
158
bsp/src/bsp_bt.c
158
bsp/src/bsp_bt.c
|
@ -4,6 +4,38 @@
|
||||||
#include "rtdef.h"
|
#include "rtdef.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define LOG_TAG "bsp_bt"
|
||||||
|
#define LOG_LVL LOG_LVL_DBG
|
||||||
|
#include <ulog.h>
|
||||||
|
|
||||||
|
#define BT_UART "uart5"
|
||||||
|
|
||||||
|
rt_timer_t bt_timer;
|
||||||
|
struct rt_semaphore bt_rx_sem;
|
||||||
|
static rt_device_t rt_bt_device;
|
||||||
|
|
||||||
|
#define BT_THREAD_TIMESLICE (5)
|
||||||
|
#define BT_THREAD_PRIORITY (10)
|
||||||
|
#define BT_THREAD_STACK_SIZE (2048)
|
||||||
|
|
||||||
|
|
||||||
|
ALIGN(RT_ALIGN_SIZE)
|
||||||
|
static rt_uint8_t bt_thread_stack[BT_THREAD_STACK_SIZE] = {0};
|
||||||
|
static struct rt_thread bt_thread = {0};
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
rt_size_t recv_bufsz;
|
||||||
|
char recv_line_buf[128];
|
||||||
|
rt_size_t recv_line_len;
|
||||||
|
} bt_device;
|
||||||
|
|
||||||
|
bt_device bt = {
|
||||||
|
.recv_bufsz = 64,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
valve_data_t valve_t[MAX_VALVE_NUM];
|
valve_data_t valve_t[MAX_VALVE_NUM];
|
||||||
|
|
||||||
int BSP_BT_Init(void)
|
int BSP_BT_Init(void)
|
||||||
|
@ -31,3 +63,129 @@ int BSP_BT_Init(void)
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
INIT_PREV_EXPORT(BSP_BT_Init);
|
INIT_PREV_EXPORT(BSP_BT_Init);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static rt_err_t bt_getchar(char *ch, rt_int32_t timeout)
|
||||||
|
{
|
||||||
|
rt_err_t result = RT_EOK;
|
||||||
|
|
||||||
|
while (rt_device_read(rt_bt_device, 0, ch, 1) == 0)
|
||||||
|
{
|
||||||
|
result = rt_sem_take(&bt_rx_sem, rt_tick_from_millisecond(timeout));
|
||||||
|
if (result != RT_EOK)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return RT_EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int bt_recv_readline(bt_device *dev)
|
||||||
|
{
|
||||||
|
rt_size_t read_len = 0;
|
||||||
|
char ch = 0, last_ch = 0;
|
||||||
|
rt_bool_t is_full = RT_FALSE;
|
||||||
|
rt_err_t result = RT_EOK;
|
||||||
|
char bt_data[128] = {0};
|
||||||
|
rt_memset(dev->recv_line_buf, 0x00, dev->recv_bufsz);
|
||||||
|
dev->recv_line_len = 0;
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
result = bt_getchar(&ch, RT_WAITING_FOREVER);
|
||||||
|
if (result != RT_EOK)
|
||||||
|
{
|
||||||
|
LOG_D("get sem bt_rx_sem error");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (read_len < dev->recv_bufsz)
|
||||||
|
{
|
||||||
|
bt_data[read_len++] = ch;
|
||||||
|
dev->recv_line_len = read_len;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
is_full = RT_TRUE;
|
||||||
|
}
|
||||||
|
if (ch == '\n' && last_ch == '\r')
|
||||||
|
{
|
||||||
|
bt_data[dev->recv_line_len - 1] = '\0';
|
||||||
|
rt_memcpy(dev->recv_line_buf, bt_data, read_len);
|
||||||
|
rt_memset(bt_data, 0, dev->recv_line_len);
|
||||||
|
if (is_full)
|
||||||
|
{
|
||||||
|
LOG_E("read line failed. The line data length is out of buffer size(%d)!", dev->recv_bufsz);
|
||||||
|
rt_memset(dev->recv_line_buf, 0x00, dev->recv_bufsz);
|
||||||
|
dev->recv_line_len = 0;
|
||||||
|
return -RT_EFULL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
last_ch = ch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return read_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Bt_Thread_Entry(void *parameter)
|
||||||
|
{
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
if (bt_recv_readline(&bt) > 0)
|
||||||
|
{
|
||||||
|
LOG_D("bt recv data: %s", bt.recv_line_buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 接收数据回调函数 */
|
||||||
|
static rt_err_t Bt_Rcv_Cb(rt_device_t dev, rt_size_t size)
|
||||||
|
{
|
||||||
|
rt_sem_release(&bt_rx_sem);
|
||||||
|
|
||||||
|
return RT_EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int BSP_Bt_Init(void)
|
||||||
|
{
|
||||||
|
rt_err_t ret = RT_EOK;
|
||||||
|
|
||||||
|
/* 查找系统中的串口设备 */
|
||||||
|
rt_bt_device = rt_device_find(BT_UART);
|
||||||
|
if (!rt_bt_device)
|
||||||
|
{
|
||||||
|
LOG_E("find %s failed!\n", BT_UART);
|
||||||
|
return RT_ERROR;
|
||||||
|
}
|
||||||
|
/* 以中断接收模式打开串口设备 */
|
||||||
|
if (rt_device_open(rt_bt_device, RT_DEVICE_FLAG_INT_RX) != RT_EOK)
|
||||||
|
{
|
||||||
|
LOG_E("rt_device_open failed!\n");
|
||||||
|
return RT_ERROR;
|
||||||
|
}
|
||||||
|
rt_sem_init(&bt_rx_sem, "bt_rx_sem", 0, RT_IPC_FLAG_PRIO); /* 初始化信号量 */
|
||||||
|
/* 设置接收回调函数 */
|
||||||
|
if (rt_device_set_rx_indicate(rt_bt_device, Bt_Rcv_Cb) != RT_EOK)
|
||||||
|
{
|
||||||
|
LOG_E("rt_device_set_rx_indicate failed!\n");
|
||||||
|
return RT_ERROR;
|
||||||
|
}
|
||||||
|
/* 静态初始化线程 1*/
|
||||||
|
ret = rt_thread_init(&bt_thread, // 该线程用于数据解析
|
||||||
|
"bt_thread",
|
||||||
|
Bt_Thread_Entry,
|
||||||
|
RT_NULL,
|
||||||
|
&bt_thread_stack[0],
|
||||||
|
sizeof(bt_thread_stack),
|
||||||
|
BT_THREAD_PRIORITY,
|
||||||
|
BT_THREAD_TIMESLICE);
|
||||||
|
/* 创建成功则启动线程 */
|
||||||
|
rt_thread_startup(&bt_thread);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
INIT_DEVICE_EXPORT(BSP_Bt_Init);
|
||||||
|
|
|
@ -82,9 +82,9 @@ static rt_base_t interrupt_value;
|
||||||
rt_uint8_t sys_hw_ver = 0x10;
|
rt_uint8_t sys_hw_ver = 0x10;
|
||||||
rt_uint8_t sys_sw_ver = 0x11;
|
rt_uint8_t sys_sw_ver = 0x11;
|
||||||
rt_uint8_t sys_nb_retry = 0x03; // 重试次数3次
|
rt_uint8_t sys_nb_retry = 0x03; // 重试次数3次
|
||||||
rt_uint16_t sys_nb_upload_cycle = 0x0001; // 120分钟一次
|
rt_uint16_t sys_nb_upload_cycle = 0x0078; // 120分钟一次
|
||||||
rt_uint16_t sys_alarm_h_value = 0x0032; // 50
|
rt_uint16_t sys_alarm_h_value = 0x0032; // 50
|
||||||
rt_uint16_t sys_alarm_l_value = 0x09C4; // 10
|
rt_uint16_t sys_alarm_l_value = 0x09C4; // 2500
|
||||||
rt_uint8_t sys_temp_alarm_threshold = 0x32;
|
rt_uint8_t sys_temp_alarm_threshold = 0x32;
|
||||||
rt_uint8_t sys_emagnetic_switch = 0x04; // 具备阀门功能
|
rt_uint8_t sys_emagnetic_switch = 0x04; // 具备阀门功能
|
||||||
rt_uint8_t sys_relay_switch = 0x04; // 具备继电器功能
|
rt_uint8_t sys_relay_switch = 0x04; // 具备继电器功能
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* @Author : stark1898y 1658608470@qq.com
|
* @Author : stark1898y 1658608470@qq.com
|
||||||
* @Date : 2024-06-18 15:48:01
|
* @Date : 2024-06-18 15:48:01
|
||||||
* @LastEditors: mbw && 1600520629@qq.com
|
* @LastEditors: mbw && 1600520629@qq.com
|
||||||
* @LastEditTime: 2024-12-05 16:44:14
|
* @LastEditTime: 2024-12-06 16:09:12
|
||||||
* @FilePath: \ble_bjq_ch303rct6_ml307\bsp\src\bsp_mq.c
|
* @FilePath: \ble_bjq_ch303rct6_ml307\bsp\src\bsp_mq.c
|
||||||
* @Description :
|
* @Description :
|
||||||
*
|
*
|
||||||
|
@ -39,7 +39,7 @@ TsSensor_t Sensor_device;
|
||||||
uint16_t Get_Gas_VoltageInt1000x(void)
|
uint16_t Get_Gas_VoltageInt1000x(void)
|
||||||
{
|
{
|
||||||
uint16_t voltage = (Get_ADC_Average(kGasAdc) * 3.3 / 4096) * MQ_VOLTAGE_RATIO * 1000;
|
uint16_t voltage = (Get_ADC_Average(kGasAdc) * 3.3 / 4096) * MQ_VOLTAGE_RATIO * 1000;
|
||||||
LOG_D("Get_Gas_VoltageInt1000x = %04d", voltage);
|
// LOG_D("Get_Gas_VoltageInt1000x = %04d", voltage);
|
||||||
return voltage;
|
return voltage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue