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
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
62#define JOYSTICK_I2C_ADDRESS_0 0x40
63#define JOYSTICK_I2C_ADDRESS_1 0x41
64
65// -------------------------------------------------------------- PUBLIC MACROS
70#define JOYSTICK_ID_CODE 0x0C
71#define JOYSTICK_ID_VERSION 0x0D
72#define JOYSTICK_SIL_REV 0x0E
73#define JOYSTICK_CONTROL1 0x0F
74#define JOYSTICK_CONTROL2 0x2E
75#define JOYSTICK_X 0x10
76#define JOYSTICK_Y_RES_INT 0x11
77#define JOYSTICK_XP 0x12
78#define JOYSTICK_XN 0x13
79#define JOYSTICK_YP 0x14
80#define JOYSTICK_YN 0x15
81#define JOYSTICK_AGC 0x2A
82#define JOYSTICK_M_CTRL 0x2B
83#define JOYSTICK_J_CTRL 0x2C
84#define JOYSTICK_T_CTRL 0x2D
91#define JOYSTICK_CONTROL2_TEST_CMD 0x84
92#define JOYSTICK_AGC_MAX_SENSITIVITY_CMD 0x3F
93#define JOYSTICK_T_CTRL_SCALING_90_8_CMD 0x0A
94#define JOYSTICK_T_CTRL_SCALING_100_CMD 0x09
95#define JOYSTICK_CONTROL1_RESET_CMD 0x88
96#define JOYSTICK_INVERT_SPINING_CMD 0x86
103#define JOYSTCIK_MAP_MIKROBUS( cfg, mikrobus ) \
104 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
105 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );\
106 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );\
107 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );\
108 cfg.tst = MIKROBUS( mikrobus, MIKROBUS_CS );
109
115#define JOYSTCIK_RETVAL uint8_t
116#define JOYSTCIK_OK 0x00
117#define JOYSTCIK_INIT_ERROR 0xFF
120 // End group macro
121// --------------------------------------------------------------- PUBLIC TYPES
130typedef struct
131{
132 // Output pins
133
134 digital_out_t rst;
135
136
137 // Input pins
138
139 digital_in_t int_pin;
140 digital_in_t tst;
141
142 // Modules
143
144 i2c_master_t i2c;
145
146 // ctx variable
147
149
150} joystick_t;
151
155typedef struct
156{
157 // Communication gpio pins
158
159 pin_name_t scl;
160 pin_name_t sda;
161
162 // Additional gpio pins
163
164 pin_name_t rst;
165 pin_name_t tst;
166 pin_name_t int_pin;
167
168 // static variable
169
170 uint32_t i2c_speed;
171 uint8_t i2c_address;
172
174
175 // End types group
176// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
177
183#ifdef __cplusplus
184extern "C"{
185#endif
186
196
205
214
225void joystick_generic_write ( joystick_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
226
238void joystick_generic_read ( joystick_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
239
252
268
284
305void joystick_set_low_power_mode ( joystick_t *ctx, uint8_t timings );
306
351void joystick_set_scaling_factor ( joystick_t *ctx, uint8_t scaling_factor );
352
363
372
382
406
423
440
452
462
463#ifdef __cplusplus
464}
465#endif
466#endif // _JOYSTCIK_H_
467
468 // End public_function group
470
471// ------------------------------------------------------------------------- END
#define JOYSTCIK_RETVAL
Definition joystick.h:115
void joystick_enabled_interrupt(joystick_t *ctx)
Set interrupt enabled function.
void joystick_hardware_reset(joystick_t *ctx)
General hardware reset function.
void joystick_disabled_interrupt(joystick_t *ctx)
Set interrupt disabled function.
uint8_t joystick_get_interrupt(joystick_t *ctx)
Get state of interrupt pin function.
void joystick_set_low_power_mode(joystick_t *ctx, uint8_t timings)
Set Low Power Mode function.
JOYSTCIK_RETVAL joystick_init(joystick_t *ctx, joystick_cfg_t *cfg)
Initialization function.
void joystick_set_default_configuration(joystick_t *ctx)
Set default configuration function.
uint8_t joystick_get_position(joystick_t *ctx)
Get joystick position function.
uint8_t joystick_check_id_version(joystick_t *ctx)
Check sensor ID version function.
void joystick_generic_write(joystick_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void joystick_set_scaling_factor(joystick_t *ctx, uint8_t scaling_factor)
Set scaling factor function.
void joystick_generic_read(joystick_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void joystick_invert_spinning(joystick_t *ctx)
Invert the channel voltage function.
void joystick_soft_reset(joystick_t *ctx)
General soft reset function.
uint8_t joystick_press_button(joystick_t *ctx)
Get state of Joystick button function.
void joystick_default_cfg(joystick_t *ctx)
Click Default Configuration function.
uint8_t joystick_check_id_code(joystick_t *ctx)
Check sensor ID code function.
void joystick_cfg_setup(joystick_cfg_t *cfg)
Config Object Initialization function.
Click configuration structure definition.
Definition joystick.h:156
uint32_t i2c_speed
Definition joystick.h:170
pin_name_t tst
Definition joystick.h:165
pin_name_t scl
Definition joystick.h:159
pin_name_t int_pin
Definition joystick.h:166
pin_name_t sda
Definition joystick.h:160
pin_name_t rst
Definition joystick.h:164
uint8_t i2c_address
Definition joystick.h:171
Click ctx object definition.
Definition joystick.h:131
digital_in_t tst
Definition joystick.h:140
digital_in_t int_pin
Definition joystick.h:139
i2c_master_t i2c
Definition joystick.h:144
digital_out_t rst
Definition joystick.h:134
uint8_t slave_address
Definition joystick.h:148