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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define C16X12_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
66  cfg.sdb = MIKROBUS( mikrobus, MIKROBUS_CS ); \
67  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
68 
74 #define C16X12_RETVAL uint8_t
75 
76 #define C16X12_OK 0x00
77 #define C16X12_INIT_ERROR 0xFF
78 
84 #define C16X12G_PSR 0xFD
85 #define C16X12G_PSWL 0xFE
86 #define C16X12G_IMR 0xF0
87 #define C16X12G_ISR 0xF1
88 #define C16X12G_PSWL_DISABLE 0x00
89 #define C16X12G_PSWL_ENABLE 0xC5
90 #define C16X12G_IMR_IAC 0x08
91 #define C16X12G_IMR_IAB 0x04
92 #define C16X12G_IMR_IS 0x02
93 #define C16X12G_IMR_IO 0x01
94 #define C16X12G_ISR_ABM3 0x10
95 #define C16X12G_ISR_ABM2 0x08
96 #define C16X12G_ISR_ABM1 0x04
97 #define C16X12G_ISR_SB 0x02
98 #define C16X12G_ISR_OB 0x01
99 
105 #define C16X12G_CR_SYNC_MASTER 0x40
106 #define C16X12G_CR_SYNC_SLAVE 0x80
107 #define C16X12G_CR_OSD 0x04
108 #define C16X12G_CR_BEN 0x02
109 #define C16X12G_CR_SSD 0x01
110 #define C16X12G_LEDONOFF 0x0000
111 #define C16X12G_LEDOPEN 0x0018
112 #define C16X12G_LEDSHORT 0x0030
113 #define C16X12G_LEDPWM 0x0100
114 #define C16X12G_LEDABM 0x0200
115 #define C16X12G_CR 0x0300
116 #define C16X12G_GCC 0x0301
117 #define C16X12G_ABM1 0x0302
118 #define C16X12G_ABM2 0x0306
119 #define C16X12G_ABM3 0x030A
120 #define C16X12G_TUR 0x030E
121 #define C16X12G_SWPUR 0x030F
122 #define C16X12G_CSPDR 0x0310
123 #define C16X12G_RESET 0x0311
124 
130 #define C16X12G_CS 16
131 #define C16X12G_SW 12
132 #define C16X12G_GND_ADDR 0x00
133 #define C16X12G_SCL_ADDR 0x01
134 #define C16X12G_SDA_ADDR 0x02
135 #define C16X12G_VCC_ADDR 0x03
136 #define C16X12G_ABM_LOOP_TIMES_MAX 0x0FFF
137 #define C16X12G_ABM_LOOP_FOREVER 0x0000
138 
144 #define C16X12G_LED_STATE_OFF 0x00
145 #define C16X12G_LED_STATE_ON 0x01
146 
152 #define C16X12G_CONTINUE_SETTINGS 0x00
153 #define C16X12G_STOP_SETTINGS 0x01
154 
160 #define C16X12G_LED_STATUS_NORMAL 0x00
161 #define C16X12G_LED_STATUS_OPEN 0x01
162 #define C16X12G_LED_STATUS_SHORT 0x02
163 #define C16X12G_LED_STATUS_UNKNOWN 0x03
164 
170 #define C16X12G_RESISTOR_OFF 0x00
171 #define C16X12G_RESISTOR_500 0x01
172 #define C16X12G_RESISTOR_1K 0x02
173 #define C16X12G_RESISTOR_2K 0x03
174 #define C16X12G_RESISTOR_4K 0x04
175 #define C16X12G_RESISTOR_8K 0x05
176 #define C16X12G_RESISTOR_16K 0x06
177 #define C16X12G_RESISTOR_32K 0x07
178 
184 #define C16X12G_LED_MODE_PWM 0x00
185 #define C16X12G_LED_MODE_ABM1 0x01
186 #define C16X12G_LED_MODE_ABM2 0x02
187 #define C16X12G_LED_MODE_ABM3 0x03
188 
194 #define C16X12G_ABM_T1_210MS 0x00
195 #define C16X12G_ABM_T1_420MS 0x20
196 #define C16X12G_ABM_T1_840MS 0x40
197 #define C16X12G_ABM_T1_1680MS 0x60
198 #define C16X12G_ABM_T1_3360MS 0x80
199 #define C16X12G_ABM_T1_6720MS 0xA0
200 #define C16X12G_ABM_T1_13440MS 0xC0
201 #define C16X12G_ABM_T1_26880MS 0xE0
202 
208 #define C16X12G_ABM_T2_0MS 0x00
209 #define C16X12G_ABM_T2_210MS 0x02
210 #define C16X12G_ABM_T2_420MS 0x04
211 #define C16X12G_ABM_T2_840MS 0x06
212 #define C16X12G_ABM_T2_1680MS 0x08
213 #define C16X12G_ABM_T2_3360MS 0x0A
214 #define C16X12G_ABM_T2_6720MS 0x0C
215 #define C16X12G_ABM_T2_13440MS 0x0E
216 #define C16X12G_ABM_T2_26880MS 0x10
217 
223 #define C16X12G_ABM_T3_210MS 0x00
224 #define C16X12G_ABM_T3_420MS 0x20
225 #define C16X12G_ABM_T3_840MS 0x40
226 #define C16X12G_ABM_T3_1680MS 0x60
227 #define C16X12G_ABM_T3_3360MS 0x80
228 #define C16X12G_ABM_T3_6720MS 0xA0
229 #define C16X12G_ABM_T3_13440MS 0xC0
230 #define C16X12G_ABM_T3_26880MS 0xE0
231 
237 #define C16X12G_ABM_T4_0MS 0x00
238 #define C16X12G_ABM_T4_210MS 0x02
239 #define C16X12G_ABM_T4_420MS 0x04
240 #define C16X12G_ABM_T4_840MS 0x06
241 #define C16X12G_ABM_T4_1680MS 0x08
242 #define C16X12G_ABM_T4_3360MS 0x0A
243 #define C16X12G_ABM_T4_6720MS 0x0C
244 #define C16X12G_ABM_T4_13440MS 0x0E
245 #define C16X12G_ABM_T4_26880MS 0x10
246 #define C16X12G_ABM_T4_53760MS 0x12
247 #define C16X12G_ABM_T4_107520MS 0x14
248 
254 #define C16X12G_ABM_LOOP_BEGIN_T1 0x00
255 #define C16X12G_ABM_LOOP_BEGIN_T2 0x10
256 #define C16X12G_ABM_LOOP_BEGIN_T3 0x20
257 #define C16X12G_ABM_LOOP_BEGIN_T4 0x30
258 
264 #define C16X12G_ABM_LOOP_END_T3 0x00
265 #define C16X12G_ABM_LOOP_END_T1 0x40
266 
272 #define C16X12G_ABM_NUM_1 0x0302
273 #define C16X12G_ABM_NUM_2 0x0306
274 #define C16X12G_ABM_NUM_3 0x030A
275  // End group macro
278 
279 // --------------------------------------------------------------- PUBLIC TYPES
288 typedef struct
289 {
290  // Output pins
291 
292  digital_out_t rst;
293  digital_out_t sdb;
294 
295  // Input pins
296 
297  digital_in_t int_pin;
298 
299  // Modules
300 
301  i2c_master_t i2c;
302 
303  // ctx variable
304 
305  uint8_t slave_address;
306 
307 } c16x12_t;
308 
312 typedef struct
313 {
314  // Communication gpio pins
315 
316  pin_name_t scl;
317  pin_name_t sda;
318 
319  // Additional gpio pins
320 
321  pin_name_t rst;
322  pin_name_t sdb;
323  pin_name_t int_pin;
324 
325  // static variable
326 
327  uint32_t i2c_speed;
328  uint8_t i2c_address;
329 
330 } c16x12_cfg_t;
331 
335 typedef struct
336 {
337  uint8_t time_1;
338  uint8_t time_2;
339  uint8_t time_3;
340  uint8_t time_4;
341  uint8_t loop_begin;
342  uint8_t loop_end;
343  uint16_t loop_times;
344 
345 }c16x12_abm_t;
346  // End types group
348 
349 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
350 
356 #ifdef __cplusplus
357 extern "C"{
358 #endif
359 
369 
379 
388 
399 void c16x12_generic_write ( c16x12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
400 
411 void c16x12_generic_read ( c16x12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
412 
420 void c16x12g_write_reg ( c16x12_t *ctx, uint8_t reg, uint8_t c_data );
421 
428 void c16x12g_select_page ( c16x12_t *ctx, uint8_t page );
429 
439 void c16x12g_write_page_byte ( c16x12_t *ctx, uint16_t reg_addr, uint8_t reg_value );
440 
451 void c16x12g_write_page_data ( c16x12_t *ctx, uint16_t reg, uint8_t *data_buf, uint8_t n_data );
452 
460 uint8_t c16x12g_read_reg ( c16x12_t *ctx, uint8_t reg );
461 
468 void c16x12g_set_stand_by ( c16x12_t *ctx, uint8_t state );
469 
476 
485 
496 
505 void c16x12g_set_all_leds ( c16x12_t *ctx, uint8_t state );
506 
514 void c16x12g_set_global_current_control ( c16x12_t *ctx, uint8_t gcc );
515 
522 
534 void c16x12g_set_column_state ( c16x12_t *ctx, uint8_t col, uint16_t state, uint8_t c_end );
535 
551 void c16x12g_set_leds_mode ( c16x12_t *ctx, uint8_t mode );
552 
559 void c16x12g_set_pmw ( c16x12_t *ctx, uint8_t pwm_value );
560 
575 void c16x12g_set_led ( c16x12_t *ctx, uint8_t x_pos, uint8_t y_pos, uint8_t state, uint8_t c_end );
576 
584 void c16x12g_display_byte ( c16x12_t *ctx, char ch );
585 
593 void c16x12g_display_image ( c16x12_t *ctx, uint16_t *p_image );
594 
604 void c16x12g_display_text ( c16x12_t *ctx, char *p_text, uint8_t n_char, uint8_t speed );
605 
614 void c16x12g_config_abm ( c16x12_t *ctx, uint16_t n_abm, c16x12_abm_t *config );
615 
624 
625 
626 
627 #ifdef __cplusplus
628 }
629 #endif
630 #endif // _C16X12_H_
631  // End public_function group
634 
635 // ------------------------------------------------------------------------- END
c16x12_t::int_pin
digital_in_t int_pin
Definition: c16x12.h:297
c16x12g_set_leds_mode
void c16x12g_set_leds_mode(c16x12_t *ctx, uint8_t mode)
Functions for sets LEDs mode.
c16x12g_config_abm
void c16x12g_config_abm(c16x12_t *ctx, uint16_t n_abm, c16x12_abm_t *config)
Functions for ABM configuration.
c16x12g_clear_display
void c16x12g_clear_display(c16x12_t *ctx)
Functions for clear display.
c16x12_t::rst
digital_out_t rst
Definition: c16x12.h:292
c16x12_abm_t::time_1
uint8_t time_1
Definition: c16x12.h:337
c16x12_cfg_t::scl
pin_name_t scl
Definition: c16x12.h:316
c16x12_abm_t::loop_end
uint8_t loop_end
Definition: c16x12.h:342
c16x12g_write_page_data
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.
c16x12_generic_read
void c16x12_generic_read(c16x12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
c16x12_abm_t
ABM structure definition.
Definition: c16x12.h:336
c16x12_t::sdb
digital_out_t sdb
Definition: c16x12.h:293
c16x12_abm_t::time_3
uint8_t time_3
Definition: c16x12.h:339
c16x12_abm_t::loop_times
uint16_t loop_times
Definition: c16x12.h:343
c16x12g_read_reg
uint8_t c16x12g_read_reg(c16x12_t *ctx, uint8_t reg)
Functions for read byte from register.
c16x12g_write_page_byte
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.
c16x12g_device_configuration
void c16x12g_device_configuration(c16x12_t *ctx)
Functions for device configuration.
c16x12g_display_byte
void c16x12g_display_byte(c16x12_t *ctx, char ch)
Functions for display one Byte.
c16x12g_set_led
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.
c16x12_cfg_t::i2c_address
uint8_t i2c_address
Definition: c16x12.h:328
c16x12g_select_page
void c16x12g_select_page(c16x12_t *ctx, uint8_t page)
Functions for select page.
c16x12_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c16x12.h:327
c16x12_cfg_t
Click configuration structure definition.
Definition: c16x12.h:313
c16x12g_display_text
void c16x12g_display_text(c16x12_t *ctx, char *p_text, uint8_t n_char, uint8_t speed)
Functions for display text with scroll.
c16x12g_set_pmw
void c16x12g_set_pmw(c16x12_t *ctx, uint8_t pwm_value)
Functions for sets PWM for all LEDs.
c16x12_cfg_setup
void c16x12_cfg_setup(c16x12_cfg_t *cfg)
Config Object Initialization function.
c16x12g_set_global_current_control
void c16x12g_set_global_current_control(c16x12_t *ctx, uint8_t gcc)
Functions for sets global current for all leds.
c16x12g_set_stand_by
void c16x12g_set_stand_by(c16x12_t *ctx, uint8_t state)
Functions for sets SDB pin state.
c16x12_t::i2c
i2c_master_t i2c
Definition: c16x12.h:301
c16x12_generic_write
void c16x12_generic_write(c16x12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
c16x12g_set_all_leds
void c16x12g_set_all_leds(c16x12_t *ctx, uint8_t state)
Functions for sets all LEDs on the state.
c16x12_cfg_t::sdb
pin_name_t sdb
Definition: c16x12.h:322
c16x12g_device_reset
void c16x12g_device_reset(c16x12_t *ctx)
Functions for device reset.
c16x12_init
C16X12_RETVAL c16x12_init(c16x12_t *ctx, c16x12_cfg_t *cfg)
Initialization function.
c16x12_cfg_t::int_pin
pin_name_t int_pin
Definition: c16x12.h:323
c16x12_t::slave_address
uint8_t slave_address
Definition: c16x12.h:305
c16x12g_display_image
void c16x12g_display_image(c16x12_t *ctx, uint16_t *p_image)
Functions for display Image.
c16x12g_write_reg
void c16x12g_write_reg(c16x12_t *ctx, uint8_t reg, uint8_t c_data)
Functions for write one byte in register.
C16X12_RETVAL
#define C16X12_RETVAL
Definition: c16x12.h:74
c16x12_cfg_t::sda
pin_name_t sda
Definition: c16x12.h:317
c16x12_default_cfg
void c16x12_default_cfg(c16x12_t *ctx)
Click Default Configuration function.
c16x12_abm_t::loop_begin
uint8_t loop_begin
Definition: c16x12.h:341
c16x12_abm_t::time_4
uint8_t time_4
Definition: c16x12.h:340
c16x12_t
Click ctx object definition.
Definition: c16x12.h:289
c16x12g_start_abm
void c16x12g_start_abm(c16x12_t *ctx)
Functions for start new ABM configuration.
c16x12_cfg_t::rst
pin_name_t rst
Definition: c16x12.h:321
c16x12g_get_interrupt
uint8_t c16x12g_get_interrupt(c16x12_t *ctx)
Functions for reads interrupt state.
c16x12g_set_column_state
void c16x12g_set_column_state(c16x12_t *ctx, uint8_t col, uint16_t state, uint8_t c_end)
Functions for sets column state.
c16x12_abm_t::time_2
uint8_t time_2
Definition: c16x12.h:338