@@ -3,99 +3,101 @@ use pio::{InSource, InstructionOperands, JmpCondition, OutDestination, SetDestin
33
44use crate :: pio:: { Instance , StateMachine } ;
55
6- /// Set value of scratch register X.
7- pub unsafe fn set_x < PIO : Instance , const SM : usize > ( sm : & mut StateMachine < PIO , SM > , value : u32 ) {
8- const OUT : u16 = InstructionOperands :: OUT {
9- destination : OutDestination :: X ,
10- bit_count : 32 ,
6+ impl < ' d , PIO : Instance , const SM : usize > StateMachine < ' d , PIO , SM > {
7+ /// Set value of scratch register X.
8+ pub unsafe fn set_x ( & mut self , value : u32 ) {
9+ const OUT : u16 = InstructionOperands :: OUT {
10+ destination : OutDestination :: X ,
11+ bit_count : 32 ,
12+ }
13+ . encode ( ) ;
14+ self . tx ( ) . push ( value) ;
15+ self . exec_instr ( OUT ) ;
1116 }
12- . encode ( ) ;
13- sm. tx ( ) . push ( value) ;
14- sm. exec_instr ( OUT ) ;
15- }
1617
17- /// Get value of scratch register X.
18- pub unsafe fn get_x < PIO : Instance , const SM : usize > ( sm : & mut StateMachine < PIO , SM > ) -> u32 {
19- const IN : u16 = InstructionOperands :: IN {
20- source : InSource :: X ,
21- bit_count : 32 ,
18+ /// Get value of scratch register X.
19+ pub unsafe fn get_x ( & mut self ) -> u32 {
20+ const IN : u16 = InstructionOperands :: IN {
21+ source : InSource :: X ,
22+ bit_count : 32 ,
23+ }
24+ . encode ( ) ;
25+ self . exec_instr ( IN ) ;
26+ self . rx ( ) . pull ( )
2227 }
23- . encode ( ) ;
24- sm. exec_instr ( IN ) ;
25- sm. rx ( ) . pull ( )
26- }
2728
28- /// Set value of scratch register Y.
29- pub unsafe fn set_y < PIO : Instance , const SM : usize > ( sm : & mut StateMachine < PIO , SM > , value : u32 ) {
30- const OUT : u16 = InstructionOperands :: OUT {
31- destination : OutDestination :: Y ,
32- bit_count : 32 ,
29+ /// Set value of scratch register Y.
30+ pub unsafe fn set_y ( & mut self , value : u32 ) {
31+ const OUT : u16 = InstructionOperands :: OUT {
32+ destination : OutDestination :: Y ,
33+ bit_count : 32 ,
34+ }
35+ . encode ( ) ;
36+ self . tx ( ) . push ( value) ;
37+ self . exec_instr ( OUT ) ;
3338 }
34- . encode ( ) ;
35- sm. tx ( ) . push ( value) ;
36- sm. exec_instr ( OUT ) ;
37- }
3839
39- /// Get value of scratch register Y.
40- pub unsafe fn get_y < PIO : Instance , const SM : usize > ( sm : & mut StateMachine < PIO , SM > ) -> u32 {
41- const IN : u16 = InstructionOperands :: IN {
42- source : InSource :: Y ,
43- bit_count : 32 ,
44- }
45- . encode ( ) ;
46- sm . exec_instr ( IN ) ;
40+ /// Get value of scratch register Y.
41+ pub unsafe fn get_y ( & mut self ) -> u32 {
42+ const IN : u16 = InstructionOperands :: IN {
43+ source : InSource :: Y ,
44+ bit_count : 32 ,
45+ }
46+ . encode ( ) ;
47+ self . exec_instr ( IN ) ;
4748
48- sm . rx ( ) . pull ( )
49- }
49+ self . rx ( ) . pull ( )
50+ }
5051
51- /// Set instruction for pindir destination.
52- pub unsafe fn set_pindir < PIO : Instance , const SM : usize > ( sm : & mut StateMachine < PIO , SM > , data : u8 ) {
53- let set: u16 = InstructionOperands :: SET {
54- destination : SetDestination :: PINDIRS ,
55- data,
52+ /// Set instruction for pindir destination.
53+ pub unsafe fn set_pindir ( & mut self , data : u8 ) {
54+ let set: u16 = InstructionOperands :: SET {
55+ destination : SetDestination :: PINDIRS ,
56+ data,
57+ }
58+ . encode ( ) ;
59+ self . exec_instr ( set) ;
5660 }
57- . encode ( ) ;
58- sm. exec_instr ( set) ;
59- }
6061
61- /// Set instruction for pin destination.
62- pub unsafe fn set_pin < PIO : Instance , const SM : usize > ( sm : & mut StateMachine < PIO , SM > , data : u8 ) {
63- let set: u16 = InstructionOperands :: SET {
64- destination : SetDestination :: PINS ,
65- data,
62+ /// Set instruction for pin destination.
63+ pub unsafe fn set_pin ( & mut self , data : u8 ) {
64+ let set: u16 = InstructionOperands :: SET {
65+ destination : SetDestination :: PINS ,
66+ data,
67+ }
68+ . encode ( ) ;
69+ self . exec_instr ( set) ;
6670 }
67- . encode ( ) ;
68- sm. exec_instr ( set) ;
69- }
7071
71- /// Out instruction for pin destination.
72- pub unsafe fn set_out_pin < PIO : Instance , const SM : usize > ( sm : & mut StateMachine < PIO , SM > , data : u32 ) {
73- const OUT : u16 = InstructionOperands :: OUT {
74- destination : OutDestination :: PINS ,
75- bit_count : 32 ,
72+ /// Out instruction for pin destination.
73+ pub unsafe fn set_out_pin ( & mut self , data : u32 ) {
74+ const OUT : u16 = InstructionOperands :: OUT {
75+ destination : OutDestination :: PINS ,
76+ bit_count : 32 ,
77+ }
78+ . encode ( ) ;
79+ self . tx ( ) . push ( data) ;
80+ self . exec_instr ( OUT ) ;
7681 }
77- . encode ( ) ;
78- sm. tx ( ) . push ( data) ;
79- sm. exec_instr ( OUT ) ;
80- }
8182
82- /// Out instruction for pindir destination.
83- pub unsafe fn set_out_pindir < PIO : Instance , const SM : usize > ( sm : & mut StateMachine < PIO , SM > , data : u32 ) {
84- const OUT : u16 = InstructionOperands :: OUT {
85- destination : OutDestination :: PINDIRS ,
86- bit_count : 32 ,
83+ /// Out instruction for pindir destination.
84+ pub unsafe fn set_out_pindir ( & mut self , data : u32 ) {
85+ const OUT : u16 = InstructionOperands :: OUT {
86+ destination : OutDestination :: PINDIRS ,
87+ bit_count : 32 ,
88+ }
89+ . encode ( ) ;
90+ self . tx ( ) . push ( data) ;
91+ self . exec_instr ( OUT ) ;
8792 }
88- . encode ( ) ;
89- sm. tx ( ) . push ( data) ;
90- sm. exec_instr ( OUT ) ;
91- }
9293
93- /// Jump instruction to address.
94- pub unsafe fn exec_jmp < PIO : Instance , const SM : usize > ( sm : & mut StateMachine < PIO , SM > , to_addr : u8 ) {
95- let jmp: u16 = InstructionOperands :: JMP {
96- address : to_addr,
97- condition : JmpCondition :: Always ,
94+ /// Jump instruction to address.
95+ pub unsafe fn exec_jmp ( & mut self , to_addr : u8 ) {
96+ let jmp: u16 = InstructionOperands :: JMP {
97+ address : to_addr,
98+ condition : JmpCondition :: Always ,
99+ }
100+ . encode ( ) ;
101+ self . exec_instr ( jmp) ;
98102 }
99- . encode ( ) ;
100- sm. exec_instr ( jmp) ;
101103}
0 commit comments