dram  2.1.0.0
dram.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 DRAM_H
29 #define DRAM_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 
60 #define DRAM_CMD_READ 0x03
61 #define DRAM_CMD_FAST_READ 0x0B
62 #define DRAM_CMD_WRITE 0x02
63 #define DRAM_CMD_RESET_ENABLE 0x66
64 #define DRAM_CMD_RESET 0x99
65 #define DRAM_CMD_WRAP_BOUNDARY_TOGGLE 0xC0
66 #define DRAM_CMD_READ_ID 0x9F
67  // dram_reg
69 
84 #define DRAM_MIN_ADDRESS 0x000000
85 #define DRAM_MAX_ADDRESS 0x7FFFFFul
86 
91 #define DRAM_MANUFACTURER_ID 0x0D
92 
101 #define DRAM_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
102 #define DRAM_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
103  // dram_set
105 
120 #define DRAM_MAP_MIKROBUS( cfg, mikrobus ) \
121  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
122  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
123  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
124  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
125  cfg.io3 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
126  cfg.io2 = MIKROBUS( mikrobus, MIKROBUS_PWM );
127  // dram_map // dram
130 
135 typedef struct
136 {
137  // Output pins
138  digital_out_t io3;
139  digital_out_t io2;
141  // Modules
142  spi_master_t spi;
144  pin_name_t chip_select;
146 } dram_t;
147 
152 typedef struct
153 {
154  // Communication gpio pins
155  pin_name_t miso;
156  pin_name_t mosi;
157  pin_name_t sck;
158  pin_name_t cs;
160  // Additional gpio pins
161  pin_name_t io3;
162  pin_name_t io2;
164  // static variable
165  uint32_t spi_speed;
166  spi_master_mode_t spi_mode;
167  spi_master_chip_select_polarity_t cs_polarity;
169 } dram_cfg_t;
170 
175 typedef enum
176 {
177  DRAM_OK = 0,
178  DRAM_ERROR = -1
179 
181 
198 
212 err_t dram_init ( dram_t *ctx, dram_cfg_t *cfg );
213 
228 err_t dram_memory_write ( dram_t *ctx, uint32_t address, uint8_t *data_in, uint32_t len );
229 
244 err_t dram_memory_read ( dram_t *ctx, uint32_t address, uint8_t *data_out, uint32_t len );
245 
260 err_t dram_memory_read_fast ( dram_t *ctx, uint32_t address, uint8_t *data_out, uint32_t len );
261 
273 err_t dram_reset ( dram_t *ctx );
274 
287 
299 err_t dram_read_id ( dram_t *ctx, uint8_t *device_id );
300 
313 
323 void dram_set_io3_pin ( dram_t *ctx, uint8_t state );
324 
334 void dram_set_io2_pin ( dram_t *ctx, uint8_t state );
335 
336 #ifdef __cplusplus
337 }
338 #endif
339 #endif // DRAM_H
340  // dram
342 
343 // ------------------------------------------------------------------------ END
dram_set_io2_pin
void dram_set_io2_pin(dram_t *ctx, uint8_t state)
DRAM set io2 pin function.
DRAM_ERROR
@ DRAM_ERROR
Definition: dram.h:178
dram_cfg_t::io3
pin_name_t io3
Definition: dram.h:161
dram_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: dram.h:166
dram_memory_read
err_t dram_memory_read(dram_t *ctx, uint32_t address, uint8_t *data_out, uint32_t len)
DRAM memory read function.
dram_memory_read_fast
err_t dram_memory_read_fast(dram_t *ctx, uint32_t address, uint8_t *data_out, uint32_t len)
DRAM memory read fast function.
dram_return_value_t
dram_return_value_t
DRAM Click return value data.
Definition: dram.h:176
spi_specifics.h
This file contains SPI specific macros, functions, etc.
dram_toggle_wrap_boundary
err_t dram_toggle_wrap_boundary(dram_t *ctx)
DRAM toggle wrap boundary function.
dram_t::io3
digital_out_t io3
Definition: dram.h:138
DRAM_OK
@ DRAM_OK
Definition: dram.h:177
dram_cfg_t::mosi
pin_name_t mosi
Definition: dram.h:156
dram_set_io3_pin
void dram_set_io3_pin(dram_t *ctx, uint8_t state)
DRAM set io3 pin function.
dram_check_communication
err_t dram_check_communication(dram_t *ctx)
DRAM check communication function.
dram_init
err_t dram_init(dram_t *ctx, dram_cfg_t *cfg)
DRAM initialization function.
dram_t::chip_select
pin_name_t chip_select
Definition: dram.h:144
dram_cfg_t::cs
pin_name_t cs
Definition: dram.h:158
dram_t::spi
spi_master_t spi
Definition: dram.h:142
dram_t::io2
digital_out_t io2
Definition: dram.h:139
dram_cfg_t
DRAM Click configuration object.
Definition: dram.h:153
dram_t
DRAM Click context object.
Definition: dram.h:136
dram_cfg_t::miso
pin_name_t miso
Definition: dram.h:155
dram_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: dram.h:167
dram_cfg_setup
void dram_cfg_setup(dram_cfg_t *cfg)
DRAM configuration object setup function.
dram_cfg_t::spi_speed
uint32_t spi_speed
Definition: dram.h:165
dram_memory_write
err_t dram_memory_write(dram_t *ctx, uint32_t address, uint8_t *data_in, uint32_t len)
DRAM memory write function.
dram_cfg_t::io2
pin_name_t io2
Definition: dram.h:162
dram_cfg_t::sck
pin_name_t sck
Definition: dram.h:157
dram_reset
err_t dram_reset(dram_t *ctx)
DRAM reset function.
dram_read_id
err_t dram_read_id(dram_t *ctx, uint8_t *device_id)
DRAM read id function.