rotaryg  2.0.0.0
rotaryg.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 ROTARYG_H
29 #define ROTARYG_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 
54 #define ROTARYG_ONE_LED 0x0001
55 #define ROTARYG_TWO_LED 0x0101
56 #define ROTARYG_FOUR_LED 0x1111
57 #define ROTARYG_EIGHT_LED 0x5555
58 #define ROTARYG_RESET_LED 0x0000
59  // rotaryg_led
61 
76 #define ROTARYG_MAP_MIKROBUS( cfg, mikrobus ) \
77  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
78  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
79  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
80  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
81  cfg.ecb = MIKROBUS( mikrobus, MIKROBUS_AN ); \
82  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
83  cfg.eca = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
84  cfg.sw = MIKROBUS( mikrobus, MIKROBUS_INT )
85  // rotaryg_map // rotaryg
88 
93 typedef struct
94 {
95  // Output pins
96 
97  digital_out_t rst;
98  digital_out_t cs;
99 
100  // Input pins
101 
102  digital_in_t ecb;
103  digital_in_t eca;
104  digital_in_t sw;
105 
106  // Modules
107 
108  spi_master_t spi;
110  pin_name_t chip_select;
112 } rotaryg_t;
113 
118 typedef struct
119 {
120  // Communication gpio pins
121 
122  pin_name_t miso;
123  pin_name_t mosi;
124  pin_name_t sck;
125  pin_name_t cs;
127  // Additional gpio pins
128 
129  pin_name_t ecb;
130  pin_name_t rst;
131  pin_name_t eca;
132  pin_name_t sw;
133 
134  // static variable
135 
136  uint32_t spi_speed;
137  spi_master_mode_t spi_mode;
138  spi_master_chip_select_polarity_t cs_polarity;
140 } rotaryg_cfg_t;
141 
146 typedef enum
147 {
149  ROTARYG_ERROR = -1
150 
152 
169 
184 err_t rotaryg_init ( rotaryg_t *ctx, rotaryg_cfg_t *cfg );
185 
200 void rotaryg_generic_transfer ( rotaryg_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
201 
212 void rotaryg_turn_on_led_by_data ( rotaryg_t *ctx, uint16_t write_data );
213 
224 void rotaryg_turn_on_led_by_position ( rotaryg_t *ctx, uint8_t led_position );
225 
237 
246 uint16_t rotaryg_get_led_data ( uint8_t current_led_state );
247 
258 
269 
280 
281 #ifdef __cplusplus
282 }
283 #endif
284 #endif // ROTARYG_H
285  // rotaryg
287 
288 // ------------------------------------------------------------------------ END
rotaryg_return_value_t
rotaryg_return_value_t
ROTARY G Click return value data.
Definition: rotaryg.h:147
rotaryg_t::spi
spi_master_t spi
Definition: rotaryg.h:108
rotaryg_cfg_t
ROTARY G Click configuration object.
Definition: rotaryg.h:119
rotaryg_cfg_t::rst
pin_name_t rst
Definition: rotaryg.h:130
rotaryg_button_push
uint8_t rotaryg_button_push(rotaryg_t *ctx)
Button push state.
rotaryg_t::cs
digital_out_t cs
Definition: rotaryg.h:98
rotaryg_t::rst
digital_out_t rst
Definition: rotaryg.h:97
rotaryg_get_led_data
uint16_t rotaryg_get_led_data(uint8_t current_led_state)
Get led data state.
rotaryg_t::eca
digital_in_t eca
Definition: rotaryg.h:103
rotaryg_cfg_t::mosi
pin_name_t mosi
Definition: rotaryg.h:123
rotaryg_cfg_t::cs
pin_name_t cs
Definition: rotaryg.h:125
rotaryg_turn_on_led_by_data
void rotaryg_turn_on_led_by_data(rotaryg_t *ctx, uint16_t write_data)
ROTARY G generic data write function.
rotaryg_cfg_t::spi_speed
uint32_t spi_speed
Definition: rotaryg.h:136
rotaryg_t
ROTARY G Click context object.
Definition: rotaryg.h:94
rotaryg_t::chip_select
pin_name_t chip_select
Definition: rotaryg.h:110
ROTARYG_OK
@ ROTARYG_OK
Definition: rotaryg.h:148
rotaryg_turn_on_led_by_position
void rotaryg_turn_on_led_by_position(rotaryg_t *ctx, uint8_t led_position)
ROTARY G turn on led by position function.
rotaryg_cfg_t::eca
pin_name_t eca
Definition: rotaryg.h:131
rotaryg_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: rotaryg.h:137
rotaryg_generic_transfer
void rotaryg_generic_transfer(rotaryg_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
ROTARY G data transfer function.
rotaryg_get_eca_state
uint8_t rotaryg_get_eca_state(rotaryg_t *ctx)
State eca pin.
rotaryg_init
err_t rotaryg_init(rotaryg_t *ctx, rotaryg_cfg_t *cfg)
ROTARY G initialization function.
rotaryg_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: rotaryg.h:138
rotaryg_cfg_t::sw
pin_name_t sw
Definition: rotaryg.h:132
rotaryg_t::ecb
digital_in_t ecb
Definition: rotaryg.h:102
rotaryg_get_ecb_state
uint8_t rotaryg_get_ecb_state(rotaryg_t *ctx)
State ecb pin.
rotaryg_cfg_setup
void rotaryg_cfg_setup(rotaryg_cfg_t *cfg)
ROTARY G configuration object setup function.
rotaryg_cfg_t::sck
pin_name_t sck
Definition: rotaryg.h:124
rotaryg_t::sw
digital_in_t sw
Definition: rotaryg.h:104
rotaryg_reset_led
void rotaryg_reset_led(rotaryg_t *ctx)
Reset led.
rotaryg_cfg_t::miso
pin_name_t miso
Definition: rotaryg.h:122
rotaryg_cfg_t::ecb
pin_name_t ecb
Definition: rotaryg.h:129
ROTARYG_ERROR
@ ROTARYG_ERROR
Definition: rotaryg.h:149