mirror of
				https://github.com/mik3y/usb-serial-for-android
				synced 2025-10-30 18:07:21 +00:00 
			
		
		
		
	Merge pull request #156 from grevaillot/master
ch34xSerialDriver: support more baudrates.
This commit is contained in:
		
						commit
						f1c147125f
					
				| @ -271,30 +271,34 @@ public class Ch34xSerialDriver implements UsbSerialDriver { | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 		private void setBaudRate(int baudRate) throws IOException { | 		private void setBaudRate(int baudRate) throws IOException { | ||||||
| 			int[] baud = new int[]{2400, 0xd901, 0x0038, 4800, 0x6402, | 			final long CH341_BAUDBASE_FACTOR = 1532620800; | ||||||
| 					0x001f, 9600, 0xb202, 0x0013, 19200, 0xd902, 0x000d, 38400, | 			final int CH341_BAUDBASE_DIVMAX = 3; | ||||||
| 					0x6403, 0x000a, 115200, 0xcc03, 0x0008}; |  | ||||||
| 
 | 
 | ||||||
| 			for (int i = 0; i < baud.length / 3; i++) { | 			long factor = CH341_BAUDBASE_FACTOR / baudRate; | ||||||
| 				if (baud[i * 3] == baudRate) { | 			int divisor = CH341_BAUDBASE_DIVMAX; | ||||||
| 					int ret = controlOut(0x9a, 0x1312, baud[i * 3 + 1]); | 
 | ||||||
| 					if (ret < 0) { | 			while ((factor > 0xfff0) && divisor > 0) { | ||||||
| 						throw new IOException("Error setting baud rate. #1"); | 				factor >>= 3; | ||||||
| 					} | 				divisor--; | ||||||
| 					ret = controlOut(0x9a, 0x0f2c, baud[i * 3 + 2]); |  | ||||||
| 					if (ret < 0) { |  | ||||||
| 						throw new IOException("Error setting baud rate. #1"); |  | ||||||
| 					} | 					} | ||||||
| 
 | 
 | ||||||
| 					return; | 			if (factor > 0xfff0) { | ||||||
| 				} | 				throw new IOException("Baudrate " + baudRate + " not supported"); | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
|  | 			factor = 0x10000 - factor; | ||||||
| 
 | 
 | ||||||
| 			throw new IOException("Baud rate " + baudRate + " currently not supported"); | 			int ret = controlOut(0x9a, 0x1312, (int) ((factor & 0xff00) | divisor)); | ||||||
|  | 			if (ret < 0) { | ||||||
|  | 				throw new IOException("Error setting baud rate. #1)"); | ||||||
|  | 			} | ||||||
|  | 
 | ||||||
|  | 			ret = controlOut(0x9a, 0x0f2c, (int) (factor & 0xff)); | ||||||
|  | 			if (ret < 0) { | ||||||
|  | 				throw new IOException("Error setting baud rate. #2"); | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 		@Override | 		@Override | ||||||
| 		public void setParameters(int baudRate, int dataBits, int stopBits, int parity) | 		public void setParameters(int baudRate, int dataBits, int stopBits, int parity) | ||||||
| 				throws IOException { | 				throws IOException { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user