@@ -319,152 +319,7 @@ cfg_if! {
319
319
}
320
320
}
321
321
322
- /// Types for configuring a serial interface.
323
- pub mod config {
324
- use crate :: pac:: usart1:: cr2:: STOP_A ;
325
- use crate :: time:: rate:: { Baud , Extensions } ;
326
-
327
- /// Stop Bit configuration parameter for serial.
328
- ///
329
- /// Wrapper around [`STOP_A`]
330
- #[ derive( Clone , Copy , Debug , PartialEq ) ]
331
- #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
332
- pub enum StopBits {
333
- /// 0.5 stop bit
334
- Stop0P5 ,
335
- /// 1 stop bit
336
- Stop1 ,
337
- /// 1.5 stop bit
338
- Stop1P5 ,
339
- /// 2 stop bit
340
- Stop2 ,
341
- }
342
-
343
- impl From < StopBits > for STOP_A {
344
- fn from ( stopbit : StopBits ) -> Self {
345
- match stopbit {
346
- StopBits :: Stop0P5 => STOP_A :: STOP0P5 ,
347
- StopBits :: Stop1 => STOP_A :: STOP1 ,
348
- StopBits :: Stop1P5 => STOP_A :: STOP1P5 ,
349
- StopBits :: Stop2 => STOP_A :: STOP2 ,
350
- }
351
- }
352
- }
353
-
354
- impl From < STOP_A > for StopBits {
355
- fn from ( stopbit : STOP_A ) -> Self {
356
- match stopbit {
357
- STOP_A :: STOP0P5 => StopBits :: Stop0P5 ,
358
- STOP_A :: STOP1 => StopBits :: Stop1 ,
359
- STOP_A :: STOP1P5 => StopBits :: Stop1P5 ,
360
- STOP_A :: STOP2 => StopBits :: Stop2 ,
361
- }
362
- }
363
- }
364
-
365
- /// Parity generation and checking. If odd or even parity is selected, the
366
- /// underlying USART will be configured to send/receive the parity bit in
367
- /// addtion to the data bits.
368
- #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
369
- #[ derive( Debug , Clone , Copy , PartialEq ) ]
370
- pub enum Parity {
371
- /// No parity bit will be added/checked.
372
- None ,
373
- /// The MSB transmitted/received will be generated/checked to have a
374
- /// even number of bits set.
375
- Even ,
376
- /// The MSB transmitted/received will be generated/checked to have a
377
- /// odd number of bits set.
378
- Odd ,
379
- }
380
-
381
- /// Configuration struct for [`Serial`](super::Serial) providing all
382
- /// communication-related / parameters. `Serial` always uses eight data
383
- /// bits plus the parity bit - if selected.
384
- ///
385
- /// Create a configuration by using `default` in combination with the
386
- /// builder methods. The following snippet shows creating a configuration
387
- /// for 19,200 Baud, 8N1 by deriving it from the default value:
388
- /// ```
389
- /// # use stm32f3xx_hal::serial::config::*;
390
- /// # use stm32f3xx_hal::time::rate::{Baud, Extensions};
391
- /// let config = Config::default().baudrate(19_200.Bd());
392
- ///
393
- /// assert!(config.baudrate == 19_200.Bd());
394
- /// assert!(config.parity == Parity::None);
395
- /// assert!(config.stopbits == StopBits::STOP1);
396
- /// ```
397
- #[ derive( Debug , Clone , Copy , PartialEq ) ]
398
- #[ non_exhaustive]
399
- pub struct Config {
400
- /// Serial interface baud rate
401
- pub baudrate : Baud ,
402
- /// Whether and how to generate/check a parity bit
403
- pub parity : Parity ,
404
- /// The number of stop bits to follow the last data bit or the parity
405
- /// bit
406
- pub stopbits : StopBits ,
407
- }
408
-
409
- impl Config {
410
- /// Sets the given baudrate.
411
- pub fn baudrate ( mut self , baudrate : impl Into < Baud > ) -> Self {
412
- self . baudrate = baudrate. into ( ) ;
413
- self
414
- }
415
-
416
- /// Sets the given parity.
417
- pub fn parity ( mut self , parity : Parity ) -> Self {
418
- self . parity = parity;
419
- self
420
- }
421
-
422
- /// Sets the stop bits to `stopbits`.
423
- pub fn stopbits ( mut self , stopbits : StopBits ) -> Self {
424
- self . stopbits = stopbits;
425
- self
426
- }
427
- }
428
-
429
- impl Default for Config {
430
- /// Creates a new configuration with typically used parameters: 115,200
431
- /// Baud 8N1.
432
- fn default ( ) -> Config {
433
- Config {
434
- baudrate : 115_200 . Bd ( ) ,
435
- parity : Parity :: None ,
436
- stopbits : StopBits :: Stop1 ,
437
- }
438
- }
439
- }
440
-
441
- impl < T : Into < Baud > > From < T > for Config {
442
- fn from ( b : T ) -> Config {
443
- Config {
444
- baudrate : b. into ( ) ,
445
- ..Default :: default ( )
446
- }
447
- }
448
- }
449
-
450
- #[ cfg( feature = "defmt" ) ]
451
- impl defmt:: Format for Config {
452
- fn format ( & self , f : defmt:: Formatter ) {
453
- // Omitting pins makes it:
454
- // 1. Easier.
455
- // 2. Not to specialized to use it ergonimically for users
456
- // even in a generic context.
457
- // 3. Not require specialization.
458
- defmt:: write!(
459
- f,
460
- "Serial {{ baudrate: {} Bd , parity: {} , stopbits: {} }}" ,
461
- self . baudrate. 0 ,
462
- self . parity,
463
- self . stopbits,
464
- ) ;
465
- }
466
- }
467
- }
322
+ pub mod config;
468
323
469
324
/// Serial abstraction
470
325
///
0 commit comments