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 );
71 
77 #define C16X9_RETVAL uint8_t
78 
79 #define C16X9_OK 0x00
80 #define C16X9_INIT_ERROR 0xFF
81 
87 #define C16X9_SLAVE_ADDRESS 0x74
88 
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
103 
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
122 
128 #define C16X9_CFG_PICTURE_MODE 0x00
129 #define C16X9_CFG_AUTO_FRAME_PLAY_MODE 0x08
130 
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
152 
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
162 
168 #define C16X9_AUDIO_SYNCHRONIZATION_DISABLE 0x00
169 #define C16X9_AUDIO_SYNCHRONIZATION_ENABLE 0x01
170 
176 #define C16X9_SHUTDOWN_MODE 0x00
177 #define C16X9_NORMAL_OPERATION 0x01
178 
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
196 
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
210 
216 #define C16X9_CTRL_LED 0x01
217 #define C16X9_CTRL_LED_BLINK 0x02
218  // End group macro
221 // --------------------------------------------------------------- PUBLIC TYPES
230 typedef 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 
246  uint8_t slave_address;
247 
248 } c16x9_t;
249 
253 typedef 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 
270 } c16x9_cfg_t;
271 
275 typedef struct
276 {
277  uint8_t x; // Start coordinate x
278  uint8_t y; // Start coordinate y
279  uint8_t pwm; // PWM value
280 
282 
286 typedef struct
287 {
288  uint16_t buf[ 9 ]; // Image buffer
289  uint8_t frame; // Select frame
290  uint8_t pwm; // PWM value
291 
293 
297 typedef struct
298 {
299  char character; // Character
300  uint8_t frame; // Select frame
301  uint8_t pwm; // PWM value
302 
303 }c16x9_char_t;
304 
308 typedef 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  // End types group
320 
321 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
322 
328 #ifdef __cplusplus
329 extern "C"{
330 #endif
331 
341 
351 
362 void c16x9_generic_write ( c16x9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
363 
373 void c16x9_control_all ( c16x9_t *ctx, uint8_t ctrl, uint8_t state );
374 
383 void c16x9_fill_screen ( c16x9_t *ctx, uint8_t pwm );
384 
393 
400 void c16x9_draw_point ( c16x9_t *ctx, c16x9_point_t *point );
401 
412 
420 
428 
436 
437 #ifdef __cplusplus
438 }
439 #endif
440 #endif // _C16X9_H_
441  // End public_function group
444 
445 // ------------------------------------------------------------------------- END
c16x9_get_interrupt_state
uint8_t c16x9_get_interrupt_state(c16x9_t *ctx)
Interrupt pin state.
c16x9_t::sdb
digital_out_t sdb
Definition: c16x9.h:234
c16x9_cfg_setup
void c16x9_cfg_setup(c16x9_cfg_t *cfg)
Config Object Initialization function.
c16x9_cfg_t
Click configuration structure definition.
Definition: c16x9.h:254
c16x9_display_refresh
void c16x9_display_refresh(c16x9_t *ctx)
Function for refresh display.
c16x9_t::i2c
i2c_master_t i2c
Definition: c16x9.h:242
data_char
c16x9_char_t data_char
Definition: main.c:33
c16x9_rectangle_t::frame
uint8_t frame
Definition: c16x9.h:314
c16x9_draw_rectangle
void c16x9_draw_rectangle(c16x9_t *ctx, c16x9_rectangle_t *rectangle)
Draw rectangle.
c16x9_image_t
Image structure definition.
Definition: c16x9.h:287
c16x9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c16x9.h:267
c16x9_draw_point
void c16x9_draw_point(c16x9_t *ctx, c16x9_point_t *point)
Functions for draw point .
c16x9_point_t::y
uint8_t y
Definition: c16x9.h:278
c16x9_char_t::pwm
uint8_t pwm
Definition: c16x9.h:301
c16x9_point_t::x
uint8_t x
Definition: c16x9.h:277
c16x9_cfg_t::i2c_address
uint8_t i2c_address
Definition: c16x9.h:268
C16X9_RETVAL
#define C16X9_RETVAL
Definition: c16x9.h:77
c16x9_char_t::character
char character
Definition: c16x9.h:299
c16x9_control_all
void c16x9_control_all(c16x9_t *ctx, uint8_t ctrl, uint8_t state)
Functions for control all leds.
c16x9_cfg_t::int_pin
pin_name_t int_pin
Definition: c16x9.h:263
c16x9_char_t
Character structure definition.
Definition: c16x9.h:298
c16x9_cfg_t::sdb
pin_name_t sdb
Definition: c16x9.h:262
c16x9_point_t
Point structure definition.
Definition: c16x9.h:276
c16x9_cfg_t::scl
pin_name_t scl
Definition: c16x9.h:257
c16x9_t::slave_address
uint8_t slave_address
Definition: c16x9.h:246
c16x9_rectangle_t::height
uint8_t height
Definition: c16x9.h:313
c16x9_image_t::frame
uint8_t frame
Definition: c16x9.h:289
c16x9_generic_write
void c16x9_generic_write(c16x9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
c16x9_rectangle_t::x
uint8_t x
Definition: c16x9.h:310
c16x9_init
C16X9_RETVAL c16x9_init(c16x9_t *ctx, c16x9_cfg_t *cfg)
Initialization function.
c16x9_rectangle_t::pwm
uint8_t pwm
Definition: c16x9.h:315
rectangle
c16x9_rectangle_t rectangle
Definition: main.c:34
c16x9_image_t::pwm
uint8_t pwm
Definition: c16x9.h:290
c16x9_t::int_pin
digital_in_t int_pin
Definition: c16x9.h:238
c16x9_display_image
void c16x9_display_image(c16x9_t *ctx, c16x9_image_t *image)
Image display function.
c16x9_char_t::frame
uint8_t frame
Definition: c16x9.h:300
c16x9_display_byte
void c16x9_display_byte(c16x9_t *ctx, c16x9_char_t *data_char)
Function for displaying one character.
c16x9_cfg_t::sda
pin_name_t sda
Definition: c16x9.h:258
c16x9_rectangle_t::width
uint8_t width
Definition: c16x9.h:312
c16x9_point_t::pwm
uint8_t pwm
Definition: c16x9.h:279
c16x9_rectangle_t::y
uint8_t y
Definition: c16x9.h:311
c16x9_fill_screen
void c16x9_fill_screen(c16x9_t *ctx, uint8_t pwm)
Functions for fill screen.
c16x9_t
Click ctx object definition.
Definition: c16x9.h:231
c16x9_rectangle_t
Rectangle structure definition.
Definition: c16x9.h:309