bluetooth: extract btuart_register interface
add btuart_create interface, which would be more flexible in complex cases. And extract btuart_register interface. Signed-off-by: chengkai <chengkai@xiaomi.com>
This commit is contained in:
parent
cae60fb4a0
commit
3144971704
5 changed files with 70 additions and 45 deletions
|
@ -326,3 +326,39 @@ int btuart_ioctl(FAR struct bt_driver_s *dev,
|
|||
return -ENOTTY;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: btuart_register
|
||||
*
|
||||
* Description:
|
||||
* Register the UART-based bluetooth driver.
|
||||
*
|
||||
* Input Parameters:
|
||||
* lower - an instance of the lower half driver interface
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned on success; a negated errno value is returned on any
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int btuart_register(FAR const struct btuart_lowerhalf_s *lower)
|
||||
{
|
||||
FAR struct bt_driver_s *driver;
|
||||
int ret;
|
||||
|
||||
ret = btuart_create(lower, &driver);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = bt_netdev_register(driver);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: bt_netdev_register failed: %d\n", ret);
|
||||
kmm_free(driver);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -379,10 +379,9 @@ load_bcm4343x_firmware_finished:
|
|||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: btuart_register
|
||||
* Name: btuart_create
|
||||
*
|
||||
* Create the UART-based Bluetooth device and register it with the
|
||||
* Bluetooth stack.
|
||||
* Create the UART-based bluetooth device.
|
||||
*
|
||||
* Input Parameters:
|
||||
* lower - an instance of the lower half driver interface
|
||||
|
@ -393,7 +392,8 @@ load_bcm4343x_firmware_finished:
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
int btuart_register(FAR const struct btuart_lowerhalf_s *lower)
|
||||
int btuart_create(FAR const struct btuart_lowerhalf_s *lower,
|
||||
FAR struct bt_driver_s **driver)
|
||||
{
|
||||
FAR struct btuart_upperhalf_s *upper;
|
||||
int ret;
|
||||
|
@ -436,14 +436,6 @@ int btuart_register(FAR const struct btuart_lowerhalf_s *lower)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* And register the driver with the network and the Bluetooth stack. */
|
||||
|
||||
ret = bt_netdev_register(&upper->dev);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: bt_netdev_register failed: %d\n", ret);
|
||||
kmm_free(upper);
|
||||
}
|
||||
|
||||
*driver = &upper->dev;
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -145,11 +145,9 @@ int load_cc2564_firmware(FAR const struct btuart_lowerhalf_s *lower)
|
|||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: btuart_register
|
||||
* Name: btuart_create
|
||||
*
|
||||
* Description:
|
||||
* Create the UART-based Bluetooth device and register it with the
|
||||
* Bluetooth stack.
|
||||
* Create the UART-based bluetooth device.
|
||||
*
|
||||
* Input Parameters:
|
||||
* lower - an instance of the lower half driver interface
|
||||
|
@ -160,7 +158,8 @@ int load_cc2564_firmware(FAR const struct btuart_lowerhalf_s *lower)
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
int btuart_register(FAR const struct btuart_lowerhalf_s *lower)
|
||||
int btuart_create(FAR const struct btuart_lowerhalf_s *lower,
|
||||
FAR struct bt_driver_s **driver)
|
||||
{
|
||||
FAR struct btuart_upperhalf_s *upper;
|
||||
int ret;
|
||||
|
@ -203,14 +202,6 @@ int btuart_register(FAR const struct btuart_lowerhalf_s *lower)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* And register the driver with the network and the Bluetooth stack. */
|
||||
|
||||
ret = bt_netdev_register(&upper->dev);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: bt_netdev_register failed: %d\n", ret);
|
||||
kmm_free(upper);
|
||||
}
|
||||
|
||||
*driver = &upper->dev;
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -39,11 +39,9 @@
|
|||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: btuart_register
|
||||
* Name: btuart_create
|
||||
*
|
||||
* Description:
|
||||
* Create the UART-based Bluetooth device and register it with the
|
||||
* Bluetooth stack.
|
||||
* Create the UART-based bluetooth device.
|
||||
*
|
||||
* Input Parameters:
|
||||
* lower - an instance of the lower half driver interface
|
||||
|
@ -54,10 +52,10 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
int btuart_register(FAR const struct btuart_lowerhalf_s *lower)
|
||||
int btuart_create(FAR const struct btuart_lowerhalf_s *lower,
|
||||
FAR struct bt_driver_s **driver)
|
||||
{
|
||||
FAR struct btuart_upperhalf_s *upper;
|
||||
int ret;
|
||||
|
||||
wlinfo("lower %p\n", lower);
|
||||
|
||||
|
@ -87,14 +85,6 @@ int btuart_register(FAR const struct btuart_lowerhalf_s *lower)
|
|||
upper->dev.ioctl = btuart_ioctl;
|
||||
upper->lower = lower;
|
||||
|
||||
/* And register the driver with the network and the Bluetooth stack. */
|
||||
|
||||
ret = bt_netdev_register(&upper->dev);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: bt_netdev_registe failed: %d\n", ret);
|
||||
kmm_free(upper);
|
||||
}
|
||||
|
||||
return ret;
|
||||
*driver = &upper->dev;
|
||||
return OK;
|
||||
}
|
||||
|
|
|
@ -148,12 +148,28 @@ struct btuart_lowerhalf_s
|
|||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: btuart_create
|
||||
*
|
||||
* Create the UART-based Bluetooth device.
|
||||
*
|
||||
* Input Parameters:
|
||||
* lower - an instance of the lower half driver interface
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned on success; a negated errno value is returned on any
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int btuart_create(FAR const struct btuart_lowerhalf_s *lower,
|
||||
FAR struct bt_driver_s **driver);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: btuart_register
|
||||
*
|
||||
* Description:
|
||||
* Create the generic UART-based Bluetooth device and register it with the
|
||||
* Bluetooth stack.
|
||||
* Register the generic UART-based bluetooth driver.
|
||||
*
|
||||
* Input Parameters:
|
||||
* lower - an instance of the lower half driver interface
|
||||
|
|
Loading…
Reference in a new issue