c16x12  2.0.0.0
c16x12.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 C16X12_H
36 #define C16X12_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define C16X12_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56  cfg.sdb = MIKROBUS( mikrobus, MIKROBUS_CS ); \
57  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
58 
64 #define C16X12_RETVAL uint8_t
65 
66 #define C16X12_OK 0x00
67 #define C16X12_INIT_ERROR 0xFF
68 
74 #define C16X12G_PSR 0xFD
75 #define C16X12G_PSWL 0xFE
76 #define C16X12G_IMR 0xF0
77 #define C16X12G_ISR 0xF1
78 #define C16X12G_PSWL_DISABLE 0x00
79 #define C16X12G_PSWL_ENABLE 0xC5
80 #define C16X12G_IMR_IAC 0x08
81 #define C16X12G_IMR_IAB 0x04
82 #define C16X12G_IMR_IS 0x02
83 #define C16X12G_IMR_IO 0x01
84 #define C16X12G_ISR_ABM3 0x10
85 #define C16X12G_ISR_ABM2 0x08
86 #define C16X12G_ISR_ABM1 0x04
87 #define C16X12G_ISR_SB 0x02
88 #define C16X12G_ISR_OB 0x01
89 
95 #define C16X12G_CR_SYNC_MASTER 0x40
96 #define C16X12G_CR_SYNC_SLAVE 0x80
97 #define C16X12G_CR_OSD 0x04
98 #define C16X12G_CR_BEN 0x02
99 #define C16X12G_CR_SSD 0x01
100 #define C16X12G_LEDONOFF 0x0000
101 #define C16X12G_LEDOPEN 0x0018
102 #define C16X12G_LEDSHORT 0x0030
103 #define C16X12G_LEDPWM 0x0100
104 #define C16X12G_LEDABM 0x0200
105 #define C16X12G_CR 0x0300
106 #define C16X12G_GCC 0x0301
107 #define C16X12G_ABM1 0x0302
108 #define C16X12G_ABM2 0x0306
109 #define C16X12G_ABM3 0x030A
110 #define C16X12G_TUR 0x030E
111 #define C16X12G_SWPUR 0x030F
112 #define C16X12G_CSPDR 0x0310
113 #define C16X12G_RESET 0x0311
114 
120 #define C16X12G_CS 16
121 #define C16X12G_SW 12
122 #define C16X12G_GND_ADDR 0x00
123 #define C16X12G_SCL_ADDR 0x01
124 #define C16X12G_SDA_ADDR 0x02
125 #define C16X12G_VCC_ADDR 0x03
126 #define C16X12G_ABM_LOOP_TIMES_MAX 0x0FFF
127 #define C16X12G_ABM_LOOP_FOREVER 0x0000
128 
134 #define C16X12G_LED_STATE_OFF 0x00
135 #define C16X12G_LED_STATE_ON 0x01
136 
142 #define C16X12G_CONTINUE_SETTINGS 0x00
143 #define C16X12G_STOP_SETTINGS 0x01
144 
150 #define C16X12G_LED_STATUS_NORMAL 0x00
151 #define C16X12G_LED_STATUS_OPEN 0x01
152 #define C16X12G_LED_STATUS_SHORT 0x02
153 #define C16X12G_LED_STATUS_UNKNOWN 0x03
154 
160 #define C16X12G_RESISTOR_OFF 0x00
161 #define C16X12G_RESISTOR_500 0x01
162 #define C16X12G_RESISTOR_1K 0x02
163 #define C16X12G_RESISTOR_2K 0x03
164 #define C16X12G_RESISTOR_4K 0x04
165 #define C16X12G_RESISTOR_8K 0x05
166 #define C16X12G_RESISTOR_16K 0x06
167 #define C16X12G_RESISTOR_32K 0x07
168 
174 #define C16X12G_LED_MODE_PWM 0x00
175 #define C16X12G_LED_MODE_ABM1 0x01
176 #define C16X12G_LED_MODE_ABM2 0x02
177 #define C16X12G_LED_MODE_ABM3 0x03
178 
184 #define C16X12G_ABM_T1_210MS 0x00
185 #define C16X12G_ABM_T1_420MS 0x20
186 #define C16X12G_ABM_T1_840MS 0x40
187 #define C16X12G_ABM_T1_1680MS 0x60
188 #define C16X12G_ABM_T1_3360MS 0x80
189 #define C16X12G_ABM_T1_6720MS 0xA0
190 #define C16X12G_ABM_T1_13440MS 0xC0
191 #define C16X12G_ABM_T1_26880MS 0xE0
192 
198 #define C16X12G_ABM_T2_0MS 0x00
199 #define C16X12G_ABM_T2_210MS 0x02
200 #define C16X12G_ABM_T2_420MS 0x04
201 #define C16X12G_ABM_T2_840MS 0x06
202 #define C16X12G_ABM_T2_1680MS 0x08
203 #define C16X12G_ABM_T2_3360MS 0x0A
204 #define C16X12G_ABM_T2_6720MS 0x0C
205 #define C16X12G_ABM_T2_13440MS 0x0E
206 #define C16X12G_ABM_T2_26880MS 0x10
207 
213 #define C16X12G_ABM_T3_210MS 0x00
214 #define C16X12G_ABM_T3_420MS 0x20
215 #define C16X12G_ABM_T3_840MS 0x40
216 #define C16X12G_ABM_T3_1680MS 0x60
217 #define C16X12G_ABM_T3_3360MS 0x80
218 #define C16X12G_ABM_T3_6720MS 0xA0
219 #define C16X12G_ABM_T3_13440MS 0xC0
220 #define C16X12G_ABM_T3_26880MS 0xE0
221 
227 #define C16X12G_ABM_T4_0MS 0x00
228 #define C16X12G_ABM_T4_210MS 0x02
229 #define C16X12G_ABM_T4_420MS 0x04
230 #define C16X12G_ABM_T4_840MS 0x06
231 #define C16X12G_ABM_T4_1680MS 0x08
232 #define C16X12G_ABM_T4_3360MS 0x0A
233 #define C16X12G_ABM_T4_6720MS 0x0C
234 #define C16X12G_ABM_T4_13440MS 0x0E
235 #define C16X12G_ABM_T4_26880MS 0x10
236 #define C16X12G_ABM_T4_53760MS 0x12
237 #define C16X12G_ABM_T4_107520MS 0x14
238 
244 #define C16X12G_ABM_LOOP_BEGIN_T1 0x00
245 #define C16X12G_ABM_LOOP_BEGIN_T2 0x10
246 #define C16X12G_ABM_LOOP_BEGIN_T3 0x20
247 #define C16X12G_ABM_LOOP_BEGIN_T4 0x30
248 
254 #define C16X12G_ABM_LOOP_END_T3 0x00
255 #define C16X12G_ABM_LOOP_END_T1 0x40
256 
262 #define C16X12G_ABM_NUM_1 0x0302
263 #define C16X12G_ABM_NUM_2 0x0306
264 #define C16X12G_ABM_NUM_3 0x030A
265  // End group macro
268 
269 // --------------------------------------------------------------- PUBLIC TYPES
278 typedef struct
279 {
280  // Output pins
281 
282  digital_out_t rst;
283  digital_out_t sdb;
284 
285  // Input pins
286 
287  digital_in_t int_pin;
288 
289  // Modules
290 
291  i2c_master_t i2c;
292 
293  // ctx variable
294 
295  uint8_t slave_address;
296 
297 } c16x12_t;
298 
302 typedef struct
303 {
304  // Communication gpio pins
305 
306  pin_name_t scl;
307  pin_name_t sda;
308 
309  // Additional gpio pins
310 
311  pin_name_t rst;
312  pin_name_t sdb;
313  pin_name_t int_pin;
314 
315  // static variable
316 
317  uint32_t i2c_speed;
318  uint8_t i2c_address;
319 
320 } c16x12_cfg_t;
321 
325 typedef struct
326 {
327  uint8_t time_1;
328  uint8_t time_2;
329  uint8_t time_3;
330  uint8_t time_4;
331  uint8_t loop_begin;
332  uint8_t loop_end;
333  uint16_t loop_times;
334 
335 }c16x12_abm_t;
336  // End types group
338 
339 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
340 
346 #ifdef __cplusplus
347 extern "C"{
348 #endif
349 
358 void c16x12_cfg_setup ( c16x12_cfg_t *cfg );
359 
369 
377 void c16x12_default_cfg ( c16x12_t *ctx );
378 
389 void c16x12_generic_write ( c16x12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
390 
401 void c16x12_generic_read ( c16x12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
402 
410 void c16x12g_write_reg ( c16x12_t *ctx, uint8_t reg, uint8_t c_data );
411 
418 void c16x12g_select_page ( c16x12_t *ctx, uint8_t page );
419 
429 void c16x12g_write_page_byte ( c16x12_t *ctx, uint16_t reg_addr, uint8_t reg_value );
430 
441 void c16x12g_write_page_data ( c16x12_t *ctx, uint16_t reg, uint8_t *data_buf, uint8_t n_data );
442 
450 uint8_t c16x12g_read_reg ( c16x12_t *ctx, uint8_t reg );
451 
458 void c16x12g_set_stand_by ( c16x12_t *ctx, uint8_t state );
459 
465 void c16x12g_device_reset ( c16x12_t *ctx );
466 
474 uint8_t c16x12g_get_interrupt ( c16x12_t *ctx );
475 
486 
495 void c16x12g_set_all_leds ( c16x12_t *ctx, uint8_t state );
496 
504 void c16x12g_set_global_current_control ( c16x12_t *ctx, uint8_t gcc );
505 
511 void c16x12g_clear_display ( c16x12_t *ctx );
512 
524 void c16x12g_set_column_state ( c16x12_t *ctx, uint8_t col, uint16_t state, uint8_t c_end );
525 
541 void c16x12g_set_leds_mode ( c16x12_t *ctx, uint8_t mode );
542 
549 void c16x12g_set_pmw ( c16x12_t *ctx, uint8_t pwm_value );
550 
565 void c16x12g_set_led ( c16x12_t *ctx, uint8_t x_pos, uint8_t y_pos, uint8_t state, uint8_t c_end );
566 
574 void c16x12g_display_byte ( c16x12_t *ctx, char ch );
575 
583 void c16x12g_display_image ( c16x12_t *ctx, uint16_t *p_image );
584 
594 void c16x12g_display_text ( c16x12_t *ctx, char *p_text, uint8_t n_char, uint8_t speed );
595 
604 void c16x12g_config_abm ( c16x12_t *ctx, uint16_t n_abm, c16x12_abm_t *config );
605 
613 void c16x12g_start_abm ( c16x12_t *ctx );
614 
615 
616 
617 #ifdef __cplusplus
618 }
619 #endif
620 #endif // _C16X12_H_
621  // End public_function group
624 
625 // ------------------------------------------------------------------------- END
void c16x12_cfg_setup(c16x12_cfg_t *cfg)
Config Object Initialization function.
digital_out_t sdb
Definition: c16x12.h:283
void c16x12g_set_column_state(c16x12_t *ctx, uint8_t col, uint16_t state, uint8_t c_end)
Functions for sets column state.
pin_name_t sda
Definition: c16x12.h:307
void c16x12g_start_abm(c16x12_t *ctx)
Functions for start new ABM configuration.
digital_in_t int_pin
Definition: c16x12.h:287
void c16x12g_write_page_data(c16x12_t *ctx, uint16_t reg, uint8_t *data_buf, uint8_t n_data)
Functions for write n byte in registers with select page.
void c16x12g_set_pmw(c16x12_t *ctx, uint8_t pwm_value)
Functions for sets PWM for all LEDs.
Click ctx object definition.
Definition: c16x12.h:278
pin_name_t scl
Definition: c16x12.h:306
void c16x12g_set_stand_by(c16x12_t *ctx, uint8_t state)
Functions for sets SDB pin state.
uint8_t time_4
Definition: c16x12.h:330
ABM structure definition.
Definition: c16x12.h:325
void c16x12g_write_page_byte(c16x12_t *ctx, uint16_t reg_addr, uint8_t reg_value)
Functions for write one byte in register with select page.
uint16_t loop_times
Definition: c16x12.h:333
uint8_t i2c_address
Definition: c16x12.h:318
pin_name_t sdb
Definition: c16x12.h:312
void c16x12g_set_led(c16x12_t *ctx, uint8_t x_pos, uint8_t y_pos, uint8_t state, uint8_t c_end)
Functions for sets LEDs state.
pin_name_t rst
Definition: c16x12.h:311
Click configuration structure definition.
Definition: c16x12.h:302
void c16x12g_display_text(c16x12_t *ctx, char *p_text, uint8_t n_char, uint8_t speed)
Functions for display text with scroll.
void c16x12g_set_global_current_control(c16x12_t *ctx, uint8_t gcc)
Functions for sets global current for all leds.
void c16x12g_set_leds_mode(c16x12_t *ctx, uint8_t mode)
Functions for sets LEDs mode.
void c16x12_generic_read(c16x12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void c16x12_generic_write(c16x12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
i2c_master_t i2c
Definition: c16x12.h:291
void c16x12g_clear_display(c16x12_t *ctx)
Functions for clear display.
pin_name_t int_pin
Definition: c16x12.h:313
uint8_t loop_end
Definition: c16x12.h:332
void c16x12_default_cfg(c16x12_t *ctx)
Click Default Configuration function.
uint8_t loop_begin
Definition: c16x12.h:331
uint32_t i2c_speed
Definition: c16x12.h:317
void c16x12g_display_byte(c16x12_t *ctx, char ch)
Functions for display one Byte.
uint8_t c16x12g_read_reg(c16x12_t *ctx, uint8_t reg)
Functions for read byte from register.
void c16x12g_set_all_leds(c16x12_t *ctx, uint8_t state)
Functions for sets all LEDs on the state.
void c16x12g_config_abm(c16x12_t *ctx, uint16_t n_abm, c16x12_abm_t *config)
Functions for ABM configuration.
uint8_t slave_address
Definition: c16x12.h:295
uint8_t time_2
Definition: c16x12.h:328
uint8_t c16x12g_get_interrupt(c16x12_t *ctx)
Functions for reads interrupt state.
void c16x12g_display_image(c16x12_t *ctx, uint16_t *p_image)
Functions for display Image.
void c16x12g_device_configuration(c16x12_t *ctx)
Functions for device configuration.
void c16x12g_device_reset(c16x12_t *ctx)
Functions for device reset.
digital_out_t rst
Definition: c16x12.h:282
#define C16X12_RETVAL
Definition: c16x12.h:64
C16X12_RETVAL c16x12_init(c16x12_t *ctx, c16x12_cfg_t *cfg)
Initialization function.
uint8_t time_1
Definition: c16x12.h:327
void c16x12g_select_page(c16x12_t *ctx, uint8_t page)
Functions for select page.
void c16x12g_write_reg(c16x12_t *ctx, uint8_t reg, uint8_t c_data)
Functions for write one byte in register.
uint8_t time_3
Definition: c16x12.h:329