rotaryo2 2.1.0.0
rotaryo2.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 ROTARYO2_H
29#define ROTARYO2_H
30
31#ifdef __cplusplus
32extern "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#include "spi_specifics.h"
53
74#define ROTARYO2_SET_LED_OFF 0x0000u
75#define ROTARYO2_SET_LED_DATA_1 0x0001u
76#define ROTARYO2_SET_LED_DATA_2 0x0002u
77#define ROTARYO2_SET_LED_DATA_3 0x0004u
78#define ROTARYO2_SET_LED_DATA_4 0x0008u
79#define ROTARYO2_SET_LED_DATA_5 0x0010u
80#define ROTARYO2_SET_LED_DATA_6 0x0020u
81#define ROTARYO2_SET_LED_DATA_7 0x0040u
82#define ROTARYO2_SET_LED_DATA_8 0x0080u
83#define ROTARYO2_SET_LED_DATA_9 0x0100u
84#define ROTARYO2_SET_LED_DATA_10 0x0200u
85#define ROTARYO2_SET_LED_DATA_11 0x0400u
86#define ROTARYO2_SET_LED_DATA_12 0x0800u
87#define ROTARYO2_SET_LED_DATA_13 0x1000u
88#define ROTARYO2_SET_LED_DATA_14 0x2000u
89#define ROTARYO2_SET_LED_DATA_15 0x4000u
90#define ROTARYO2_SET_LED_DATA_16 0x8000u
91
96#define ROTARYO2_SET_LED_POS_1 1
97#define ROTARYO2_SET_LED_POS_2 2
98#define ROTARYO2_SET_LED_POS_3 3
99#define ROTARYO2_SET_LED_POS_4 4
100#define ROTARYO2_SET_LED_POS_5 5
101#define ROTARYO2_SET_LED_POS_6 6
102#define ROTARYO2_SET_LED_POS_7 7
103#define ROTARYO2_SET_LED_POS_8 8
104#define ROTARYO2_SET_LED_POS_9 9
105#define ROTARYO2_SET_LED_POS_10 10
106#define ROTARYO2_SET_LED_POS_11 11
107#define ROTARYO2_SET_LED_POS_12 12
108#define ROTARYO2_SET_LED_POS_13 13
109#define ROTARYO2_SET_LED_POS_14 14
110#define ROTARYO2_SET_LED_POS_15 15
111#define ROTARYO2_SET_LED_POS_16 16
112
121#define ROTARYO2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
122#define ROTARYO2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
123
124 // rotaryo2_set
125
140#define ROTARYO2_MAP_MIKROBUS( cfg, mikrobus ) \
141 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
142 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
143 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
144 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
145 cfg.enb = MIKROBUS( mikrobus, MIKROBUS_AN ); \
146 cfg.ena = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
147 cfg.sw = MIKROBUS( mikrobus, MIKROBUS_INT )
148
149 // rotaryo2_map
150 // rotaryo2
151
156typedef struct
157{
158 // Input pins
159 digital_in_t enb;
160 digital_in_t ena;
161 digital_in_t sw;
163 // Modules
164 spi_master_t spi;
166 pin_name_t chip_select;
168} rotaryo2_t;
169
174typedef struct
175{
176 // Communication gpio pins
177 pin_name_t miso;
178 pin_name_t mosi;
179 pin_name_t sck;
180 pin_name_t cs;
182 // Additional gpio pins
183 pin_name_t enb;
184 pin_name_t ena;
185 pin_name_t sw;
187 // static variable
188 uint32_t spi_speed;
189 spi_master_mode_t spi_mode;
190 spi_master_chip_select_polarity_t cs_polarity;
193
198typedef enum
199{
201 ROTARYO2_ERROR = -1
202
204
221
236
250
264err_t rotaryo2_set_led_data ( rotaryo2_t *ctx, uint16_t data_in );
265
279err_t rotaryo2_get_led_data ( rotaryo2_t *ctx, uint16_t *data_out );
280
294err_t rotaryo2_set_led_pos ( rotaryo2_t *ctx, uint8_t led_pos );
295
307
319
331
332#ifdef __cplusplus
333}
334#endif
335#endif // ROTARYO2_H
336
337 // rotaryo2
338
339// ------------------------------------------------------------------------ END
err_t rotaryo2_set_led_data(rotaryo2_t *ctx, uint16_t data_in)
Rotary O 2 set LED data function.
err_t rotaryo2_default_cfg(rotaryo2_t *ctx)
Rotary O 2 default configuration function.
uint8_t rotaryo2_get_state_enb(rotaryo2_t *ctx)
Rotary O 2 get enb state function.
err_t rotaryo2_get_led_data(rotaryo2_t *ctx, uint16_t *data_out)
Rotary O 2 get LED data function.
void rotaryo2_cfg_setup(rotaryo2_cfg_t *cfg)
Rotary O 2 configuration object setup function.
uint8_t rotaryo2_get_state_ena(rotaryo2_t *ctx)
Rotary O 2 get ena state function.
err_t rotaryo2_init(rotaryo2_t *ctx, rotaryo2_cfg_t *cfg)
Rotary O 2 initialization function.
uint8_t rotaryo2_get_state_switch(rotaryo2_t *ctx)
Rotary O 2 get switch state function.
err_t rotaryo2_set_led_pos(rotaryo2_t *ctx, uint8_t led_pos)
Rotary O 2 set LED position function.
rotaryo2_return_value_t
Rotary O 2 Click return value data.
Definition rotaryo2.h:199
@ ROTARYO2_ERROR
Definition rotaryo2.h:201
@ ROTARYO2_OK
Definition rotaryo2.h:200
This file contains SPI specific macros, functions, etc.
Rotary O 2 Click configuration object.
Definition rotaryo2.h:175
pin_name_t ena
Definition rotaryo2.h:184
spi_master_chip_select_polarity_t cs_polarity
Definition rotaryo2.h:190
pin_name_t sck
Definition rotaryo2.h:179
spi_master_mode_t spi_mode
Definition rotaryo2.h:189
pin_name_t enb
Definition rotaryo2.h:183
pin_name_t mosi
Definition rotaryo2.h:178
uint32_t spi_speed
Definition rotaryo2.h:188
pin_name_t sw
Definition rotaryo2.h:185
pin_name_t miso
Definition rotaryo2.h:177
pin_name_t cs
Definition rotaryo2.h:180
Rotary O 2 Click context object.
Definition rotaryo2.h:157
spi_master_t spi
Definition rotaryo2.h:164
digital_in_t enb
Definition rotaryo2.h:159
digital_in_t ena
Definition rotaryo2.h:160
digital_in_t sw
Definition rotaryo2.h:161
pin_name_t chip_select
Definition rotaryo2.h:166