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
38#include "drv_digital_out.h"
39#include "drv_digital_in.h"
40#include "drv_spi_master.h"
41
42// -------------------------------------------------------------- PUBLIC MACROS
53#define FRAM2_MAP_MIKROBUS( cfg, mikrobus ) \
54 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
55 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
56 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
57 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
58 cfg.wp = MIKROBUS( mikrobus, MIKROBUS_RST ); \
59 cfg.hld = MIKROBUS( mikrobus, MIKROBUS_PWM )
66#define FRAM2_RETVAL uint8_t
67
68#define FRAM2_OK 0x00
69#define FRAM2_INIT_ERROR 0xFF
76#define FRAM_WREN 0x06
77#define FRAM_WRDI 0x04
78#define FRAM_RDSR 0x05
79#define FRAM_WRSR 0x01
80#define FRAM_READ 0x03
81#define FRAM_WRITE 0x02
82#define FRAM_MEM_SIZE 0x80000 // End group macro
86// --------------------------------------------------------------- PUBLIC TYPES
95typedef struct
96{
97 // Output pins
98
99 digital_out_t cs;
100 digital_out_t wp;
101 digital_out_t hld;
102
103 // Modules
104
105 spi_master_t spi;
106 pin_name_t chip_select;
107
108} fram2_t;
109
113typedef struct
114{
115 // Communication gpio pins
116
117 pin_name_t miso;
118 pin_name_t mosi;
119 pin_name_t sck;
120 pin_name_t cs;
121
122 // Additional gpio pins
123
124 pin_name_t wp;
125 pin_name_t hld;
126
127 // static variable
128
129 uint32_t spi_speed;
130 spi_master_mode_t spi_mode;
131 spi_master_chip_select_polarity_t cs_polarity;
132
134 // End types group
136
137// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
138
143#ifdef __cplusplus
144extern "C"{
145#endif
146
156
166
176
188void fram2_generic_transfer ( fram2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
189
198
207
217uint8_t fram2_read_status ( fram2_t *ctx );
218
227void fram2_write_status ( fram2_t *ctx, uint8_t value );
228
240void fram2_read ( fram2_t *ctx, uint32_t address, uint8_t *buffer, uint8_t count );
241
252void fram2_write( fram2_t *ctx, uint32_t address, uint8_t *buffer, uint8_t counter );
253
254
255#ifdef __cplusplus
256}
257#endif
258#endif // _FRAM2_H_
259 // End public_function group
262
263// ------------------------------------------------------------------------- END
#define FRAM2_RETVAL
Definition: fram2.h:66
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:114
pin_name_t hld
Definition: fram2.h:125
spi_master_chip_select_polarity_t cs_polarity
Definition: fram2.h:131
pin_name_t sck
Definition: fram2.h:119
spi_master_mode_t spi_mode
Definition: fram2.h:130
pin_name_t mosi
Definition: fram2.h:118
uint32_t spi_speed
Definition: fram2.h:129
pin_name_t wp
Definition: fram2.h:124
pin_name_t miso
Definition: fram2.h:117
pin_name_t cs
Definition: fram2.h:120
Click ctx object definition.
Definition: fram2.h:96
digital_out_t cs
Definition: fram2.h:99
digital_out_t hld
Definition: fram2.h:101
spi_master_t spi
Definition: fram2.h:105
pin_name_t chip_select
Definition: fram2.h:106
digital_out_t wp
Definition: fram2.h:100