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
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_spi_master.h"
54
55
56// -------------------------------------------------------------- PUBLIC MACROS
67#define EXCELONLP_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_PWM )
79#define EXCELONLP_RETVAL uint8_t
80
81#define EXCELONLP_OK 0x00
82#define EXCELONLP_INIT_ERROR 0xFF
89#define EXCELONLP_OPCODE_SET_WRITE_ENABLE_LATCH 0x06
90#define EXCELONLP_OPCODE_RESET_WRITE_ENABLE_LATCH 0x04
91#define EXCELONLP_OPCODE_READ_STATUS_REGISTER 0x05
92#define EXCELONLP_OPCODE_WRITE_STATUS_REGISTER 0x01
93#define EXCELONLP_OPCODE_WRITE_MEMORY_DATA 0x02
94#define EXCELONLP_OPCODE_READ_MEMORY_DATA 0x03
95#define EXCELONLP_OPCODE_FAST_READ_MEMORY_DATA 0x0B
96#define EXCELONLP_OPCODE_SPECIAL_SECTOR_WRITE 0x42
97#define EXCELONLP_OPCODE_SPECIAL_SECTOR_READ 0x4B
98#define EXCELONLP_OPCODE_READ_DEVICE_ID 0x9F
99#define EXCELONLP_OPCODE_READ_UNIQUE_ID 0x4C
100#define EXCELONLP_OPCODE_WRITE_SERIAL_NUMBER 0xC2
101#define EXCELONLP_OPCODE_READ_SERIAL_NUMBER 0xC3
102#define EXCELONLP_OPCODE_ENTER_DEEP_POWER_DOWN 0xBA
103#define EXCELONLP_OPCODE_Enter_Hibernate_Mode 0xB9
106 // End group macro
107// --------------------------------------------------------------- PUBLIC TYPES
116typedef struct
117{
118 digital_out_t cs;
119
120 // Output pins
121
122 digital_out_t wp;
123
124 // Modules
125
126 spi_master_t spi;
127 pin_name_t chip_select;
128
130
134typedef struct
135{
136 // Communication gpio pins
137
138 pin_name_t miso;
139 pin_name_t mosi;
140 pin_name_t sck;
141 pin_name_t cs;
142
143 // Additional gpio pins
144
145 pin_name_t wp;
146
147 // static variable
148
149 uint32_t spi_speed;
150 spi_master_mode_t spi_mode;
151 spi_master_chip_select_polarity_t cs_polarity;
152
154
155 // End types group
156// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
157
162#ifdef __cplusplus
163extern "C"{
164#endif
165
175
185
197void excelonlp_generic_transfer ( excelonlp_t *ctx, uint8_t *wr_buf,
198 uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
199
207void excelonlp_send_command ( excelonlp_t *ctx, uint8_t opcode );
208
218void excelonlp_read_data ( excelonlp_t *ctx, uint8_t opcode, uint8_t *out_buf, uint8_t n_data);
219
229void excelonlp_write_memory_data ( excelonlp_t *ctx, uint8_t opcode, uint32_t addr, uint8_t c_data);
230
239uint8_t excelonlp_read_memory_data ( excelonlp_t *ctx, uint8_t opcode, uint32_t addr );
240
241
242#ifdef __cplusplus
243}
244#endif
245#endif // _EXCELONLP_H_
246
247 // End public_function group
249
250// ------------------------------------------------------------------------- END
#define EXCELONLP_RETVAL
Definition excelonlp.h:79
uint8_t excelonlp_read_memory_data(excelonlp_t *ctx, uint8_t opcode, uint32_t addr)
Functions for read data form memory.
void excelonlp_send_command(excelonlp_t *ctx, uint8_t opcode)
Functions for send opcode command.
void excelonlp_write_memory_data(excelonlp_t *ctx, uint8_t opcode, uint32_t addr, uint8_t c_data)
Functions for write data to memory.
void excelonlp_read_data(excelonlp_t *ctx, uint8_t opcode, uint8_t *out_buf, uint8_t n_data)
Functions for read data.
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_RETVAL excelonlp_init(excelonlp_t *ctx, excelonlp_cfg_t *cfg)
Initialization function.
void excelonlp_cfg_setup(excelonlp_cfg_t *cfg)
Config Object Initialization function.
Click configuration structure definition.
Definition excelonlp.h:135
spi_master_chip_select_polarity_t cs_polarity
Definition excelonlp.h:151
pin_name_t sck
Definition excelonlp.h:140
spi_master_mode_t spi_mode
Definition excelonlp.h:150
pin_name_t mosi
Definition excelonlp.h:139
uint32_t spi_speed
Definition excelonlp.h:149
pin_name_t wp
Definition excelonlp.h:145
pin_name_t miso
Definition excelonlp.h:138
pin_name_t cs
Definition excelonlp.h:141
Click ctx object definition.
Definition excelonlp.h:117
digital_out_t cs
Definition excelonlp.h:118
spi_master_t spi
Definition excelonlp.h:126
pin_name_t chip_select
Definition excelonlp.h:127
digital_out_t wp
Definition excelonlp.h:122