knob 2.0.0.0
knob.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef KNOB_H
36#define KNOB_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
67#define KNOB_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
70 cfg.ena = MIKROBUS( mikrobus, MIKROBUS_AN ); \
71 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
72 cfg.enb = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73 cfg.oe = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
74 cfg.sw = MIKROBUS( mikrobus, MIKROBUS_INT );
81#define KNOB_RETVAL uint8_t
82
83#define KNOB_OK 0x00
84#define KNOB_INIT_ERROR 0xFF
91#define KNOB_REG_MODE_1 0x00
92#define KNOB_REG_MODE_2 0x01
93#define KNOB_REG_LED_OUTPUT_STATE_0 0x02
94#define KNOB_REG_LED_OUTPUT_STATE_1 0x03
95#define KNOB_REG_LED_OUTPUT_STATE_2 0x04
96#define KNOB_REG_LED_OUTPUT_STATE_3 0x05
97#define KNOB_REG_LED_OUTPUT_STATE_4 0x06
98#define KNOB_REG_LED_OUTPUT_STATE_5 0x07
99#define KNOB_REG_GROUP_DUTY_CYCLE_CONTROL 0x08
100#define KNOB_REG_GROUP_FREQUENCY 0x09
101#define KNOB_REG_BRIGHTNESS_CONTROL_LED_0 0x0A
102#define KNOB_REG_BRIGHTNESS_CONTROL_LED_1 0x0B
103#define KNOB_REG_BRIGHTNESS_CONTROL_LED_2 0x0C
104#define KNOB_REG_BRIGHTNESS_CONTROL_LED_3 0x0D
105#define KNOB_REG_BRIGHTNESS_CONTROL_LED_4 0x0E
106#define KNOB_REG_BRIGHTNESS_CONTROL_LED_5 0x0F
107#define KNOB_REG_BRIGHTNESS_CONTROL_LED_6 0x10
108#define KNOB_REG_BRIGHTNESS_CONTROL_LED_7 0x11
109#define KNOB_REG_BRIGHTNESS_CONTROL_LED_8 0x12
110#define KNOB_REG_BRIGHTNESS_CONTROL_LED_9 0x13
111#define KNOB_REG_BRIGHTNESS_CONTROL_LED_10 0x14
112#define KNOB_REG_BRIGHTNESS_CONTROL_LED_11 0x15
113#define KNOB_REG_BRIGHTNESS_CONTROL_LED_12 0x16
114#define KNOB_REG_BRIGHTNESS_CONTROL_LED_13 0x17
115#define KNOB_REG_BRIGHTNESS_CONTROL_LED_14 0x18
116#define KNOB_REG_BRIGHTNESS_CONTROL_LED_15 0x19
117#define KNOB_REG_BRIGHTNESS_CONTROL_LED_16 0x1A
118#define KNOB_REG_BRIGHTNESS_CONTROL_LED_17 0x1B
119#define KNOB_REG_BRIGHTNESS_CONTROL_LED_18 0x1C
120#define KNOB_REG_BRIGHTNESS_CONTROL_LED_19 0x1D
121#define KNOB_REG_BRIGHTNESS_CONTROL_LED_20 0x1E
122#define KNOB_REG_BRIGHTNESS_CONTROL_LED_21 0x1F
123#define KNOB_REG_BRIGHTNESS_CONTROL_LED_22 0x20
124#define KNOB_REG_BRIGHTNESS_CONTROL_LED_23 0x21
125#define KNOB_REG_OUTPUT_GAIN_CONTROL_0 0x22
126#define KNOB_REG_OUTPUT_GAIN_CONTROL_1 0x23
127#define KNOB_REG_OUTPUT_GAIN_CONTROL_2 0x24
128#define KNOB_REG_OUTPUT_GAIN_CONTROL_3 0x25
129#define KNOB_REG_OUTPUT_GAIN_CONTROL_4 0x26
130#define KNOB_REG_OUTPUT_GAIN_CONTROL_5 0x27
131#define KNOB_REG_OUTPUT_GAIN_CONTROL_6 0x28
132#define KNOB_REG_OUTPUT_GAIN_CONTROL_7 0x29
133#define KNOB_REG_OUTPUT_GAIN_CONTROL_8 0x2A
134#define KNOB_REG_OUTPUT_GAIN_CONTROL_9 0x2B
135#define KNOB_REG_OUTPUT_GAIN_CONTROL_10 0x2C
136#define KNOB_REG_OUTPUT_GAIN_CONTROL_11 0x2D
137#define KNOB_REG_OUTPUT_GAIN_CONTROL_12 0x2E
138#define KNOB_REG_OUTPUT_GAIN_CONTROL_13 0x2F
139#define KNOB_REG_OUTPUT_GAIN_CONTROL_14 0x30
140#define KNOB_REG_OUTPUT_GAIN_CONTROL_15 0x31
141#define KNOB_REG_OUTPUT_GAIN_CONTROL_16 0x32
142#define KNOB_REG_OUTPUT_GAIN_CONTROL_17 0x33
143#define KNOB_REG_OUTPUT_GAIN_CONTROL_18 0x34
144#define KNOB_REG_OUTPUT_GAIN_CONTROL_19 0x35
145#define KNOB_REG_OUTPUT_GAIN_CONTROL_20 0x36
146#define KNOB_REG_OUTPUT_GAIN_CONTROL_21 0x37
147#define KNOB_REG_OUTPUT_GAIN_CONTROL_22 0x38
148#define KNOB_REG_OUTPUT_GAIN_CONTROL_23 0x39
149#define KNOB_REG_OFFSET 0x3A
150#define KNOB_REG_I2C_BUS_SUBADDRESS_1 0x3B
151#define KNOB_REG_I2C_BUS_SUBADDRESS_2 0x3C
152#define KNOB_REG_I2C_BUS_SUBADDRESS_3 0x3D
153#define KNOB_REG_ALL_CALL_I2C_BUS_ADDRESS 0x3E
154#define KNOB_REG_BRIGHTNESS_CONTROL_FOR_ALL_LED 0x3F
155#define KNOB_REG_GAIN_CONTROL_FOR_ALL_LED 0x40
156#define KNOB_REG_OUTPUT_ERROR_FLAG_0 0x41
157#define KNOB_REG_OUTPUT_ERROR_FLAG_1 0x42
158#define KNOB_REG_OUTPUT_ERROR_FLAG_2 0x43
159#define KNOB_REG_OUTPUT_ERROR_FLAG_3 0x44
160#define KNOB_REG_OUTPUT_ERROR_FLAG_4 0x45
161#define KNOB_REG_OUTPUT_ERROR_FLAG_5 0x46
168#define KNOB_M1_AUTO_INCREMENT_BIT_1_TO_0 0x00
169#define KNOB_M1_AUTO_INCREMENT_BIT_1_TO_1 0x40
170#define KNOB_M1_AUTO_INCREMENT_BIT_0_TO_0 0x00
171#define KNOB_M1_AUTO_INCREMENT_BIT_0_TO_1 0x20
172#define KNOB_M1_SET_NORMAL_MODE 0x00
173#define KNOB_M1_SET_LOW_POWER_MODE 0x10
174#define KNOB_M1_USES_I2C_BUS_SUBADDRESS_1 0x08
175#define KNOB_M1_USES_I2C_BUS_SUBADDRESS_2 0x04
176#define KNOB_M1_USES_I2C_BUS_SUBADDRESS_3 0x02
177#define KNOB_M1_USES_ALL_CALL_I2C_BUS_ADDRESS 0x01
184#define KNOB_M2_GROUP_CONTROL_DIMMING 0x00
185#define KNOB_M2_GROUP_CONTROL_BLINKING 0x20
186#define KNOB_M2_CHANGE_ON_STOP_CMD 0x00
187#define KNOB_M2_CHANGE_ON_ACK 0x10
194#define KNOB_BRIGHTNESS_ALL_LED 0x30
195#define KNOB_OUTPUT_GAIN_ALL_LED 0x40
202#define KNOB_LED_ON 0xFF
203#define KNOB_LED_OFF 0x00
210#define KNOB_DEF_SLAVE_ADDRESS 0x70
217#define KNOB_FULL_OUTPUT_CURRENT_GAIN 0xFF
224#define KNOB_ENABLE_LED_OUTPUTS 0x00
225#define KNOB_DISABLE_LED_OUTPUTS 0x01
228 // End group macro
229// --------------------------------------------------------------- PUBLIC TYPES
238typedef struct
239{
240 // Output pins
241
242 digital_out_t rst;
243 digital_out_t oe;
244
245 // Input pins
246
247 digital_in_t ena;
248 digital_in_t enb;
249 digital_in_t sw;
250
251 // Modules
252
253 i2c_master_t i2c;
254
255 // ctx variable
256
258
263
264} knob_t;
265
269typedef struct
270{
271 // Communication gpio pins
272
273 pin_name_t scl;
274 pin_name_t sda;
275
276 // Additional gpio pins
277
278 pin_name_t ena;
279 pin_name_t rst;
280 pin_name_t enb;
281 pin_name_t oe;
282 pin_name_t sw;
283
284 // static variable
285
286 uint32_t i2c_speed;
287 uint8_t i2c_address;
288
289} knob_cfg_t;
290
291 // End types group
292
293// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
294
300#ifdef __cplusplus
301extern "C"{
302#endif
303
313
322
342
353void knob_generic_write ( knob_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
354
366void knob_generic_read ( knob_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
367
373void knob_reset ( knob_t *ctx );
374
381void knob_led_output_enable ( knob_t *ctx, uint8_t state);
382
390
397uint8_t knob_get_enb_state ( knob_t *ctx );
398
406
413void knob_set_encoder_start_position ( knob_t *ctx, int32_t position );
414
422void knob_set_led_state ( knob_t *ctx, uint8_t led, uint8_t state );
423
434void knob_set_brightness ( knob_t *ctx, uint8_t led, uint8_t value );
435
446void knob_set_output_gain ( knob_t *ctx, uint8_t led, uint8_t value );
447
455void knob_get_encoder_position ( knob_t *ctx, int32_t *position, uint8_t *dir );
456
457#ifdef __cplusplus
458}
459#endif
460#endif // _KNOB_H_
461
462 // End public_function group
464
465// ------------------------------------------------------------------------- END
#define KNOB_RETVAL
Definition knob.h:81
uint8_t knob_get_ena_state(knob_t *ctx)
Functions for get ENA pin state.
void knob_generic_write(knob_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void knob_get_encoder_position(knob_t *ctx, int32_t *position, uint8_t *dir)
Functions for get Encoder position.
void knob_set_brightness(knob_t *ctx, uint8_t led, uint8_t value)
Functions for set Brightness.
uint8_t knob_get_enb_state(knob_t *ctx)
Functions for get ENB pin state.
void knob_reset(knob_t *ctx)
Functions for reset device.
uint8_t knob_get_sw_button_state(knob_t *ctx)
Functions for get SW pin(switch button) state.
KNOB_RETVAL knob_init(knob_t *ctx, knob_cfg_t *cfg)
Initialization function.
void knob_set_led_state(knob_t *ctx, uint8_t led, uint8_t state)
Functions for set led state(PWM on the LED)
void knob_cfg_setup(knob_cfg_t *cfg)
Config Object Initialization function.
void knob_default_cfg(knob_t *ctx)
Click Default Configuration function.
void knob_set_encoder_start_position(knob_t *ctx, int32_t position)
Functions for set new start encoder position.
void knob_led_output_enable(knob_t *ctx, uint8_t state)
Functions for enable Led Output.
void knob_set_output_gain(knob_t *ctx, uint8_t led, uint8_t value)
Functions for set output GAIN.
void knob_generic_read(knob_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
Click configuration structure definition.
Definition knob.h:270
uint32_t i2c_speed
Definition knob.h:286
pin_name_t ena
Definition knob.h:278
pin_name_t oe
Definition knob.h:281
pin_name_t enb
Definition knob.h:280
pin_name_t scl
Definition knob.h:273
pin_name_t sw
Definition knob.h:282
pin_name_t sda
Definition knob.h:274
pin_name_t rst
Definition knob.h:279
uint8_t i2c_address
Definition knob.h:287
Click ctx object definition.
Definition knob.h:239
digital_in_t enb
Definition knob.h:248
uint8_t state_old_rotate
Definition knob.h:260
digital_in_t ena
Definition knob.h:247
int32_t encoder_position
Definition knob.h:259
digital_in_t sw
Definition knob.h:249
uint8_t state_new_rotate
Definition knob.h:261
i2c_master_t i2c
Definition knob.h:253
digital_out_t oe
Definition knob.h:243
uint8_t start_status
Definition knob.h:262
digital_out_t rst
Definition knob.h:242
uint8_t slave_address
Definition knob.h:257