thumbwheel  2.0.0.0
thumbwheel.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 THUMBWHEEL_H
29 #define THUMBWHEEL_H
30 
31 #ifdef __cplusplus
32 extern "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_one_wire.h"
52 
73 #define THUMBWHEEL_CMD_CHANNEL_ACCESS_READ 0xF5
74 #define THUMBWHEEL_CMD_RESET_ACTIVITY_LATCHES 0xC3
75 #define THUMBWHEEL_CMD_WRITE_COND_SEARCH_REG 0xCC
76 #define THUMBWHEEL_CMD_READ_PIO_REG 0xF0
77  // thumbwheel_cmd
79 
94 #define THUMBWHEEL_REG_CONTROL_STATUS 0x008D
95 #define THUMBWHEEL_REG_COND_SEARCH_SELECTION 0x008B
96 #define THUMBWHEEL_REG_PIO_LOGIC 0x0088
97  // thumbwheel_reg
99 
109 #define THUMBWHEEL_FAMILY_CODE 0x29
110 #define THUMBWHEEL_CONFIG_RESERVED_BITS 0x70
111  // thumbwheel_set
113 
128 #define THUMBWHEEL_MAP_MIKROBUS( cfg, mikrobus ) \
129  cfg.gp0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
130  cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
131  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
132  // thumbwheel_map // thumbwheel
135 
140 typedef enum
141 {
146 
151 typedef struct
152 {
153  // Output pins
154  digital_out_t rst;
156  // Modules
157  one_wire_t ow;
159  one_wire_rom_address_t rom_addr;
161 } thumbwheel_t;
162 
167 typedef struct
168 {
169  // Communication gpio pins
170  pin_name_t gp0;
171  pin_name_t gp1;
173  // Additional gpio pins
174  pin_name_t rst;
179 
184 typedef enum
185 {
187  THUMBWHEEL_ERROR = -1
188 
190 
207 
223 
239 
252 
265 err_t thumbwheel_write_register ( thumbwheel_t *ctx, uint16_t reg, uint8_t data_in );
266 
279 err_t thumbwheel_read_register ( thumbwheel_t *ctx, uint16_t reg, uint8_t *data_out );
280 
292 
304 err_t thumbwheel_get_position ( thumbwheel_t *ctx, uint8_t *position );
305 
315 void thumbwheel_set_rst_pin ( thumbwheel_t *ctx, uint8_t state );
316 
317 #ifdef __cplusplus
318 }
319 #endif
320 #endif // THUMBWHEEL_H
321  // thumbwheel
323 
324 // ------------------------------------------------------------------------ END
thumbwheel_get_position
err_t thumbwheel_get_position(thumbwheel_t *ctx, uint8_t *position)
Thumbwheel get position function.
thumbwheel_cfg_setup
void thumbwheel_cfg_setup(thumbwheel_cfg_t *cfg)
Thumbwheel configuration object setup function.
THUMBWHEEL_OK
@ THUMBWHEEL_OK
Definition: thumbwheel.h:186
thumbwheel_t::rst
digital_out_t rst
Definition: thumbwheel.h:154
thumbwheel_check_communication
err_t thumbwheel_check_communication(thumbwheel_t *ctx)
Thumbwheel check communication function.
thumbwheel_return_value_t
thumbwheel_return_value_t
Thumbwheel Click return value data.
Definition: thumbwheel.h:185
thumbwheel_cfg_t::gp1
pin_name_t gp1
Definition: thumbwheel.h:171
THUMBWHEEL_GPIO_0
@ THUMBWHEEL_GPIO_0
Definition: thumbwheel.h:142
thumbwheel_gpio_selection
void thumbwheel_gpio_selection(thumbwheel_cfg_t *cfg, thumbwheel_gpio_sel_t gpio_sel)
Thumbwheel driver interface setup function.
thumbwheel_set_rst_pin
void thumbwheel_set_rst_pin(thumbwheel_t *ctx, uint8_t state)
Thumbwheel set reset pin function.
thumbwheel_reset_latches
err_t thumbwheel_reset_latches(thumbwheel_t *ctx)
Thumbwheel reset latches function.
thumbwheel_gpio_sel_t
thumbwheel_gpio_sel_t
Thumbwheel Click gpio selector.
Definition: thumbwheel.h:141
thumbwheel_write_register
err_t thumbwheel_write_register(thumbwheel_t *ctx, uint16_t reg, uint8_t data_in)
Thumbwheel write register function.
thumbwheel_init
err_t thumbwheel_init(thumbwheel_t *ctx, thumbwheel_cfg_t *cfg)
Thumbwheel initialization function.
thumbwheel_t::ow
one_wire_t ow
Definition: thumbwheel.h:157
thumbwheel_cfg_t::gp0
pin_name_t gp0
Definition: thumbwheel.h:170
thumbwheel_cfg_t::gpio_sel
thumbwheel_gpio_sel_t gpio_sel
Definition: thumbwheel.h:176
THUMBWHEEL_GPIO_1
@ THUMBWHEEL_GPIO_1
Definition: thumbwheel.h:143
THUMBWHEEL_ERROR
@ THUMBWHEEL_ERROR
Definition: thumbwheel.h:187
thumbwheel_t
Thumbwheel Click context object.
Definition: thumbwheel.h:152
thumbwheel_cfg_t::rst
pin_name_t rst
Definition: thumbwheel.h:174
thumbwheel_read_register
err_t thumbwheel_read_register(thumbwheel_t *ctx, uint16_t reg, uint8_t *data_out)
Thumbwheel read register function.
thumbwheel_t::rom_addr
one_wire_rom_address_t rom_addr
Definition: thumbwheel.h:159
thumbwheel_cfg_t
Thumbwheel Click configuration object.
Definition: thumbwheel.h:168