rotaryb  2.0.0.0
rotaryb.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 ROTARYB_H
29 #define ROTARYB_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 
68 #define ROTARYB_ONE_LED 0x0001
69 #define ROTARYB_TWO_LED 0x0101
70 #define ROTARYB_FOUR_LED 0x1111
71 #define ROTARYB_EIGHT_LED 0x5555
72 #define ROTARYB_RESET_LED 0x0000
73  // rotaryb_led
75 
90 #define ROTARYB_MAP_MIKROBUS( cfg, mikrobus ) \
91  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
92  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
93  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
94  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
95  cfg.ecb = MIKROBUS( mikrobus, MIKROBUS_AN ); \
96  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
97  cfg.eca = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
98  cfg.sw = MIKROBUS( mikrobus, MIKROBUS_INT )
99  // rotaryb_map // rotaryb
102 
107 typedef struct
108 {
109  // Output pins
110 
111  digital_out_t rst;
112  digital_out_t cs;
113 
114  // Input pins
115 
116  digital_in_t ecb;
117  digital_in_t eca;
118  digital_in_t sw;
119 
120  // Modules
121 
122  spi_master_t spi;
124  pin_name_t chip_select;
126 } rotaryb_t;
127 
132 typedef struct
133 {
134  // Communication gpio pins
135 
136  pin_name_t miso;
137  pin_name_t mosi;
138  pin_name_t sck;
139  pin_name_t cs;
141  // Additional gpio pins
142 
143  pin_name_t ecb;
144  pin_name_t rst;
145  pin_name_t eca;
146  pin_name_t sw;
147 
148  // static variable
149 
150  uint32_t spi_speed;
151  spi_master_mode_t spi_mode;
152  spi_master_chip_select_polarity_t cs_polarity;
154 } rotaryb_cfg_t;
155 
160 typedef enum
161 {
163  ROTARYB_ERROR = -1
164 
166 
183 
198 err_t rotaryb_init ( rotaryb_t *ctx, rotaryb_cfg_t *cfg );
199 
214 void rotaryb_generic_transfer ( rotaryb_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
215 
226 void rotaryb_turn_on_led_by_data ( rotaryb_t *ctx, uint16_t write_data );
227 
238 void rotaryb_turn_on_led_by_position ( rotaryb_t *ctx, uint8_t led_position );
239 
251 
260 uint16_t rotaryb_get_led_data ( uint8_t current_led_state );
261 
272 
283 
294 
295 #ifdef __cplusplus
296 }
297 #endif
298 #endif // ROTARYB_H
299  // rotaryb
301 
302 // ------------------------------------------------------------------------ END
rotaryb_turn_on_led_by_position
void rotaryb_turn_on_led_by_position(rotaryb_t *ctx, uint8_t led_position)
ROTARY B turn on led by position function.
rotaryb_t
ROTARY B Click context object.
Definition: rotaryb.h:108
rotaryb_cfg_t::ecb
pin_name_t ecb
Definition: rotaryb.h:143
rotaryb_cfg_t::spi_speed
uint32_t spi_speed
Definition: rotaryb.h:150
rotaryb_t::eca
digital_in_t eca
Definition: rotaryb.h:117
rotaryb_cfg_t
ROTARY B Click configuration object.
Definition: rotaryb.h:133
rotaryb_t::cs
digital_out_t cs
Definition: rotaryb.h:112
rotaryb_cfg_t::sck
pin_name_t sck
Definition: rotaryb.h:138
rotaryb_cfg_t::miso
pin_name_t miso
Definition: rotaryb.h:136
rotaryb_cfg_t::eca
pin_name_t eca
Definition: rotaryb.h:145
rotaryb_cfg_t::rst
pin_name_t rst
Definition: rotaryb.h:144
rotaryb_get_led_data
uint16_t rotaryb_get_led_data(uint8_t current_led_state)
Get led data state.
rotaryb_get_eca_state
uint8_t rotaryb_get_eca_state(rotaryb_t *ctx)
State eca pin.
rotaryb_get_ecb_state
uint8_t rotaryb_get_ecb_state(rotaryb_t *ctx)
State ecb pin.
rotaryb_init
err_t rotaryb_init(rotaryb_t *ctx, rotaryb_cfg_t *cfg)
ROTARY B initialization function.
rotaryb_return_value_t
rotaryb_return_value_t
ROTARY B Click return value data.
Definition: rotaryb.h:161
rotaryb_reset_led
void rotaryb_reset_led(rotaryb_t *ctx)
Reset led.
rotaryb_cfg_setup
void rotaryb_cfg_setup(rotaryb_cfg_t *cfg)
ROTARY B configuration object setup function.
ROTARYB_ERROR
@ ROTARYB_ERROR
Definition: rotaryb.h:163
rotaryb_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: rotaryb.h:151
rotaryb_cfg_t::mosi
pin_name_t mosi
Definition: rotaryb.h:137
rotaryb_cfg_t::sw
pin_name_t sw
Definition: rotaryb.h:146
rotaryb_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: rotaryb.h:152
rotaryb_t::chip_select
pin_name_t chip_select
Definition: rotaryb.h:124
rotaryb_button_push
uint8_t rotaryb_button_push(rotaryb_t *ctx)
Button push state.
rotaryb_t::ecb
digital_in_t ecb
Definition: rotaryb.h:116
rotaryb_t::spi
spi_master_t spi
Definition: rotaryb.h:122
rotaryb_generic_transfer
void rotaryb_generic_transfer(rotaryb_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
ROTARY B data transfer function.
ROTARYB_OK
@ ROTARYB_OK
Definition: rotaryb.h:162
rotaryb_t::rst
digital_out_t rst
Definition: rotaryb.h:111
rotaryb_t::sw
digital_in_t sw
Definition: rotaryb.h:118
rotaryb_cfg_t::cs
pin_name_t cs
Definition: rotaryb.h:139
rotaryb_turn_on_led_by_data
void rotaryb_turn_on_led_by_data(rotaryb_t *ctx, uint16_t write_data)
ROTARY B generic data write function.