@@ -85,9 +85,81 @@ impl Repl {
85
85
}
86
86
crate :: println!( "" ) ;
87
87
}
88
+
89
+ "blinky" => {
90
+ if args. len ( ) != 2 {
91
+ crate :: println!( "Usage: blinky <LED_NAME> <RGB_HEX_VALUE>" ) ;
92
+ crate :: println!( "Example: blinky LD2 ff0000" ) ;
93
+ crate :: println!( "Available LEDs: LD0, LD1, LD2" ) ;
94
+ self . do_cmd = false ;
95
+ self . cmdline . clear ( ) ;
96
+ return ;
97
+ }
98
+
99
+ let ld_name = & args[ 0 ] ;
100
+ let hex_code = & args[ 1 ] ;
101
+
102
+ // Determine shift from LED name based on the hardware layout.
103
+ let shift = match ld_name. as_str ( ) {
104
+ "LD0" => 0 ,
105
+ "LD1" => 3 ,
106
+ "LD2" => 6 ,
107
+ _ => {
108
+ crate :: println!( "Invalid LD name: {}. Use LD0, LD1, or LD2" , ld_name) ;
109
+ self . do_cmd = false ;
110
+ self . cmdline . clear ( ) ;
111
+ return ;
112
+ }
113
+ } ;
114
+
115
+ let color_val = if hex_code. starts_with ( "0x" ) {
116
+ u32:: from_str_radix ( & hex_code[ 2 ..] , 16 )
117
+ } else {
118
+ u32:: from_str_radix ( hex_code, 16 )
119
+ } ;
120
+
121
+ match color_val {
122
+ Ok ( color) => {
123
+ // convert 24-bit RRGGBB into 3-bit BGR
124
+ let r_msb = color & 0x800000 ;
125
+ let g_msb = color & 0x008000 ;
126
+ let b_msb = color & 0x000080 ;
127
+ let bgr_val = ( b_msb >> 6 ) | ( g_msb >> 13 ) | ( r_msb >> 23 ) ;
128
+
129
+ let mut rgb = CSR :: new ( utra:: rgb:: HW_RGB_BASE as * mut u32 ) ;
130
+ let new_state = bgr_val << shift;
131
+
132
+ rgb. rmwf ( utra:: rgb:: OUT_OUT , rgb. r ( utra:: rgb:: OUT ) | new_state) ;
133
+
134
+ crate :: println!(
135
+ "Set {} to BGR value 0b{:03b} (from hex {}). Other LEDs are off." ,
136
+ ld_name,
137
+ bgr_val,
138
+ hex_code
139
+ ) ;
140
+ }
141
+ Err ( _) => {
142
+ crate :: println!( "Invalid hex color value: {}" , hex_code) ;
143
+ }
144
+ }
145
+ }
146
+ "help" => {
147
+ crate :: println!( "Available commands:" ) ;
148
+ crate :: println!( " help - Shows this help message." ) ;
149
+ crate :: println!( " echo [ARGS] - Prints the arguments to the console." ) ;
150
+ crate :: println!(
151
+ " mon - Monitors the program counters of the BIO cores."
152
+ ) ;
153
+ crate :: println!( " blinky <LD> <RGB_HEX> - Sets an LED to a color (turns others off)." ) ;
154
+ crate :: println!( " LD: LD1, LD2, or LD3" ) ;
155
+ crate :: println!( " RGB_HEX: e.g., ff0000 (red), 00ff00 (green), 0000ff (blue)" ) ;
156
+ }
157
+
158
+ "" => { }
159
+
88
160
_ => {
89
- crate :: println!( "Command not recognized: {} " , cmd) ;
90
- crate :: println!( "Commands include: echo, mon " ) ;
161
+ crate :: println!( "Command not recognized: '{}' " , cmd) ;
162
+ crate :: println!( "Type 'help' for a list of commands. " ) ;
91
163
}
92
164
}
93
165
0 commit comments