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 
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 C16X9_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.sdb = MIKROBUS( mikrobus, MIKROBUS_CS ); \
66  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
67 
73 #define C16X9_RETVAL uint8_t
74 
75 #define C16X9_OK 0x00
76 #define C16X9_INIT_ERROR 0xFF
77 
83 #define C16X9_SLAVE_ADDRESS 0x74
84 
90 #define C16X9_POINT_TO_PAGE_ONE 0x00
91 #define C16X9_POINT_TO_PAGE_TWO 0x01
92 #define C16X9_POINT_TO_PAGE_THREE 0x02
93 #define C16X9_POINT_TO_PAGE_FOUR 0x03
94 #define C16X9_POINT_TO_PAGE_FIVE 0x04
95 #define C16X9_POINT_TO_PAGE_SIX 0x05
96 #define C16X9_POINT_TO_PAGE_SEVEN 0x06
97 #define C16X9_POINT_TO_PAGE_EIGHT 0x07
98 #define C16X9_POINT_TO_PAGE_NINE 0x0B
99 
105 #define C16X9_REG_CONFIG 0x00
106 #define C16X9_REG_PICTURE_DISPLAY 0x01
107 #define C16X9_REG_AUTO_PLAY_CTRL1 0x02
108 #define C16X9_REG_AUTO_PLAY_CTRL2 0x03
109 #define C16X9_REG_DISPLAY_OPTION 0x05
110 #define C16X9_REG_AUDIO_SYNC 0x06
111 #define C16X9_REG_FRAME_STATE 0x07
112 #define C16X9_REG_BREATH_CTRL1 0x08
113 #define C16X9_REG_BREATH_CTRL2 0x09
114 #define C16X9_REG_SHUTDOWN 0x0A
115 #define C16X9_REG_AGC_CTRL 0x0B
116 #define C16X9_REG_AUDIO_ADC_RATE 0x0C
117 #define C16X9_REG_COMMAND 0xFD
118 
124 #define C16X9_CFG_PICTURE_MODE 0x00
125 #define C16X9_CFG_AUTO_FRAME_PLAY_MODE 0x08
126 
132 #define C16X9_AP_CTRL1_PLAY_ENDLESS 0x00
133 #define C16X9_AP_CTRL1_LOOP_1 0x10
134 #define C16X9_AP_CTRL1_LOOP_2 0x20
135 #define C16X9_AP_CTRL1_LOOP_3 0x30
136 #define C16X9_AP_CTRL1_LOOP_4 0x40
137 #define C16X9_AP_CTRL1_LOOP_5 0x50
138 #define C16X9_AP_CTRL1_LOOP_6 0x60
139 #define C16X9_AP_CTRL1_LOOP_7 0x70
140 #define C16X9_AP_CTRL1_ALL_FRAME 0x00
141 #define C16X9_AP_CTRL1_FRAME_1 0x01
142 #define C16X9_AP_CTRL1_FRAME_2 0x02
143 #define C16X9_AP_CTRL1_FRAME_3 0x03
144 #define C16X9_AP_CTRL1_FRAME_4 0x04
145 #define C16X9_AP_CTRL1_FRAME_5 0x05
146 #define C16X9_AP_CTRL1_FRAME_6 0x06
147 #define C16X9_AP_CTRL1_FRAME_7 0x07
148 
154 #define C16X9_SET_ONE_FRAME_INTENSITY 0x00
155 #define C16X9_SET_ALL_FRAME_INTENSITY 0x20
156 #define C16X9_BLINK_DISABLE 0x00
157 #define C16X9_BLINK_ENABLE 0x08
158 
164 #define C16X9_AUDIO_SYNCHRONIZATION_DISABLE 0x00
165 #define C16X9_AUDIO_SYNCHRONIZATION_ENABLE 0x01
166 
172 #define C16X9_SHUTDOWN_MODE 0x00
173 #define C16X9_NORMAL_OPERATION 0x01
174 
180 #define C16X9_AGC_SLOW_MODE 0x00
181 #define C16X9_AGC_FAST_MODE 0x10
182 #define C16X9_AGC_DISABLE 0x00
183 #define C16X9_AGC_ENABLE 0x08
184 #define C16X9_AGC_GAIN_0dB 0x00
185 #define C16X9_AGC_GAIN_3dB 0x01
186 #define C16X9_AGC_GAIN_6dB 0x02
187 #define C16X9_AGC_GAIN_9dB 0x03
188 #define C16X9_AGC_GAIN_12dB 0x04
189 #define C16X9_AGC_GAIN_15dB 0x05
190 #define C16X9_AGC_GAIN_18dB 0x06
191 #define C16X9_AGC_GAIN_21dB 0x07
192 
198 #define C16X9_FRAME_1 0x00
199 #define C16X9_FRAME_2 0x01
200 #define C16X9_FRAME_3 0x02
201 #define C16X9_FRAME_4 0x03
202 #define C16X9_FRAME_5 0x04
203 #define C16X9_FRAME_6 0x05
204 #define C16X9_FRAME_7 0x06
205 #define C16X9_FRAME_8 0x07
206 
212 #define C16X9_CTRL_LED 0x01
213 #define C16X9_CTRL_LED_BLINK 0x02
214  // End group macro
217 // --------------------------------------------------------------- PUBLIC TYPES
226 typedef struct
227 {
228  // Output pins
229 
230  digital_out_t sdb;
231 
232  // Input pins
233 
234  digital_in_t int_pin;
235 
236  // Modules
237 
238  i2c_master_t i2c;
239 
240  // ctx variable
241 
242  uint8_t slave_address;
243 
244 } c16x9_t;
245 
249 typedef struct
250 {
251  // Communication gpio pins
252 
253  pin_name_t scl;
254  pin_name_t sda;
255 
256  // Additional gpio pins
257 
258  pin_name_t sdb;
259  pin_name_t int_pin;
260 
261  // static variable
262 
263  uint32_t i2c_speed;
264  uint8_t i2c_address;
265 
266 } c16x9_cfg_t;
267 
271 typedef struct
272 {
273  uint8_t x; // Start coordinate x
274  uint8_t y; // Start coordinate y
275  uint8_t pwm; // PWM value
276 
278 
282 typedef struct
283 {
284  uint16_t buf[ 9 ]; // Image buffer
285  uint8_t frame; // Select frame
286  uint8_t pwm; // PWM value
287 
289 
293 typedef struct
294 {
295  char character; // Character
296  uint8_t frame; // Select frame
297  uint8_t pwm; // PWM value
298 
299 }c16x9_char_t;
300 
304 typedef struct
305 {
306  uint8_t x; // Start coordinate x
307  uint8_t y; // Start coordinate y
308  uint8_t width; // Rectangle width
309  uint8_t height; // Rectangle height
310  uint8_t frame; // Select frame
311  uint8_t pwm; // PWM value
312 
314  // End types group
316 
317 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
318 
324 #ifdef __cplusplus
325 extern "C"{
326 #endif
327 
337 
347 
358 void c16x9_generic_write ( c16x9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
359 
369 void c16x9_control_all ( c16x9_t *ctx, uint8_t ctrl, uint8_t state );
370 
379 void c16x9_fill_screen ( c16x9_t *ctx, uint8_t pwm );
380 
389 
396 void c16x9_draw_point ( c16x9_t *ctx, c16x9_point_t *point );
397 
408 
416 
424 
432 
433 #ifdef __cplusplus
434 }
435 #endif
436 #endif // _C16X9_H_
437  // End public_function group
440 
441 // ------------------------------------------------------------------------- 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:230
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:250
c16x9_display_refresh
void c16x9_display_refresh(c16x9_t *ctx)
Function for refresh display.
c16x9_t::i2c
i2c_master_t i2c
Definition: c16x9.h:238
data_char
c16x9_char_t data_char
Definition: main.c:33
c16x9_rectangle_t::frame
uint8_t frame
Definition: c16x9.h:310
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:283
c16x9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c16x9.h:263
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:274
c16x9_char_t::pwm
uint8_t pwm
Definition: c16x9.h:297
c16x9_point_t::x
uint8_t x
Definition: c16x9.h:273
c16x9_cfg_t::i2c_address
uint8_t i2c_address
Definition: c16x9.h:264
C16X9_RETVAL
#define C16X9_RETVAL
Definition: c16x9.h:73
c16x9_char_t::character
char character
Definition: c16x9.h:295
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:259
c16x9_char_t
Character structure definition.
Definition: c16x9.h:294
c16x9_cfg_t::sdb
pin_name_t sdb
Definition: c16x9.h:258
c16x9_point_t
Point structure definition.
Definition: c16x9.h:272
c16x9_cfg_t::scl
pin_name_t scl
Definition: c16x9.h:253
c16x9_t::slave_address
uint8_t slave_address
Definition: c16x9.h:242
c16x9_rectangle_t::height
uint8_t height
Definition: c16x9.h:309
c16x9_image_t::frame
uint8_t frame
Definition: c16x9.h:285
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:306
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:311
rectangle
c16x9_rectangle_t rectangle
Definition: main.c:34
c16x9_image_t::pwm
uint8_t pwm
Definition: c16x9.h:286
c16x9_t::int_pin
digital_in_t int_pin
Definition: c16x9.h:234
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:296
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:254
c16x9_rectangle_t::width
uint8_t width
Definition: c16x9.h:308
c16x9_point_t::pwm
uint8_t pwm
Definition: c16x9.h:275
c16x9_rectangle_t::y
uint8_t y
Definition: c16x9.h:307
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:227
c16x9_rectangle_t
Rectangle structure definition.
Definition: c16x9.h:305