rotaryw2  2.1.0.0
rotaryw2.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 ROTARYW2_H
29 #define ROTARYW2_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 
60 #define ROTARYW2_SET_LED_OFF 0x0000u
61 #define ROTARYW2_SET_LED_DATA_1 0x0001u
62 #define ROTARYW2_SET_LED_DATA_2 0x0002u
63 #define ROTARYW2_SET_LED_DATA_3 0x0004u
64 #define ROTARYW2_SET_LED_DATA_4 0x0008u
65 #define ROTARYW2_SET_LED_DATA_5 0x0010u
66 #define ROTARYW2_SET_LED_DATA_6 0x0020u
67 #define ROTARYW2_SET_LED_DATA_7 0x0040u
68 #define ROTARYW2_SET_LED_DATA_8 0x0080u
69 #define ROTARYW2_SET_LED_DATA_9 0x0100u
70 #define ROTARYW2_SET_LED_DATA_10 0x0200u
71 #define ROTARYW2_SET_LED_DATA_11 0x0400u
72 #define ROTARYW2_SET_LED_DATA_12 0x0800u
73 #define ROTARYW2_SET_LED_DATA_13 0x1000u
74 #define ROTARYW2_SET_LED_DATA_14 0x2000u
75 #define ROTARYW2_SET_LED_DATA_15 0x4000u
76 #define ROTARYW2_SET_LED_DATA_16 0x8000u
77 
82 #define ROTARYW2_SET_LED_POS_1 1
83 #define ROTARYW2_SET_LED_POS_2 2
84 #define ROTARYW2_SET_LED_POS_3 3
85 #define ROTARYW2_SET_LED_POS_4 4
86 #define ROTARYW2_SET_LED_POS_5 5
87 #define ROTARYW2_SET_LED_POS_6 6
88 #define ROTARYW2_SET_LED_POS_7 7
89 #define ROTARYW2_SET_LED_POS_8 8
90 #define ROTARYW2_SET_LED_POS_9 9
91 #define ROTARYW2_SET_LED_POS_10 10
92 #define ROTARYW2_SET_LED_POS_11 11
93 #define ROTARYW2_SET_LED_POS_12 12
94 #define ROTARYW2_SET_LED_POS_13 13
95 #define ROTARYW2_SET_LED_POS_14 14
96 #define ROTARYW2_SET_LED_POS_15 15
97 #define ROTARYW2_SET_LED_POS_16 16
98 
107 #define ROTARYW2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
108 #define ROTARYW2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
109  // rotaryw2_set
111 
126 #define ROTARYW2_MAP_MIKROBUS( cfg, mikrobus ) \
127  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
128  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
129  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
130  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
131  cfg.enb = MIKROBUS( mikrobus, MIKROBUS_AN ); \
132  cfg.ena = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
133  cfg.sw = MIKROBUS( mikrobus, MIKROBUS_INT )
134  // rotaryw2_map // rotaryw2
137 
142 typedef struct
143 {
144  // Input pins
145  digital_in_t enb;
146  digital_in_t ena;
147  digital_in_t sw;
149  // Modules
150  spi_master_t spi;
152  pin_name_t chip_select;
154 } rotaryw2_t;
155 
160 typedef struct
161 {
162  // Communication gpio pins
163  pin_name_t miso;
164  pin_name_t mosi;
165  pin_name_t sck;
166  pin_name_t cs;
168  // Additional gpio pins
169  pin_name_t enb;
170  pin_name_t ena;
171  pin_name_t sw;
173  // static variable
174  uint32_t spi_speed;
175  spi_master_mode_t spi_mode;
176  spi_master_chip_select_polarity_t cs_polarity;
179 
184 typedef enum
185 {
187  ROTARYW2_ERROR = -1
188 
190 
207 
222 
236 
250 err_t rotaryw2_set_led_data ( rotaryw2_t *ctx, uint16_t data_in );
251 
265 err_t rotaryw2_get_led_data ( rotaryw2_t *ctx, uint16_t *data_out );
266 
280 err_t rotaryw2_set_led_pos ( rotaryw2_t *ctx, uint8_t led_pos );
281 
293 
305 
317 
318 #ifdef __cplusplus
319 }
320 #endif
321 #endif // ROTARYW2_H
322  // rotaryw2
324 
325 // ------------------------------------------------------------------------ END
rotaryw2_set_led_data
err_t rotaryw2_set_led_data(rotaryw2_t *ctx, uint16_t data_in)
Rotary W 2 set LED data function.
rotaryw2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: rotaryw2.h:176
rotaryw2_cfg_t::sw
pin_name_t sw
Definition: rotaryw2.h:171
rotaryw2_get_state_ena
uint8_t rotaryw2_get_state_ena(rotaryw2_t *ctx)
Rotary W 2 get ena state function.
rotaryw2_t::sw
digital_in_t sw
Definition: rotaryw2.h:147
rotaryw2_cfg_t
Rotary W 2 Click configuration object.
Definition: rotaryw2.h:161
rotaryw2_return_value_t
rotaryw2_return_value_t
Rotary W 2 Click return value data.
Definition: rotaryw2.h:185
rotaryw2_t
Rotary W 2 Click context object.
Definition: rotaryw2.h:143
rotaryw2_t::enb
digital_in_t enb
Definition: rotaryw2.h:145
rotaryw2_cfg_t::mosi
pin_name_t mosi
Definition: rotaryw2.h:164
spi_specifics.h
This file contains SPI specific macros, functions, etc.
rotaryw2_get_state_enb
uint8_t rotaryw2_get_state_enb(rotaryw2_t *ctx)
Rotary W 2 get enb state function.
ROTARYW2_OK
@ ROTARYW2_OK
Definition: rotaryw2.h:186
rotaryw2_cfg_setup
void rotaryw2_cfg_setup(rotaryw2_cfg_t *cfg)
Rotary W 2 configuration object setup function.
rotaryw2_cfg_t::enb
pin_name_t enb
Definition: rotaryw2.h:169
rotaryw2_t::spi
spi_master_t spi
Definition: rotaryw2.h:150
rotaryw2_set_led_pos
err_t rotaryw2_set_led_pos(rotaryw2_t *ctx, uint8_t led_pos)
Rotary W 2 set LED position function.
rotaryw2_t::ena
digital_in_t ena
Definition: rotaryw2.h:146
rotaryw2_get_led_data
err_t rotaryw2_get_led_data(rotaryw2_t *ctx, uint16_t *data_out)
Rotary W 2 get LED data function.
rotaryw2_cfg_t::spi_speed
uint32_t spi_speed
Definition: rotaryw2.h:174
rotaryw2_t::chip_select
pin_name_t chip_select
Definition: rotaryw2.h:152
rotaryw2_cfg_t::miso
pin_name_t miso
Definition: rotaryw2.h:163
ROTARYW2_ERROR
@ ROTARYW2_ERROR
Definition: rotaryw2.h:187
rotaryw2_default_cfg
err_t rotaryw2_default_cfg(rotaryw2_t *ctx)
Rotary W 2 default configuration function.
rotaryw2_cfg_t::cs
pin_name_t cs
Definition: rotaryw2.h:166
rotaryw2_cfg_t::sck
pin_name_t sck
Definition: rotaryw2.h:165
rotaryw2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: rotaryw2.h:175
rotaryw2_init
err_t rotaryw2_init(rotaryw2_t *ctx, rotaryw2_cfg_t *cfg)
Rotary W 2 initialization function.
rotaryw2_get_state_switch
uint8_t rotaryw2_get_state_switch(rotaryw2_t *ctx)
Rotary W 2 get switch state function.
rotaryw2_cfg_t::ena
pin_name_t ena
Definition: rotaryw2.h:170