From 04bc7f2d071778573fea04e5a10dd1a3edd41f57 Mon Sep 17 00:00:00 2001 From: lxowalle Date: Mon, 2 Dec 2024 11:11:36 +0800 Subject: [PATCH] * add fp5510 driver --- docs/doc/en/modules/fp5510.md | 47 +++++++++++++++++++++++++++++++++++ docs/doc/en/sidebar.yaml | 4 ++- docs/doc/zh/modules/fp5510.md | 47 +++++++++++++++++++++++++++++++++++ docs/doc/zh/sidebar.yaml | 4 ++- examples/ext_dev/fp5510.py | 14 +++++++++++ 5 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 docs/doc/en/modules/fp5510.md create mode 100644 docs/doc/zh/modules/fp5510.md create mode 100644 examples/ext_dev/fp5510.py diff --git a/docs/doc/en/modules/fp5510.md b/docs/doc/en/modules/fp5510.md new file mode 100644 index 00000000..f429a225 --- /dev/null +++ b/docs/doc/en/modules/fp5510.md @@ -0,0 +1,47 @@ +--- +title: MaixPy FP5510 Instructions +update: + - date: 2024-12-02 + author: lxowalle + version: 1.0.0 + content: Initial document +--- + +## Overview + +The **FP5510** is a single 10-bit DAC with a 120mA output current voice coil motor, specifically designed for autofocus operations. It is commonly used in cameras, smartphones, and other electronic devices requiring focus adjustments. + +## Using FP5510 in MaixPy + +MaixPy supports the operation of the `FP5510` through the `FP5510` object. + +Example Code: + +```python +from maix.ext_dev import fp5510 + +fp = fp5510.FP5510() + +fp.set_pos(value) +position = fp.get_pos() +print(f'set position to {position}') + +``` +- Use the `fp5510.FP5510()` method to construct an object for controlling the `fp5510`. Typically, the FP5510 may have slave addresses of `0x0e` or `0x0c`. You can specify the slave address via the `slave_addr` parameter, e.g.: + + > **Note**: If the address of fp5510 is found to change between 0x0e and 0x0c, it may be because the `FP5510` shares a reset pin with the `camera`. When the reset pin is enabled, the FP5510 address is `0x0c`. When the reset pin is disabled, the FP5510 address changes to `0x0e`. + + ```python + fp = fp5510.FP5510(slave_addr = 0x0c) + ``` +- Use the `set_pos` method of the `FP5510` class to set the position of the voice coil motor. The range is [0, 1023]. For example: + + ```python + fp.set_pos(500) + ``` +- Use the `get_pos` method of the `FP5510` class to get the position of the voice coil motor. For example: + + ```python + position = fp.get_pos() + print(f'set position to {position}') + ``` \ No newline at end of file diff --git a/docs/doc/en/sidebar.yaml b/docs/doc/en/sidebar.yaml index b3c6a593..30cb05b1 100644 --- a/docs/doc/en/sidebar.yaml +++ b/docs/doc/en/sidebar.yaml @@ -172,8 +172,10 @@ items: label: TOF - file: modules/thermal_cam.md label: Thermal imaging - file: modules/pmu.md + - file: modules/pmu.md label: Power Management Unit + - file: modules/fp5510.md + label: Voice Coil Motor FP5510 - label: Projects items: diff --git a/docs/doc/zh/modules/fp5510.md b/docs/doc/zh/modules/fp5510.md new file mode 100644 index 00000000..d8ead066 --- /dev/null +++ b/docs/doc/zh/modules/fp5510.md @@ -0,0 +1,47 @@ +--- +title: MaixPy FP5510 使用说明 +update: + - date: 2024-12-02 + author: lxowalle + version: 1.0.0 + content: 初版文档 +--- + +## FP5510 简介 + +FP5510是一款单10位DAC,具有120mA输出的电流音圈电机,专为自动对焦操作设计,常用于相机,手机等需要对焦的电子设备. + +## MaixPy 中使用 FP5510 + +MaixPy支持使用`FP5510`对象来操作`fp5510` + +示例代码: + +```python +from maix.ext_dev import fp5510 + +fp = fp5510.FP5510() + +fp.set_pos(value) +position = fp.get_pos() +print(f'set position to {position}') + +``` +- 使用`fp5510.FP5510()`方法构造一个操作`fp5510`的对象.一般情况, fp5510可能有`0x0e`和`0x0c`两种从机地址, 通过`slave_addr`参数指定从机地址, 例如: + + > 注意: 如果发现fp5510的地址在`0x0e`和`0x0c`间变化,可能是因为`fp5510`与`摄像头`共用了reset引脚,当使能reset脚时fp5510地址是`0x0c`, 当失能reset脚时fp5510地址是`0x0e` + + ```python + fp = fp5510.FP5510(slave_addr = 0x0c) + ``` +- 使用`FP5510`类的`set_pos`方法来设置音圈电机的位置,范围为[0, 1023], 例如: + + ```python + fp.set_pos(500) + ``` +- 使用`FP5510`类的`get_pos`方法来获取音圈电机的位置, 例如: + + ```python + position = fp.get_pos() + print(f'set position to {position}') + ``` \ No newline at end of file diff --git a/docs/doc/zh/sidebar.yaml b/docs/doc/zh/sidebar.yaml index b89ece45..7704bda7 100644 --- a/docs/doc/zh/sidebar.yaml +++ b/docs/doc/zh/sidebar.yaml @@ -173,8 +173,10 @@ items: label: TOF 测距 - file: modules/thermal_cam.md label: 热成像摄像头 - file: modules/pmu.md + - file: modules/pmu.md label: 电源管理单元 + - file: modules/fp5510.md + label: 音圈电机 FP5510 - label: 项目实战 items: diff --git a/examples/ext_dev/fp5510.py b/examples/ext_dev/fp5510.py new file mode 100644 index 00000000..a7bd216d --- /dev/null +++ b/examples/ext_dev/fp5510.py @@ -0,0 +1,14 @@ +from maix import app, time +from maix.ext_dev import fp5510 + +fp = fp5510.FP5510() + +value = 0 +while not app.need_exit(): + fp.set_pos(value) + print(f'set pos to {fp.get_pos()}') + + value += 100 + if value > 1023: + value = 0 + time.sleep_ms(100)