daniel-p-carvalho opened a new pull request, #20824: URL: https://github.com/apache/nuttx/pull/20824
## Summary Add a lower-half driver for the Microchip MCP454X, MCP456X, MCP464X and MCP466X 7/8-bit, single/dual, I2C digital potentiometers with nonvolatile wiper memory (DS22107B), on top of the common potentiometer interface (`POTIOC_*`). The only other potentiometer driver, MCP445X, has no nonvolatile memory, so `POTIOC_STORE_WIPER` and `POTIOC_RECALL_WIPER` had no lower half yet. What the driver does: - `mcp45xx_initialize(i2c, addr, chip, rab)` takes the device type (`MCP45XX_MCP4541`, `_MCP4561`, `_MCP4641`, `_MCP4661`), which sets the number of wipers (1 or 2) and the full scale (128 for 7-bit, 256 for 8-bit). The potentiometer and rheostat versions of a device share the same registers. Like the MCP445X driver, it does not write to the chip at initialization or open: the wiper keeps the value the device loaded at power-up. - Set and get use the volatile wiper registers. Move uses the native increment and decrement commands, sent as one continuous transfer of up to 16 commands, and the device saturates at zero and at full scale. - `POTIOC_SET_ENABLE` forces a wiper into the shutdown configuration through the TCON register (read-modify-write, so the other TCON bits are kept). - `POTIOC_STORE_WIPER` and `POTIOC_RECALL_WIPER` use the nonvolatile wiper register that is loaded at power-up (slot 0; other slots return `-EINVAL`). A store waits for the EEPROM write cycle (tWC 10 ms max) by polling `STATUS.EEWA` and reads the register back. It returns `-EROFS` when `STATUS` shows the EEPROM write protected or the wiper locked, because the device ignores those writes without a NACK. - New options: `CONFIG_POT_MCP45XX` and `CONFIG_POT_MCP45XX_I2C_FREQUENCY` (default 400 kHz). Added to `Make.defs`, `CMakeLists.txt` and the potentiometer documentation page. Not included: the high-voltage commands (WiperLock and write protect enable/disable need a voltage on the HVC pin), the general purpose EEPROM locations, the RAM-only variants (MCP453X, MCP455X, MCP463X and MCP465X, which have a different datasheet) and per-terminal TCON control. ## Impact New driver behind a new option, off by default. No change to existing code: the only edits to existing files are a prototype and an enum in `pot.h` and the build and documentation entries. No impact on other boards. ## Testing Host: Linux x86_64, `arm-none-eabi-gcc` 15.2.1. Target: custom STM32G474RE board with an MCP4561 (50 kOhm according to the board design, address 0x2E) on I2C2 at 400 kHz, driven from NSH with a small test tool that issues the `POTIOC_*` ioctls. `tools/checkpatch.sh` passes and `nxstyle` reports nothing on the new file. Only the MCP4561 was tested; the other three devices follow the datasheet. The `-EROFS` path was not exercised (it needs the high-voltage command to turn write protect on). The CMake build and `make html` were not run. The output below is abridged from several sessions on the same board. Device properties and power-on value: ``` nsh> potctl info wipers 1 max 256 rab 50000 ohm caps 0xf nsh> potctl get 0 wiper 0 = 128 ``` Write, read, limits and errors: ``` nsh> potctl set 0 200 nsh> potctl get 0 wiper 0 = 200 nsh> potctl set 0 256 nsh> potctl get 0 wiper 0 = 256 nsh> potctl set 0 0 nsh> potctl get 0 wiper 0 = 0 nsh> potctl set 0 257 set failed: 22 nsh> potctl set 1 10 set failed: 22 ``` Move, with saturation in both directions: ``` nsh> potctl move 0 5 nsh> potctl get 0 wiper 0 = 5 nsh> potctl move 0 -2 nsh> potctl get 0 wiper 0 = 3 nsh> potctl move 0 1000 nsh> potctl get 0 wiper 0 = 256 nsh> potctl move 0 -1000 nsh> potctl get 0 wiper 0 = 0 ``` Store and recall, and the stored value after a reset (the volatile wiper is loaded from the nonvolatile register at power-up): ``` nsh> potctl set 0 200 nsh> potctl store 0 nsh> potctl set 0 10 nsh> potctl get 0 wiper 0 = 10 nsh> potctl recall 0 nsh> potctl get 0 wiper 0 = 200 nsh> potctl store 0 1 store failed: 22 <reset> nsh> potctl get 0 wiper 0 = 200 ``` The nonvolatile register was then restored to 128 and a second reset read 128 back. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
