joystick2  2.0.0.0
joystick2.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 JOYSTICK2_H
36 #define JOYSTICK2_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_i2c_master.h"
55 
56 
57 // -------------------------------------------------------------- PUBLIC MACROS
67 #define JOYSTICK2_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
70  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
72 
78 #define JOYSTICK2_RETVAL uint8_t
79 
80 #define JOYSTICK2_OK 0x00
81 #define JOYSTICK2_INIT_ERROR 0xFF
82 
88 #define JOYSTICK2_DEVICE_SLAVE_ADDR_0_0 0x70
89 #define JOYSTICK2_DEVICE_SLAVE_ADDR_0_1 0x71
90 #define JOYSTICK2_DEVICE_SLAVE_ADDR_1_0 0x72
91 #define JOYSTICK2_DEVICE_SLAVE_ADDR_1_1 0x73
92 
98 #define JOYSTICK2_CMD_INPUT_PORT 0x00
99 #define JOYSTICK2_CMD_OUTPUT_PORT 0x01
100 #define JOYSTICK2_CMD_POLARITY_INVERSION 0x02
101 #define JOYSTICK2_CMD_CONFIGURATION 0x03
102 
108 #define JOYSTICK2_CFG_ENABLE_ALL_PORT 0xFF
109 #define JOYSTICK2_CFG_DISABLE_ALL_PORT 0x00
110 #define JOYSTICK2_CFG_ENABLE_BUTTON 0x02
111 #define JOYSTICK2_CFG_ENABLE_LEFT_POS 0x01
112 #define JOYSTICK2_CFG_ENABLE_RIGHT_POS 0x10
113 #define JOYSTICK2_CFG_ENABLE_UP_POS 0x08
114 #define JOYSTICK2_CFG_ENABLE_DOWN_POS 0x04
115 
121 #define JOYSTICK2_POSITION_LEFT 0x01
122 #define JOYSTICK2_POSITION_RIGHT 0x10
123 #define JOYSTICK2_POSITION_UP 0x08
124 #define JOYSTICK2_POSITION_DOWN 0x04
125 #define JOYSTICK2_BUTTON_ACTIVE 0x02
126  // End group macro
129 // --------------------------------------------------------------- PUBLIC TYPES
138 typedef struct
139 {
140  // Output pins
141 
142  digital_out_t rst;
143 
144  // Input pins
145 
146  digital_in_t int_pin;
147 
148  // Modules
149 
150  i2c_master_t i2c;
151 
152  // ctx variable
153 
154  uint8_t slave_address;
155 
156 } joystick2_t;
157 
161 typedef struct
162 {
163  // Communication gpio pins
164 
165  pin_name_t scl;
166  pin_name_t sda;
167 
168  // Additional gpio pins
169 
170  pin_name_t rst;
171  pin_name_t int_pin;
172 
173  // static variable
174 
175  uint32_t i2c_speed;
176  uint8_t i2c_address;
177 
179  // End types group
181 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
182 
188 #ifdef __cplusplus
189 extern "C"{
190 #endif
191 
201 
210 
229 
240 void joystick2_generic_write ( joystick2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
241 
253 void joystick2_generic_read ( joystick2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
254 
261 
269 
278 void joystick2_set_cfg_register ( joystick2_t *ctx, uint8_t cfg_data );
279 
287 
288 #ifdef __cplusplus
289 }
290 #endif
291 #endif // _JOYSTICK2_H_
292  // End public_function group
295 
296 // ------------------------------------------------------------------------- END
joystick2_cfg_t::int_pin
pin_name_t int_pin
Definition: joystick2.h:171
joystick2_generic_read
void joystick2_generic_read(joystick2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
joystick2_cfg_t::rst
pin_name_t rst
Definition: joystick2.h:170
joystick2_default_cfg
void joystick2_default_cfg(joystick2_t *ctx)
Click Default Configuration function.
joystick2_cfg_t
Click configuration structure definition.
Definition: joystick2.h:162
joystick2_t::rst
digital_out_t rst
Definition: joystick2.h:142
joystick2_cfg_setup
void joystick2_cfg_setup(joystick2_cfg_t *cfg)
Config Object Initialization function.
joystick2_get_position
uint8_t joystick2_get_position(joystick2_t *ctx)
Functions for get Joystick position.
joystick2_init
JOYSTICK2_RETVAL joystick2_init(joystick2_t *ctx, joystick2_cfg_t *cfg)
Initialization function.
joystick2_cfg_t::sda
pin_name_t sda
Definition: joystick2.h:166
joystick2_set_cfg_register
void joystick2_set_cfg_register(joystick2_t *ctx, uint8_t cfg_data)
Functions for configuration joystick.
joystick2_generic_write
void joystick2_generic_write(joystick2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
joystick2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: joystick2.h:175
JOYSTICK2_RETVAL
#define JOYSTICK2_RETVAL
Definition: joystick2.h:78
joystick2_t::int_pin
digital_in_t int_pin
Definition: joystick2.h:146
joystick2_cfg_t::i2c_address
uint8_t i2c_address
Definition: joystick2.h:176
joystick2_t::i2c
i2c_master_t i2c
Definition: joystick2.h:150
joystick2_cfg_t::scl
pin_name_t scl
Definition: joystick2.h:165
joystick2_t::slave_address
uint8_t slave_address
Definition: joystick2.h:154
joystick2_t
Click ctx object definition.
Definition: joystick2.h:139
joystick2_reset
void joystick2_reset(joystick2_t *ctx)
Functions for reset module.
joystick2_get_interrupt_state
uint8_t joystick2_get_interrupt_state(joystick2_t *ctx)
Functions for read interrupt state.