GaIA BIOS Library
Loading...
Searching...
No Matches
gwa_encoder.h File Reference

Encoder function prototypes. More...

#include <stdint.h>

Macros

#define MAX_ENCODER_CHANNEL   4
#define ENCODER_CHANNEL_BASE0   0
 First encoder on the BASE board (TIM4 PD12-PD13)
#define ENCODER_CHANNEL_BASE1   1
 Second encoder on the BASE board (TIM3 PB4-PC7)
#define ENCODER_CHANNEL_EXP0   2
 Encoder on the EXPANSION board (TIM2 PA15-PB3)
#define ENCODER_CHANNEL_EXP1   3
 Encoder EXPANSION (TIM1 PA8-PE11)
#define ENCODER_DIR_UP   0
 Counting direction up.
#define ENCODER_DIR_DOWN   1
 Counting direction down.
#define ENC_OK   0
 No errors.
#define ENC_INVALID_PARAM   1
 Invalid parameter error.

Functions

int gwa_encoder_init (uint8_t channel, uint8_t direction, uint32_t value)
 Sets up the encoder.
int gwa_encoder_read (uint8_t channel, uint32_t *value)
 Reads the value of the counter.
int gwa_encoder_enable_ovr_int (uint8_t channel)
 Enables the overflow interrupt.
int gwa_encoder_disable_ovr_int (uint8_t channel)
 Disables the overflow interrupt.
int gwa_encoder_clear_ovr_int (uint8_t channel)
 Acknowledges the overflow interrupt.
int gwa_encoder_handle_ovr_int (uint8_t channel)
 Handles overflow interrupt so that encoder value is 32-bit wide.

Detailed Description

Encoder function prototypes.

Author
Tecnologix, 2017

Function Documentation

◆ gwa_encoder_clear_ovr_int()

int gwa_encoder_clear_ovr_int ( uint8_t channel)

Acknowledges the overflow interrupt.

Parameters
channelencoder channel:
Returns
ENC_OK if everything is ok, an error code otherwise.

◆ gwa_encoder_disable_ovr_int()

int gwa_encoder_disable_ovr_int ( uint8_t channel)

Disables the overflow interrupt.

Parameters
channelencoder channel:
Returns
ENC_OK if everything is ok, an error code otherwise.

◆ gwa_encoder_enable_ovr_int()

int gwa_encoder_enable_ovr_int ( uint8_t channel)

Enables the overflow interrupt.

Parameters
channelencoder channel:
Returns
ENC_OK if everything is ok, an error code otherwise.

◆ gwa_encoder_handle_ovr_int()

int gwa_encoder_handle_ovr_int ( uint8_t channel)

Handles overflow interrupt so that encoder value is 32-bit wide.

This function must be called from the timer IRQ handler of the peripheral used for the encoder:

This function checks if the overflow interrupt flag is set and clears it so it can be called from the timer IRQ handler without any check on the interrupt type.

Parameters
channelencoder channel:
Returns
ENC_OK if everything is ok, an error code otherwise.

◆ gwa_encoder_init()

int gwa_encoder_init ( uint8_t channel,
uint8_t direction,
uint32_t value )

Sets up the encoder.

Parameters
channelencoder channel:
directionspecifies if the counter counts up (ENCODER_DIR_UP) or down (ENCODER_DIR_DOWN).
valueinitial value of the counter.
Returns
ENC_OK if everything is ok, an error code otherwise.

◆ gwa_encoder_read()

int gwa_encoder_read ( uint8_t channel,
uint32_t * value )

Reads the value of the counter.

Parameters
channelencoder channel:
valuepointer to a variable that holds the counter value
Returns
ENC_OK if everything is ok, an error code otherwise.