excelonlp  2.0.0.0
excelonlp.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 EXCELONLP_H
36 #define EXCELONLP_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_spi_master.h"
50 
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
63 #define EXCELONLP_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
65  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
66  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
67  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
68  cfg.wp = MIKROBUS( mikrobus, MIKROBUS_PWM )
69 
75 #define EXCELONLP_RETVAL uint8_t
76 
77 #define EXCELONLP_OK 0x00
78 #define EXCELONLP_INIT_ERROR 0xFF
79 
85 #define EXCELONLP_OPCODE_SET_WRITE_ENABLE_LATCH 0x06
86 #define EXCELONLP_OPCODE_RESET_WRITE_ENABLE_LATCH 0x04
87 #define EXCELONLP_OPCODE_READ_STATUS_REGISTER 0x05
88 #define EXCELONLP_OPCODE_WRITE_STATUS_REGISTER 0x01
89 #define EXCELONLP_OPCODE_WRITE_MEMORY_DATA 0x02
90 #define EXCELONLP_OPCODE_READ_MEMORY_DATA 0x03
91 #define EXCELONLP_OPCODE_FAST_READ_MEMORY_DATA 0x0B
92 #define EXCELONLP_OPCODE_SPECIAL_SECTOR_WRITE 0x42
93 #define EXCELONLP_OPCODE_SPECIAL_SECTOR_READ 0x4B
94 #define EXCELONLP_OPCODE_READ_DEVICE_ID 0x9F
95 #define EXCELONLP_OPCODE_READ_UNIQUE_ID 0x4C
96 #define EXCELONLP_OPCODE_WRITE_SERIAL_NUMBER 0xC2
97 #define EXCELONLP_OPCODE_READ_SERIAL_NUMBER 0xC3
98 #define EXCELONLP_OPCODE_ENTER_DEEP_POWER_DOWN 0xBA
99 #define EXCELONLP_OPCODE_Enter_Hibernate_Mode 0xB9
100  // End group macro
103 // --------------------------------------------------------------- PUBLIC TYPES
112 typedef struct
113 {
114  digital_out_t cs;
115 
116  // Output pins
117 
118  digital_out_t wp;
119 
120  // Modules
121 
122  spi_master_t spi;
123  pin_name_t chip_select;
124 
125 } excelonlp_t;
126 
130 typedef struct
131 {
132  // Communication gpio pins
133 
134  pin_name_t miso;
135  pin_name_t mosi;
136  pin_name_t sck;
137  pin_name_t cs;
138 
139  // Additional gpio pins
140 
141  pin_name_t wp;
142 
143  // static variable
144 
145  uint32_t spi_speed;
146  spi_master_mode_t spi_mode;
147  spi_master_chip_select_polarity_t cs_polarity;
148 
150  // End types group
152 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
153 
158 #ifdef __cplusplus
159 extern "C"{
160 #endif
161 
171 
181 
193 void excelonlp_generic_transfer ( excelonlp_t *ctx, uint8_t *wr_buf,
194  uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
195 
203 void excelonlp_send_command ( excelonlp_t *ctx, uint8_t opcode );
204 
214 void excelonlp_read_data ( excelonlp_t *ctx, uint8_t opcode, uint8_t *out_buf, uint8_t n_data);
215 
225 void excelonlp_write_memory_data ( excelonlp_t *ctx, uint8_t opcode, uint32_t addr, uint8_t c_data);
226 
235 uint8_t excelonlp_read_memory_data ( excelonlp_t *ctx, uint8_t opcode, uint32_t addr );
236 
237 
238 #ifdef __cplusplus
239 }
240 #endif
241 #endif // _EXCELONLP_H_
242  // End public_function group
245 
246 // ------------------------------------------------------------------------- END
excelonlp_read_memory_data
uint8_t excelonlp_read_memory_data(excelonlp_t *ctx, uint8_t opcode, uint32_t addr)
Functions for read data form memory.
excelonlp_read_data
void excelonlp_read_data(excelonlp_t *ctx, uint8_t opcode, uint8_t *out_buf, uint8_t n_data)
Functions for read data.
excelonlp_write_memory_data
void excelonlp_write_memory_data(excelonlp_t *ctx, uint8_t opcode, uint32_t addr, uint8_t c_data)
Functions for write data to memory.
excelonlp_cfg_t::sck
pin_name_t sck
Definition: excelonlp.h:136
excelonlp_cfg_setup
void excelonlp_cfg_setup(excelonlp_cfg_t *cfg)
Config Object Initialization function.
excelonlp_cfg_t::spi_speed
uint32_t spi_speed
Definition: excelonlp.h:145
excelonlp_t::cs
digital_out_t cs
Definition: excelonlp.h:114
excelonlp_cfg_t::mosi
pin_name_t mosi
Definition: excelonlp.h:135
excelonlp_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: excelonlp.h:147
excelonlp_cfg_t
Click configuration structure definition.
Definition: excelonlp.h:131
excelonlp_cfg_t::miso
pin_name_t miso
Definition: excelonlp.h:134
excelonlp_cfg_t::wp
pin_name_t wp
Definition: excelonlp.h:141
excelonlp_generic_transfer
void excelonlp_generic_transfer(excelonlp_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
excelonlp_init
EXCELONLP_RETVAL excelonlp_init(excelonlp_t *ctx, excelonlp_cfg_t *cfg)
Initialization function.
excelonlp_send_command
void excelonlp_send_command(excelonlp_t *ctx, uint8_t opcode)
Functions for send opcode command.
excelonlp_cfg_t::cs
pin_name_t cs
Definition: excelonlp.h:137
EXCELONLP_RETVAL
#define EXCELONLP_RETVAL
Definition: excelonlp.h:75
excelonlp_t::chip_select
pin_name_t chip_select
Definition: excelonlp.h:123
excelonlp_t::spi
spi_master_t spi
Definition: excelonlp.h:122
excelonlp_t::wp
digital_out_t wp
Definition: excelonlp.h:118
excelonlp_t
Click ctx object definition.
Definition: excelonlp.h:113
excelonlp_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: excelonlp.h:146