counter2 2.2.0
Loading...
Searching...
No Matches
counter2.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
27
28#ifndef COUNTER2_H
29#define COUNTER2_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
58
63
68
73#define COUNTER2_FREE_DATA_READ 0x01
74#define COUNTER2_FREE_DATA_WRITE 0x81
75#define COUNTER2_FREE_DATA_RESET_CNT 0x02
76
81#define COUNTER2_LOOP_IDLE 0
82#define COUNTER2_LOOP_TOGGLED 1
83#define COUNTER2_LOOP_THRESHOLD 16777216ul
84
90#define COUNTER2_DEVICE_ADDRESS 0x32
91 // counter2_set
93
98
103
108#define COUNTER2_MAP_MIKROBUS( cfg, mikrobus ) \
109 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
110 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
111 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
112 cfg.loop = MIKROBUS( mikrobus, MIKROBUS_INT )
113 // counter2_map // counter2
116
121typedef struct
122{
123 // Output pins
124 digital_out_t rst;
125
126 // Input pins
127 digital_in_t loop;
128
129 // Modules
130 i2c_master_t i2c;
131
132 // I2C slave address
134
135} counter2_t;
136
141typedef struct
142{
143 pin_name_t scl;
144 pin_name_t sda;
145
146 pin_name_t rst;
147 pin_name_t loop;
148
149 uint32_t i2c_speed;
150 uint8_t i2c_address;
151
153
158typedef enum
159{
162
164
170
181
196
206void counter2_set_rst_pin ( counter2_t *ctx, uint8_t state );
207
217
227
238
249err_t counter2_get_counter ( counter2_t *ctx, uint32_t *counter );
250
261err_t counter2_read_free_data ( counter2_t *ctx, uint32_t *free_data );
262
273err_t counter2_write_free_data ( counter2_t *ctx, uint32_t free_data );
274
285
286#ifdef __cplusplus
287}
288#endif
289#endif // COUNTER2_H
290 // counter2
292
293// ------------------------------------------------------------------------ END
counter2_return_value_t
Counter 2 Click return value data.
Definition counter2.h:159
@ COUNTER2_OK
Definition counter2.h:160
@ COUNTER2_ERROR
Definition counter2.h:161
err_t counter2_read_free_data(counter2_t *ctx, uint32_t *free_data)
Counter 2 read free data register function.
void counter2_set_rst_pin(counter2_t *ctx, uint8_t state)
Counter 2 set RST pin state function.
void counter2_reset_counter(counter2_t *ctx)
Counter 2 reset counter function.
uint8_t counter2_check_loop(counter2_t *ctx)
Counter 2 check loop toggle function.
uint8_t counter2_get_loop_pin(counter2_t *ctx)
Counter 2 get LOOP pin function.
void counter2_cfg_setup(counter2_cfg_t *cfg)
Counter 2 configuration object setup function.
err_t counter2_init(counter2_t *ctx, counter2_cfg_t *cfg)
Counter 2 initialization function.
err_t counter2_sw_reset_counter(counter2_t *ctx)
Counter 2 software counter reset function.
err_t counter2_write_free_data(counter2_t *ctx, uint32_t free_data)
Counter 2 write free data register function.
err_t counter2_get_counter(counter2_t *ctx, uint32_t *counter)
Counter 2 get counter value function.
Counter 2 Click configuration object.
Definition counter2.h:142
uint32_t i2c_speed
Definition counter2.h:149
pin_name_t loop
Definition counter2.h:147
pin_name_t scl
Definition counter2.h:143
pin_name_t sda
Definition counter2.h:144
pin_name_t rst
Definition counter2.h:146
uint8_t i2c_address
Definition counter2.h:150
Counter 2 Click context object.
Definition counter2.h:122
digital_in_t loop
Definition counter2.h:127
i2c_master_t i2c
Definition counter2.h:130
digital_out_t rst
Definition counter2.h:124
uint8_t slave_address
Definition counter2.h:133