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 
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_i2c_master.h"
52 
73 #define C7SEG2_REG_DEVICE_ID 0x00
74 #define C7SEG2_REG_DEVICE_EN 0x01
75 #define C7SEG2_REG_CH_EN_LOW 0x02
76 #define C7SEG2_REG_CH_EN_HIGH 0x03
77 #define C7SEG2_REG_CONFIG 0x04
78 #define C7SEG2_REG_FAULT_MASK 0x05
79 #define C7SEG2_REG_FAULT_INT 0x06
80 #define C7SEG2_REG_OPEN_LED_LOW 0x07
81 #define C7SEG2_REG_OPEN_LED_HIGH 0x08
82 #define C7SEG2_REG_CUR_LED_CS0 0x09
83 #define C7SEG2_REG_CUR_LED_CS1 0x0A
84 #define C7SEG2_REG_CUR_LED_CS2 0x0B
85 #define C7SEG2_REG_CUR_LED_CS3 0x0C
86 #define C7SEG2_REG_CUR_LED_CS4 0x0D
87 #define C7SEG2_REG_CUR_LED_CS5 0x0E
88 #define C7SEG2_REG_CUR_LED_CS6 0x0F
89 #define C7SEG2_REG_CUR_LED_CS7 0x10
90 #define C7SEG2_REG_CUR_LED_CS8 0x11
91 #define C7SEG2_REG_CUR_LED_CS9 0x12
92 #define C7SEG2_REG_CUR_LED_CS10 0x13
93 #define C7SEG2_REG_CUR_LED_CS11 0x14
94 #define C7SEG2_REG_PATTERN_SEQ_REP 0x15
95 #define C7SEG2_REG_PATTERN_0_DUR 0x16
96 #define C7SEG2_REG_PATTERN_1_DUR 0x17
97 #define C7SEG2_REG_PATTERN_2_DUR 0x18
98 #define C7SEG2_REG_PATTERN_3_DUR 0x19
99 #define C7SEG2_REG_PATTERN_4_DUR 0x1A
100 #define C7SEG2_REG_PATTERN_5_DUR 0x1B
101 #define C7SEG2_REG_PATTERN_6_DUR 0x1C
102 #define C7SEG2_REG_PATTERN_7_DUR 0x1D
103 #define C7SEG2_REG_PWMREG_OFFSET 0x1E
104 #define C7SEG2_REG_CLOCK_CONFIG 0xE0
105  // c7seg2_reg
107 
122 #define C7SEG2_SEGMENT_0 0
123 #define C7SEG2_SEGMENT_1 1
124 #define C7SEG2_SEGMENT_2 2
125 #define C7SEG2_SEGMENTS_NUMBER 3
126 #define C7SEG2_SEGMENTS_DISABLED 0x0000u
127 
132 #define C7SEG2_DP_NONE 0
133 #define C7SEG2_DP_AT_SEGMENT_0 1
134 #define C7SEG2_DP_AT_SEGMENT_1 2
135 #define C7SEG2_DP_AT_SEGMENT_2 3
136 #define C7SEG2_DP_MASK 0x03
137 #define C7SEG2_DP_PIN_MASK 0x0010u
138 
143 #define C7SEG2_REFRESH_RATE_US 7500
144 #define C7SEG2_REFRESH_RATE_DELAY ( C7SEG2_REFRESH_RATE_US / 50 )
145 
150 #define C7SEG2_DIGIT_0 0
151 #define C7SEG2_DIGIT_1 1
152 #define C7SEG2_DIGIT_2 2
153 #define C7SEG2_DIGIT_3 3
154 #define C7SEG2_DIGIT_4 4
155 #define C7SEG2_DIGIT_5 5
156 #define C7SEG2_DIGIT_6 6
157 #define C7SEG2_DIGIT_7 7
158 #define C7SEG2_DIGIT_8 8
159 #define C7SEG2_DIGIT_9 9
160 #define C7SEG2_DIGITS_NUMBER 10
161 #define C7SEG2_MAX_NUMBER 999
162 
167 #define C7SEG2_DEVICE_ID 0x12
168 
174 #define C7SEG2_SW_RESET 0x80
175 #define C7SEG2_ENABLE 0x01
176 
182 #define C7SEG2_CURRENT_DEFAULT 15.0f
183 #define C7SEG2_CURRENT_STEP_TO_HEX 12.75f
184 
190 #define C7SEG2_DEVICE_ADDRESS 0x58
191  // c7seg2_set
193 
208 #define C7SEG2_MAP_MIKROBUS( cfg, mikrobus ) \
209  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
210  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
211  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
212  // c7seg2_map // c7seg2
215 
220 typedef struct
221 {
222  // Input pins
223  digital_in_t int_pin;
225  // Modules
226  i2c_master_t i2c;
228  // I2C slave address
229  uint8_t slave_address;
231 } c7seg2_t;
232 
237 typedef struct
238 {
239  pin_name_t scl;
240  pin_name_t sda;
242  pin_name_t int_pin;
244  uint32_t i2c_speed;
245  uint8_t i2c_address;
247  float current;
249 } c7seg2_cfg_t;
250 
255 typedef enum
256 {
258  C7SEG2_ERROR = -1
259 
261 
283 
297 err_t c7seg2_init ( c7seg2_t *ctx, c7seg2_cfg_t *cfg );
298 
309 err_t c7seg2_sw_reset ( c7seg2_t *ctx );
310 
324 
339 err_t c7seg2_generic_write ( c7seg2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
340 
355 err_t c7seg2_generic_read ( c7seg2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
356 
365 uint8_t c7seg2_get_int_pin ( c7seg2_t *ctx );
366 
380 err_t c7seg2_write_reg ( c7seg2_t *ctx, uint8_t reg, uint8_t data_in );
381 
395 err_t c7seg2_read_reg ( c7seg2_t *ctx, uint8_t reg, uint8_t *data_out );
396 
408 err_t c7seg2_set_segments_current ( c7seg2_t *ctx, float current_val );
409 
423 err_t c7seg2_write_segment ( c7seg2_t *ctx, uint8_t segment, uint8_t number, uint8_t dpt );
424 
436 
449 err_t c7seg2_write_number ( c7seg2_t *ctx, uint16_t number, uint8_t dpt );
450 
451 #ifdef __cplusplus
452 }
453 #endif
454 #endif // C7SEG2_H
455  // c7seg2
457 
458 // ------------------------------------------------------------------------ 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:229
c7seg2_cfg_t::scl
pin_name_t scl
Definition: c7seg2.h:239
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:223
c7seg2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c7seg2.h:244
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:247
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:256
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:226
c7seg2_t
7-SEG 2 Click context object.
Definition: c7seg2.h:221
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:245
c7seg2_cfg_t::int_pin
pin_name_t int_pin
Definition: c7seg2.h:242
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:258
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:257
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:238
c7seg2_cfg_t::sda
pin_name_t sda
Definition: c7seg2.h:240