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 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define THUNDEREMU_MODE_CLOSE 0
60 #define THUNDEREMU_MODE_MID 1
61 #define THUNDEREMU_MODE_FAR 2
62 
67 #define THUNDEREMU_DAC_MODE_FAST_NORMAL 0x00
68 #define THUNDEREMU_DAC_MODE_FAST_PDOWN_1K 0x10
69 #define THUNDEREMU_DAC_MODE_FAST_PDOWN_100K 0x20
70 #define THUNDEREMU_DAC_MODE_FAST_PDOWN_500K 0x30
71 #define THUNDEREMU_DAC_MODE_EEPROM_NORMAL 0x60
72 #define THUNDEREMU_DAC_MODE_EEPROM_PDOWN_1K 0x62
73 #define THUNDEREMU_DAC_MODE_EEPROM_PDOWN_100K 0x64
74 #define THUNDEREMU_DAC_MODE_EEPROM_PDOWN_500K 0x66
75 
80 #define THUNDEREMU_DAC_OUT_MIN 0x0000
81 #define THUNDEREMU_DAC_OUT_MAX 0x0FFF
82 
88 #define THUNDEREMU_DEVICE_ADDRESS_0 0x60
89 #define THUNDEREMU_DEVICE_ADDRESS_1 0x61
90  // thunderemu_set
92 
107 #define THUNDEREMU_MAP_MIKROBUS( cfg, mikrobus ) \
108  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
109  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
110  cfg.close = MIKROBUS( mikrobus, MIKROBUS_AN ); \
111  cfg.led = MIKROBUS( mikrobus, MIKROBUS_RST ); \
112  cfg.mid = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
113  cfg.far_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
114  // thunderemu_map // thunderemu
117 
122 typedef struct
123 {
124  // Output pins
125  digital_out_t led;
127  // Input pins
128  digital_in_t close;
129  digital_in_t mid;
130  digital_in_t far_pin;
132  // Modules
133  i2c_master_t i2c;
135  // I2C slave address
136  uint8_t slave_address;
138 } thunderemu_t;
139 
144 typedef struct
145 {
146  pin_name_t scl;
147  pin_name_t sda;
149  pin_name_t led;
150  pin_name_t close;
151  pin_name_t mid;
152  pin_name_t far_pin;
154  uint32_t i2c_speed;
155  uint8_t i2c_address;
158 
163 typedef enum
164 {
166  THUNDEREMU_ERROR = -1
167 
169 
186 
201 
215 
228 err_t thunderemu_set_dac_output ( thunderemu_t *ctx, uint8_t mode, uint16_t dac_data );
229 
244 err_t thunderemu_generate_thunder ( thunderemu_t *ctx, uint8_t mode );
245 
255 
265 
275 
285 
295 
296 #ifdef __cplusplus
297 }
298 #endif
299 #endif // THUNDEREMU_H
300  // thunderemu
302 
303 // ------------------------------------------------------------------------ END
thunderemu_cfg_t::mid
pin_name_t mid
Definition: thunderemu.h:151
thunderemu_cfg_t
Thunder EMU Click configuration object.
Definition: thunderemu.h:145
thunderemu_t
Thunder EMU Click context object.
Definition: thunderemu.h:123
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:147
thunderemu_cfg_setup
void thunderemu_cfg_setup(thunderemu_cfg_t *cfg)
Thunder EMU configuration object setup function.
THUNDEREMU_OK
@ THUNDEREMU_OK
Definition: thunderemu.h:165
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:150
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:136
thunderemu_cfg_t::far_pin
pin_name_t far_pin
Definition: thunderemu.h:152
thunderemu_cfg_t::i2c_address
uint8_t i2c_address
Definition: thunderemu.h:155
thunderemu_cfg_t::scl
pin_name_t scl
Definition: thunderemu.h:146
thunderemu_t::led
digital_out_t led
Definition: thunderemu.h:125
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:154
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:164
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:133
thunderemu_t::mid
digital_in_t mid
Definition: thunderemu.h:129
thunderemu_t::close
digital_in_t close
Definition: thunderemu.h:128
thunderemu_t::far_pin
digital_in_t far_pin
Definition: thunderemu.h:130
THUNDEREMU_ERROR
@ THUNDEREMU_ERROR
Definition: thunderemu.h:166
thunderemu_cfg_t::led
pin_name_t led
Definition: thunderemu.h:149
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.