recnplay  2.0.0.0
recnplay.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 RECNPLAY_H
36 #define RECNPLAY_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_digital_in.h"
50 #include "drv_spi_master.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
64 #define RECNPLAY_MAP_MIKROBUS( cfg, mikrobus ) \
65  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
66  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
67  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
68  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
69  cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_AN ); \
70  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
72 
78 #define RECPLAY_PLAY_VP 0xA6
79 #define RECPLAY_PLAY_VP_RN 0xAE
80 #define RECPLAY_EXE_VM 0xB0
81 #define RECPLAY_REC_MSG 0x38
82 #define RECPLAY_REC_MSG_ADDR 0x3A
83 #define RECPLAY_PLAY_MSG 0x3C
84 #define RECPLAY_PLAY_SIL 0xA8
85 #define RECPLAY_STOP 0x2A
86 #define RECPLAY_ERASE_MSG 0x3E
87 #define RECPLAY_SPI_PCM_WRITE 0xAA
88 #define RECPLAY_SPI_PCM_READ 0xAC
89 #define RECPLAY_SPI_SND_DEC 0xC0
90 #define RECPLAY_SPI_RCV_ENC 0xC2
91 #define RECPLAY_READ_STATUS 0x40
92 #define RECPLAY_READ_INT 0x46
93 #define RECPLAY_READ_MSG_ADDR 0x42
94 #define RECPLAY_READ_MSG_LEN 0x44
95 #define RECPLAY_READ_ID 0x48
96 #define RECPLAY_DIG_READ 0xA2
97 #define RECPLAY_DIG_WRITE 0xA0
98 #define RECPLAY_ERASE_MEM 0x24
99 #define RECPLAY_CHIP_ERASE 0x26
100 #define RECPLAY_PWR_UP 0x10
101 #define RECPLAY_PWR_DOWN 0x12
102 #define RECPLAY_SET_CLK_CFG 0xB4
103 #define RECPLAY_READ_CLK_CFG 0xB6
104 #define RECPLAY_WRITE_CFG_REG 0xB8
105 #define RECPLAY_READ_CFG_REG 0xBA
106 
112 #define RECPLAY_INT_PEAK_DET_MASK 0x80
113 #define RECPLAY_INT_MEM_PROT_ERR_MASK 0x40
114 #define RECPLAY_INT_WR_FIN_MASK 0x20
115 #define RECPLAY_INT_CMD_ERR_MASK 0x10
116 #define RECPLAY_INT_OVF_ERR_MASK 0x08
117 #define RECPLAY_INT_CMD_FIN_MASK 0x04
118 #define RECPLAY_INT_ADDR_ERR_MASK 0x02
119 #define RECPLAY_INT_FULL_ERR_MASK 0x01
120 
126 #define RECPLAY_STAT_PWR_DOWN_MASK 0x80
127 #define RECPLAY_STAT_DBUF_RDY_MASK 0x40
128 #define RECPLAY_STAT_INT_GEN_MASK 0x20
129 #define RECPLAY_STAT_REC_MEM_FULL_MASK 0x10
130 #define RECPLAY_STAT_VM_BSY_MASK 0x04
131 #define RECPLAY_STAT_CBUF_FULL_MASK 0x02
132 #define RECPLAY_STAT_CMD_BSY_MASK 0x01
133 
139 #define RECPLAY_INT_GEN_PIN 0x00
140 #define RECPLAY_INT_NO_GEN_PIN 0x01
141 #define RECPLAY_SPI_RDY_PIN 0x01
142 #define RECPLAY_SPI_BSY_PIN 0x00
143 
149 #define RECPLAY_CFG00_REG 0x00
150 #define RECPLAY_CFG01_REG 0x01
151 #define RECPLAY_CFG02_REG 0x02
152 #define RECPLAY_CFG03_REG 0x03
153 #define RECPLAY_CFG04_REG 0x04
154 #define RECPLAY_CFG05_REG 0x05
155 #define RECPLAY_CFG06_REG 0x06
156 #define RECPLAY_CFG07_REG 0x07
157 #define RECPLAY_CFG08_REG 0x08
158 #define RECPLAY_CFG09_REG 0x09
159 #define RECPLAY_CFG0A_REG 0x0A
160 #define RECPLAY_CFG0B_REG 0x0B
161 #define RECPLAY_CFG0C_REG 0x0C
162 #define RECPLAY_CFG0D_REG 0x0D
163 #define RECPLAY_CFG0E_REG 0x0E
164 #define RECPLAY_CFG0F_REG 0x0F
165 #define RECPLAY_CFG10_REG 0x10
166 #define RECPLAY_CFG11_REG 0x11
167 #define RECPLAY_CFG12_REG 0x12
168 #define RECPLAY_CFG13_REG 0x13
169 #define RECPLAY_CFG14_REG 0x14
170 #define RECPLAY_CFG15_REG 0x15
171 #define RECPLAY_CFG16_REG 0x16
172 #define RECPLAY_CFG17_REG 0x17
173 #define RECPLAY_CFG18_REG 0x18
174 #define RECPLAY_CFG19_REG 0x19
175 #define RECPLAY_CFG1A_REG 0x1A
176 #define RECPLAY_CFG1B_REG 0x1B
177 #define RECPLAY_CFG1C_REG 0x1C
178 #define RECPLAY_CFG1D_REG 0x1D
179 #define RECPLAY_CFG1E_REG 0x1E
180 #define RECPLAY_CFG1F_REG 0x1F
181 #define RECPLAY_CFG20_REG 0x20
182 #define RECPLAY_CFG21_REG 0x21
183 #define RECPLAY_CFG22_REG 0x22
184 #define RECPLAY_CFG23_REG 0x23
185 #define RECPLAY_CFG24_REG 0x24
186 #define RECPLAY_CFG25_REG 0x25
187 #define RECPLAY_CFG26_REG 0x26
188 #define RECPLAY_CFG27_REG 0x27
189 #define RECPLAY_CFG28_REG 0x28
190 #define RECPLAY_CFG29_REG 0x29
191 #define RECPLAY_CFG2A_REG 0x2A
192 #define RECPLAY_CFG2B_REG 0x2B
193 #define RECPLAY_CFG2C_REG 0x2C
194 #define RECPLAY_CFG2D_REG 0x2D
195 #define RECPLAY_CFG2E_REG 0x2E
196 #define RECPLAY_CFG2F_REG 0x2F
197 
203 #define RECNPLAY_RETVAL uint8_t
204 
205 #define RECNPLAY_OK 0x00
206 #define RECNPLAY_INIT_ERROR 0xFF
207  // End group macro
210 // --------------------------------------------------------------- PUBLIC TYPES
219 typedef struct
220 {
221  // Output pins
222 
223  digital_out_t cs;
224  digital_out_t rst;
225 
226  // Input pins
227 
228  digital_in_t rdy;
229  digital_in_t int_pin;
230 
231  // Modules
232 
233  spi_master_t spi;
234  pin_name_t chip_select;
235 
236 } recnplay_t;
237 
241 typedef struct
242 {
243  uint8_t part_id;
244  uint8_t man_id;
245  uint8_t mem_type;
246  uint8_t dev_id;
247 
249 
253 typedef struct
254 {
255  // Communication gpio pins
256 
257  pin_name_t miso;
258  pin_name_t mosi;
259  pin_name_t sck;
260  pin_name_t cs;
261 
262  // Additional gpio pins
263 
264  pin_name_t rdy;
265  pin_name_t rst;
266  pin_name_t int_pin;
267 
268  // static variable
269 
270  uint32_t spi_speed;
271  spi_master_mode_t spi_mode;
272  spi_master_chip_select_polarity_t cs_polarity;
273 
275  // End types group
277 
278 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
279 
284 #ifdef __cplusplus
285 extern "C"{
286 #endif
287 
297 
307 
319 void recnplay_generic_transfer ( recnplay_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
320 
333 RECNPLAY_RETVAL recplay_play_vp ( recnplay_t* ctx, uint16_t index );
334 
347 RECNPLAY_RETVAL recplay_play_vp_rn ( recnplay_t* ctx, uint8_t value_rn );
348 
361 
374 
388 
402 RECNPLAY_RETVAL recplay_play_msg ( recnplay_t* ctx, uint32_t mem_addr, uint16_t sector_offset );
403 
415 RECNPLAY_RETVAL recplay_play_silence ( recnplay_t* ctx, uint8_t silence_length );
416 
428 
441 RECNPLAY_RETVAL recplay_erase_msg ( recnplay_t* ctx, uint32_t mem_addr );
442 
455 RECNPLAY_RETVAL recplay_spi_write_pcm ( recnplay_t* ctx, uint16_t* data_pcm, uint8_t num_pcm );
456 
469 RECNPLAY_RETVAL recplay_spi_read_pcm ( recnplay_t* ctx, uint16_t* data_pcm, uint8_t num_pcm );
470 
483 RECNPLAY_RETVAL recplay_spi_send_cmprsd_data ( recnplay_t* ctx, uint8_t* cmprsd_data, uint8_t n_data );
484 
497 RECNPLAY_RETVAL recplay_spi_receive_enc_data ( recnplay_t* ctx, uint8_t* encoded_data, uint8_t n_data );
498 
510 RECNPLAY_RETVAL recplay_read_status ( recnplay_t* ctx, uint8_t* interr_status );
511 
523 RECNPLAY_RETVAL recplay_read_interr ( recnplay_t* ctx, uint8_t* interr_status );
524 
537 RECNPLAY_RETVAL recplay_read_msg_addr ( recnplay_t* ctx, uint32_t* msg_addr, uint16_t* msg_length );
538 
550 RECNPLAY_RETVAL recplay_read_msg_length ( recnplay_t* ctx, uint16_t* msg_length );
551 
564 
579 RECNPLAY_RETVAL recplay_dig_read ( recnplay_t* ctx, uint32_t mem_addr, uint8_t* data_out, uint8_t n_data );
580 
595 RECNPLAY_RETVAL recplay_dig_write ( recnplay_t* ctx, uint32_t mem_addr, uint8_t* data_in, uint8_t n_data );
596 
610 RECNPLAY_RETVAL recplay_erase_mem ( recnplay_t* ctx, uint32_t start_addr, uint32_t end_addr );
611 
624 
636 
648 
660 
673 
687 RECNPLAY_RETVAL recplay_write_cnfg_reg ( recnplay_t* ctx, uint8_t reg_addr, uint8_t* cnfg_data, uint8_t n_data );
688 
702 RECNPLAY_RETVAL recplay_read_cnfg_reg ( recnplay_t* ctx, uint8_t reg_addr, uint8_t* cnfg_data, uint8_t n_data );
703 
713 uint8_t recplay_check_rdy ( recnplay_t* ctx );
714 
724 uint8_t recplay_check_int ( recnplay_t* ctx );
725 
733 void recplay_reset ( recnplay_t* ctx );
734 
735 
736 #ifdef __cplusplus
737 }
738 #endif
739 #endif // _RECNPLAY_H_
740  // End public_function group
743 
744 // ------------------------------------------------------------------------- END
recplay_read_interr
RECNPLAY_RETVAL recplay_read_interr(recnplay_t *ctx, uint8_t *interr_status)
Interrupt Read Command.
recplay_play_vp
RECNPLAY_RETVAL recplay_play_vp(recnplay_t *ctx, uint16_t index)
Voice Prompt Play Command.
recnplay_t::rst
digital_out_t rst
Definition: recnplay.h:224
recnplay_t::cs
digital_out_t cs
Definition: recnplay.h:223
recnplay_dev_id_t::mem_type
uint8_t mem_type
Definition: recnplay.h:245
recplay_read_cnfg_reg
RECNPLAY_RETVAL recplay_read_cnfg_reg(recnplay_t *ctx, uint8_t reg_addr, uint8_t *cnfg_data, uint8_t n_data)
Configuration Read Command.
RECNPLAY_RETVAL
#define RECNPLAY_RETVAL
Definition: recnplay.h:203
recplay_check_rdy
uint8_t recplay_check_rdy(recnplay_t *ctx)
SPI Data Transfer Status Check Command.
recnplay_t
Click ctx object definition.
Definition: recnplay.h:220
recplay_spi_receive_enc_data
RECNPLAY_RETVAL recplay_spi_receive_enc_data(recnplay_t *ctx, uint8_t *encoded_data, uint8_t n_data)
SPI Receive Encoded Data Command.
recplay_play_msg
RECNPLAY_RETVAL recplay_play_msg(recnplay_t *ctx, uint32_t mem_addr, uint16_t sector_offset)
Message Play at Address Command.
recplay_stop
RECNPLAY_RETVAL recplay_stop(recnplay_t *ctx)
Stop Command.
recplay_play_vp_rn
RECNPLAY_RETVAL recplay_play_vp_rn(recnplay_t *ctx, uint8_t value_rn)
Voice Prompt @Rn Play Command.
recplay_execute_vm
RECNPLAY_RETVAL recplay_execute_vm(recnplay_t *ctx, uint16_t index)
Voice Macro Execute Command.
recplay_erase_chip
RECNPLAY_RETVAL recplay_erase_chip(recnplay_t *ctx)
Chip Erase Command.
recnplay_dev_id_t::man_id
uint8_t man_id
Definition: recnplay.h:244
recnplay_dev_id_t::dev_id
uint8_t dev_id
Definition: recnplay.h:246
recplay_write_cnfg_reg
RECNPLAY_RETVAL recplay_write_cnfg_reg(recnplay_t *ctx, uint8_t reg_addr, uint8_t *cnfg_data, uint8_t n_data)
Configuration Write Command.
recnplay_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: recnplay.h:271
recnplay_init
RECNPLAY_RETVAL recnplay_init(recnplay_t *ctx, recnplay_cfg_t *cfg)
Initialization function.
recplay_spi_write_pcm
RECNPLAY_RETVAL recplay_spi_write_pcm(recnplay_t *ctx, uint16_t *data_pcm, uint8_t num_pcm)
PCM Data SPI Write Command.
recplay_read_clk_cnfg
RECNPLAY_RETVAL recplay_read_clk_cnfg(recnplay_t *ctx, uint8_t *clk_cnfg)
Clock Configuration Read Command.
recplay_reset
void recplay_reset(recnplay_t *ctx)
ISD3900 Reset Command.
recnplay_cfg_t::rst
pin_name_t rst
Definition: recnplay.h:265
recplay_record_msg_addr
RECNPLAY_RETVAL recplay_record_msg_addr(recnplay_t *ctx, uint32_t mem_addr)
Message Record at Address Command.
recnplay_cfg_t
Click configuration structure definition.
Definition: recnplay.h:254
recnplay_cfg_t::rdy
pin_name_t rdy
Definition: recnplay.h:264
recnplay_generic_transfer
void recnplay_generic_transfer(recnplay_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
recplay_dig_write
RECNPLAY_RETVAL recplay_dig_write(recnplay_t *ctx, uint32_t mem_addr, uint8_t *data_in, uint8_t n_data)
Digital Write Command.
recnplay_cfg_t::mosi
pin_name_t mosi
Definition: recnplay.h:258
recnplay_cfg_setup
void recnplay_cfg_setup(recnplay_cfg_t *cfg)
Config Object Initialization function.
recplay_spi_send_cmprsd_data
RECNPLAY_RETVAL recplay_spi_send_cmprsd_data(recnplay_t *ctx, uint8_t *cmprsd_data, uint8_t n_data)
SPI Send Compressed Data to Decode Command.
recplay_record_msg
RECNPLAY_RETVAL recplay_record_msg(recnplay_t *ctx)
Message Record Command.
recnplay_cfg_t::spi_speed
uint32_t spi_speed
Definition: recnplay.h:270
recplay_pwr_up
RECNPLAY_RETVAL recplay_pwr_up(recnplay_t *ctx)
Power Up Command.
recplay_read_msg_addr
RECNPLAY_RETVAL recplay_read_msg_addr(recnplay_t *ctx, uint32_t *msg_addr, uint16_t *msg_length)
Recorded Message Address Read Command.
recnplay_t::chip_select
pin_name_t chip_select
Definition: recnplay.h:234
recplay_erase_msg
RECNPLAY_RETVAL recplay_erase_msg(recnplay_t *ctx, uint32_t mem_addr)
Message Erase at Address Command.
recnplay_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: recnplay.h:272
recplay_erase_mem
RECNPLAY_RETVAL recplay_erase_mem(recnplay_t *ctx, uint32_t start_addr, uint32_t end_addr)
Memory Erase Command.
recplay_dig_read
RECNPLAY_RETVAL recplay_dig_read(recnplay_t *ctx, uint32_t mem_addr, uint8_t *data_out, uint8_t n_data)
Digital Read Command.
recnplay_t::int_pin
digital_in_t int_pin
Definition: recnplay.h:229
recnplay_dev_id_t
Device ID data.
Definition: recnplay.h:242
recplay_set_clk_cnfg
RECNPLAY_RETVAL recplay_set_clk_cnfg(recnplay_t *ctx, uint8_t clk_cnfg)
Clock Configuration Set Command.
recnplay_cfg_t::sck
pin_name_t sck
Definition: recnplay.h:259
recnplay_cfg_t::miso
pin_name_t miso
Definition: recnplay.h:257
recplay_play_silence
RECNPLAY_RETVAL recplay_play_silence(recnplay_t *ctx, uint8_t silence_length)
Silence Play Command.
recplay_pwr_down
RECNPLAY_RETVAL recplay_pwr_down(recnplay_t *ctx)
Power Down Command.
recnplay_cfg_t::int_pin
pin_name_t int_pin
Definition: recnplay.h:266
recnplay_t::rdy
digital_in_t rdy
Definition: recnplay.h:228
recnplay_cfg_t::cs
pin_name_t cs
Definition: recnplay.h:260
recplay_spi_read_pcm
RECNPLAY_RETVAL recplay_spi_read_pcm(recnplay_t *ctx, uint16_t *data_pcm, uint8_t num_pcm)
PCM Data SPI Read Command.
recplay_read_msg_length
RECNPLAY_RETVAL recplay_read_msg_length(recnplay_t *ctx, uint16_t *msg_length)
Message Length Read Command.
recplay_read_id
RECNPLAY_RETVAL recplay_read_id(recnplay_t *ctx, recnplay_dev_id_t *dev_id_data)
ISD3900 ID Read Command.
recnplay_t::spi
spi_master_t spi
Definition: recnplay.h:233
recnplay_dev_id_t::part_id
uint8_t part_id
Definition: recnplay.h:243
recplay_read_status
RECNPLAY_RETVAL recplay_read_status(recnplay_t *ctx, uint8_t *interr_status)
Status Read Command.
recplay_check_int
uint8_t recplay_check_int(recnplay_t *ctx)
Interrupt Request Pin Check Command.