joystick2  2.0.0.0
joystick2.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef JOYSTICK2_H
36 #define JOYSTICK2_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define JOYSTICK2_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
57  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
58 
64 #define JOYSTICK2_RETVAL uint8_t
65 
66 #define JOYSTICK2_OK 0x00
67 #define JOYSTICK2_INIT_ERROR 0xFF
68 
74 #define JOYSTICK2_DEVICE_SLAVE_ADDR_0_0 0x70
75 #define JOYSTICK2_DEVICE_SLAVE_ADDR_0_1 0x71
76 #define JOYSTICK2_DEVICE_SLAVE_ADDR_1_0 0x72
77 #define JOYSTICK2_DEVICE_SLAVE_ADDR_1_1 0x73
78 
84 #define JOYSTICK2_CMD_INPUT_PORT 0x00
85 #define JOYSTICK2_CMD_OUTPUT_PORT 0x01
86 #define JOYSTICK2_CMD_POLARITY_INVERSION 0x02
87 #define JOYSTICK2_CMD_CONFIGURATION 0x03
88 
94 #define JOYSTICK2_CFG_ENABLE_ALL_PORT 0xFF
95 #define JOYSTICK2_CFG_DISABLE_ALL_PORT 0x00
96 #define JOYSTICK2_CFG_ENABLE_BUTTON 0x02
97 #define JOYSTICK2_CFG_ENABLE_LEFT_POS 0x01
98 #define JOYSTICK2_CFG_ENABLE_RIGHT_POS 0x10
99 #define JOYSTICK2_CFG_ENABLE_UP_POS 0x08
100 #define JOYSTICK2_CFG_ENABLE_DOWN_POS 0x04
101 
107 #define JOYSTICK2_POSITION_LEFT 0x01
108 #define JOYSTICK2_POSITION_RIGHT 0x10
109 #define JOYSTICK2_POSITION_UP 0x08
110 #define JOYSTICK2_POSITION_DOWN 0x04
111 #define JOYSTICK2_BUTTON_ACTIVE 0x02
112  // End group macro
115 // --------------------------------------------------------------- PUBLIC TYPES
124 typedef struct
125 {
126  // Output pins
127 
128  digital_out_t rst;
129 
130  // Input pins
131 
132  digital_in_t int_pin;
133 
134  // Modules
135 
136  i2c_master_t i2c;
137 
138  // ctx variable
139 
140  hal_i2c_address_t slave_address;
141 
142 } joystick2_t;
143 
147 typedef struct
148 {
149  // Communication gpio pins
150 
151  pin_name_t scl;
152  pin_name_t sda;
153 
154  // Additional gpio pins
155 
156  pin_name_t rst;
157  pin_name_t int_pin;
158 
159  // static variable
160 
161  hal_i2c_speed_t i2c_speed;
162  hal_i2c_address_t i2c_address;
163 
165  // End types group
167 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
168 
174 #ifdef __cplusplus
175 extern "C"{
176 #endif
177 
187 
196 
214 void joystick2_default_cfg ( joystick2_t *ctx );
215 
226 void joystick2_generic_write ( joystick2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
227 
239 void joystick2_generic_read ( joystick2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
240 
246 void joystick2_reset ( joystick2_t *ctx );
247 
255 
264 void joystick2_set_cfg_register ( joystick2_t *ctx, uint8_t cfg_data );
265 
272 uint8_t joystick2_get_position ( joystick2_t *ctx );
273 
274 #ifdef __cplusplus
275 }
276 #endif
277 #endif // _JOYSTICK2_H_
278  // End public_function group
281 
282 // ------------------------------------------------------------------------- END
void joystick2_set_cfg_register(joystick2_t *ctx, uint8_t cfg_data)
Functions for configuration joystick.
hal_i2c_address_t i2c_address
Definition: joystick2.h:162
hal_i2c_address_t slave_address
Definition: joystick2.h:140
void joystick2_cfg_setup(joystick2_cfg_t *cfg)
Config Object Initialization function.
JOYSTICK2_RETVAL joystick2_init(joystick2_t *ctx, joystick2_cfg_t *cfg)
Initialization function.
void joystick2_reset(joystick2_t *ctx)
Functions for reset module.
uint8_t joystick2_get_position(joystick2_t *ctx)
Functions for get Joystick position.
void joystick2_generic_write(joystick2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
Click ctx object definition.
Definition: joystick2.h:124
void joystick2_default_cfg(joystick2_t *ctx)
Click Default Configuration function.
pin_name_t scl
Definition: joystick2.h:151
digital_out_t rst
Definition: joystick2.h:128
#define JOYSTICK2_RETVAL
Definition: joystick2.h:64
pin_name_t sda
Definition: joystick2.h:152
hal_i2c_speed_t i2c_speed
Definition: joystick2.h:161
i2c_master_t i2c
Definition: joystick2.h:136
digital_in_t int_pin
Definition: joystick2.h:132
void joystick2_generic_read(joystick2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
pin_name_t int_pin
Definition: joystick2.h:157
uint8_t joystick2_get_interrupt_state(joystick2_t *ctx)
Functions for read interrupt state.
Click configuration structure definition.
Definition: joystick2.h:147
pin_name_t rst
Definition: joystick2.h:156