c16x9 2.0.0.0
c16x9.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 C16X9_H
36#define C16X9_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// -------------------------------------------------------------- PUBLIC MACROS
66#define C16X9_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.sdb = MIKROBUS( mikrobus, MIKROBUS_CS ); \
70 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
77#define C16X9_RETVAL uint8_t
78
79#define C16X9_OK 0x00
80#define C16X9_INIT_ERROR 0xFF
87#define C16X9_SLAVE_ADDRESS 0x74
94#define C16X9_POINT_TO_PAGE_ONE 0x00
95#define C16X9_POINT_TO_PAGE_TWO 0x01
96#define C16X9_POINT_TO_PAGE_THREE 0x02
97#define C16X9_POINT_TO_PAGE_FOUR 0x03
98#define C16X9_POINT_TO_PAGE_FIVE 0x04
99#define C16X9_POINT_TO_PAGE_SIX 0x05
100#define C16X9_POINT_TO_PAGE_SEVEN 0x06
101#define C16X9_POINT_TO_PAGE_EIGHT 0x07
102#define C16X9_POINT_TO_PAGE_NINE 0x0B
109#define C16X9_REG_CONFIG 0x00
110#define C16X9_REG_PICTURE_DISPLAY 0x01
111#define C16X9_REG_AUTO_PLAY_CTRL1 0x02
112#define C16X9_REG_AUTO_PLAY_CTRL2 0x03
113#define C16X9_REG_DISPLAY_OPTION 0x05
114#define C16X9_REG_AUDIO_SYNC 0x06
115#define C16X9_REG_FRAME_STATE 0x07
116#define C16X9_REG_BREATH_CTRL1 0x08
117#define C16X9_REG_BREATH_CTRL2 0x09
118#define C16X9_REG_SHUTDOWN 0x0A
119#define C16X9_REG_AGC_CTRL 0x0B
120#define C16X9_REG_AUDIO_ADC_RATE 0x0C
121#define C16X9_REG_COMMAND 0xFD
128#define C16X9_CFG_PICTURE_MODE 0x00
129#define C16X9_CFG_AUTO_FRAME_PLAY_MODE 0x08
136#define C16X9_AP_CTRL1_PLAY_ENDLESS 0x00
137#define C16X9_AP_CTRL1_LOOP_1 0x10
138#define C16X9_AP_CTRL1_LOOP_2 0x20
139#define C16X9_AP_CTRL1_LOOP_3 0x30
140#define C16X9_AP_CTRL1_LOOP_4 0x40
141#define C16X9_AP_CTRL1_LOOP_5 0x50
142#define C16X9_AP_CTRL1_LOOP_6 0x60
143#define C16X9_AP_CTRL1_LOOP_7 0x70
144#define C16X9_AP_CTRL1_ALL_FRAME 0x00
145#define C16X9_AP_CTRL1_FRAME_1 0x01
146#define C16X9_AP_CTRL1_FRAME_2 0x02
147#define C16X9_AP_CTRL1_FRAME_3 0x03
148#define C16X9_AP_CTRL1_FRAME_4 0x04
149#define C16X9_AP_CTRL1_FRAME_5 0x05
150#define C16X9_AP_CTRL1_FRAME_6 0x06
151#define C16X9_AP_CTRL1_FRAME_7 0x07
158#define C16X9_SET_ONE_FRAME_INTENSITY 0x00
159#define C16X9_SET_ALL_FRAME_INTENSITY 0x20
160#define C16X9_BLINK_DISABLE 0x00
161#define C16X9_BLINK_ENABLE 0x08
168#define C16X9_AUDIO_SYNCHRONIZATION_DISABLE 0x00
169#define C16X9_AUDIO_SYNCHRONIZATION_ENABLE 0x01
176#define C16X9_SHUTDOWN_MODE 0x00
177#define C16X9_NORMAL_OPERATION 0x01
184#define C16X9_AGC_SLOW_MODE 0x00
185#define C16X9_AGC_FAST_MODE 0x10
186#define C16X9_AGC_DISABLE 0x00
187#define C16X9_AGC_ENABLE 0x08
188#define C16X9_AGC_GAIN_0dB 0x00
189#define C16X9_AGC_GAIN_3dB 0x01
190#define C16X9_AGC_GAIN_6dB 0x02
191#define C16X9_AGC_GAIN_9dB 0x03
192#define C16X9_AGC_GAIN_12dB 0x04
193#define C16X9_AGC_GAIN_15dB 0x05
194#define C16X9_AGC_GAIN_18dB 0x06
195#define C16X9_AGC_GAIN_21dB 0x07
202#define C16X9_FRAME_1 0x00
203#define C16X9_FRAME_2 0x01
204#define C16X9_FRAME_3 0x02
205#define C16X9_FRAME_4 0x03
206#define C16X9_FRAME_5 0x04
207#define C16X9_FRAME_6 0x05
208#define C16X9_FRAME_7 0x06
209#define C16X9_FRAME_8 0x07
216#define C16X9_CTRL_LED 0x01
217#define C16X9_CTRL_LED_BLINK 0x02
220 // End group macro
221// --------------------------------------------------------------- PUBLIC TYPES
230typedef struct
231{
232 // Output pins
233
234 digital_out_t sdb;
235
236 // Input pins
237
238 digital_in_t int_pin;
239
240 // Modules
241
242 i2c_master_t i2c;
243
244 // ctx variable
245
247
248} c16x9_t;
249
253typedef struct
254{
255 // Communication gpio pins
256
257 pin_name_t scl;
258 pin_name_t sda;
259
260 // Additional gpio pins
261
262 pin_name_t sdb;
263 pin_name_t int_pin;
264
265 // static variable
266
267 uint32_t i2c_speed;
268 uint8_t i2c_address;
269
271
275typedef struct
276{
277 uint8_t x; // Start coordinate x
278 uint8_t y; // Start coordinate y
279 uint8_t pwm; // PWM value
280
282
286typedef struct
287{
288 uint16_t buf[ 9 ]; // Image buffer
289 uint8_t frame; // Select frame
290 uint8_t pwm; // PWM value
291
293
297typedef struct
298{
299 char character; // Character
300 uint8_t frame; // Select frame
301 uint8_t pwm; // PWM value
302
304
308typedef struct
309{
310 uint8_t x; // Start coordinate x
311 uint8_t y; // Start coordinate y
312 uint8_t width; // Rectangle width
313 uint8_t height; // Rectangle height
314 uint8_t frame; // Select frame
315 uint8_t pwm; // PWM value
316
318
319 // End types group
320
321// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
322
328#ifdef __cplusplus
329extern "C"{
330#endif
331
341
351
362void c16x9_generic_write ( c16x9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
363
373void c16x9_control_all ( c16x9_t *ctx, uint8_t ctrl, uint8_t state );
374
383void c16x9_fill_screen ( c16x9_t *ctx, uint8_t pwm );
384
393
401
412
420
428
436
437#ifdef __cplusplus
438}
439#endif
440#endif // _C16X9_H_
441
442 // End public_function group
444
445// ------------------------------------------------------------------------- END
#define C16X9_RETVAL
Definition c16x9.h:77
void c16x9_cfg_setup(c16x9_cfg_t *cfg)
Config Object Initialization function.
void c16x9_generic_write(c16x9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void c16x9_control_all(c16x9_t *ctx, uint8_t ctrl, uint8_t state)
Functions for control all leds.
uint8_t c16x9_get_interrupt_state(c16x9_t *ctx)
Interrupt pin state.
void c16x9_display_refresh(c16x9_t *ctx)
Function for refresh display.
void c16x9_fill_screen(c16x9_t *ctx, uint8_t pwm)
Functions for fill screen.
void c16x9_draw_point(c16x9_t *ctx, c16x9_point_t *point)
Functions for draw point .
void c16x9_draw_rectangle(c16x9_t *ctx, c16x9_rectangle_t *rectangle)
Draw rectangle.
C16X9_RETVAL c16x9_init(c16x9_t *ctx, c16x9_cfg_t *cfg)
Initialization function.
void c16x9_display_byte(c16x9_t *ctx, c16x9_char_t *data_char)
Function for displaying one character.
void c16x9_display_image(c16x9_t *ctx, c16x9_image_t *image)
Image display function.
c16x9_rectangle_t rectangle
Definition main.c:34
c16x9_char_t data_char
Definition main.c:33
Click configuration structure definition.
Definition c16x9.h:254
pin_name_t sdb
Definition c16x9.h:262
uint32_t i2c_speed
Definition c16x9.h:267
pin_name_t scl
Definition c16x9.h:257
pin_name_t int_pin
Definition c16x9.h:263
pin_name_t sda
Definition c16x9.h:258
uint8_t i2c_address
Definition c16x9.h:268
Character structure definition.
Definition c16x9.h:298
uint8_t frame
Definition c16x9.h:300
uint8_t pwm
Definition c16x9.h:301
char character
Definition c16x9.h:299
Image structure definition.
Definition c16x9.h:287
uint8_t frame
Definition c16x9.h:289
uint8_t pwm
Definition c16x9.h:290
Point structure definition.
Definition c16x9.h:276
uint8_t x
Definition c16x9.h:277
uint8_t y
Definition c16x9.h:278
uint8_t pwm
Definition c16x9.h:279
Rectangle structure definition.
Definition c16x9.h:309
uint8_t width
Definition c16x9.h:312
uint8_t x
Definition c16x9.h:310
uint8_t y
Definition c16x9.h:311
uint8_t frame
Definition c16x9.h:314
uint8_t pwm
Definition c16x9.h:315
uint8_t height
Definition c16x9.h:313
Click ctx object definition.
Definition c16x9.h:231
digital_in_t int_pin
Definition c16x9.h:238
i2c_master_t i2c
Definition c16x9.h:242
digital_out_t sdb
Definition c16x9.h:234
uint8_t slave_address
Definition c16x9.h:246