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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
58 #define JOYSTICK_I2C_ADDRESS_0 0x40
59 #define JOYSTICK_I2C_ADDRESS_1 0x41
60 
61 // -------------------------------------------------------------- PUBLIC MACROS
66 #define JOYSTICK_ID_CODE 0x0C
67 #define JOYSTICK_ID_VERSION 0x0D
68 #define JOYSTICK_SIL_REV 0x0E
69 #define JOYSTICK_CONTROL1 0x0F
70 #define JOYSTICK_CONTROL2 0x2E
71 #define JOYSTICK_X 0x10
72 #define JOYSTICK_Y_RES_INT 0x11
73 #define JOYSTICK_XP 0x12
74 #define JOYSTICK_XN 0x13
75 #define JOYSTICK_YP 0x14
76 #define JOYSTICK_YN 0x15
77 #define JOYSTICK_AGC 0x2A
78 #define JOYSTICK_M_CTRL 0x2B
79 #define JOYSTICK_J_CTRL 0x2C
80 #define JOYSTICK_T_CTRL 0x2D
81 
87 #define JOYSTICK_CONTROL2_TEST_CMD 0x84
88 #define JOYSTICK_AGC_MAX_SENSITIVITY_CMD 0x3F
89 #define JOYSTICK_T_CTRL_SCALING_90_8_CMD 0x0A
90 #define JOYSTICK_T_CTRL_SCALING_100_CMD 0x09
91 #define JOYSTICK_CONTROL1_RESET_CMD 0x88
92 #define JOYSTICK_INVERT_SPINING_CMD 0x86
93 
99 #define JOYSTCIK_MAP_MIKROBUS( cfg, mikrobus ) \
100  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
101  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );\
102  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );\
103  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );\
104  cfg.tst = MIKROBUS( mikrobus, MIKROBUS_CS );
105 
111 #define JOYSTCIK_RETVAL uint8_t
112 #define JOYSTCIK_OK 0x00
113 #define JOYSTCIK_INIT_ERROR 0xFF
114  // End group macro
117 // --------------------------------------------------------------- PUBLIC TYPES
126 typedef struct
127 {
128  // Output pins
129 
130  digital_out_t rst;
131 
132 
133  // Input pins
134 
135  digital_in_t int_pin;
136  digital_in_t tst;
137 
138  // Modules
139 
140  i2c_master_t i2c;
141 
142  // ctx variable
143 
144  uint8_t slave_address;
145 
146 } joystick_t;
147 
151 typedef struct
152 {
153  // Communication gpio pins
154 
155  pin_name_t scl;
156  pin_name_t sda;
157 
158  // Additional gpio pins
159 
160  pin_name_t rst;
161  pin_name_t tst;
162  pin_name_t int_pin;
163 
164  // static variable
165 
166  uint32_t i2c_speed;
167  uint8_t i2c_address;
168 
170  // End types group
172 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
173 
179 #ifdef __cplusplus
180 extern "C"{
181 #endif
182 
192 
201 
210 
221 void joystick_generic_write ( joystick_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
222 
234 void joystick_generic_read ( joystick_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
235 
248 
264 
280 
301 void joystick_set_low_power_mode ( joystick_t *ctx, uint8_t timings );
302 
347 void joystick_set_scaling_factor ( joystick_t *ctx, uint8_t scaling_factor );
348 
359 
368 
378 
402 
419 
436 
448 
458 
459 #ifdef __cplusplus
460 }
461 #endif
462 #endif // _JOYSTCIK_H_
463  // End public_function group
466 
467 // ------------------------------------------------------------------------- END
joystick_t::tst
digital_in_t tst
Definition: joystick.h:136
JOYSTCIK_RETVAL
#define JOYSTCIK_RETVAL
Definition: joystick.h:111
joystick_default_cfg
void joystick_default_cfg(joystick_t *ctx)
Click Default Configuration function.
joystick_t::slave_address
uint8_t slave_address
Definition: joystick.h:144
joystick_t::int_pin
digital_in_t int_pin
Definition: joystick.h:135
joystick_cfg_t::int_pin
pin_name_t int_pin
Definition: joystick.h:162
joystick_generic_write
void joystick_generic_write(joystick_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
joystick_get_position
uint8_t joystick_get_position(joystick_t *ctx)
Get joystick position function.
joystick_disabled_interrupt
void joystick_disabled_interrupt(joystick_t *ctx)
Set interrupt disabled function.
joystick_t
Click ctx object definition.
Definition: joystick.h:127
joystick_set_scaling_factor
void joystick_set_scaling_factor(joystick_t *ctx, uint8_t scaling_factor)
Set scaling factor function.
joystick_cfg_setup
void joystick_cfg_setup(joystick_cfg_t *cfg)
Config Object Initialization function.
joystick_cfg_t::i2c_address
uint8_t i2c_address
Definition: joystick.h:167
joystick_t::rst
digital_out_t rst
Definition: joystick.h:130
joystick_invert_spinning
void joystick_invert_spinning(joystick_t *ctx)
Invert the channel voltage function.
joystick_get_interrupt
uint8_t joystick_get_interrupt(joystick_t *ctx)
Get state of interrupt pin function.
joystick_t::i2c
i2c_master_t i2c
Definition: joystick.h:140
joystick_generic_read
void joystick_generic_read(joystick_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
joystick_cfg_t::sda
pin_name_t sda
Definition: joystick.h:156
joystick_check_id_version
uint8_t joystick_check_id_version(joystick_t *ctx)
Check sensor ID version function.
joystick_set_default_configuration
void joystick_set_default_configuration(joystick_t *ctx)
Set default configuration function.
joystick_cfg_t::tst
pin_name_t tst
Definition: joystick.h:161
joystick_check_id_code
uint8_t joystick_check_id_code(joystick_t *ctx)
Check sensor ID code function.
joystick_cfg_t::rst
pin_name_t rst
Definition: joystick.h:160
joystick_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: joystick.h:166
joystick_hardware_reset
void joystick_hardware_reset(joystick_t *ctx)
General hardware reset function.
joystick_set_low_power_mode
void joystick_set_low_power_mode(joystick_t *ctx, uint8_t timings)
Set Low Power Mode function.
joystick_init
JOYSTCIK_RETVAL joystick_init(joystick_t *ctx, joystick_cfg_t *cfg)
Initialization function.
joystick_cfg_t::scl
pin_name_t scl
Definition: joystick.h:155
joystick_soft_reset
void joystick_soft_reset(joystick_t *ctx)
General soft reset function.
joystick_cfg_t
Click configuration structure definition.
Definition: joystick.h:152
joystick_press_button
uint8_t joystick_press_button(joystick_t *ctx)
Get state of Joystick button function.
joystick_enabled_interrupt
void joystick_enabled_interrupt(joystick_t *ctx)
Set interrupt enabled function.