@@ -61,21 +61,6 @@ void flash_error(int n) {
6161 led_state (PYB_LED_R2 , 0 );
6262}
6363
64- static void impl02_c_version (void ) {
65- int x = 0 ;
66- while (x < 400 ) {
67- int y = 0 ;
68- while (y < 400 ) {
69- volatile int z = 0 ;
70- while (z < 400 ) {
71- z = z + 1 ;
72- }
73- y = y + 1 ;
74- }
75- x = x + 1 ;
76- }
77- }
78-
7964void __fatal_error (const char * msg ) {
8065 lcd_print_strn ("\nFATAL ERROR:\n" , 14 );
8166 lcd_print_strn (msg , strlen (msg ));
@@ -108,41 +93,6 @@ mp_obj_t pyb_delay(mp_obj_t count) {
10893 return mp_const_none ;
10994}
11095
111- mp_obj_t pyb_led (mp_obj_t state ) {
112- led_state (PYB_LED_G1 , rt_is_true (state ));
113- return state ;
114- }
115-
116- /*
117- void g(uint i) {
118- printf("g:%d\n", i);
119- if (i & 1) {
120- nlr_jump((void*)(42 + i));
121- }
122- }
123- void f(void) {
124- nlr_buf_t nlr;
125- int i;
126- for (i = 0; i < 4; i++) {
127- printf("f:loop:%d:%p\n", i, &nlr);
128- if (nlr_push(&nlr) == 0) {
129- // normal
130- //printf("a:%p:%p %p %p %u\n", &nlr, nlr.ip, nlr.sp, nlr.prev, nlr.ret_val);
131- g(i);
132- printf("f:lp:%d:nrm\n", i);
133- nlr_pop();
134- } else {
135- // nlr
136- //printf("b:%p:%p %p %p %u\n", &nlr, nlr.ip, nlr.sp, nlr.prev, nlr.ret_val);
137- printf("f:lp:%d:nlr:%d\n", i, (int)nlr.ret_val);
138- }
139- }
140- }
141- void nlr_test(void) {
142- f(1);
143- }
144- */
145-
14696void fatality (void ) {
14797 led_state (PYB_LED_R1 , 1 );
14898 led_state (PYB_LED_G1 , 1 );
@@ -180,6 +130,8 @@ static const char *help_text =
180130" pyb.switch() -- return True/False if switch pressed or not\n"
181131" pyb.accel() -- get accelerometer values\n"
182132" pyb.rand() -- get a 16-bit random number\n"
133+ " pyb.gpio(<port>) -- get port value (port='a4' for example)\n"
134+ " pyb.gpio(<port>, <val>) -- set port value, True or False, 1 or 0\n"
183135;
184136
185137// get some help about available functions
@@ -587,7 +539,7 @@ mp_obj_t pyb_hid_send_report(mp_obj_t arg) {
587539
588540static void rtc_init (void ) {
589541 uint32_t rtc_clksrc ;
590- uint32_t timeout = 10000 ;
542+ uint32_t timeout = 1000000 ;
591543
592544 /* Enable the PWR clock */
593545 RCC_APB1PeriphClockCmd (RCC_APB1Periph_PWR , ENABLE );
@@ -839,7 +791,6 @@ int main(void) {
839791 rt_store_attr (m , MP_QSTR_sync , rt_make_function_n (0 , pyb_sync ));
840792 rt_store_attr (m , MP_QSTR_gc , rt_make_function_n (0 , pyb_gc ));
841793 rt_store_attr (m , MP_QSTR_delay , rt_make_function_n (1 , pyb_delay ));
842- rt_store_attr (m , MP_QSTR_led , rt_make_function_n (1 , pyb_led ));
843794 rt_store_attr (m , MP_QSTR_switch , (mp_obj_t )& pyb_switch_obj );
844795 rt_store_attr (m , MP_QSTR_servo , rt_make_function_n (2 , pyb_servo_set ));
845796 rt_store_attr (m , MP_QSTR_pwm , rt_make_function_n (2 , pyb_pwm_set ));
@@ -849,7 +800,7 @@ int main(void) {
849800 rt_store_attr (m , MP_QSTR_hid , rt_make_function_n (1 , pyb_hid_send_report ));
850801 rt_store_attr (m , MP_QSTR_time , rt_make_function_n (0 , pyb_rtc_read ));
851802 rt_store_attr (m , MP_QSTR_rand , rt_make_function_n (0 , pyb_rng_get ));
852- rt_store_attr (m , MP_QSTR_Led , rt_make_function_n ( 1 , pyb_Led ) );
803+ rt_store_attr (m , MP_QSTR_Led , ( mp_obj_t ) & pyb_Led_obj );
853804 rt_store_attr (m , MP_QSTR_Servo , rt_make_function_n (1 , pyb_Servo ));
854805 rt_store_attr (m , MP_QSTR_I2C , rt_make_function_n (2 , pyb_I2C ));
855806 rt_store_attr (m , MP_QSTR_gpio , (mp_obj_t )& pyb_gpio_obj );
@@ -990,151 +941,6 @@ int main(void) {
990941 vstr_free (vstr );
991942 }
992943
993- //printf("init;al=%u\n", m_get_total_bytes_allocated()); // 1600, due to qstr_init
994- //sys_tick_delay_ms(1000);
995-
996- // Python!
997- if (0 ) {
998- //const char *pysrc = "def f():\n x=x+1\nprint(42)\n";
999- const char * pysrc =
1000- // impl01.py
1001- /*
1002- "x = 0\n"
1003- "while x < 400:\n"
1004- " y = 0\n"
1005- " while y < 400:\n"
1006- " z = 0\n"
1007- " while z < 400:\n"
1008- " z = z + 1\n"
1009- " y = y + 1\n"
1010- " x = x + 1\n";
1011- */
1012- // impl02.py
1013- /*
1014- "#@micropython.native\n"
1015- "def f():\n"
1016- " x = 0\n"
1017- " while x < 400:\n"
1018- " y = 0\n"
1019- " while y < 400:\n"
1020- " z = 0\n"
1021- " while z < 400:\n"
1022- " z = z + 1\n"
1023- " y = y + 1\n"
1024- " x = x + 1\n"
1025- "f()\n";
1026- */
1027- /*
1028- "print('in python!')\n"
1029- "x = 0\n"
1030- "while x < 4:\n"
1031- " pyb_led(True)\n"
1032- " pyb_delay(201)\n"
1033- " pyb_led(False)\n"
1034- " pyb_delay(201)\n"
1035- " x += 1\n"
1036- "print('press me!')\n"
1037- "while True:\n"
1038- " pyb_led(pyb_sw())\n";
1039- */
1040- /*
1041- // impl16.py
1042- "@micropython.asm_thumb\n"
1043- "def delay(r0):\n"
1044- " b(loop_entry)\n"
1045- " label(loop1)\n"
1046- " movw(r1, 55999)\n"
1047- " label(loop2)\n"
1048- " subs(r1, r1, 1)\n"
1049- " cmp(r1, 0)\n"
1050- " bgt(loop2)\n"
1051- " subs(r0, r0, 1)\n"
1052- " label(loop_entry)\n"
1053- " cmp(r0, 0)\n"
1054- " bgt(loop1)\n"
1055- "print('in python!')\n"
1056- "@micropython.native\n"
1057- "def flash(n):\n"
1058- " x = 0\n"
1059- " while x < n:\n"
1060- " pyb_led(True)\n"
1061- " delay(249)\n"
1062- " pyb_led(False)\n"
1063- " delay(249)\n"
1064- " x = x + 1\n"
1065- "flash(20)\n";
1066- */
1067- // impl18.py
1068- /*
1069- "# basic exceptions\n"
1070- "x = 1\n"
1071- "try:\n"
1072- " x.a()\n"
1073- "except:\n"
1074- " print(x)\n";
1075- */
1076- // impl19.py
1077- "# for loop\n"
1078- "def f():\n"
1079- " for x in range(400):\n"
1080- " for y in range(400):\n"
1081- " for z in range(400):\n"
1082- " pass\n"
1083- "f()\n" ;
1084-
1085- mp_lexer_t * lex = mp_lexer_new_from_str_len ("<stdin>" , pysrc , strlen (pysrc ), 0 );
1086-
1087- // nalloc=1740;6340;6836 -> 140;4600;496 bytes for lexer, parser, compiler
1088- printf ("lex; al=%u\n" , m_get_total_bytes_allocated ());
1089- sys_tick_delay_ms (1000 );
1090- qstr parse_exc_id ;
1091- const char * parse_exc_msg ;
1092- mp_parse_node_t pn = mp_parse (lex , MP_PARSE_FILE_INPUT , & parse_exc_id , & parse_exc_msg );
1093- mp_lexer_free (lex );
1094- if (pn != MP_PARSE_NODE_NULL ) {
1095- printf ("pars;al=%u\n" , m_get_total_bytes_allocated ());
1096- sys_tick_delay_ms (1000 );
1097- //parse_node_show(pn, 0);
1098- mp_obj_t module_fun = mp_compile (pn , 0 , false);
1099- printf ("comp;al=%u\n" , m_get_total_bytes_allocated ());
1100- sys_tick_delay_ms (1000 );
1101-
1102- if (module_fun == mp_const_none ) {
1103- printf ("compile error\n" );
1104- } else {
1105- // execute it!
1106-
1107- // flash once
1108- led_state (PYB_LED_G1 , 1 );
1109- sys_tick_delay_ms (100 );
1110- led_state (PYB_LED_G1 , 0 );
1111-
1112- nlr_buf_t nlr ;
1113- if (nlr_push (& nlr ) == 0 ) {
1114- mp_obj_t ret = rt_call_function_0 (module_fun );
1115- printf ("done! got: " );
1116- mp_obj_print (ret , PRINT_REPR );
1117- printf ("\n" );
1118- nlr_pop ();
1119- } else {
1120- // uncaught exception
1121- printf ("exception: " );
1122- mp_obj_print ((mp_obj_t )nlr .ret_val , PRINT_REPR );
1123- printf ("\n" );
1124- }
1125-
1126- // flash once
1127- led_state (PYB_LED_G1 , 1 );
1128- sys_tick_delay_ms (100 );
1129- led_state (PYB_LED_G1 , 0 );
1130-
1131- sys_tick_delay_ms (1000 );
1132- printf ("nalloc=%u\n" , m_get_total_bytes_allocated ());
1133- sys_tick_delay_ms (1000 );
1134- }
1135- }
1136- }
1137-
1138944 // HID example
1139945 if (0 ) {
1140946 uint8_t data [4 ];
@@ -1170,23 +976,6 @@ int main(void) {
1170976
1171977 do_repl ();
1172978
1173- // benchmark C version of impl02.py
1174- if (0 ) {
1175- led_state (PYB_LED_G1 , 1 );
1176- sys_tick_delay_ms (100 );
1177- led_state (PYB_LED_G1 , 0 );
1178- impl02_c_version ();
1179- led_state (PYB_LED_G1 , 1 );
1180- sys_tick_delay_ms (100 );
1181- led_state (PYB_LED_G1 , 0 );
1182- }
1183-
1184- // SD card testing
1185- if (0 ) {
1186- extern void sdio_init (void );
1187- sdio_init ();
1188- }
1189-
1190979 printf ("PYB: sync filesystems\n" );
1191980 pyb_sync ();
1192981
@@ -1196,7 +985,8 @@ int main(void) {
1196985 goto soft_reset ;
1197986}
1198987
1199- /* now supplied by libgcc library
988+ // these 2 functions seem to actually work... no idea why
989+ // replacing with libgcc does not work (probably due to wrong calling conventions)
1200990double __aeabi_f2d (float x ) {
1201991 // TODO
1202992 return 0.0 ;
@@ -1206,7 +996,6 @@ float __aeabi_d2f(double x) {
1206996 // TODO
1207997 return 0.0 ;
1208998}
1209- */
1210999
12111000double sqrt (double x ) {
12121001 // TODO
0 commit comments