@@ -4,23 +4,23 @@ use spi_memory::series25::Flash;
4
4
use std:: thread:: sleep;
5
5
use std:: time:: Duration ;
6
6
7
- #[ cfg( all( feature = "ftdi" , feature = "libftd2xx" ) ) ]
8
- compile_error ! ( "features 'ftdi' and 'libftd2xx' cannot be enabled at the same time" ) ;
9
-
10
- #[ cfg( not( any( feature = "ftdi" , feature = "libftd2xx" ) ) ) ]
11
- compile_error ! ( "one of features 'ftdi' and 'libftd2xx' shall be enabled" ) ;
12
-
13
7
const LINE : u32 = 0x10 ;
14
8
15
9
fn main ( ) {
16
- #[ cfg( feature = "ftdi" ) ]
17
- let device = ftdi:: find_by_vid_pid ( 0x0403 , 0x6014 )
18
- . interface ( ftdi:: Interface :: A )
19
- . open ( )
20
- . unwrap ( ) ;
21
-
22
- #[ cfg( feature = "libftd2xx" ) ]
23
- let device = libftd2xx:: Ft232h :: with_description ( "Single RS232-HS" ) . unwrap ( ) ;
10
+ cfg_if:: cfg_if! {
11
+ if #[ cfg( feature = "ftdi" ) ] {
12
+ let device = ftdi:: find_by_vid_pid( 0x0403 , 0x6014 )
13
+ . interface( ftdi:: Interface :: A )
14
+ . open( )
15
+ . unwrap( ) ;
16
+ let data: [ u8 ; 8 ] = [ 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 ] ;
17
+ } else if #[ cfg( feature = "libftd2xx" ) ] {
18
+ let device = libftd2xx:: Ft232h :: with_description( "Single RS232-HS" ) . unwrap( ) ;
19
+ let data: [ u8 ; 8 ] = [ 0x00 , 0x10 , 0x20 , 0x30 , 0x40 , 0x50 , 0x60 , 0x70 ] ;
20
+ } else {
21
+ compile_error!( "one of features 'ftdi' and 'libftd2xx' shall be enabled" ) ;
22
+ }
23
+ }
24
24
25
25
let hal = hal:: FtHal :: init_freq ( device, 1_000_000 ) . unwrap ( ) ;
26
26
let spi = hal. spi ( ) . unwrap ( ) ;
@@ -31,11 +31,6 @@ fn main() {
31
31
let id = flash. read_jedec_id ( ) . unwrap ( ) ;
32
32
println ! ( "JEDEC ID: {:?}" , id) ;
33
33
34
- #[ cfg( feature = "libftd2xx" ) ]
35
- let data: [ u8 ; 8 ] = [ 0x00 , 0x10 , 0x20 , 0x30 , 0x40 , 0x50 , 0x60 , 0x70 ] ;
36
- #[ cfg( feature = "ftdi" ) ]
37
- let data: [ u8 ; 8 ] = [ 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 ] ;
38
-
39
34
let addrs: [ u32 ; 5 ] = [ 0 , LINE , 2 * LINE , 3 * LINE , 4 * LINE ] ;
40
35
let zero: [ u8 ; 8 ] = [ 0 ; 8 ] ;
41
36
let mut bytes_w: [ u8 ; 8 ] = [ 0 ; 8 ] ;
0 commit comments