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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define C16X9_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.sdb = MIKROBUS( mikrobus, MIKROBUS_CS ); \
56  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
57 
63 #define C16X9_RETVAL uint8_t
64 
65 #define C16X9_OK 0x00
66 #define C16X9_INIT_ERROR 0xFF
67 
73 #define C16X9_SLAVE_ADDRESS 0x74
74 
80 #define C16X9_POINT_TO_PAGE_ONE 0x00
81 #define C16X9_POINT_TO_PAGE_TWO 0x01
82 #define C16X9_POINT_TO_PAGE_THREE 0x02
83 #define C16X9_POINT_TO_PAGE_FOUR 0x03
84 #define C16X9_POINT_TO_PAGE_FIVE 0x04
85 #define C16X9_POINT_TO_PAGE_SIX 0x05
86 #define C16X9_POINT_TO_PAGE_SEVEN 0x06
87 #define C16X9_POINT_TO_PAGE_EIGHT 0x07
88 #define C16X9_POINT_TO_PAGE_NINE 0x0B
89 
95 #define C16X9_REG_CONFIG 0x00
96 #define C16X9_REG_PICTURE_DISPLAY 0x01
97 #define C16X9_REG_AUTO_PLAY_CTRL1 0x02
98 #define C16X9_REG_AUTO_PLAY_CTRL2 0x03
99 #define C16X9_REG_DISPLAY_OPTION 0x05
100 #define C16X9_REG_AUDIO_SYNC 0x06
101 #define C16X9_REG_FRAME_STATE 0x07
102 #define C16X9_REG_BREATH_CTRL1 0x08
103 #define C16X9_REG_BREATH_CTRL2 0x09
104 #define C16X9_REG_SHUTDOWN 0x0A
105 #define C16X9_REG_AGC_CTRL 0x0B
106 #define C16X9_REG_AUDIO_ADC_RATE 0x0C
107 #define C16X9_REG_COMMAND 0xFD
108 
114 #define C16X9_CFG_PICTURE_MODE 0x00
115 #define C16X9_CFG_AUTO_FRAME_PLAY_MODE 0x08
116 
122 #define C16X9_AP_CTRL1_PLAY_ENDLESS 0x00
123 #define C16X9_AP_CTRL1_LOOP_1 0x10
124 #define C16X9_AP_CTRL1_LOOP_2 0x20
125 #define C16X9_AP_CTRL1_LOOP_3 0x30
126 #define C16X9_AP_CTRL1_LOOP_4 0x40
127 #define C16X9_AP_CTRL1_LOOP_5 0x50
128 #define C16X9_AP_CTRL1_LOOP_6 0x60
129 #define C16X9_AP_CTRL1_LOOP_7 0x70
130 #define C16X9_AP_CTRL1_ALL_FRAME 0x00
131 #define C16X9_AP_CTRL1_FRAME_1 0x01
132 #define C16X9_AP_CTRL1_FRAME_2 0x02
133 #define C16X9_AP_CTRL1_FRAME_3 0x03
134 #define C16X9_AP_CTRL1_FRAME_4 0x04
135 #define C16X9_AP_CTRL1_FRAME_5 0x05
136 #define C16X9_AP_CTRL1_FRAME_6 0x06
137 #define C16X9_AP_CTRL1_FRAME_7 0x07
138 
144 #define C16X9_SET_ONE_FRAME_INTENSITY 0x00
145 #define C16X9_SET_ALL_FRAME_INTENSITY 0x20
146 #define C16X9_BLINK_DISABLE 0x00
147 #define C16X9_BLINK_ENABLE 0x08
148 
154 #define C16X9_AUDIO_SYNCHRONIZATION_DISABLE 0x00
155 #define C16X9_AUDIO_SYNCHRONIZATION_ENABLE 0x01
156 
162 #define C16X9_SHUTDOWN_MODE 0x00
163 #define C16X9_NORMAL_OPERATION 0x01
164 
170 #define C16X9_AGC_SLOW_MODE 0x00
171 #define C16X9_AGC_FAST_MODE 0x10
172 #define C16X9_AGC_DISABLE 0x00
173 #define C16X9_AGC_ENABLE 0x08
174 #define C16X9_AGC_GAIN_0dB 0x00
175 #define C16X9_AGC_GAIN_3dB 0x01
176 #define C16X9_AGC_GAIN_6dB 0x02
177 #define C16X9_AGC_GAIN_9dB 0x03
178 #define C16X9_AGC_GAIN_12dB 0x04
179 #define C16X9_AGC_GAIN_15dB 0x05
180 #define C16X9_AGC_GAIN_18dB 0x06
181 #define C16X9_AGC_GAIN_21dB 0x07
182 
188 #define C16X9_FRAME_1 0x00
189 #define C16X9_FRAME_2 0x01
190 #define C16X9_FRAME_3 0x02
191 #define C16X9_FRAME_4 0x03
192 #define C16X9_FRAME_5 0x04
193 #define C16X9_FRAME_6 0x05
194 #define C16X9_FRAME_7 0x06
195 #define C16X9_FRAME_8 0x07
196 
202 #define C16X9_CTRL_LED 0x01
203 #define C16X9_CTRL_LED_BLINK 0x02
204  // End group macro
207 // --------------------------------------------------------------- PUBLIC TYPES
216 typedef struct
217 {
218  // Output pins
219 
220  digital_out_t sdb;
221 
222  // Input pins
223 
224  digital_in_t int_pin;
225 
226  // Modules
227 
228  i2c_master_t i2c;
229 
230  // ctx variable
231 
232  uint8_t slave_address;
233 
234 } c16x9_t;
235 
239 typedef struct
240 {
241  // Communication gpio pins
242 
243  pin_name_t scl;
244  pin_name_t sda;
245 
246  // Additional gpio pins
247 
248  pin_name_t sdb;
249  pin_name_t int_pin;
250 
251  // static variable
252 
253  uint32_t i2c_speed;
254  uint8_t i2c_address;
255 
256 } c16x9_cfg_t;
257 
261 typedef struct
262 {
263  uint8_t x; // Start coordinate x
264  uint8_t y; // Start coordinate y
265  uint8_t pwm; // PWM value
266 
268 
272 typedef struct
273 {
274  uint16_t buf[ 9 ]; // Image buffer
275  uint8_t frame; // Select frame
276  uint8_t pwm; // PWM value
277 
279 
283 typedef struct
284 {
285  char character; // Character
286  uint8_t frame; // Select frame
287  uint8_t pwm; // PWM value
288 
289 }c16x9_char_t;
290 
294 typedef struct
295 {
296  uint8_t x; // Start coordinate x
297  uint8_t y; // Start coordinate y
298  uint8_t width; // Rectangle width
299  uint8_t height; // Rectangle height
300  uint8_t frame; // Select frame
301  uint8_t pwm; // PWM value
302 
304  // End types group
306 
307 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
308 
314 #ifdef __cplusplus
315 extern "C"{
316 #endif
317 
326 void c16x9_cfg_setup ( c16x9_cfg_t *cfg );
327 
337 
348 void c16x9_generic_write ( c16x9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
349 
359 void c16x9_control_all ( c16x9_t *ctx, uint8_t ctrl, uint8_t state );
360 
369 void c16x9_fill_screen ( c16x9_t *ctx, uint8_t pwm );
370 
378 void c16x9_display_refresh ( c16x9_t *ctx );
379 
386 void c16x9_draw_point ( c16x9_t *ctx, c16x9_point_t *point );
387 
397 void c16x9_display_image ( c16x9_t *ctx, c16x9_image_t *image );
398 
406 
414 
421 uint8_t c16x9_get_interrupt_state( c16x9_t *ctx );
422 
423 #ifdef __cplusplus
424 }
425 #endif
426 #endif // _C16X9_H_
427  // End public_function group
430 
431 // ------------------------------------------------------------------------- END
#define C16X9_RETVAL
Definition: c16x9.h:63
Click configuration structure definition.
Definition: c16x9.h:239
Click ctx object definition.
Definition: c16x9.h:216
uint8_t height
Definition: c16x9.h:299
digital_out_t sdb
Definition: c16x9.h:220
uint8_t pwm
Definition: c16x9.h:287
void c16x9_generic_write(c16x9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint8_t y
Definition: c16x9.h:297
pin_name_t sdb
Definition: c16x9.h:248
pin_name_t int_pin
Definition: c16x9.h:249
Point structure definition.
Definition: c16x9.h:261
void c16x9_display_byte(c16x9_t *ctx, c16x9_char_t *data_char)
Function for displaying one character.
pin_name_t scl
Definition: c16x9.h:243
char character
Definition: c16x9.h:285
uint8_t x
Definition: c16x9.h:263
uint8_t x
Definition: c16x9.h:296
uint8_t frame
Definition: c16x9.h:300
void c16x9_draw_point(c16x9_t *ctx, c16x9_point_t *point)
Functions for draw point .
uint8_t y
Definition: c16x9.h:264
Character structure definition.
Definition: c16x9.h:283
Rectangle structure definition.
Definition: c16x9.h:294
uint8_t c16x9_get_interrupt_state(c16x9_t *ctx)
Interrupt pin state.
uint8_t slave_address
Definition: c16x9.h:232
void c16x9_draw_rectangle(c16x9_t *ctx, c16x9_rectangle_t *rectangle)
Draw rectangle.
void c16x9_display_refresh(c16x9_t *ctx)
Function for refresh display.
c16x9_rectangle_t rectangle
Definition: main.c:34
uint32_t i2c_speed
Definition: c16x9.h:253
i2c_master_t i2c
Definition: c16x9.h:228
pin_name_t sda
Definition: c16x9.h:244
C16X9_RETVAL c16x9_init(c16x9_t *ctx, c16x9_cfg_t *cfg)
Initialization function.
uint8_t pwm
Definition: c16x9.h:276
uint8_t width
Definition: c16x9.h:298
uint8_t frame
Definition: c16x9.h:275
uint8_t pwm
Definition: c16x9.h:265
uint8_t pwm
Definition: c16x9.h:301
void c16x9_control_all(c16x9_t *ctx, uint8_t ctrl, uint8_t state)
Functions for control all leds.
void c16x9_fill_screen(c16x9_t *ctx, uint8_t pwm)
Functions for fill screen.
void c16x9_display_image(c16x9_t *ctx, c16x9_image_t *image)
Image display function.
uint8_t i2c_address
Definition: c16x9.h:254
c16x9_char_t data_char
Definition: main.c:33
uint8_t frame
Definition: c16x9.h:286
digital_in_t int_pin
Definition: c16x9.h:224
Image structure definition.
Definition: c16x9.h:272
void c16x9_cfg_setup(c16x9_cfg_t *cfg)
Config Object Initialization function.