Skip to content

Commit 08b9e5a

Browse files
committed
update joystick driver
1 parent bf825be commit 08b9e5a

6 files changed

Lines changed: 184 additions & 183 deletions

File tree

src/peripherals/joystick/Kconfig

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,7 @@ config ENABLE_JOYSTICK
33
default n
44

55
if (ENABLE_JOYSTICK)
6-
config JOYSTICK_BUTTON_NUM
7-
int "the num of joystick button"
8-
range 0 36
9-
default 7
10-
11-
config JOYSTICK_STICK_NUM1
12-
int "the num of joystick stick 1"
13-
range 0 36
14-
default 22
15-
16-
config JOYSTICK_STICK_NUM2
17-
int "the num of joystick stick 2"
18-
range 0 36
19-
default 24
20-
216
config JOYSTICK_NAME
22-
string "the name of joystick button"
7+
string "the name of joystick"
238
default "joystick"
24-
25-
config STICK_NAME1
26-
string "the name of stick 1"
27-
default "stick1"
28-
29-
config STICK_NAME2
30-
string "the name of stick 2"
31-
default "stick2"
32-
339
endif

src/peripherals/joystick/tdd_joystick/include/tdd_joystick.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ typedef struct {
2424
TDL_JOYSTICK_MODE_E mode; /* joystick mode */
2525

2626
TUYA_ADC_NUM_E adc_num; /* adc num */
27+
uint8_t adc_ch_x;
28+
uint8_t adc_ch_y;
2729
TUYA_ADC_BASE_CFG_T adc_cfg; /* adc cfg */
2830
} JOYSTICK_GPIO_CFG_T;
2931

@@ -35,16 +37,6 @@ typedef struct {
3537
*/
3638
OPERATE_RET tdd_joystick_register(char *name, JOYSTICK_GPIO_CFG_T *gpio_cfg);
3739

38-
/**
39-
* @brief Update joystick configuration level
40-
* @param[in] handle joystick handle
41-
* @param[in] level level
42-
* @return Function Operation Result OPRT_OK is ok other is fail
43-
*
44-
* @return Function Operation Result OPRT_OK is ok other is fail
45-
*/
46-
OPERATE_RET tdd_joystick_register(char *name, JOYSTICK_GPIO_CFG_T *gpio_cfg);
47-
4840
/**
4941
* @brief Update the effective level of joystick configuration
5042
* @param[in] handle joystick handle

src/peripherals/joystick/tdd_joystick/src/tdd_joystick.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ OPERATE_RET tdd_joystick_register(char *name, JOYSTICK_GPIO_CFG_T *gpio_cfg)
230230
if (NULL != handle) {
231231
device_info.dev_handle = handle;
232232
device_info.mode = gpio_cfg->mode;
233+
device_info.adc_num = gpio_cfg->adc_num;
234+
device_info.adc_ch_x = gpio_cfg->adc_ch_x;
235+
device_info.adc_ch_y = gpio_cfg->adc_ch_y;
233236
}
234237

235238
ret = tdl_joystick_register(name, &ctrl_info, &device_info);

src/peripherals/joystick/tdl_joystick/include/tdl_joystick_driver.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ typedef struct {
3737
typedef struct {
3838
void *dev_handle; /* joystick device handle */
3939
TDL_JOYSTICK_MODE_E mode; /* joystick mode */
40+
TUYA_ADC_NUM_E adc_num; /* adc num */
41+
uint8_t adc_ch_x;
42+
uint8_t adc_ch_y;
4043
} TDL_JOYSTICK_DEVICE_INFO_T;
4144

4245
/**

src/peripherals/joystick/tdl_joystick/include/tdl_joystick_manage.h

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extern "C" {
2020
/***********************************************************
2121
*************************micro define***********************
2222
***********************************************************/
23-
typedef void *TDL_JOYSTICK_HANDLE;
23+
typedef void *TDL_JOYSTICK_HANDLE;
2424

2525
/***********************************************************
2626
***********************typedef define***********************
@@ -35,30 +35,28 @@ typedef enum {
3535
TDL_JOYSTICK_BUTTON_LONG_PRESS_HOLD, /* long press hold */
3636
TDL_JOYSTICK_BUTTON_RECOVER_PRESS_UP, /* recover press up */
3737

38-
TDL_JOYSTICK_UP, /* joystick up */
39-
TDL_JOYSTICK_DOWN, /* joystick down */
40-
TDL_JOYSTICK_LEFT, /* joystick left */
41-
TDL_JOYSTICK_RIGHT, /* joystick right */
42-
TDL_JOYSTICK_LONG_UP, /* joystick long up */
43-
TDL_JOYSTICK_LONG_DOWN, /* joystick long down */
44-
TDL_JOYSTICK_LONG_LEFT, /* joystick long left */
45-
TDL_JOYSTICK_LONG_RIGHT, /* joystick long right */
46-
TDL_JOYSTICK_TOUCH_EVENT_MAX, /* joystick touch event max */
47-
TDL_JOYSTICK_TOUCH_EVENT_NONE, /* joystick touch event none */
48-
} TDL_JOYSTICK_TOUCH_EVENT_E; /* joystick touch event enum */
38+
TDL_JOYSTICK_UP, /* joystick up */
39+
TDL_JOYSTICK_DOWN, /* joystick down */
40+
TDL_JOYSTICK_LEFT, /* joystick left */
41+
TDL_JOYSTICK_RIGHT, /* joystick right */
42+
TDL_JOYSTICK_LONG_UP, /* joystick long up */
43+
TDL_JOYSTICK_LONG_DOWN, /* joystick long down */
44+
TDL_JOYSTICK_LONG_LEFT, /* joystick long left */
45+
TDL_JOYSTICK_LONG_RIGHT, /* joystick long right */
46+
TDL_JOYSTICK_TOUCH_EVENT_MAX, /* joystick touch event max */
47+
TDL_JOYSTICK_TOUCH_EVENT_NONE, /* joystick touch event none */
48+
} TDL_JOYSTICK_TOUCH_EVENT_E; /* joystick touch event enum */
4949

5050
typedef struct {
51-
uint16_t adc_max_val; /* adc max value */
52-
uint16_t adc_min_val; /* adc min value */
53-
uint16_t normalized_range; /* adc normalized range */
54-
uint8_t sensitivity; /* joystick sensitivity */
55-
uint8_t channel_x; /* adc channel x */
56-
uint8_t channel_y; /* adc channel y */
51+
uint16_t adc_max_val; /* adc max value */
52+
uint16_t adc_min_val; /* adc min value */
53+
uint16_t normalized_range; /* adc normalized range */
54+
uint8_t sensitivity; /* joystick sensitivity */
5755
} TDL_ADC_CFG_T;
5856

5957
typedef struct {
60-
TDL_BUTTON_CFG_T button_cfg; /* joystick button configuration */
61-
TDL_ADC_CFG_T adc_cfg; /* joystick adc configuration */
58+
TDL_BUTTON_CFG_T button_cfg; /* joystick button configuration */
59+
TDL_ADC_CFG_T adc_cfg; /* joystick adc configuration */
6260
} TDL_JOYSTICK_CFG_T;
6361

6462
/***********************************************************
@@ -107,7 +105,8 @@ OPERATE_RET tdl_joystick_delete_without_hardware(TDL_JOYSTICK_HANDLE handle);
107105
* @param[in] cb The function corresponding to the joystick event
108106
* @return none
109107
*/
110-
void tdl_joystick_event_register(TDL_JOYSTICK_HANDLE handle, TDL_JOYSTICK_TOUCH_EVENT_E event, TDL_JOYSTICK_EVENT_CB cb);
108+
void tdl_joystick_event_register(TDL_JOYSTICK_HANDLE handle, TDL_JOYSTICK_TOUCH_EVENT_E event,
109+
TDL_JOYSTICK_EVENT_CB cb);
111110

112111
/**
113112
* @brief Turn joystick function off or on
@@ -160,27 +159,23 @@ OPERATE_RET tdl_joystick_set_level(TDL_JOYSTICK_HANDLE handle, TUYA_GPIO_LEVEL_E
160159
*/
161160
OPERATE_RET tdl_joystick_set_scan_time(uint8_t time_ms);
162161

163-
/**
162+
/**
164163
* @brief get joystick raw data
165164
* @param[in] handle joystick handle
166-
* @param[in] channel_x x axis adc channel
167-
* @param[in] channel_y y axis adc channel
168165
* @param[out] x x axis data
169166
* @param[out] y y axis data
170167
*/
171-
void tdl_joystick_get_raw_xy(TDL_JOYSTICK_HANDLE handle, int channel_x, int channel_y, int *x, int *y);
168+
OPERATE_RET tdl_joystick_get_raw_xy(TDL_JOYSTICK_HANDLE handle, int *x, int *y);
172169

173170
/**
174171
* @brief get joystick normalized data
175172
* @param[in] handle joystick handle
176-
* @param[in] channel_x x axis adc channel
177-
* @param[in] channel_y y axis adc channel
178173
* @param[out] x x axis data
179174
* @param[out] y y axis data
180-
*
175+
*
181176
* @return OPRT_OK if successful
182177
*/
183-
void tdl_joystick_calibrated_xy(TDL_JOYSTICK_HANDLE handle, int channel_x, int channel_y, int *x, int *y);
178+
OPERATE_RET tdl_joystick_calibrated_xy(TDL_JOYSTICK_HANDLE handle, int *x, int *y);
184179

185180
#ifdef __cplusplus
186181
}

0 commit comments

Comments
 (0)