usb: extract ST USB FS peripheral core. [BREAKING CHANGE]
The breaking changes here changes in header location, and changes in driver
name passed down to the usb stack.
Changes affect: stm32f102/f103, stm32l1, and some f3 parts
* instead of the confusingly generic "usb" use the name "st_usbfs" for the USB
Full speed peripheral ST provides in a variety of their stm32 products.
Include directives should change as:
#include <libopencm3/stm32/usb.h> => <libopencm3/stm32/st_usbfs.h>
* instead of the confusingly specific "f103" name for the driver, use
"st_usbfs_v1" [BREAKING_CHANGE]
Instead of:
usbd_init(&stm32f103_usb_driver, .....) ==>
usbd_init(&st_usbfs_v1_usb_driver, .....) ==>
The purpose of these changes is to reduce some confusion around naming, but
primarily to prepare for the "v2" peripheral available on stm32f0/l0 and some
f3 devices.
Work by Frantisek Burian, Kuldeep Singh Dhaka, Robin Kreis, fenugrec and zyp
on irc, and all those forgotten.
This commit is contained in:
86
lib/stm32/st_usbfs_v1.c
Normal file
86
lib/stm32/st_usbfs_v1.c
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Gareth McMullin <gareth@blacksphere.co.nz>
|
||||
*
|
||||
* This library is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/cm3/common.h>
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/tools.h>
|
||||
#include <libopencm3/stm32/st_usbfs.h>
|
||||
#include <libopencm3/usb/usbd.h>
|
||||
#include "../usb/usb_private.h"
|
||||
#include "common/st_usbfs_core.h"
|
||||
|
||||
static usbd_device *st_usbfs_v1_usbd_init(void);
|
||||
|
||||
const struct _usbd_driver st_usbfs_v1_usb_driver = {
|
||||
.init = st_usbfs_v1_usbd_init,
|
||||
.set_address = st_usbfs_set_address,
|
||||
.ep_setup = st_usbfs_ep_setup,
|
||||
.ep_reset = st_usbfs_endpoints_reset,
|
||||
.ep_stall_set = st_usbfs_ep_stall_set,
|
||||
.ep_stall_get = st_usbfs_ep_stall_get,
|
||||
.ep_nak_set = st_usbfs_ep_nak_set,
|
||||
.ep_write_packet = st_usbfs_ep_write_packet,
|
||||
.ep_read_packet = st_usbfs_ep_read_packet,
|
||||
.poll = st_usbfs_poll,
|
||||
};
|
||||
|
||||
/** Initialize the USB device controller hardware of the STM32. */
|
||||
static usbd_device *st_usbfs_v1_usbd_init(void)
|
||||
{
|
||||
rcc_periph_clock_enable(RCC_USB);
|
||||
SET_REG(USB_CNTR_REG, 0);
|
||||
SET_REG(USB_BTABLE_REG, 0);
|
||||
SET_REG(USB_ISTR_REG, 0);
|
||||
|
||||
/* Enable RESET, SUSPEND, RESUME and CTR interrupts. */
|
||||
SET_REG(USB_CNTR_REG, USB_CNTR_RESETM | USB_CNTR_CTRM |
|
||||
USB_CNTR_SUSPM | USB_CNTR_WKUPM);
|
||||
return &st_usbfs_dev;
|
||||
}
|
||||
|
||||
void st_usbfs_copy_to_pm(volatile void *vPM, const void *buf, uint16_t len)
|
||||
{
|
||||
const uint16_t *lbuf = buf;
|
||||
volatile uint32_t *PM = vPM;
|
||||
for (len = (len + 1) >> 1; len; len--) {
|
||||
*PM++ = *lbuf++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy a data buffer from packet memory.
|
||||
*
|
||||
* @param buf Source pointer to data buffer.
|
||||
* @param vPM Destination pointer into packet memory.
|
||||
* @param len Number of bytes to copy.
|
||||
*/
|
||||
void st_usbfs_copy_from_pm(void *buf, const volatile void *vPM, uint16_t len)
|
||||
{
|
||||
uint16_t *lbuf = buf;
|
||||
const volatile uint16_t *PM = vPM;
|
||||
uint8_t odd = len & 1;
|
||||
|
||||
for (len >>= 1; len; PM += 2, lbuf++, len--) {
|
||||
*lbuf = *PM;
|
||||
}
|
||||
|
||||
if (odd) {
|
||||
*(uint8_t *) lbuf = *(uint8_t *) PM;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user