dmx  2.0.0.0
dmx.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 DMX_H
36 #define DMX_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_uart.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define DMX_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
68  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
69  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70  cfg.abr = MIKROBUS( mikrobus, MIKROBUS_CS ); \
71  cfg.run = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
72  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
73 
79 #define DMX_OK 0
80 #define DMX_ERROR -1
81 #define DMX_ERROR_TIMEOUT -2
82 
88 #define DMX_RSP_OK "OK"
89 #define DMX_RSP_ERROR "ERR"
90 
96 #define DMX_CMD_SADR "@SADR,001\0"
97 #define DMX_CMD_BLEN "@BLEN,006\0"
98 #define DMX_CMD_ITMR "@ITMR,001\0"
99 #define DMX_CMD_FTMR "@FTMR,001\0"
100 #define DMX_CMD_FLEN_MASTER "@FLEN,010\0"
101 #define DMX_CMD_FLEN_SLAVE "@FLEN,006\0"
102 #define DMX_CMD_SCOD "@SCOD,000\0"
103 #define DMX_CMD_PURGEBFR "!PURGEBFR\0"
104 #define DMX_CMD_STORECFG "!STORECFG\0"
105 #define DMX_CMD_CLEARCFG "!CLEARCFG\0"
106 #define DMX_CMD_DISPLCFG "!DISPLCFG\0"
107 
113 #define DMX_SLAVE 0
114 #define DMX_MASTER 1
115 #define DMX_CONFIG_MODE 0
116 #define DMX_RUN_MODE 1
117 #define DMX_INT_INACTIVE 0
118 #define DMX_INT_ACTIVE 1
119 
125 #define DMX_DRV_RX_BUFFER_SIZE 300
126 #define DMX_DRV_TX_BUFFER_SIZE 100
127  // End group macro
130 // --------------------------------------------------------------- PUBLIC TYPES
138 typedef struct
139 {
140  // Output pins
141  digital_out_t rst;
142  digital_out_t abr;
143  digital_out_t run;
144 
145  // Input pins
146  digital_in_t int_pin;
147 
148  // Modules
149  uart_t uart;
150 
151  uint8_t uart_rx_buffer[ DMX_DRV_RX_BUFFER_SIZE ];
152  uint8_t uart_tx_buffer[ DMX_DRV_TX_BUFFER_SIZE ];
153 
154 } dmx_t;
155 
159 typedef struct
160 {
161  // Communication gpio pins
162  pin_name_t rx_pin;
163  pin_name_t tx_pin;
164 
165  // Additional gpio pins
166  pin_name_t rst;
167  pin_name_t abr;
168  pin_name_t run;
169  pin_name_t int_pin;
170 
171  // static variable
172  uint32_t baud_rate; // Clock speed.
174  uart_data_bits_t data_bit; // Data bits.
175  uart_parity_t parity_bit; // Parity bit.
176  uart_stop_bits_t stop_bit; // Stop bits.
177 
178 } dmx_cfg_t;
179  // End types group
181 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
182 
188 #ifdef __cplusplus
189 extern "C"{
190 #endif
191 
200 void dmx_cfg_setup ( dmx_cfg_t *cfg );
201 
210 err_t dmx_init ( dmx_t *ctx, dmx_cfg_t *cfg );
211 
216 void dmx_reset ( dmx_t *ctx, uint8_t dev_mode );
217 
224 void dmx_generic_write ( dmx_t *ctx, uint8_t *data_buf, uint16_t len );
225 
233 err_t dmx_generic_read ( dmx_t *ctx, uint8_t *data_buf, uint16_t max_len );
234 
240 void dmx_send_cmd ( dmx_t* ctx, uint8_t *cmd );
241 
250 void dmx_run ( dmx_t *ctx, uint8_t run_mode );
251 
259 uint8_t dmx_check_int ( dmx_t *ctx );
260 
268 void dmx_set_reset ( dmx_t *ctx, uint8_t state );
269 
278 void dmx_set_auto_baud_rate ( dmx_t *ctx, uint8_t state );
279 
280 #ifdef __cplusplus
281 }
282 #endif
283 #endif // _DMX_H_
284  // End public_function group
287 
288 // ------------------------------------------------------------------------- END
dmx_cfg_setup
void dmx_cfg_setup(dmx_cfg_t *cfg)
Config Object Initialization function.
dmx_check_int
uint8_t dmx_check_int(dmx_t *ctx)
Interrupt Check function.
dmx_cfg_t::uart_blocking
bool uart_blocking
Definition: dmx.h:173
dmx_cfg_t::tx_pin
pin_name_t tx_pin
Definition: dmx.h:163
dmx_t::run
digital_out_t run
Definition: dmx.h:143
dmx_t::int_pin
digital_in_t int_pin
Definition: dmx.h:146
dmx_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: dmx.h:176
dmx_t::rst
digital_out_t rst
Definition: dmx.h:141
dmx_t::uart
uart_t uart
Definition: dmx.h:149
dmx_cfg_t::abr
pin_name_t abr
Definition: dmx.h:167
dmx_send_cmd
void dmx_send_cmd(dmx_t *ctx, uint8_t *cmd)
Send command function.
dmx_cfg_t::baud_rate
uint32_t baud_rate
Definition: dmx.h:172
dmx_set_auto_baud_rate
void dmx_set_auto_baud_rate(dmx_t *ctx, uint8_t state)
Auto Baud Rate Setting function.
dmx_init
err_t dmx_init(dmx_t *ctx, dmx_cfg_t *cfg)
Initialization function.
dmx_t
Click ctx object definition.
Definition: dmx.h:139
dmx_cfg_t::rst
pin_name_t rst
Definition: dmx.h:166
DMX_DRV_TX_BUFFER_SIZE
#define DMX_DRV_TX_BUFFER_SIZE
Definition: dmx.h:126
dmx_generic_read
err_t dmx_generic_read(dmx_t *ctx, uint8_t *data_buf, uint16_t max_len)
Generic read function.
DMX_DRV_RX_BUFFER_SIZE
#define DMX_DRV_RX_BUFFER_SIZE
Definition: dmx.h:125
dmx_t::abr
digital_out_t abr
Definition: dmx.h:142
dmx_reset
void dmx_reset(dmx_t *ctx, uint8_t dev_mode)
Reset function.
dmx_cfg_t::int_pin
pin_name_t int_pin
Definition: dmx.h:169
dmx_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: dmx.h:174
dmx_cfg_t::rx_pin
pin_name_t rx_pin
Definition: dmx.h:162
dmx_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: dmx.h:175
dmx_run
void dmx_run(dmx_t *ctx, uint8_t run_mode)
Mode Setting function.
dmx_generic_write
void dmx_generic_write(dmx_t *ctx, uint8_t *data_buf, uint16_t len)
Generic write function.
dmx_set_reset
void dmx_set_reset(dmx_t *ctx, uint8_t state)
Reset Setting function.
dmx_cfg_t::run
pin_name_t run
Definition: dmx.h:168
dmx_cfg_t
Click configuration structure definition.
Definition: dmx.h:160