rotaryb2  2.1.0.0
rotaryb2.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 ROTARYB2_H
29 #define ROTARYB2_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_spi_master.h"
52 #include "spi_specifics.h"
53 
74 #define ROTARYB2_SET_LED_OFF 0x0000u
75 #define ROTARYB2_SET_LED_DATA_1 0x0001u
76 #define ROTARYB2_SET_LED_DATA_2 0x0002u
77 #define ROTARYB2_SET_LED_DATA_3 0x0004u
78 #define ROTARYB2_SET_LED_DATA_4 0x0008u
79 #define ROTARYB2_SET_LED_DATA_5 0x0010u
80 #define ROTARYB2_SET_LED_DATA_6 0x0020u
81 #define ROTARYB2_SET_LED_DATA_7 0x0040u
82 #define ROTARYB2_SET_LED_DATA_8 0x0080u
83 #define ROTARYB2_SET_LED_DATA_9 0x0100u
84 #define ROTARYB2_SET_LED_DATA_10 0x0200u
85 #define ROTARYB2_SET_LED_DATA_11 0x0400u
86 #define ROTARYB2_SET_LED_DATA_12 0x0800u
87 #define ROTARYB2_SET_LED_DATA_13 0x1000u
88 #define ROTARYB2_SET_LED_DATA_14 0x2000u
89 #define ROTARYB2_SET_LED_DATA_15 0x4000u
90 #define ROTARYB2_SET_LED_DATA_16 0x8000u
91 
96 #define ROTARYB2_SET_LED_POS_1 1
97 #define ROTARYB2_SET_LED_POS_2 2
98 #define ROTARYB2_SET_LED_POS_3 3
99 #define ROTARYB2_SET_LED_POS_4 4
100 #define ROTARYB2_SET_LED_POS_5 5
101 #define ROTARYB2_SET_LED_POS_6 6
102 #define ROTARYB2_SET_LED_POS_7 7
103 #define ROTARYB2_SET_LED_POS_8 8
104 #define ROTARYB2_SET_LED_POS_9 9
105 #define ROTARYB2_SET_LED_POS_10 10
106 #define ROTARYB2_SET_LED_POS_11 11
107 #define ROTARYB2_SET_LED_POS_12 12
108 #define ROTARYB2_SET_LED_POS_13 13
109 #define ROTARYB2_SET_LED_POS_14 14
110 #define ROTARYB2_SET_LED_POS_15 15
111 #define ROTARYB2_SET_LED_POS_16 16
112 
121 #define ROTARYB2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
122 #define ROTARYB2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
123  // rotaryb2_set
125 
140 #define ROTARYB2_MAP_MIKROBUS( cfg, mikrobus ) \
141  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
142  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
143  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
144  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
145  cfg.enb = MIKROBUS( mikrobus, MIKROBUS_AN ); \
146  cfg.ena = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
147  cfg.sw = MIKROBUS( mikrobus, MIKROBUS_INT )
148  // rotaryb2_map // rotaryb2
151 
156 typedef struct
157 {
158  // Input pins
159  digital_in_t enb;
160  digital_in_t ena;
161  digital_in_t sw;
163  // Modules
164  spi_master_t spi;
166  pin_name_t chip_select;
168 } rotaryb2_t;
169 
174 typedef struct
175 {
176  // Communication gpio pins
177  pin_name_t miso;
178  pin_name_t mosi;
179  pin_name_t sck;
180  pin_name_t cs;
182  // Additional gpio pins
183  pin_name_t enb;
184  pin_name_t ena;
185  pin_name_t sw;
187  // static variable
188  uint32_t spi_speed;
189  spi_master_mode_t spi_mode;
190  spi_master_chip_select_polarity_t cs_polarity;
193 
198 typedef enum
199 {
201  ROTARYB2_ERROR = -1
202 
204 
221 
236 
250 
264 err_t rotaryb2_set_led_data ( rotaryb2_t *ctx, uint16_t data_in );
265 
279 err_t rotaryb2_get_led_data ( rotaryb2_t *ctx, uint16_t *data_out );
280 
294 err_t rotaryb2_set_led_pos ( rotaryb2_t *ctx, uint8_t led_pos );
295 
307 
319 
331 
332 #ifdef __cplusplus
333 }
334 #endif
335 #endif // ROTARYB2_H
336  // rotaryb2
338 
339 // ------------------------------------------------------------------------ END
rotaryb2_cfg_t::sw
pin_name_t sw
Definition: rotaryb2.h:185
rotaryb2_t::spi
spi_master_t spi
Definition: rotaryb2.h:164
rotaryb2_t::chip_select
pin_name_t chip_select
Definition: rotaryb2.h:166
rotaryb2_t::enb
digital_in_t enb
Definition: rotaryb2.h:159
rotaryb2_cfg_t::ena
pin_name_t ena
Definition: rotaryb2.h:184
rotaryb2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: rotaryb2.h:190
rotaryb2_cfg_t::mosi
pin_name_t mosi
Definition: rotaryb2.h:178
rotaryb2_default_cfg
err_t rotaryb2_default_cfg(rotaryb2_t *ctx)
Rotary B 2 default configuration function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
rotaryb2_set_led_pos
err_t rotaryb2_set_led_pos(rotaryb2_t *ctx, uint8_t led_pos)
Rotary B 2 set LED position function.
rotaryb2_cfg_setup
void rotaryb2_cfg_setup(rotaryb2_cfg_t *cfg)
Rotary B 2 configuration object setup function.
rotaryb2_get_state_enb
uint8_t rotaryb2_get_state_enb(rotaryb2_t *ctx)
Rotary B 2 get enb state function.
ROTARYB2_ERROR
@ ROTARYB2_ERROR
Definition: rotaryb2.h:201
rotaryb2_t::sw
digital_in_t sw
Definition: rotaryb2.h:161
rotaryb2_t::ena
digital_in_t ena
Definition: rotaryb2.h:160
rotaryb2_cfg_t
Rotary B 2 Click configuration object.
Definition: rotaryb2.h:175
rotaryb2_cfg_t::spi_speed
uint32_t spi_speed
Definition: rotaryb2.h:188
rotaryb2_get_led_data
err_t rotaryb2_get_led_data(rotaryb2_t *ctx, uint16_t *data_out)
Rotary B 2 get LED data function.
rotaryb2_init
err_t rotaryb2_init(rotaryb2_t *ctx, rotaryb2_cfg_t *cfg)
Rotary B 2 initialization function.
rotaryb2_cfg_t::enb
pin_name_t enb
Definition: rotaryb2.h:183
rotaryb2_t
Rotary B 2 Click context object.
Definition: rotaryb2.h:157
rotaryb2_cfg_t::sck
pin_name_t sck
Definition: rotaryb2.h:179
rotaryb2_get_state_ena
uint8_t rotaryb2_get_state_ena(rotaryb2_t *ctx)
Rotary B 2 get ena state function.
ROTARYB2_OK
@ ROTARYB2_OK
Definition: rotaryb2.h:200
rotaryb2_cfg_t::miso
pin_name_t miso
Definition: rotaryb2.h:177
rotaryb2_cfg_t::cs
pin_name_t cs
Definition: rotaryb2.h:180
rotaryb2_get_state_switch
uint8_t rotaryb2_get_state_switch(rotaryb2_t *ctx)
Rotary B 2 get switch state function.
rotaryb2_return_value_t
rotaryb2_return_value_t
Rotary B 2 Click return value data.
Definition: rotaryb2.h:199
rotaryb2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: rotaryb2.h:189
rotaryb2_set_led_data
err_t rotaryb2_set_led_data(rotaryb2_t *ctx, uint16_t data_in)
Rotary B 2 set LED data function.