Ver código fonte

Merge pull request #9 from SummerGGift/2018330

【更新】:优化 QSTR 脚本,添加 SPI 相关功能
朱天龙 (Armink) 8 anos atrás
pai
commit
ac31ee3e18

+ 1 - 1
port/genhdr/gen_qstr.py

@@ -48,7 +48,7 @@ def make_bytes(cfg_bytes_len, cfg_bytes_hash, qstr):
         assert False
     qlen_str = ('\\x%02x' * cfg_bytes_len) % tuple(((qlen >> (8 * i)) & 0xff) for i in range(cfg_bytes_len))
     qhash_str = ('\\x%02x' * cfg_bytes_hash) % tuple(((qhash >> (8 * i)) & 0xff) for i in range(cfg_bytes_hash))
-    return '(const byte*)"%s%s" "%s"' % (qhash_str, qlen_str, qdata)
+    return 'QDEF(MP_QSTR_%s, (const byte*)"%s%s" "%s")' % (qdata,qhash_str, qlen_str, qdata)
     
 if __name__ == "__main__":
     print ("This program will gen qstr for micropython:")

+ 12 - 0
port/genhdr/qstrdefs.generated.h

@@ -617,5 +617,17 @@ QDEF(MP_QSTR_arg, (const byte*)"\x91\x03" "arg")
 QDEF(MP_QSTR_timeout, (const byte*)"\x3e\x07" "timeout")
 QDEF(MP_QSTR_writeto_mem, (const byte*)"\x79\x0b" "writeto_mem")
 QDEF(MP_QSTR_writeto, (const byte*)"\x03\x07" "writeto")
+QDEF(MP_QSTR_deinit, (const byte*)"\x9e\x06" "deinit")
+QDEF(MP_QSTR_firstbit, (const byte*)"\x20\x08" "firstbit")
+QDEF(MP_QSTR_mosi, (const byte*)"\x1d\x04" "mosi")
+QDEF(MP_QSTR_polarity, (const byte*)"\x41\x08" "polarity")
+QDEF(MP_QSTR_SPI, (const byte*)"\xef\x03" "SPI")
+QDEF(MP_QSTR_baudrate, (const byte*)"\xf5\x08" "baudrate")
+QDEF(MP_QSTR_bits, (const byte*)"\x49\x04" "bits")
+QDEF(MP_QSTR_miso, (const byte*)"\x9d\x04" "miso")
+QDEF(MP_QSTR_MSB, (const byte*)"\x59\x03" "MSB")
+QDEF(MP_QSTR_SoftSPI, (const byte*)"\x21\x07" "SoftSPI")
+QDEF(MP_QSTR_write_readinto, (const byte*)"\x89\x0e" "write_readinto")
+QDEF(MP_QSTR_LSB, (const byte*)"\xd8\x03" "LSB")
 
 // This file was automatically generated by makeqstrdata.py

+ 4 - 0
port/machine_pin.c

@@ -66,6 +66,10 @@ void mp_hal_pin_open_set(void *machine_pin, int mode) {
     rt_pin_mode(((machine_pin_obj_t *)machine_pin)->pin, mode);
 }
 
+char* mp_hal_pin_get_name(void *machine_pin) {
+    return ((machine_pin_obj_t *)machine_pin)->name;
+}
+
 STATIC mp_obj_t machine_pin_obj_init_helper(machine_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
 
 STATIC void machine_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {

+ 2 - 1
port/modmachine.c

@@ -35,6 +35,7 @@
 #include "extmod/machine_signal.h"
 #include "extmod/machine_pulse.h"
 #include "extmod/machine_i2c.h"
+#include "extmod/machine_spi.h"
 #include "modmachine.h"
 
 #include <rthw.h>
@@ -191,7 +192,7 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
     { MP_ROM_QSTR(MP_QSTR_I2C),                 MP_ROM_PTR(&machine_i2c_type) },
 #endif
 #if MICROPY_PY_MACHINE_SPI
-    { MP_ROM_QSTR(MP_QSTR_SPI),                 MP_ROM_PTR(&machine_hard_spi_type) },
+    { MP_ROM_QSTR(MP_QSTR_SPI),                 MP_ROM_PTR(&mp_machine_soft_spi_type) },
 #endif
 //    { MP_ROM_QSTR(MP_QSTR_UART),                MP_ROM_PTR(&pyb_uart_type) },
 //    { MP_ROM_QSTR(MP_QSTR_WDT),                 MP_ROM_PTR(&pyb_wdt_type) },

+ 6 - 0
port/mphalport.h

@@ -47,6 +47,8 @@ static inline void mp_hal_delay_ms(mp_uint_t delay) {
     rt_thread_delay(rt_tick_from_millisecond(delay));
 }
 
+#define MP_HAL_PIN_FMT                 "%s"
+
 extern void mp_hal_set_interrupt_char (int c);
 extern void mp_pin_od_write(void *machine_pin, int stat);
 extern void mp_hal_pin_open_set(void *machine_pin, int mode);
@@ -57,3 +59,7 @@ extern void mp_hal_pin_open_set(void *machine_pin, int mode);
 #define mp_hal_pin_od_high(pin)  mp_pin_od_write(pin, PIN_HIGH)
 #define mp_hal_pin_open_drain(p) mp_hal_pin_open_set(p, PIN_MODE_OUTPUT_OD)
 
+// needed for soft machine.SPI
+#define mp_hal_pin_output(p)     mp_hal_pin_open_set(p, PIN_MODE_OUTPUT)
+#define mp_hal_pin_input(p)      mp_hal_pin_open_set(p, PIN_MODE_INPUT)
+#define mp_hal_pin_name(p)       mp_hal_pin_get_name(p)