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
32extern "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
105 // 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
129 // thunderemu_map
130 // thunderemu
131
136typedef 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
153
158typedef 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
183
200
215
229
242err_t thunderemu_set_dac_output ( thunderemu_t *ctx, uint8_t mode, uint16_t dac_data );
243
258err_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
315 // thunderemu
316
317// ------------------------------------------------------------------------ END
void thunderemu_cfg_setup(thunderemu_cfg_t *cfg)
Thunder EMU configuration object setup function.
err_t thunderemu_generate_thunder(thunderemu_t *ctx, uint8_t mode)
Thunder EMU generate thunder function.
err_t thunderemu_init(thunderemu_t *ctx, thunderemu_cfg_t *cfg)
Thunder EMU initialization function.
err_t thunderemu_default_cfg(thunderemu_t *ctx)
Thunder EMU default configuration function.
uint8_t thunderemu_get_mid_pin(thunderemu_t *ctx)
Thunder EMU get mid pin function.
void thunderemu_led_disable(thunderemu_t *ctx)
Thunder EMU led disable function.
uint8_t thunderemu_get_far_pin(thunderemu_t *ctx)
Thunder EMU get far pin function.
err_t thunderemu_set_dac_output(thunderemu_t *ctx, uint8_t mode, uint16_t dac_data)
Thunder EMU set dac output function.
void thunderemu_led_enable(thunderemu_t *ctx)
Thunder EMU led enable function.
uint8_t thunderemu_get_close_pin(thunderemu_t *ctx)
Thunder EMU get close pin function.
Thunder EMU Click configuration object.
Definition thunderemu.h:159
pin_name_t led
Definition thunderemu.h:163
uint32_t i2c_speed
Definition thunderemu.h:168
pin_name_t mid
Definition thunderemu.h:165
pin_name_t close
Definition thunderemu.h:164
pin_name_t scl
Definition thunderemu.h:160
pin_name_t sda
Definition thunderemu.h:161
pin_name_t far_pin
Definition thunderemu.h:166
uint8_t i2c_address
Definition thunderemu.h:169
Thunder EMU Click context object.
Definition thunderemu.h:137
digital_in_t mid
Definition thunderemu.h:143
digital_out_t led
Definition thunderemu.h:139
digital_in_t close
Definition thunderemu.h:142
i2c_master_t i2c
Definition thunderemu.h:147
digital_in_t far_pin
Definition thunderemu.h:144
uint8_t slave_address
Definition thunderemu.h:150
thunderemu_return_value_t
Thunder EMU Click return value data.
Definition thunderemu.h:178
@ THUNDEREMU_OK
Definition thunderemu.h:179
@ THUNDEREMU_ERROR
Definition thunderemu.h:180