-
Notifications
You must be signed in to change notification settings - Fork 0
/
capsenseThread.cpp
99 lines (79 loc) · 3.4 KB
/
capsenseThread.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "mbed.h"
#include "cy_pdl.h"
#include "cycfg_capsense.h"
#include "cycfg.h"
#include "temperatureThread.h"
static Semaphore capsense_sem;
/*****************************************************************************
* Function Name: CapSense_InterruptHandler()
******************************************************************************
* Summary:
* Wrapper function for handling interrupts from CSD block.
*
*****************************************************************************/
static void CapSense_InterruptHandler(void)
{
Cy_CapSense_InterruptHandler(CYBSP_CSD_HW, &cy_capsense_context);
}
/*****************************************************************************
* Function Name: CapSenseEndOfScanCallback()
******************************************************************************
* Summary:
* This function releases a semaphore to indicate end of a CapSense scan.
*
* Parameters:
* cy_stc_active_scan_sns_t* : pointer to active sensor details.
*
*****************************************************************************/
static void CapSenseEndOfScanCallback(cy_stc_active_scan_sns_t * ptrActiveScan)
{
capsense_sem.release();
}
void capsenseThread(void)
{
/* Configure AMUX bus for CapSense */
init_cycfg_routing();
/* Configure PERI clocks for CapSense */
Cy_SysClk_PeriphAssignDivider(PCLK_CSD_CLOCK, CYBSP_CSD_CLK_DIV_HW, CYBSP_CSD_CLK_DIV_NUM);
Cy_SysClk_PeriphDisableDivider(CYBSP_CSD_CLK_DIV_HW, CYBSP_CSD_CLK_DIV_NUM);
Cy_SysClk_PeriphSetDivider(CYBSP_CSD_CLK_DIV_HW, CYBSP_CSD_CLK_DIV_NUM, 0u);
Cy_SysClk_PeriphEnableDivider(CYBSP_CSD_CLK_DIV_HW, CYBSP_CSD_CLK_DIV_NUM);
/* Initialize the CSD HW block to the default state. */
Cy_CapSense_Init(&cy_capsense_context);
const cy_stc_sysint_t CapSense_ISR_cfg =
{
.intrSrc = CYBSP_CSD_IRQ,
.intrPriority = 4u
};
/* Initialize CapSense interrupt */
Cy_SysInt_Init(&CapSense_ISR_cfg, &CapSense_InterruptHandler);
NVIC_ClearPendingIRQ(CapSense_ISR_cfg.intrSrc);
NVIC_EnableIRQ(CapSense_ISR_cfg.intrSrc);
/* Initialize the CapSense firmware modules. */
Cy_CapSense_Enable(&cy_capsense_context);
Cy_CapSense_RegisterCallback(CY_CAPSENSE_END_OF_SCAN_E, CapSenseEndOfScanCallback, &cy_capsense_context);
Cy_CapSense_ScanAllWidgets(&cy_capsense_context); // Launch the initial scan
uint32_t prevBtn0Status = 0u;
uint32_t prevBtn1Status = 0u;
while(1)
{
capsense_sem.acquire();
if (CY_CAPSENSE_NOT_BUSY == Cy_CapSense_IsBusy(&cy_capsense_context))
{
Cy_CapSense_ProcessAllWidgets(&cy_capsense_context);
uint32_t currBtn0Status = Cy_CapSense_IsSensorActive(CY_CAPSENSE_BUTTON0_WDGT_ID, CY_CAPSENSE_BUTTON0_SNS0_ID, &cy_capsense_context);
uint32_t currBtn1Status = Cy_CapSense_IsSensorActive(CY_CAPSENSE_BUTTON1_WDGT_ID, CY_CAPSENSE_BUTTON1_SNS0_ID, &cy_capsense_context);
if(currBtn0Status != prevBtn0Status && currBtn0Status==1 )
{
tempSendUpdateCurrentSetPointF(-0.1);
}
prevBtn0Status = currBtn0Status;
if(currBtn1Status != prevBtn1Status && currBtn1Status == 1)
{
tempSendUpdateCurrentSetPointF(0.1);
}
prevBtn1Status = currBtn1Status;
Cy_CapSense_ScanAllWidgets(&cy_capsense_context);
}
}
}