-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFM24C.h
130 lines (104 loc) · 4.08 KB
/
FM24C.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
124
125
126
127
128
129
130
/*!\file FM24C.h
** \author SMFSW
** \copyright MIT (c) 2017-2024, SMFSW
** \brief FM24C FRAM Driver (bank switching at I2C address level protocol)
** \details FM24C16B: 16-Kbit (2K * 8) Serial I2C F-RAM
** FM24C04B: 4-Kbit (512 * 8) Serial I2C F-RAM
** \note Legacy component: consider switching to I2CMEM component for new designs
** \note Compatibility (tested):
** - FM24C16B
** - FM24C04B
** - BR24T04FVM
**/
/****************************************************************/
#ifndef __FM24C_H__
#define __FM24C_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_FM24C_NB
//! \note Define I2C_FM24C_NB to enable multiple peripherals of this type
#define I2C_FM24C_NB 1 //!< Number of FM24C peripherals
#endif
// *****************************************************************************
// Section: Constants
// *****************************************************************************
#ifndef FM24C_BASE_ADDR
//! \note Define FM24C_BASE_ADDR to change default device base address
#define FM24C_BASE_ADDR 0x50 //!< FM24C Base address
#endif
#define FM24C_BANK_SIZE 0x100 //!< FM24C bank size (in bytes)
#define FM24C04B_SIZE 0x200 //!< FM24C04 size (in bytes)
#define FM24C16B_SIZE 0x800 //!< FM24C16 size (in bytes)
#ifndef FM24C_SIZE
//! \note FM24C_SIZE defaults to FM24C16B size, but can be defined to FM24C04B_SIZE (for example)
#define FM24C_SIZE FM24C16B_SIZE //!< FM24C size
#endif
// *****************************************************************************
// Section: Types
// *****************************************************************************
/*!\struct FM24C_t
** \brief FM24C user interface struct
**/
typedef struct FM24C_t {
struct {
I2C_slave_t * slave_inst; //!< Slave structure
PeripheralGPIO_t WP_GPIO; //!< Write Protect GPIO struct
} cfg;
} FM24C_t;
// *****************************************************************************
// Section: Datas
// *****************************************************************************
extern FM24C_t FM24C[I2C_FM24C_NB]; //!< FM24C User structure
// *****************************************************************************
// Section: Interface Routines
// *****************************************************************************
/******************/
/*** Slave init ***/
/******************/
/*!\brief Initialization for FM24C peripheral
** \param[in] idx - FM24C index
** \param[in] hi2c - pointer to FM24C I2C instance
** \param[in] devAddress - FM24C device address
** \return FctERR - error code
**/
FctERR NONNULL__ FM24C_Init(const uint8_t idx, I2C_HandleTypeDef * const hi2c, const uint16_t devAddress);
/*!\brief Initialization for FM24C peripheral
** \warning In case multiple devices (defined by I2C_FM24C_NB > 1), you shall use FM24C_Init instead
** \return FctERR - error code
**/
FctERR FM24C_Init_Single(void);
/************************/
/*** Low level access ***/
/************************/
/*!\brief I2C Write function for FM24C
**
** \param[in] pCpnt - Pointer to FM24C 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__ FM24C_Write(FM24C_t * const pCpnt, const uint8_t * const data, const uint16_t addr, const uint16_t nb);
/*!\brief I2C Read function for FM24C
**
** \param[in] pCpnt - Pointer to FM24C 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__ FM24C_Read(FM24C_t * const pCpnt, uint8_t * const data, const uint16_t addr, const uint16_t nb);
/****************************************************************/
#include "FM24C_ex.h" // Include extensions
#endif
#ifdef __cplusplus
}
#endif
#endif /* __FM24C_H__ */
/****************************************************************/