Hierodule 1.6.2
Utility module set for STM32 MCUs
Loading...
Searching...
No Matches
hierodule_usb.c
Go to the documentation of this file.
1
12#include <hierodule_usb.h>
13
28
44
58{
59 if(Wrapper.RX_New > 0)
60 {
62
63 return Wrapper.RX_Buffer
64 [
67 ];
68 }
69 else
70 {
71 return 0;
72 }
73}
74
78void HIERODULE_USB_InitWrapper(uint16_t RX_BufferSize, void (*TC_Handler)(void) )
79{
80 Wrapper.RX_Index = 0;
81 Wrapper.RX_New = 0;
82
83 Wrapper.RX_BufferSize = RX_BufferSize;
84 Wrapper.RX_Buffer = (uint8_t*)malloc( (Wrapper.RX_BufferSize) * sizeof(uint8_t));
85 for( uint16_t _rxb_init = 0 ; _rxb_init < Wrapper.RX_BufferSize ; _rxb_init++ )
86 {
87 (Wrapper.RX_Buffer)[_rxb_init] = '\0';
88 }
89
90 Wrapper.TC_Handler = TC_Handler;
91}
92
96{
97 free(Wrapper.RX_Buffer);
98 Wrapper.RX_Buffer = NULL;
99}
100
104void HIERODULE_USB_TransmitPackage(uint8_t *TX_Buffer, uint32_t Size)
105{
107 #ifdef __USBD_CDC_IF_H__
108 CDC_Transmit_FS(TX_Buffer, Size);
110 #endif
111}
112
116void HIERODULE_USB_Receive_Callback(uint8_t *Buf, uint32_t *Len)
117{
118 for(uint32_t _b = 0 ; _b < *Len ; _b++)
119 {
120 AppendToBuffer( Buf[_b] );
121 }
122
123 if(Wrapper.TC_Handler != NULL)
124 {
126 }
127}
128
void AppendToBuffer(uint8_t byte)
Appends a byte to the RX ring buffer.
HIERODULE_USB_Wrapper Wrapper
Actual declaration for the Wrapper in the source file.
uint8_t HIERODULE_USB_GetNextByte(void)
Fetches the next byte in the RX ring buffer.
void HIERODULE_USB_InitWrapper(uint16_t RX_BufferSize, void(*TC_Handler)(void))
Initializes the wrapper for the USB peripheral.
void HIERODULE_USB_TransmitPackage(uint8_t *TX_Buffer, uint32_t Size)
Sets up the data to be transmitted.
void HIERODULE_USB_Receive_Callback(uint8_t *Buf, uint32_t *Len)
Callback function that updates the ring buffer and invokes TC_Handler if it's not NULL.
void HIERODULE_USB_ReleaseWrapper(void)
De-initializes the wrapper for the USB peripheral.
: Header file for the USB module.
Struct that keeps variables for the ring buffer and a pointer to the transmission end callback routin...
uint8_t * RX_Buffer
The ring buffer where the data received is appended.
uint32_t RX_New
Number of new bytes in the ring buffer.
uint16_t RX_BufferSize
Number of elements in the ring buffer.
void(* TC_Handler)(void)
Pointer to the callback function to be called on a completed transmission.
uint32_t RX_Index
Index of next-byte-to-be-received in the ring buffer.