mirror of
https://github.com/eddyem/stm32samples.git
synced 2026-03-21 17:21:04 +03:00
Fix USB HID for F103
This commit is contained in:
Binary file not shown.
@@ -193,7 +193,7 @@ int main(void){
|
||||
USB_send((uint8_t*)"USART overflow!\n", 16);
|
||||
}
|
||||
uint8_t tmpbuf[USB_RXBUFSZ], *txt;
|
||||
uint16_t x = USB_receive(tmpbuf);
|
||||
uint8_t x = USB_receive(tmpbuf);
|
||||
if(x){
|
||||
//for(int _ = 0; _ < 7000000; ++_)nop();
|
||||
//USB_send(tmpbuf, x);
|
||||
|
||||
@@ -67,7 +67,6 @@ void USB_setup(){
|
||||
DBG("USB irq enabled");
|
||||
}
|
||||
|
||||
|
||||
static int usbwr(const uint8_t *buf, uint16_t l){
|
||||
uint32_t ctra = 1000000;
|
||||
while(--ctra && tx_succesfull == 0){
|
||||
@@ -97,14 +96,14 @@ static void send_next(){
|
||||
// unblocking sending - just fill a buffer
|
||||
void USB_send(const uint8_t *buf, uint16_t len){
|
||||
if(!usbON || !len) return;
|
||||
if(len > USB_TXBUFSZ-1){
|
||||
USB_send_blk(buf, len);
|
||||
return;
|
||||
}
|
||||
if(len > USB_TXBUFSZ-1 - buflen){
|
||||
usbwr(usbbuff, buflen);
|
||||
buflen = 0;
|
||||
}
|
||||
if(len > USB_TXBUFSZ-1){
|
||||
USB_send_blk(buf, len);
|
||||
return;
|
||||
}
|
||||
while(len--) usbbuff[buflen++] = *buf++;
|
||||
}
|
||||
|
||||
@@ -128,7 +127,6 @@ void USB_send_blk(const uint8_t *buf, uint16_t len){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void usb_proc(){
|
||||
switch(USB_Dev.USB_Status){
|
||||
case USB_STATE_CONFIGURED:
|
||||
|
||||
@@ -198,6 +198,7 @@ static void wr0(const uint8_t *buf, uint16_t size){
|
||||
if(setup_packet.wLength < size) size = setup_packet.wLength; // shortened request
|
||||
if(size < endpoints[0].txbufsz){
|
||||
EP_WriteIRQ(0, buf, size);
|
||||
return;
|
||||
}
|
||||
while(size){
|
||||
uint16_t l = size;
|
||||
@@ -305,8 +306,6 @@ bmRequestType: 76543210
|
||||
*/
|
||||
/**
|
||||
* Endpoint0 (control) handler
|
||||
* @param ep - endpoint state
|
||||
* @return data written to EP0R
|
||||
*/
|
||||
static void EP0_Handler(){
|
||||
uint8_t reqtype = setup_packet.bmRequestType & 0x7f;
|
||||
@@ -487,7 +486,7 @@ void usb_lp_can_rx0_isr(){
|
||||
*/
|
||||
void EP_WriteIRQ(uint8_t number, const uint8_t *buf, uint16_t size){
|
||||
uint8_t i;
|
||||
if(size > USB_TXBUFSZ) size = USB_TXBUFSZ;
|
||||
if(size > endpoints[number].txbufsz) size = endpoints[number].txbufsz;
|
||||
uint16_t N2 = (size + 1) >> 1;
|
||||
// the buffer is 16-bit, so we should copy data as it would be uint16_t
|
||||
uint16_t *buf16 = (uint16_t *)buf;
|
||||
|
||||
Reference in New Issue
Block a user