-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathI2CMEM.h
123 lines (99 loc) · 4.24 KB
/
I2CMEM.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*!\file I2CMEM.h
** \author SMFSW
** \copyright MIT (c) 2017-2024, SMFSW
** \brief FRAM / EEPROM Driver
** \note Fully compatible between EEPROM / FRAM type components
** \note When EEPROM compatibility is not needed, buf_size at init can be set to \ref I2CMEM_WBUF_NONE for more efficiency
**/
/****************************************************************/
#ifndef __I2CMEM_H__
#define __I2CMEM_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "sarmfsw.h"
#include "I2C_component.h"
#include "I2C_peripheral.h"
#if defined(HAL_I2C_MODULE_ENABLED)
/****************************************************************/
#ifndef I2C_I2CMEM_NB
//! \note Define I2C_I2CMEM_NB to enable multiple peripherals of this type
#define I2C_I2CMEM_NB 1 //!< Number of I2CMEM peripherals
#endif
// *****************************************************************************
// Section: Constants
// *****************************************************************************
#ifndef I2CMEM_BASE_ADDR
//! \note Define I2CMEM_BASE_ADDR to change default device base address
#define I2CMEM_BASE_ADDR 0x50 //!< I2CMEM Base address
#endif
#define I2CMEM_BANK_SIZE 0x100 //!< I2CMEM bank size (in bytes) for <=16Kb devices
// *****************************************************************************
// Section: Types
// *****************************************************************************
/*!\struct I2CMEM_t
** \brief I2CMEM user interface struct
**/
typedef struct I2CMEM_t {
struct {
I2C_slave_t * slave_inst; //!< Slave structure
size_t chip_size; //!< Memory range (number of bytes)
size_t buf_size; //!< Useful for EEPROM writes (FRAM not restricted, can be changed to I2CMEM_BANK_SIZE)
PeripheralGPIO_t WP_GPIO; //!< Write Protect GPIO struct
} cfg;
} I2CMEM_t;
// *****************************************************************************
// Section: Datas
// *****************************************************************************
extern I2CMEM_t I2CMEM[I2C_I2CMEM_NB]; //!< I2CMEM User structure
// *****************************************************************************
// Section: Interface Routines
// *****************************************************************************
/******************/
/*** Slave init ***/
/******************/
/*!\brief Initialization for I2CMEM peripheral
** \param[in] idx - I2CMEM index
** \param[in] hi2c - pointer to I2CMEM I2C instance
** \param[in] devAddress - I2CMEM device address
** \param[in] size - I2CMEM device size
** \param[in] buf_size - I2CMEM device write buffer size (typically \ref I2CMEM_WBUF_NONE for FRAM component)
** \return FctERR - error code
**/
FctERR NONNULL__ I2CMEM_Init(const uint8_t idx, I2C_HandleTypeDef * const hi2c, const uint16_t devAddress, const size_t size, const size_t buf_size);
/*!\brief Initialization for I2CMEM peripheral
** \warning In case multiple devices (defined by I2C_I2CMEM_NB > 1), you shall use I2CMEM_Init instead
** \param[in] size - I2CMEM device size
** \param[in] buf_size - I2CMEM device write buffer size (typically \ref I2CMEM_WBUF_NONE for FRAM component)
** \return FctERR - error code
**/
FctERR I2CMEM_Init_Single(const size_t size, const size_t buf_size);
/************************/
/*** Low level access ***/
/************************/
/*!\brief I2C Write function for I2CMEM
**
** \param[in] pCpnt - Pointer to I2CMEM component
** \param[in,out] data - pointer to read/write to/from
** \param[in] addr - Address to read from
** \param[in] nb - Number of bytes to read
** \return FctERR - error code
**/
FctERR NONNULL__ I2CMEM_Write(I2CMEM_t * const pCpnt, const uint8_t * const data, const uint16_t addr, const uint16_t nb);
/*!\brief I2C Read function for I2CMEM
**
** \param[in] pCpnt - Pointer to I2CMEM component
** \param[in,out] data - pointer to read/write to/from
** \param[in] addr - Address to read from
** \param[in] nb - Number of bytes to read
** \return FctERR - error code
**/
FctERR NONNULL__ I2CMEM_Read(I2CMEM_t * const pCpnt, uint8_t * const data, const uint16_t addr, const uint16_t nb);
/****************************************************************/
#include "I2CMEM_ex.h" // Include extensions
#endif
#ifdef __cplusplus
}
#endif
#endif /* __I2CMEM_H__ */
/****************************************************************/