@@ -127,6 +127,44 @@ py_obj_t pyb_led(py_obj_t state) {
127
127
return state ;
128
128
}
129
129
130
+ py_obj_t py_obj_new_user (const py_user_info_t * info , machine_uint_t data1 , machine_uint_t data2 );
131
+ void py_user_get_data (py_obj_t o , machine_uint_t * data1 , machine_uint_t * data2 );
132
+ void py_user_set_data (py_obj_t o , machine_uint_t data1 , machine_uint_t data2 );
133
+
134
+ py_obj_t led_obj_on (py_obj_t self ) {
135
+ machine_uint_t led_id ;
136
+ py_user_get_data (self , & led_id , NULL );
137
+ switch (led_id ) {
138
+ case 1 : led_state (PYB_LED_G1 , 1 ); break ;
139
+ case 2 : led_state (PYB_LED_G2 , 1 ); break ;
140
+ }
141
+ return py_const_none ;
142
+ }
143
+
144
+ py_obj_t led_obj_off (py_obj_t self ) {
145
+ machine_uint_t led_id ;
146
+ py_user_get_data (self , & led_id , NULL );
147
+ switch (led_id ) {
148
+ case 1 : led_state (PYB_LED_G1 , 0 ); break ;
149
+ case 2 : led_state (PYB_LED_G2 , 0 ); break ;
150
+ }
151
+ return py_const_none ;
152
+ }
153
+
154
+ const py_user_info_t led_obj_info = {
155
+ "Led" ,
156
+ NULL , // print
157
+ {
158
+ {"on" , 0 , led_obj_on },
159
+ {"off" , 0 , led_obj_off },
160
+ {NULL , 0 , NULL },
161
+ }
162
+ };
163
+
164
+ py_obj_t pyb_Led (py_obj_t led_id ) {
165
+ return py_obj_new_user (& led_obj_info , (machine_uint_t )py_obj_get_int (led_id ), 0 );
166
+ }
167
+
130
168
py_obj_t pyb_sw (void ) {
131
169
if (sw_get ()) {
132
170
return py_const_true ;
@@ -749,6 +787,9 @@ py_obj_t pyb_rng_get(void) {
749
787
int main (void ) {
750
788
// TODO disable JTAG
751
789
790
+ // update the SystemCoreClock variable
791
+ SystemCoreClockUpdate ();
792
+
752
793
// set interrupt priority config to use all 4 bits for pre-empting
753
794
NVIC_PriorityGroupConfig (NVIC_PriorityGroup_4 );
754
795
@@ -833,6 +874,7 @@ int main(void) {
833
874
rt_store_attr (m , qstr_from_str_static ("uin" ), rt_make_function_0 (pyb_usart_receive ));
834
875
rt_store_attr (m , qstr_from_str_static ("ustat" ), rt_make_function_0 (pyb_usart_status ));
835
876
rt_store_attr (m , qstr_from_str_static ("rng" ), rt_make_function_0 (pyb_rng_get ));
877
+ rt_store_attr (m , qstr_from_str_static ("Led" ), rt_make_function_1 (pyb_Led ));
836
878
rt_store_name (qstr_from_str_static ("pyb" ), m );
837
879
838
880
rt_store_name (qstr_from_str_static ("open" ), rt_make_function_2 (pyb_io_open ));
@@ -841,14 +883,28 @@ int main(void) {
841
883
// print a message to the LCD
842
884
lcd_print_str (" micro py board\n" );
843
885
886
+ // check if user switch held (initiates reset of filesystem)
887
+ bool reset_filesystem = false;
888
+ if (sw_get ()) {
889
+ reset_filesystem = true;
890
+ for (int i = 0 ; i < 50 ; i ++ ) {
891
+ if (!sw_get ()) {
892
+ reset_filesystem = false;
893
+ break ;
894
+ }
895
+ sys_tick_delay_ms (10 );
896
+ }
897
+ }
898
+
844
899
// local filesystem init
845
900
{
846
901
// try to mount the flash
847
902
FRESULT res = f_mount (& fatfs0 , "0:" , 1 );
848
- if (res == FR_OK ) {
903
+ if (! reset_filesystem && res == FR_OK ) {
849
904
// mount sucessful
850
- } else if (res == FR_NO_FILESYSTEM ) {
905
+ } else if (reset_filesystem || res == FR_NO_FILESYSTEM ) {
851
906
// no filesystem, so create a fresh one
907
+ // TODO doesn't seem to work correctly when reset_filesystem is true...
852
908
853
909
// LED on to indicate creation of LFS
854
910
led_state (PYB_LED_R2 , 1 );
@@ -1165,8 +1221,8 @@ int main(void) {
1165
1221
}
1166
1222
1167
1223
// wifi
1168
- pyb_wlan_init ();
1169
- pyb_wlan_start ();
1224
+ // pyb_wlan_init();
1225
+ // pyb_wlan_start();
1170
1226
1171
1227
do_repl ();
1172
1228
0 commit comments