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
32extern "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 ROTARYB_ONE_LED 0x0001
55#define ROTARYB_TWO_LED 0x0101
56#define ROTARYB_FOUR_LED 0x1111
57#define ROTARYB_EIGHT_LED 0x5555
58#define ROTARYB_RESET_LED 0x0000
59 // rotaryb_led
61
76#define ROTARYB_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 // rotaryb_map // rotaryb
88
93typedef 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} rotaryb_t;
113
118typedef 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;
141
146typedef enum
147{
149 ROTARYB_ERROR = -1
150
152
169
185
200void rotaryb_generic_transfer ( rotaryb_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
201
212void rotaryb_turn_on_led_by_data ( rotaryb_t *ctx, uint16_t write_data );
213
224void rotaryb_turn_on_led_by_position ( rotaryb_t *ctx, uint8_t led_position );
225
237
246uint16_t rotaryb_get_led_data ( uint8_t current_led_state );
247
258
269
280
281#ifdef __cplusplus
282}
283#endif
284#endif // ROTARYB_H
285 // rotaryb
287
288// ------------------------------------------------------------------------ END
uint8_t rotaryb_button_push(rotaryb_t *ctx)
Button push state.
uint8_t rotaryb_get_ecb_state(rotaryb_t *ctx)
State ecb pin.
void rotaryb_turn_on_led_by_position(rotaryb_t *ctx, uint8_t led_position)
ROTARY B turn on led by position function.
uint16_t rotaryb_get_led_data(uint8_t current_led_state)
Get led data state.
void rotaryb_turn_on_led_by_data(rotaryb_t *ctx, uint16_t write_data)
ROTARY B generic data write function.
err_t rotaryb_init(rotaryb_t *ctx, rotaryb_cfg_t *cfg)
ROTARY B initialization function.
void rotaryb_reset_led(rotaryb_t *ctx)
Reset led.
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.
void rotaryb_cfg_setup(rotaryb_cfg_t *cfg)
ROTARY B configuration object setup function.
uint8_t rotaryb_get_eca_state(rotaryb_t *ctx)
State eca pin.
rotaryb_return_value_t
ROTARY B Click return value data.
Definition: rotaryb.h:147
@ ROTARYB_OK
Definition: rotaryb.h:148
@ ROTARYB_ERROR
Definition: rotaryb.h:149
ROTARY B Click configuration object.
Definition: rotaryb.h:119
spi_master_chip_select_polarity_t cs_polarity
Definition: rotaryb.h:138
pin_name_t eca
Definition: rotaryb.h:131
pin_name_t sck
Definition: rotaryb.h:124
spi_master_mode_t spi_mode
Definition: rotaryb.h:137
pin_name_t mosi
Definition: rotaryb.h:123
uint32_t spi_speed
Definition: rotaryb.h:136
pin_name_t sw
Definition: rotaryb.h:132
pin_name_t miso
Definition: rotaryb.h:122
pin_name_t rst
Definition: rotaryb.h:130
pin_name_t cs
Definition: rotaryb.h:125
pin_name_t ecb
Definition: rotaryb.h:129
ROTARY B Click context object.
Definition: rotaryb.h:94
digital_out_t cs
Definition: rotaryb.h:98
digital_in_t eca
Definition: rotaryb.h:103
spi_master_t spi
Definition: rotaryb.h:108
digital_in_t ecb
Definition: rotaryb.h:102
digital_in_t sw
Definition: rotaryb.h:104
digital_out_t rst
Definition: rotaryb.h:97
pin_name_t chip_select
Definition: rotaryb.h:110