c7seg2  2.1.0.0
c7seg2.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2023 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 C7SEG2_H
29 #define C7SEG2_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define C7SEG2_REG_DEVICE_ID 0x00
70 #define C7SEG2_REG_DEVICE_EN 0x01
71 #define C7SEG2_REG_CH_EN_LOW 0x02
72 #define C7SEG2_REG_CH_EN_HIGH 0x03
73 #define C7SEG2_REG_CONFIG 0x04
74 #define C7SEG2_REG_FAULT_MASK 0x05
75 #define C7SEG2_REG_FAULT_INT 0x06
76 #define C7SEG2_REG_OPEN_LED_LOW 0x07
77 #define C7SEG2_REG_OPEN_LED_HIGH 0x08
78 #define C7SEG2_REG_CUR_LED_CS0 0x09
79 #define C7SEG2_REG_CUR_LED_CS1 0x0A
80 #define C7SEG2_REG_CUR_LED_CS2 0x0B
81 #define C7SEG2_REG_CUR_LED_CS3 0x0C
82 #define C7SEG2_REG_CUR_LED_CS4 0x0D
83 #define C7SEG2_REG_CUR_LED_CS5 0x0E
84 #define C7SEG2_REG_CUR_LED_CS6 0x0F
85 #define C7SEG2_REG_CUR_LED_CS7 0x10
86 #define C7SEG2_REG_CUR_LED_CS8 0x11
87 #define C7SEG2_REG_CUR_LED_CS9 0x12
88 #define C7SEG2_REG_CUR_LED_CS10 0x13
89 #define C7SEG2_REG_CUR_LED_CS11 0x14
90 #define C7SEG2_REG_PATTERN_SEQ_REP 0x15
91 #define C7SEG2_REG_PATTERN_0_DUR 0x16
92 #define C7SEG2_REG_PATTERN_1_DUR 0x17
93 #define C7SEG2_REG_PATTERN_2_DUR 0x18
94 #define C7SEG2_REG_PATTERN_3_DUR 0x19
95 #define C7SEG2_REG_PATTERN_4_DUR 0x1A
96 #define C7SEG2_REG_PATTERN_5_DUR 0x1B
97 #define C7SEG2_REG_PATTERN_6_DUR 0x1C
98 #define C7SEG2_REG_PATTERN_7_DUR 0x1D
99 #define C7SEG2_REG_PWMREG_OFFSET 0x1E
100 #define C7SEG2_REG_CLOCK_CONFIG 0xE0
101  // c7seg2_reg
103 
118 #define C7SEG2_SEGMENT_0 0
119 #define C7SEG2_SEGMENT_1 1
120 #define C7SEG2_SEGMENT_2 2
121 #define C7SEG2_SEGMENTS_NUMBER 3
122 #define C7SEG2_SEGMENTS_DISABLED 0x0000u
123 
128 #define C7SEG2_DP_NONE 0
129 #define C7SEG2_DP_AT_SEGMENT_0 1
130 #define C7SEG2_DP_AT_SEGMENT_1 2
131 #define C7SEG2_DP_AT_SEGMENT_2 3
132 #define C7SEG2_DP_MASK 0x03
133 #define C7SEG2_DP_PIN_MASK 0x0010u
134 
139 #define C7SEG2_REFRESH_RATE_US 7500
140 #define C7SEG2_REFRESH_RATE_DELAY ( C7SEG2_REFRESH_RATE_US / 50 )
141 
146 #define C7SEG2_DIGIT_0 0
147 #define C7SEG2_DIGIT_1 1
148 #define C7SEG2_DIGIT_2 2
149 #define C7SEG2_DIGIT_3 3
150 #define C7SEG2_DIGIT_4 4
151 #define C7SEG2_DIGIT_5 5
152 #define C7SEG2_DIGIT_6 6
153 #define C7SEG2_DIGIT_7 7
154 #define C7SEG2_DIGIT_8 8
155 #define C7SEG2_DIGIT_9 9
156 #define C7SEG2_DIGITS_NUMBER 10
157 #define C7SEG2_MAX_NUMBER 999
158 
163 #define C7SEG2_DEVICE_ID 0x12
164 
170 #define C7SEG2_SW_RESET 0x80
171 #define C7SEG2_ENABLE 0x01
172 
178 #define C7SEG2_CURRENT_DEFAULT 15.0f
179 #define C7SEG2_CURRENT_STEP_TO_HEX 12.75f
180 
186 #define C7SEG2_DEVICE_ADDRESS 0x58
187  // c7seg2_set
189 
204 #define C7SEG2_MAP_MIKROBUS( cfg, mikrobus ) \
205  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
206  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
207  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
208  // c7seg2_map // c7seg2
211 
216 typedef struct
217 {
218  // Input pins
219  digital_in_t int_pin;
221  // Modules
222  i2c_master_t i2c;
224  // I2C slave address
225  uint8_t slave_address;
227 } c7seg2_t;
228 
233 typedef struct
234 {
235  pin_name_t scl;
236  pin_name_t sda;
238  pin_name_t int_pin;
240  uint32_t i2c_speed;
241  uint8_t i2c_address;
243  float current;
245 } c7seg2_cfg_t;
246 
251 typedef enum
252 {
254  C7SEG2_ERROR = -1
255 
257 
279 
293 err_t c7seg2_init ( c7seg2_t *ctx, c7seg2_cfg_t *cfg );
294 
305 err_t c7seg2_sw_reset ( c7seg2_t *ctx );
306 
320 
335 err_t c7seg2_generic_write ( c7seg2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
336 
351 err_t c7seg2_generic_read ( c7seg2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
352 
361 uint8_t c7seg2_get_int_pin ( c7seg2_t *ctx );
362 
376 err_t c7seg2_write_reg ( c7seg2_t *ctx, uint8_t reg, uint8_t data_in );
377 
391 err_t c7seg2_read_reg ( c7seg2_t *ctx, uint8_t reg, uint8_t *data_out );
392 
404 err_t c7seg2_set_segments_current ( c7seg2_t *ctx, float current_val );
405 
419 err_t c7seg2_write_segment ( c7seg2_t *ctx, uint8_t segment, uint8_t number, uint8_t dpt );
420 
432 
445 err_t c7seg2_write_number ( c7seg2_t *ctx, uint16_t number, uint8_t dpt );
446 
447 #ifdef __cplusplus
448 }
449 #endif
450 #endif // C7SEG2_H
451  // c7seg2
453 
454 // ------------------------------------------------------------------------ END
c7seg2_write_reg
err_t c7seg2_write_reg(c7seg2_t *ctx, uint8_t reg, uint8_t data_in)
7-SEG 2 I2C register writing function.
c7seg2_t::slave_address
uint8_t slave_address
Definition: c7seg2.h:225
c7seg2_cfg_t::scl
pin_name_t scl
Definition: c7seg2.h:235
c7seg2_default_cfg
err_t c7seg2_default_cfg(c7seg2_t *ctx)
7-SEG 2 default configuration function.
c7seg2_t::int_pin
digital_in_t int_pin
Definition: c7seg2.h:219
c7seg2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c7seg2.h:240
c7seg2_sw_reset
err_t c7seg2_sw_reset(c7seg2_t *ctx)
7-SEG 2 software reset function.
c7seg2_cfg_t::current
float current
Definition: c7seg2.h:243
c7seg2_generic_read
err_t c7seg2_generic_read(c7seg2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
7-SEG 2 I2C reading function.
c7seg2_return_value_t
c7seg2_return_value_t
7-SEG 2 Click return value data.
Definition: c7seg2.h:252
c7seg2_generic_write
err_t c7seg2_generic_write(c7seg2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
7-SEG 2 I2C writing function.
c7seg2_t::i2c
i2c_master_t i2c
Definition: c7seg2.h:222
c7seg2_t
7-SEG 2 Click context object.
Definition: c7seg2.h:217
c7seg2_disable_segments
err_t c7seg2_disable_segments(c7seg2_t *ctx)
7-SEG 2 disable segments function.
c7seg2_init
err_t c7seg2_init(c7seg2_t *ctx, c7seg2_cfg_t *cfg)
7-SEG 2 initialization function.
c7seg2_cfg_t::i2c_address
uint8_t i2c_address
Definition: c7seg2.h:241
c7seg2_cfg_t::int_pin
pin_name_t int_pin
Definition: c7seg2.h:238
c7seg2_write_number
err_t c7seg2_write_number(c7seg2_t *ctx, uint16_t number, uint8_t dpt)
7-SEG 2 number writing function.
C7SEG2_ERROR
@ C7SEG2_ERROR
Definition: c7seg2.h:254
c7seg2_read_reg
err_t c7seg2_read_reg(c7seg2_t *ctx, uint8_t reg, uint8_t *data_out)
7-SEG 2 I2C register reading function.
c7seg2_set_segments_current
err_t c7seg2_set_segments_current(c7seg2_t *ctx, float current_val)
7-SEG 2 set segments current value function.
c7seg2_get_int_pin
uint8_t c7seg2_get_int_pin(c7seg2_t *ctx)
7-SEG 2 get interrupt pin state function.
C7SEG2_OK
@ C7SEG2_OK
Definition: c7seg2.h:253
c7seg2_cfg_setup
void c7seg2_cfg_setup(c7seg2_cfg_t *cfg)
7-SEG 2 configuration object setup function.
c7seg2_write_segment
err_t c7seg2_write_segment(c7seg2_t *ctx, uint8_t segment, uint8_t number, uint8_t dpt)
7-SEG 2 single segment writing function.
c7seg2_cfg_t
7-SEG 2 Click configuration object.
Definition: c7seg2.h:234
c7seg2_cfg_t::sda
pin_name_t sda
Definition: c7seg2.h:236