libeasymcp2221 2.0.3
Classes | Functions
mcp2221_flash_info.h File Reference

Aggregate flash-information and configuration-save helpers. More...

#include <stdint.h>
#include "mcp2221.h"
Include dependency graph for mcp2221_flash_info.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  mcp2221_flash_info_t
 Snapshot of the public MCP2221 flash-information sections. More...
 

Functions

mcp2221_error_code_t mcp2221_flash_read_info (mcp2221_t *dev, mcp2221_flash_info_t *info)
 Read all public flash-information sections. More...
 
mcp2221_error_code_t mcp2221_flash_get_usb_serial (mcp2221_t *dev, char *serial, size_t serial_size)
 Read the persistent USB serial number from flash. More...
 
mcp2221_error_code_t mcp2221_flash_get_factory_serial (mcp2221_t *dev, char *serial, size_t serial_size)
 Read the read-only factory/chip serial number from flash. More...
 
mcp2221_error_code_t mcp2221_flash_save_config (mcp2221_t *dev)
 Save the current runtime configuration to persistent flash. More...
 

Detailed Description

Aggregate flash-information and configuration-save helpers.

Definition in file mcp2221_flash_info.h.

Function Documentation

◆ mcp2221_flash_get_factory_serial()

mcp2221_error_code_t mcp2221_flash_get_factory_serial ( mcp2221_t dev,
char *  serial,
size_t  serial_size 
)

Read the read-only factory/chip serial number from flash.

Reads only the factory/chip serial-number flash section.

Parameters
[in]devOpen MCP2221 device handle.
[out]serialReceives the null-terminated factory serial on success.
[in]serial_sizeSize of serial in bytes, including the terminator.
Returns
MCP2221_ERR_OK on success, MCP2221_ERR_INVALID for invalid arguments or an output buffer too small for the complete serial, MCP2221_ERR_PROTOCOL for malformed length metadata, or another error returned while reading flash. The output is unchanged on failure.

◆ mcp2221_flash_get_usb_serial()

mcp2221_error_code_t mcp2221_flash_get_usb_serial ( mcp2221_t dev,
char *  serial,
size_t  serial_size 
)

Read the persistent USB serial number from flash.

Reads only the USB serial-number flash section and decodes its validated UTF-16LE descriptor payload to UTF-8.

Parameters
[in]devOpen MCP2221 device handle.
[out]serialReceives the null-terminated UTF-8 serial on success.
[in]serial_sizeSize of serial in bytes, including the terminator.
Returns
MCP2221_ERR_OK on success, MCP2221_ERR_INVALID for invalid arguments or an output buffer too small for the complete serial, MCP2221_ERR_PROTOCOL for malformed descriptor metadata, or another error returned while reading flash. The output is unchanged on failure.

◆ mcp2221_flash_read_info()

mcp2221_error_code_t mcp2221_flash_read_info ( mcp2221_t dev,
mcp2221_flash_info_t info 
)

Read all public flash-information sections.

The output structure is cleared first, then the chip settings, GP settings, USB manufacturer, USB product, USB serial, and factory/chip serial sections are read. USB descriptor metadata is validated before USB-style wide-character structures are decoded to UTF-8 on a best-effort basis.

Parameters
[in]devOpen MCP2221 device handle.
[out]infoReceives raw flash sections and decoded strings.
Returns
MCP2221_ERR_OK on success, MCP2221_ERR_INVALID for invalid arguments, MCP2221_ERR_PROTOCOL for malformed string-descriptor metadata, or another error returned while reading flash.

◆ mcp2221_flash_save_config()

mcp2221_error_code_t mcp2221_flash_save_config ( mcp2221_t dev)

Save the current runtime configuration to persistent flash.

The function updates the persistent chip-settings and GP-settings sections from the current device SRAM state. GPIO values are taken from the library's cached GPIO state when available so that changes made through the GPIO API are retained.

Enumeration-time USB power attributes and requested-current values remain unchanged unless the corresponding USB setter has staged an explicit update.

Parameters
[in]devOpen MCP2221 device handle.
Returns
MCP2221_ERR_OK on success, MCP2221_ERR_INVALID for an invalid device handle or internal state, MCP2221_ERR_PROTOCOL for malformed GET SRAM length metadata, MCP2221_ERR_FLASH_PASSWD when chip protection prevents a safe configuration save, or another mcp2221_error_code_t value on failure.
Warning
This function performs persistent flash writes and is not atomic. The chip-settings section is written before the GP-settings section, so a later failure can leave the earlier section already persisted. Staged USB settings are cleared only after both writes succeed; they remain staged if the save fails.