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 
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_spi_master.h"
48 #include "spi_specifics.h"
49 
70 #define ROTARYB2_SET_LED_OFF 0x0000u
71 #define ROTARYB2_SET_LED_DATA_1 0x0001u
72 #define ROTARYB2_SET_LED_DATA_2 0x0002u
73 #define ROTARYB2_SET_LED_DATA_3 0x0004u
74 #define ROTARYB2_SET_LED_DATA_4 0x0008u
75 #define ROTARYB2_SET_LED_DATA_5 0x0010u
76 #define ROTARYB2_SET_LED_DATA_6 0x0020u
77 #define ROTARYB2_SET_LED_DATA_7 0x0040u
78 #define ROTARYB2_SET_LED_DATA_8 0x0080u
79 #define ROTARYB2_SET_LED_DATA_9 0x0100u
80 #define ROTARYB2_SET_LED_DATA_10 0x0200u
81 #define ROTARYB2_SET_LED_DATA_11 0x0400u
82 #define ROTARYB2_SET_LED_DATA_12 0x0800u
83 #define ROTARYB2_SET_LED_DATA_13 0x1000u
84 #define ROTARYB2_SET_LED_DATA_14 0x2000u
85 #define ROTARYB2_SET_LED_DATA_15 0x4000u
86 #define ROTARYB2_SET_LED_DATA_16 0x8000u
87 
92 #define ROTARYB2_SET_LED_POS_1 1
93 #define ROTARYB2_SET_LED_POS_2 2
94 #define ROTARYB2_SET_LED_POS_3 3
95 #define ROTARYB2_SET_LED_POS_4 4
96 #define ROTARYB2_SET_LED_POS_5 5
97 #define ROTARYB2_SET_LED_POS_6 6
98 #define ROTARYB2_SET_LED_POS_7 7
99 #define ROTARYB2_SET_LED_POS_8 8
100 #define ROTARYB2_SET_LED_POS_9 9
101 #define ROTARYB2_SET_LED_POS_10 10
102 #define ROTARYB2_SET_LED_POS_11 11
103 #define ROTARYB2_SET_LED_POS_12 12
104 #define ROTARYB2_SET_LED_POS_13 13
105 #define ROTARYB2_SET_LED_POS_14 14
106 #define ROTARYB2_SET_LED_POS_15 15
107 #define ROTARYB2_SET_LED_POS_16 16
108 
117 #define ROTARYB2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
118 #define ROTARYB2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
119  // rotaryb2_set
121 
136 #define ROTARYB2_MAP_MIKROBUS( cfg, mikrobus ) \
137  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
138  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
139  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
140  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
141  cfg.enb = MIKROBUS( mikrobus, MIKROBUS_AN ); \
142  cfg.ena = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
143  cfg.sw = MIKROBUS( mikrobus, MIKROBUS_INT )
144  // rotaryb2_map // rotaryb2
147 
152 typedef struct
153 {
154  // Input pins
155  digital_in_t enb;
156  digital_in_t ena;
157  digital_in_t sw;
159  // Modules
160  spi_master_t spi;
162  pin_name_t chip_select;
164 } rotaryb2_t;
165 
170 typedef struct
171 {
172  // Communication gpio pins
173  pin_name_t miso;
174  pin_name_t mosi;
175  pin_name_t sck;
176  pin_name_t cs;
178  // Additional gpio pins
179  pin_name_t enb;
180  pin_name_t ena;
181  pin_name_t sw;
183  // static variable
184  uint32_t spi_speed;
185  spi_master_mode_t spi_mode;
186  spi_master_chip_select_polarity_t cs_polarity;
189 
194 typedef enum
195 {
197  ROTARYB2_ERROR = -1
198 
200 
217 
232 
246 
260 err_t rotaryb2_set_led_data ( rotaryb2_t *ctx, uint16_t data_in );
261 
275 err_t rotaryb2_get_led_data ( rotaryb2_t *ctx, uint16_t *data_out );
276 
290 err_t rotaryb2_set_led_pos ( rotaryb2_t *ctx, uint8_t led_pos );
291 
303 
315 
327 
328 #ifdef __cplusplus
329 }
330 #endif
331 #endif // ROTARYB2_H
332  // rotaryb2
334 
335 // ------------------------------------------------------------------------ END
rotaryb2_cfg_t::sw
pin_name_t sw
Definition: rotaryb2.h:181
rotaryb2_t::spi
spi_master_t spi
Definition: rotaryb2.h:160
rotaryb2_t::chip_select
pin_name_t chip_select
Definition: rotaryb2.h:162
rotaryb2_t::enb
digital_in_t enb
Definition: rotaryb2.h:155
rotaryb2_cfg_t::ena
pin_name_t ena
Definition: rotaryb2.h:180
rotaryb2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: rotaryb2.h:186
rotaryb2_cfg_t::mosi
pin_name_t mosi
Definition: rotaryb2.h:174
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:197
rotaryb2_t::sw
digital_in_t sw
Definition: rotaryb2.h:157
rotaryb2_t::ena
digital_in_t ena
Definition: rotaryb2.h:156
rotaryb2_cfg_t
Rotary B 2 Click configuration object.
Definition: rotaryb2.h:171
rotaryb2_cfg_t::spi_speed
uint32_t spi_speed
Definition: rotaryb2.h:184
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:179
rotaryb2_t
Rotary B 2 Click context object.
Definition: rotaryb2.h:153
rotaryb2_cfg_t::sck
pin_name_t sck
Definition: rotaryb2.h:175
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:196
rotaryb2_cfg_t::miso
pin_name_t miso
Definition: rotaryb2.h:173
rotaryb2_cfg_t::cs
pin_name_t cs
Definition: rotaryb2.h:176
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:195
rotaryb2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: rotaryb2.h:185
rotaryb2_set_led_data
err_t rotaryb2_set_led_data(rotaryb2_t *ctx, uint16_t data_in)
Rotary B 2 set LED data function.