소스 검색

[machine_i2c]:Add I2C related functions

SummerGift 8 년 전
부모
커밋
1950d79b91
4개의 변경된 파일29개의 추가작업 그리고 9개의 파일을 삭제
  1. 8 8
      extmod/machine_i2c.c
  2. 16 0
      port/genhdr/qstrdefs.generated.h
  3. 3 1
      port/modmachine.c
  4. 2 0
      port/mpconfigport.h

+ 8 - 8
extmod/machine_i2c.c

@@ -40,21 +40,21 @@ typedef mp_machine_soft_i2c_obj_t machine_i2c_obj_t;
 STATIC void mp_hal_i2c_delay(machine_i2c_obj_t *self) {
     // We need to use an accurate delay to get acceptable I2C
     // speeds (eg 1us should be not much more than 1us).
-    mp_hal_delay_us_fast(self->us_delay);
+    // mp_hal_delay_us_fast(self->us_delay);
 }
 
 STATIC void mp_hal_i2c_scl_low(machine_i2c_obj_t *self) {
-    mp_hal_pin_od_low(self->scl);
+    //mp_hal_pin_od_low(self->scl);
 }
 
 STATIC int mp_hal_i2c_scl_release(machine_i2c_obj_t *self) {
     uint32_t count = self->us_timeout;
 
-    mp_hal_pin_od_high(self->scl);
+    //mp_hal_pin_od_high(self->scl);
     mp_hal_i2c_delay(self);
     // For clock stretching, wait for the SCL pin to be released, with timeout.
     for (; mp_hal_pin_read(self->scl) == 0 && count; --count) {
-        mp_hal_delay_us_fast(1);
+        // mp_hal_delay_us_fast(1);
     }
     if (count == 0) {
         return -MP_ETIMEDOUT;
@@ -63,11 +63,11 @@ STATIC int mp_hal_i2c_scl_release(machine_i2c_obj_t *self) {
 }
 
 STATIC void mp_hal_i2c_sda_low(machine_i2c_obj_t *self) {
-    mp_hal_pin_od_low(self->sda);
+    //mp_hal_pin_od_low(self->sda);
 }
 
 STATIC void mp_hal_i2c_sda_release(machine_i2c_obj_t *self) {
-    mp_hal_pin_od_high(self->sda);
+    //mp_hal_pin_od_high(self->sda);
 }
 
 STATIC int mp_hal_i2c_sda_read(machine_i2c_obj_t *self) {
@@ -101,8 +101,8 @@ STATIC void mp_hal_i2c_init(machine_i2c_obj_t *self, uint32_t freq) {
     if (self->us_delay == 0) {
         self->us_delay = 1;
     }
-    mp_hal_pin_open_drain(self->scl);
-    mp_hal_pin_open_drain(self->sda);
+    //mp_hal_pin_open_drain(self->scl);
+    //mp_hal_pin_open_drain(self->sda);
     mp_hal_i2c_stop(self); // ignore error
 }
 

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

@@ -601,5 +601,21 @@ QDEF(MP_QSTR___dict__, (const byte*)"\x7f\x08" "__dict__")
 QDEF(MP_QSTR_release, (const byte*)"\xec\x07" "release")
 QDEF(MP_QSTR_iterable, (const byte*)"\x25\x08" "iterable")
 QDEF(MP_QSTR_quit, (const byte*)"\x5c\x04" "quit")
+QDEF(MP_QSTR_addr, (const byte*)"\xb6\x04" "addr")
+QDEF(MP_QSTR_addrsize, (const byte*)"\x93\x08" "addrsize")
+QDEF(MP_QSTR_I2C, (const byte*)"\x5d\x03" "I2C")
+QDEF(MP_QSTR_memaddr, (const byte*)"\x93\x07" "memaddr")
+QDEF(MP_QSTR_readfrom_into, (const byte*)"\x82\x0d" "readfrom_into")
+QDEF(MP_QSTR_readfrom_mem, (const byte*)"\x3b\x0c" "readfrom_mem")
+QDEF(MP_QSTR_readfrom_mem_into, (const byte*)"\x38\x11" "readfrom_mem_into")
+QDEF(MP_QSTR_readfrom, (const byte*)"\x41\x08" "readfrom")
+QDEF(MP_QSTR_scan, (const byte*)"\x1a\x04" "scan")
+QDEF(MP_QSTR_sck, (const byte*)"\xfe\x03" "sck")
+QDEF(MP_QSTR_scl, (const byte*)"\xf9\x03" "scl")
+QDEF(MP_QSTR_sda, (const byte*)"\x53\x03" "sda")
+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")
 
 // This file was automatically generated by makeqstrdata.py

+ 3 - 1
port/modmachine.c

@@ -187,7 +187,9 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
     { MP_ROM_QSTR(MP_QSTR_Pin),                 MP_ROM_PTR(&machine_pin_type) },
 #endif
     { MP_ROM_QSTR(MP_QSTR_Signal),              MP_ROM_PTR(&machine_signal_type) },
-//    { MP_ROM_QSTR(MP_QSTR_I2C),                 MP_ROM_PTR(&machine_i2c_type) },
+#if MICROPY_PY_MACHINE_I2C
+    { MP_ROM_QSTR(MP_QSTR_I2C),                 MP_ROM_PTR(&machine_i2c_type) },
+#endif
 //    { MP_ROM_QSTR(MP_QSTR_SPI),                 MP_ROM_PTR(&machine_hard_spi_type) },
 //    { MP_ROM_QSTR(MP_QSTR_UART),                MP_ROM_PTR(&pyb_uart_type) },
 //    { MP_ROM_QSTR(MP_QSTR_WDT),                 MP_ROM_PTR(&pyb_wdt_type) },

+ 2 - 0
port/mpconfigport.h

@@ -124,6 +124,8 @@
 #define MICROPY_PY_UTIME_MP_HAL     (1)
 #define MICROPY_PY_UTIMEQ           (1)
 #define MICROPY_PY_RTTHREAD         (1)
+#define MICROPY_PY_MACHINE_I2C      (1)
+
 
 /*****************************************************************************/
 /* System Module                                                             */