smartmic  2.0.0.0
smartmic.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 SMARTMIC_H
29 #define SMARTMIC_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_uart.h"
48 #include "drv_i2c_master.h"
49 #include "drv_spi_master.h"
50 #include "spi_specifics.h"
51 
72 #define SMARTMIC_NO_RESPONSE_BIT 0x1000
73 #define SMARTMIC_CMD_SYNC 0x8000
74 #define SMARTMIC_CMD_SET_AUDIO_DATA_PORT 0x8004
75 #define SMARTMIC_CMD_GET_DEVICE_PARAM 0x800B
76 #define SMARTMIC_CMD_SET_DEVICE_PARAM_ID 0x800C
77 #define SMARTMIC_CMD_SET_DEVICE_PARAM 0x800D
78 #define SMARTMIC_CMD_GET_CHIP_ID 0x800E
79 #define SMARTMIC_CMD_SET_POWER_STATE ( 0x8010 | SMARTMIC_NO_RESPONSE_BIT )
80 #define SMARTMIC_CMD_SET_CLOCK_SOURCE 0x8011
81 #define SMARTMIC_CMD_SET_UART_STOP_BITS 0x8012
82 #define SMARTMIC_CMD_GET_SIG_RMS 0x8013
83 #define SMARTMIC_CMD_GET_SIG_PEAK 0x8014
84 #define SMARTMIC_CMD_SET_DIG_GAIN 0x8015
85 #define SMARTMIC_CMD_GET_ALGO_PARAM 0x8016
86 #define SMARTMIC_CMD_SET_ALGO_PARAM_ID 0x8017
87 #define SMARTMIC_CMD_SET_ALGO_PARAM 0x8018
88 #define SMARTMIC_CMD_UART_RATE_REQUEST 0x8019
89 #define SMARTMIC_CMD_SET_EVENT_RESP 0x801A
90 #define SMARTMIC_CMD_SET_DIAG_CONFIG 0x801C
91 #define SMARTMIC_CMD_GET_DIG_GAIN 0x801D
92 #define SMARTMIC_CMD_OUTPUT_KNOWN_SIG 0x801E
93 #define SMARTMIC_CMD_GET_FIRST_BUILD_STR 0x8020
94 #define SMARTMIC_CMD_GET_NEXT_BUILD_STR 0x8021
95 #define SMARTMIC_CMD_GET_INFO 0x8022
96 #define SMARTMIC_CMD_SET_SPI_SAMPLE_CFG 0x8023
97 #define SMARTMIC_CMD_SET_STREAMING 0x8025
98 #define SMARTMIC_CMD_GET_BAF_INFO 0x8027
99 #define SMARTMIC_CMD_SELECT_STREAMING 0x8028
100 #define SMARTMIC_CMD_CONFIG_DATA_PORT 0x802C
101 #define SMARTMIC_CMD_READ_DATA_BLOCK 0x802E
102 #define SMARTMIC_CMD_WRITE_DATA_BLOCK 0x802F
103 #define SMARTMIC_CMD_SET_SAMPLE_RATE 0x8030
104 #define SMARTMIC_CMD_SET_PRESET 0x8031
105 #define SMARTMIC_CMD_SELECT_ROUTE 0x8032
106 #define SMARTMIC_CMD_STOP_ROUTE 0x8033
107 #define SMARTMIC_CMD_SET_BUFF_DATA_FORMAT 0x8034
108 #define SMARTMIC_CMD_SET_FRAME_SIZE 0x8035
109 #define SMARTMIC_CMD_PDM_BYPASS_MODE 0x8040
110 #define SMARTMIC_CMD_SET_AUDIO_PORT_CLK_F 0x8042
111 #define SMARTMIC_CMD_POWER_DOWN_INT_OSC 0x8043
112 #define SMARTMIC_CMD_SET_DIG_HW_PT 0x8052
113 #define SMARTMIC_CMD_ENABLE_DISABLE_JTAG 0x8061
114 #define SMARTMIC_CMD_SET_PAD_CONTROL 0x8062
115 #define SMARTMIC_CMD_GET_EVENT 0x806D
116  // smartmic_reg
118 
133 #define SMARTMIC_VQ_CMD_VS_PROCESSING_MODE 0x5003
134 #define SMARTMIC_VQ_CMD_OEM_SENSITIVITY 0x5008
135 #define SMARTMIC_VQ_CMD_UTK_SENSITIVITY 0x5009
136 #define SMARTMIC_VQ_CMD_VID_SENSITIVITY 0x500D
137 #define SMARTMIC_VQ_CMD_RESET 0x500E
138 
143 #define SMARTMIC_VS_PROCESSING_MODE_KW 0x0000 // Keyword Detection mode
144 #define SMARTMIC_OEM_SENSITIVITY_5 0x0005 // Set the OEM Detection Sensitivity to 5
145 #define SMARTMIC_UTK_SENSITIVITY_0 0x0000 // Set the UTK Detection Sensitivity to 0
146 #define SMARTMIC_VID_SENSITIVITY_2 0x0002 // Set the Voice ID Detection Sensitivity to 0
147 #define SMARTMIC_RESET 0x0001 // Perform reset
148 
153 #define SMARTMIC_SYNC_BYTE 0xB7
154 #define SMARTMIC_BOOT_BYTE 0x01
155 #define SMARTMIC_SAMPLE_RATE_16K 0x0001 // 16k Sample Rate
156 #define SMARTMIC_FRAME_SIZE_16MS 0x0010 // For Voice Q 16 mS Frame Size
157 #define SMARTMIC_BUFF_DATA_FORMAT_16BIT 0x0002 // 16 bit Buffer Data Format
158 #define SMARTMIC_ROUTE_6 0x0006 // Select Route 6
159 #define SMARTMIC_DIGITAL_GAIN_20 0x0C14 // 20 db Gain and End point ID = 12
160 #define SMARTMIC_END_POINT_ID 0x0C00 // Endpoint ID for Route-6 Stream manager-0
161 #define SMARTMIC_LOW_POWER_MODE_RT6 0x0002 // Low Power mode for Route 6
162 #define SMARTMIC_IA611_INT_RISING_EDGE 0x04
163 #define SMARTMIC_IA611_INT_FALLING_EDGE 0x03
164 #define SMARTMIC_IA611_INT_LOW_LEVEL 0x01
165 #define SMARTMIC_WDB_SIZE_NO_HEADER 508 // Data block size without 4 byte Header
166 #define SMARTMIC_WDB_SIZE 512 // Data block size with 4 byte Header
167 #define SMARTMIC_UART_EVENT_HEADER 0xFE
168 #define SMARTMIC_NO_KWD_DETECTED 0
169 #define SMARTMIC_OEM1_KWD_DETECTED 1
170 #define SMARTMIC_OEM2_KWD_DETECTED 2
171 #define SMARTMIC_OEM3_KWD_DETECTED 3
172 #define SMARTMIC_OEM4_KWD_DETECTED 4
173 
178 #define SMARTMIC_DRIVER_UART 0
179 #define SMARTMIC_DRIVER_SPI 1
180 #define SMARTMIC_DRIVER_I2C 2
181 #define SMARTMIC_DRIVER_SELECTOR SMARTMIC_DRIVER_I2C
182 
187 #define SMARTMIC_SYS_CFG_6SEC_TO 0
188 #define SMARTMIC_SYS_CFG_6SEC_TO_UTK 1
189 #define SMARTMIC_SYS_CFG_6SEC_TO_VID 2
190 #define SMARTMIC_SYS_CFG_SELECTOR SMARTMIC_SYS_CFG_6SEC_TO
191 
197 #define SMARTMIC_DEVICE_ADDRESS_0 0x3E
198 #define SMARTMIC_DEVICE_ADDRESS_1 0x3F
199 #define SMARTMIC_DEVICE_ADDRESS_2 0x38
200 #define SMARTMIC_DEVICE_ADDRESS_3 0x39
201 
210 #define SMARTMIC_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
211 #define SMARTMIC_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
212 
218 #define DRV_BUFFER_SIZE 256
219  // smartmic_set
221 
236 #define SMARTMIC_MAP_MIKROBUS( cfg, mikrobus ) \
237  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
238  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
239  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
240  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
241  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
242  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
243  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
244  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
245  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
246  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
247  // smartmic_map // smartmic
250 
255 typedef struct smartmic_s
256 {
257  digital_out_t en;
259  digital_in_t irq;
261 #if ( SMARTMIC_DRIVER_SELECTOR == SMARTMIC_DRIVER_UART )
262  uart_t uart;
263  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
264  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
265 #elif ( SMARTMIC_DRIVER_SELECTOR == SMARTMIC_DRIVER_I2C )
266  i2c_master_t i2c;
267  uint8_t slave_address;
268 #else
269  spi_master_t spi;
270  pin_name_t chip_select;
271 #endif
272 
274 
279 typedef struct
280 {
281  pin_name_t rx_pin;
282  pin_name_t tx_pin;
283  pin_name_t scl;
284  pin_name_t sda;
285  pin_name_t miso;
286  pin_name_t mosi;
287  pin_name_t sck;
288  pin_name_t cs;
289  pin_name_t en;
290  pin_name_t int_pin;
292 #if ( SMARTMIC_DRIVER_SELECTOR == SMARTMIC_DRIVER_UART )
293  uint32_t baud_rate;
294  bool uart_blocking;
295  uart_data_bits_t data_bit;
296  uart_parity_t parity_bit;
297  uart_stop_bits_t stop_bit;
298 #elif ( SMARTMIC_DRIVER_SELECTOR == SMARTMIC_DRIVER_I2C )
299  uint32_t i2c_speed;
300  uint8_t i2c_address;
301 #else
302  uint32_t spi_speed;
303  spi_master_mode_t spi_mode;
304  spi_master_chip_select_polarity_t cs_polarity;
305 #endif
306 
308 
313 typedef enum
314 {
318 
320 
337 
352 
366 
379 err_t smartmic_write_data ( smartmic_t *ctx, uint8_t *data_in, uint16_t len );
380 
393 err_t smartmic_read_data ( smartmic_t *ctx, uint8_t *data_out, uint16_t len );
394 
409 err_t smartmic_send_command ( smartmic_t *ctx, uint16_t cmd, uint16_t data_in, uint16_t *response );
410 
424 err_t smartmic_download_bin ( smartmic_t *ctx, uint8_t *data_in, uint32_t len );
425 
438 
452 
465 err_t smartmic_download_keyword ( smartmic_t *ctx, uint16_t *data_in, uint16_t len );
466 
479 
491 
501 
511 
521 
522 #ifdef __cplusplus
523 }
524 #endif
525 #endif // SMARTMIC_H
526  // smartmic
528 
529 // ------------------------------------------------------------------------ END
SMARTMIC_OK
@ SMARTMIC_OK
Definition: smartmic.h:315
smartmic_cfg_setup
void smartmic_cfg_setup(smartmic_cfg_t *cfg)
Smart Mic configuration object setup function.
smartmic_cfg_t
Smart Mic Click configuration object.
Definition: smartmic.h:280
smartmic_download_config
err_t smartmic_download_config(smartmic_t *ctx)
Smart Mic download config function.
smartmic_write_data
err_t smartmic_write_data(smartmic_t *ctx, uint8_t *data_in, uint16_t len)
Smart Mic write data function.
smartmic_s::irq
digital_in_t irq
Definition: smartmic.h:259
smartmic_s::slave_address
uint8_t slave_address
Definition: smartmic.h:267
spi_specifics.h
This file contains SPI specific macros, functions, etc.
smartmic_cfg_t::miso
pin_name_t miso
Definition: smartmic.h:285
smartmic_cfg_t::en
pin_name_t en
Definition: smartmic.h:289
smartmic_send_command
err_t smartmic_send_command(smartmic_t *ctx, uint16_t cmd, uint16_t data_in, uint16_t *response)
Smart Mic send command function.
smartmic_cfg_t::sck
pin_name_t sck
Definition: smartmic.h:287
smartmic_download_firmware
err_t smartmic_download_firmware(smartmic_t *ctx)
Smart Mic download firmware function.
smartmic_download_keyword
err_t smartmic_download_keyword(smartmic_t *ctx, uint16_t *data_in, uint16_t len)
Smart Mic download keyword function.
smartmic_cfg_t::tx_pin
pin_name_t tx_pin
Definition: smartmic.h:282
smartmic_s
Smart Mic Click context object.
Definition: smartmic.h:256
smartmic_cfg_t::int_pin
pin_name_t int_pin
Definition: smartmic.h:290
smartmic_cfg_t::cs
pin_name_t cs
Definition: smartmic.h:288
smartmic_cfg_t::mosi
pin_name_t mosi
Definition: smartmic.h:286
SMARTMIC_FIRMWARE_OK
@ SMARTMIC_FIRMWARE_OK
Definition: smartmic.h:317
smartmic_t
struct smartmic_s smartmic_t
Smart Mic Click context object.
smartmic_init
err_t smartmic_init(smartmic_t *ctx, smartmic_cfg_t *cfg)
Smart Mic initialization function.
smartmic_cfg_t::sda
pin_name_t sda
Definition: smartmic.h:284
smartmic_download_bin
err_t smartmic_download_bin(smartmic_t *ctx, uint8_t *data_in, uint32_t len)
Smart Mic download bin function.
smartmic_wait_keyword
err_t smartmic_wait_keyword(smartmic_t *ctx)
Smart Mic wait keyword function.
SMARTMIC_ERROR
@ SMARTMIC_ERROR
Definition: smartmic.h:316
smartmic_enable_device
void smartmic_enable_device(smartmic_t *ctx)
Smart Mic enable device function.
smartmic_cfg_t::scl
pin_name_t scl
Definition: smartmic.h:283
smartmic_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: smartmic.h:299
smartmic_cfg_t::rx_pin
pin_name_t rx_pin
Definition: smartmic.h:281
smartmic_disable_device
void smartmic_disable_device(smartmic_t *ctx)
Smart Mic disable device function.
smartmic_s::i2c
i2c_master_t i2c
Definition: smartmic.h:266
smartmic_default_cfg
err_t smartmic_default_cfg(smartmic_t *ctx)
Smart Mic default configuration function.
smartmic_s::en
digital_out_t en
Definition: smartmic.h:257
smartmic_return_value_t
smartmic_return_value_t
Smart Mic Click return value data.
Definition: smartmic.h:314
smartmic_voice_make
err_t smartmic_voice_make(smartmic_t *ctx)
Smart Mic voice make function.
smartmic_cfg_t::i2c_address
uint8_t i2c_address
Definition: smartmic.h:300
smartmic_read_data
err_t smartmic_read_data(smartmic_t *ctx, uint8_t *data_out, uint16_t len)
Smart Mic read data function.
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
Smart Mic driver buffer size.
Definition: smartmic.h:218
smartmic_get_irq_pin
uint8_t smartmic_get_irq_pin(smartmic_t *ctx)
Smart Mic get irq pin function.