SNAKE_STM32F3
Loading...
Searching...
No Matches
joystick.c File Reference

Implementation of joystick handling module (STM32 HAL). More...

#include "joystick.h"
Include dependency graph for joystick.c:

Macros

#define JOYSTICK_TH_LOW   100
#define JOYSTICK_TH_HIGH   3900

Functions

void joystick_init (ADC_HandleTypeDef *adc_handler)
 Initializes joystick handling by passing given ADC handler and starting ADC.
vec2_t joystick_read (void)
 Reads current joystick position from ADC.
bool joystick_check_tilt (void)
 Checks if joystick is tilted past the defined dead zone.
direction_t joystick_get_direction (void)
 interprets current joystick state as one of 4 directions or NONE.

Detailed Description

Implementation of joystick handling module (STM32 HAL).

Author
bslrd
Date
2026

SPDX-License-Identifier: MIT

Macro Definition Documentation

◆ JOYSTICK_TH_HIGH

#define JOYSTICK_TH_HIGH   3900

◆ JOYSTICK_TH_LOW

#define JOYSTICK_TH_LOW   100

Function Documentation

◆ joystick_check_tilt()

bool joystick_check_tilt ( void )

Checks if joystick is tilted past the defined dead zone.

Returns
returns true if joystick is outside the deadzone and false otherwise
Here is the call graph for this function:

◆ joystick_get_direction()

direction_t joystick_get_direction ( void )

interprets current joystick state as one of 4 directions or NONE.

Returns
direction type value.
Here is the call graph for this function:

◆ joystick_init()

void joystick_init ( ADC_HandleTypeDef * adc_handler)

Initializes joystick handling by passing given ADC handler and starting ADC.

Parameters
adc_handlerpointer to ADC handler of choice.
Note
Should be called from main() before use of other joystick functions

◆ joystick_read()

vec2_t joystick_read ( void )

Reads current joystick position from ADC.

Parameters
adc_handlerpointer to ADC handler of choice.
Returns
vec2_t type vector with vec.x and vec.y values of joystick position.