thunderemu  2.1.0.0
thunderemu.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef THUNDEREMU_H
29 #define THUNDEREMU_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_i2c_master.h"
52 
73 #define THUNDEREMU_MODE_CLOSE 0
74 #define THUNDEREMU_MODE_MID 1
75 #define THUNDEREMU_MODE_FAR 2
76 
81 #define THUNDEREMU_DAC_MODE_FAST_NORMAL 0x00
82 #define THUNDEREMU_DAC_MODE_FAST_PDOWN_1K 0x10
83 #define THUNDEREMU_DAC_MODE_FAST_PDOWN_100K 0x20
84 #define THUNDEREMU_DAC_MODE_FAST_PDOWN_500K 0x30
85 #define THUNDEREMU_DAC_MODE_EEPROM_NORMAL 0x60
86 #define THUNDEREMU_DAC_MODE_EEPROM_PDOWN_1K 0x62
87 #define THUNDEREMU_DAC_MODE_EEPROM_PDOWN_100K 0x64
88 #define THUNDEREMU_DAC_MODE_EEPROM_PDOWN_500K 0x66
89 
94 #define THUNDEREMU_DAC_OUT_MIN 0x0000
95 #define THUNDEREMU_DAC_OUT_MAX 0x0FFF
96 
102 #define THUNDEREMU_DEVICE_ADDRESS_0 0x60
103 #define THUNDEREMU_DEVICE_ADDRESS_1 0x61
104  // thunderemu_set
106 
121 #define THUNDEREMU_MAP_MIKROBUS( cfg, mikrobus ) \
122  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
123  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
124  cfg.close = MIKROBUS( mikrobus, MIKROBUS_AN ); \
125  cfg.led = MIKROBUS( mikrobus, MIKROBUS_RST ); \
126  cfg.mid = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
127  cfg.far_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
128  // thunderemu_map // thunderemu
131 
136 typedef struct
137 {
138  // Output pins
139  digital_out_t led;
141  // Input pins
142  digital_in_t close;
143  digital_in_t mid;
144  digital_in_t far_pin;
146  // Modules
147  i2c_master_t i2c;
149  // I2C slave address
150  uint8_t slave_address;
152 } thunderemu_t;
153 
158 typedef struct
159 {
160  pin_name_t scl;
161  pin_name_t sda;
163  pin_name_t led;
164  pin_name_t close;
165  pin_name_t mid;
166  pin_name_t far_pin;
168  uint32_t i2c_speed;
169  uint8_t i2c_address;
172 
177 typedef enum
178 {
180  THUNDEREMU_ERROR = -1
181 
183 
200 
215 
229 
242 err_t thunderemu_set_dac_output ( thunderemu_t *ctx, uint8_t mode, uint16_t dac_data );
243 
258 err_t thunderemu_generate_thunder ( thunderemu_t *ctx, uint8_t mode );
259 
269 
279 
289 
299 
309 
310 #ifdef __cplusplus
311 }
312 #endif
313 #endif // THUNDEREMU_H
314  // thunderemu
316 
317 // ------------------------------------------------------------------------ END
thunderemu_cfg_t::mid
pin_name_t mid
Definition: thunderemu.h:165
thunderemu_cfg_t
Thunder EMU Click configuration object.
Definition: thunderemu.h:159
thunderemu_t
Thunder EMU Click context object.
Definition: thunderemu.h:137
thunderemu_get_close_pin
uint8_t thunderemu_get_close_pin(thunderemu_t *ctx)
Thunder EMU get close pin function.
thunderemu_cfg_t::sda
pin_name_t sda
Definition: thunderemu.h:161
thunderemu_cfg_setup
void thunderemu_cfg_setup(thunderemu_cfg_t *cfg)
Thunder EMU configuration object setup function.
THUNDEREMU_OK
@ THUNDEREMU_OK
Definition: thunderemu.h:179
thunderemu_default_cfg
err_t thunderemu_default_cfg(thunderemu_t *ctx)
Thunder EMU default configuration function.
thunderemu_cfg_t::close
pin_name_t close
Definition: thunderemu.h:164
thunderemu_get_mid_pin
uint8_t thunderemu_get_mid_pin(thunderemu_t *ctx)
Thunder EMU get mid pin function.
thunderemu_generate_thunder
err_t thunderemu_generate_thunder(thunderemu_t *ctx, uint8_t mode)
Thunder EMU generate thunder function.
thunderemu_t::slave_address
uint8_t slave_address
Definition: thunderemu.h:150
thunderemu_cfg_t::far_pin
pin_name_t far_pin
Definition: thunderemu.h:166
thunderemu_cfg_t::i2c_address
uint8_t i2c_address
Definition: thunderemu.h:169
thunderemu_cfg_t::scl
pin_name_t scl
Definition: thunderemu.h:160
thunderemu_t::led
digital_out_t led
Definition: thunderemu.h:139
thunderemu_led_enable
void thunderemu_led_enable(thunderemu_t *ctx)
Thunder EMU led enable function.
thunderemu_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: thunderemu.h:168
thunderemu_led_disable
void thunderemu_led_disable(thunderemu_t *ctx)
Thunder EMU led disable function.
thunderemu_init
err_t thunderemu_init(thunderemu_t *ctx, thunderemu_cfg_t *cfg)
Thunder EMU initialization function.
thunderemu_return_value_t
thunderemu_return_value_t
Thunder EMU Click return value data.
Definition: thunderemu.h:178
thunderemu_get_far_pin
uint8_t thunderemu_get_far_pin(thunderemu_t *ctx)
Thunder EMU get far pin function.
thunderemu_t::i2c
i2c_master_t i2c
Definition: thunderemu.h:147
thunderemu_t::mid
digital_in_t mid
Definition: thunderemu.h:143
thunderemu_t::close
digital_in_t close
Definition: thunderemu.h:142
thunderemu_t::far_pin
digital_in_t far_pin
Definition: thunderemu.h:144
THUNDEREMU_ERROR
@ THUNDEREMU_ERROR
Definition: thunderemu.h:180
thunderemu_cfg_t::led
pin_name_t led
Definition: thunderemu.h:163
thunderemu_set_dac_output
err_t thunderemu_set_dac_output(thunderemu_t *ctx, uint8_t mode, uint16_t dac_data)
Thunder EMU set dac output function.