diff --git a/components/micropython/include/mpconfigboard.h b/components/micropython/include/mpconfigboard.h index f3a24752ce550b4711c954e1521459ade07f883f..933be9981a62876e7eb1fa195b4d04c94dc2050e 100644 --- a/components/micropython/include/mpconfigboard.h +++ b/components/micropython/include/mpconfigboard.h @@ -4,8 +4,8 @@ #define MICROPY_ENABLE_FINALISER (1) #define MICROPY_PY_MACHINE_DAC (0) #define MICROPY_PY_MACHINE_PWM (1) -#define MICROPY_HW_I2C0_SCL (9) -#define MICROPY_HW_I2C0_SDA (8) +#define MICROPY_HW_I2C1_SCL (45) +#define MICROPY_HW_I2C1_SDA (17) #define MICROPY_HW_ESP32S3_EXTENDED_IO (0) #define MICROPY_ESP_IDF_4 1 diff --git a/python_payload/apps/i2c_scanner/__init__.py b/python_payload/apps/i2c_scanner/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e8bad7490b89a841e7c46b4751c5026594ae8131 --- /dev/null +++ b/python_payload/apps/i2c_scanner/__init__.py @@ -0,0 +1,48 @@ +# micropython imports +from machine import I2C, Pin + +# flow3r imports +from st3m.application import Application, ApplicationContext +from ctx import Context +from st3m.input import InputController, InputState + + +class I2CScanner(Application): + def __init__(self, app_ctx: ApplicationContext) -> None: + super().__init__(app_ctx) + self.input = InputController() + self.qwiic = I2C(1, freq=400000) + self._devices = self.qwiic.scan() + print("Found Devices:") + print(self._devices) + + def on_enter(self, vm): + super().on_enter(vm) + + def draw(self, ctx: Context) -> None: + # Get the default font + ctx.font = ctx.get_font_name(1) + # Draw a black background + ctx.rgb(0, 0, 0).rectangle(-120, -120, 240, 240).fill() + + ctx.font_size = 16 + + ctx.rgb(0.7, 0.7, 0.7) + ctx.text_align = ctx.MIDDLE + ctx.move_to(0, -62).text("Press OK to Re-Scan") + ctx.move_to(0, -42).text("Found Devices:") + for i, d in enumerate(self._devices): + ctx.move_to(0, -24 + (i * 12)).text(hex(d)) + + def think(self, ins: InputState, delta_ms: int) -> None: + super().think(ins, delta_ms) + + if self.input.buttons.app.middle.pressed: + self._devices = self.qwiic.scan() + + +# For running with `mpremote run`: +if __name__ == "__main__": + import st3m.run + + st3m.run.run_app(I2CScanner) diff --git a/python_payload/apps/i2c_scanner/flow3r.toml b/python_payload/apps/i2c_scanner/flow3r.toml new file mode 100644 index 0000000000000000000000000000000000000000..f0b976f32db7081e273c3ac04227a14bed5401bc --- /dev/null +++ b/python_payload/apps/i2c_scanner/flow3r.toml @@ -0,0 +1,11 @@ +[app] +name = "I2C/Qwiic Scanner" +category = "Apps" + +[entry] +class = "I2CScanner" + +[metadata] +author = "Flow3r Badge Authors" +license = "LGPL-3.0-only" +url = "https://git.flow3r.garden/flow3r/flow3r-firmware"