/*! \file fm24cl16.h \brief the header file of AT24Cxx \version 2025-01-24, V1.4.0, firmware for GD32H7xx */ /* Copyright (c) 2025, GigaDevice Semiconductor Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FM24CL16_H #define FM24CL16_H #include "gd32h7xx_it.h" typedef enum { I2C_START = 0, I2C_SEND_ADDRESS, I2C_RESTART, I2C_TRANSMIT_DATA, I2C_RELOAD, I2C_STOP, I2C_END } i2c_process_enum; #define I2C_TIME_OUT (uint32_t)(20000) #define EEP_FIRST_PAGE 0x00 #define I2C_OK 0 #define I2C_FAIL 1 /* FM24xx logical capacity/address map */ #define FRAM_SIZE_KBIT (16U) #define FRAM_SIZE_BYTES (2048U) #define FRAM_ADDR_BITS (11U) #define FRAM_START_ADDR (0x0000U) #define FRAM_END_ADDR (0x07FFU) #define FRAM_TOTAL_ADDR (0x0800U) #define FRAM_PAGE_SIZE (256U) #define FRAM_PAGES_COUNT (8U) /* Logical partitions (ported from CCU601E_D) */ #define EEPROM_ADDR_CHGRCD_MNG (0x0000U) /* charge record manager */ #define EEPROM_ADDR_HISALARM_MNG (0x0020U) /* history alarm manager */ #define EEPROM_ADDR_UNSETTLED_MNG (0x0040U) /* unsettled order manager */ #define EEPROM_ADDR_CARD_MNG (0x00A0U) /* card whitelist manager */ #define EEPROM_ADDR_A_LOG_DATA (0x0100U) /* gun A temporary order data */ #define EEPROM_ADDR_B_LOG_DATA (0x0400U) /* gun B temporary order data */ #define EEPROM_ADDR_OCPP_MV_OFFLINE_CTRL 0x0700U #define EEPROM_OCPP_MV_OFFLINE_CTRL_SIZE 128u #define EEPROM_ADDR_OCPP_FW_INSTALLED_PENDING 0x0780U #define EEPROM_OCPP_FW_INSTALLED_PENDING_VAL 0x55U #define EEPROM_OCPP_FW_INSTALLED_PENDING_CLEAR 0x00U #define EEPROM_ADDR_IN_RANGE(addr) ((uint16_t)(addr) <= (uint16_t)FRAM_END_ADDR) /* function declarations */ /* unified EEPROM init: GPIO + I2C + device address */ void eeprom_driver_init(void); /* initialize peripherals used by the I2C EEPROM driver */ void i2c_eeprom_init(void); /* write buffer of data to the I2C EEPROM */ void eeprom_buffer_write(uint8_t *p_buffer, uint16_t write_address, uint16_t number_of_byte); /* read data from the EEPROM */ void eeprom_buffer_read(uint8_t *p_buffer, uint16_t read_address, uint16_t number_of_byte); /* read latest driver error code (0 means no error) */ uint32_t eeprom_get_last_error(void); /* probe one EEPROM block address and return I2C_OK/I2C_FAIL */ uint8_t eeprom_probe(uint16_t mem_address); /* -------------------------------------------------------------------------- * Compatibility layer for migrated modules from CCU601E_D * - old API: eeprom_write/eeprom_read(...) returns HAL_OK on success * - local API: eeprom_buffer_write/eeprom_buffer_read(...) with error queried * -------------------------------------------------------------------------- */ #ifndef HAL_OK #define HAL_OK (0) #endif #ifndef HAL_ERROR #define HAL_ERROR (1) #endif static inline int eeprom_write(uint16_t addr, uint8_t *buf, uint16_t len) { eeprom_buffer_write(buf, addr, len); return (eeprom_get_last_error() == 0U) ? HAL_OK : HAL_ERROR; } static inline int eeprom_read(uint16_t addr, uint8_t *buf, uint16_t len) { eeprom_buffer_read(buf, addr, len); return (eeprom_get_last_error() == 0U) ? HAL_OK : HAL_ERROR; } #endif /* AT24CXX_H */