eeprom7  2.0.0.0
eeprom7.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef EEPROM7_H
29 #define EEPROM7_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 
69 #define EEPROM7_OPCODE_STATUS_RDSR 0x05
70 #define EEPROM7_OPCODE_STATUS_WRBP 0x08
71 #define EEPROM7_OPCODE_STATUS_WREN 0x06
72 #define EEPROM7_OPCODE_STATUS_WRDI 0x04
73 #define EEPROM7_OPCODE_STATUS_WRSR 0x01
74 
79 #define EEPROM7_OPCODE_EEPROM_SECURITY_READ 0x03
80 #define EEPROM7_OPCODE_EEPROM_SECURITY_WRITE 0x02
81 #define EEPROM7_OPCODE_EEPROM_SECURITY_RDEX 0x83
82 #define EEPROM7_OPCODE_EEPROM_SECURITY_WREX 0x82
83 #define EEPROM7_OPCODE_EEPROM_SECURITY_LOCK 0x82
84 #define EEPROM7_OPCODE_EEPROM_SECURITY_CHLK 0x83
85 
90 #define EEPROM7_OPCODE_MP_REG_RMPR 0x31
91 #define EEPROM7_OPCODE_MP_REG_PRWE 0x07
92 #define EEPROM7_OPCODE_MP_REG_PRWD 0x0A
93 #define EEPROM7_OPCODE_MP_REG_WMPR 0x32
94 #define EEPROM7_OPCODE_MP_REG_PPAB 0x34
95 #define EEPROM7_OPCODE_MP_REG_FRZR 0x37
96 
101 #define EEPROM7_OPCODE_MP_REG_SPID 0x9F
102 
107 #define EEPROM7_OPCODE_SW_RESET_SRST 0x7C
108 
113 #define EEPROM7_SEC_WRITE_DISABLE 0x00
114 #define EEPROM7_SEC_WRITE_ENABLE 0x01
115 
120 #define EEPROM7_PIN_WRITE_PROTECT_DISABLE 0x00
121 #define EEPROM7_PIN_WRITE_PROTECT_ENABLE 0x01
122 #define EEPROM7_PIN_HOLD_PROTECT_DISABLE 0x00
123 #define EEPROM7_PIN_HOLD_PROTECT_ENABLE 0x01
124 
129 #define EEPROM7_STATUS_ERROR 0x00
130 #define EEPROM7_STATUS_SUCCESS 0x01
131 #define EEPROM7_DUMMY 0x00
132 #define EEPROM7_ENABLE_WRITE_DISABLE 0x00
133 #define EEPROM7_ENABLE_WRITE_ENABLE 0x01
134 #define EEPROM7_DEVICE_NOT_READY 0x00
135 #define EEPROM7_DEVICE_IS_READY 0x01
136  // eeprom7_reg
138 
153 #define EEPROM7_MAP_MIKROBUS( cfg, mikrobus ) \
154  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
155  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
156  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
157  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
158  cfg.wp = MIKROBUS( mikrobus, MIKROBUS_RST ); \
159  cfg.hld = MIKROBUS( mikrobus, MIKROBUS_PWM )
160  // eeprom7_map // eeprom7
163 
168 typedef struct
169 {
170  // Output pins
171  digital_out_t wp;
172  digital_out_t hld;
174  // Modules
175  spi_master_t spi;
177  pin_name_t chip_select;
179 } eeprom7_t;
180 
185 typedef struct
186 {
187  // Communication gpio pins
188  pin_name_t miso;
189  pin_name_t mosi;
190  pin_name_t sck;
191  pin_name_t cs;
193  // Additional gpio pins
194  pin_name_t wp;
195  pin_name_t hld;
197  // static variable
198  uint32_t spi_speed;
199  spi_master_mode_t spi_mode;
200  spi_master_chip_select_polarity_t cs_polarity;
202 } eeprom7_cfg_t;
203 
208 typedef enum
209 {
211  EEPROM7_ERROR = -1
212 
214 
231 
246 err_t eeprom7_init ( eeprom7_t *ctx, eeprom7_cfg_t *cfg );
247 
262 
278 err_t eeprom7_generic_write ( eeprom7_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
279 
295 err_t eeprom7_generic_read ( eeprom7_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
296 
312 err_t eeprom7_generic_write_then_read ( eeprom7_t *ctx, uint8_t *data_in, uint8_t len_in, uint8_t *data_out, uint8_t len_out );
313 
325 void eeprom7_enable_write_protect ( eeprom7_t *ctx, uint8_t en_write_protect );
326 
337 void eeprom7_enable_hold_operation ( eeprom7_t *ctx, uint8_t en_hold );
338 
349 void eeprom7_enable_write ( eeprom7_t *ctx, uint8_t en_write );
350 
360 uint16_t eeprom7_read_status ( eeprom7_t *ctx );
361 
374 
389 err_t eeprom7_send_cmd ( eeprom7_t *ctx, uint8_t cmd );
390 
402 
414 void eeprom7_set_status ( eeprom7_t *ctx, uint8_t status );
415 
426 uint8_t eeprom7_get_status ( eeprom7_t *ctx );
427 
441 void eeprom7_write_memory ( eeprom7_t *ctx, uint32_t addr, uint8_t *p_tx_data, uint8_t n_bytes );
442 
456 void eeprom7_read_memory ( eeprom7_t *ctx, uint32_t addr, uint8_t *p_rx_data, uint8_t n_bytes);
472 err_t eeprom7_check_status ( eeprom7_t *ctx, uint8_t check_bit );
473 
474 #ifdef __cplusplus
475 }
476 #endif
477 #endif // EEPROM7_H
478  // eeprom7
480 
481 // ------------------------------------------------------------------------ END
eeprom7_return_value_t
eeprom7_return_value_t
EEPROM 7 Click return value data.
Definition: eeprom7.h:209
eeprom7_generic_write_then_read
err_t eeprom7_generic_write_then_read(eeprom7_t *ctx, uint8_t *data_in, uint8_t len_in, uint8_t *data_out, uint8_t len_out)
EEPROM 7 data writing function.
eeprom7_t
EEPROM 7 Click context object.
Definition: eeprom7.h:169
eeprom7_check_status
err_t eeprom7_check_status(eeprom7_t *ctx, uint8_t check_bit)
Status register bits check function.
eeprom7_cfg_t::spi_speed
uint32_t spi_speed
Definition: eeprom7.h:198
eeprom7_read_status
uint16_t eeprom7_read_status(eeprom7_t *ctx)
Read status function.
eeprom7_write_memory
void eeprom7_write_memory(eeprom7_t *ctx, uint32_t addr, uint8_t *p_tx_data, uint8_t n_bytes)
Write EEPROM memory function.
eeprom7_cfg_t::sck
pin_name_t sck
Definition: eeprom7.h:190
eeprom7_send_cmd
err_t eeprom7_send_cmd(eeprom7_t *ctx, uint8_t cmd)
Send command function.
eeprom7_cfg_t::cs
pin_name_t cs
Definition: eeprom7.h:191
EEPROM7_ERROR
@ EEPROM7_ERROR
Definition: eeprom7.h:211
eeprom7_default_cfg
err_t eeprom7_default_cfg(eeprom7_t *ctx)
EEPROM 7 default configuration function.
eeprom7_sw_reset
void eeprom7_sw_reset(eeprom7_t *ctx)
Software device reset function.
eeprom7_init
err_t eeprom7_init(eeprom7_t *ctx, eeprom7_cfg_t *cfg)
EEPROM 7 initialization function.
eeprom7_enable_hold_operation
void eeprom7_enable_hold_operation(eeprom7_t *ctx, uint8_t en_hold)
Enable hold operation function.
eeprom7_generic_read
err_t eeprom7_generic_read(eeprom7_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
EEPROM 7 data reading function.
eeprom7_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: eeprom7.h:199
eeprom7_cfg_setup
void eeprom7_cfg_setup(eeprom7_cfg_t *cfg)
EEPROM 7 configuration object setup function.
eeprom7_generic_write
err_t eeprom7_generic_write(eeprom7_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
EEPROM 7 data writing function.
eeprom7_enable_write
void eeprom7_enable_write(eeprom7_t *ctx, uint8_t en_write)
Enable write function.
eeprom7_cfg_t::wp
pin_name_t wp
Definition: eeprom7.h:194
eeprom7_t::chip_select
pin_name_t chip_select
Definition: eeprom7.h:177
eeprom7_is_device_ready
uint8_t eeprom7_is_device_ready(eeprom7_t *ctx)
Check the device is ready function.
eeprom7_t::spi
spi_master_t spi
Definition: eeprom7.h:175
eeprom7_get_status
uint8_t eeprom7_get_status(eeprom7_t *ctx)
Get status function.
eeprom7_cfg_t::miso
pin_name_t miso
Definition: eeprom7.h:188
eeprom7_read_memory
void eeprom7_read_memory(eeprom7_t *ctx, uint32_t addr, uint8_t *p_rx_data, uint8_t n_bytes)
Read EEPROM memory function.
eeprom7_cfg_t
EEPROM 7 Click configuration object.
Definition: eeprom7.h:186
eeprom7_t::hld
digital_out_t hld
Definition: eeprom7.h:172
EEPROM7_OK
@ EEPROM7_OK
Definition: eeprom7.h:210
eeprom7_enable_write_protect
void eeprom7_enable_write_protect(eeprom7_t *ctx, uint8_t en_write_protect)
Enable write protect function.
eeprom7_cfg_t::hld
pin_name_t hld
Definition: eeprom7.h:195
eeprom7_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: eeprom7.h:200
eeprom7_t::wp
digital_out_t wp
Definition: eeprom7.h:171
eeprom7_cfg_t::mosi
pin_name_t mosi
Definition: eeprom7.h:189
eeprom7_set_status
void eeprom7_set_status(eeprom7_t *ctx, uint8_t status)
Set status function.