mirror of
				https://github.com/mfulz/qmk_firmware.git
				synced 2025-11-04 07:12:33 +01:00 
			
		
		
		
	Minor fixes to demos to add in some missing comments, printf() formatting. Make incomplete Bluetooth demo indicate connections visually via the board LEDs.
This commit is contained in:
		
							parent
							
								
									75d440ace3
								
							
						
					
					
						commit
						931ca42a6e
					
				@ -98,6 +98,7 @@ void ProcessNextSample(void)
 | 
				
			|||||||
	/* Check if the sample reload timer period has elapsed, and that the USB bus is ready for a new sample */
 | 
						/* Check if the sample reload timer period has elapsed, and that the USB bus is ready for a new sample */
 | 
				
			||||||
	if ((TIFR0 & (1 << OCF0A)) && Audio_Device_IsReadyForNextSample(&Microphone_Audio_Interface))
 | 
						if ((TIFR0 & (1 << OCF0A)) && Audio_Device_IsReadyForNextSample(&Microphone_Audio_Interface))
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
 | 
							/* Clear the sample reload timer compare flag, ready for the next interval */
 | 
				
			||||||
		TIFR0 |= (1 << OCF0A);
 | 
							TIFR0 |= (1 << OCF0A);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* Audio sample is ADC value scaled to fit the entire range */
 | 
							/* Audio sample is ADC value scaled to fit the entire range */
 | 
				
			||||||
 | 
				
			|||||||
@ -93,7 +93,7 @@ void ProcessNextSample(void)
 | 
				
			|||||||
	/* Check if the sample reload timer period has elapsed, and that the USB bus is ready for a new sample */
 | 
						/* Check if the sample reload timer period has elapsed, and that the USB bus is ready for a new sample */
 | 
				
			||||||
	if ((TIFR0 & (1 << OCF0A)) && Audio_Device_IsSampleReceived(&Speaker_Audio_Interface))
 | 
						if ((TIFR0 & (1 << OCF0A)) && Audio_Device_IsSampleReceived(&Speaker_Audio_Interface))
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		/* Clear the sample reload timer */
 | 
							/* Clear the sample reload timer compare flag, ready for the next interval */
 | 
				
			||||||
		TIFR0 |= (1 << OCF0A);
 | 
							TIFR0 |= (1 << OCF0A);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* Retrieve the signed 16-bit left and right audio samples, convert to 8-bit */
 | 
							/* Retrieve the signed 16-bit left and right audio samples, convert to 8-bit */
 | 
				
			||||||
 | 
				
			|||||||
@ -171,7 +171,7 @@ void PrintIncomingPackets(void)
 | 
				
			|||||||
		printf_P(PSTR("***PACKET (Size %d)***\r\n"), PacketLength);
 | 
							printf_P(PSTR("***PACKET (Size %d)***\r\n"), PacketLength);
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
		for (uint16_t i = 0; i < PacketLength; i++)
 | 
							for (uint16_t i = 0; i < PacketLength; i++)
 | 
				
			||||||
		  printf("%02x ", PacketBuffer[i]);
 | 
							  printf("0x%02x ", PacketBuffer[i]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		printf_P(PSTR("\r\n\r\n"));
 | 
							printf_P(PSTR("\r\n\r\n"));
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 | 
				
			|||||||
@ -245,6 +245,8 @@ void Bluetooth_ConnectionComplete(void)
 | 
				
			|||||||
	         Bluetooth_Connection.RemoteAddress[5], Bluetooth_Connection.RemoteAddress[4],
 | 
						         Bluetooth_Connection.RemoteAddress[5], Bluetooth_Connection.RemoteAddress[4],
 | 
				
			||||||
	         Bluetooth_Connection.RemoteAddress[3], Bluetooth_Connection.RemoteAddress[2],
 | 
						         Bluetooth_Connection.RemoteAddress[3], Bluetooth_Connection.RemoteAddress[2],
 | 
				
			||||||
	         Bluetooth_Connection.RemoteAddress[1], Bluetooth_Connection.RemoteAddress[0]);
 | 
						         Bluetooth_Connection.RemoteAddress[1], Bluetooth_Connection.RemoteAddress[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** Bluetooth stack callback event for a completed Bluetooth disconnection. When this callback is made,
 | 
					/** Bluetooth stack callback event for a completed Bluetooth disconnection. When this callback is made,
 | 
				
			||||||
@ -258,6 +260,8 @@ void Bluetooth_DisconnectionComplete(void)
 | 
				
			|||||||
	         Bluetooth_Connection.RemoteAddress[5], Bluetooth_Connection.RemoteAddress[4],
 | 
						         Bluetooth_Connection.RemoteAddress[5], Bluetooth_Connection.RemoteAddress[4],
 | 
				
			||||||
	         Bluetooth_Connection.RemoteAddress[3], Bluetooth_Connection.RemoteAddress[2],
 | 
						         Bluetooth_Connection.RemoteAddress[3], Bluetooth_Connection.RemoteAddress[2],
 | 
				
			||||||
	         Bluetooth_Connection.RemoteAddress[1], Bluetooth_Connection.RemoteAddress[0]);
 | 
						         Bluetooth_Connection.RemoteAddress[1], Bluetooth_Connection.RemoteAddress[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						LEDs_SetAllLEDs(LEDMASK_USB_READY);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** Bluetooth stack callback event for a Bluetooth ACL Channel connection request. When is callback fires,
 | 
					/** Bluetooth stack callback event for a Bluetooth ACL Channel connection request. When is callback fires,
 | 
				
			||||||
 | 
				
			|||||||
@ -70,6 +70,9 @@
 | 
				
			|||||||
		/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
 | 
							/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
 | 
				
			||||||
		#define LEDMASK_USB_ERROR        (LEDS_LED1 | LEDS_LED3)
 | 
							#define LEDMASK_USB_ERROR        (LEDS_LED1 | LEDS_LED3)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/** LED mask for the library LED driver, to indicate that the USB interface is busy. */
 | 
				
			||||||
 | 
							#define LEDMASK_USB_BUSY          LEDS_LED2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Task Definitions: */
 | 
						/* Task Definitions: */
 | 
				
			||||||
		void Bluetooth_Host_Task(void);
 | 
							void Bluetooth_Host_Task(void);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 | 
				
			|||||||
@ -73,6 +73,7 @@ void RFCOMM_ProcessPacket(void* Data, Bluetooth_Channel_t* const Channel)
 | 
				
			|||||||
	const uint8_t*         FrameData    = (const uint8_t*)Data + sizeof(RFCOMM_Header_t);
 | 
						const uint8_t*         FrameData    = (const uint8_t*)Data + sizeof(RFCOMM_Header_t);
 | 
				
			||||||
	uint16_t               FrameDataLen = RFCOMM_GetFrameDataLength(FrameData);
 | 
						uint16_t               FrameDataLen = RFCOMM_GetFrameDataLength(FrameData);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Adjust the frame data pointer to skip over the variable size field */
 | 
				
			||||||
	FrameData += (FrameDataLen < 128) ? 1 : 2;
 | 
						FrameData += (FrameDataLen < 128) ? 1 : 2;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	/* Decode the RFCOMM frame type from the header */
 | 
						/* Decode the RFCOMM frame type from the header */
 | 
				
			||||||
@ -192,6 +193,8 @@ static void RFCOMM_ProcessControlCommand(const RFCOMM_Command_t* CommandHeader,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			RFCOMM_SendFrame(RFCOMM_CONTROL_DLCI, false, RFCOMM_Frame_UIH, sizeof(RFCOMM_Command_t), &Response, Channel);			
 | 
								RFCOMM_SendFrame(RFCOMM_CONTROL_DLCI, false, RFCOMM_Frame_UIH, sizeof(RFCOMM_Command_t), &Response, Channel);			
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
 | 
							default:
 | 
				
			||||||
 | 
								BT_RFCOMM_DEBUG(1, "<< Unknown Command");			
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -242,11 +245,10 @@ static void RFCOMM_SendFrame(const uint8_t DLCI, const bool CommandResponse, con
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static uint8_t RFCOMM_GetFCSValue(const void* FrameStart, uint8_t Length)
 | 
					static uint8_t RFCOMM_GetFCSValue(const void* FrameStart, uint8_t Length)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	const uint8_t* CurrPos = FrameStart;
 | 
					 | 
				
			||||||
	uint8_t FCS = 0xFF;
 | 
						uint8_t FCS = 0xFF;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	for (uint8_t i = 0; i < Length; i++)
 | 
						for (uint8_t i = 0; i < Length; i++)
 | 
				
			||||||
	  FCS = pgm_read_byte(&CRC8_Table[FCS ^ *(CurrPos++)]);
 | 
						  FCS = pgm_read_byte(&CRC8_Table[FCS ^ ((uint8_t*)FrameStart)[i]]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return ~FCS;
 | 
						return ~FCS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -155,7 +155,7 @@ void PrintIncomingPackets(void)
 | 
				
			|||||||
		Pipe_Read_Stream_LE(&PacketBuffer, PacketLength);
 | 
							Pipe_Read_Stream_LE(&PacketBuffer, PacketLength);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		for (uint16_t i = 0; i < PacketLength; i++)
 | 
							for (uint16_t i = 0; i < PacketLength; i++)
 | 
				
			||||||
		  printf("%02x ", PacketBuffer[i]);
 | 
							  printf("0x%02x ", PacketBuffer[i]);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	Pipe_ClearIN();
 | 
						Pipe_ClearIN();
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user