fram2 2.0.0.0
fram2.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef FRAM2_H
36#define FRAM2_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_spi_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
67#define FRAM2_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
69 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
70 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
71 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72 cfg.wp = MIKROBUS( mikrobus, MIKROBUS_RST ); \
73 cfg.hld = MIKROBUS( mikrobus, MIKROBUS_PWM )
80#define FRAM2_RETVAL uint8_t
81
82#define FRAM2_OK 0x00
83#define FRAM2_INIT_ERROR 0xFF
90#define FRAM_WREN 0x06
91#define FRAM_WRDI 0x04
92#define FRAM_RDSR 0x05
93#define FRAM_WRSR 0x01
94#define FRAM_READ 0x03
95#define FRAM_WRITE 0x02
96#define FRAM_MEM_SIZE 0x80000
99 // End group macro
100// --------------------------------------------------------------- PUBLIC TYPES
109typedef struct
110{
111 // Output pins
112
113 digital_out_t cs;
114 digital_out_t wp;
115 digital_out_t hld;
116
117 // Modules
118
119 spi_master_t spi;
120 pin_name_t chip_select;
121
122} fram2_t;
123
127typedef struct
128{
129 // Communication gpio pins
130
131 pin_name_t miso;
132 pin_name_t mosi;
133 pin_name_t sck;
134 pin_name_t cs;
135
136 // Additional gpio pins
137
138 pin_name_t wp;
139 pin_name_t hld;
140
141 // static variable
142
143 uint32_t spi_speed;
144 spi_master_mode_t spi_mode;
145 spi_master_chip_select_polarity_t cs_polarity;
146
148
149 // End types group
150
151// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
152
157#ifdef __cplusplus
158extern "C"{
159#endif
160
170
180
190
202void fram2_generic_transfer ( fram2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
203
212
221
231uint8_t fram2_read_status ( fram2_t *ctx );
232
241void fram2_write_status ( fram2_t *ctx, uint8_t value );
242
254void fram2_read ( fram2_t *ctx, uint32_t address, uint8_t *buffer, uint8_t count );
255
266void fram2_write( fram2_t *ctx, uint32_t address, uint8_t *buffer, uint8_t counter );
267
268
269#ifdef __cplusplus
270}
271#endif
272#endif // _FRAM2_H_
273
274 // End public_function group
276
277// ------------------------------------------------------------------------- END
#define FRAM2_RETVAL
Definition fram2.h:80
FRAM2_RETVAL fram2_init(fram2_t *ctx, fram2_cfg_t *cfg)
Initialization function.
void fram2_default_cfg(fram2_t *ctx)
Click Default Configuration function.
void fram2_generic_transfer(fram2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
void fram2_write_enable(fram2_t *ctx)
Enable write operation.
void fram2_read(fram2_t *ctx, uint32_t address, uint8_t *buffer, uint8_t count)
Read from FRAM click memory.
void fram2_write(fram2_t *ctx, uint32_t address, uint8_t *buffer, uint8_t counter)
Write to FRAM click memory.
uint8_t fram2_read_status(fram2_t *ctx)
Read Fram click status.
void fram2_write_disable(fram2_t *ctx)
Disable write operation.
void fram2_write_status(fram2_t *ctx, uint8_t value)
Write Fram click status.
void fram2_cfg_setup(fram2_cfg_t *cfg)
Config Object Initialization function.
Click configuration structure definition.
Definition fram2.h:128
pin_name_t hld
Definition fram2.h:139
spi_master_chip_select_polarity_t cs_polarity
Definition fram2.h:145
pin_name_t sck
Definition fram2.h:133
spi_master_mode_t spi_mode
Definition fram2.h:144
pin_name_t mosi
Definition fram2.h:132
uint32_t spi_speed
Definition fram2.h:143
pin_name_t wp
Definition fram2.h:138
pin_name_t miso
Definition fram2.h:131
pin_name_t cs
Definition fram2.h:134
Click ctx object definition.
Definition fram2.h:110
digital_out_t cs
Definition fram2.h:113
digital_out_t hld
Definition fram2.h:115
spi_master_t spi
Definition fram2.h:119
pin_name_t chip_select
Definition fram2.h:120
digital_out_t wp
Definition fram2.h:114