pcr 2.1.0.0
pcr.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 PCR_H
29#define PCR_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
73#define PCR_REG_VERSION 0x0000
74#define PCR_REG_PROTOCOL_STATUS 0x0001
75#define PCR_REG_MEASURE_CNT 0x0002
76#define PCR_REG_DETECTOR_STATUS 0x0003
77#define PCR_REG_DISTANCE_RESULT 0x0010
78#define PCR_REG_PEAK0_DISTANCE 0x0011
79#define PCR_REG_PEAK1_DISTANCE 0x0012
80#define PCR_REG_PEAK2_DISTANCE 0x0013
81#define PCR_REG_PEAK3_DISTANCE 0x0014
82#define PCR_REG_PEAK4_DISTANCE 0x0015
83#define PCR_REG_PEAK5_DISTANCE 0x0016
84#define PCR_REG_PEAK6_DISTANCE 0x0017
85#define PCR_REG_PEAK7_DISTANCE 0x0018
86#define PCR_REG_PEAK8_DISTANCE 0x0019
87#define PCR_REG_PEAK9_DISTANCE 0x001A
88#define PCR_REG_PEAK0_STRENGTH 0x001B
89#define PCR_REG_PEAK1_STRENGTH 0x001C
90#define PCR_REG_PEAK2_STRENGTH 0x001D
91#define PCR_REG_PEAK3_STRENGTH 0x001E
92#define PCR_REG_PEAK4_STRENGTH 0x001F
93#define PCR_REG_PEAK5_STRENGTH 0x0020
94#define PCR_REG_PEAK6_STRENGTH 0x0021
95#define PCR_REG_PEAK7_STRENGTH 0x0022
96#define PCR_REG_PEAK8_STRENGTH 0x0023
97#define PCR_REG_PEAK9_STRENGTH 0x0024
98#define PCR_REG_START 0x0040
99#define PCR_REG_END 0x0041
100#define PCR_REG_MAX_STEP_LEN 0x0042
101#define PCR_REG_CLOSE_RANGE_LEAK 0x0043
102#define PCR_REG_SIGNAL_QUALITY 0x0044
103#define PCR_REG_MAX_PROFILE 0x0045
104#define PCR_REG_TRESHOLD_SENSITIVITY 0x0046
105#define PCR_REG_PEAK_SORTI 0x0047
106#define PCR_REG_MAX_FRAMES_RECORDED 0x0048
107#define PCR_REG_AMPLITUDE_TERSHOLD 0x0049
108#define PCR_REG_TERSHOLD_SENSITIVITY 0x004A
109#define PCR_REG_REFLECTOR_SHAPE 0x004B
110#define PCR_REG_STRENGHT_TRESHOLD 0x004C
111#define PCR_REG_MEASURE_ON_WAKEUP 0x0080
112#define PCR_REG_COMMAND 0x0100
113
114 // pcr_reg
115
135#define PCR_STATUS_RSS_REG_OK 0x00000001ul
136#define PCR_STATUS_CFG_CREATE_OK 0x00000002ul
137#define PCR_STATUS_SENSOR_CREATE_OK 0x00000004ul
138#define PCR_STATUS_DETECTOR_CREATE_OK 0x00000008ul
139#define PCR_STATUS_DETECTOR_BUFFER_OK 0x00000010ul
140#define PCR_STATUS_SENSOR_BUFFER_OK 0x00000020ul
141#define PCR_STATUS_CALIB_BUFFER_OK 0x00000040ul
142#define PCR_STATUS_CFG_APPLY_OK 0x00000080ul
143#define PCR_STATUS_SENSOR_CALIB_OK 0x00000100ul
144#define PCR_STATUS_DETECTOR_CALIB_OK 0x00000200ul
145#define PCR_STATUS_RSS_REG_ERR 0x00010000ul
146#define PCR_STATUS_CFG_CREATE_ERR 0x00020000ul
147#define PCR_STATUS_SENSOR_CREATE_ERR 0x00040000ul
148#define PCR_STATUS_DETECTOR_CREATE_ERR 0x00080000ul
149#define PCR_STATUS_DETECTOR_BUFFER_ERR 0x00100000ul
150#define PCR_STATUS_SENSOR_BUFFER_ERR 0x00200000ul
151#define PCR_STATUS_CALIB_BUFFER_ERR 0x00400000ul
152#define PCR_STATUS_CFG_APPLY_ERR 0x00800000ul
153#define PCR_STATUS_SENSOR_CALIB_ERR 0x01000000ul
154#define PCR_STATUS_DETECTOR_CALIB_ERR 0x02000000ul
155#define PCR_STATUS_DETECTOR_ERR 0x10000000ul
156#define PCR_STATUS_BUSY 0x80000000ul
157
162#define PCR_APPLY_CFG_AND_CALIB_CMD 0x00000001ul
163#define PCR_MEASURE_DISTANCE_CMD 0x00000002ul
164#define PCR_APPLY_CONFIGURATION_CMD 0x00000003ul
165#define PCR_CALIBRATE_CMD 0x00000004ul
166#define PCR_RECALIBRATE_CMD 0x00000005ul
167#define PCR_ENABLE_UART_LOGS_CMD 0x00000020ul
168#define PCR_DISABLE_UART_LOGS_CMD 0x00000021ul
169#define PCR_LOG_CONFIGURATION_CMD 0x00000022ul
170#define PCR_RESET_MODULE_CMD 0x52535421ul
171
176#define PCR_PIN_STATE_HIGH 0x01
177#define PCR_PIN_STATE_LOW 0x00
178
183#define PCR_MIN_DISTANCE 10
184#define PCR_MAX_DISTANCE 5000
185
191#define PCR_DEVICE_ADDRESS 0x52
192
193 // pcr_set
194
209#define PCR_MAP_MIKROBUS( cfg, mikrobus ) \
210 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
211 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
212 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
213 cfg.wup = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
214 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
215
216 // pcr_map
217 // pcr
218
223typedef struct
224{
225 // Output pins
226 digital_out_t rst;
227 digital_out_t wup;
229 // Input pins
230 digital_in_t int_pin;
232 // Modules
233 i2c_master_t i2c;
235 // I2C slave address
238} pcr_t;
239
244typedef struct
245{
246 pin_name_t scl;
247 pin_name_t sda;
249 pin_name_t rst;
250 pin_name_t wup;
251 pin_name_t int_pin;
253 uint32_t i2c_speed;
254 uint8_t i2c_address;
256} pcr_cfg_t;
257
262typedef enum
263{
266 PCR_ERROR = -1
267
269
286
300err_t pcr_init ( pcr_t *ctx, pcr_cfg_t *cfg );
301
314err_t pcr_default_cfg ( pcr_t *ctx );
315
330err_t pcr_generic_write ( pcr_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
331
346err_t pcr_generic_read ( pcr_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
347
358void pcr_set_wup_pin ( pcr_t *ctx, uint8_t pin_state );
359
370void pcr_set_rst_pin ( pcr_t *ctx, uint8_t pin_state );
371
381uint8_t pcr_get_int_pin ( pcr_t *ctx );
382
392void pcr_hw_reset ( pcr_t *ctx );
393
407err_t pcr_write_reg ( pcr_t *ctx, uint16_t reg, uint32_t data_in );
408
422err_t pcr_read_reg ( pcr_t *ctx, uint16_t reg, uint32_t *data_out );
423
436err_t pcr_get_status ( pcr_t *ctx, uint32_t *status );
437
450
462err_t pcr_check_if_ok ( pcr_t *ctx );
463
476err_t pcr_get_distance ( pcr_t *ctx, uint32_t *distance_data );
477
478#ifdef __cplusplus
479}
480#endif
481#endif // PCR_H
482
483 // pcr
484
485// ------------------------------------------------------------------------ END
uint8_t pcr_get_int_pin(pcr_t *ctx)
PCR get interrupt pin state function.
err_t pcr_check_if_busy(pcr_t *ctx)
PCR check if device is busy function.
err_t pcr_get_distance(pcr_t *ctx, uint32_t *distance_data)
PCR read distance function.
err_t pcr_read_reg(pcr_t *ctx, uint16_t reg, uint32_t *data_out)
PCR register reading function.
void pcr_set_wup_pin(pcr_t *ctx, uint8_t pin_state)
PCR set wake up pin state function.
err_t pcr_generic_read(pcr_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
PCR I2C reading function.
err_t pcr_generic_write(pcr_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
PCR I2C writing function.
err_t pcr_init(pcr_t *ctx, pcr_cfg_t *cfg)
PCR initialization function.
err_t pcr_default_cfg(pcr_t *ctx)
PCR default configuration function.
void pcr_hw_reset(pcr_t *ctx)
PCR hardware reset function.
void pcr_cfg_setup(pcr_cfg_t *cfg)
PCR configuration object setup function.
err_t pcr_get_status(pcr_t *ctx, uint32_t *status)
PCR get status function.
err_t pcr_write_reg(pcr_t *ctx, uint16_t reg, uint32_t data_in)
PCR register writing function.
void pcr_set_rst_pin(pcr_t *ctx, uint8_t pin_state)
PCR set reset pin state function.
err_t pcr_check_if_ok(pcr_t *ctx)
PCR check if device is ok function.
pcr_return_value_t
PCR Click return value data.
Definition pcr.h:263
@ PCR_BUSY
Definition pcr.h:265
@ PCR_ERROR
Definition pcr.h:266
@ PCR_OK
Definition pcr.h:264
PCR Click configuration object.
Definition pcr.h:245
pin_name_t wup
Definition pcr.h:250
uint32_t i2c_speed
Definition pcr.h:253
pin_name_t scl
Definition pcr.h:246
pin_name_t int_pin
Definition pcr.h:251
pin_name_t sda
Definition pcr.h:247
pin_name_t rst
Definition pcr.h:249
uint8_t i2c_address
Definition pcr.h:254
PCR Click context object.
Definition pcr.h:224
digital_in_t int_pin
Definition pcr.h:230
i2c_master_t i2c
Definition pcr.h:233
digital_out_t wup
Definition pcr.h:227
digital_out_t rst
Definition pcr.h:226
uint8_t slave_address
Definition pcr.h:236