From: Nathael Pajani Date: Wed, 8 Feb 2023 02:45:05 +0000 (+0100) Subject: Limited example of AT42QT1012 capacitive touch sensor support X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=26b242de78e37540f9dd0a5cfedaa437f6321661;p=soft%2Flpc122x%2Fexamples Limited example of AT42QT1012 capacitive touch sensor support --- diff --git a/touch_sensor/Makefile b/touch_sensor/Makefile new file mode 100644 index 0000000..41ae555 --- /dev/null +++ b/touch_sensor/Makefile @@ -0,0 +1,21 @@ +# Makefile for apps + +MODULE = $(shell basename $(shell cd .. && pwd && cd -)) +NAME = $(shell basename $(CURDIR)) + +# Add this to your ~/.vimrc in order to get proper function of :make in vim : +# let $COMPILE_FROM_IDE = 1 +ifeq ($(strip $(COMPILE_FROM_IDE)),) + PRINT_DIRECTORY = --no-print-directory +else + PRINT_DIRECTORY = + LANG = C +endif + +.PHONY: $(NAME).bin +$(NAME).bin: + @make -C ../../.. ${PRINT_DIRECTORY} NAME=$(NAME) MODULE=$(MODULE) apps/$(MODULE)/$(NAME)/$@ + +clean mrproper: + @make -C ../../.. ${PRINT_DIRECTORY} $@ + diff --git a/touch_sensor/README b/touch_sensor/README new file mode 100644 index 0000000..4826da3 --- /dev/null +++ b/touch_sensor/README @@ -0,0 +1,33 @@ +Limited example of AT42QT1012 capacitive touch sensor support + +Copyright 2015 Nathael Pajani + + +/* **************************************************************************** + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + *************************************************************************** */ + +This example shows the support of the AT42QT1012 touch sensor support. + +This sensor basically acts as a button, and can be handled as such. Thus, this +code is almost the same as the GPIO interrupt exemple. + +For this example, the sensor must be connected to GPIO_0_7. Refer to the user +manual of the module you selected to test this example to know how to connect +to this GPIO. + +Any contact change on touch button turns on the Green status led and displays +a message on UART0 + diff --git a/touch_sensor/main.c b/touch_sensor/main.c new file mode 100644 index 0000000..27d41c1 --- /dev/null +++ b/touch_sensor/main.c @@ -0,0 +1,126 @@ +/**************************************************************************** + * touch_sensor/main.c + * + * AT42QT1012 capacitive touch sensor example + * + * Copyright 2020 Nathael Pajani + * + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + *************************************************************************** */ + +/* + * Any contact change on touch button turns on the Green status led and + * displays a message on UART0 +*/ + +#include "core/system.h" +#include "core/systick.h" +#include "core/pio.h" +#include "lib/stdio.h" +#include "drivers/serial.h" +#include "drivers/gpio.h" +#include "extdrv/status_led.h" + + +#define MODULE_VERSION 0x04 +#define MODULE_NAME "GPIO Demo Module" + + +#define SELECTED_FREQ FREQ_SEL_48MHz + +/***************************************************************************** */ +/* Pins configuration */ +/* pins blocks are passed to set_pins() for pins configuration. + * Unused pin blocks can be removed safely with the corresponding set_pins() call + * All pins blocks may be safelly merged in a single block for single set_pins() call.. + */ +const struct pio_config common_pins[] = { + /* UART 0 */ + { LPC_UART0_RX_PIO_0_1, LPC_IO_DIGITAL }, + { LPC_UART0_TX_PIO_0_2, LPC_IO_DIGITAL }, + { LPC_GPIO_0_7, LPC_IO_DIGITAL }, + ARRAY_LAST_PIO, +}; + +const struct pio status_led_green = LPC_GPIO_1_4; +const struct pio status_led_red = LPC_GPIO_1_5; + +const struct pio button = LPC_GPIO_0_12; /* ISP button */ +const struct pio touch = LPC_GPIO_0_7; /* Touch button - AT42QT1012 */ + + +/***************************************************************************** */ +void system_init() +{ + /* Stop the watchdog */ + startup_watchdog_disable(); /* Do it right now, before it gets a chance to break in */ + system_brown_out_detection_config(0); /* No ADC used */ + system_set_default_power_state(); + clock_config(SELECTED_FREQ); + set_pins(common_pins); + gpio_on(); + status_led_config(&status_led_green, &status_led_red); + /* System tick timer MUST be configured and running in order to use the sleeping + * functions */ + systick_timer_on(1); /* 1ms */ + systick_start(); +} + +/* Define our fault handler. This one is not mandatory, the dummy fault handler + * will be used when it's not overridden here. + * Note : The default one does a simple infinite loop. If the watchdog is deactivated + * the system will hang. + */ +void fault_info(const char* name, uint32_t len) +{ + uprintf(UART0, name); + while (1); +} + + +volatile uint8_t activation_request = 0; +void activate(uint32_t gpio) { + activation_request = gpio; +} + + +/***************************************************************************** */ +int main(void) +{ + system_init(); + uart_on(UART0, 115200, NULL); + + /* Activate the interrupt on both edges (button press and button release) */ + config_gpio(&touch, 0, GPIO_DIR_IN, 0); + set_gpio_callback(activate, &touch, EDGES_BOTH); + + + uprintf(UART0, "Configured\n"); + while (1) { + if (activation_request != 0) { + status_led(green_only); + uprintf(UART0, "Detection: %d : %s\n", activation_request, (gpio_read(touch) ? "ON" : "OFF")); + msleep(100); + activation_request = 0; + } + status_led(none); + msleep(200); + } + return 0; +} + + +