-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b60c7ef
commit f07e8d7
Showing
34 changed files
with
4,292 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Keep this first line. | ||
TOP = ../.. | ||
|
||
# If your firmware targets a specific board, specify it here, | ||
# or omit it and provide it on the command line (make BOARD=foo). | ||
BOARD=vectorscope_touch | ||
|
||
# Leave this line here. | ||
include $(TOP)/make.mk | ||
|
||
SRCS += \ | ||
./app.c \ | ||
./qtouch/touch.c \ | ||
./qtouch/hal_atomic.c \ | ||
./qtouch/utils_list.c \ | ||
|
||
LIBS += ./qtouch/lib/gcc/libqtm_acq_saml21_0x0026.a \ | ||
./qtouch/lib/gcc/libqtm_surface_cs_cm0p_0x0021.a \ | ||
./qtouch/lib/gcc/libqtm_touch_key_cm0p_0x0002.a | ||
|
||
# Finally, leave this line at the bottom of the file. | ||
include $(TOP)/rules.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
#include "app.h" | ||
#include "tc.h" | ||
#include "dac.h" | ||
#include "dma.h" | ||
#include "eic.h" | ||
#include "delay.h" | ||
#include "qtouch/touch.h" | ||
#include <stdio.h> | ||
#include <math.h> | ||
|
||
void eic_callback(uint8_t channel); | ||
void reset_to_bootloader(void); | ||
|
||
extern volatile uint8_t measurement_done_touch; | ||
|
||
int getentropy(void *buffer, size_t length); | ||
int getentropy(void *buffer, size_t length) { | ||
(void)buffer; | ||
(void)length; | ||
return 0; | ||
} | ||
|
||
// x and y values are a union of two 16-bit values | ||
typedef union { | ||
struct { | ||
uint16_t x; | ||
uint16_t y; | ||
} position; | ||
uint32_t data; | ||
} touch_val_t; | ||
|
||
touch_val_t live_touch_value; | ||
|
||
void app_init(void) { | ||
// set up 4 MHz clock for touch controller | ||
GCLK->GENCTRL[1].reg = GCLK_GENCTRL_DIV(2) | | ||
GCLK_GENCTRL_SRC_OSC16M | | ||
GCLK_GENCTRL_RUNSTDBY | | ||
GCLK_GENCTRL_GENEN; | ||
} | ||
|
||
void app_setup(void) { | ||
// configure EIC | ||
eic_init(); | ||
eic_enable(); | ||
|
||
// Configure buttons as EIC inputs with pullups | ||
HAL_GPIO_STOP_LIVE_in(); | ||
HAL_GPIO_STOP_LIVE_pullup(); | ||
HAL_GPIO_STOP_LIVE_pmuxen(HAL_GPIO_PMUX_EIC); | ||
eic_configure_pin(HAL_GPIO_STOP_LIVE_pin(), INTERRUPT_TRIGGER_FALLING); | ||
eic_enable_interrupt(HAL_GPIO_STOP_LIVE_pin()); | ||
|
||
HAL_GPIO_PLAY_PAUSE_in(); | ||
HAL_GPIO_PLAY_PAUSE_pullup(); | ||
HAL_GPIO_PLAY_PAUSE_pmuxen(HAL_GPIO_PMUX_EIC); | ||
eic_configure_pin(HAL_GPIO_PLAY_PAUSE_pin(), INTERRUPT_TRIGGER_FALLING); | ||
eic_enable_interrupt(HAL_GPIO_PLAY_PAUSE_pin()); | ||
|
||
HAL_GPIO_RECORD_in(); | ||
HAL_GPIO_RECORD_pullup(); | ||
HAL_GPIO_RECORD_pmuxen(HAL_GPIO_PMUX_EIC); | ||
eic_configure_pin(HAL_GPIO_RECORD_pin(), INTERRUPT_TRIGGER_FALLING); | ||
eic_enable_interrupt(HAL_GPIO_RECORD_pin()); | ||
|
||
HAL_GPIO_FASTER_in(); | ||
HAL_GPIO_FASTER_pullup(); | ||
HAL_GPIO_FASTER_pmuxen(HAL_GPIO_PMUX_EIC); | ||
eic_configure_pin(HAL_GPIO_FASTER_pin(), INTERRUPT_TRIGGER_FALLING); | ||
eic_enable_interrupt(HAL_GPIO_FASTER_pin()); | ||
|
||
HAL_GPIO_SLOWER_in(); | ||
HAL_GPIO_SLOWER_pullup(); | ||
HAL_GPIO_SLOWER_pmuxen(HAL_GPIO_PMUX_EIC); | ||
eic_configure_pin(HAL_GPIO_SLOWER_pin(), INTERRUPT_TRIGGER_FALLING); | ||
eic_enable_interrupt(HAL_GPIO_SLOWER_pin()); | ||
|
||
eic_configure_callback(eic_callback); | ||
|
||
// configure DACs | ||
HAL_GPIO_XOUT_pmuxen(HAL_GPIO_PMUX_DAC); | ||
HAL_GPIO_YOUT_pmuxen(HAL_GPIO_PMUX_DAC); | ||
dac_init(); | ||
dac_enable(DAC_CHANNEL_BOTH); | ||
live_touch_value.position.x = 2048; | ||
live_touch_value.position.y = 2048; | ||
|
||
// Configure LEDs | ||
HAL_GPIO_LED_BLUE_out(); | ||
HAL_GPIO_LED_GREEN_out(); | ||
HAL_GPIO_LED_YELLOW_out(); | ||
HAL_GPIO_LED_RED_out(); | ||
|
||
// Configure touch pads | ||
HAL_GPIO_X0_pmuxen(HAL_GPIO_PMUX_PTC); | ||
HAL_GPIO_X0_out(); | ||
HAL_GPIO_X1_pmuxen(HAL_GPIO_PMUX_PTC); | ||
HAL_GPIO_X1_out(); | ||
HAL_GPIO_X2_pmuxen(HAL_GPIO_PMUX_PTC); | ||
HAL_GPIO_X2_out(); | ||
HAL_GPIO_X3_pmuxen(HAL_GPIO_PMUX_PTC); | ||
HAL_GPIO_X3_out(); | ||
HAL_GPIO_X4_pmuxen(HAL_GPIO_PMUX_PTC); | ||
HAL_GPIO_X4_out(); | ||
HAL_GPIO_X5_pmuxen(HAL_GPIO_PMUX_PTC); | ||
HAL_GPIO_X5_out(); | ||
HAL_GPIO_X6_pmuxen(HAL_GPIO_PMUX_PTC); | ||
HAL_GPIO_X6_out(); | ||
HAL_GPIO_X7_pmuxen(HAL_GPIO_PMUX_PTC); | ||
HAL_GPIO_X7_out(); | ||
HAL_GPIO_Y0_pmuxen(HAL_GPIO_PMUX_PTC); | ||
HAL_GPIO_Y0_in(); | ||
HAL_GPIO_Y1_pmuxen(HAL_GPIO_PMUX_PTC); | ||
HAL_GPIO_Y1_in(); | ||
HAL_GPIO_Y2_pmuxen(HAL_GPIO_PMUX_PTC); | ||
HAL_GPIO_Y2_in(); | ||
HAL_GPIO_Y3_pmuxen(HAL_GPIO_PMUX_PTC); | ||
HAL_GPIO_Y3_in(); | ||
HAL_GPIO_Y4_pmuxen(HAL_GPIO_PMUX_PTC); | ||
HAL_GPIO_Y4_in(); | ||
HAL_GPIO_Y5_pmuxen(HAL_GPIO_PMUX_PTC); | ||
HAL_GPIO_Y5_in(); | ||
HAL_GPIO_Y6_pmuxen(HAL_GPIO_PMUX_PTC); | ||
HAL_GPIO_Y6_in(); | ||
HAL_GPIO_Y7_pmuxen(HAL_GPIO_PMUX_PTC); | ||
HAL_GPIO_Y7_in(); | ||
|
||
GCLK->PCHCTRL[PTC_GCLK_ID].reg = GCLK_PCHCTRL_GEN_GCLK1_Val | (1 << GCLK_PCHCTRL_CHEN_Pos); | ||
MCLK->APBDMASK.bit.PTC_ = 1; | ||
|
||
tc_init(4, GENERIC_CLOCK_0, TC_PRESCALER_DIV1024); // 8 MHz / 1024 = 7182 | ||
tc_set_wavegen(4, TC_WAVE_WAVEGEN_MFRQ); // Match frequency mode, overflow at CC0 | ||
tc_count16_set_cc(4, 0, 156); // 7182 / 156 roughly equals 50 Hz or once every 20 ms | ||
TC4->COUNT16.INTENSET.reg = TC_INTENSET_OVF; // enable overflow interrupt | ||
NVIC_EnableIRQ(TC4_IRQn); | ||
tc_enable(4); | ||
|
||
// Configure touch sensors with Application specific settings | ||
touch_init(); | ||
} | ||
|
||
double i = 0; | ||
|
||
bool app_loop(void) { | ||
touch_process(); | ||
if (measurement_done_touch == 1) { | ||
measurement_done_touch = 0; | ||
} | ||
|
||
uint8_t status = get_surface_status(); | ||
if (status & 1) { | ||
live_touch_value.position.x = get_surface_position(HOR_POS) >> 4; | ||
live_touch_value.position.y = get_surface_position(VER_POS) >> 4; | ||
} else { | ||
live_touch_value.position.x = arc4random() % 4096; | ||
live_touch_value.position.y = arc4random() % 4096; | ||
} | ||
|
||
if (HAL_GPIO_PLAY_PAUSE_read()) { | ||
dac_set_analog_value(0, live_touch_value.position.x); | ||
dac_set_analog_value(1, live_touch_value.position.y); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
void irq_handler_tc4(void); | ||
void irq_handler_tc4(void) { | ||
touch_timer_handler(); | ||
HAL_GPIO_LED_BLUE_toggle(); | ||
TC4->COUNT16.INTFLAG.reg = TC_INTFLAG_OVF; | ||
} | ||
|
||
void irq_handler_tc1(void); | ||
void irq_handler_tc1(void) { | ||
TC1->COUNT16.INTFLAG.reg = TC_INTFLAG_OVF; | ||
} | ||
|
||
void eic_callback(uint8_t channel) { | ||
switch (channel) { | ||
case 1: // stop/live | ||
break; | ||
case 2: // play/pause | ||
break; | ||
case 15: // record | ||
// if both STOP and PLAY are also held down, reset to bootloader | ||
if (!HAL_GPIO_STOP_LIVE_read() && !HAL_GPIO_PLAY_PAUSE_read()) { | ||
reset_to_bootloader(); | ||
} | ||
break; | ||
case 3: // faster | ||
break; | ||
case 0: // slower | ||
break; | ||
} | ||
} | ||
|
||
void reset_to_bootloader(void) { | ||
volatile uint32_t *dbl_tap_ptr = ((volatile uint32_t *)(HSRAM_ADDR + HSRAM_SIZE - 4)); | ||
*dbl_tap_ptr = 0xf01669ef; // from the UF2 bootloaer: uf2.h line 255 | ||
NVIC_SystemReset(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Code generated from Atmel Start. | ||
* | ||
* This file will be overwritten when reconfiguring your Atmel Start project. | ||
* Please copy examples or other code you want to keep to a separate file | ||
* to avoid losing it when reconfiguring. | ||
*/ | ||
#ifndef ATMEL_START_PINS_H_INCLUDED | ||
#define ATMEL_START_PINS_H_INCLUDED | ||
|
||
#include <hal_gpio.h> | ||
|
||
// SAML22 has 9 pin functions | ||
|
||
#define GPIO_PIN_FUNCTION_A 0 | ||
#define GPIO_PIN_FUNCTION_B 1 | ||
#define GPIO_PIN_FUNCTION_C 2 | ||
#define GPIO_PIN_FUNCTION_D 3 | ||
#define GPIO_PIN_FUNCTION_E 4 | ||
#define GPIO_PIN_FUNCTION_F 5 | ||
#define GPIO_PIN_FUNCTION_G 6 | ||
#define GPIO_PIN_FUNCTION_H 7 | ||
#define GPIO_PIN_FUNCTION_I 8 | ||
|
||
#define PA02 GPIO(GPIO_PORTA, 2) | ||
#define PA03 GPIO(GPIO_PORTA, 3) | ||
#define PA10 GPIO(GPIO_PORTA, 10) | ||
#define PA11 GPIO(GPIO_PORTA, 11) | ||
#define PA27 GPIO(GPIO_PORTA, 27) | ||
#define PA30 GPIO(GPIO_PORTA, 30) | ||
#define PB08 GPIO(GPIO_PORTB, 8) | ||
#define PB22 GPIO(GPIO_PORTB, 22) | ||
#define PB23 GPIO(GPIO_PORTB, 23) | ||
|
||
#endif // ATMEL_START_PINS_H_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* \file | ||
* | ||
* \brief Critical sections related functionality implementation. | ||
* | ||
* Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries. | ||
* | ||
* \asf_license_start | ||
* | ||
* \page License | ||
* | ||
* Subject to your compliance with these terms, you may use Microchip | ||
* software and any derivatives exclusively with Microchip products. | ||
* It is your responsibility to comply with third party license terms applicable | ||
* to your use of third party software (including open source software) that | ||
* may accompany Microchip software. | ||
* | ||
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, | ||
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, | ||
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, | ||
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE | ||
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL | ||
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE | ||
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE | ||
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT | ||
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY | ||
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, | ||
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. | ||
* | ||
* \asf_license_stop | ||
* | ||
*/ | ||
|
||
#include "hal_atomic.h" | ||
|
||
/** | ||
* \brief Driver version | ||
*/ | ||
#define DRIVER_VERSION 0x00000001u | ||
|
||
/** | ||
* \brief Disable interrupts, enter critical section | ||
*/ | ||
void atomic_enter_critical(hal_atomic_t volatile *atomic) | ||
{ | ||
*atomic = __get_PRIMASK(); | ||
__disable_irq(); | ||
__DMB(); | ||
} | ||
|
||
/** | ||
* \brief Exit atomic section | ||
*/ | ||
void atomic_leave_critical(hal_atomic_t volatile *atomic) | ||
{ | ||
__DMB(); | ||
__set_PRIMASK(*atomic); | ||
} | ||
|
||
/** | ||
* \brief Retrieve the current driver version | ||
*/ | ||
uint32_t atomic_get_version(void) | ||
{ | ||
return DRIVER_VERSION; | ||
} |
Oops, something went wrong.