117 lines
2.9 KiB
C
117 lines
2.9 KiB
C
#include "device.h"
|
|
#include "config/board_config.h"
|
|
|
|
uint8_t device_init(device_t *port)
|
|
{
|
|
uint8_t res = DEVICE_OK;
|
|
#if UART_ENABLE
|
|
res = uart_init(&port->init_device);
|
|
if(res)
|
|
{
|
|
SYS_LOG_WRN("device start uart error");
|
|
return DEVICE_UART_ERROR;
|
|
}
|
|
#endif
|
|
#if BLE_ENABLE
|
|
res = ble_init(&port->init_device);
|
|
if(res)
|
|
{
|
|
SYS_LOG_WRN("ble init error");
|
|
return DEVICE_BLE_ERROR;
|
|
}
|
|
#endif
|
|
#if WIFI_ENABLE
|
|
res = wifi_init(&port->init_device);
|
|
if(res)
|
|
{
|
|
SYS_LOG_WRN("wifi init error");
|
|
return DEVICE_WIFI_ERROR;
|
|
}
|
|
#endif
|
|
//默认选择串口
|
|
res = embedded_device_choice(port, DATA_PORT_TYPE_UART);
|
|
if(res == DEVICE_EMBEDDED_ERROR)
|
|
{
|
|
SYS_LOG_ERR("embedded device choice error");
|
|
}
|
|
|
|
return DEVICE_OK;
|
|
}
|
|
uint8_t uart_init(init_device_t *port)
|
|
{
|
|
// port->uart_port = sb_uart_port_bind(g_cfg_board->uart_fc.id, g_cfg_board->uart_fc.br, g_cfg_board->uart_fc.pin_txd.pin, g_cfg_board->uart_fc.pin_rxd.pin, g_cfg_board->uart_fc.irq_prior, 1024, 0, NULL);
|
|
port->uart_port = sb_uart_port_bind(1, 115200, 0, 10, 21, 1024, 0, NULL);
|
|
|
|
if(port->uart_port == NULL)
|
|
{
|
|
SYS_LOG_WRN("uart init error");
|
|
return 1;
|
|
}
|
|
if(sb_data_port_start(port->uart_port))
|
|
{
|
|
SYS_LOG_WRN("uart start error");
|
|
return 1;
|
|
}
|
|
return DEVICE_OK;
|
|
}
|
|
|
|
uint8_t ble_init(init_device_t *port)
|
|
{
|
|
return DEVICE_OK;
|
|
}
|
|
|
|
uint8_t wifi_init(init_device_t *port)
|
|
{
|
|
return DEVICE_OK;
|
|
}
|
|
|
|
uint8_t embedded_device_choice(device_t *port, uint8_t type)
|
|
{
|
|
//端口与PC一致
|
|
if(port->pc_device_type == type)
|
|
{
|
|
SYS_LOG_WRN("pc Port consistency");
|
|
return DEVICE_WRN_EMBEDDED_TYPE;
|
|
}
|
|
|
|
port->embedded_device_type = type;
|
|
switch (port->embedded_device_type)
|
|
{
|
|
case DATA_PORT_TYPE_UART:
|
|
port->embedded_device = port->init_device.uart_port;
|
|
break;
|
|
case DATA_PORT_TYPE_WIFI:
|
|
port->embedded_device = port->init_device.wifi;
|
|
break;
|
|
case DATA_PORT_TYPE_BLE_CMD:
|
|
port->embedded_device = port->init_device.ble_spp_server_cmd;
|
|
break;
|
|
case DATA_PORT_TYPE_BLE_VAL:
|
|
port->embedded_device = port->init_device.ble_spp_server_val;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
if(port->embedded_device == NULL)
|
|
{
|
|
SYS_LOG_WRN("embedded device choice error");
|
|
return DEVICE_EMBEDDED_ERROR;
|
|
}
|
|
|
|
return DEVICE_OK;
|
|
}
|
|
|
|
int embedded_device_read(device_t *port, void *buffer, uint32_t length)
|
|
{
|
|
return sb_data_port_read(port->embedded_device, buffer, length, 0);
|
|
}
|
|
|
|
int embedded_device_write(device_t *port, void *buffer, uint32_t length)
|
|
{
|
|
return sb_data_port_write(port->embedded_device, buffer, length, 0);
|
|
}
|
|
uint32_t embedded_device_get_rx_length(device_t *port)
|
|
{
|
|
return sb_data_port_get_rx_length(port->embedded_device);
|
|
} |