joystick  2.0.0.0
joystick.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 JOYSTCIK_H
36 #define JOYSTCIK_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
48 #define JOYSTICK_I2C_ADDRESS_0 0x40
49 #define JOYSTICK_I2C_ADDRESS_1 0x41
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
56 #define JOYSTICK_ID_CODE 0x0C
57 #define JOYSTICK_ID_VERSION 0x0D
58 #define JOYSTICK_SIL_REV 0x0E
59 #define JOYSTICK_CONTROL1 0x0F
60 #define JOYSTICK_CONTROL2 0x2E
61 #define JOYSTICK_X 0x10
62 #define JOYSTICK_Y_RES_INT 0x11
63 #define JOYSTICK_XP 0x12
64 #define JOYSTICK_XN 0x13
65 #define JOYSTICK_YP 0x14
66 #define JOYSTICK_YN 0x15
67 #define JOYSTICK_AGC 0x2A
68 #define JOYSTICK_M_CTRL 0x2B
69 #define JOYSTICK_J_CTRL 0x2C
70 #define JOYSTICK_T_CTRL 0x2D
71 
77 #define JOYSTICK_CONTROL2_TEST_CMD 0x84
78 #define JOYSTICK_AGC_MAX_SENSITIVITY_CMD 0x3F
79 #define JOYSTICK_T_CTRL_SCALING_90_8_CMD 0x0A
80 #define JOYSTICK_T_CTRL_SCALING_100_CMD 0x09
81 #define JOYSTICK_CONTROL1_RESET_CMD 0x88
82 #define JOYSTICK_INVERT_SPINING_CMD 0x86
83 
89 #define JOYSTCIK_MAP_MIKROBUS( cfg, mikrobus ) \
90  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
91  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );\
92  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );\
93  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );\
94  cfg.tst = MIKROBUS( mikrobus, MIKROBUS_CS );
95 
101 #define JOYSTCIK_RETVAL uint8_t
102 #define JOYSTCIK_OK 0x00
103 #define JOYSTCIK_INIT_ERROR 0xFF
104  // End group macro
107 // --------------------------------------------------------------- PUBLIC TYPES
116 typedef struct
117 {
118  // Output pins
119 
120  digital_out_t rst;
121 
122 
123  // Input pins
124 
125  digital_in_t int_pin;
126  digital_in_t tst;
127 
128  // Modules
129 
130  i2c_master_t i2c;
131 
132  // ctx variable
133 
134  uint8_t slave_address;
135 
136 } joystick_t;
137 
141 typedef struct
142 {
143  // Communication gpio pins
144 
145  pin_name_t scl;
146  pin_name_t sda;
147 
148  // Additional gpio pins
149 
150  pin_name_t rst;
151  pin_name_t tst;
152  pin_name_t int_pin;
153 
154  // static variable
155 
156  uint32_t i2c_speed;
157  uint8_t i2c_address;
158 
160  // End types group
162 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
163 
169 #ifdef __cplusplus
170 extern "C"{
171 #endif
172 
181 void joystick_cfg_setup ( joystick_cfg_t *cfg );
182 
191 
199 void joystick_default_cfg ( joystick_t *ctx );
200 
211 void joystick_generic_write ( joystick_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
212 
224 void joystick_generic_read ( joystick_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
225 
238 
253 uint8_t joystick_check_id_code ( joystick_t *ctx );
254 
269 uint8_t joystick_check_id_version ( joystick_t *ctx );
270 
291 void joystick_set_low_power_mode ( joystick_t *ctx, uint8_t timings );
292 
337 void joystick_set_scaling_factor ( joystick_t *ctx, uint8_t scaling_factor );
338 
349 
358 
368 
391 uint8_t joystick_get_position( joystick_t *ctx );
392 
408 uint8_t joystick_get_interrupt ( joystick_t *ctx );
409 
425 uint8_t joystick_press_button( joystick_t *ctx );
426 
437 void joystick_soft_reset( joystick_t *ctx );
438 
448 
449 #ifdef __cplusplus
450 }
451 #endif
452 #endif // _JOYSTCIK_H_
453  // End public_function group
456 
457 // ------------------------------------------------------------------------- END
pin_name_t scl
Definition: joystick.h:145
digital_in_t tst
Definition: joystick.h:126
void joystick_set_default_configuration(joystick_t *ctx)
Set default configuration function.
void joystick_generic_read(joystick_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
pin_name_t int_pin
Definition: joystick.h:152
uint8_t joystick_check_id_code(joystick_t *ctx)
Check sensor ID code function.
uint8_t joystick_get_position(joystick_t *ctx)
Get joystick position function.
digital_in_t int_pin
Definition: joystick.h:125
uint8_t joystick_press_button(joystick_t *ctx)
Get state of Joystick button function.
void joystick_generic_write(joystick_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
i2c_master_t i2c
Definition: joystick.h:130
uint8_t i2c_address
Definition: joystick.h:157
void joystick_set_low_power_mode(joystick_t *ctx, uint8_t timings)
Set Low Power Mode function.
digital_out_t rst
Definition: joystick.h:120
pin_name_t tst
Definition: joystick.h:151
pin_name_t sda
Definition: joystick.h:146
void joystick_soft_reset(joystick_t *ctx)
General soft reset function.
uint32_t i2c_speed
Definition: joystick.h:156
uint8_t joystick_check_id_version(joystick_t *ctx)
Check sensor ID version function.
Click configuration structure definition.
Definition: joystick.h:141
#define JOYSTCIK_RETVAL
Definition: joystick.h:101
uint8_t slave_address
Definition: joystick.h:134
void joystick_invert_spinning(joystick_t *ctx)
Invert the channel voltage function.
uint8_t joystick_get_interrupt(joystick_t *ctx)
Get state of interrupt pin function.
void joystick_default_cfg(joystick_t *ctx)
Click Default Configuration function.
void joystick_cfg_setup(joystick_cfg_t *cfg)
Config Object Initialization function.
void joystick_set_scaling_factor(joystick_t *ctx, uint8_t scaling_factor)
Set scaling factor function.
void joystick_enabled_interrupt(joystick_t *ctx)
Set interrupt enabled function.
pin_name_t rst
Definition: joystick.h:150
JOYSTCIK_RETVAL joystick_init(joystick_t *ctx, joystick_cfg_t *cfg)
Initialization function.
void joystick_disabled_interrupt(joystick_t *ctx)
Set interrupt disabled function.
Click ctx object definition.
Definition: joystick.h:116
void joystick_hardware_reset(joystick_t *ctx)
General hardware reset function.