From ebcf1978106322e92a7b1f53b58a33c6ff432cbd Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Sat, 26 May 2018 14:59:14 +0200 Subject: usb: make usb_disconnect() weak usb_disconnect() is board/platform specific for chips that don't have built-in handling for this. Allow the application to provide its own version of usb_disconnect() to handle this. See https://github.com/libopencm3/libopencm3/pull/924 --- include/libopencm3/usb/usbd.h | 7 ++++++- lib/usb/usb.c | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/libopencm3/usb/usbd.h b/include/libopencm3/usb/usbd.h index fa9af67c..04452d9b 100644 --- a/include/libopencm3/usb/usbd.h +++ b/include/libopencm3/usb/usbd.h @@ -160,7 +160,12 @@ extern void usbd_register_set_altsetting_callback(usbd_device *usbd_dev, /* Functions to be provided by the hardware abstraction layer */ extern void usbd_poll(usbd_device *usbd_dev); -/** Disconnect, if supported by the driver */ +/** Disconnect, if supported by the driver + * + * This function is implemented as weak function and can be replaced by an + * application specific version to handle chips that don't have built-in + * handling for this (e.g. STM32F1.) + */ extern void usbd_disconnect(usbd_device *usbd_dev, bool disconnected); /** Setup an endpoint diff --git a/lib/usb/usb.c b/lib/usb/usb.c index cca6dde1..e2dd0c27 100644 --- a/lib/usb/usb.c +++ b/lib/usb/usb.c @@ -112,7 +112,8 @@ void usbd_poll(usbd_device *usbd_dev) usbd_dev->driver->poll(usbd_dev); } -void usbd_disconnect(usbd_device *usbd_dev, bool disconnected) +__attribute__((weak)) void usbd_disconnect(usbd_device *usbd_dev, + bool disconnected) { /* not all drivers support disconnection */ if (usbd_dev->driver->disconnect) { -- cgit v1.2.3