cursada_mc2
Base de control de temperatura para EDU-CIAA-NXP
Loading...
Searching...
No Matches
buttons_driver.c File Reference
#include "buttons_driver.h"
#include <stdbool.h>
#include <stddef.h>
+ Include dependency graph for buttons_driver.c:

Go to the source code of this file.

Data Structures

struct  button_hw_t
 
struct  button_estado_t
 

Macros

#define BUTTONS_CANTIDAD   4U
 
#define BUTTONS_DEBOUNCE_MS   40U
 

Functions

static int8_t button_indice_desde_tecla (uint8_t tecla)
 
static bool button_esta_presionado (uint8_t indice)
 
void buttons_init (void)
 Inicializa los pines asociados a los cuatro pulsadores.
 
void button_notify_irq (uint8_t button_id)
 Notifica al driver que una tecla genero una interrupcion externa.
 
void buttons_process (uint32_t delta_ms)
 Procesa el debounce y actualiza los eventos latcheados de teclas.
 
uint8_t button_get_event (void)
 Devuelve y consume el siguiente evento de tecla confirmado.
 

Variables

static const button_hw_t button_hw_ [BUTTONS_CANTIDAD]
 
static volatile button_estado_t button_estados_ [BUTTONS_CANTIDAD]
 

Detailed Description

Author
agustinavila (tinto.nosp@m..avi.nosp@m.la@gm.nosp@m.ail..nosp@m.com)
Version
0.1
Date
2023-04-26

Definition in file buttons_driver.c.

Macro Definition Documentation

◆ BUTTONS_CANTIDAD

#define BUTTONS_CANTIDAD   4U

Definition at line 17 of file buttons_driver.c.

◆ BUTTONS_DEBOUNCE_MS

#define BUTTONS_DEBOUNCE_MS   40U

Definition at line 18 of file buttons_driver.c.

Function Documentation

◆ button_esta_presionado()

static bool button_esta_presionado ( uint8_t  indice)
static

Definition at line 71 of file buttons_driver.c.

References button_hw_.

Referenced by buttons_process().

◆ button_get_event()

uint8_t button_get_event ( void  )
Returns
TECLA1..TECLA4 si hay un evento pendiente, o 0 si no hay eventos para consumir.

Definition at line 163 of file buttons_driver.c.

References button_estados_, button_hw_, BUTTONS_CANTIDAD, button_estado_t::evento_pendiente, and button_hw_t::tecla.

Referenced by hmi_process().

◆ button_indice_desde_tecla()

static int8_t button_indice_desde_tecla ( uint8_t  tecla)
static

Definition at line 55 of file buttons_driver.c.

References TECLA1, TECLA2, TECLA3, and TECLA4.

Referenced by button_notify_irq().

◆ button_notify_irq()

void button_notify_irq ( uint8_t  button_id)

Esta funcion debe llamarse desde el handler asociado a la tecla correspondiente.

Parameters
button_idIdentificador de la tecla que disparo la IRQ.

Definition at line 107 of file buttons_driver.c.

References button_estados_, and button_indice_desde_tecla().

Referenced by PININT0_IRQ_HANDLER(), PININT1_IRQ_HANDLER(), PININT2_IRQ_HANDLER(), and PININT3_IRQ_HANDLER().

◆ buttons_init()

◆ buttons_process()

void buttons_process ( uint32_t  delta_ms)

Debe llamarse de manera periodica desde el lazo principal.

Parameters
delta_msTiempo transcurrido desde la ultima llamada, en milisegundos.

Definition at line 120 of file buttons_driver.c.

References button_estado_t::armado, button_esta_presionado(), button_estados_, BUTTONS_CANTIDAD, BUTTONS_DEBOUNCE_MS, button_estado_t::debounce_acumulado_ms, button_estado_t::evento_pendiente, and button_estado_t::irq_pendiente.

Referenced by app_step_20ms().

Variable Documentation

◆ button_estados_

volatile button_estado_t button_estados_[BUTTONS_CANTIDAD]
static
Initial value:
= {
[0] = {.armado = true},
[1] = {.armado = true},
[2] = {.armado = true},
[3] = {.armado = true},
}

Definition at line 48 of file buttons_driver.c.

Referenced by button_get_event(), button_notify_irq(), buttons_init(), and buttons_process().

◆ button_hw_

const button_hw_t button_hw_[BUTTONS_CANTIDAD]
static
Initial value:
= {
[0] = {.tecla = TECLA1, .scu_port = 1U, .scu_pin = 0U, .scu_mode = (MD_PUP | MD_EZI | MD_ZI), .scu_func = FUNC0, .gpio_port = 0U, .gpio_pin = 4U, .pinint_selector = 0U, .pinint_mask = PININTCH0, .irqn = PIN_INT0_IRQn},
[1] = {.tecla = TECLA2, .scu_port = 1U, .scu_pin = 1U, .scu_mode = (MD_PUP | MD_EZI | MD_ZI), .scu_func = FUNC0, .gpio_port = 0U, .gpio_pin = 8U, .pinint_selector = 1U, .pinint_mask = PININTCH1, .irqn = PIN_INT1_IRQn},
[2] = {.tecla = TECLA3, .scu_port = 1U, .scu_pin = 2U, .scu_mode = (MD_PUP | MD_EZI | MD_ZI), .scu_func = FUNC0, .gpio_port = 0U, .gpio_pin = 9U, .pinint_selector = 2U, .pinint_mask = PININTCH2, .irqn = PIN_INT2_IRQn},
[3] = {.tecla = TECLA4, .scu_port = 1U, .scu_pin = 6U, .scu_mode = (MD_PUP | MD_EZI | MD_ZI), .scu_func = FUNC0, .gpio_port = 1U, .gpio_pin = 9U, .pinint_selector = 3U, .pinint_mask = PININTCH3, .irqn = PIN_INT3_IRQn},
}
#define TECLA4
Identificador de la tecla 4.
#define TECLA1
Identificador de la tecla 1.
#define TECLA2
Identificador de la tecla 2.
#define TECLA3
Identificador de la tecla 3.

Definition at line 41 of file buttons_driver.c.

Referenced by button_esta_presionado(), button_get_event(), and buttons_init().