forked from mfulz_github/qmk_firmware
		
	Reduce the amount of inlining of core Endpoint functions for XMEGA, to reduce the compiled code size (size/speed tradeoff).
This commit is contained in:
		
							parent
							
								
									70c59a7e42
								
							
						
					
					
						commit
						b6a38164bd
					
				| @ -48,6 +48,106 @@ volatile uint8_t          USB_Endpoint_SelectedEndpoint; | |||||||
| volatile USB_EP_t*        USB_Endpoint_SelectedHandle; | volatile USB_EP_t*        USB_Endpoint_SelectedHandle; | ||||||
| volatile Endpoint_FIFO_t* USB_Endpoint_SelectedFIFO; | volatile Endpoint_FIFO_t* USB_Endpoint_SelectedFIFO; | ||||||
| 
 | 
 | ||||||
|  | bool Endpoint_IsINReady(void) | ||||||
|  | { | ||||||
|  | 	Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint | ENDPOINT_DIR_IN); | ||||||
|  | 
 | ||||||
|  | 	return ((USB_Endpoint_SelectedHandle->STATUS & USB_EP_BUSNACK0_bm) ? true : false); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | bool Endpoint_IsOUTReceived(void) | ||||||
|  | { | ||||||
|  | 	Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint & ~ENDPOINT_DIR_IN); | ||||||
|  | 
 | ||||||
|  | 	if (USB_Endpoint_SelectedHandle->STATUS & USB_EP_TRNCOMPL0_bm) | ||||||
|  | 	{ | ||||||
|  | 		USB_Endpoint_SelectedFIFO->Length = USB_Endpoint_SelectedHandle->CNT; | ||||||
|  | 		return true; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return false; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | bool Endpoint_IsSETUPReceived(void) | ||||||
|  | { | ||||||
|  | 	Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint & ~ENDPOINT_DIR_IN); | ||||||
|  | 
 | ||||||
|  | 	if (USB_Endpoint_SelectedHandle->STATUS & USB_EP_SETUP_bm) | ||||||
|  | 	{ | ||||||
|  | 		USB_Endpoint_SelectedFIFO->Length = USB_Endpoint_SelectedHandle->CNT; | ||||||
|  | 		return true; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return false; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void Endpoint_ClearSETUP(void) | ||||||
|  | { | ||||||
|  | 	Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint & ~ENDPOINT_DIR_IN); | ||||||
|  | 	USB_Endpoint_SelectedHandle->STATUS &= ~(USB_EP_SETUP_bm | USB_EP_TRNCOMPL0_bm | USB_EP_BUSNACK0_bm | USB_EP_OVF_bm); | ||||||
|  | 	USB_Endpoint_SelectedHandle->STATUS |= USB_EP_TOGGLE_bm; | ||||||
|  | 	USB_Endpoint_SelectedFIFO->Position  = 0; | ||||||
|  | 
 | ||||||
|  | 	Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint | ENDPOINT_DIR_IN); | ||||||
|  | 	USB_Endpoint_SelectedHandle->STATUS |= USB_EP_TOGGLE_bm; | ||||||
|  | 	USB_Endpoint_SelectedFIFO->Position  = 0; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void Endpoint_ClearIN(void) | ||||||
|  | { | ||||||
|  | 	USB_Endpoint_SelectedHandle->CNT     = USB_Endpoint_SelectedFIFO->Position; | ||||||
|  | 	USB_Endpoint_SelectedHandle->STATUS &= ~(USB_EP_TRNCOMPL0_bm | USB_EP_BUSNACK0_bm | USB_EP_OVF_bm); | ||||||
|  | 	USB_Endpoint_SelectedFIFO->Position  = 0; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void Endpoint_ClearOUT(void) | ||||||
|  | { | ||||||
|  | 	USB_Endpoint_SelectedHandle->STATUS &= ~(USB_EP_TRNCOMPL0_bm | USB_EP_BUSNACK0_bm | USB_EP_OVF_bm); | ||||||
|  | 	USB_Endpoint_SelectedFIFO->Position  = 0; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void Endpoint_StallTransaction(void) | ||||||
|  | { | ||||||
|  | 	USB_Endpoint_SelectedHandle->CTRL |= USB_EP_STALL_bm; | ||||||
|  | 
 | ||||||
|  | 	if ((USB_Endpoint_SelectedHandle->CTRL & USB_EP_TYPE_gm) == USB_EP_TYPE_CONTROL_gc) | ||||||
|  | 	{ | ||||||
|  | 		Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint ^ ENDPOINT_DIR_IN); | ||||||
|  | 		USB_Endpoint_SelectedHandle->CTRL |= USB_EP_STALL_bm; | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | uint8_t Endpoint_Read_8(void) | ||||||
|  | { | ||||||
|  | 	return USB_Endpoint_SelectedFIFO->Data[USB_Endpoint_SelectedFIFO->Position++]; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void Endpoint_Write_8(const uint8_t Data) | ||||||
|  | { | ||||||
|  | 	USB_Endpoint_SelectedFIFO->Data[USB_Endpoint_SelectedFIFO->Position++] = Data; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void Endpoint_SelectEndpoint(const uint8_t Address) | ||||||
|  | { | ||||||
|  | 	uint8_t EndpointNumber = (Address & ENDPOINT_EPNUM_MASK); | ||||||
|  | 
 | ||||||
|  | 	USB_Endpoint_SelectedEndpoint = Address; | ||||||
|  | 
 | ||||||
|  | 	Endpoint_FIFOPair_t* EndpointFIFOPair = &USB_Endpoint_FIFOs[EndpointNumber]; | ||||||
|  | 	USB_EndpointTable_t* EndpointTable    = (USB_EndpointTable_t*)USB.EPPTR; | ||||||
|  | 
 | ||||||
|  | 	if (Address & ENDPOINT_DIR_IN) | ||||||
|  | 	{ | ||||||
|  | 		USB_Endpoint_SelectedFIFO   = &EndpointFIFOPair->IN; | ||||||
|  | 		USB_Endpoint_SelectedHandle = &EndpointTable->Endpoints[EndpointNumber].IN; | ||||||
|  | 	} | ||||||
|  | 	else | ||||||
|  | 	{ | ||||||
|  | 		USB_Endpoint_SelectedFIFO   = &EndpointFIFOPair->OUT; | ||||||
|  | 		USB_Endpoint_SelectedHandle = &EndpointTable->Endpoints[EndpointNumber].OUT; | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
| bool Endpoint_ConfigureEndpointTable(const USB_Endpoint_Table_t* const Table, | bool Endpoint_ConfigureEndpointTable(const USB_Endpoint_Table_t* const Table, | ||||||
|                                      const uint8_t Entries) |                                      const uint8_t Entries) | ||||||
| { | { | ||||||
| @ -55,13 +155,13 @@ bool Endpoint_ConfigureEndpointTable(const USB_Endpoint_Table_t* const Table, | |||||||
| 	{ | 	{ | ||||||
| 		if (!(Table[i].Address)) | 		if (!(Table[i].Address)) | ||||||
| 		  continue; | 		  continue; | ||||||
| 	 | 
 | ||||||
| 		if (!(Endpoint_ConfigureEndpoint(Table[i].Address, Table[i].Type, Table[i].Size, Table[i].Banks))) | 		if (!(Endpoint_ConfigureEndpoint(Table[i].Address, Table[i].Type, Table[i].Size, Table[i].Banks))) | ||||||
| 		{ | 		{ | ||||||
| 			return false; | 			return false; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	 | 
 | ||||||
| 	return true; | 	return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -192,24 +192,7 @@ | |||||||
| 			 * | 			 * | ||||||
| 			 *  \param[in] Address  Endpoint address to select. | 			 *  \param[in] Address  Endpoint address to select. | ||||||
| 			 */ | 			 */ | ||||||
| 			static inline void Endpoint_SelectEndpoint(const uint8_t Address); | 			void Endpoint_SelectEndpoint(const uint8_t Address); | ||||||
| 			static inline void Endpoint_SelectEndpoint(const uint8_t Address) |  | ||||||
| 			{ |  | ||||||
| 				uint8_t EndpointNumber = (Address & ENDPOINT_EPNUM_MASK); |  | ||||||
| 
 |  | ||||||
| 				USB_Endpoint_SelectedEndpoint = Address; |  | ||||||
| 
 |  | ||||||
| 				if (Address & ENDPOINT_DIR_IN) |  | ||||||
| 				{ |  | ||||||
| 					USB_Endpoint_SelectedFIFO   = &USB_Endpoint_FIFOs[EndpointNumber].IN; |  | ||||||
| 					USB_Endpoint_SelectedHandle = &((USB_EndpointTable_t*)USB.EPPTR)->Endpoints[EndpointNumber].IN; |  | ||||||
| 				} |  | ||||||
| 				else |  | ||||||
| 				{ |  | ||||||
| 					USB_Endpoint_SelectedFIFO   = &USB_Endpoint_FIFOs[EndpointNumber].OUT; |  | ||||||
| 					USB_Endpoint_SelectedHandle = &((USB_EndpointTable_t*)USB.EPPTR)->Endpoints[EndpointNumber].OUT; |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 
 | 
 | ||||||
| 			/** Configures the specified endpoint address with the given endpoint type, direction, bank size
 | 			/** Configures the specified endpoint address with the given endpoint type, direction, bank size
 | ||||||
| 			 *  and banking mode. Once configured, the endpoint may be read from or written to, depending | 			 *  and banking mode. Once configured, the endpoint may be read from or written to, depending | ||||||
| @ -369,13 +352,7 @@ | |||||||
| 			 * | 			 * | ||||||
| 			 *  \return Boolean \c true if the current endpoint is ready for an IN packet, \c false otherwise. | 			 *  \return Boolean \c true if the current endpoint is ready for an IN packet, \c false otherwise. | ||||||
| 			 */ | 			 */ | ||||||
| 			static inline bool Endpoint_IsINReady(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; | 			bool Endpoint_IsINReady(void) ATTR_WARN_UNUSED_RESULT; | ||||||
| 			static inline bool Endpoint_IsINReady(void) |  | ||||||
| 			{ |  | ||||||
| 				Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint | ENDPOINT_DIR_IN); |  | ||||||
| 
 |  | ||||||
| 				return ((USB_Endpoint_SelectedHandle->STATUS & USB_EP_BUSNACK0_bm) ? true : false); |  | ||||||
| 			} |  | ||||||
| 
 | 
 | ||||||
| 			/** Determines if the selected OUT endpoint has received new packet from the host.
 | 			/** Determines if the selected OUT endpoint has received new packet from the host.
 | ||||||
| 			 * | 			 * | ||||||
| @ -383,19 +360,7 @@ | |||||||
| 			 * | 			 * | ||||||
| 			 *  \return Boolean \c true if current endpoint is has received an OUT packet, \c false otherwise. | 			 *  \return Boolean \c true if current endpoint is has received an OUT packet, \c false otherwise. | ||||||
| 			 */ | 			 */ | ||||||
| 			static inline bool Endpoint_IsOUTReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; | 			bool Endpoint_IsOUTReceived(void) ATTR_WARN_UNUSED_RESULT; | ||||||
| 			static inline bool Endpoint_IsOUTReceived(void) |  | ||||||
| 			{ |  | ||||||
| 				Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint & ~ENDPOINT_DIR_IN); |  | ||||||
| 
 |  | ||||||
| 				if (USB_Endpoint_SelectedHandle->STATUS & USB_EP_TRNCOMPL0_bm) |  | ||||||
| 				{ |  | ||||||
| 					USB_Endpoint_SelectedFIFO->Length = USB_Endpoint_SelectedHandle->CNT; |  | ||||||
| 					return true; |  | ||||||
| 				} |  | ||||||
| 
 |  | ||||||
| 				return false; |  | ||||||
| 			} |  | ||||||
| 
 | 
 | ||||||
| 			/** Determines if the current CONTROL type endpoint has received a SETUP packet.
 | 			/** Determines if the current CONTROL type endpoint has received a SETUP packet.
 | ||||||
| 			 * | 			 * | ||||||
| @ -403,19 +368,7 @@ | |||||||
| 			 * | 			 * | ||||||
| 			 *  \return Boolean \c true if the selected endpoint has received a SETUP packet, \c false otherwise. | 			 *  \return Boolean \c true if the selected endpoint has received a SETUP packet, \c false otherwise. | ||||||
| 			 */ | 			 */ | ||||||
| 			static inline bool Endpoint_IsSETUPReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; | 			bool Endpoint_IsSETUPReceived(void) ATTR_WARN_UNUSED_RESULT; | ||||||
| 			static inline bool Endpoint_IsSETUPReceived(void) |  | ||||||
| 			{ |  | ||||||
| 				Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint & ~ENDPOINT_DIR_IN); |  | ||||||
| 
 |  | ||||||
| 				if (USB_Endpoint_SelectedHandle->STATUS & USB_EP_SETUP_bm) |  | ||||||
| 				{ |  | ||||||
| 					USB_Endpoint_SelectedFIFO->Length = USB_Endpoint_SelectedHandle->CNT; |  | ||||||
| 					return true; |  | ||||||
| 				} |  | ||||||
| 
 |  | ||||||
| 				return false; |  | ||||||
| 			} |  | ||||||
| 
 | 
 | ||||||
| 			/** Clears a received SETUP packet on the currently selected CONTROL type endpoint, freeing up the
 | 			/** Clears a received SETUP packet on the currently selected CONTROL type endpoint, freeing up the
 | ||||||
| 			 *  endpoint for the next packet. | 			 *  endpoint for the next packet. | ||||||
| @ -424,43 +377,21 @@ | |||||||
| 			 * | 			 * | ||||||
| 			 *  \note This is not applicable for non CONTROL type endpoints. | 			 *  \note This is not applicable for non CONTROL type endpoints. | ||||||
| 			 */ | 			 */ | ||||||
| 			static inline void Endpoint_ClearSETUP(void) ATTR_ALWAYS_INLINE; | 			void Endpoint_ClearSETUP(void); | ||||||
| 			static inline void Endpoint_ClearSETUP(void) |  | ||||||
| 			{ |  | ||||||
| 				Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint & ~ENDPOINT_DIR_IN); |  | ||||||
| 				USB_Endpoint_SelectedHandle->STATUS &= ~(USB_EP_SETUP_bm | USB_EP_TRNCOMPL0_bm | USB_EP_BUSNACK0_bm | USB_EP_OVF_bm); |  | ||||||
| 				USB_Endpoint_SelectedHandle->STATUS |= USB_EP_TOGGLE_bm; |  | ||||||
| 				USB_Endpoint_SelectedFIFO->Position  = 0; |  | ||||||
| 
 |  | ||||||
| 				Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint | ENDPOINT_DIR_IN); |  | ||||||
| 				USB_Endpoint_SelectedHandle->STATUS |= USB_EP_TOGGLE_bm; |  | ||||||
| 				USB_Endpoint_SelectedFIFO->Position  = 0; |  | ||||||
| 			} |  | ||||||
| 
 | 
 | ||||||
| 			/** Sends an IN packet to the host on the currently selected endpoint, freeing up the endpoint for the
 | 			/** Sends an IN packet to the host on the currently selected endpoint, freeing up the endpoint for the
 | ||||||
| 			 *  next packet and switching to the alternative endpoint bank if double banked. | 			 *  next packet and switching to the alternative endpoint bank if double banked. | ||||||
| 			 * | 			 * | ||||||
| 			 *  \ingroup Group_EndpointPacketManagement_XMEGA | 			 *  \ingroup Group_EndpointPacketManagement_XMEGA | ||||||
| 			 */ | 			 */ | ||||||
| 			static inline void Endpoint_ClearIN(void) ATTR_ALWAYS_INLINE; | 			void Endpoint_ClearIN(void); | ||||||
| 			static inline void Endpoint_ClearIN(void) |  | ||||||
| 			{ |  | ||||||
| 				USB_Endpoint_SelectedHandle->CNT     = USB_Endpoint_SelectedFIFO->Position; |  | ||||||
| 				USB_Endpoint_SelectedHandle->STATUS &= ~(USB_EP_TRNCOMPL0_bm | USB_EP_BUSNACK0_bm | USB_EP_OVF_bm); |  | ||||||
| 				USB_Endpoint_SelectedFIFO->Position  = 0; |  | ||||||
| 			} |  | ||||||
| 
 | 
 | ||||||
| 			/** Acknowledges an OUT packet to the host on the currently selected endpoint, freeing up the endpoint
 | 			/** Acknowledges an OUT packet to the host on the currently selected endpoint, freeing up the endpoint
 | ||||||
| 			 *  for the next packet and switching to the alternative endpoint bank if double banked. | 			 *  for the next packet and switching to the alternative endpoint bank if double banked. | ||||||
| 			 * | 			 * | ||||||
| 			 *  \ingroup Group_EndpointPacketManagement_XMEGA | 			 *  \ingroup Group_EndpointPacketManagement_XMEGA | ||||||
| 			 */ | 			 */ | ||||||
| 			static inline void Endpoint_ClearOUT(void) ATTR_ALWAYS_INLINE; | 			void Endpoint_ClearOUT(void); | ||||||
| 			static inline void Endpoint_ClearOUT(void) |  | ||||||
| 			{ |  | ||||||
| 				USB_Endpoint_SelectedHandle->STATUS &= ~(USB_EP_TRNCOMPL0_bm | USB_EP_BUSNACK0_bm | USB_EP_OVF_bm); |  | ||||||
| 				USB_Endpoint_SelectedFIFO->Position  = 0; |  | ||||||
| 			} |  | ||||||
| 
 | 
 | ||||||
| 			/** Stalls the current endpoint, indicating to the host that a logical problem occurred with the
 | 			/** Stalls the current endpoint, indicating to the host that a logical problem occurred with the
 | ||||||
| 			 *  indicated endpoint and that the current transfer sequence should be aborted. This provides a | 			 *  indicated endpoint and that the current transfer sequence should be aborted. This provides a | ||||||
| @ -473,17 +404,7 @@ | |||||||
| 			 * | 			 * | ||||||
| 			 *  \ingroup Group_EndpointPacketManagement_XMEGA | 			 *  \ingroup Group_EndpointPacketManagement_XMEGA | ||||||
| 			 */ | 			 */ | ||||||
| 			static inline void Endpoint_StallTransaction(void) ATTR_ALWAYS_INLINE; | 			void Endpoint_StallTransaction(void); | ||||||
| 			static inline void Endpoint_StallTransaction(void) |  | ||||||
| 			{ |  | ||||||
| 				USB_Endpoint_SelectedHandle->CTRL |= USB_EP_STALL_bm; |  | ||||||
| 
 |  | ||||||
| 				if ((USB_Endpoint_SelectedHandle->CTRL & USB_EP_TYPE_gm) == USB_EP_TYPE_CONTROL_gc) |  | ||||||
| 				{ |  | ||||||
| 					Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint ^ ENDPOINT_DIR_IN); |  | ||||||
| 					USB_Endpoint_SelectedHandle->CTRL |= USB_EP_STALL_bm; |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 
 | 
 | ||||||
| 			/** Clears the STALL condition on the currently selected endpoint.
 | 			/** Clears the STALL condition on the currently selected endpoint.
 | ||||||
| 			 * | 			 * | ||||||
| @ -530,11 +451,7 @@ | |||||||
| 			 * | 			 * | ||||||
| 			 *  \return Next byte in the currently selected endpoint's FIFO buffer. | 			 *  \return Next byte in the currently selected endpoint's FIFO buffer. | ||||||
| 			 */ | 			 */ | ||||||
| 			static inline uint8_t Endpoint_Read_8(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; | 			uint8_t Endpoint_Read_8(void) ATTR_WARN_UNUSED_RESULT; | ||||||
| 			static inline uint8_t Endpoint_Read_8(void) |  | ||||||
| 			{ |  | ||||||
| 				return USB_Endpoint_SelectedFIFO->Data[USB_Endpoint_SelectedFIFO->Position++]; |  | ||||||
| 			} |  | ||||||
| 
 | 
 | ||||||
| 			/** Writes one byte to the currently selected endpoint's bank, for IN direction endpoints.
 | 			/** Writes one byte to the currently selected endpoint's bank, for IN direction endpoints.
 | ||||||
| 			 * | 			 * | ||||||
| @ -542,11 +459,7 @@ | |||||||
| 			 * | 			 * | ||||||
| 			 *  \param[in] Data  Data to write into the the currently selected endpoint's FIFO buffer. | 			 *  \param[in] Data  Data to write into the the currently selected endpoint's FIFO buffer. | ||||||
| 			 */ | 			 */ | ||||||
| 			static inline void Endpoint_Write_8(const uint8_t Data) ATTR_ALWAYS_INLINE; | 			void Endpoint_Write_8(const uint8_t Data); | ||||||
| 			static inline void Endpoint_Write_8(const uint8_t Data) |  | ||||||
| 			{ |  | ||||||
| 				USB_Endpoint_SelectedFIFO->Data[USB_Endpoint_SelectedFIFO->Position++] = Data; |  | ||||||
| 			} |  | ||||||
| 
 | 
 | ||||||
| 			/** Discards one byte from the currently selected endpoint's bank, for OUT direction endpoints.
 | 			/** Discards one byte from the currently selected endpoint's bank, for OUT direction endpoints.
 | ||||||
| 			 * | 			 * | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Dean Camera
						Dean Camera